[cairo] drawing into GDK bitmap (pixmap of depth 1)?

Owen Taylor otaylor at redhat.com
Mon Feb 20 04:16:38 PST 2006


On Sun, 2006-02-19 at 16:11 -0800, Eric Smith wrote:
> I'm trying to convert a simple GTK application from using GDK drawing
> primitives to Cairo (1.0.2 on Fedora Core 5 test 2 x86_64).  Most of it
> works fine.  But the application wants a round window, so it creates a
> GDK bitmap, fills it with black, draws a filled white circle in it, and
> passes that to gtk_widget_shape_combine_mask() to get a round window.
> That worked fine drawing into the bitmap with GDK, but I can't seem to
> make it work with Cairo.  My attempt is:
> 
>     bitmap = (GdkDrawable *) gdk_pixmap_new (NULL, width, height, 1);
>     cr = gdk_cairo_create (bitmap);
> 
>     // fill bitmap with black
>     cairo_rectangle (cr, 0, 0, width, height);
>     cairo_set_source_rgb (cr, 0, 0, 0);
>     cairo_fill (cr);
> 
>     // draw white filled circle
>     cairo_arc (cr, width / 2, height / 2, width / 2, 0, 2 * M_PI);
>     cairo_set_source_rgb (cr, 1, 1, 1);
>     cairo_fill (cr);
> 
>     cairo_destroy (cr);
> 
> What happens is the entire bitmap gets filled with white, so the window
> ends up being rectangular.  If I comment out the section that attempts
> to fill the rectangle with black, as expected I get random (leftover)
> black and white pixels outside the circle, and white pixels inside the
> circle.

Where's the white and black? Unless you are working with monochrome 
monitor and create the bitmap with a colormap for that monitor, a bitmap
in GTK+ has no color interpretation - it's just zeros and ones.

IIRC, when you use a GTK+ bitmap with Cairo it's treated as a 1-bit
alpha bitmap, so you might want to try adjusting you code appropriately.

Try - set_operator(CAIRO_CLEAR); cairo_fill(); rather than painting
with black.

Regards,
						Owen




More information about the cairo mailing list