2

I am using FLTK to create a GUI and I have to draw onto the screen some polygons (shapes).

From their documentation of fl_complex_polygon:

Start and end drawing a convex filled polygon.

The problem? The polygon is not filled, but only the stroke is displayed. How can I make the polygon a filled shape?

My code looks like this:

fl_color(FL_RED);
fl_begin_complex_polygon();
fl_line(mX,mY, x, y);
....
fl_line(mX,mY, x, y);
fl_end_complex_polygon();

Other related question: How can I redraw a FL_BOX? Do I have to draw a blank (background-colored) rectangle over it, or is there some FL_BOX::clear() function?

XCS
  • 27,244
  • 26
  • 101
  • 151

1 Answers1

2

Re: the filled polygon. The polygon is made up of vertices: not of lines. It doesn't know about lines. Use fl_vertex instead of fl_line.

Re: fl_box There are two fl_boxes, depending on case.

fl_box sets the box type Fl_Box from Fl_Box.H draws a box. The redraw code will automatically redraw it if it is damaged. Say the widget is called box. Call box->damage(FL_USER1) to force a redraw.

For more tricks, have a look at http://seriss.com/people/erco/fltk/

cup
  • 7,589
  • 4
  • 19
  • 42
  • Thank you, the polygon works. If I `use this->damage()` it will only draw what I have inside my function, and not the label or other default box drawing. Isn't possible to also trigger the Fl_Box redraw, to draw the labels for example. If I add `Fl_Box::draw()` before or after the damage then the drawings will stack. – XCS Jan 15 '14 at 14:08
  • Damage just sets a flag. It will only get redrawn in the redraw loop. That is to stop the flickering. If you force a draw, then you may get some flickering. Do the labels you wish to redraw belong to the Fl_Box? If they don't, then you need to set the damage on the parent of the labels. – cup Jan 15 '14 at 14:59
  • Ok, this is how I did: I used `Fl_Box::draw()`. The problem was that the style of the box was with empty background, so next time it was drawn there was nothing to cover the old drawings width. The fix was to set box style. http://www.fltk.org/doc-1.1/common.html#boxtypes – XCS Jan 15 '14 at 21:08
  • The box type should be set when the box is created: before the draw. – cup Jan 15 '14 at 21:36
  • Yes, that's what I did. By default the box type is transparent. Had to use FLTK for University project. http://i.snag.gy/e3pUV.jpg :D – XCS Jan 15 '14 at 21:40
  • Can you post the code you are using to draw your box if you are still having a problem. – cup Jan 15 '14 at 21:57
  • No, everything is good now. Just had to set the box type not to be transparent. Thank you for your answer! – XCS Jan 15 '14 at 22:01