From b983b285cc4f0627a1f72c9d6c510047af0ad116 Mon Sep 17 00:00:00 2001
From: Michael R Sweet A control widget typically interacts with the user to receive and/or
display a value of some sort. A container widget holds a list of child widgets and handles moving,
+ A composite widget widget holds a list of child widgets and handles moving,
sizing, showing, or hiding them as needed. Fl_Group is the
-main container widget class in FLTK, and all of the other containers (
+main composite widget widget class in FLTK, and all of the other composite widgets (
Fl_Pack, Fl_Scroll, Fl_Tabs, Fl_Tile,
and Fl_Window) are subclasses of it. You can also subclass other existing widgets to provide a different
@@ -23,13 +23,13 @@ the face of the button. The constructor must call the constructor for the base class and
pass the same arguments: Subclassing
New widgets are created by subclassing an existing FLTK widget,
typically Fl_Widget for controls and Fl_Group for
-containers.
+composite widgets.
The Constructor
- The constructor should access the following arguments:
+ The constructor should have the following arguments:
MyClass(int x, int y, int w, int h, const char *label = 0);
- This will allow the class to be used in Fluid
+ This will allow the class to be used in FLUID
without problems.
@@ -62,14 +62,14 @@ flags(ACTIVE|VISIBLE);
Protected Methods of Fl_Widget
The following methods are provided for subclasses to use:
-
void Fl_Widget::damage(uchar mask)
void Fl_Widget::damage(uchar mask, int x, int y, int w, int h)
@@ -84,9 +84,31 @@ your widget can call the private damage(n).
calls are done in a window (no calls to damage(n)) then FLTK
will clip to the union of all these calls before drawing anything.
This can greatly speed up incremental displays. The mask bits are
-or'd into damage() unless this is a Fl_Window widget.
The third form returns the bitwise-OR of all damage(n) calls done since the last draw().
+When redrawing your widgets you should look at the damage bits to +see what parts of your widget need redrawing. The handle() +method can then set individual damage bits to limit the amount of drawing +that needs to be done: +
+MyClass::handle(int event) {
+ ...
+ if (change_to_part1) damage(1);
+ if (change_to_part2) damage(2);
+ if (change_to_part3) damage(4);
+}
+
+MyClass::draw() {
+ if (damage() & FL_DAMAGE_ALL) {
+ ... draw frame/box and other static stuff ...
+ }
+
+ if (damage() & (FL_DAMAGE_ALL | 1)) draw_part1();
+ if (damage() & (FL_DAMAGE_ALL | 2)) draw_part2();
+ if (damage() & (FL_DAMAGE_ALL | 4)) draw_part3();
+}
+
The second form uses the passed bounding box instead of the widget's bounding box. This is useful so "centered" labels are aligned with some -feature, such as a moving slider.
+feature, like a moving slider.The third form draws the label anywhere. It acts as though -FL_ALIGN_INSIDE has been forced on, the label will appear inside +FL_ALIGN_INSIDE has been forced on so the label will appear inside the passed bounding box. This is designed for parent groups to draw labels with.
If you don't have RTTI you can use the clumsy FLTK mechanisim, by -having type() have a unique value. These unique values must +having type() use a unique value. These unique values must be greater than the symbol FL_RESERVED_TYPE (which is 100). Look through the header files for FL_RESERVED_TYPE to find an unused number. If you make a subclass of Fl_Window @@ -215,13 +236,13 @@ be called from non-drawing code. calls to this widget since it was last drawn. This can be used for minimal update, by only redrawing the parts whose bits are set. FLTK will turn on the FL_DAMAGE_ALL bit if it thinks the entire widget -must be redrawn (for instance due to an expose event).
+must be redrawn (e.g. for an expose event).Expose events (and the above damage(b,x,y,w,h)) will cause draw() to be called with FLTK's clipping turned on. You can greatly speed up redrawing in some cases by testing fl_clipped and fl_current_clip and skipping invisible parts.
-Besides the protected methods described above, FLTK provide a large +
Besides the protected methods described above, FLTK provides a large number of basic drawing functions, which are described below.
This should not call redraw(), at least if only the -x() and y() change. This is because group objects like +x() and y() change. This is because composite widgets like Fl_Scroll may have a more efficient way of drawing the new position.
-Subclassing Fl_Window is almost exactly like subclassing -Fl_Widget, in fact you can easily switch a subclass back and +Fl_Widget, and in fact you can easily switch a subclass back and forth. Watch out for the following differences: