The class is OK at least for the code I can see, but many relevant parts are
missing. Most importantly, whe and how do you change the color of the widget?
Do you call widget->redraw() after changing the color? And do you return to the
main loop, so the actual drawing can take place?
On 29.06.2011, at 13:35, Paul R wrote:
>
> 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) {
>
> //assign a value to fill_colour here...
> if(fill_colour == 25) //will be consts when colours are decided..!
You are setting the line_color based on a fill_color that was not set
> line_color = 25;
> else
> line_color = 0;
>
> SetDims(X,Y,W,H);
> }
> void draw()
> {
> fl_color(fill_color);
> fl_polygon(x,y,x1,y1,x2,y2,x3,y3); //four sided polgon
> fl_color(line_color);
> fl_yxline(x,y,y2);
> }
That looks ok, but you could also use fl_rectf()to draw a rectangle. Also, your
x,y,x1,y1,x2,y2,x3,y3 coordintaes do not update in case the widget changes
position or size (in a resizable window, for example).
>
>
> private:
> int fill_color;
> int line_color;
> int x, x1, x2, x3;
> int y, y1, y2, y3;
> void SetDims(int xpos, int ypos, int wid, int hgt)
> {
> x = xpos + (wid * 0.5);
> y = ypos;
> x1 = xpos + wid;
> y1 = ypos + (hgt * 0.75);
> x2 = x; //reuse the 'halfway accross widget' value already calculated
> y2 = ypos + hgt;
> x3 = xpos;
> y3 = y1; //reuse the '2thirds of way down widget' value }
> };
>
> _______________________________________________
> fltk mailing list
> [email protected]
> http://lists.easysw.com/mailman/listinfo/fltk
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk