Colormaps?



After roughly two days peering into source code I've only become
increasingly confused as to how to handle colors using gtk/gdk...

I'm trying to draw a bunch of things onto a GdkPixmap (which then gets
drawn onto a GtkDrawingArea) and I need to be able to set the color with
which I'm drawing. (eg. draw a red rectangle at point blah.) I get the 
impression I need to create a graphics context with the appropriate color
set up, but there seems to be no clear way in which to do this. I can use
the GtkStyle structure from the GtkDrawingArea to get myself a couple of
colors to draw with, but this is by no means adequate, since there are
only a few available.... Looking the code now, it seems I could create a
GC with gdk_gc_new_with_values, and that way I'd need to initialize the
GdkGCValues struct with the requisite information.... One of these is the
GdkColormap... Now would I be right in saying that I'm going to have to
handle the Colormap differently depending on whether or not I'm using an
8-bit display? Or since I'm only likely to be using 10-15 new colors, is
it pretty safe to just call gdk_colormap_get_system()? Or will that break
on black and white monitors? Or would I only need to handle 8-bit displays
differently if I wanted to make the window install a new colormap,
otherwise just calling gdk_colormap_get_system() without much caring
whether the requisite color was available....

What people like me really need is just the ability to have a java-like
system where there are a bunch of predefined colors which any old fool can
use, since the above seems like a _HUGE_ amount of work just to set the
pen color for drawing a flipping rectangle!

On a different note, what is the GtkPreview widget actually _for_? From
what little I've gleaned from the source code, it seems to be simulating a
raster scan device in some way, but I can't even work out how it gets the
pixels onto the screen yet... (gtk_preview_draw_row just calls 
gtk_color_24 [or whatever], which just fills up an array with a bunch of
colors then that's it...)

Apologies if my questions are in some way dumb, but I'm trying to teach
myself Gtk/Gdk/Xlib all in one go and my head is starting to hurt even
after only a couple of days of this stuff...


Mark


              -- Mark Hulme-Jones <ceemahj@cee.hw.ac.uk> --
                --  http://www.cee.hw.ac.uk/~ceemahj   --



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