I am late to this discussion and did not follow it (so forget my
ignorance), but why the offscreen drawing needs to be within draw (so it
is called during Fl::flush()) and not the other way around? I thought
that you can draw to the ofscreen at any time. I would make some
function which can be called from some callback on any widget (usually a
group which encapsulates what do you want to draw), no subclassing required:
// Function creates an RGB image with defined resolution w and h.
// If w or h is zero then current size of the widget is used.
// The returned buffer should be delete[](d)
// after uhe user is done with it.
unsigned char * fl_create_widget_image(Fl_Widget * widget, int w=0, int
h=0){
// Might not be necessary but assures that there is no
// partial/user damage which could restrict the explicit
// call of widget->draw() later - see below
Fl::flush()
// storing recent widget size:
int X = widget->x();
int Y = widget->y();
int W = widget->w();
int H = widget->h();
if(!w) w = W;
if(!h) h = H;
Fl_Offscreen o = fl_ctreate_offscreen(w, h);
fl_begin_offscreen(o);
// placing the widget so that it covers the offscreen dimentions
widget->resize(0, 0, w, h);
// Overparanoya? Assuring that the widget is really, really drawn
// even with some stupid custom damage conditional drawings
widget->redraw();
widget->draw() // What a joy draw() is public!
// Creating an RGB buffer and reading the data
// from the offscreen to it
unsigned char * rgb = fl_read_image(0, 0, 0, w, h, 0);
fl_end_offscreem()
fl_delete_offscreen(o); // cleanup
// setting back the widget placement
widget->resize(X, Y, W, H);
// We can clear damage because we have flushed
// the screen at the beginning
widget->clear_damage();
return rgb;
}
DISCLAIMER: code not tested.
R.
Fabio Bracci wrote:
>> 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.
>>
>>
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk