> > I think you might be able to make your approach work by starting the
> > offscreen, then clearing your boolean and directly calling
> the widget
> > ::draw() method again.
> > Then, when that returns, reset the boolean and end the offscreen.
> > Well, maybe that can work.
>
> Well, I was trying exactly this, to trigger draw() at the
> group widget holding the complex structure, but I get a weird
> compile error ...
Hmm, odd. I would expect (but have not tried) that the draw method
should be able to recursively call itself in that case. I wonder why it
fails?
Might be worth posting the error message you get, someone might know
what it pertains to.
> Thanx! I couldn't figure it out.
> btw, int X, int Y, are the coordinates where fl_read_image
> starts to read and int W, int H are the width and height, I
> suppose ... documentation bug?
> well, this will be the pixmap then. but what is it then a
> Fl_Offscreen variable? this is just typed as ulong, I can't
> figure out its real meaning
Here's a worked example... CAUTION: This WILL NOT actually work, as it
assumes the existence of my PNG helper library to write the grabbed data
to a PNG file, so you'll need to substitute your own data storage
mechanism in place of that.
(Provide a function to replace my write_png() function )
--------------
// 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 */
----------
Ian
SELEX Sensors and Airborne Systems Limited
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14
3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk