Re: Drawing area color weirdness help?
- From: Owen Taylor <otaylor redhat com>
- To: "Andrew P. Lentvorski" <andrewl deliverator io com>
- Cc: gtk-list redhat com
- Subject: Re: Drawing area color weirdness help?
- Date: 10 Jan 1999 14:41:52 -0500
"Andrew P. Lentvorski" <andrewl@deliverator.io.com> writes:
> Okay, I created a set of widgets and packed everything together.
> One of the widgets is a GtlDrawingArea. Fine. I attach the expose
> event to the callback function at the bottom of this message.
> Everything comes up fine. It even creates a nice red rectangle.
> Then I resize the window ... urp ... the color in the GtlDrawingArea
> changes to a random color every time I resize it. Yellow .. Green ...
> Blue ... you name it. No particular rhyme or reason.
>
> Why?
>
> I'm assuming that I'm doing something wrong, but I have no idea what.
>
> Also, how do you create a GdkColor from an RGB value?
>
> Thanks,
> Andy Lentvorski
>
> Expose callback function starts here:
> static gint
> wave_expose_event(GtkWidget *widget, GdkEventExpose *event)
> {
> gint width,height;
> GdkColor foreground;
> GdkGC *mygc;
>
> if (!gdk_color_parse("red",&foreground))
> {
> fprintf(stderr,"Failed to parse color\n");
> }
>
> gdk_window_get_size(widget->window,&width,&height);
>
> if (!(mygc = gdk_gc_new(widget->window)))
> {
> fprintf(stderr,"Failed to allocate GC\n");
> }
>
> gdk_gc_set_foreground(mygc,&foreground);
gdk_color_parse() does not allocate the color, it just
fills in the .red .green and .blue fields. It is
a coincidence you got Red the first time.
The values for red, green and blue range from
0-65535.
To use a color, you must first fill in the red,
green and blue fields, then call gdk_color_alloc().
(You probably don't want to parse and allocate the color
on each expose event though - best to do that only
once.)
I think that should answer your other question as well.
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]