Drawing Bitmaps


how do I draw a bitmap into a drawable with depth != 1?

gdk.h declares the function gdk_draw_bitmap which would probably do what
I want, but it's not defined anywhere (gtk 1.2.3). Is this just an
oversight, or was it a design decision to leave it out?

Implementing gdk_draw_bitmap shouldn't be difficult, at least for the
Xlib version, as it's basically gdk_draw_pixmap with XCopyPlane instead
of XCopyArea.

Looking through the gtk sources for an example, I found a place in
gtktext.c where a bitmap is drawn with this ugly sequence (line 5115ff):

  gdk_gc_set_stipple (text->gc,
  gdk_gc_set_fill (text->gc, GDK_STIPPLED);
  gdk_gc_set_foreground (text->gc, &GTK_WIDGET (text)->style->text[GTK_STATE_NORMAL]);
  gdk_gc_set_ts_origin (text->gc,
			width + 1,
			height - bitmap_height - 1);
  gdk_draw_rectangle (text->text_area,
		      width + 1,
		      height - bitmap_height - 1 /* one pixel above the baseline. */,
  gdk_gc_set_ts_origin (text->gc, 0, 0);
  gdk_gc_set_fill (text->gc, GDK_SOLID);

This works, but IMO it's very ugly and convoluted. Surely there's a
better way.


Bernhard Herzog	  | Sketch, a python based drawing program
herzog@online.de  | http://www.online.de/home/sketch/

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]