Ian:
>No, I don't think this is correct - I don't think there is a problem
>with X per se, rather I think your example is (still) slightly wrong.
>
>As I said in earlier posts, you can really only be sure the graphical
>context is correct for you to call fl_read_image() when you are in
>the draw() method of the widget you are trying to sample.
>
>But you persist in calling it from your callback, so you *can not*
>expect it to work correctly.
You mean, like this?
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
#include <FL/fl_draw.H>
#include <FL/x.H>
#include <FL/Fl_File_Chooser.H>
#include <stdlib.h>
#include <stdio.h>
class MyWindow : public Fl_Double_Window {
private:
bool pnm;
const char *pnmname;
Fl_Offscreen off;
void draw(){
if (pnm){
make_current();
damage(FL_DAMAGE_ALL);
for (int i = 0; i < children(); i++)
child(i)->damage(FL_DAMAGE_ALL);
//off = fl_create_offscreen(w(), h());
//fl_begin_offscreen(off);
Fl_Double_Window::draw();
//fl_end_offscreen();
uchar *buf = new uchar[3*w()*h()];
fl_read_image(buf, 0, 0, w(), h());
FILE *fp = fopen(pnmname, "w+");
fprintf(fp, "P6\n%d %d\n255\n", w(), h());
fwrite((uchar*)buf, w()*h()*3, 1, fp);
fclose(fp);
//fl_delete_offscreen(off);
delete buf;
pnm = false;
}
else Fl_Double_Window::draw();
return;
}
public:
MyWindow(int x, int y, int w, int h, const char
*l):Fl_Double_Window(x, y, w, h, l){
pnm = false;
}
void save_pnm(const char *name){
pnmname = name;
pnm = true;
Fl::flush();
redraw();
draw();
Fl::check();
return;
}
};
void wincb(Fl_Widget*, void *w){
MyWindow *win = (MyWindow*)w;
win->save_pnm("fig.pnm");
exit(0);
return;
}
void btncb(Fl_Widget*, void *w){
MyWindow *win = (MyWindow*)w;
Fl_File_Chooser chooser(".", "*.pnm", Fl_File_Chooser::CREATE,
"Save as PNM");
chooser.show();
while(chooser.shown()) Fl::wait();
if (chooser.value() != NULL){
win->save_pnm(chooser.value());
}
return;
}
int main(int argc, char *argv[]){
MyWindow win(10, 10, 200, 100, "Test");
Fl_Button btn(10, 10, win.w() - 20, win.h() - 20, "Save as PNM");
btn.callback(btncb, &win);
win.end();
win.callback(wincb, &win);
win.show();
return Fl::run();
}
The results are the same: Under Windows it works. Under Ubuntu with
Compiz it works. Under Ubuntu, being tunneled to Windows (using Xming)
it works. Under Ubuntu using the standard "Visual Appearance" (that
is, no Compiz) it produces a black area if the window is partially
occluded.
Roman:
Using offscreens has no impact on the problem, I'm afraid. The
documentation states that offscreens can be used anytime and not just
inside the draw() method. However, if fl_read_image can only be used
within the draw() method, subclassing is a must, I think. However,
perhaps I'm missing something.
Rodrigo
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk