Symbol Class Reference

Inherited by AdjusterGlyph, BgBox, BoldSymbol, BorderFrame, BrowserGlyph, CenterSymbol, CheckBox, ColorSymbol, DefaultGlyph, DiamondBox, DxSymbol, DySymbol, FileIcon, FixedSymbol, FlatBox, FocusFrame, FrameBox, Image, ItalicSymbol, LeftSymbol, LightButtonGlyph, MultiImage, NoBox, NormalSymbol, NothingSymbol, OvalBox, OvalFlatBox, OvalShadowBox, RadioButtonGlyph, ReturnButtonGlyph, RFlatBox, RightSymbol, RoundedBox, RShadowBox, ScrollBarGlyph, ShadowBox, SizeSymbol, SliderGlyph, SymbolSymbol, and TiledImage.

List of all members.

Public Member Functions

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

Static Public Member Functions

const Symbolfind (const char *name)
const Symbolfind (const char *start, const char *end)
const Symboliterate (int &index)
void text (const char *s, unsigned n)
const char * text ()
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.


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 Image, MultiImage, and 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 Image, MultiImage, and TiledImage.

int Symbol::dh  )  const
 

See dx(). Returns the change in height (positive means smaller)

void Symbol::draw const Rectangle r,
const Style style,
Flags  flags
const
 

This function is for back-compatability only. It does drawstyle(style, flags^OUTPUT) and then draw(r).

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 setcolor(), setbgcolor(), setdrawflags(), 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).

int Symbol::dw  )  const
 

See dx(). Returns the change in width (positive means smaller)

int Symbol::dx  )  const
 

Back-compatability function. This returns the amount that inset() moves the left edge, but this only works if inset() moves that edge by a constant amount no matter what rectangle is used and no matter what drawflags() or any other graphics state is set to. Notice also that dx() is overridden in the FrameBox subclass, both produce the same result but that one is inline.

Reimplemented in FrameBox.

int Symbol::dy  )  const
 

See dx(). Returns the inset of the top edge.

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 Image, and MultiImage.

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.

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.

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

Move the edges of r to be the "interior" of the symbol. If this symbol is used as a Widget::box() then this method is used to determine where to put the widget interior.

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

The default implementation returns r unchanged.

Reimplemented in MultiImage.

bool Symbol::is_frame  )  const [virtual]
 

Return true to indicate that the area returned by inset() is solidly filled with the value from getbgcolor(). Many widgets will use this fact (or assumme it) in order to accelerate drawing.

If the INVISIBLE flag is passed to draw(), this symbol is allowed to skip drawing the interior. This is used by widgets to indicate they are going to fill it anyway, and can save some time.

The default implementation returns false, but most of the useful values for a Widget's box() return true.

Reimplemented in 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 setcolor(), setbgcolor(), setdrawflags(), 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.

You must call name(0) before destroying a Symbol. The Symbol class does not have a destructor because C++ will call it for all the static symbols and thus slow down program exit.

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:
text_length()

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

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

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:
text()


The documentation for this class was generated from the following files:
Sun Jan 7 00:55:18 2007. FLTK ©2006 Bill Spitzak and others.
Permission is granted to reproduce this manual or any portion for any purpose, provided this copyright and permission notice are preserved.