Re: Color Confusion




John Kodis <kodis@jagunet.com> writes:

> I've been trying to develop a small Gtk application which needs to use
> the gdk_draw routines to generate an image in a pixmap, and then copy
> this pixmap into a previously created drawing_area.  I'm having a
> great deal of trouble figuring out what to pass as the gc parameter
> that all the gdk_draw routines use.
> 
> The examples that I've found all seem to either just use one of the
> widget->window->gcs, or else involve so much code that I can't follow
> them.  After spending most of a weekend plowing through colors, color
> maps, visuals, color contexts, graphics contexts, styles, and much
> else, it seems like time to ask for help.
> 
> The little test program below is intended to paint a blue square on a
> white background.  When run, however, the center square shows up in
> black rather than the intended blue.  The print statement seems to
> indicate that blue has RGB values of 20480,20480,63488, even though
> blue is listed as 0,0,255 in my rgb.txt file.  This however seems like
> a minor problem.

One thing to realize is that GDK deals with colors components
as 16 bit ints rather than 8 bit ints. I don't know why it isn't
0,0,65535 though.

> I'd be most appreciative if someone could take a look at the exposure
> handler in the attached test program and give me a hint as to what
> I've done wrong here, or what general approach should be used in
> getting a properly set up GC from a symbolic color name.  TIA.

gdk_color_parse only gets the color definition, to actually allocate
the color, you need to call gdk_color_alloc. (With a colormap)

  GdkColormap colormap = gdk_widget_get_colormap (widgt);
  gdk_color_parse("blue", &blue);
  gdk_color_alloc (colormap, &blue);
  gdk_gc_set_foreground(blu_gc, &blue);

(Untested)

Regards,
                                        Owen

(Yes, it is a confusing area....)



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