Re: Colours...
- From: Peter Zelezny <pzel dodo com au>
- To: gtk-app-devel-list gnome org
- Subject: Re: Colours...
- Date: Mon, 3 Jun 2002 14:03:13 +1000
On Mon, 3 Jun 2002 00:52:47 +0100
Ian Molton <spyro armlinux org> wrote:
2) Can someone explain the horrible mess that seems to obscure choosing
a simple colour?
I want to modify the (gtk2) scribble example so that I can draw a chart
on the backing pixmap. to do this, I thought I would create my own GC
with its own foreground colour, and simply draw a line.
well, I thought I'd start simple and simply change the colour of the
'foreground' (the rectangle used to clear the pixmap). here is my
attempt, which does not work:
----------------------------------------------------------------
static GdkPixmap *pixmap = NULL;
/* Create a new backing pixmap of the appropriate size */
static gint configure_event( GtkWidget *widget,
GdkEventConfigure *event )
{
GdkGC *backgroundgc;
GdkColor colour;
GdkVisual *visual;
GdkColormap *colourmap;
if (pixmap)
g_object_unref (pixmap);
pixmap = gdk_pixmap_new (widget->window,
widget->allocation.width,
widget->allocation.height,
-1);
backgroundgc = gdk_gc_new(pixmap);
gdk_color_parse("004400", &colour);
visual = gdk_visual_get_system();
colourmap = gdk_colormap_new(visual, TRUE);
gdk_colormap_alloc_color(colourmap, &colour, FALSE, TRUE);
gdk_gc_set_foreground(backgroundgc, &colour);
gdk_draw_rectangle (pixmap,
/*widget->style->white_gc,*/
backgroundgc,
TRUE,
0, 0,
widget->allocation.width,
widget->allocation.height);
return TRUE;
}
You probably need to copy your pixmap onto the screen (i.e. widget->window).
Otherwise all your drawing is in memory only.
I think you can also use the colormap of your widget when allocating
the color, rather than creating a new one.
colormap = gtk_widget_get_colormap (widget);
gdk_colormap_alloc_color (colormap, &colour, TRUE, TRUE);
--
Peter Zelezny.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]