Below, a version of what I was proposing deriving from Fl_Group as a  
container widget to hold all the other widgets to be rendered into  
the offscreen context.

With this approach, the only derived widget is the "offscreen_group"  
class, derived simply from Fl_Group.
All other widgets operate totally conventionally.

Note that the buttons are actually rendered into the offscreen,  
although they appear on screen and are fully functional (if you doubt  
that, comment out the call to fl_copy_offscreen(0, 0, wo, ho, offscr,  
0, 0); and see what happens!)

I think this was the effect that Fabio was aiming for?

I haven't actually checked the offscreen to see that all the widgets  
(even the non-visible ones) are fully rendered, I assume they are,  
but if not then presumably judicious use of fl_no_clip() would  
resolve that.

---------------
// offscreen-group.cxx
// fltk-config --compile offscreen-group.cxx
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Scroll.H>
#include <FL/x.H>

Fl_Offscreen offscr = 0;
int offscrW = 750;
int offscrH = 750;

class offscreen_group : public Fl_Group {
protected:
        void draw( );
public:
         offscreen_group(int X, int Y, int W, int H) :
         Fl_Group(X,Y,W,H) { }
};

void offscreen_group::draw() {
        int wo = w();
        int ho = h();
        if (!offscr) offscr = fl_create_offscreen(offscrW, offscrH);
        if(!offscr) return; // create must have failed!
        fl_begin_offscreen(offscr);
        // draw the widget hierarchy of this group into the offscreen
        Fl_Group::draw();
        fl_end_offscreen();
        // copy the offscreen back onto this window...
        fl_copy_offscreen(0, 0, wo, ho, offscr, 0, 0);
}

int main(int argc, char **argv) {
        Fl_Double_Window *main_win = new Fl_Double_Window(400, 400,  
"Fl_Offscreen group test");
        main_win->begin();
          Fl_Scroll *scroller = new Fl_Scroll(0,0,400,400);
          scroller->begin();
            offscreen_group *osg = new offscreen_group(0, 0, offscrW, offscrH);
            osg->begin();
             osg->box(FL_FLAT_BOX);
             Fl_Button *b0 = new Fl_Button( 40,  40, 60, 60, "BUTTON");
             Fl_Button *b1 = new Fl_Button(100, 100, 60, 60, "BUTTON");
             Fl_Button *b2 = new Fl_Button(160, 160, 60, 60, "BUTTON");
             Fl_Button *b3 = new Fl_Button(220, 220, 60, 60, "BUTTON");
             Fl_Button *b4 = new Fl_Button(280, 280, 60, 60, "BUTTON");
            osg->end();
          scroller->end();
        main_win->end();
        main_win->resizable(scroller);
        main_win->show(argc, argv);
        return Fl::run( );
}

/* end of file */
----------
Ian


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

Reply via email to