On 29.06.2011 14:39, Paul R wrote:

> The update screen function looks like this:
>
> (this is not changed from the version that used fl_rectf, it worked
> fine with that, but fails to do anything in my polygon version)
>
> I
> void LifeWorld::DrawWorld()
> {
>      for(int count = 0; count<  cellGrp->children(); count++)
>      {
>          if(cells[count].LIVE == true)
>          {
>              cellGrp->child(count)->color(Fl_Color(fl_color(68));
>          }
>          else
>          {
>              cellGrp->child(count)->color(fl_color(25));
>          }
>      }
>      cellGrp->redraw();
> }

So it seems that you update the widget's color() value, but you
never used this in your draw() method posted earlier in this thread.

I can see at least three ways to solve this:

(1) Modify your draw() method:

     void draw()
       {
         fill_color = color();  // use the widget's color()
         if (fill_color == 25)  // note: NOT fill_colour !
           line_color = 25;
         else
           line_color = 0;

         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);
       }

This is not very elegant, because it (re)sets the widget's private
variables on every draw() call, but this is close to your existing
code.

(2) Override the color() method. Add this to your class declaration:

     void color(Fl_Color c)
     {
       Fl_Widget::color(c);
       fill_color = c;
       line_color = <...calculated value...>;
     }

This would be more consistent with FLTK's usual setter methods, but
may need some casts (or you could change fill_color and line_color to
Fl_Color types).

(3) Add your own color setting methods for fill_color and line_color.
Left as an exercise ;-)

This does only address setting the color values in your widgets.
I don't know if your drawing functions would do what you like, but
setting the colors should be the first step.

But I could be completely wrong with this since you didn't show all
the relevant code to us. If this doesn't solve your problem, please
elaborate on what you expect and what you (don't) get from your
code. E.g. do the cells draw correctly when created, but don't change
their colors during the runtime, or ... ?

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

Reply via email to