Hi,
I am writing a program that uses fltk 1.3.
Basically I want to make a graphic that is updated every time I click on it.
The problem is :
If I move a window of another program over my program window,
the graphic is not redrawn.
This problem appears with Fl_Double_Window.
If I use single buffer the program works fine, but I need use double buffer.
Can some one tell me what the problem could be?
Below I give you an example and I would greatly appreciate if anyone can help
me.
Thank you very much
Nick
#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
#define MAIN_WINDOW_H 300 // high of the Main Window
#define MAIN_WINDOW_W 500 // width of the Main Window
#define BOX_SIZE_H 200 // high of the inner BOX
#define BOX_SIZE_W 400 // width of the inner BOX
#define ARRAY_SIZE 1000 // buffer size
// distance between the XXX margin and the BOX
#define TOP_MARGIN 50
#define LEFT_MARGIN 35
// Max and Min values of the vertical axi
#define MIN_AXIS_Y -2
#define MAX_AXIS_Y 2
//********************************************
///\class Data
///\ Points to draw
//********************************************
class Data
{
private:
int buffer [ARRAY_SIZE];
int last;
public:
Data (void): last (0) {make_square ();};
int get_y (void) {last = (last + 1) % ARRAY_SIZE; return buffer [last]; };
int get_y (int x) {return buffer [x]; };
int get_last (void) {return last;};
void make_square (void) {for (int i = 0; i < ARRAY_SIZE ; buffer [i] = i
% 10 > 4 ? 1 : -1, i++);};
};
//********************************************
///\class FD_plot
///\ Plot window container
//********************************************
class FD_plot
{
public:
Fl_Double_Window *form;
FD_plot (void) {form = new Fl_Double_Window (MAIN_WINDOW_W,
MAIN_WINDOW_H);};
//Fl_Window *form;
//FD_plot (void) {form = new Fl_Window (MAIN_WINDOW_H, MAIN_WINDOW_W);};
void del (void) { form->hide (); Fl::delete_widget (form);}
~FD_plot (void) {del ();};
};
class Fl_Graphic : public Fl_Box
{
public:
Data point;
int pushes; ///< Number of clicks over white area (graphic)
double scale_x; ///< Horizontal plot scale
double scale_y; ///< Vertical plot scale
int lastx; ///< X coordinate of last point drawn
int lasty; ///< Y coordinate of last point drawn
int x0, y0, x1, y1; ///< Effective drawing area coordinates
Fl_Graphic (int x,int y,int w,int h,const char *l = 0);
void calc_scales (void);
virtual int handle(int);
void draw_all_points (void);
void resize(int X,int Y,int W,int H) { X = x (); Fl_Box::resize (X,Y,W,H); };
void draw_point (void);
virtual void draw ();
};
//*************************************************************
// class Fl_Graphic - Definition of the member functions
//*************************************************************
void Fl_Graphic::calc_scales (void)
///\ Calculates drawing bounds and scales according to window size
{
x0 = x () ;
y0 = y () ;
x1 = x () + w ();
y1 = y () + h ();
scale_y = (float) (y1 - y0) / (MIN_AXIS_Y - MAX_AXIS_Y);
}
void Fl_Graphic::draw_all_points (void)
///\ draws all points of the graphic
{
int k, xx, yy;
double currenty;
fl_push_clip (x0, y0, x1 - x0, y1 - y0);
fl_color (FL_RED);
lastx = x0;
lasty = y0;
for ( k = 0; k <= pushes + 1; k++)
{
xx = (int)(x0 + k);
currenty = point.get_y (k);
yy = (int)(y1 + (currenty - -2) * scale_y);
fl_line (lastx, lasty, xx, yy);
lastx = xx;
lasty = yy;
}
printf ("Redrawing all points...last coord x=%d, y=%d\n", lastx, lasty);
fl_pop_clip ();
}
void Fl_Graphic::draw_point (void)
///\ draw the last point
{
int xx, yy;
double currenty, delta_history;
fl_push_clip (x0, y0, x1 - x0, y1 - y0);
fl_color (FL_GREEN);
xx = (int)(x0 + point.get_last ());
currenty = point.get_y ();
yy = (int)(y1 + (currenty - (-2)) * scale_y);
fl_line (lastx, lasty, xx, yy);
lastx = xx;
lasty = yy;
printf ("Redrawing one point...coord x=%d, y=%d\n", lastx, lasty);
fl_pop_clip ();
}
Fl_Graphic::Fl_Graphic (int x,int y,int w,int h,const char *l) : Fl_Box (x, y,
w, h, l)
///\ Constructor
{
pushes = 0;
lastx = x;
lasty = y;
}
void Fl_Graphic::draw ()
///\ draw method
{
// Draw the graphic area
fl_color (FL_WHITE); // background color
fl_rectf (x (), y (), w (), h ());
fl_color (FL_BLACK); // contour color
fl_rect (x (), y (), w (), h ());
// draw all points
calc_scales ();
draw_all_points ();
}
int Fl_Graphic::handle (int i)
///\Event handler
{
switch (i)
{
case FL_PUSH:
pushes++;
draw_point ();
return (i);
}
return (0);
}
int main (void)
{
FD_plot *ui = new FD_plot;
Fl_Graphic *ch;
ui->form->begin ();
ch = new Fl_Graphic (LEFT_MARGIN,TOP_MARGIN, BOX_SIZE_W, BOX_SIZE_H);
ui->form->label ("MyGraphic_ Click over white area");
ui->form->end ();
ui->form->resizable (ui->form);
ui->form->show ();
Fl::run ();
return (0);
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk