Re: drawables and refresh rates



Rob Benton wrote:

Andrew E. Makeev wrote:

Before to answer you, we need to know how do you "draw" your circles? The common way is to use expose_event to redraw only those parts of the drawing area that actually were changed. In this case I never seen any flickering in my applications even on Celeron 300Mhz.


Right now I'm using 2 methods. Method A handles the expose event of the Gtk::DrawingArea which then calls method B. Method B is also connected to the value changed signal of both the Gtk::HScale widgets.


Method A looks like this:
----------------------------------------------------------------------
bool MyClass::drawarea_expose_event(GdkEventExpose * e)
{
    Glib::RefPtr<Gdk::Window> window = _drawarea.get_window();
    window->clear();
    draw_circles();
    return true;
}
----------------------------------------------------------------------


I guess, you should to draw everything first time in the constructor, then use GdkEventExpose dimension values to redraw only parts of the drawing area. I am sure that "window->clear()" is the reason you see some flickering. And if you think that it is impossible to calculate what to redraw exactly, you have to "freeze" window updates somehow when redrawing whole picture.

 Method B looks like this:
----------------------------------------------------------------------
void MyClass::draw_circles()
{
    _gc->set_foreground(blue);
    _gc->draw_arc(/* whole circle */);
    _gc->set_foreground(red);
    _gc->draw_arc(/* arc */);
}
----------------------------------------------------------------------

For HScale value changed simple object redrawing may be implemented as following:

set_foreground( blue );
draw_arc( /* arc */ );  /* old values */
/* modify params */
set_foreground( red );
draw_arc( /* arc */ );  /* new values */

Finally,
to get your app faster and smoother you have to redraw minimal parts of your picture in event handlers.

Regards,
-andrew




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