示例#1
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);
  }
}
示例#2
0
/** Convert Dia color objects into GDK color objects.
 * If the highlight color is set, that will be used instead.  This allows
 * rendering of an object to do highlight rendering.
 * @param renderer The renderer to check for highlight color.
 * @param col A color object to convert.
 * @param gdk_col Resulting GDK convert.
 */
static void
renderer_color_convert(DiaGdkRenderer *renderer,
		       Color *col, GdkColor *gdk_col)
{
  if (renderer->highlight_color != NULL) {
    color_convert(renderer->highlight_color, gdk_col);
  } else {
    color_convert(col, gdk_col);
  }
  if (col->alpha != renderer->current_alpha) {
    if (col->alpha == 1.0)
      gdk_gc_set_fill(renderer->gc, GDK_SOLID);
    else {
      static gchar bits[9][4] = {
        { 0x00, 0x00, 0x00, 0x00 }, /*   0% */
	{ 0x20, 0x02, 0x20, 0x02 },
        { 0x22, 0x88, 0x22, 0x88 }, /*  25% */
	{ 0x4A, 0xA4, 0x4A, 0xA4 },
        { 0x5A, 0xA5, 0x5A, 0xA5 }, /*  50% */
	{ 0x57, 0xBA, 0x57, 0xBA },
        { 0xBE, 0xEB, 0xBE, 0xEB }, /*  75% */
	{ 0xEF, 0xFE, 0xEF, 0xFE },
        { 0xFF, 0xFF, 0xFF, 0xFF }, /* 100% */
      };
      GdkBitmap *stipple = gdk_bitmap_create_from_data (NULL, bits[(int)(9*col->alpha+.49)], 4, 4);
      gdk_gc_set_stipple (renderer->gc, stipple);
      g_object_unref (stipple);
      gdk_gc_set_fill(renderer->gc, GDK_STIPPLED);
    }
    renderer->current_alpha = col->alpha;
  }
}
示例#3
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;
}
示例#4
0
文件: cdgdk.c 项目: LuaDist/cd
static int cdinteriorstyle(cdCtxCanvas *ctxcanvas, int style)
{
  GdkFill sty = GDK_SOLID;

  switch (style)
  {
    case CD_SOLID:
      sty = GDK_SOLID;
      break;

    case CD_HATCH :
      if (!ctxcanvas->last_hatch) 
        return ctxcanvas->canvas->interior_style;

      gdk_gc_set_stipple(ctxcanvas->gc, ctxcanvas->last_hatch);

      if (ctxcanvas->canvas->back_opacity == CD_OPAQUE)
        sty = GDK_OPAQUE_STIPPLED;
      else
        sty = GDK_STIPPLED;
      break;

    case CD_STIPPLE:
      gdk_gc_set_stipple(ctxcanvas->gc, ctxcanvas->last_stipple);

      if (ctxcanvas->canvas->back_opacity == CD_OPAQUE)
        sty = GDK_OPAQUE_STIPPLED;
      else
        sty = GDK_STIPPLED;
      break;

    case CD_PATTERN:
      gdk_gc_set_tile(ctxcanvas->gc, ctxcanvas->last_pattern);
      sty = GDK_TILED;
      break;
  }

  gdk_gc_set_fill(ctxcanvas->gc, sty);

  return style;
}
示例#5
0
文件: gdkgc.c 项目: amery/clip-itk
/* Set the stipple bitmap for a graphics context. The stipple will
 * only be used if the fill mode is GDK_STIPPLED or GDK_OPAQUE_STIPPLED. */
int
clip_GDK_GCSETSTIPPLE(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_stipple(GDK_GC(cgc->object), GTK_PIXMAP(cxpm->widget)->pixmap);
	return 0;
err:
	return 1;
}
示例#6
0
static void	
zune_render_set_pattern (struct MUI_RenderInfo *mri, LONG pattern)
{
    SetAPen(mri->mri_RastPort, mri->mri_Pens[patternPens[pattern - MUII_BACKGROUND].fg]);
    SetBPen(mri->mri_RastPort, mri->mri_Pens[patternPens[pattern - MUII_BACKGROUND].bg]);    
    gdk_gc_set_fill(mri->mri_RastPort, GDK_OPAQUE_STIPPLED);
    if (!mri->mri_PatternStipple)
    {
	mri->mri_PatternStipple =
	    gdk_bitmap_create_from_data(mri->mri_Window, patstipple_bits,
					patstipple_width, patstipple_height);
    }
    gdk_gc_set_stipple(mri->mri_RastPort, mri->mri_PatternStipple);
}
示例#7
0
/* Re-render the internal font data so that changes will be reflected on
 * the next display refresh. */
void
vga_refresh_font(VGAText *vga)
{
	g_return_if_fail(vga != NULL);
	g_return_if_fail(VGA_IS_TEXT(vga));

#ifdef USE_DEPRECATED_GDK
	g_object_unref(vga->pvt->glyphs);
	vga->pvt->glyphs = vga_font_get_bitmap(vga->pvt->font,
			GTK_WIDGET(vga)->window);
	gdk_gc_set_stipple(vga->pvt->gc, vga->pvt->glyphs);
#else
	/* FIXME: ??? */
#endif
}
示例#8
0
/**
 * gimp_canvas_set_stipple_index:
 * @canvas: a #GimpCanvas widget
 * @style:  the #GimpCanvasStyle to alter
 * @index:  the new stipple index
 *
 * Some styles of the #GimpCanvas do a stipple fill. #GimpCanvas has a
 * set of %GIMP_CANVAS_NUM_STIPPLES stipple bitmaps. This function
 * allows you to change the bitmap being used. This can be used to
 * implement a marching ants effect. An older implementation used to
 * use this feature and so it is included since it might be useful in
 * the future. All stipple bitmaps but the default one are created on
 * the fly.
 */
void
gimp_canvas_set_stipple_index (GimpCanvas      *canvas,
                               GimpCanvasStyle  style,
                               guint            index)
{
  if (! gimp_canvas_ensure_style (canvas, style))
    return;

  index = index % GIMP_CANVAS_NUM_STIPPLES;

  if (! canvas->stipple[index])
    {
      canvas->stipple[index] =
        gdk_bitmap_create_from_data (GTK_WIDGET (canvas)->window,
                                     (const gchar *) stipples[index], 8, 8);
    }

  gdk_gc_set_stipple (canvas->gc[style], canvas->stipple[index]);
}
示例#9
0
static void
vga_realize(GtkWidget *widget)
{
	GdkWindowAttr attributes;
	gint attributes_mask;
	//GdkCursor * cursor;
	VGAText *vga;

#ifdef VGA_DEBUG
	fprintf(stderr, "vga_realize()\n");
#endif
	g_return_if_fail(widget != NULL);
	g_return_if_fail(VGA_IS_TEXT(widget));

	vga = VGA_TEXT(widget);

	/* Set the realized flag. */
	GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);

	/* Main widget window */
	attributes.window_type = GDK_WINDOW_CHILD;
	attributes.x = 0;
	attributes.y = 0;
	attributes.width = widget->allocation.width;
	attributes.height = widget->allocation.height;
	attributes.wclass = GDK_INPUT_OUTPUT;
	attributes.visual = gtk_widget_get_visual(widget);
	attributes.colormap = gtk_widget_get_colormap(widget);
	attributes.event_mask = gtk_widget_get_events(widget) |
				GDK_EXPOSURE_MASK |
				GDK_BUTTON_PRESS_MASK |
				GDK_BUTTON_RELEASE_MASK |
				GDK_POINTER_MOTION_MASK |
				GDK_BUTTON1_MOTION_MASK |
				GDK_KEY_PRESS_MASK |
				GDK_KEY_RELEASE_MASK;
	attributes_mask = GDK_WA_X |
			  GDK_WA_Y |
			  GDK_WA_VISUAL |
			  GDK_WA_COLORMAP;
	widget->window = gdk_window_new(gtk_widget_get_parent_window(widget),
					&attributes,
					attributes_mask);
	gdk_window_move_resize(widget->window,
			       widget->allocation.x,
			       widget->allocation.y,
			       widget->allocation.width,
			       widget->allocation.height);
	gdk_window_set_user_data(widget->window, widget);

	gdk_window_show(widget->window);


#ifdef USE_DEPRECATED_GDK
	/* Initialize private data that depends on the window */
	if (vga->pvt->gc == NULL)
	{
		vga->pvt->glyphs = vga_font_get_bitmap(vga->pvt->font,
				widget->window);
		vga->pvt->gc = gdk_gc_new(widget->window);
		// not needed i guess?
		//gdk_gc_set_colormap(vga->pvt->gc, attributes.colormap);
		gdk_gc_set_rgb_fg_color(vga->pvt->gc,
			vga_palette_get_color(vga->pvt->pal, vga->pvt->fg));
		gdk_gc_set_rgb_bg_color(vga->pvt->gc,
			vga_palette_get_color(vga->pvt->pal, vga->pvt->bg));
		gdk_gc_set_stipple(vga->pvt->gc, vga->pvt->glyphs);
		gdk_gc_set_fill(vga->pvt->gc, GDK_OPAQUE_STIPPLED);
	}
#else
#if 0
	if (vga->pvt->cr == NULL) {
		vga->pvt->cr = gdk_cairo_create(widget->window);
		cairo_set_source_rgb(vga->pvt->cr, 0.5, 0.5, 0.0);
		cairo_set_operator(vga->pvt->cr, CAIRO_OPERATOR_SOURCE);
		cairo_paint(vga->pvt->cr);
		cairo_set_font_face(vga->pvt->cr, vga->pvt->font->face);
		cairo_set_font_size(vga->pvt->cr, 1.0);
		cairo_move_to(vga->pvt->cr, 10.0, 370.0);
		cairo_set_source_rgb(vga->pvt->cr, 1.0, 1.0, 1.0);
		cairo_show_text(vga->pvt->cr, "Testing");
#endif
#if 0
		cairo_select_font_face (vga->pvt->cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
	                               CAIRO_FONT_WEIGHT_BOLD);
		cairo_set_font_size(vga->pvt->cr, 12.0);
	}
#endif
#endif

	/* create a gdk window?  is that what we really want? */
	gtk_widget_grab_focus(widget);
}
示例#10
0
static void
gtk_text_render_state_update (GtkTextRenderState *state,
                              GtkTextAppearance  *new_appearance)
{
  GdkScreen *screen = gtk_widget_get_screen (state->widget);
  
  if (!state->last_appearance ||
      !gdk_color_equal (&new_appearance->fg_color, &state->last_appearance->fg_color))
    gtk_text_render_state_set_color (state, state->fg_gc, &new_appearance->fg_color);

  if (!state->last_appearance ||
      new_appearance->fg_stipple != state->last_appearance->fg_stipple)
    {
      if (new_appearance->fg_stipple)
        {
	  if (screen == gdk_drawable_get_screen (new_appearance->fg_stipple))
	    {
	      gdk_gc_set_fill (state->fg_gc, GDK_STIPPLED);
	      gdk_gc_set_stipple (state->fg_gc, new_appearance->fg_stipple);
	    }
	  else
	    g_warning ("gtk_text_render_state_update:\n"
		       "The foreground stipple bitmap has been created on the wrong screen.\n"
		       "Ignoring the stipple bitmap information.");
        }
      else
        {
          gdk_gc_set_fill (state->fg_gc, GDK_SOLID);
        }
    }

  if (new_appearance->draw_bg)
    {
      if (!state->last_bg_appearance ||
          !gdk_color_equal (&new_appearance->bg_color, &state->last_bg_appearance->bg_color))
        gtk_text_render_state_set_color (state, state->bg_gc, &new_appearance->bg_color);

      if (!state->last_bg_appearance ||
          new_appearance->bg_stipple != state->last_bg_appearance->bg_stipple)
        {
          if (new_appearance->bg_stipple)
            {
	      if (screen == gdk_drawable_get_screen (new_appearance->bg_stipple))
		{
		  gdk_gc_set_fill (state->bg_gc, GDK_STIPPLED);
		  gdk_gc_set_stipple (state->bg_gc, new_appearance->bg_stipple);
		}
	      else
		g_warning ("gtk_text_render_state_update:\n"
			   "The background stipple bitmap has been created on the wrong screen.\n"
			   "Ignoring the stipple bitmap information.");

            }
          else
            {
              gdk_gc_set_fill (state->bg_gc, GDK_SOLID);
            }
        }

      state->last_bg_appearance = new_appearance;
    }

  state->last_appearance = new_appearance;
}
示例#11
0
文件: rbgdkgc.c 项目: tec/ruby-gnome2
static VALUE
rg_set_stipple(VALUE self, VALUE stipple)
{
    gdk_gc_set_stipple(_SELF(self), GDK_PIXMAP(RVAL2GOBJ(stipple)));
    return self;
}