function from the widget class.
> >
> > Whenever i wanted to draw the rectangle i could just call
> > myClass.draw(x,y,w,h) ??
>
>       When FLTK wants to draw a widget, it calls the draw() method
>       of each FLTK widget.
>
>       If you derive a class from one of the FLTK widgets
>       and don't define a draw() method of your own, the widget's
>       draw() method will be called. If you DO define a draw() method,
>       yours will be called instead of the class you derive from.
>       So it's up to you to handle drawing the entire widget's area
>       (the entire x()/y()/w()/h() area assigned to the widget).

Thanks for the info, I have tinkered with some code and things are clearer now, 
but i still have some questions.

For the sake of argument lets say i want to fill a window area with
randomly  sized & placed and randomly coloured rectangles.

I found that i can 'pass' arguments to the draw() function by using its 
constructor XYWH and a global value for colour (which is a really poor
hack i would like to find a better solution for)
something like this altered version of Gregs x drawing example is the
best i can come up with so far, but this just seems all wrong,
What would be the best way of repeatedly creating rectangles?
Also the colour assignment seems to be redundant as when the GUI redraws
It just sets all the rectangles to whatever the current value is,
Or did i just imagine that cant rememeber was last night

int gColour;

class DrawBox : public Fl_Widget {
public:
    DrawBox(int X, int Y, int W, int H, const char*L=0) : Fl_Widget(X,Y,W,H,L) {
    }
    void draw() {

        fl_rectf(x(), y(), w(), h(), gColour);
    }
};
int main()
{
    Fl_Double_Window win(200,200);

    gColour = 2;

    int x = 10, y = 10, w = 20, h = 20;

    win.show();

    DrawBox* draw_box = new draw_box(x, y, w, h);
    //loop start
    gColour = 4;
    x = 15;
    y = 15;
    w = 20;
    h = 25;
    DrawBox* draw_box = new draw_box(x, y, w, h);
    //etc but the above in a loop assigning random size, position and colour 
values
    //instead of the hard coded stuff shown.

    return(Fl::run());
}

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

Reply via email to