In the little program below I added a zoom-in function. It works partially but
I could not find the right way to correctly update the range of the scrollbars
during zoom in. Also the redrawing after the first zoom in does not work very
well.
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Scroll.H>
#include <FL/Fl_Button.H>
#include <iostream>
using namespace std;
class Draw : public Fl_Widget {
public:
Draw(long int x, long int y, long int w, long int h, const char *l=0) :
Fl_Widget(x, y ,w ,h, l) {}
static int zoom;
protected:
void draw() {
fl_color(FL_RED);
fl_rectf(zoom*x(), zoom*y(), zoom*w(), zoom*h());
fl_color(FL_BLACK);
fl_rect(zoom*x(), zoom*y(), zoom*w(), zoom*h());
}
};
int Draw::zoom = 1;
static void zoomincb(Fl_Widget *w, void *userdata) {
cout << "zoomincb: " << Draw::zoom <<endl;
Draw::zoom++;
Fl::redraw();
}
static void zoomoutcb(Fl_Widget *w, void *userdata) {
cout << "zoomoutcb: " << Draw::zoom <<endl;
if(Draw::zoom>1)
Draw::zoom--;
Fl::redraw();
}
int main() {
Fl_Double_Window win(800,800);
Fl_Scroll scroll(0,0,win.w(),win.h()-50);
Draw *draw;
int x,y,w,h;
w = 20;
h = 30;
for(x=0;x<800;x=x+w) {
for(y=0;y<800;y=y+h) {
draw = new Draw((x), (y), (w), (h));
}
}
scroll.end();
win.resizable(scroll);
Fl_Box box(0,win.h()-50,win.w(),50);
Fl_Button zoomin(0,win.h()-40,100,35,"Zoom In");
zoomin.callback(zoomincb);
Fl_Button zoomout(150,win.h()-40,100,35,"Zoom Out");
zoomout.callback(zoomoutcb);
win.end();
win.show();
return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk