Exemplo n.º 1
0
static void get_alpha_mask(float_shape_t *shape)
{
   GdkColormap *colormap;
   GdkColor black;
   GdkColor white;
   GdkGC *gc;
   int rowstride, nchannels, x, y;
   guchar *pixels, *p;
   bool bright_green, has_alpha;

   colormap = gdk_colormap_get_system();
   gdk_color_black(colormap, &black);
   gdk_color_white(colormap, &white);

   shape->mask_bitmap =
      (GdkDrawable*)gdk_pixmap_new(NULL, shape->width, shape->height, 1);
   gc = gdk_gc_new(shape->mask_bitmap);
   
   gdk_gc_set_foreground(gc, &black);
   gdk_gc_set_background(gc, &white);
   gdk_draw_rectangle(shape->mask_bitmap, gc, TRUE, 0, 0,
                      shape->width, shape->height);

   nchannels = gdk_pixbuf_get_n_channels(shape->pixbuf);
   g_assert(gdk_pixbuf_get_colorspace(shape->pixbuf) == GDK_COLORSPACE_RGB);
   g_assert(gdk_pixbuf_get_bits_per_sample(shape->pixbuf) == 8);

   has_alpha = gdk_pixbuf_get_has_alpha(shape->pixbuf);
   
   rowstride = gdk_pixbuf_get_rowstride(shape->pixbuf);
   pixels = gdk_pixbuf_get_pixels(shape->pixbuf);

   gdk_gc_set_foreground(gc, &white);
   gdk_gc_set_background(gc, &black);
   
   for (y = 0; y < shape->height; y++) {
      for (x = 0; x < shape->width; x++) {
         p = pixels + y*rowstride + x*nchannels;
         bright_green = 0 == p[0] && 255 == p[1] && 0 == p[2];
         if (has_alpha) {
            if (255 == p[3])  // p[3] is alpha channel
               gdk_draw_point(shape->mask_bitmap, gc, x, y);
         } 
         else if (!bright_green) {   // Bright green is alpha for RGB images
            gdk_draw_point(shape->mask_bitmap, gc, x, y);
         }
      }
   }
}
Exemplo n.º 2
0
Arquivo: cdgdk.c Projeto: LuaDist/cd
static void cdpattern(cdCtxCanvas *ctxcanvas, int w, int h, const long int *colors)
{
  int x, y;
  GdkColor color;

  if (ctxcanvas->last_pattern == 0 || (ctxcanvas->last_pattern_w != w || ctxcanvas->last_pattern_h != h))
  {
    if (ctxcanvas->last_pattern != 0)
    {
      g_object_unref(ctxcanvas->last_pattern);
      g_object_unref(ctxcanvas->last_pattern_gc);
    }

    ctxcanvas->last_pattern = gdk_pixmap_new(ctxcanvas->wnd, w, h, ctxcanvas->depth);
    if (!ctxcanvas->last_pattern)
      return;

    ctxcanvas->last_pattern_gc = gdk_gc_new((GdkDrawable*)ctxcanvas->last_pattern);
    ctxcanvas->last_pattern_w = w;
    ctxcanvas->last_pattern_h = h;
  }

  for (y = 0; y < h; y++)
  {
    for (x = 0; x < w; x++)
    {
      color = cdColorToGdk(colors[y*w+x]);
      gdk_gc_set_rgb_fg_color(ctxcanvas->last_pattern_gc, &color);
      gdk_draw_point(ctxcanvas->last_pattern, ctxcanvas->last_pattern_gc, x, h-y-1);
    }
  }

  cdinteriorstyle(ctxcanvas, CD_PATTERN);
}
Exemplo n.º 3
0
static VALUE
rg_draw_point(VALUE self, VALUE gc, VALUE x, VALUE y)
{
    gdk_draw_point(_SELF(self), GDK_GC(RVAL2GOBJ(gc)),
                   NUM2INT(x), NUM2INT(y));
    return self;
}
Exemplo n.º 4
0
/*!
  Display a point at the image point \e ip location.
  \param ip : Point location.
  \param color : Point color.
*/
void vpDisplayGTK::displayPoint ( const vpImagePoint &ip,
				  const vpColor &color )
{
  if (displayHasBeenInitialized)
  {
    if (color.id < vpColor::id_unknown)
      gdk_gc_set_foreground(gc, col[color.id]);
    else {
      gdkcolor.red   = 256 * color.R;
      gdkcolor.green = 256 * color.G;
      gdkcolor.blue  = 256 * color.B;
      gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
      gdk_gc_set_foreground(gc, &gdkcolor);     
    }

    gdk_draw_point(background,gc, 
		   vpMath::round( ip.get_u() ), 
		   vpMath::round( ip.get_v() ) );
  }
  else
  {
    vpERROR_TRACE("GTK not initialized " ) ;
    throw(vpDisplayException(vpDisplayException::notInitializedError,
                             "GTK not initialized")) ;
  }
}
Exemplo n.º 5
0
static GdkPixmap *
scale_pixmap (GdkWindow *window, GdkPixmap *pixmap, gdouble scale_x, gdouble scale_y)
{
  GdkGC *gc;
  GdkColormap *colormap;
  GdkColorContext *cc;
  GdkVisual *visual;
  GdkImage *image;
  GdkPixmap *new_pixmap;
  gint x, y, width, height, new_width, new_height;

  if(!pixmap) return NULL;
  if(!window) return NULL;

  gc = gdk_gc_new(pixmap);
  colormap = gdk_colormap_get_system ();
  visual = gdk_visual_get_system ();
  cc = gdk_color_context_new(visual, colormap);
  gdk_window_get_size(pixmap, &width, &height);

  if(scale_x == 1.0 && scale_y == 1.0){
    new_pixmap = gdk_pixmap_new(window, width, height, -1);
    gdk_draw_pixmap(new_pixmap,
                    gc,
                    pixmap,
                    0, 0,
                    0, 0,
                    width, height);
    return new_pixmap;
  }

  new_width = roundint(width * scale_x);
  new_height = roundint(height * scale_y);
  new_pixmap = gdk_pixmap_new(window, new_width, new_height, -1);

  image = gdk_image_get(pixmap,
                        0, 0,
                        width, height);

  for(x = 0; x < new_width; x++){
    for(y = 0; y < new_height; y++){
      GdkColor color;
      gint px, py;

      px = MIN(roundint(x / scale_x), width - 1);
      py = MIN(roundint(y / scale_y), height - 1);

      color.pixel = gdk_image_get_pixel(image, px, py);
      gdk_color_context_query_color(cc, &color);

      gdk_gc_set_foreground(gc, &color);
      gdk_draw_point(new_pixmap, gc, x, y);
    }
  }

  gdk_image_destroy(image);
  gdk_color_context_free(cc);
  return new_pixmap;
}
Exemplo n.º 6
0
void SDC::DrawPoint(int x, int y) {
#ifdef __WXGTK__
	gdk_draw_point(m_gdkbmp, m_gc, x, y);
#else
	Select();
	LOGPEN lp;
	GetObject((HPEN)m_pen.GetResourceHandle(), sizeof(lp), &lp);
	SetPixel(m_gc, x, y, lp.lopnColor);
#endif
}
Exemplo n.º 7
0
static void
gtk_plot_gdk_draw_point                              (GtkPlotPC *pc,
                                                     gdouble x, gdouble y)
{
  if(!GTK_PLOT_GDK(pc)->gc) return;
  if(!GTK_PLOT_GDK(pc)->drawable) return;

  gdk_draw_point(GTK_PLOT_GDK(pc)->drawable, GTK_PLOT_GDK(pc)->gc,
                 roundint(x), roundint(y));
}
Exemplo n.º 8
0
/**
 * gimp_canvas_draw_point:
 * @canvas: a #GimpCanvas widget
 * @style:  one of the enumerated #GimpCanvasStyle's.
 * @x:      x coordinate
 * @y:      y coordinate
 *
 * Draw a single pixel at the specified location in the specified
 * style.
 **/
void
gimp_canvas_draw_point (GimpCanvas      *canvas,
                        GimpCanvasStyle  style,
                        gint             x,
                        gint             y)
{
  if (! gimp_canvas_ensure_style (canvas, style))
    return;

  gdk_draw_point (GTK_WIDGET (canvas)->window, canvas->gc[style],
                  x, y);
}
Exemplo n.º 9
0
static void draw (QCADDesignObject *obj, GdkDrawable *dst, GdkFunction rop, GdkRectangle *rcClip)
  {
  int Nix, Nix1 ;
  GdkGC *gc = NULL ;
  GdkRectangle rcReal ;
  GdkPoint ptSrc, ptDst ;
  QCADRectangleElectrode *rc_electrode = QCAD_RECTANGLE_ELECTRODE (obj) ;
  GdkColor *clr = NULL ;

  world_to_real_rect (&(obj->bounding_box), &rcReal) ;

  if (!RECT_INTERSECT_RECT (rcReal.x, rcReal.y, rcReal.width, rcReal.height, rcClip->x, rcClip->y, rcClip->width, rcClip->height))
    return ;

  clr = obj->bSelected ? clr_idx_to_clr_struct (RED) : &(obj->clr) ;
  gc = gdk_gc_new (dst) ;
  gdk_gc_set_foreground (gc, clr) ;
  gdk_gc_set_background (gc, clr) ;
  gdk_gc_set_function (gc, rop) ;
  gdk_gc_set_clip_rectangle (gc, rcClip) ;

  ptSrc.x = world_to_real_x (rc_electrode->precompute_params.pt[0].xWorld) ;
  ptSrc.y = world_to_real_y (rc_electrode->precompute_params.pt[0].yWorld) ;
  ptDst.x = world_to_real_x (rc_electrode->precompute_params.pt[1].xWorld) ;
  ptDst.y = world_to_real_y (rc_electrode->precompute_params.pt[1].yWorld) ;
  gdk_draw_line (dst, gc, ptSrc.x, ptSrc.y, ptDst.x, ptDst.y) ;
  ptSrc = ptDst ;
  ptDst.x = world_to_real_x (rc_electrode->precompute_params.pt[2].xWorld) ;
  ptDst.y = world_to_real_y (rc_electrode->precompute_params.pt[2].yWorld) ;
  gdk_draw_line (dst, gc, ptSrc.x, ptSrc.y, ptDst.x, ptDst.y) ;
  ptSrc = ptDst ;
  ptDst.x = world_to_real_x (rc_electrode->precompute_params.pt[3].xWorld) ;
  ptDst.y = world_to_real_y (rc_electrode->precompute_params.pt[3].yWorld) ;
  gdk_draw_line (dst, gc, ptSrc.x, ptSrc.y, ptDst.x, ptDst.y) ;
  ptSrc = ptDst ;
  ptDst.x = world_to_real_x (rc_electrode->precompute_params.pt[0].xWorld) ;
  ptDst.y = world_to_real_y (rc_electrode->precompute_params.pt[0].yWorld) ;
  gdk_draw_line (dst, gc, ptSrc.x, ptSrc.y, ptDst.x, ptDst.y) ;

  for (Nix = 0 ; Nix < rc_electrode->n_x_divisions ; Nix++)
    for (Nix1 = 0 ; Nix1 < rc_electrode->n_y_divisions ; Nix1++)
      {
      ptSrc.x = world_to_real_x (exp_array_index_2d (rc_electrode->precompute_params.pts, WorldPoint, Nix1, Nix).xWorld) ;
      ptSrc.y = world_to_real_y (exp_array_index_2d (rc_electrode->precompute_params.pts, WorldPoint, Nix1, Nix).yWorld) ;
      if (PT_IN_RECT (ptSrc.x, ptSrc.y, rcClip->x, rcClip->y, rcClip->width, rcClip->height))
        gdk_draw_point (dst, gc, ptSrc.x, ptSrc.y) ;
      }

  g_object_unref (gc) ;
  }
/* FIXME Draw a dotted grid over the specified area to make it look 
 * insensitive. Actually, we should generate that pixbuf once and 
 * just render it over later... */
static void
draw_grid                                       (GdkDrawable *drawable, 
                                                 GdkGC *gc, 
                                                 int x, 
                                                 int y,
                                                 gint w, 
                                                 gint h)
{
    int currentx;
    int currenty;
    for (currenty = y; currenty <= h; currenty++)
        for (currentx = ((currenty % 2 == 0) ? x : x + 1); currentx <= w; currentx += 2)
            gdk_draw_point (drawable, gc, currentx, currenty);
}
Exemplo n.º 11
0
Arquivo: main.cpp Projeto: cjhgo/nrciz
static void draw_brush (GtkWidget *widget, gint x, gint y)
{

	//GdkRectangle update_rect;

	//update_rect.x = x;
	//update_rect.y = y;
	//update_rect.width = 1;
	//update_rect.height = 1;

	/* Paint to the pixmap, where we store our state */
	if (g_map[y][x]) {
		gdk_draw_point(pixmap,
				widget->style->black_gc,
				x, y);
		//gdk_draw_rectangle (pixmap,
				//widget->style->black_gc,
				//TRUE,
				//update_rect.x, update_rect.y,
				//update_rect.width, update_rect.height);
	} else  {
		gdk_draw_point(pixmap,
				widget->style->white_gc,
				x, y);
		//gdk_draw_rectangle (pixmap,
				//widget->style->white_gc,
				//TRUE,
				//update_rect.x, update_rect.y,
				//update_rect.width, update_rect.height);
	} 

	/* Now invalidate the affected region of the drawing area. */
	//gdk_window_invalidate_rect (widget->window,
			//&update_rect,
			//FALSE);
}
Exemplo n.º 12
0
void dessiner_balise(balise* pt_balise,file_opener* donnees)
{
    GdkDrawable* cartew=donnees->carte->window;
    if(pt_balise->affichage==1)
    {
     //   printf("IF balise : Je change car affichage = %d\n", pt_balise->affichage);
        double x=conversion_longitude(pt_balise->longitude,donnees);
        double y=conversion_lat(pt_balise->latitude,donnees);
        gdk_draw_string(cartew,donnees->font,donnees->gc, donnees->xcarte*x+2,donnees->ycarte*y + 7, pt_balise->nom);
        gdk_draw_point(cartew,donnees->gc, donnees->xcarte*x,donnees->ycarte*y);
    }
    else
    {
      //  printf("ELSE balise : Je change pas car affichage = %d\n", pt_balise->affichage);
    }

}
Exemplo n.º 13
0
/*! \brief Records a new point for the stroke.
 *  \par Function Description
 *  This function adds the point (<B>x</B>,<B>y</B>) as a new point in
 *  the stroke.
 *
 * The footprint is updated and the new point is drawn on the drawing area.
 *
 *  \param [in] w_current The GSCHEM_TOPLEVEL object.
 *  \param [in] x        The X coord of the new point.
 *  \param [in] Y        The X coord of the new point.
 */
void
x_stroke_record (GSCHEM_TOPLEVEL *w_current, gint x, gint y)
{
  g_assert (stroke_points != NULL);

  stroke_record (x, y);

  if (stroke_points->len < STROKE_MAX_POINTS) {
    StrokePoint point = { x, y };

    g_array_append_val (stroke_points, point);

    gdk_gc_set_foreground (w_current->gc, x_get_color (STROKE_COLOR));
    gdk_draw_point (w_current->window, w_current->gc, x, y);
  }

}
Exemplo n.º 14
0
Arquivo: cdgdk.c Projeto: LuaDist/cd
static void cdpixel(cdCtxCanvas *ctxcanvas, int x, int y, long int color)
{
  if (ctxcanvas->canvas->foreground != color)
  {
    GdkColor clr = cdColorToGdk(color);
    gdk_gc_set_rgb_fg_color(ctxcanvas->gc, &clr);
  }

  if (ctxcanvas->canvas->use_matrix)
    cdMatrixTransformPoint(ctxcanvas->xmatrix, x, y, &x, &y);

  /* Draw pixel */
  gdk_draw_point(ctxcanvas->wnd, ctxcanvas->gc, x, y);

  if (ctxcanvas->canvas->foreground != color)
    gdk_gc_set_rgb_fg_color(ctxcanvas->gc, &ctxcanvas->fg);
}
Exemplo n.º 15
0
Arquivo: main.cpp Projeto: cjhgo/nrciz
static void draw_point(GtkWidget* widget, int x, int y)
{

	//GdkRectangle update_rect;

	//update_rect.x = x;
	//update_rect.y = y;
	//update_rect.width = 1;
	//update_rect.height = 1;

	//gdk_draw_rectangle (pixmap,
			//widget->style->dark_gc[1],
			//TRUE,
			//update_rect.x, update_rect.y,
			//update_rect.width, update_rect.height);
	gdk_draw_point(pixmap,
			widget->style->dark_gc[1],
			x, y);
}
Exemplo n.º 16
0
void		on_edge1_menu_activate (const gchar *handler_name,
					GObject *object,
					const gchar *signal_name,
					const gchar *signal_data,
					GObject *connect_object,
					gboolean after,
					gpointer user_data)
{
  GtkWidget	*view;
  GtkWidget	*draw;
  int		i;
  gint		width;
  gint		height;
  
  START;
  i = 0;
  if(!vue_is_displayed[0])
    {
      vue_is_displayed[0] = 1;
      uv_gtk_env->quasar_proj[0] = set_quasar_proj(uv_gtk_env, uv_gtk_env->quasar_pos,0);
      view = deglade("uv_view.glade", "uv_view");
      draw = get_child(view, "uv_draw");
      if (draw != NULL)
	{
	  gtk_widget_show(draw);
	  gtk_widget_get_size_request(draw, &width, &height);
	  width = width/2;
	  height = height/2;
	  for(i = 0; i < uv_gtk_env->data_lenght; i++)
	    {
	      gdk_draw_point(draw->window,
			     draw->style->black_gc,
			     (int) (uv_gtk_env->quasar_proj[0][i].x*width+width),
			     (int) (height-uv_gtk_env->quasar_proj[0][i].y*height)
			     );
	    }
	  gtk_widget_show(view);
	}
      else
	printf("GTK de merde !\n");
    }
}
Exemplo n.º 17
0
void dessiner_aerodromes(aerodrome* pt_aero,file_opener* donnees)
{
    GdkDrawable* cartew=donnees->carte->window;
    //  Si l'affichage est autorisé
    if(pt_aero->affichage==1)
    {
    // On récupère on on converti les points
    double x=conversion_longitude(pt_aero->longitude,donnees);
    double y=conversion_lat(pt_aero->latitude,donnees);

    // On trace le point et le nom
    gdk_draw_string(cartew,donnees->font,donnees->gc, donnees->xcarte*x+2,donnees->ycarte*y + 7, pt_aero->oaci);
    gdk_draw_point(cartew,donnees->gc, donnees->xcarte*x,donnees->ycarte*y);
    }
    else
    {
      //  printf("ELSE aero : Je change pas car affichage = %d\n", pt_aero->affichage);
    }


}
Exemplo n.º 18
0
gboolean draw_city_dots_timezone_map() {
	int i;
	GtkWidget *drawarea = lookup_widget(MainWindow,"drawingarea1");
	GdkGC *gc = gdk_gc_new(drawarea->window);
	GdkColor color;
	gdk_color_parse("yellow",&color);
	gdk_colormap_alloc_color(gdk_colormap_get_system(),&color,TRUE,TRUE);
	gtk_widget_modify_fg(drawarea,GTK_STATE_NORMAL,&color);
	
	gdk_gc_set_foreground(gc,&color);
	for (i = 0; i < timezones_count; i++) {
//		debug("Drawing point %d %d of %s\n",
//		      map2canvas_lon(timezones[i].lon,MAP_WIDTH),
//		      map2canvas_lat(timezones[i].lat,MAP_HEIGHT),
//		      timezones[i].tz);
		gdk_draw_point(drawarea->window,gc,
			       map2canvas_lon(timezones[i].lon,MAP_WIDTH),
			       map2canvas_lat(timezones[i].lat,MAP_HEIGHT));
	}
	g_object_unref(gc);
	return TRUE;
}
Exemplo n.º 19
0
Arquivo: cdgdk.c Projeto: LuaDist/cd
static void cdstipple(cdCtxCanvas *ctxcanvas, int w, int h, const unsigned char *data)
{
  int x, y;

  if (ctxcanvas->last_stipple == 0 || (ctxcanvas->last_stipple_w != w || ctxcanvas->last_stipple_h != h))
  {
    if (ctxcanvas->last_stipple != 0)
    {
      g_object_unref(ctxcanvas->last_stipple);
      g_object_unref(ctxcanvas->last_stipple_gc);
    }

    ctxcanvas->last_stipple = gdk_pixmap_new(ctxcanvas->wnd, w, h, 1);
    if (!ctxcanvas->last_stipple)
      return;
    
    ctxcanvas->last_stipple_gc = gdk_gc_new((GdkDrawable*)ctxcanvas->last_stipple);
    ctxcanvas->last_stipple_w = w;
    ctxcanvas->last_stipple_h = h;
  }

  for (y = 0; y < h; y++)
  {
    for (x = 0; x < w; x++)
    {
      GdkColor clr;

      if(data[y*w+x])
        clr.pixel = 1;
      else
        clr.pixel = 0;

      gdk_gc_set_foreground(ctxcanvas->last_stipple_gc, &clr);
      gdk_draw_point(ctxcanvas->last_stipple, ctxcanvas->last_stipple_gc, x, h-y-1);
    }
  }

  cdinteriorstyle(ctxcanvas, CD_STIPPLE);
}
Exemplo n.º 20
0
/*! \brief Records a new point for the stroke.
 *  \par Function Description
 *  This function adds the point (<B>x</B>,<B>y</B>) as a new point in
 *  the stroke.
 *
 * The footprint is updated and the new point is drawn on the drawing area.
 *
 *  \param [in] w_current The GschemToplevel object.
 *  \param [in] x        The X coord of the new point.
 *  \param [in] Y        The X coord of the new point.
 */
void
x_stroke_record (GschemToplevel *w_current, gint x, gint y)
{
  GschemPageView *view = gschem_toplevel_get_current_page_view (w_current);
  g_return_if_fail (view != NULL);

  GdkGC *view_gc = gschem_page_view_get_gc (view);

  g_assert (stroke_points != NULL);

  stroke_record (x, y);

  if (stroke_points->len < STROKE_MAX_POINTS) {
    StrokePoint point = { x, y };

    g_array_append_val (stroke_points, point);

    gdk_gc_set_foreground (view_gc, x_get_color (STROKE_COLOR));
    gdk_draw_point (gtk_widget_get_window (GTK_WIDGET(view)), view_gc, x, y);
  }

}
Exemplo n.º 21
0
Arquivo: gtkfb.c Projeto: sgh/aos
void ugui_putpixel(int x, int y, unsigned int color) {
	int dx,dy;
	GdkColor rgb;

	x += bound_x1;
	y += bound_y1;

	if (x > bound_x2 || y > bound_y2)
		return;

	gdk_threads_enter();
	rgb.red   = ((color >> 16) & 0xFF) * 0x101;
  rgb.green = ((color >>  8) & 0xFF) * 0x101;
  rgb.blue  = ((color >>  0) & 0xFF) * 0x101;


	gdk_gc_set_rgb_fg_color(drawing_area->style->fg_gc[GTK_WIDGET_STATE (drawing_area)], &rgb );

	for (dx = 0; dx<SCALE; dx++)
	for (dy = 0; dy<SCALE; dy++)
		gdk_draw_point(pixmap, drawing_area->style->fg_gc[GTK_WIDGET_STATE (drawing_area)], x*SCALE + dx, y*SCALE + dy);
	 
	gdk_threads_leave();
}
Exemplo n.º 22
0
void dessiner_pdv(pdv* pt_pdv_current, file_opener* donnees)
{
    GdkDrawable* cartew=donnees->carte->window;
            if(pt_pdv_current->affichage==1) // Vérifie si le plan de vol doit être affiché
            {
            position* loc_avion=malloc(sizeof(position));
//            Position_avion(donnees,pt_pdv_current,loc_avion);
            get_position_avion(loc_avion,pt_pdv_current,donnees->temps);
            loc_avion->y=conversion_lat(loc_avion->y,donnees)*donnees->ycarte;
            loc_avion->x=conversion_longitude(loc_avion->x,donnees)*donnees->xcarte;

        //  On change la couleur du tracé pour le carré et le nom de l'avion
            couleur(donnees->gc,donnees->c,donnees->couleur_avion);
            gdk_draw_rectangle(cartew,donnees->gc,TRUE,loc_avion->x-2,loc_avion->y-2,5,5);
            gdk_draw_string(cartew,donnees->font,donnees->gc,loc_avion->x+3,loc_avion->y-2,pt_pdv_current->nom);
            couleur(donnees->gc,donnees->c,10);


            int x1=-9,x2=0,y1=0,y2=0; // Variables de stockage des coordonnées pour les points de passage

            pt_pass * pt_pass_current = pt_pdv_current->pass_debut;

                if(x1==-9 && pt_pass_current->ptsuiv!=NULL) // Cas du premier point
                {

                    if(pt_pass_current->type_point==0) // Si le point est un aérodrome
                    {
                        aerodrome * pass_aerodrome = pt_pass_current->point;
                        //printf("\n AERODROME 1 \n");
                        x1=conversion_longitude(pass_aerodrome->longitude,donnees)* donnees->xcarte;
                        y1=conversion_lat(pass_aerodrome->latitude,donnees)* donnees->ycarte;

                        // Affichage de l'aérodrome
                        pass_aerodrome->affichage=1;
                        dessiner_aerodromes(pass_aerodrome,donnees);
                    }

                    if(pt_pass_current->type_point==1) // Si le point est une balise
                    {
                        balise * pass_balise = pt_pass_current->point;
                       // printf("\n BALISE 1 \n");
                        x1=conversion_longitude(pass_balise->longitude,donnees)* donnees->xcarte;
                        y1=conversion_lat(pass_balise->latitude,donnees)* donnees->ycarte;

                        // Affichage de la balise
                        pass_balise->affichage=1;
                        dessiner_balise(pass_balise,donnees);
                    }

                    if(pt_pass_current->type_point==2) // Si le point est une ptgpx
                    {
                        ptgpx * pass = pt_pass_current->point;
                       // printf("\n BALISE 1 \n");
                        x1=conversion_longitude(pass->longitude,donnees)* donnees->xcarte;
                        y1=conversion_lat(pass->latitude,donnees)* donnees->ycarte;

                        // Affichage de la balise
                        //gdk_draw_string(carte,font,gc, x1 + 2,y1 + 7, pass_balise->nom);
                        gdk_draw_point(cartew,donnees->gc, x1,y1);
                    }

                pt_pass_current = pt_pass_current->ptsuiv;

                }


                while(pt_pass_current->ptsuiv!=NULL) // Parcours de tous les autres points de passage
                {


                    if(pt_pass_current->type_point==0) // Si le point est un aérodrome
                    {
                    aerodrome * pass_aerodrome = pt_pass_current->point;
                   // printf("\n AERODROME \n");
                    x2=conversion_longitude(pass_aerodrome->longitude,donnees)* donnees->xcarte;
                    y2=conversion_lat(pass_aerodrome->latitude,donnees)* donnees->ycarte;

                    // Affichage de l'aerodrome
                    pass_aerodrome->affichage=1;
                    dessiner_aerodromes(pass_aerodrome,donnees);
                    }

                    if(pt_pass_current->type_point==1) // Si le point est une balise
                    {
                    balise * pass_balise = pt_pass_current->point;
                  //  printf("\n BALISE \n");

                    x2=conversion_longitude(pass_balise->longitude,donnees)* donnees->xcarte;
                    y2=conversion_lat(pass_balise->latitude,donnees)* donnees->ycarte;

                    // Affichage de la balise
                    pass_balise->affichage=1;
                    dessiner_balise(pass_balise,donnees);
                    }

                    if(pt_pass_current->type_point==2) // Si le point est un ptgpx
                    {
                    ptgpx * pass = pt_pass_current->point;

                    x2=conversion_longitude(pass->longitude,donnees)* donnees->xcarte;
                    y2=conversion_lat(pass->latitude,donnees)* donnees->ycarte;

                    // Affichage de la balise
                    int x=conversion_longitude(pass->longitude,donnees)* donnees->xcarte;
                    int y=conversion_lat(pass->latitude,donnees)* donnees->ycarte;
                    //gdk_draw_string(carte,font,gc, x + 2,y + 7, pass_balise->nom);
                    gdk_draw_point(cartew,donnees->gc, x,y);
                    }



//                  Une couleur différente par avion
                    couleur(donnees->gc,donnees->c,donnees->couleur_avion);

//                  Trace la ligne et remet la couleur normalement.
                    gdk_draw_line(cartew, donnees->gc, x1,y1,x2,y2);
                    couleur(donnees->gc,donnees->c,10);

                    // Le point 2 devient le point 1
                    x1=x2;
                    y1=y2;
                    pt_pass_current = pt_pass_current->ptsuiv;

                }

            free(loc_avion);
            }
}
Exemplo n.º 23
0
static void cl_draw_corner (GdkWindow *window, GtkWidget *widget, GtkStyle *style,
                     int x, int y, int width, int height,
                     CLRectangle *r, CLCornerSide corner)
{
	GdkColor    *color;
	GdkColor     aacolor; /* anti-aliasing color */
	GdkGCValues  values;
	GdkColor     tmp;
	GdkColor    *bgcolor;

	int x1;
	int y1;

	if (r->corners[corner] == CL_CORNER_NONE)
		return;
	
	color = cl_get_gradient_corner_color (r, corner);
	gdk_gc_get_values (r->bordergc, &values);

	if (color == NULL)
	{
		tmp = values.foreground;
		gdk_colormap_query_color (gtk_widget_get_colormap(widget), values.foreground.pixel, &tmp);
		color = &tmp;
	}

	bgcolor = get_parent_bgcolor(widget);

	if (bgcolor == NULL)
	{
		bgcolor = color;
	}

	blend (style->colormap, bgcolor, color, &aacolor, 70);

	if (r->corners[corner] == CL_CORNER_ROUND)
	{
		x1 = (corner == CL_CORNER_TOPLEFT ||
		      corner == CL_CORNER_BOTTOMLEFT) ? x+1 : x+width - 2;
		
		y1 = (corner == CL_CORNER_TOPLEFT ||
		      corner == CL_CORNER_TOPRIGHT) ? y+1 : y+height - 2;
		
		gdk_gc_set_foreground (r->bordergc, color);
		gdk_draw_point (window, r->bordergc, x1, y1);
		
		gdk_gc_set_foreground (r->bordergc, &aacolor);
		
		x1 = (corner == CL_CORNER_TOPLEFT ||
		      corner == CL_CORNER_BOTTOMLEFT) ? x+1 : x+width-2;

		y1 = (corner == CL_CORNER_TOPLEFT ||
		      corner == CL_CORNER_TOPRIGHT) ? y : y+height-1;		
		
		gdk_draw_point (window, r->bordergc, x1, y1);

		x1 = (corner == CL_CORNER_TOPLEFT ||
		      corner == CL_CORNER_BOTTOMLEFT) ? x : x+width-1;

		y1 = (corner == CL_CORNER_TOPLEFT ||
		      corner == CL_CORNER_TOPRIGHT) ? y+1 : y+height-2;

		gdk_draw_point (window, r->bordergc, x1, y1);
								
	}
	else if (r->corners[corner] == CL_CORNER_NARROW)
	{
		x1 = (corner == CL_CORNER_TOPLEFT ||
		      corner == CL_CORNER_BOTTOMLEFT) ? x : x+width-1;

		y1 = (corner == CL_CORNER_TOPLEFT ||
		      corner == CL_CORNER_TOPRIGHT) ? y : y+height-1;
				
		gdk_gc_set_foreground (r->bordergc, &aacolor);
		gdk_draw_point (window, r->bordergc, x1, y1);
 	}

	gdk_gc_set_foreground (r->bordergc, &values.foreground);
}
Exemplo n.º 24
0
static GtkWidget *
mnb_notification_gtk_create ()
{
  GtkWidget *widget = NULL;
  GtkWindow *window;
  GtkWidget *evbox;
  GdkPixbuf *pixbuf;

  img_normal = gtk_image_new_from_file (THEMEDIR
                                        "/notifiers/fscreen-notif-normal.png");

  if (img_normal)
    g_object_ref (img_normal);

  img_hover  = gtk_image_new_from_file (THEMEDIR
                                        "/notifiers/fscreen-notif-hover.png");

  if (img_hover)
    g_object_ref (img_hover);

  widget = gtk_window_new (GTK_WINDOW_POPUP);
  window = GTK_WINDOW (widget);

  pixbuf = gdk_pixbuf_new_from_file (THEMEDIR
                                     "/notifiers/fscreen-notif-normal.png",
                                     NULL);

  if (pixbuf)
    {
      gint width, height, rowstride, channels;
      guchar *pixels;
      gint x, y;

      GdkDrawable *mask;
      GdkGC *gc;

      rowstride = gdk_pixbuf_get_rowstride (pixbuf);
      pixels    = gdk_pixbuf_get_pixels (pixbuf);
      width     = gdk_pixbuf_get_width (pixbuf);
      height    = gdk_pixbuf_get_height (pixbuf);
      channels = gdk_pixbuf_get_n_channels (pixbuf);

      g_assert (channels == 4);

      mask = gdk_pixmap_new (NULL, width, height, 1);
      gc   = gdk_gc_new (mask);

      for (x = 0; x < width; ++x)
        for (y = 0; y < height; ++y)
          {
            GdkColor clr;
            guchar *p = pixels + y * rowstride + x * channels;

            if (p[3] == 0)
              clr.pixel = 0;
            else
              clr.pixel = 1;

            gdk_gc_set_foreground (gc, &clr);

            gdk_draw_point (mask, gc, x, y);
          }

      gtk_widget_shape_combine_mask (widget, mask, 0, 0);

      g_object_unref (mask);
      g_object_unref (pixbuf);
      g_object_unref (gc);
    }

  gtk_window_set_decorated (window, FALSE);
  gtk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_NOTIFICATION);
  gtk_window_set_resizable (window, FALSE);
  gtk_window_set_title (window, "mnb-notification-gtk");
  gtk_window_set_accept_focus (window, FALSE);

  gtk_window_move (window, 20, 20);

  evbox = gtk_event_box_new ();
  gtk_event_box_set_visible_window (GTK_EVENT_BOX (evbox), FALSE);
  gtk_event_box_set_above_child (GTK_EVENT_BOX (evbox), TRUE);

  if (!img_normal)
    {
      gtk_container_add (GTK_CONTAINER (evbox),
                         gtk_button_new_with_label ("Notifications"));
    }
  else
    {
      gtk_container_add (GTK_CONTAINER (evbox), img_normal);
    }

  gtk_container_add (GTK_CONTAINER (window), evbox);
  gtk_widget_show (evbox);

  g_signal_connect (evbox, "button-press-event",
                    G_CALLBACK(mnb_notification_gtk_click_cb),
                    NULL);

  if (img_normal && img_hover)
    {
      g_signal_connect (evbox, "enter-notify-event",
                        G_CALLBACK(mnb_notification_gtk_crossing_cb),
                        NULL);

      g_signal_connect (evbox, "leave-notify-event",
                        G_CALLBACK(mnb_notification_gtk_crossing_cb),
                        NULL);
    }

  return widget;
}
Exemplo n.º 25
0
void draw_grid(void)
{
    scope_disp_t *disp;
    double xscale, yscale;
    int xmajor, xminor, ymajor, yminor;
    int nx, ny, m;
    double fx, fy;
    int x, y;

    disp = &(ctrl_usr->disp);
    /* set color to draw */
    gdk_gc_set_foreground(disp->context, &(disp->color_grid));
    /* calculate scale factors */
    xscale = disp->width - 1.0;
    yscale = disp->height - 1.0;
    /* calculate grid spacings */
    xmajor = xscale * 0.1;
    if (xmajor >= 40) {
	xminor = 10;
    } else if (xmajor >= 20) {
	xminor = 5;
    } else {
	xminor = xmajor / 4;
    }
    ymajor = yscale * 0.1;
    if (ymajor >= 40) {
	yminor = 10;
    } else if (ymajor >= 20) {
	yminor = 5;
    } else {
	yminor = ymajor / 4;
    }
    /* draw the vertical lines */
    for (nx = 0; nx <= 10; nx++) {
	/* calc the major division x coordinate */
	fx = nx * 0.1;
	for (ny = 0; ny <= 10; ny++) {
	    /* calc the major division y coordinate */
	    fy = ny * 0.1;
	    /* draw the major division point */
	    x = fx * xscale;
	    y = fy * yscale;
	    gdk_draw_point(disp->win, disp->context, x, y);
	    /* draw minor divisions (vertical) */
	    if (ny < 10) {
		for (m = 1; m < yminor; m++) {
		    y = (((0.1 * m) / yminor) + fy) * yscale;
		    gdk_draw_point(disp->win, disp->context, x, y);
		}
	    }
	    /* draw minor divisions (horizontal) */
	    if (nx < 10) {
		y = fy * yscale;
		for (m = 1; m < xminor; m++) {
		    x = (((0.1 * m) / xminor) + fx) * xscale;
		    gdk_draw_point(disp->win, disp->context, x, y);
		}
	    }
	}
    }
}
Exemplo n.º 26
0
void
on_button_run_clicked                  (GtkButton       *button,
                                        gpointer         user_data)
{
	// guard
	if(point_list.empty()) return;

	svm_parameter param;
	int i,j;	

	// default values
	param.svm_type = C_SVC;
	param.kernel_type = RBF;
	param.degree = 3;
	param.gamma = 0;
	param.coef0 = 0;
	param.nu = 0.5;
	param.cache_size = 40;
	param.C = 1;
	param.eps = 1e-3;
	param.p = 0.1;
	param.shrinking = 1;
	param.nr_weight = 0;
	param.weight_label = NULL;
	param.weight = NULL;

	// parse options
	const char *p = gtk_entry_get_text(GTK_ENTRY(entry_option));

	while (1) {
		while (*p && *p != '-')
			p++;

		if (*p == '\0')
			break;

		p++;
		switch (*p++) {
			case 's':
				param.svm_type = atoi(p);
				break;
			case 't':
				param.kernel_type = atoi(p);
				break;
			case 'd':
				param.degree = atof(p);
				break;
			case 'g':
				param.gamma = atof(p);
				break;
			case 'r':
				param.coef0 = atof(p);
				break;
			case 'n':
				param.nu = atof(p);
				break;
			case 'm':
				param.cache_size = atof(p);
				break;
			case 'c':
				param.C = atof(p);
				break;
			case 'e':
				param.eps = atof(p);
				break;
			case 'p':
				param.p = atof(p);
				break;
			case 'h':
				param.shrinking = atoi(p);
				break;
			case 'w':
				++param.nr_weight;
				param.weight_label = (int *)realloc(param.weight_label,sizeof(int)*param.nr_weight);
				param.weight = (double *)realloc(param.weight,sizeof(double)*param.nr_weight);
				param.weight_label[param.nr_weight-1] = atoi(p);
				while(*p && !isspace(*p)) ++p;
				param.weight[param.nr_weight-1] = atof(p);
				break;
		}
	}
	
	// build problem
	svm_problem prob;

	prob.l = point_list.size();
	prob.y = new double[prob.l];

	if(param.svm_type == EPSILON_SVR ||
	   param.svm_type == NU_SVR)
	{
		if(param.gamma == 0) param.gamma = 1;
		svm_node *x_space = new svm_node[2 * prob.l];
		prob.x = new svm_node *[prob.l];

		i = 0;
		for (list <point>::iterator q = point_list.begin(); q != point_list.end(); q++, i++)
		{
			x_space[2 * i].index = 1;
			x_space[2 * i].value = q->x;
			x_space[2 * i + 1].index = -1;
			prob.x[i] = &x_space[2 * i];
			prob.y[i] = q->y;
		}

		// build model & classify
		svm_model *model = svm_train(&prob, &param);
		svm_node x[2];
		x[0].index = 1;
		x[1].index = -1;
		int *j = new int[XLEN];
	
		for (i = 0; i < XLEN; i++) 
		{
			x[0].value = (double) i / XLEN;
			j[i] = (int)(YLEN*svm_predict(model, x));
		}

		gdk_gc_set_foreground(gc,&colors[0]);
		gdk_draw_line(pixmap,gc,0,0,0,YLEN-1);
		gdk_draw_line(draw_main->window,gc,0,0,0,YLEN-1);
		
		int p = (int)(param.p * YLEN);
		for(i = 1; i < XLEN; i++)
		{
			gdk_gc_set_foreground(gc,&colors[0]);
			gdk_draw_line(pixmap,gc,i,0,i,YLEN-1);
			gdk_draw_line(draw_main->window,gc,i,0,i,YLEN-1);
			
			gdk_gc_set_foreground(gc,&colors[5]);
			gdk_draw_line(pixmap,gc,i-1,j[i-1],i,j[i]);
			gdk_draw_line(draw_main->window,gc,i-1,j[i-1],i,j[i]);
			
			if(param.svm_type == EPSILON_SVR)
			{
				gdk_gc_set_foreground(gc,&colors[2]);
				gdk_draw_line(pixmap,gc,i-1,j[i-1]+p,i,j[i]+p);
				gdk_draw_line(draw_main->window,gc,i-1,j[i-1]+p,i,j[i]+p);
			
				gdk_gc_set_foreground(gc,&colors[2]);
				gdk_draw_line(pixmap,gc,i-1,j[i-1]-p,i,j[i]-p);
				gdk_draw_line(draw_main->window,gc,i-1,j[i-1]-p,i,j[i]-p);
			}
		}

		svm_destroy_model(model);
		delete[] j;
		delete[] x_space;
		delete[] prob.x;
		delete[] prob.y;
	}
	else
	{
		if(param.gamma == 0) param.gamma = 0.5;
		svm_node *x_space = new svm_node[3 * prob.l];
		prob.x = new svm_node *[prob.l];

		i = 0;
		for (list <point>::iterator q = point_list.begin(); q != point_list.end(); q++, i++)
		{
			x_space[3 * i].index = 1;
			x_space[3 * i].value = q->x;
			x_space[3 * i + 1].index = 2;
			x_space[3 * i + 1].value = q->y;
			x_space[3 * i + 2].index = -1;
			prob.x[i] = &x_space[3 * i];
			prob.y[i] = q->value;
		}

		// build model & classify
		svm_model *model = svm_train(&prob, &param);
		svm_node x[3];
		x[0].index = 1;
		x[1].index = 2;
		x[2].index = -1;
	
		for (i = 0; i < XLEN; i++) 
			for (j = 0; j < YLEN; j++) {
				x[0].value = (double) i / XLEN;
				x[1].value = (double) j / YLEN;
				double d = svm_predict(model, x);
				gdk_gc_set_foreground(gc,&colors[(int)d]);
				gdk_draw_point(pixmap,gc,i,j);
				gdk_draw_point(draw_main->window,gc,i,j);
			}

		svm_destroy_model(model);
		delete[] x_space;
		delete[] prob.x;
		delete[] prob.y;
	}
	free(param.weight_label);
	free(param.weight);
	draw_all_points();
}
Exemplo n.º 27
0
static void 
gtk_plot_gdk_draw_string                        (GtkPlotPC *pc,
                                                gint tx, gint ty,
                                                gint angle,
                                                const GdkColor *fg,
                                                const GdkColor *bg,
                                                gboolean transparent,
                                                gint border,
                                                gint border_space,
                                                gint border_width,
                                                gint shadow_width,
                                                const gchar *font_name,
                                                gint font_height,
                                                GtkJustification just,
                                                const gchar *text)
{
  GdkBitmap *text_bitmap;
  GdkPixmap *text_pixmap;
  GdkBitmap *text_mask;
  GdkImage *image;
  GdkGC *gc, *bitmap_gc;
  GdkColormap *colormap;
  GdkColor white, black, mask_color;
  GList *family = NULL;
  gint y0;
  gint old_width, old_height;
  gboolean bold, italic;
  gint fontsize;
  gint ascent, descent;
  gint numf;
  gint xp = 0, yp = 0;
  gint width, height;
  gint x, y;
  gint i;
  GdkFont *font, *latin_font, *dfont;
  GtkPSFont *psfont, *base_psfont, *latin_psfont;
  gchar subs[2], insert_char;
  GdkWChar *aux, *wtext, *lastchar = NULL, *xaux;
  gchar num[4];

  if(!GTK_PLOT_GDK(pc)->drawable) return;
  if(!GTK_PLOT_GDK(pc)->window) return;
  if(!GTK_PLOT_GDK(pc)->gc) return;
  if(!text || strlen(text) == 0) return;

  colormap = gdk_colormap_get_system ();
  gc = GTK_PLOT_GDK(pc)->gc;

  if(!gc) return;

  gtk_plot_text_get_size(text, angle, font_name, font_height, &width, &height, &ascent, &descent);

  if(height == 0 || width == 0) return;

  old_width = width;
  old_height = height;
  if(angle == 90 || angle == 270)
    {
      old_width = height;
      old_height = width;
    }

  gtk_psfont_get_families(&family, &numf);
  font = gtk_psfont_get_gdkfont(font_name, font_height);
  base_psfont = psfont = gtk_psfont_get_font(font_name);
  italic = psfont->italic;
  bold = psfont->bold;
  fontsize = font_height;
  x = 0;
  y0 = y = ascent;

  if (psfont->i18n_latinfamily) {
    latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily, italic,
					     bold);
    latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname, fontsize);
  } else {
    latin_psfont = NULL;
    latin_font = NULL;
  }

  i = strlen(text) + 2;
  aux = wtext = g_malloc0(sizeof(GdkWChar) * i);
  gdk_mbstowcs(wtext, text, i - 1);

  /* initializing text bitmap - ajd */
  text_bitmap = gdk_pixmap_new(GTK_PLOT_GDK(pc)->window,
                              old_width, old_height, 1);
  bitmap_gc = gdk_gc_new(text_bitmap);
  gdk_color_white (colormap, &white);
  gdk_gc_set_foreground(bitmap_gc, &white);
  gdk_draw_rectangle(text_bitmap, bitmap_gc, TRUE,
                     0, 0, -1, -1);
  gdk_color_black (colormap, &black);
  gdk_gc_set_foreground(bitmap_gc, &black);

  while(aux && *aux != '\0' && *aux != '\n'){
   if(*aux == '\\'){
     aux++;
     switch(*aux){
       case '0': case '1': case '2': case '3':
       case '4': case '5': case '6': case '7': case '9':
           psfont = gtk_psfont_find_by_family((gchar *)g_list_nth_data(family, *aux-'0'), italic, bold);
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
           aux++;
           break;
       case '8': case 'g':
           psfont = gtk_psfont_find_by_family("Symbol", italic, bold);
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
           aux++;
           break;
       case 'B':
           bold = TRUE;
           psfont = gtk_psfont_find_by_family(psfont->family, italic, bold);
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
	   if (psfont->i18n_latinfamily) {
	     latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily,
						      italic, bold);
	     latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname,
						 fontsize);
	   }
           aux++;
           break;
       case 'x':
           xaux = aux + 1;
           for (i=0; i<3; i++){
            if (xaux[i] >= '0' && xaux[i] <= '9')
              num[i] = xaux[i];
            else
              break;
           }
           if (i < 3){
              aux++;
              break;
           }
           num[3] = '\0';
           insert_char = (gchar)atoi(num);
           subs[0] = insert_char;
           subs[1] = '\0';
	   /* \xNNN is always outputted with latin fonts. */
	   dfont = (psfont->i18n_latinfamily != NULL) ? latin_font : font;
           gdk_draw_string (text_bitmap, dfont,
                            bitmap_gc,
                            x, y,
                            subs);

           x += gdk_char_width(font, insert_char);
           aux += 4;
           lastchar = aux - 1;
           break;
       case 'i':
           italic = TRUE;
           psfont = gtk_psfont_find_by_family(psfont->family, italic, bold);
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
	   if (psfont->i18n_latinfamily) {
	     latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily,
						      italic, bold);
	     latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname,
						 fontsize);
	   }
           aux++;
           break;
       case 'S': case '^':
           fontsize = (int)((gdouble)fontsize * 0.6 + 0.5);
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
           y -= font->ascent;
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
	   if (psfont->i18n_latinfamily) {
	     latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily,
						      italic, bold);
	     latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname,
						 fontsize);
	   }
           aux++;
           break;
       case 's': case '_':
           fontsize = (int)((gdouble)fontsize * 0.6 + 0.5);
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
           y += font->descent;
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
	   if (psfont->i18n_latinfamily) {
	     latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily,
						      italic, bold);
	     latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname,
						 fontsize);
	   }
           aux++;
           break;
       case '+':
           fontsize += 3;
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
	   if (psfont->i18n_latinfamily) {
	     latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily,
						      italic, bold);
	     latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname,
						 fontsize);
	   }
           aux++;
           break;
       case '-':
           fontsize -= 3;
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
	   if (psfont->i18n_latinfamily) {
	     latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily,
						      italic, bold);
	     latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname,
						 fontsize);
	   }
           aux++;
           break;
       case 'N':
	   psfont = base_psfont;
           gdk_font_unref(font);
           fontsize = font_height;
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
           y = y0;
           italic = psfont->italic;
           bold = psfont->bold;
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
	   if (psfont->i18n_latinfamily) {
	     latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily,
						      italic, bold);
	     latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname,
						 fontsize);
	   }
           aux++;
           break;
       case 'b':
	   if (lastchar) {
	     gtk_psfont_get_char_size(psfont, font, latin_font, *lastchar, &i,
				    NULL, NULL);
	     x -= i;

	     if (lastchar == wtext)
	       lastchar = NULL;
	     else
	       lastchar--;
	   } else {
	     gtk_psfont_get_char_size(psfont, font, latin_font, 'X', &i, NULL,
				    NULL);
	     x -= i;
	   }
           aux++;
           break;
       default:
           if(aux && *aux != '\0' && *aux !='\n'){
	     x += drawstring(pc, text_bitmap, bitmap_gc, &black, &white, x, y,
			     psfont, font, latin_font, *aux);
	     lastchar = aux;
	     aux++;
	   }
	   break;
     }
   } else {
     if(aux && *aux != '\0' && *aux !='\n'){
       x += drawstring(pc, text_bitmap, bitmap_gc, &black, &white, x, y,
		       psfont, font, latin_font, *aux);
       lastchar = aux;
       aux++;
     }
   }
  }

  g_free(wtext);

  /* initializing clip mask bitmap - ajd */
  text_mask = gdk_pixmap_new(GTK_PLOT_GDK(pc)->window, width, height, 1);
  mask_color = white;
  mask_color.pixel = 0;
  gdk_gc_set_foreground(bitmap_gc, &mask_color);
  gdk_draw_rectangle(text_mask, bitmap_gc, TRUE, 0, 0, -1, -1);
  mask_color = black;
  mask_color.pixel = 1;
  gdk_gc_set_foreground(bitmap_gc, &mask_color);

  /* performing text rotation and saving it onto clip mask bitmap - ajd */
  image = gdk_image_get(text_bitmap, 0, 0, old_width, old_height);
  for(y = 0; y < old_height; y++)
      for(x = 0; x < old_width; x++)
         {
           if( black.pixel == gdk_image_get_pixel(image, x, y) ){
           switch(angle){
            case 0:
                xp = x;
                yp = y;
                break;
            case 90:
                xp = y;
                yp = old_width - x;
                break;
            case 180:
                xp = old_width - x;
                yp = old_height - y;
                break;
            case 270:
                xp = old_height - y;
                yp = x;
                break;
            }
            gdk_draw_point(text_mask, bitmap_gc, xp, yp);
           }
         }
  gdk_image_destroy(image);


  /* initializing text pixmap - ajd */
  text_pixmap = gdk_pixmap_new(GTK_PLOT_GDK(pc)->window, width, height, -1);
  gdk_gc_set_foreground(gc, (GdkColor *) bg);
  gdk_draw_rectangle(text_pixmap, gc, TRUE, 0, 0, -1, -1);
  gdk_gc_set_foreground(gc, (GdkColor *) fg);

  /* copying clip mask bitmap onto text pixmap - ajd */
  gdk_gc_set_clip_mask(gc, text_mask);
  gdk_gc_set_clip_origin(gc, 0, 0);
  gdk_draw_rectangle(text_pixmap, gc, TRUE, 0, 0, -1, -1);
  gdk_gc_set_clip_mask(gc, NULL);

  gtk_plot_text_get_area(text, angle, just, font_name, font_height,
                         &x, &y, &width, &height);
  tx += x;
  ty += y;

  if(transparent){
    gdk_gc_set_clip_mask (gc, text_mask);
    gdk_gc_set_clip_origin (gc, tx, ty);
  } else {
    gdk_gc_set_foreground(gc, (GdkColor *) bg);
    gtk_plot_pc_draw_rectangle(pc,
   		         TRUE, 
                         tx - border_space, ty - border_space, 
                         width + 2*border_space, height + 2*border_space);
  }

  gdk_draw_pixmap(GTK_PLOT_GDK(pc)->drawable, gc,
                  text_pixmap, 0, 0,
                  tx, ty, -1, -1);
  gdk_gc_set_clip_mask(gc, NULL);

  gdk_pixmap_unref(text_pixmap);
  gdk_bitmap_unref(text_mask);
  gdk_font_unref(font);
  if (latin_font) gdk_font_unref(latin_font);
  gdk_gc_unref(bitmap_gc);
  gdk_pixmap_unref(text_bitmap);


/* border */

  gdk_gc_set_foreground(gc, (GdkColor *) fg);
  gtk_plot_pc_set_dash(pc, 0, NULL, 0);
  gtk_plot_pc_set_lineattr(pc, border_width, 0, 0, 0);
  switch(border){
    case GTK_PLOT_BORDER_SHADOW: 
      gtk_plot_pc_draw_rectangle(pc,
   		         TRUE, 
                         tx - border_space + shadow_width, 
                         ty + height + border_space, 
                         width + 2 * border_space, shadow_width);
      gtk_plot_pc_draw_rectangle(pc,
   		         TRUE, 
                         tx + width + border_space, 
                         ty - border_space + shadow_width, 
                         shadow_width, height + 2 * border_space);
    case GTK_PLOT_BORDER_LINE: 
      gtk_plot_pc_draw_rectangle(pc,
   		         FALSE, 
                         tx - border_space, ty - border_space, 
                         width + 2*border_space, height + 2*border_space);
    case GTK_PLOT_BORDER_NONE: 
    default:
	break; 
  }

  return;
}
Exemplo n.º 28
0
void draw_picture(GdkDrawable *gd)
{
  int i;
  double WIDTH,HEIGHT,OriginX,OriginY,ScaleX,ScaleY;

  double Max_X,Min_X,Max_Y,Min_Y;
  double r;
  gT_M31 p;
  gT_M33 m1,m2,m3,m4;
  
  Max_X=50;
  Min_X=-50;
  Max_Y=160;
  Min_Y=-10;
  
  // 論理座標系の描画領域
  WIDTH=Max_X-Min_X;
  HEIGHT=Max_Y-Min_Y;
  
  // 論理座標系の中心座標
  OriginX=WIDTH/2.0-(Max_X+Min_X)/2;
  OriginY=HEIGHT/2.0+(Max_Y+Min_Y)/2;
  
  // スケールファクタの計算
  ScaleX=(double)PICT_WIDTH/WIDTH,
  ScaleY=(double)PICT_HEIGHT/HEIGHT;

  // 変換行列の設定
  m1=gM33Set(0.2,-0.26,0,0.23,0.22,24,0,0,1);
  m2=gM33Set(-0.15,0.28,0,0.26,0.24,6.6,0,0,1);
  m3=gM33Set(0,0,0,0,0.16,0,0,0,1);
  m4=gM33Set(0.85,0.04,0,-0.04,0.85,24,0,0,1);
  
  // 初期値の設定
  p=gM31Set(0,0,1);
  
  /* 背景を白に設定 */
  SetColor( 0xffff, 0xffff, 0xffff);
  gdk_gc_set_line_attributes( g_gc, 1, GDK_LINE_SOLID,
           GDK_CAP_BUTT, GDK_JOIN_ROUND );
  gdk_draw_rectangle(gd,g_gc,TRUE,0,0,300,510);

  // 点の色を青に設定
  SetColor( 0x0000, 0x0000, 0xffff);
  gdk_gc_set_line_attributes( g_gc, 1, GDK_LINE_SOLID,
           GDK_CAP_BUTT, GDK_JOIN_ROUND );

  // 乱数の初期化
  srand(time(NULL));

  // 乱数の値によって変換行列を選択
  for(i=0;i<MAX;i++){

    r=rand()/(double)RAND_MAX;

    if(0<=r&&r<0.065)
      p=gM33xM31(m1,p);
    if(0.065<=r&&r<0.13)
      p=gM33xM31(m2,p);
    if(0.13<=r&&r<0.150)
      p=gM33xM31(m3,p);
    if(0.150<r&&r<=1)
      p=gM33xM31(m4,p);

    // 点の描画
    gdk_draw_point(gd,g_gc,(OriginX+p.v[0])*ScaleX,(OriginY-p.v[1])*ScaleY);
  }
}
Exemplo n.º 29
0
wxBitmap wxBitmap::Rescale( int clipx, int clipy, int clipwidth, int clipheight, int newx, int newy )
{
    wxCHECK_MSG( Ok(), wxNullBitmap, wxT("invalid bitmap") );

    if (newy==M_BMPDATA->m_width && newy==M_BMPDATA->m_height)
        return *this;
    
    int width = wxMax(newx, 1);
    int height = wxMax(newy, 1);
    width = wxMin(width, clipwidth);
    height = wxMin(height, clipheight);
        
    wxBitmap bmp;

#ifdef __WXGTK20__
    if (HasPixbuf())
    {
        bmp.SetWidth(width);
        bmp.SetHeight(height);
        bmp.SetDepth(GetDepth());
        bmp.SetPixbuf(gdk_pixbuf_new(GDK_COLORSPACE_RGB,
                                     gdk_pixbuf_get_has_alpha(GetPixbuf()),
                                     8, width, height));
        gdk_pixbuf_scale(GetPixbuf(), bmp.GetPixbuf(),
                         0, 0, width, height,
                         clipx, clipy, 
                         (double)newx/GetWidth(), (double)newy/GetHeight(),
                         GDK_INTERP_BILINEAR);
    }
    else
#endif // __WXGTK20__
    {
        GdkImage *img = (GdkImage*) NULL;
        if (GetPixmap())
            img = gdk_image_get( GetPixmap(), 0, 0, GetWidth(), GetHeight() );
        else if (GetBitmap())
            img = gdk_image_get( GetBitmap(), 0, 0, GetWidth(), GetHeight() );
        else
            wxFAIL_MSG( wxT("Ill-formed bitmap") );

        wxCHECK_MSG( img, wxNullBitmap, wxT("couldn't create image") );

        int bpp = -1;

        
        GdkGC *gc = NULL;
        GdkPixmap *dstpix = NULL;
        if (GetPixmap())
        {
            GdkVisual *visual = gdk_window_get_visual( GetPixmap() );
            if (visual == NULL)
                visual = wxTheApp->GetGdkVisual();

            bpp = visual->depth;
            bmp = wxBitmap(width,height,bpp);
            dstpix = bmp.GetPixmap();
            gc = gdk_gc_new( dstpix );
        }

        char *dst = NULL;
        long dstbyteperline = 0;
        
        if (GetBitmap())
        {
            bpp = 1;
            dstbyteperline = width/8*M_BMPDATA->m_bpp;
            if (width*M_BMPDATA->m_bpp % 8 != 0)
                dstbyteperline++;
            dst = (char*) malloc(dstbyteperline*height);
        }
                 
        // be careful to use the right scaling factor
        float scx = (float)M_BMPDATA->m_width/(float)newx;
        float scy = (float)M_BMPDATA->m_height/(float)newy;
        // prepare accel-tables
        int *tablex = (int *)calloc(width,sizeof(int));
        int *tabley = (int *)calloc(height,sizeof(int));

        // accel table filled with clipped values
        for (int x = 0; x < width; x++)
            tablex[x] = (int) (scx * (x+clipx));
        for (int y = 0; y < height; y++)
            tabley[y] = (int) (scy * (y+clipy));

        // Main rescaling routine starts here
        for (int h = 0; h < height; h++)
        {
            char outbyte = 0;
            int old_x = -1;
            guint32 old_pixval = 0;

            for (int w = 0; w < width; w++)
            {
                guint32 pixval;
                int x = tablex[w];
                if (x == old_x)
                    pixval = old_pixval;
                else
                {
                    pixval = gdk_image_get_pixel( img, x, tabley[h] );
                    old_pixval = pixval;
                    old_x = x;
                }
                    
                if (bpp == 1)
                {
                    if (!pixval)
                    {
                        char bit=1;
                        char shift = bit << w % 8;
                        outbyte |= shift;
                    }
                    
                    if ((w+1)%8==0)
                    {
                        dst[h*dstbyteperline+w/8] = outbyte;
                        outbyte = 0;
                    }
                }
                else
                {
                    GdkColor col;
                    col.pixel = pixval;
                    gdk_gc_set_foreground( gc, &col );
                    gdk_draw_point( dstpix, gc, w, h);
                }
            }
        
            // do not forget the last byte
            if ((bpp == 1) && (width % 8 != 0))
                dst[h*dstbyteperline+width/8] = outbyte;
        }
        
        gdk_image_destroy( img );
        if (gc) gdk_gc_unref( gc );

        if (bpp == 1)
        {
            bmp = wxBitmap( (const char *)dst, width, height, 1 );
            free( dst );
        }
        
        if (GetMask())
        {
            dstbyteperline = width/8;
            if (width % 8 != 0)
                dstbyteperline++;
            dst = (char*) malloc(dstbyteperline*height);
            img = gdk_image_get( GetMask()->GetBitmap(), 0, 0, GetWidth(), GetHeight() );

            for (int h = 0; h < height; h++)
            {
                char outbyte = 0;
                int old_x = -1;
                guint32 old_pixval = 0;
        
                for (int w = 0; w < width; w++)
                {
                    guint32 pixval;
                    int x = tablex[w];
                    if (x == old_x)
                        pixval = old_pixval;
                    else
                    {
                        pixval = gdk_image_get_pixel( img, x, tabley[h] );
                        old_pixval = pixval;
                        old_x = x;
                    }
                    
                    if (pixval)
                    {
                        char bit=1;
                        char shift = bit << w % 8;
                        outbyte |= shift;
                    }
                    
                    if ((w+1)%8 == 0)
                    {
                        dst[h*dstbyteperline+w/8] = outbyte;
                        outbyte = 0;
                    }
                }
            
                // do not forget the last byte
                if (width % 8 != 0)
                    dst[h*dstbyteperline+width/8] = outbyte;
            }
            wxMask* mask = new wxMask;
            mask->m_bitmap = gdk_bitmap_create_from_data( wxGetRootWindow()->window, (gchar *) dst, width, height );
            bmp.SetMask(mask);

            free( dst );
            gdk_image_destroy( img );
        }

        free( tablex );
        free( tabley );
    }
    
    return bmp; 
}
Exemplo n.º 30
0
static void _mt_draw_point(MT_WINDOW *win, MT_GC *gc, int x, int y)
{
   _set_clipping(gc);
   gdk_draw_point((GdkWindow *)win, ((MT_GTK_GC *)gc)->gc, x, y);
   _unset_clipping(gc);
}