> Now I know how to produce the error (using xfce) I might try a few
> tests to see if I can see what happens - time permitting!
Sorry all, this post is going to be stupidly long...
Anyway, attached below are two files, simplified versions of
Rodrigo's example, one using the "offscreen" mode and the other
simply grabbing from a double_window...
Both appear to work correctly (for me) under gnome with/without
compiz, and under xfce. And under OSX, for what that is worth...
All I did was simplify the code that Rodrigo had, sort out the
ordering of events and ensure the target filename was stored. It is
not obvious to me that these changes should really have made much
difference to the "double window" case, but there was a slight
ordering bug in the offscreen case.
Either way, (Rodrigo et al) try the attached code; does it now work
for you?
------------------
// Basic double window example
#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;
char pnmname[256];
void draw(){
if (pnm){
Fl_Double_Window::draw();
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);
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){
// need to copy name, as it goes out of scope before I
use it...
strncpy(pnmname, name, 256);
pnm = true;
redraw();
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.show(argc, argv);
return Fl::run();
}
/* end of file */
-----------------
// offscreen grab example
#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;
char pnmname[256];
Fl_Offscreen off;
void draw(){
if (pnm){
off = fl_create_offscreen(w(), h());
fl_begin_offscreen(off);
Fl_Double_Window::draw();
uchar *buf = new uchar[3*w()*h()];
fl_read_image(buf, 0, 0, w(), h());
fl_end_offscreen();
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){
// need to copy name, as it goes out of scope before I
use it...
strncpy(pnmname, name, 256);
pnm = true;
redraw();
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.show(argc, argv);
return Fl::run();
}
/* end of file */
-------
Cheers,
--
Ian
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk