|
Am 18.10.07, 08:30 +0200 schrieb Kai-Uwe Behrmann:
> I tried in one of Erco's examples to catch the mouse dragging but never
> see a FL_PUSH event in the derived handle().
> Can someone jump in? The code is attached.
>
> kind regards
> Kai-Uwe Behrmann
> --
> developing for colour management
> www.behrmann.name + www.oyranos.org + www.cinepaint.org
//!c++ `fltk-config --cflags` push.cpp `fltk-config --ldflags` -DTARGET=\"cairoWerkbank\" -o push
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
#include <cstdio>
#define XSIZE 500
#define YSIZE 500
float delay = 1.f/24.f;
class Fl_Cairo_Box : public Fl_Box {
unsigned char pixbuf[YSIZE][XSIZE][3]; // image buffer
// FLTK DRAW METHOD
void draw() {
fl_draw_image((const uchar*)&pixbuf, 0, 0, XSIZE, YSIZE, 3, XSIZE*3);
}
// TIMER CALLBACK: CALLED TO UPDATE THE DRAWING
static void DrawPicture_CB(void *userdata) {
Fl_Cairo_Box *box = (Fl_Cairo_Box*)userdata;
box->DrawPicture();
Fl::repeat_timeout(delay, DrawPicture_CB, userdata);
}
public:
// CTOR
Fl_Cairo_Box(int x, int y, int w, int h) : Fl_Box(x,y,w,h) {
DrawPicture(); // show first drawing
// Start timer updating
Fl::add_timeout(delay, DrawPicture_CB, (void*)this);
}
// PLOT A PIXEL AS AN RGB COLOR INTO THE PIXEL BUFFER
void PlotPixel(int x, int y, unsigned char r, unsigned char g, unsigned char b) {
pixbuf[y][x][0] = r;
pixbuf[y][x][1] = g;
pixbuf[y][x][2] = b;
}
// MAKE A NEW PICTURE IN THE PIXEL BUFFER, SCHEDULE FLTK TO DRAW IT
void DrawPicture() {
static unsigned char drawcount = 0;
for ( int x=0; x<XSIZE; x++ )
for ( int y=0; y<XSIZE; y++ )
PlotPixel(x, y, x+drawcount, y+drawcount, x+y+drawcount);
++drawcount;
window()->redraw();
}
int e, ox, oy, dx, dy;
int handle(int event) {
e = event;
switch(e) {
case FL_PUSH:
printf("FL_PUSH\n");
ox = x() - Fl::event_x();
oy = y() - Fl::event_y();
return (1);
case FL_RELEASE:
printf("FL_RELEASE\n");
return (1);
case FL_DRAG:
printf("FL_DRAG\n");
dx = ox+Fl::event_x();
dy = oy+Fl::event_y();
return (1);
}
int ret = Fl_Box::handle(e);
return ret;
}
};
int
main (int argc, char *argv[])
{
int w = XSIZE,
h = YSIZE;
Fl::get_system_colors();
Fl_Double_Window *win = new Fl_Double_Window( w, h, TARGET );
Fl_Group *g = new Fl_Group(0,h,w,100);
Fl_Cairo_Box * cairo_box = new Fl_Cairo_Box(0,0,w,h);
cairo_box->box(FL_FLAT_BOX);
g->end();
g->resizable(cairo_box);
win->end();
win->resizable(g);
win->show((int)argc, (char**)argv);
Fl::run();
return 0;
}
[ Direct Link to Message ] | |