Re: forcing immediate redraw on widget



Am Mo, den 26.04.2004 schrieb Gus Koppel um 23:43:
Marc Santhoff wrote:

How can the immediate redraw of a widget be forced using GTK+ 1.2?

I think the following should work in GTK+ 1.2 and 2.x:

    gtk_widget_queue_draw (widget_to_redraw);
    while (gtk_events_pending ())
        gtk_main_iteration ();

Thank you for answering, although after testing this seems to be only
one half of the solution.

The other half would be to invalidate or mark the widget for
redrawing, so that there are events to process. Apparently changing
the background color on a widget (hscale in this case) does not do it.

Have you included the first half (the call to gtk_widget_queue_draw ())
into your test? Just changing simple attributes isn't enough indeed to
force a widget to be redrawn. gtk_widget_queue_draw () is supposed to do
excatly what you were suggesting: invalidate the the widget for

Yes, i saw that too late. I should have written that it does not work as
expected.

redrawing. See:

http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#gtk-widget-queue-draw
http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#gtk-widget-queue-draw-area

If it still doesn't work using gtk_widget_queue_draw () I suspect either
a deficiency of GTK+ 1.2 or another bug in your program.

I agree. I've posted the code already, but this is what I'm doing:

// declaring one pointer and two color variables
var
        st      : pGtkRcStyle;
        cola, colp      : TGdkColor;
begin

// and try to switch appearance on a hscale

                { swap the visual focus }
                gdk_color_parse(SPEED_COLOR_ACTIVE, @cola);
                gdk_color_parse(SPEED_COLOR_PASSIVE, @colp);

                st := gtk_rc_style_new ();
                
                if (target = 1) then begin
                        gtk_widget_grab_focus(GTK_WIDGET(scales[1]));

// dereferencing a pointer var like "st->bg[]"                  
                        st^.bg[GTK_STATE_ACTIVE] := colp;

// or'ing together style and new bg change
                        st^.color_flags[GTK_STATE_ACTIVE] := st^.color_flags[GTK_STATE_ACTIVE] OR GTK_RC_BG;
                        gtk_widget_modify_style(GTK_WIDGET(scales[0]), st);

After this I've tried several methods of getting the change visible,
starting without or with a definition in an rc file for testing what
color setting looks good on the hscale.

If there is an other way of changing this color I would be glad, but I
could not find a way to switch the style of a widget between to rc-file
definitons.

The goal is to toggle color schemes for active and passive on two
hscales, that used to set some motor speeds. They're xor working, inly
one active at a time.

Marc






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