Re: setting Gtk2::Gdk::Color pixel
- From: muppet <scott asofyet org>
- To: gtk2-perl List <gtk-perl-list gnome org>
- Subject: Re: setting Gtk2::Gdk::Color pixel
- Date: Thu, 15 Nov 2007 20:25:26 -0500
On Nov 15, 2007, at 7:11 PM, Kevin Ryde wrote:
I had an urge to do some xor-ing of pixels, to flip between colours
for
easy un-drawing of an interactive "lasso" in a widget, so I want to
set
the "foreground" pixel of a GC to a calculated value (as opposed to
getting it from a colour lookup or alloc).
If I'm not mistaken $gc->set_values and friends take a
Gtk2::Gdk::Color
object in the hash for "GdkGCValues", but I couldn't spot how to set
the
pixel field in such an object. Is there a secret setter method, or a
way to create with a given pixel?
The trick is to set the foreground to solid white and set the gdk
function to XOR.
From some old C code i have sitting around:
if ( ! r->draginfo.gc ) {
r->draginfo.gc = gdk_gc_new (GTK_WIDGET (c)->window);
gdk_gc_set_function (r->draginfo.gc, GDK_XOR);
gdk_gc_set_foreground (r->draginfo.gc,
&(GTK_WIDGET (c)->style-
>white));
}
which translates into perl as
$gc = Gtk2::Gdk::GC->new ($widget->window);
$gc->set_function ('xor');
$gc->set_foreground ($widget->style->white);
(I see Gtk2::Gdk::Color->new takes the RGB fields, but not a pixel.)
(Of course why GdkGCValues etc uses a GdkColor struct when it only
looks
at the pixel value is anyone's guess. Must have seemed like a good
idea
at the time.)
My understanding is that you specify the RGB values you want, and the
GdkColor contains the actual visual-specific pixel value allocated by
the underlying system. This was very important back in the colormap
and low-bitdepth days.
--
The stereo, playing the Beastie Boys' "Rhymin' and Stealin'": "I'll
steal your girlie like I stole your bike!"
Elysse: "You mean, take off the chain and ride away?"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]