Re: Colors and GDK, this the best way?
- From: Eric Harlow <linuxgeek yahoo com>
- To: gtk-list redhat com
- Subject: Re: Colors and GDK, this the best way?
- Date: Sun, 20 Sep 1998 18:48:45 -0700 (PDT)
Situation:
I have a drawing area (drawing_area) that I'm trying to create
colorful drawings in. I want to create a few gc's using different
colors so I don't have to recreate them over and over again as I need
them.
In doing so, I create a "GetPen" routine that I pass the color
information and get a gc. It's currently called from the
configure_event so I assume that my drawing area is almost ready for
drawing. I do no drawing in the configure event though. My existing
routine works - the new one fails. I like the new one because it's
shorter. I'm using 1.0.4 GTK.
I'm new to GDK and would appreciate some enlightment on my mistakes.
(Get out the spotlight. <g>)
My current routine to get a color gc is as follows:
GdkGC *GetPen (int nRed, int nGreen, int nBlue)
{
GtkStyle *style;
GdkGCValuesMask gc_values_mask;
GdkGCValues gc_values;
GdkGC *gc;
style = drawing_area->style;
gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_FONT;
gc_values.foreground.red = nRed;
gc_values.foreground.blue = nGreen;
gc_values.foreground.green = nBlue;
gdk_color_alloc (style->colormap, &gc_values.foreground);
gc = gtk_gc_get (style->depth,
style->colormap,
&gc_values,
gc_values_mask);
return (gc);
}
Using the code that was sent to me I recreated the routine as:
GdkGC *GetPen (int nRed, int nGreen, int nBlue)
{
GdkColor *c;
GdkGC *gc;
c = (GdkColor *) malloc (sizeof (GdkColor));
c->red = nRed;
c->green = nGreen;
c->blue = nBlue;
gdk_color_alloc (gdk_colormap_get_system (), c);
gc = (GdkGC *) malloc (sizeof (GdkGC));
gdk_gc_set_foreground (gc, c);
return (gc);
}
---Havoc Pennington <rhpennin@midway.uchicago.edu> wrote:
>
>
> On Sun, 20 Sep 1998, Eric Harlow wrote:
> >
> > Didn't work. Dies in XSetForeground.
> >
> > called from gdk_gc_set_foreground.
> >
>
> You're probably doing something else wrong. Maybe send along more
info.
>
> Havoc
>
>
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com <
/dev/null
>
>
_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]