visible white flash when redrawing a drawingarea

View: New views
6 Messages — Rating Filter:   Alert me  

visible white flash when redrawing a drawingarea

by Chris Dams :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear all,

I have a class that inherits from DrawingArea of which the visible
contents should change a bit after a certain signal occurs. I do this
by connecting this signal to a method that modifies the data
representation of the drawingarea and thereafter calls
on_expose_event(NULL) to redraw the drawing area. This on_expose_event
is my own method that overrides the virtual function on_expose_event
of the class DrawingArea. This seems to work just fine in principle,
but I do notice that sometimes (not always) the redrawing causes a
clearly visible white flash of the DrawingArea. It also happens
sometimes that the white flash only occurs in the upper or lower part
of the DrawingArea. A bit of experimentation with the code leads to
the conclusion that the drawing is at first done invisibly to the user
and that, after the drawing is finished, the visible DrawingArea is
updated to show the new picture. My question is if there is anything I
can do to avoid seeing the white flash, which, I think, is very ugly.
Is this a bug in libgtk?

I use gtkmm version 2.4 that came with my ubuntu installation and
version 7.2.0 of the Xorg X-server.

All the best,
Chris
_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: visible white flash when redrawing a drawingarea

by Chris Wilson-26 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I had this problem a while ago. While the details are a little foggy (wasn't documenting changes as well as I should have, I've gotten better). Instead of calling the on_expose_event, try just invalidating that area.

void myDrawingAreaClass::invalidate()
{
    Glib::RefPtr<Gdk::Window> window = get_window();
    if ( window )
    {
        Gdk::Rectangle r ( 0, 0, get_allocation().get_width(), get_allocation().get_height() );
        window->invalidate_rect ( r, false );
    }
}

I think that's what worked for me.

Sorry if anyone gets this twice.
On Sun, Jun 29, 2008 at 10:00 AM, Chris Dams <chris.dams.nl@gmail.com> wrote:
Dear all,

I have a class that inherits from DrawingArea of which the visible
contents should change a bit after a certain signal occurs. I do this
by connecting this signal to a method that modifies the data
representation of the drawingarea and thereafter calls
on_expose_event(NULL) to redraw the drawing area. This on_expose_event
is my own method that overrides the virtual function on_expose_event
of the class DrawingArea. This seems to work just fine in principle,
but I do notice that sometimes (not always) the redrawing causes a
clearly visible white flash of the DrawingArea. It also happens
sometimes that the white flash only occurs in the upper or lower part
of the DrawingArea. A bit of experimentation with the code leads to
the conclusion that the drawing is at first done invisibly to the user
and that, after the drawing is finished, the visible DrawingArea is
updated to show the new picture. My question is if there is anything I
can do to avoid seeing the white flash, which, I think, is very ugly.
Is this a bug in libgtk?

I use gtkmm version 2.4 that came with my ubuntu installation and
version 7.2.0 of the Xorg X-server.

All the best,
Chris
_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list


_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Parent Message unknown Re: visible white flash when redrawing a drawingarea

by Chris Dams :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear Chris,

2008/6/30 Chris Wilson <christopher dot g dot wilson at gmail dot com>:
> I had this problem a while ago. While the details are a little foggy (wasn't
> documenting changes as well as I should have, I've gotten better). Instead
> of calling the on_expose_event, try just invalidating that area.

Thank you for the hint. This indeed solves the problem for me.

It still puzzles me that such a solution is necessary for such a
simple problem. How could a gtk-newbie ever find this solution on his
own..... very strange really.... makes me wonder if something like Qt
would be more usable.

All the best,
Chris
_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: visible white flash when redrawing a drawingarea

by Chris Wilson-26 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well, there is the example clock program located at http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-drawing-clock-example.html
This has the on_expose_event() and then updates the clock every second by invalidating the drawing area's space on the screen.

Replacing that invalidate block with a call to on_expose_even(NULL) results in the flashing. As I understand it, and someone please correct me if I'm wrong, calling the on_expose_event directly results in two actual calls to the function.

The invalidate simply tells Gtk to redraw the window when it does all the redrawing stuff, typically in the idle handler. Now, you can force it to redraw immediately by calling Gtk::Window::process_all_updates() if you cannot wait for the idle handler.

--Chris

On Mon, Jun 30, 2008 at 2:46 AM, Chris Dams <chris.dams.nl@gmail.com> wrote:
Dear Chris,

2008/6/30 Chris Wilson <christopher dot g dot wilson at gmail dot com>:
> I had this problem a while ago. While the details are a little foggy (wasn't
> documenting changes as well as I should have, I've gotten better). Instead
> of calling the on_expose_event, try just invalidating that area.

Thank you for the hint. This indeed solves the problem for me.

It still puzzles me that such a solution is necessary for such a
simple problem. How could a gtk-newbie ever find this solution on his
own..... very strange really.... makes me wonder if something like Qt
would be more usable.

All the best,
Chris


_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: visible white flash when redrawing a drawingarea

by Dave Foster-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all -

I use the queue_draw() function of Gtk::Widget (http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1Widget.html#63912f0924724c78298882b7c85139b4) to schedule a repaint for my custom DrawingAreas.

Slightly easier than the invalidate business you all have going on in this thread.

dave


_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: visible white flash when redrawing a drawingarea

by Chris Dams :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear Dave,

2008/7/7 Dave Foster <dave.foster@...>:
> I use the queue_draw() function of Gtk::Widget

Thank you! This works very well and it is a lot more straightforward.
Maybe the documentations should mention this method more prominently.

All the best,
Chris
_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list