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 Symbol * | find (const char *name) |
const Symbol * | find (const char *start, const char *end) |
const Symbol * | iterate (int &index) |
void | text (const char *s, unsigned n) |
const char * | text () |
unsigned | text_length () |
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.
|
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. |
|
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:
Implemented in Image, MultiImage, and TiledImage. |
|
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. |
|
See dx(). Returns the change in height (positive means smaller) |
|
This function is for back-compatability only. It does drawstyle(style, flags^OUTPUT) and then draw(r). |
|
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). |
|
See dx(). Returns the change in width (positive means smaller) |
|
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. |
|
See dx(). Returns the inset of the top edge. |
|
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. |
|
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. |
|
Locate a symbol by the name used to construct it. Returns either a pointer to the symbol, or null if it is undefined. |
|
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. |
|
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. |
|
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; ... } |
|
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. |
|
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. |
|
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.
|
|
Set the values returned by text() and text_length() |
|
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().
|