Improve docs about subclassing
- fix syntax errors in example code, e.g.: children_ is private - use FLTK coding style - improve alignment
This commit is contained in:
parent
eb545c981b
commit
f9f89be7d7
@ -47,8 +47,8 @@ pass the same arguments:
|
|||||||
|
|
||||||
\code
|
\code
|
||||||
MyClass::MyClass(int x, int y, int w, int h, const char *label)
|
MyClass::MyClass(int x, int y, int w, int h, const char *label)
|
||||||
: Fl_Widget(x, y, w, h, label) {
|
: Fl_Widget(x, y, w, h, label) {
|
||||||
// do initialization stuff...
|
// do initialization stuff...
|
||||||
}
|
}
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
@ -57,19 +57,19 @@ Fl_Widget's protected constructor sets \p x(), \p y(),
|
|||||||
and initializes the other instance variables to:
|
and initializes the other instance variables to:
|
||||||
|
|
||||||
\code
|
\code
|
||||||
type(0);
|
type(0);
|
||||||
box(FL_NO_BOX);
|
box(FL_NO_BOX);
|
||||||
color(FL_BACKGROUND_COLOR);
|
color(FL_BACKGROUND_COLOR);
|
||||||
selection_color(FL_BACKGROUND_COLOR);
|
selection_color(FL_BACKGROUND_COLOR);
|
||||||
labeltype(FL_NORMAL_LABEL);
|
labeltype(FL_NORMAL_LABEL);
|
||||||
labelstyle(FL_NORMAL_STYLE);
|
labelstyle(FL_NORMAL_STYLE);
|
||||||
labelsize(FL_NORMAL_SIZE);
|
labelsize(FL_NORMAL_SIZE);
|
||||||
labelcolor(FL_FOREGROUND_COLOR);
|
labelcolor(FL_FOREGROUND_COLOR);
|
||||||
align(FL_ALIGN_CENTER);
|
align(FL_ALIGN_CENTER);
|
||||||
callback(default_callback,0);
|
callback(default_callback,0);
|
||||||
flags(ACTIVE|VISIBLE);
|
flags(ACTIVE|VISIBLE);
|
||||||
image(0);
|
image(0);
|
||||||
deimage(0);
|
deimage(0);
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
\section subclassing_protected Protected Methods of Fl_Widget
|
\section subclassing_protected Protected Methods of Fl_Widget
|
||||||
@ -118,22 +118,22 @@ see what parts of your widget need redrawing.</I> The \p handle()
|
|||||||
method can then set individual damage bits to limit the amount of drawing
|
method can then set individual damage bits to limit the amount of drawing
|
||||||
that needs to be done:
|
that needs to be done:
|
||||||
\code
|
\code
|
||||||
MyClass::handle(int event) {
|
int MyClass::handle(int event) {
|
||||||
...
|
// ...
|
||||||
if (change_to_part1) damage(1);
|
if (change_to_part1) damage(1);
|
||||||
if (change_to_part2) damage(2);
|
if (change_to_part2) damage(2);
|
||||||
if (change_to_part3) damage(4);
|
if (change_to_part3) damage(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
MyClass::draw() {
|
void MyClass::draw() {
|
||||||
if (damage() & FL_DAMAGE_ALL) {
|
if (damage() & FL_DAMAGE_ALL) {
|
||||||
... draw frame/box and other static stuff ...
|
// ... draw frame/box and other static stuff ...
|
||||||
}
|
}
|
||||||
|
|
||||||
if (damage() & (FL_DAMAGE_ALL | 1)) draw_part1();
|
if (damage() & (FL_DAMAGE_ALL | 1)) draw_part1();
|
||||||
if (damage() & (FL_DAMAGE_ALL | 2)) draw_part2();
|
if (damage() & (FL_DAMAGE_ALL | 2)) draw_part2();
|
||||||
if (damage() & (FL_DAMAGE_ALL | 4)) draw_part3();
|
if (damage() & (FL_DAMAGE_ALL | 4)) draw_part3();
|
||||||
}
|
}
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
\todo Clarify Fl_Window::damage(uchar) handling - seems confused/wrong?
|
\todo Clarify Fl_Window::damage(uchar) handling - seems confused/wrong?
|
||||||
@ -259,7 +259,7 @@ a pushbutton and also accepts the keystroke \p 'x' to cause the callback:
|
|||||||
|
|
||||||
\code
|
\code
|
||||||
int MyClass::handle(int event) {
|
int MyClass::handle(int event) {
|
||||||
switch(event) {
|
switch (event) {
|
||||||
case FL_PUSH:
|
case FL_PUSH:
|
||||||
highlight = 1;
|
highlight = 1;
|
||||||
redraw();
|
redraw();
|
||||||
@ -416,14 +416,16 @@ that a child needs to be drawn. It is fastest if you avoid
|
|||||||
drawing anything else in this case:
|
drawing anything else in this case:
|
||||||
|
|
||||||
\code
|
\code
|
||||||
int MyClass::draw() {
|
void MyClass::draw() {
|
||||||
Fl_Widget *const*a = array();
|
Fl_Widget *const*a = array();
|
||||||
if (damage() == FL_DAMAGE_CHILD) { // only redraw some children
|
if (damage() == FL_DAMAGE_CHILD) { // only redraw some children
|
||||||
for (int i = children(); i --; a ++) update_child(**a);
|
for (int i = children(); i--; a++) {
|
||||||
|
update_child(**a);
|
||||||
|
}
|
||||||
} else { // total redraw
|
} else { // total redraw
|
||||||
... draw background graphics ...
|
// ... draw background graphics ...
|
||||||
// now draw all the children atop the background:
|
// now draw all the children atop the background:
|
||||||
for (int i = children_; i --; a ++) {
|
for (int i = children(); i--; a++) {
|
||||||
draw_child(**a);
|
draw_child(**a);
|
||||||
draw_outside_label(**a); // you may not need to do this
|
draw_outside_label(**a); // you may not need to do this
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user