Clipping-Masks in Gdk
- From: Stephan Krings <slothkri zedat fu-berlin de>
- To: gtk-list redhat com
- Subject: Clipping-Masks in Gdk
- Date: Mon, 12 Oct 1998 00:02:48 +0200 (CEST)
Hello out there,
could anyone please explain me while the code appended does not
work. Forgive me if this is a stupid question, but although I'm
beginning to feel comfortable with Gtk and Gdk, I don't know much
about the underlying Xlib-calls and -mechanisms (maybe I need to
invest in one of those expensive Xlib-books), and I'd guess this is
the problem.
I hope my intention is clear, when reading the code: I want to create
an offscreen clipping-mask for a window or pixmap. Unfortunatly I'm
not sure, how to create the GdkBitmap in memory (it works, when
loading the bitmap from a file with gdk_bitmap_create_from_data for
example).
Oh yes, the program crashes with an abort-signal and BadMatch error
message.
So, how do I create this magic GdkBitmap or mask in memory?
Thank you all in advance,
Stephan
---------------------------------------------------------------------------
#include <gtk/gtk.h>
int main (int argc, char **argv) {
GtkWidget *window;
GtkWidget *drawarea;
GdkPixmap *mask;
GdkGC *gc;
GdkColor red;
GdkColor white;
gtk_init(&argc, &argv);
drawarea = gtk_drawing_area_new();
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_add(GTK_CONTAINER (window), drawarea);
gtk_widget_show(GTK_WIDGET (drawarea));
gtk_widget_show(GTK_WIDGET (window));
gdk_color_parse("red", &red);
gdk_color_alloc(gtk_widget_get_colormap(drawarea), &red);
gdk_color_parse("white", &white);
gdk_color_alloc(gtk_widget_get_colormap(drawarea), &white);
gc = gdk_gc_new(drawarea->window);
gdk_gc_copy(gc, drawarea->style->black_gc);
gdk_gc_set_foreground(gc, &white);
mask = gdk_pixmap_new(drawarea->window,
drawarea->allocation.width,
drawarea->allocation.height,
-1);
gdk_draw_rectangle(mask, gc, TRUE, 10, 10, 20, 20);
gdk_gc_set_foreground(gc, &red);
gdk_gc_set_clip_mask(gc, mask);
gdk_gc_set_clip_origin(gc, 0, 0);
gdk_draw_rectangle(drawarea->window, gc, TRUE, 0, 0,
drawarea->allocation.width,
drawarea->allocation.height);
gtk_main();
return 0;
}
---------------------------------------------------------------------------
--
Stephan Krings Freie Universitaet Berlin
AG Kommunikationsserver Zentraleinrichtung fuer Datenverarbeitung (ZEDAT)
slothkri@zedat.fu-berlin.de Fabeckstr. 32
Tel: +49 30 838 3239 14195 Berlin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]