DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2257
Version: 1.3-current





Link: http://www.fltk.org/str.php?L2257
Version: 1.3-current
// offscreen-grab.cxx
// fltk-config --compile offscreen-grab.cxx
#include <FL/Fl.H>
#include <FL/x.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Scroll.H>
#include <Fl/fl_draw.h>

#include "write_png.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);
}

/*****************************************************************************/
uchar *data_p = NULL;

static void cb_bt_grab(Fl_Button*, void*)
{
        if(offscr) { // offscreen exists, grab something
                if(data_p){
                        delete[] data_p;
                        data_p = NULL;
                }
                fl_begin_offscreen(offscr); /* Open the offscreen context for 
reading */

                data_p = fl_read_image(data_p, 0, 0, offscrW, offscrH, 0);

                write_png("Test2.png", data_p, offscrW, offscrH, 3, 
"meta-data", "comment");

                fl_end_offscreen(); // close the offscreen context
        }
} // cb_bt_grab

/*****************************************************************************/
int main(int argc, char **argv) {
        Fl_Double_Window *main_win = new Fl_Double_Window(450, 430, 
"Fl_Offscreen group test");
        main_win->begin();

        Fl_Button *grab_bt = new Fl_Button(405, 405, 40, 20, "Grab");
        grab_bt->callback((Fl_Callback*)cb_bt_grab);


        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);
        int a = 40, b = 40;
        Fl_Button *b0;

        while ((a + 60) < offscrW)
        {
                b0 = new Fl_Button( a, b, 60, 60, "BUTTON");
                a += 60;
                b += 60;
        }
        osg->end();
        scroller->end();
        main_win->end();
        main_win->resizable(scroller);
        main_win->show(argc, argv);
        return Fl::run( );
}

/* end of file */
_______________________________________________
fltk-bugs mailing list
fltk-bugs@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to