gtk_widget_modify_fg() problems



Hi everyone,

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.

When the dial is set to a value higher than the danger or critical levels, I want the text to change color. Also when the dial is drawn, I want the ticks past the danger and critical levels to be drawn in a color besides black. For example, look at the tachometer in a car. Too high a reading and you enter the 'red' zone. Currently danger is blue and critical is red on the dial.

Well that's how I would like it to be. I'm working on drawing the ticks in the different color at the moment, and I encounter a problem.

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.

Problem is, when I add this code the expose event function gets called repeatedly, which measurably slows down the rendering of any window using the dial. Thinking it was my code, I tested it on the gtk_dial in the tutorial and managed to replicate the problem, so I assume it's not my code entirely.

What am I not getting, or understanding about this? Here's a code snippet from a modified gtkdial.c, all I'm trying to do here is draw the ticks in red.

static gint
gtk_dial_expose (GtkWidget      *widget,
                 GdkEventExpose *event)
{
...
...
..
Gdkcolor color;
...
...

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 */

I'd appreciate any help on this. I've been going around and around, trying every method I can find to change the colors, I've used GdkGCs (which, by the way, also loop through expose() over and over). I'm just not getting something, hopefully something obvious.

Thanks and I apologize for the long post,

Cheers,

Rikke



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