Verena wrote:
> Hi there,
> 
> I need some help with double buffering.
> I made my own fltk class, extending Widget, with a load of drawing code in 
> the "draw()" method. The instance of this class gets redrawn many times a 
> second, so I get some flickering, which I would like to get rid of.
> I noticed that there is a DoubleBufferWindow class, so that seems like the 
> natural thing to use. But just using that as a superclass to my custom widget 
> doesn't do the trick.
> What else do I need to do to get rid of the flickering? Is there some "swap 
> buffers" method or something that I need to call in draw()?
> Any help greatly appreciated!
> 
>  VA

Glad someone asked about this, because I'm having a similar problem
with the latest 1.1.x snapshot.
I'm just subclassing Fl_Double_Window and overriding the draw() method.
My subclass is basically just a composite widget.  I've been following
the docs but the window just isn't being drawn correctly. Its just
full of garbage, like the buffer hasnt been properly initialized.
Here's the code:



#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/fl_draw.H>

class mywin : public Fl_Double_Window {

public:

     mywin(int x,int y,int w,int h,const char * label = 0)
         : Fl_Double_Window(x,y,w,h,label) {
         box(FL_THIN_UP_BOX);
         color(fl_rgb_color(190,192,190));
     }

     ~mywin() { }

protected:

     void draw();

};

void mywin::draw() {
     Fl_Widget * const * a = array();
     if(damage() == FL_DAMAGE_CHILD) {
         for(int i = children(); i--; a++)
             update_child(**a);
     }
     else if(damage() == FL_DAMAGE_ALL) {
         draw_box(box(),color());
         for(int i = children(); i--; a++)
             draw_child(**a);
     }
     else if(damage() & (FL_DAMAGE_ALL | 1)) {
         // update area 1 ...
     }
}

int main(int argc, char ** argv) {

     mywin * w = new mywin(200,200,200,200,"mywin");
     w->end();

     w->show();

     return Fl::run();
}


Thanks,
David
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to