Damage and Redrawing


Enumerations

enum  {
  fltk::DAMAGE_VALUE, fltk::DAMAGE_PUSHED, fltk::DAMAGE_SCROLL, fltk::DAMAGE_OVERLAY,
  fltk::DAMAGE_HIGHLIGHT, fltk::DAMAGE_CHILD, fltk::DAMAGE_CHILD_LABEL, fltk::DAMAGE_EXPOSE,
  fltk::DAMAGE_CONTENTS, fltk::DAMAGE_ALL
}

Functions

uchar fltk::Widget::damage () const
virtual void fltk::Widget::draw ()
void fltk::Widget::redraw (uchar c)
void fltk::Widget::redraw ()
void fltk::Widget::redraw_highlight ()
void fltk::Widget::redraw_label ()
void fltk::Widget::set_damage (uchar c)

Variables

Widgetfl_did_clipping

Detailed Description

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() & fltk::DAMAGE_ALL) {
    ... draw frame/box and other static stuff ...
  }
  if (damage() & (fltk::DAMAGE_ALL | 1)) draw_part1();
  if (damage() & (fltk::DAMAGE_ALL | 2)) draw_part2();
  if (damage() & (fltk::DAMAGE_ALL | 4)) draw_part3();
}

Except for DAMAGE_ALL, each widget is allowed to assign any meaning to any of the bits it wants. The enumerations are just to provide suggested meanings.


Enumeration Type Documentation

anonymous enum
 

Enumeration values:
DAMAGE_VALUE  A widget may use this to indicate that the displayed value has changed.
DAMAGE_PUSHED  A widget may use this to indicate that the user has pushed or released a button.
DAMAGE_SCROLL  A widget may use this to indicate that the displayed data has scrolled moved horizontally and/or vertically.
DAMAGE_OVERLAY  Same value as fltk::DAMAGE_SCROLL.
DAMAGE_HIGHLIGHT  A widget may use this to indicate that the mouse has entered/exited part of the widget.
DAMAGE_CHILD  A child of this group widget needs to be redrawn (non-group widgets can use this bit for their own purposes).
DAMAGE_CHILD_LABEL  An outside label of this widget needs to be redrawn. This is handled (and this bit is cleared) by the parent group.

Because anti-aliasing cannot be redrawn atop itself, this is not used anymore. Instead if an outside label needs to change the entire parent widget is redrawn.

DAMAGE_EXPOSE  Damage caused by damage() or by expose events from the operating system. If this and fltk::DAMAGE_ALL is on the widget should draw every pixel inside it's region.
DAMAGE_CONTENTS  Same as fltk::DAMAGE_EXPOSE but if fltk::DAMAGE_ALL is off a widget can use this for it's own purposes.
DAMAGE_ALL  This bit is set by redraw() and indicates that all of the widget (but not "holes" where the background shows through) needs to be redraw.


Function Documentation

uchar damage  )  const [inline, inherited]
 

The 'or' of all the calls to redraw() done since the last draw(). Cleared to zero after draw() is called.

void set_damage uchar  c  )  [inline, inherited]
 

Directly change the value returned by damage(). Note that this replaces the value, it does not turn bits on. Use redraw() to turn bits on.

void redraw  )  [inherited]
 

Same as redraw(DAMAGE_ALL). This bit is used by most widgets to indicate that they should not attempt any incremental update, and should instead completely draw themselves.

void redraw uchar  flags  )  [inherited]
 

Indicates that draw() should be called, and turns on the given bits in damage(). At least these bits, and possibly others, will still be on when draw() is called.

void redraw_label  )  [inherited]
 

Indicates that the label() should be redrawn. This does nothing if there is no label. If it is an outside label (see align()) then the parent() is told to redraw it. Otherwise redraw() is called.

void redraw_highlight  )  [inherited]
 

Causes a redraw if highlighting changes.

Calls redraw(DAMAGE_HIGHLIGHT) if this widget has a non-zero highlight_color(). This is designed to be called in response to ENTER and EXIT events and not redraw the widget if the no highlight color is being used.

void draw void   )  [virtual, inherited]
 

Fltk calls this virtual function to draw the widget, after setting up the graphics (current window, xy translation, etc) so that any drawing functions will go into this widget.

User code should not call this! You probably want to call redraw().

The default version calls draw_box() and draw_label(), thus drawing the box() to fill the widget and putting the label() and image() inside it to fill it, unless the align() flags are set to put it outside.

Information on how to write your own version is here.

Reimplemented in Choice, Input, InvisibleBox, Item, and PopupMenu.


Sun May 8 21:48:57 2005. FLTK ©2004 Bill Spitzak and others. See Main Page for details.