fltk::Symbol Class Reference

Inherited by AdjusterGlyph, ArrowGlyph, BgBox, BoldSymbol, BrowserGlyph, CenterSymbol, CheckBox, ColorSymbol, DefaultFocusBox, DefaultGlyph, DxSymbol, DySymbol, FixedSymbol, fltk::FileIcon, fltk::Image, fltk::MultiImage, fltk::TiledImage, ItalicSymbol, LeftSymbol, LightButtonGlyph, NewFocusBox, NoGlyph, NormalSymbol, NothingSymbol, RadioButtonGlyph, ReturnButtonGlyph, RightSymbol, ScrollBarGlyph, SizeSymbol, SliderGlyph, SymbolSymbol, and XPScrollBarGlyph.

List of all members.

Public Member Functions

virtual void _draw (const Rectangle &) const =0
virtual void _measure (int &w, int &h) const
int dh () const
void draw (const Rectangle &r) const
virtual void draw_symbol_overlay (const Rectangle &) const
int dw () const
int dx () const
int dy () const
virtual bool fills_rectangle () const
virtual void inset (Rectangle &r) const
virtual bool is_frame () const
void measure (int &w, int &h) const
void name (const char *)
void set_inset (const Rectangle &r)
 Symbol (const char *name=0)
virtual ~Symbol ()

Static Public Member Functions

static const Symbolfind (const char *name)
static const Symbolfind (const char *start, const char *end)
static const Symboliterate (int &index)
static void text (const char *s, unsigned n)
static const char * text ()
static unsigned text_length ()

Detailed Description

All small reusable graphics drawn by fltk are based on this class. This includes bitmapped images, the boxes drawn around widgets, symbols drawn into buttons, small symbols drawn between the letters in labels, and a number of formatting symbols to change the color or fontsize or alignment of labels.

Symbols are typically statically allocated and exist for the life of the program. They may either be identified directly by a pointer to them, or by a string name. The strings are stored in a simple hash table that should be quite efficient up to a few thousand named symbols.

Constructor & Destructor Documentation

Symbol::Symbol ( const char *  name = 0)

The constructor for a Symbol adds it's name to a hash table that is looked up in when "@" signs are found in a label. See find() for details. Pass null for the name to not put it in hash table.

Symbol::~Symbol ( ) [virtual]

The destructor does name(0) and removes it from the hash table.

Unfortunately C++ calls the destructor for static objects on program exit. I consider this a mistake, particularily because the destructor cannot assumme other objects (like the display connection) still exist. It also slows down program exit. As all useable systems can harvest resources used by crashed programs, calling these destructors serve no useful purpose.

Member Function Documentation

void Symbol::_draw ( const Rectangle r) const [pure virtual]

Virtual function to draw the symbol. This is named with an underscore so that a subclass can define it without hiding alternative functions named draw() that some intermediate classes define.

If your symbol is designed to be imbedded with an @-command into drawtext() then:

  • text() points after the '@' sign
  • getfont() is the current font
  • getsize() is the current font size
  • getcolor() is the current color
  • r.baseline_y() is where to put the baseline

Implemented in fltk::Image, fltk::MultiImage, fltk::SharedImage, and fltk::TiledImage.

void Symbol::_measure ( int &  w,
int &  h 
) const [virtual]

This is the actual virtual function that measure() calls. It is named _measure so a subclass can implement it without hiding variations of the function that are also called measure() with different arguments.

The default version returns with w and h unchanged.

Reimplemented in fltk::Image, fltk::MultiImage, and fltk::TiledImage.

int Symbol::dh ( ) const [inline]

Returns -getInset().h(). This is usally the height of the top and bottom insets added together, though if the inset() method was overridden it may return a different number.

void Symbol::draw ( const Rectangle r) const [inline]

Draw the symbol in the Rectangley r. Depending on the actual symbol it may scale to fit this rectangle, or just draw in the upper-left corner, in most cases clipping to the rectangle if too big.

The most recent values sent to fltk::setcolor(), fltk::setbgcolor(), fltk::setdrawflags(), fltk::setfont(), etc, may be used by the symbol to change how it draws. The symbol should not change any of these values, if it needs to it should save and restore the original value (some fake built-in symbols will change these to affect the color used to draw the rest of a string of text).

Reimplemented in fltk::Image.

void Symbol::draw_symbol_overlay ( const Rectangle r1) const [virtual]

The drawing of the symbol can be split into two parts, a background and an overlay. When the symbol is used as a box, the widget draws the background (using draw()), then draws any labels or images on the widget, then draws the overlay by calling this. If this alpha-composites an image then the widget label will look like it is embedded in glass or plastic.

Even without compositing, this can be used to draw highlights or indicators that should go atop the image.

The default version draws a dotted line around the edge, using a system-specific XOR mode, if the FOCUSED flag is on in drawflags().

int Symbol::dw ( ) const [inline]

Returns -getInset().w(). This is usally the width of the left and right insets added together, though if the inset() method was overridden it may return a different number.

int Symbol::dx ( ) const [inline]

Returns getInset().x(). This is usally the width of the left inset for the image, though if the inset() method was overridden it may return a different number.

int Symbol::dy ( ) const [inline]

Returns getInset().y(). This is usally the height of the top inset for the image, though if the inset() method was overridden it may return a different number.

bool Symbol::fills_rectangle ( ) const [virtual]

Return true if the symbol will completely fill all the pixels in the Rectangle passed to draw(). Widgets use this to test whether they need to erase their area before drawing the box. The default implementation returns false.

Reimplemented in fltk::Image, and fltk::MultiImage.

const Symbol * Symbol::find ( const char *  name) [static]

Locate a symbol by the name used to construct it. Returns either a pointer to the symbol, or null if it is undefined.

const Symbol * Symbol::find ( const char *  name,
const char *  end 
) [static]

Locate a symbol by the substring after an '@' sign as used by drawtext(). name points at the start of the name, end points to the character after the end (this allows the name to be extracted from a longer string without having to copy it).

drawtext() can pass "arguments" to symbols as extra text before and after the actual name. If the text does not seem to correspond to a symbol name, this function tries to strip off these argments and try again. The current rules are to remove a leading '#' and '+' or '-' sign, remove a leading and trailing integer, so "@+400foo21" will locate the symbol "foo". If that still does not work, it tries the first letter as a 1-letter symbol, so "@Ccolorname" will work.

When the symbol's draw() function is called, text() is set to name and text_length() is set to end minus name, so the draw() method can examine these arguments.

void Symbol::inset ( Rectangle r) const [virtual]

Change r to be the "interior" of the symbol if it was drawn to fill it. This is used when the symbol is a Widget::box() to define the interior area where the widget can draw it's contents.

The default version adds the value of the inset() rectangle (and thus if set_inset() was not called it does nothing).

The most recent values sent to fltk::setcolor(), fltk::setbgcolor(), fltk::setdrawflags(), fltk::setfont(), etc, may influence the value that this returns (such as to return a different edge for a pushed button).

Reimplemented in fltk::MultiImage.

bool Symbol::is_frame ( ) const [virtual]

Return true to indicate that the area returned by inset() is drawn as a solid rectangle filled with fltk::getbgcolor(), and that if INVISIBLE is set in drawflags() the interior is not filled in at all and instead left with it's previous contents.

The default implementation returns false, but most of the useful values for a Widget's box() return true, and widgets can take advantage of this to reduce drawing overhead. In fact quite a few widgets currently assumme this is true, but I hope to fix this so that image boxes can be used anywhere.

Reimplemented in fltk::MultiImage.

const Symbol * Symbol::iterate ( int &  i) [static]

You can call this to get a list of all Symbols that have a non-null name(). The symbols are returned out of the hash table and are in random order.

  for (int i = 0;;) {
    const Symbol* symbol = Symbol::iterate(i);
    if (!symbol) break;
void Symbol::measure ( int &  w,
int &  h 
) const [inline]

Returns the size a Symbol will draw.

The referenced variables w and h should be preset to a size you want to draw the symbol, many Symbols can scale and will return without changing these values. Or they may alter the values to preserve aspect ratio. Or they may just return constant sizes.

The most recent values sent to fltk::setcolor(), fltk::setbgcolor(), fltk::setdrawflags(), fltk::setfont(), etc, may influence the value that this returns.

void Symbol::name ( const char *  name)

Sets the name() of the symbol. If it is in the hash table under the old name it is removed. If the new name is not NULL then it is added under the new name to the hash table.

The strings are assummed to belong to the calling program. You can go through the trouble of freeing the old one, or just leak it like Fluid does.

void Symbol::set_inset ( const Rectangle r) [inline]

Set the inset rectangle. This is normally done by the constructor for a subclass. If the inset() method is not overridden, the values in this rectangle define the edges.

void Symbol::text ( const char *  s,
unsigned  n 
) [inline, static]

Set the values returned by text() and text_length()

const char * Symbol::text ( ) [inline, static]

Return a pointer to right after the '@' sign to the text used to invoke this symbol. This is a zero-length string if not being called from drawtext(). This is useful for extracting the arguments that are skipped by the find() method.

See also:
const char * Symbol::text_length ( ) [inline, static]

Return the number of bytes between the '@' sign and the ';' or null or space that terminates the symbol when called from drawtext(). This is useful for parsing the arguments. This returns zero if it is not being called from drawtext().

See also:

The documentation for this class was generated from the following files: