> On 07/01/12 20:51, Greg Ercolano wrote:
> >>    int handle (int e) {
> >>    // DRAW vertical lines
> >>       int ret = Fl_Widget::handle (e);
> >>       switch (e) {
> >>          case FL_PUSH:
> >>             lines++;
> >>             int x1 = x();
> >>             int y1 = y(),  y2 = y()+h()-1;
> >>             fl_line(x1 + 10 * lines, y1, x1 + 10 * lines, y2);
> >
> >     You can't do any drawing functions (like fl_line) inside
> >     an event handler.
> >
> >     The only time you can draw anything is inside draw().
> >
> >     So to do what you want, you have to modify some variables
> >     and call redraw() which will flag FLTK to call draw(),
>
>    Looking at your program, what I think you want is:
>
> #include <FL/Fl.H>
> #include <FL/fl_draw.H>
> #include <FL/Fl_Double_Window.H>
> class DrawX : public Fl_Widget {
> private:
>     int lines;
> public:
>     DrawX(int X, int Y, int W, int H, const char*L=0) : Fl_Widget(X,Y,W,H,L), 
> lines(0) {
>     }
>     void draw() {
>        fl_color(FL_BLACK);
>        int x1 = x();
>        int y1 = y(),  y2 = y()+h()-1;
>        for (int i = 1; i <= lines; i++) {
>            fl_line(x1 + 10 * i, y1, x1 + 10 * i, y2);
>        }
>     }
>     int handle(int e) {
>         int ret = Fl_Widget::handle(e);
>         switch(e) {
>             case FL_PUSH:
>                 lines++;
>                 redraw();     // tells FLTK to schedule redrawing the widget
>                 return(1);
>         }
>         return(ret);
>     }
> };
> int main() {
>     Fl_Double_Window win(200,200,"Draw vertical lines");
>     DrawX draw_x(0, 0, win.w(), win.h());
>     win.resizable(draw_x);
>     win.show();
>     return(Fl::run());
> }
>
>

Now everything works correctly.
I really don't know how to thank you for the help.
Thanks Greg.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to