MacArthur, Ian (SELEX GALILEO, UK) schrieb:
>> Now I wonder, how to draw a window taller than screensize:

> I create my own group widget, that draws into the offscreen, and use
> that as my outer window, and also I can grab the "full" oversized
> "window" from the offscreen, of course.

"of course"! You are right, it doesn't work for just one program, but in 
general it works. And I found an easy way to realise a screenshot with 
adjustable resolution and without any subclassing:

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/fl_draw.H>
#include <FL/x.H>
#include "write_png.h"

Fl_Window* pMW= 0;      // Pointer to window for export

void Cb_Bn(Fl_Widget* o, void* v)
{

   enum { ow= 4000, oh= 4000 };
   if (Fl_Offscreen OF=  fl_create_offscreen(ow, oh))
   {
        Fl_Widget* pW= dynamic_cast< Fl_Widget* >(pMW); 
                // Fl_Widget::draw() is public!
        fl_begin_offscreen(OF);
        int x0= pW->x(); int y0= pW->y();
        int w0= pW->w(); int h0= pW->h();
        pW->damage_resize(0, 0, ow, oh);
        pW->draw();     // calls virtual Fl_Window::draw()
        if (unsigned char* pImage= fl_read_image(0, 0, 0, ow, oh, 0))
        {       // Get image
                write_png("/home/ed/temp/test.png", pImage, ow, oh, 3);
                delete[] pImage;
        }
        fl_end_offscreen();
        fl_delete_offscreen(OF);
        pW->resize(x0, y0, w0, h0);
   }
}

int main()
{
        Fl_Window Win(100, 100, 640, 480, "Offscreen Image");
        pMW= &Win;
        Win.resizable(pMW);
        Fl_Button* pB= new Fl_Button(10, 10, 100, 100, "&Export Png");
        pB->callback(Cb_Bn, 0);
        pB->when(FL_WHEN_RELEASE);
        Win.end();
        Win.show();
        return Fl::run();
}

This also works using pointer to groups or widgets, but for these 
pointers it is necessary to use damage_resize(), not resize().

There is an interesting effekt: I went through the program, using the 
debugger and after leaving the routine - after resizing back and forth 
and window was exported - the program resizes back and forth on screen.
I tried to clear_damage() and to do the resize "offscreen" by setting 
x/y to coordinates outside of screen, but it remained to be 0/0.

Okay, it's not a problem, just ugly. Now I will go on to find out, where 
the initial problem comes from...
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to