Exemplo n.º 1
0
static int
use_gc (hidGC gc)
{

    if (gc->me_pointer != &ghid_hid)
    {
        fprintf (stderr, "Fatal: GC from another HID passed to GTK HID\n");
        abort ();
    }

    if (!gport->pixmap)
        return 0;
    if (!gc->gc)
    {
        gc->gc = gdk_gc_new (gport->top_window->window);
        ghid_set_color (gc, gc->colorname);
        ghid_set_line_width (gc, gc->width);
        ghid_set_line_cap (gc, (EndCapStyle)gc->cap);
        ghid_set_draw_xor (gc, gc->xor_mask);
    }
    if (gc->mask_seq != mask_seq)
    {
        if (mask_seq)
            gdk_gc_set_clip_mask (gc->gc, gport->mask);
        else
            gdk_gc_set_clip_mask (gc->gc, NULL);
        gc->mask_seq = mask_seq;
    }
    gport->u_gc = WHICH_GC (gc);
    return 1;
}
Exemplo n.º 2
0
/**************************************************************************
...
**************************************************************************/
void pixmap_put_overlay_tile(GdkDrawable *pixmap,
			     int canvas_x, int canvas_y,
			     struct sprite *ssprite)
{
  if (!ssprite) {
    return;
  }

  if (ssprite->pixmap) {
    gdk_gc_set_clip_origin(civ_gc, canvas_x, canvas_y);
    gdk_gc_set_clip_mask(civ_gc, ssprite->mask);

    gdk_draw_drawable(pixmap, civ_gc, ssprite->pixmap,
		      0, 0,
		      canvas_x, canvas_y,
		      ssprite->width, ssprite->height);
    gdk_gc_set_clip_mask(civ_gc, NULL);
  } else {
    gdk_draw_pixbuf(pixmap, civ_gc, ssprite->pixbuf,
		    0, 0,
		  canvas_x, canvas_y,
		  ssprite->width, ssprite->height,
		  GDK_RGB_DITHER_NONE, 0, 0);
  }
}
Exemplo n.º 3
0
  /* Push krell pixmaps through their stencils onto a Panel expose pixmap
  */
static void
push_krell_pixmaps(GkrellmPanel *p)
	{
	GList			*list;
	GkrellmKrell	*k;
	GkrellmDrawrec	*dr;
	gboolean		restore_clip_mask   = FALSE,
					restore_clip_origin = FALSE;

	if (!p)
		return;
	for (list = p->krell_list; list; list = list->next)
		{
		k = (GkrellmKrell *) list->data;
		gdk_gc_set_clip_mask(_GK.text_GC, k->stencil);
		if (k->y0 != 0 || restore_clip_origin)
			{
			gdk_gc_set_clip_origin(_GK.text_GC, 0, k->y0);
			restore_clip_origin = TRUE;
			}
		dr = &k->draw;
		gdk_draw_drawable(p->pixmap, _GK.text_GC, k->pixmap,
					dr->x_src, dr->y_src, dr->x_dst, dr->y_dst, dr->w, dr->h);
		restore_clip_mask = TRUE;
		}
	if (restore_clip_mask)
		gdk_gc_set_clip_mask(_GK.text_GC, NULL);
	if (restore_clip_origin)
		gdk_gc_set_clip_origin(_GK.text_GC, 0, 0);
	}
Exemplo n.º 4
0
/**************************************************************************
Only used for isometric view.
**************************************************************************/
void pixmap_put_overlay_tile_draw(GdkDrawable *pixmap,
				  int canvas_x, int canvas_y,
				  struct sprite *ssprite,
				  bool fog)
{
  if (!ssprite) {
    return;
  }

  if (fog && gui_gtk2_better_fog
      && ((ssprite->pixmap && !ssprite->pixmap_fogged)
	  || (!ssprite->pixmap && !ssprite->pixbuf_fogged))) {
    fog_sprite(ssprite);
    if ((ssprite->pixmap && !ssprite->pixmap_fogged)
        || (!ssprite->pixmap && !ssprite->pixbuf_fogged)) {
      log_normal(_("Better fog will only work in truecolor. Disabling it"));
      gui_gtk2_better_fog = FALSE;
    }
  }

  if (fog && gui_gtk2_better_fog) {
    if (ssprite->pixmap) {
      if (ssprite->mask) {
	gdk_gc_set_clip_origin(civ_gc, canvas_x, canvas_y);
	gdk_gc_set_clip_mask(civ_gc, ssprite->mask);
      }
      gdk_draw_drawable(pixmap, civ_gc,
			ssprite->pixmap_fogged,
			0, 0,
			canvas_x, canvas_y,
			ssprite->width, ssprite->height);
      gdk_gc_set_clip_mask(civ_gc, NULL);
    } else {
      gdk_draw_pixbuf(pixmap, civ_gc, ssprite->pixbuf_fogged,
		      0, 0, canvas_x, canvas_y, 
		      ssprite->width, ssprite->height,
		      GDK_RGB_DITHER_NONE, 0, 0);
    }
    return;
  }

  pixmap_put_sprite(pixmap, canvas_x, canvas_y, ssprite,
		    0, 0, ssprite->width, ssprite->height);

  /* I imagine this could be done more efficiently. Some pixels We first
     draw from the sprite, and then draw black afterwards. It would be much
     faster to just draw every second pixel black in the first place. */
  if (fog) {
    gdk_gc_set_clip_origin(fill_tile_gc, canvas_x, canvas_y);
    gdk_gc_set_clip_mask(fill_tile_gc, sprite_get_mask(ssprite));
    gdk_gc_set_foreground(fill_tile_gc,
			  &get_color(tileset, COLOR_MAPVIEW_UNKNOWN)->color);
    gdk_gc_set_ts_origin(fill_tile_gc, canvas_x, canvas_y);
    gdk_gc_set_stipple(fill_tile_gc, black50);

    gdk_draw_rectangle(pixmap, fill_tile_gc, TRUE,
		       canvas_x, canvas_y, ssprite->width, ssprite->height);
    gdk_gc_set_clip_mask(fill_tile_gc, NULL);
  }
}
Exemplo n.º 5
0
void ensure_buddy_pix (GtkWidget *window, int n) {
  int width, height;
  GdkGC *white_gc;
  int pri;
  int sec;

  if (!buddy_pix[1].pix)	/* not initialized */
    return;

  if (n < 0 || n > 9 || buddy_pix[n].pix)
    return;

  sec = ((n & 0x04) != 0)? 0x04 : 0x02;
  pri = n & ~sec;

  ensure_buddy_pix (window, pri);

  if (!pri || !sec)
    return;

  if (!GTK_WIDGET_REALIZED (window))
    gtk_widget_realize (window);

  gdk_window_get_size (buddy_pix[1].pix, &width, &height);

  buddy_pix[n].pix = gdk_pixmap_new (window->window, width, height, -1);
  buddy_pix[n].mask = gdk_pixmap_new (window->window, width, height, 1);

  white_gc = window->style->white_gc;

  if (!masks_gc) {
    masks_gc = gdk_gc_new (buddy_pix[n].mask);
    gdk_gc_set_exposures (masks_gc, FALSE);
  }

  gdk_gc_set_foreground (masks_gc, &window->style->white);

  gdk_draw_pixmap (buddy_pix[n].pix, white_gc, buddy_pix[pri].pix,
                                                   0, 0, 0, 0, width, height);
  gdk_draw_pixmap (buddy_pix[n].mask, masks_gc, buddy_pix[pri].mask,
                                                   0, 0, 0, 0, width, height);

  gdk_gc_set_clip_mask (white_gc, buddy_pix[sec].mask);
  gdk_draw_pixmap (buddy_pix[n].pix, white_gc, buddy_pix[sec].pix,
                                                   0, 0, 0, 0, width, height);
  gdk_gc_set_clip_mask (white_gc, NULL);

  gdk_gc_set_clip_mask (masks_gc, buddy_pix[sec].mask);
  gdk_draw_rectangle (buddy_pix[n].mask, masks_gc, TRUE, 0, 0, width, height);
  gdk_gc_set_clip_mask (masks_gc, NULL);
}
Exemplo n.º 6
0
static int
use_gc (hidGC gc)
{
  render_priv *priv = gport->render_priv;
  GdkWindow *window = gtk_widget_get_window (gport->top_window);

  if (gc->me_pointer != &ghid_hid)
    {
      fprintf (stderr, "Fatal: GC from another HID passed to GTK HID\n");
      abort ();
    }

  if (!gport->pixmap)
    return 0;
  if (!gc->gc)
    {
      gc->gc = gdk_gc_new (window);
      ghid_set_color (gc, gc->colorname);
      ghid_set_line_width (gc, gc->width);
      ghid_set_line_cap (gc, (EndCapStyle)gc->cap);
      ghid_set_draw_xor (gc, gc->xor_mask);
      gdk_gc_set_clip_origin (gc->gc, 0, 0);
    }
  if (gc->mask_seq != mask_seq)
    {
      if (mask_seq)
	gdk_gc_set_clip_mask (gc->gc, gport->mask);
      else
	set_clip (priv, gc->gc);
      gc->mask_seq = mask_seq;
    }
  priv->u_gc = WHICH_GC (gc);
  return 1;
}
Exemplo n.º 7
0
void create_server_pixmap (GtkWidget *window, struct pixmap *stype, 
                                   int n, GdkPixmap **pix, GdkBitmap **mask) {
  GdkGC *white_gc;
  int hb, wb, hs, ws;

  if (!GTK_WIDGET_REALIZED (window))
    gtk_widget_realize (window);

  gdk_window_get_size (buddy_pix[1].pix, &wb, &hb);
  gdk_window_get_size (stype->pix, &ws, &hs);

  *pix  = gdk_pixmap_new (window->window, wb + ws, MAX (hs, hb), -1);
  *mask = gdk_pixmap_new (window->window, wb + ws, MAX (hs, hb), 1);

  white_gc = window->style->base_gc[GTK_STATE_NORMAL];

  if (!masks_gc) {
    masks_gc = gdk_gc_new (*mask);
    gdk_gc_set_exposures (masks_gc, FALSE);
  }

  mask_pattern.pixel = 0;
  gdk_gc_set_foreground (masks_gc, &mask_pattern);
  gdk_draw_rectangle (*mask, masks_gc, TRUE, 0, 0, -1, -1);

  mask_pattern.pixel = 1;
  gdk_gc_set_foreground (masks_gc, &mask_pattern);

  if (n) {
    ensure_buddy_pix (window, n);

    gdk_gc_set_clip_origin (white_gc, 0, 0);
    gdk_gc_set_clip_mask (white_gc, buddy_pix[n].mask);
    gdk_draw_pixmap (*pix, white_gc, buddy_pix[n].pix, 0, 0, 0, 0, wb, hb);

    gdk_draw_pixmap (*mask, masks_gc, buddy_pix[n].mask, 0, 0, 0, 0, wb, hb);
  }

  gdk_gc_set_clip_origin (white_gc, wb, 0);
  gdk_gc_set_clip_mask (white_gc, stype->mask);
  gdk_draw_pixmap (*pix, white_gc, stype->pix, 0, 0, wb, 0, ws, hs);

  gdk_draw_pixmap (*mask, masks_gc, stype->mask, 0, 0, wb, 0, ws, hs);

  gdk_gc_set_clip_origin (white_gc, 0, 0);
  gdk_gc_set_clip_mask (white_gc, NULL);
}
Exemplo n.º 8
0
/* {EV_PIXMAP_IMP}.set_size */
void F1202_17204 (EIF_REFERENCE Current, EIF_INTEGER_32 arg1, EIF_INTEGER_32 arg2)
{
	GTCX
	EIF_POINTER loc1 = (EIF_POINTER) 0;
	EIF_POINTER loc2 = (EIF_POINTER) 0;
	EIF_INTEGER_32 loc3 = (EIF_INTEGER_32) 0;
	EIF_INTEGER_32 loc4 = (EIF_INTEGER_32) 0;
	EIF_POINTER loc5 = (EIF_POINTER) 0;
	EIF_POINTER loc6 = (EIF_POINTER) 0;
	EIF_POINTER loc7 = (EIF_POINTER) 0;
	EIF_POINTER tp1;
	EIF_INTEGER_32 ti4_1;
	RTLD;
	
	RTLI(1);
	RTLR(0,Current);
	
	RTGC;
	loc3 = F1202_17199(Current);
	loc4 = F1202_17200(Current);
	if ((EIF_BOOLEAN) ((EIF_BOOLEAN)(loc3 != arg1) || (EIF_BOOLEAN)(loc4 != arg2))) {
		tp1 = *(EIF_POINTER *)(Current+ _PTROFF_46_11_12_3_0_5_);
		loc1 = (EIF_POINTER) gdk_pixmap_ref((GdkPixmap*) tp1);
		if ((EIF_BOOLEAN)(*(EIF_POINTER *)(Current+ _PTROFF_46_11_12_3_0_4_) != loc7)) {
			tp1 = *(EIF_POINTER *)(Current+ _PTROFF_46_11_12_3_0_4_);
			loc2 = (EIF_POINTER) gdk_pixmap_ref((GdkPixmap*) tp1);
		}
		tp1 = (EIF_POINTER) NULL;
		ti4_1 = *(EIF_INTEGER_32 *)(RTCV(RTOSCF(14148,F1079_14148,(Current)))+ _LNGOFF_49_16_0_19_);
		tp1 = (EIF_POINTER) gdk_pixmap_new((GdkWindow*) tp1, (gint) arg1, (gint) arg2, (gint) ti4_1);
		*(EIF_POINTER *)(Current+ _PTROFF_46_11_12_3_0_5_) = (EIF_POINTER) tp1;
		F1198_17038(Current, ((EIF_INTEGER_32) 0L), ((EIF_INTEGER_32) 0L), arg1, arg2);
		tp1 = *(EIF_POINTER *)(Current+ _PTROFF_46_11_12_3_0_5_);
		loc5 = (EIF_POINTER) gdk_gc_new((GdkWindow*) tp1);
		gdk_gc_set_clip_mask((GdkGC*) loc5, (GdkBitmap*) loc2);
		gdk_gc_set_clip_origin((GdkGC*) loc5, (gint) ((EIF_INTEGER_32) 0L), (gint) ((EIF_INTEGER_32) 0L));
		tp1 = *(EIF_POINTER *)(Current+ _PTROFF_46_11_12_3_0_5_);
		gdk_draw_drawable((GdkDrawable*) tp1, (GdkGC*) loc5, (GdkDrawable*) loc1, (gint) ((EIF_INTEGER_32) 0L), (gint) ((EIF_INTEGER_32) 0L), (gint) ((EIF_INTEGER_32) 0L), (gint) ((EIF_INTEGER_32) 0L), (gint) loc3, (gint) loc4);
		gdk_gc_unref((GdkGC*) loc5);
		gdk_pixmap_unref((GdkPixmap*) loc1);
		if ((EIF_BOOLEAN)(loc2 != loc7)) {
			tp1 = (EIF_POINTER) NULL;
			tp1 = (EIF_POINTER) gdk_pixmap_new((GdkWindow*) tp1, (gint) arg1, (gint) arg2, (gint) ((EIF_INTEGER_32) 1L));
			*(EIF_POINTER *)(Current+ _PTROFF_46_11_12_3_0_4_) = (EIF_POINTER) tp1;
			tp1 = *(EIF_POINTER *)(Current+ _PTROFF_46_11_12_3_0_4_);
			loc6 = (EIF_POINTER) gdk_gc_new((GdkWindow*) tp1);
			tp1 = RTOSCF(17072,F1198_17072,(Current));
			gdk_gc_set_foreground((GdkGC*) loc6, (GdkColor*) tp1);
			tp1 = *(EIF_POINTER *)(Current+ _PTROFF_46_11_12_3_0_4_);
			gdk_draw_rectangle((GdkDrawable*) tp1, (GdkGC*) loc6, (gint) ((EIF_INTEGER_32) 1L), (gint) ((EIF_INTEGER_32) 0L), (gint) ((EIF_INTEGER_32) 0L), (gint) arg1, (gint) arg2);
			tp1 = *(EIF_POINTER *)(Current+ _PTROFF_46_11_12_3_0_4_);
			gdk_draw_drawable((GdkDrawable*) tp1, (GdkGC*) loc6, (GdkDrawable*) loc2, (gint) ((EIF_INTEGER_32) 0L), (gint) ((EIF_INTEGER_32) 0L), (gint) ((EIF_INTEGER_32) 0L), (gint) ((EIF_INTEGER_32) 0L), (gint) loc3, (gint) loc4);
			gdk_gc_unref((GdkGC*) loc6);
			gdk_pixmap_unref((GdkPixmap*) loc2);
		}
		F1202_17215(Current, *(EIF_POINTER *)(Current+ _PTROFF_46_11_12_3_0_5_), *(EIF_POINTER *)(Current+ _PTROFF_46_11_12_3_0_4_));
	}
	RTLE;
}
Exemplo n.º 9
0
void DrawPixmap(GdkWindow* window, GdkGC* gc,
			 gint dstx, gint dsty, GdkPixmap* pixmap, GdkBitmap* mask)
{
	gint map_w, map_h;

	gdk_window_get_size(pixmap, &map_w, &map_h);

	gdk_gc_set_clip_mask(gc, mask);
	gdk_gc_set_clip_origin(gc, dstx, dsty);

	gdk_draw_pixmap(window, gc, pixmap,
					0,0,			// srcx, srcy
					dstx, dsty,
					map_w, map_h);

	gdk_gc_set_clip_mask(gc, NULL);
}
Exemplo n.º 10
0
/**************************************************************************
  Place part of a (possibly masked) sprite on a pixmap.
**************************************************************************/
static void pixmap_put_sprite(GdkDrawable *pixmap,
			      int pixmap_x, int pixmap_y,
			      struct sprite *ssprite,
			      int offset_x, int offset_y,
			      int width, int height)
{
#ifdef DEBUG
  static int sprites = 0, pixbufs = 0;
#endif

  if (ssprite->pixmap) {
    if (ssprite->mask) {
      gdk_gc_set_clip_origin(civ_gc, pixmap_x, pixmap_y);
      gdk_gc_set_clip_mask(civ_gc, ssprite->mask);
    }

    gdk_draw_drawable(pixmap, civ_gc, ssprite->pixmap,
		      offset_x, offset_y,
		      pixmap_x + offset_x, pixmap_y + offset_y,
		      MIN(width, MAX(0, ssprite->width - offset_x)),
		      MIN(height, MAX(0, ssprite->height - offset_y)));

    gdk_gc_set_clip_mask(civ_gc, NULL);
  } else {
    gdk_draw_pixbuf(pixmap, civ_gc, ssprite->pixbuf,
		    offset_x, offset_y,
		    pixmap_x + offset_x, pixmap_y + offset_y,
		    MIN(width, MAX(0, ssprite->width - offset_x)),
		    MIN(height, MAX(0, ssprite->height - offset_y)),
		    GDK_RGB_DITHER_NONE, 0, 0);
#ifdef DEBUG
    pixbufs++;
#endif
  }

#ifdef DEBUG
  sprites++;
  if (sprites % 1000 == 0) {
    freelog(LOG_DEBUG, "%5d / %5d pixbufs = %d%%",
	    pixbufs, sprites, 100 * pixbufs / sprites);
  }
#endif
}
Exemplo n.º 11
0
/** \brief concatenate two pixmaps
 *
 * horizontal concatenation
 * @param window
 * @param dest destination pixmap
 * @param s1 first pixmap
 * @param s2 second pixmap
 * @returns dest for convenience
 */
struct pixmap* cat_pixmaps (GtkWidget *window, struct pixmap *dest, struct pixmap* s1, struct pixmap* s2)
{
  GdkGC *white_gc;
  int h1, w1, h2, w2;

  if (!GTK_WIDGET_REALIZED (window))
    gtk_widget_realize (window);

  gdk_window_get_size (s1->pix, &w1, &h1);
  gdk_window_get_size (s2->pix, &w2, &h2);

  dest->pix  = gdk_pixmap_new (window->window, w1 + w2, MAX (h1, h2), -1);
  dest->mask = gdk_pixmap_new (window->window, w1 + w2, MAX (h1, h2), 1);

  white_gc = window->style->base_gc[GTK_STATE_NORMAL];

  if (!masks_gc) {
    masks_gc = gdk_gc_new (dest->mask);
    gdk_gc_set_exposures (masks_gc, FALSE);
  }

  mask_pattern.pixel = 0;
  gdk_gc_set_foreground (masks_gc, &mask_pattern);
  gdk_draw_rectangle (dest->mask, masks_gc, TRUE, 0, 0, -1, -1);

  mask_pattern.pixel = 1;
  gdk_gc_set_foreground (masks_gc, &mask_pattern);

  gdk_gc_set_clip_origin (white_gc, 0, 0);
  gdk_gc_set_clip_mask (white_gc, s1->mask);
  gdk_draw_pixmap (dest->pix, white_gc, s1->pix, 0, 0, 0, 0, w1, h1);
  gdk_draw_pixmap (dest->mask, masks_gc, s1->mask, 0, 0, 0, 0, w1, h1);

  gdk_gc_set_clip_origin (white_gc, w1, 0);
  gdk_gc_set_clip_mask (white_gc, s2->mask);
  gdk_draw_pixmap (dest->pix, white_gc, s2->pix, 0, 0, w1, 0, w2, h2);
  gdk_draw_pixmap (dest->mask, masks_gc, s2->mask, 0, 0, w1, 0, w2, h2);

  gdk_gc_set_clip_origin (white_gc, 0, 0);
  gdk_gc_set_clip_mask (white_gc, NULL);

  return dest;
}
Exemplo n.º 12
0
static gint
draw_cell_pixmap (GdkWindow    *window,
                  GdkRectangle *clip_rectangle,
                  GdkGC        *fg_gc,
                  GdkPixmap    *pixmap,
                  GdkBitmap    *mask,
                  gint          x,
                  gint          y,
                  gint          width,
                  gint          height)
{
   gint xsrc = 0, ysrc = 0;

   if (mask) {
      gdk_gc_set_clip_mask (fg_gc, mask);
      gdk_gc_set_clip_origin (fg_gc, x, y);
   }

   if (x < clip_rectangle->x) {
      xsrc = clip_rectangle->x - x;
      width -= xsrc;
      x = clip_rectangle->x;
   }
   if (x + width > clip_rectangle->x + clip_rectangle->width)
      width = clip_rectangle->x + clip_rectangle->width - x;

   if (y < clip_rectangle->y) {
      ysrc = clip_rectangle->y - y;
      height -= ysrc;
      y = clip_rectangle->y;
   }
   if (y + height > clip_rectangle->y + clip_rectangle->height)
      height = clip_rectangle->y + clip_rectangle->height - y;

   gdk_draw_pixmap (window, fg_gc, pixmap, xsrc, ysrc, x, y, width, height);

   if (mask) {
      gdk_gc_set_clip_origin (fg_gc, 0, 0);
      gdk_gc_set_clip_mask (fg_gc, NULL);
   }

   return x + MAX (width, 0);
}
Exemplo n.º 13
0
static void
set_clip (render_priv *priv, GdkGC *gc)
{
  if (gc == NULL)
    return;

  if (priv->clip)
    gdk_gc_set_clip_rectangle (gc, &priv->clip_rect);
  else
    gdk_gc_set_clip_mask (gc, NULL);
}
Exemplo n.º 14
0
/* gdk_cursor_new_from_pixmap is broken on Windows.
   this is a workaround using gdk_cursor_new_from_pixbuf. */
GdkCursor* fixed_gdk_cursor_new_from_pixmap(GdkPixmap *source, GdkPixmap *mask,
					    const GdkColor *fg, const GdkColor *bg,
					    gint x, gint y)
{
  GdkPixmap *rgb_pixmap;
  GdkGC *gc;
  GdkPixbuf *rgb_pixbuf, *rgba_pixbuf;
  GdkCursor *cursor;
  int width, height;

  /* HACK!  It seems impossible to work with RGBA pixmaps directly in
     GDK-Win32.  Instead we pick some third color, different from fg
     and bg, and use that as the 'transparent color'.  We do this using
     colors_too_similar (see above) because two colors could be
     unequal in GdkColor's 16-bit/sample, but equal in GdkPixbuf's
     8-bit/sample. */
  GdkColor candidates[3] = {{0,65535,0,0}, {0,0,65535,0}, {0,0,0,65535}};
  GdkColor *trans = &candidates[0];
  if (colors_too_similar(trans, fg) || colors_too_similar(trans, bg)) {
    trans = &candidates[1];
    if (colors_too_similar(trans, fg) || colors_too_similar(trans, bg)) {
      trans = &candidates[2];
    }
  } /* trans is now guaranteed to be unique from fg and bg */

  /* create an empty pixmap to hold the cursor image */
  gdk_drawable_get_size(source, &width, &height);
  rgb_pixmap = gdk_pixmap_new(NULL, width, height, 24);

  /* blit the bitmaps defining the cursor onto a transparent background */
  gc = gdk_gc_new(rgb_pixmap);
  gdk_gc_set_fill(gc, GDK_SOLID);
  gdk_gc_set_rgb_fg_color(gc, trans);
  gdk_draw_rectangle(rgb_pixmap, gc, TRUE, 0, 0, width, height);
  gdk_gc_set_fill(gc, GDK_OPAQUE_STIPPLED);
  gdk_gc_set_stipple(gc, source);
  gdk_gc_set_clip_mask(gc, mask);
  gdk_gc_set_rgb_fg_color(gc, fg);
  gdk_gc_set_rgb_bg_color(gc, bg);
  gdk_draw_rectangle(rgb_pixmap, gc, TRUE, 0, 0, width, height);
  gdk_gc_unref(gc);

  /* create a cursor out of the created pixmap */
  rgb_pixbuf = gdk_pixbuf_get_from_drawable(
    NULL, rgb_pixmap, gdk_colormap_get_system(), 0, 0, 0, 0, width, height);
  gdk_pixmap_unref(rgb_pixmap);
  rgba_pixbuf = gdk_pixbuf_add_alpha(
    rgb_pixbuf, TRUE, trans->red, trans->green, trans->blue);
  gdk_pixbuf_unref(rgb_pixbuf);
  cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), rgba_pixbuf, x, y);
  gdk_pixbuf_unref(rgba_pixbuf);

  return cursor;
}
Exemplo n.º 15
0
/* brush paint: get current pixmap/mask, and draw the part in the
 * rectangle bounds.
 */
void
_zune_fill_scaled_rectangle(struct MUI_ImageSpec *img,
			    struct MUI_RenderInfo *mri, 
			    LONG left, LONG top, LONG width, LONG height,
			    LONG xoffset, LONG yoffset)
{
    GdkPixmap *pixmap;
    GdkBitmap *mask;

    g_return_if_fail((pixmap = __zune_imspec_get_pixmap(img)) != NULL);

    mask = __zune_imspec_get_mask(img);

    gdk_gc_set_clip_mask(mri->mri_RastPort, mask);
    gdk_gc_set_clip_origin(mri->mri_RastPort, xoffset, yoffset);
/*  g_print("draw pixmap: srcx=%d srcy=%d dstx=%d dsty=%d w=%d h=%d\n", */
/*  	left - xoffset, top - yoffset, left, top, width, height); */
    gdk_draw_pixmap (mri->mri_Window, mri->mri_RastPort, pixmap,
		     left - xoffset, top - yoffset, left, top, width, height);
    gdk_gc_set_clip_mask(mri->mri_RastPort, NULL);
}
Exemplo n.º 16
0
/* Sets the clip mask for a graphics context from a bitmap.
 * The clip mask is interpreted relative to the clip origin.
 * (See gdk_gc_set_clip_origin()). */
int
clip_GDK_GCSETCLIPMASK(ClipMachine * cm)
{
	C_object  *cgc = _fetch_co_arg(cm);
	C_widget *cxpm = _fetch_cwidget(cm,_clip_spar(cm,2));
	CHECKCOBJ(cgc,GDK_IS_GC(cgc));
	CHECKARG2(2,MAP_t,NUMERIC_t); CHECKCWID(cxpm,GTK_IS_PIXMAP);
	gdk_gc_set_clip_mask(GDK_GC(cgc->object), GTK_PIXMAP(cxpm->widget)->pixmap);
	return 0;
err:
	return 1;
}
Exemplo n.º 17
0
static void
gtk_plot_gdk_clip_mask                              (GtkPlotPC *pc,
						     gdouble x,
						     gdouble y,
                                                     const GdkBitmap *mask)
{
  if(!GTK_PLOT_GDK(pc)->gc) return;

  if(x >= 0 && y >= 0)
    gdk_gc_set_clip_origin(GTK_PLOT_GDK(pc)->gc, x, y);

  gdk_gc_set_clip_mask(GTK_PLOT_GDK(pc)->gc, (GdkBitmap*)mask);
}
Exemplo n.º 18
0
static void
gtk_ui_load_picture(const char *name, int trans, Picture **pictp) {
	Picture *pict;
	char file[255];
	GdkBitmap *mask;

	UNUSED(trans);

	pict = xalloc(sizeof *pict);

	sprintf(file, "%s/pixmaps/%s.xpm", pictdir, name);
	pict->pix = gdk_pixmap_create_from_xpm(toplevel->window, &mask,
					       NULL, file);
	if (pict->pix == NULL)
		fatal("error reading %s", file);
	pict->mask = mask;
	pict->gc = gdk_gc_new(toplevel->window);
	gdk_gc_set_exposures(pict->gc, FALSE);
	gdk_gc_set_clip_mask(pict->gc, mask);
	gdk_window_get_size(pict->pix, &pict->width, &pict->height);

	*pictp = pict;
}
Exemplo n.º 19
0
  /* Push decal pixmaps through their stencils onto a Panel expose pixmap
  */
static gboolean
push_decal_pixmaps(GkrellmPanel *p, gboolean top_layer)
	{
	GList			*list;
	GkrellmDecal	*d;
	gint			x, y, w, h;
	gboolean		on_top, is_non_overlapping_text_decal;
	gboolean		restore_gc = FALSE, do_top_layer = FALSE;

	if (!p)
		return FALSE;
	for (list = p->decal_list; list; list = list->next)
		{
		d = (GkrellmDecal *) list->data;
		on_top = (d->flags & DF_TOP_LAYER);
		is_non_overlapping_text_decal
				= (d->text_list && !(d->flags & DF_TEXT_OVERLAPS));

		if (on_top && !top_layer)
			do_top_layer = TRUE;

		if (   d->state != DS_VISIBLE
			|| (top_layer && !on_top)
			|| (!top_layer && (on_top || is_non_overlapping_text_decal))
		   )
			continue;
		if (d->text_list)
			panel_draw_decal_text_list(p->pixmap, d);
		else if (d->scroll_text)
			{
			x = d->x_off;
			y = d->y_off;

			gdk_draw_drawable(p->pixmap, _GK.draw1_GC, d->pixmap,
						-x, -y, d->x, d->y, d->w, d->h);
			if (d->flags & DF_SCROLL_TEXT_H_LOOP)
				{
				x %= d->scroll_width;
				if (x > 0)
					{
					gdk_draw_drawable(p->pixmap, _GK.draw1_GC, d->pixmap,
							d->scroll_width - x, -y,
							d->x, d->y, x, d->h);
					}
				else if (   x <= 0
						 && (w = d->scroll_width + x) < d->w
						)
					{
					gdk_draw_drawable(p->pixmap, _GK.draw1_GC, d->pixmap,
							0, -y,
							d->x + w, d->y, d->w - w, d->h);
					}
				}
			if (d->flags & DF_SCROLL_TEXT_V_LOOP)
				{
				y %= d->scroll_height + d->y_ink;
				if (y > 0)
					gdk_draw_drawable(p->pixmap, _GK.draw1_GC, d->pixmap,
							-x, d->scroll_height + d->y_ink - y,
							d->x, d->y, d->w, y);
				else if (   y <= 0
						 && (h = d->scroll_height + d->y_ink + y) < d->h
						)
					gdk_draw_drawable(p->pixmap, _GK.draw1_GC, d->pixmap,
							-x, 0,
							d->x, d->y + h, d->w, d->h - h);
				}
			}
		else
			{
			gdk_gc_set_clip_mask(_GK.draw3_GC, d->stencil);
			gdk_gc_set_clip_origin(_GK.draw3_GC, d->x, d->y);
			gdk_draw_drawable(p->pixmap, _GK.draw3_GC, d->pixmap,
						0, d->y_src, d->x, d->y, d->w, d->h);
			restore_gc = TRUE;
			}
		}
	if (restore_gc)
		{
		gdk_gc_set_clip_mask(_GK.draw3_GC, NULL);
		gdk_gc_set_clip_origin(_GK.draw3_GC, 0, 0);
		}

	return do_top_layer;
	}
Exemplo n.º 20
0
static void
color_area_draw ()
{
  Color col;
  GdkColor *win_bg;
  GdkColor fg, bg, bd;
  gint rect_w, rect_h;
  gint width, height;
  gint def_width, def_height;
  gint swap_width, swap_height;
  GdkColor  mask_pattern;

  /* Check we haven't gotten initial expose yet,
   * no point in drawing anything
   */
  if (!color_area_pixmap || !color_area_gc)
    return;

  gdk_drawable_get_size (color_area_pixmap, &width, &height);

  win_bg = &(color_area->style->bg[GTK_STATE_NORMAL]);
  col = attributes_get_foreground();
  color_convert(&col, &fg);
  col = attributes_get_background();
  color_convert(&col, &bg);
  bd = color_gdk_black;

  rect_w = width * 0.65;
  rect_h = height * 0.65;

  /*  initialize the mask to transparent  */
  mask_pattern.pixel = 0;
  gdk_gc_set_foreground (mask_gc, &mask_pattern);
  gdk_draw_rectangle (color_area_mask, mask_gc, TRUE, 0, 0, -1, -1);

  /*  set the mask's gc to opaque  */
  mask_pattern.pixel = 1;
  gdk_gc_set_foreground (mask_gc, &mask_pattern);

  gdk_gc_set_foreground (color_area_gc, win_bg);
  gdk_draw_rectangle (color_area_pixmap, color_area_gc, 1,
		      0, 0, width, height);

  gdk_gc_set_foreground (color_area_gc, &bg);
  gdk_draw_rectangle (color_area_pixmap, color_area_gc, 1,
		      (width - rect_w), (height - rect_h), rect_w, rect_h);
  gdk_draw_rectangle (color_area_mask, mask_gc, TRUE,
		      (width - rect_w), (height - rect_h), rect_w, rect_h);

  if (active_color == FOREGROUND)
    gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL,
                      GTK_SHADOW_OUT,
                      NULL, color_area, NULL,
		      (width - rect_w), (height - rect_h),
                      rect_w, rect_h);
  else
    gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL,
                      GTK_SHADOW_IN,
                      NULL, color_area, NULL,
		      (width - rect_w), (height - rect_h),
                      rect_w, rect_h);

  gdk_gc_set_foreground (color_area_gc, &fg);
  gdk_draw_rectangle (color_area_pixmap, color_area_gc, 1,
		      0, 0, rect_w, rect_h);
  gdk_draw_rectangle (color_area_mask, mask_gc, TRUE,
		      0, 0, rect_w, rect_h);

  if (active_color == FOREGROUND)
    gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL,
                      GTK_SHADOW_IN,
                      NULL, color_area, NULL,
                      0, 0,
                      rect_w, rect_h);
  else
    gtk_paint_shadow (color_area->style, color_area_pixmap, GTK_STATE_NORMAL,
                      GTK_SHADOW_OUT,
                      NULL, color_area, NULL,
                      0, 0,
                      rect_w, rect_h);

  /*  draw the default pixmap  */
  gdk_drawable_get_size (default_pixmap, &def_width, &def_height);
  gdk_draw_drawable (color_area_pixmap, color_area_gc, default_pixmap,
		     0, 0, 0, height - def_height, def_width, def_height);
  gdk_draw_drawable (color_area_mask, mask_gc, default_mask,
		   0, 0, 0, height - def_height, def_width, def_height);

  /*  draw the swap pixmap  */
  gdk_drawable_get_size (swap_pixmap, &swap_width, &swap_height);
  gdk_draw_drawable (color_area_pixmap, color_area_gc, swap_pixmap,
		     0, 0, width - swap_width, 0, swap_width, swap_height);
  gdk_draw_drawable (color_area_mask, mask_gc, swap_mask,
		   0, 0, width - swap_width, 0, swap_width, swap_height);

  /*  draw the widget  */
  gdk_gc_set_clip_mask (color_area_gc, color_area_mask);
  gdk_gc_set_clip_origin (color_area_gc, 0, 0);
  gdk_draw_drawable (color_area->window, color_area_gc, color_area_pixmap,
		   0, 0, 0, 0, width, height);

  /*  reset the clip mask  */
  gdk_gc_set_clip_mask (color_area_gc, NULL);
}
Exemplo n.º 21
0
//! Draws the square (x, y). On the board it is shown at (real_x, real_y)
void board_refresh_cell_real (int x, int y, int real_x, int real_y)
{
	GdkGC *gc;
	int parity = (board_wid * board_heit + x + y + 1) % 2;
	int thepiece;
	if (opt_quiet) return;
	if (!cur_pos.board) return;
	gc = board_area->style->bg_gc[GTK_STATE_NORMAL];
	gdk_gc_set_clip_mask (gc, NULL);
	gdk_gc_set_clip_origin (gc, real_x * cell_size, real_y * cell_size);
	thepiece = cur_pos.board[y * board_wid + x] -1 + num_pieces * parity;
	if ((cur_pos.render[y * board_wid + x] & 0xFF) == RENDER_REPLACE)
		thepiece = (cur_pos.render[y * board_wid + x] >> 8) -1 + num_pieces * parity;
	if ((cur_pos.board[y * board_wid + x] != 0
			|| (cur_pos.render[y * board_wid + x] & 0xFF) == RENDER_REPLACE)
			&& !board_suspended)
	{
		/* FIXME: current impl is that if bgimage is set then bgcolor is irrelevant. Maybe we should change it so that bgimage is layered on top of bgcolor */
		if (board_bgimage)
		{
			gdk_draw_pixmap (board_area->window,
					gc, (GdkDrawable *) board_bgimage,
					real_x * cell_size, real_y * cell_size,
					real_x * cell_size, real_y * cell_size,
					cell_size, cell_size
					);
			gdk_gc_set_clip_mask (gc, piece_masks [thepiece]);
			gdk_gc_set_clip_origin (gc, real_x * cell_size, real_y * cell_size);
		}
		gdk_draw_pixmap (board_area->window, 
				gc, (GdkDrawable *) pieces [thepiece],
				0, 0, real_x * cell_size, real_y * cell_size, 
				-1, -1);
	}
	else
	{
		if (board_bgimage)
		{
			gdk_draw_pixmap (board_area->window,
					gc, (GdkDrawable *) board_bgimage,
					real_x * cell_size, real_y * cell_size,
					real_x * cell_size, real_y * cell_size,
					cell_size, cell_size
					);
		}
		else
			gdk_draw_rectangle (board_area->window, board_gcs[parity], 1, 
					real_x * cell_size, real_y * cell_size,
					cell_size, cell_size);
	}

	if (cur_pos.render[y * board_wid + x] == RENDER_SHADE1			
			&& cur_pos.board[y * board_wid + x] != 0
		   	&& !board_suspended)
	{
#if GTK_MAJOR_VERSION > 1
		GdkPixbuf *pixbuf;
		int i;
		guchar *pixels;
		pixbuf = gdk_pixbuf_get_from_drawable (NULL, pieces[thepiece], NULL,
				0, 0, 0, 0, cell_size, cell_size);
		pixels = gdk_pixbuf_get_pixels (pixbuf);
		for (i=0; i<3*cell_size*cell_size; i++)
			pixels[i] = (pixels[i] + 127)/2;
		gdk_pixbuf_render_to_drawable (pixbuf, board_area->window, gc, 0, 0,
				real_x * cell_size, real_y * cell_size, cell_size, cell_size,
				GDK_RGB_DITHER_NONE, 0, 0);
		// FIXME: find out the  correct way to free it
		g_free (pixels);
		g_free (pixbuf);
#else
		fprintf (stderr, "Warning: RENDER_SHADE currently unimplemented in gtk1 version\n");
#endif
	}

	
	if (game_draw_cell_boundaries)
	{
		if (real_x > 0)
			gdk_draw_line (board_area->window, board_gcs[2],
				real_x * cell_size, real_y * cell_size,
				real_x * cell_size, (real_y + 1) * cell_size);
		if (real_y > 0)
			gdk_draw_line (board_area->window, board_gcs[2],
				real_x * cell_size, real_y * cell_size,
				(real_x + 1) * cell_size, real_y * cell_size);
	}
	
	// TODO: do HIGHLIGHT2 and 3 also
	if (cur_pos.render[y * board_wid + x] == RENDER_HIGHLIGHT1 && !board_suspended)
	{
		int incr = game_draw_cell_boundaries ? 1 : 0;
		gdk_draw_line (board_area->window, board_highlight_gcs[0],
			real_x * cell_size + incr, real_y * cell_size + incr,
			real_x * cell_size + incr, (real_y + 1) * cell_size - 1);
		gdk_draw_line (board_area->window, board_highlight_gcs[0],
			real_x * cell_size + incr, real_y * cell_size + incr,
			(real_x + 1) * cell_size - 1, real_y * cell_size + incr);
		gdk_draw_line (board_area->window, board_highlight_gcs[0],
			(real_x + 1) * cell_size - 1, real_y * cell_size + incr,
			(real_x + 1) * cell_size - 1, (real_y + 1) * cell_size - 1);
		gdk_draw_line (board_area->window, board_highlight_gcs[0],
			real_x * cell_size + incr, (real_y + 1) * cell_size - 1,
			(real_x + 1) * cell_size - 1, (real_y + 1) * cell_size - 1);
	}
	
	if (cur_pos.render[y * board_wid + x] == RENDER_BUTTONIZE && !board_suspended)
	{
		int incr = game_draw_cell_boundaries ? 1 : 0;
		gdk_draw_line (board_area->window, board_buttonize_gcs[0],
			real_x * cell_size + incr, real_y * cell_size + incr,
			real_x * cell_size + incr, (real_y + 1) * cell_size - 1);
		gdk_draw_line (board_area->window, board_buttonize_gcs[0],
			real_x * cell_size + incr, real_y * cell_size + incr,
			(real_x + 1) * cell_size - 1, real_y * cell_size + incr);
		gdk_draw_line (board_area->window, board_buttonize_gcs[1],
			(real_x + 1) * cell_size - 1, real_y * cell_size + incr,
			(real_x + 1) * cell_size - 1, (real_y + 1) * cell_size - 1);
		gdk_draw_line (board_area->window, board_buttonize_gcs[1],
			real_x * cell_size + incr, (real_y + 1) * cell_size - 1,
			(real_x + 1) * cell_size - 1, (real_y + 1) * cell_size - 1);
	}
	
}
Exemplo n.º 22
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.º 23
0
static VALUE
rg_set_clip_mask(VALUE self, VALUE mask)
{
    gdk_gc_set_clip_mask(_SELF(self), GDK_BITMAP(RVAL2GOBJ(mask)));
    return self;
}
Exemplo n.º 24
0
static void register_pixmaps(void)
{
	gint idx;

	GtkIconFactory *factory = gtk_icon_factory_new();

	for (idx = 0; idx < G_N_ELEMENTS(pioneers_pixmaps); idx++) {
		gchar *filename;
		GtkIconSet *icon;

		icon = gtk_icon_set_new();
		/* determine full path to pixmap file */
		filename = g_build_filename(DATADIR, "pixmaps",
					    pioneers_pixmaps[idx], NULL);
		if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
			GtkIconSource *source;
			GdkPixbuf *pixbuf;
			GError *error = NULL;
			pixbuf =
			    gdk_pixbuf_new_from_file(filename, &error);
			if (error != NULL) {
				g_warning("Error loading pixmap %s\n",
					  filename);
				g_error_free(error);
			} else {
				source = gtk_icon_source_new();
				gtk_icon_source_set_pixbuf(source, pixbuf);
				g_object_unref(pixbuf);
				gtk_icon_set_add_source(icon, source);
				gtk_icon_source_free(source);
			}
		} else {
			/* Missing pixmap */
			g_warning("Pixmap not found: %s", filename);
		}

		gtk_icon_factory_add(factory, pioneers_pixmaps[idx], icon);
		g_free(filename);
		gtk_icon_set_unref(icon);
	}

	gtk_icon_factory_add_default(factory);
	g_object_unref(factory);

	for (idx = 0; idx < NO_RESOURCE; idx++) {
		gchar *filename;

		/* determine full path to pixmap file */
		filename = g_build_filename(DATADIR, "pixmaps",
					    resources_pixmaps[idx], NULL);
		if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
			GdkPixbuf *pixbuf;
			GError *error = NULL;
			pixbuf =
			    gdk_pixbuf_new_from_file(filename, &error);
			if (error != NULL) {
				g_warning("Error loading pixmap %s\n",
					  filename);
				g_error_free(error);
			} else {
				gdk_pixbuf_render_pixmap_and_mask(pixbuf,
								  &resource_pixmap
								  [idx].p,
								  &resource_pixmap
								  [idx].b,
								  128);
				resource_pixmap[idx].gcb =
				    gdk_gc_new(resource_pixmap[idx].b);
				gdk_gc_set_function(resource_pixmap
						    [idx].gcb, GDK_OR);
				resource_pixmap[idx].gcp =
				    gdk_gc_new(resource_pixmap[idx].p);
				gdk_gc_set_clip_mask(resource_pixmap
						     [idx].gcp,
						     resource_pixmap
						     [idx].b);
				if (!resource_pixmap_res)
					resource_pixmap_res =
					    gdk_pixbuf_get_width(pixbuf);
				g_object_unref(pixbuf);
			}
		} else {
			/* Missing pixmap */
			g_warning("Pixmap not found: %s", filename);
		}

		g_free(filename);
	}
}
Exemplo n.º 25
0
static void
redraw_region (GdkRectangle *rect)
{
  int eleft, eright, etop, ebottom;
  BoxType region;
  render_priv *priv = gport->render_priv;

  if (!gport->pixmap)
    return;

  if (rect != NULL)
    {
      priv->clip_rect = *rect;
      priv->clip = true;
    }
  else
    {
      priv->clip_rect.x = 0;
      priv->clip_rect.y = 0;
      priv->clip_rect.width = gport->width;
      priv->clip_rect.height = gport->height;
      priv->clip = false;
    }

  set_clip (priv, priv->bg_gc);
  set_clip (priv, priv->offlimits_gc);
  set_clip (priv, priv->mask_gc);
  set_clip (priv, priv->grid_gc);

  region.X1 = MIN(Px(priv->clip_rect.x),
                  Px(priv->clip_rect.x + priv->clip_rect.width + 1));
  region.Y1 = MIN(Py(priv->clip_rect.y),
                  Py(priv->clip_rect.y + priv->clip_rect.height + 1));
  region.X2 = MAX(Px(priv->clip_rect.x),
                  Px(priv->clip_rect.x + priv->clip_rect.width + 1));
  region.Y2 = MAX(Py(priv->clip_rect.y),
                  Py(priv->clip_rect.y + priv->clip_rect.height + 1));

  region.X1 = MAX (0, MIN (PCB->MaxWidth,  region.X1));
  region.X2 = MAX (0, MIN (PCB->MaxWidth,  region.X2));
  region.Y1 = MAX (0, MIN (PCB->MaxHeight, region.Y1));
  region.Y2 = MAX (0, MIN (PCB->MaxHeight, region.Y2));

  eleft = Vx (0);
  eright = Vx (PCB->MaxWidth);
  etop = Vy (0);
  ebottom = Vy (PCB->MaxHeight);
  if (eleft > eright)
    {
      int tmp = eleft;
      eleft = eright;
      eright = tmp;
    }
  if (etop > ebottom)
    {
      int tmp = etop;
      etop = ebottom;
      ebottom = tmp;
    }

  if (eleft > 0)
    gdk_draw_rectangle (gport->drawable, priv->offlimits_gc,
                        1, 0, 0, eleft, gport->height);
  else
    eleft = 0;
  if (eright < gport->width)
    gdk_draw_rectangle (gport->drawable, priv->offlimits_gc,
                        1, eright, 0, gport->width - eright, gport->height);
  else
    eright = gport->width;
  if (etop > 0)
    gdk_draw_rectangle (gport->drawable, priv->offlimits_gc,
                        1, eleft, 0, eright - eleft + 1, etop);
  else
    etop = 0;
  if (ebottom < gport->height)
    gdk_draw_rectangle (gport->drawable, priv->offlimits_gc,
                        1, eleft, ebottom, eright - eleft + 1,
                        gport->height - ebottom);
  else
    ebottom = gport->height;

  gdk_draw_rectangle (gport->drawable, priv->bg_gc, 1,
                      eleft, etop, eright - eleft + 1, ebottom - etop + 1);

  ghid_draw_bg_image();

  hid_expose_callback (&ghid_hid, &region, 0);
  ghid_draw_grid ();

  /* In some cases we are called with the crosshair still off */
  if (priv->attached_invalidate_depth == 0)
    DrawAttached ();

  /* In some cases we are called with the mark still off */
  if (priv->mark_invalidate_depth == 0)
    DrawMark ();

  draw_lead_user (priv);

  priv->clip = false;

  /* Rest the clip for bg_gc, as it is used outside this function */
  gdk_gc_set_clip_mask (priv->bg_gc, NULL);
}