On 07.06.2011 17:30, Paul R wrote:

> I think am kind of getting this.. the idea is derive a class from fl widget, 
> so then my own class which say calls an fl_box into being
> can then use the box as it's 'drawing canvas' by calling the inherited
> draw function from the widget class.

It is difficult to understand what you mean with "my own class which say
calls an fl_box into being". Real code would be much easier to understand
(for me).

> Whenever i wanted to draw the rectangle i could just call
> myClass.draw(x,y,w,h) ??

You mean "object_of_myclass.draw(x,y,w,h)? Again, this may seem
to be nitpicking, but how to explain something (or say "yes, this
is right") if you don't know what the OP really wanted to say?

I'll try with my own words...

The main problem you must consider before you ask how and when you
can call some drawing functions is how all GUIs behave in general.
_One_ aspect is: you must always be able to draw the entire window
when needed, e.g. because it has been obscured by another window.
This can also be true only for a part of your window. FLTK manages
an important part for you: it discovers if and when a part of your
window needs drawing and calls the draw() methods of all widgets in
the window that need drawing. Before it calls the individual draw()
methods, it will set up the internal OS drawing context so that all
drawing functions can draw into the right window.

Now, if you derive your class from Fl_Box, then yes, you can use this
box as a drawing canvas to do point, line, and rectangle drawing as
you like. But you must keep in mind that you must always draw the
entire widget, because it can be reset to an empty background
whenever the surrounding (parent) Fl_Group or Fl_Window are drawn.
At least you must be able to draw the entire widget, if draw() is
called by FLTK. Note that the box() type of your widget can even
be FL_NO_BOX, so that no background will be drawn, if you want that.
But if you derived your own draw() method, then you must call a
box drawing method anyway if you want to have a defined background;
otherwise your widget will be transparent, as Greg noted already
in his reply.

If you want to draw some points or lines (like an oscilloscope) at
arbitrary times, then you *can* [1] do it e.g. in a timer callback,
but this is somewhat "volatile", unless you also save all the data
you need to draw also somewhere in the widget's memory so that you can
replicate it at any point in time (when FLTK calls the draw() method
of your widget). Usually it is much easier to store the data in the
widget and call redraw() so that FLTK *will* call draw() for you at
the right time and after preparing the drawing context. This can be
improved if you flag the parts that need updates with damage() calls
or in the widget's memory and set up the clipping area to avoid
flicker, but that's OT here.


[1] If you *really* want to draw on-the-fly data into an existing
widget, then you can call Fl_Window::make_current() to set up the
drawing context, but this is *not* recommended. Read the comment
on make_current() in the docs at

http://www.fltk.org/doc-1.3/classFl__Window.html

about what is called "incremental update".


HTH

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

Reply via email to