On 4 Feb 2009, at 17:28, Fabio Bracci wrote:
>
> This program just produces either a black window if  
> Fl_Double_Window::draw( ) is commented out, or a grey one otherwise.
> I'm pretty unsure about how to use fl_copy_offscreen, but maybe my  
> mistake is elsewhere ... why don't I get a nice black square in the  
> middle of the window?


This amended version does what I *think* you intended? (Word-wrapping  
by my email permitting, of course!)

In general, however, I'd caution against deriving from a window type.  
If all you need is a "drawing canvas" then deriving from Fl_Box is a  
safer bet, and just have a regular Fl_Double_Window as the outer  
container widget.

However, if I understand correctly, you specifically want to make a  
container widget? You want to render a complete hierarchy of fltk  
widgets into the offscreen, not just regular drawing calls? Is that  
correct?
I think using Fl_Group as a base to derive from is probably a good  
place to start in that case.

Also, it occurs to me that fluid includes a mechanism for capturing  
the widgets as they are displayed on screen (for its print  
mechanism.) How is that implemented? Perhaps that is relevant to your  
problem?


-----------------
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
#include <FL/x.H>
#include <FL/Fl_Double_Window.H>

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

void drawOffscreen( Fl_Double_Window *aWin ) {

        int x = aWin->x( );
        int y = aWin->y( );
        int w = aWin->w( );
        int h = aWin->h( );

        if (!offscr) offscr = fl_create_offscreen( offscrW, offscrH );

        fl_begin_offscreen( offscr );

        fl_color( FL_BLACK );
        fl_rectf( 0, 0, w/2, h/2 );

        fl_end_offscreen( );

        fl_copy_offscreen( x, y, offscrW, offscrH, offscr, 0, 0 );
}

class MyWin : public Fl_Double_Window {
protected:

   void draw( ) {
     drawOffscreen( this );
   }
public:

   MyWin( int a, int b, char const *label = "Fl_Offscreen test" ) :
   Fl_Double_Window( a, b, label ) { }
};

int main( ) {
   MyWin *aWin = new MyWin( 400, 400, "Fl_Offscreen test" );
   aWin->resizable( );
   aWin->show( );

   return Fl::run( );
}

/* end of file */

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

Reply via email to