Gents:

The code below is as naive as it could get. It works correctly under
Windows XP. It also works correctly under Ubuntu Linux *if Compiz is
used*. I also tried this: I used a Windows XP virtual machine and
through SSH ran it in Ubuntu (without Compiz) and it also worked. So,
as somebody hinted, there's a problem with X.

Cheers,

Rodrigo

#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:
        void draw(){
            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){
        }
        void save_pnm(const char *name){
                uchar *buf = new uchar[3*w()*h()];
                redraw();
                Fl::check();
                fl_read_image(buf, 0, 0, w(), h());

                FILE *fp = fopen(name, "w+");
                fprintf(fp, "P6\n%d %d\n255\n", w(), h());
                fwrite((uchar*)buf, w()*h()*3, 1, fp);
                fclose(fp);

                delete buf;

            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();
}

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

Reply via email to