On 4/25/25 22:04 Heart Bleed wrote:
Can anyone please explain what this function all about :
Yes. ;-)
Sometimes it's useful to draw only a part of a widget, particularly
if the widget is big and drawing it is "expensive" (CPU intense).
The damage() bits can help to draw only those parts that have
changed between the last draw() and the next draw() call.
int MyClass::handle(int event) {
// ...
if (change_to_part1) damage(1);
if (change_to_part2) damage(2);
if (change_to_part3) damage(4);
}
As you can see, the above part of the example code is within the
handle() method. The "change_to_partx" variables are pseudo code
(examples). Your widget has to interpret user actions and decide if
a specific part has changed, and then set the bit related to that
part. For instance, if the user clicks a button that changes a
display (for instance a counter), then you would set the bit that
this display (counter) has changed.
You can set damage() bits at any time, not only in the handle()
method, for instance in a timer callback to notify the user that
"something" has changed.
void 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 code above is in the draw() method and checks what parts have
been changed, according to the bits that have been set earlier, i.e.
between draw() calls. As written above, this can be anything and
depends on the widget you are implementing.
Also
how does one detect change_to_part1?
See above, it's up to you to determine which parts of the widget
have been changed since the last draw() call.
If your widget is small you can probably ignore all this damage()
stuff.