Re: gtk_widget_modify_fg() problems



"Rikke D. Giles" <rgiles telebyte com> writes:

I'm developing a complicated dial widget to use in a weather analysis
program.  The widget goes beyond the dial widget in the gtk tutorial,
in that you can set the upper and lower boundaries, set 'danger' and
'critical' levels.  It uses a pangolayout to show a title, units (such
as m/s or joules/hour or whatever) and the current dial reading.  It's
not sensitive, it's meant for data output as opposed to input.  It
also uses a pixmap for rendering, eliminating screen flicker and so
on.

That is not necessary, because as long as you only draw in an expose
handler, gtk+ will automatically redirect the drawing to a
pixmap. Then when the expose handler finishes, gtk+ will draw the
pixmap to the screen. In other words, gtk+ automatically double
buffers the drawing as long as it happens in an expose handler.

I'm trying to change the color in the dial_expose() function by using:

Gdkcolor color;

gdk_parse_color("red", color);
gtk_widget_modify_fg(widget, &color);

this is straight from the mini-FAQ on color in GTK.

You are probably not understanding gtk_widget_modify_fg(). You can't
call that function out of an expose handler.

Conceptually gtk_widget_modify_fg(widget, NULL) means "set the
foreground color of the widget, permanently", which is something else
than "temporarily change the color of the fg_gc". When you call
gtk_widget_modify_fg() it means a property of the widget has changed,
so the widget needs to be redrawn. This means the expose event will be
emitted again, causing the loop.

gdk_parse_color("red", color);
gtk_widget_modify_fg(widget, &color);
gdk_draw_line (widget->window,
                      widget->style->fg_gc[widget->state],
                      xc + c*(dial->radius - tick_length),
                      yc - s*(dial->radius - tick_length),
                      xc + c*dial->radius,
                      yc - s*dial->radius);
....
...
...
gtk_widget_modify_fg(widget, NULL);  /* turn back to normal color */

The way to do what you want is to create a GdkGC and make it draw in
red:

    GdkGC *red_gc;
    GdkColor color = { 0, 65535, 0, 0 };
    red_gc = gdk_gc_new (widget->window);
    gdk_gc_set_rgb_fg_color (red_gc, &color);

    gdk_draw_line (widget->window, red_gc, ...);

    g_object_unref (G_OBJECT (red_gc));


Søren



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