Re: GdkBitmap - turning pixels OFF




I worked this out.

For my situation I did the following:

create a GdkBitmap* containing the original mask.

Create a second GdkBitmap* for the inverted mask.

Then create a GdkGC for inversion and draw to the inverted mask using
the inversion GdkGC

Code snippet:

GdkBitmap *original_bitmap, *inverted_bitmap;
GdkGC* gc_inverse = gdk_gc_new(original_bitmap);

//Tells the Graphics context to draw using GDK_CLEAR.
// That is, everywhere it wishes to draw it will actually
// clear the associated pixmap (in this case bitmap) instead
gdk_gc_set_function(gc_inverse, GDK_CLEAR);

//Tells the Graphics Context to ONLY draw the places where
// original_bitmap has been drawn on (ie original_bitmap is a mask)
gdk_gc_set_clip_mask(gc_inverse, original_bitmap);

gdk_draw_drawable(
    inverted_bitmap,
    gc_inverse, //Using function & mask set above,
    original_bitmap,    
    0, 0,
    0, 0,
    -1, -1
    );


I hope this is helpful to someone -> this tiny bit of code came from 2
weeks of part time work! :)

And my beef: Why isn't there a Gdk tutorial/manual anywhere? Is it just
too large a project?

-Kent.


/-------------------/
Hi,

I'm a relative newbie to the Gtk+/Gdk world and am having trouble with
the GdkBitmap.

I am creating GdkBitmaps in order to create clip masks. The mask is used
for a graphics context which I then pass as an argument to
gdk_draw_drawable. Basically I have two 'layers' which should be
exclusively independent. That is, where one 'layer' is visible (clipped
in by the mask), the other layer should be clipped out, and vice-versa.

In order to do this, and in order to update the masks as I update the
layers, I need to be able to 'turn' pixels off. I am using a Cairo
surface to write to the Bitmap. Is there a specific colour I can specify
that will be 'off' for the bitmap. I think there's some way to do this
with a GdkGC, but I can't figure it out.....

Scenario: I paint an entire 'mask' bitmap black which would clip the
entire bitmap's area. I then want to remove a small portion of the
bitmap, ie make it transparent/clear/white/off/unset again. Using Cairo
and painting an opaque white, or transparent white over the top does not
work.

Help......

Thanks. Kent.




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