Interface Manager
C4Interface.h

class TextElement

The TextElement class represents an interface element that displays a text string.
Definition

class TextElement : public RenderableElement

Member Functions
TextElement::SetElementSize Sets the size of a text element's render box.
TextElement::GetText Returns the text stored in a text element.
TextElement::SetText Sets the text stored in a text element.
TextElement::GetFont Returns the font used by a text element.
TextElement::SetFont Sets the font used by a text element.
TextElement::GetTextFlags Returns the text flags for a text element.
TextElement::SetTextFlags Sets the text flags for a text element.
TextElement::GetFirstRenderLine Returns the index of the first line rendered in a text box.
TextElement::SetFirstRenderLine Sets the index of the first line rendered in a text box.
TextElement::GetRenderLineCount Returns the number of lines rendered in a text box.
TextElement::SetRenderLineCount Sets the number of lines rendered in a text box.
TextElement::GetTextFormatExclusionMask Returns the format exclusion mask for a text element.
TextElement::SetTextFormatExclusionMask Sets the format exclusion mask for a text element.
TextElement::GetTextAlignment Returns the initial alignment for a text element.
TextElement::SetTextAlignment Sets the initial alignment for a text element.
TextElement::GetTextColor Returns the initial text color for a text element.
TextElement::SetTextColor Sets the initial text color for a text element.
TextElement::GetUnderlineColor Returns the initial underline color for a text element.
TextElement::SetUnderlineColor Sets the initial underline color for a text element.
TextElement::GetTextScale Returns the scale for a text element.
TextElement::SetTextScale Sets the scale for a text element.
TextElement::GetTextLeading Returns the leading for a text element.
TextElement::SetTextLeading Sets the leading for a text element.
Constructor

TextElement(const char *text = nullptr, Font *font = nullptr);

Parameters
text The text string that is displayed.
font The font in which the text is displayed.
Description
The TextElement class handles all text rendering in the C4 Engine. A text element displays a text string of arbitrary length using a single font. Text can be rendered on a single line, or it can be rendered on multiple lines in a text box. There are also several formatting tags that can be embedded in the text to control color, underlining, and alignment.

If the text parameter is not nullptr, then the string that it points to is copied into the text element. If the font parameter is not nullptr, then the font object's reference count is incremented, and the font is released when the text element is destroyed.

By default, a text element renders text on a single line. A text element can be changed to a text box configuration by calling the TextElement::SetTextFlags function to set the kTextWrapped flag and calling the TextElement::SetElementSize function to set the size of the text box.

The text stored in a text element may contain embedded formatting tags. A formatting tag is composed of four characters enclosed in square brackets. Formatting can be disabled altogether by setting the kTextUnformatted flag with the TextElement::SetTextFlags function, and specific types of formatting can be masked off using the TextElement::SetTextFormatExclusionMask function. (By default, alignment formatting is masked.) The following table lists the formatting tags recognized by the text element class.
[#rgb] Set the text color to the value given by the three hexadecimal digits r, g, and b.
[+UND] Begin underlining. This increments a counter that is initially 0. Underlining is rendered when the counter is positive.
[-UND] End underlining. The decrements the underline counter.
[LEFT] Set left text alignment.
[RGHT] Set right text alignment.
[CENT] Set center text alignment.
Formatting tags are case insensitive, and valid tags are not rendered regardless of whether they are masked. Any unrecognized tags appearing in the text are rendered as is.
Base Classes
RenderableElement All rendered interface elements are subclasses of RenderableElement.