#include <TextControl.h>
Inheritance diagram for GG::TextControl:
Structors | |
TextControl (int x, int y, int w, int h, const std::string &str, const boost::shared_ptr< Font > &font, Clr color=CLR_BLACK, Flags< TextFormat > format=FORMAT_NONE, Flags< WndFlag > flags=Flags< WndFlag >()) | |
TextControl (int x, int y, const std::string &str, const boost::shared_ptr< Font > &font, Clr color=CLR_BLACK, Flags< TextFormat > format=FORMAT_NONE, Flags< WndFlag > flags=Flags< WndFlag >()) | |
Accessors | |
virtual Pt | MinUsableSize () const |
Flags< TextFormat > | GetTextFormat () const |
Clr | TextColor () const |
bool | ClipText () const |
bool | SetMinSize () const |
template<class T> | |
void | operator>> (T &t) const |
template<class T> | |
T | GetValue () const |
operator const std::string & () const | |
bool | Empty () const |
int | Length () const |
Pt | TextUpperLeft () const |
Pt | TextLowerRight () const |
Mutators | |
virtual void | Render () |
virtual void | SetText (const std::string &str) |
virtual void | SizeMove (const Pt &ul, const Pt &lr) |
void | SetTextFormat (Flags< TextFormat > format) |
void | SetTextColor (Clr color) |
virtual void | SetColor (Clr c) |
void | ClipText (bool b) |
void | SetMinSize (bool b) |
template<class T> | |
void | operator<< (T t) |
void | operator+= (const std::string &str) |
void | operator+= (const char *str) |
void | operator+= (char ch) |
void | Clear () |
void | Insert (int pos, char ch) |
void | Erase (int pos, int num=1) |
virtual void | DefineAttributes (WndEditor *editor) |
Structors | |
TextControl () |
All TextControl objects know how to center, left- or right-justify, etc. themselves within their window areas. The format flags used with TextControl are defined in enum GG::TextFormat in GGBase.h. TextControl has std::string-like operators and functions that allow the m_text member string to be manipulated directly. In addition, the << and >> operators allow virtually any type (int, float, char, etc.) to be read from a Text object as if it were an input or output stream, thanks to boost::lexical_cast. Note that the Text stream operators only read the first instance of the specified type from m_text, and overwrite the entire m_text string when writing to it; both operators may throw. This is a text control based on pre-rendered font glyphs. The text is rendered character by character from a prerendered font. The font used is gotten from the GUI's font manager. Since a shared_ptr to the font is kept, the font is guaranteed to live at least as long as the TextControl object that refers to it. This also means that if the font is explicitly released from the font manager but is still held by at least one TextControl object, it will not be destroyed, due to the shared_ptr. Note that if "" is supplied as the font_filename parameter, no text will be rendered, but a valid TextControl object will be constructed, which may later contain renderable text. TextControl objects support text with formatting tags. See GG::Font for details.
Definition at line 54 of file TextControl.h.
GG::TextControl::TextControl | ( | int | x, | |
int | y, | |||
int | w, | |||
int | h, | |||
const std::string & | str, | |||
const boost::shared_ptr< Font > & | font, | |||
Clr | color = CLR_BLACK , |
|||
Flags< TextFormat > | format = FORMAT_NONE , |
|||
Flags< WndFlag > | flags = Flags< WndFlag >() | |||
) |
ctor taking a font directly
GG::TextControl::TextControl | ( | int | x, | |
int | y, | |||
const std::string & | str, | |||
const boost::shared_ptr< Font > & | font, | |||
Clr | color = CLR_BLACK , |
|||
Flags< TextFormat > | format = FORMAT_NONE , |
|||
Flags< WndFlag > | flags = Flags< WndFlag >() | |||
) |
ctor that does not require window size.
Window size is determined from the string and font; the window will be large enough to fit the text as rendered, and no larger. The private member m_fit_to_text is also set to true.
GG::TextControl::TextControl | ( | ) | [protected] |
default ctor
virtual Pt GG::TextControl::MinUsableSize | ( | ) | const [virtual] |
returns the size of the minimum bounding box that can enclose the Wnd and still show all of its elements, plus enough room for interaction with those elements (if applicable).
For example, a TextControl's MinUsableSize() is just the area of its text, and a Scroll's RenderableMinSize() is the combined sizes of its up-button, down-button, and tab (plus a bit of room in which to drag the tab).
Reimplemented from GG::Wnd.
Reimplemented in GG::StateButton, GG::Edit, and GG::MultiEdit.
Referenced by GG::Spin< T >::MinUsableSize().
Flags<TextFormat> GG::TextControl::GetTextFormat | ( | ) | const |
returns the text format (vertical and horizontal justification, use of word breaks and line wrapping, etc.
)
Clr GG::TextControl::TextColor | ( | ) | const |
returns the text color (this may differ from the Control::Color() in some subclasses)
Referenced by GG::Spin< T >::TextColor().
bool GG::TextControl::ClipText | ( | ) | const |
returns true iff the text control clips its text to its client area; by default this is not done
bool GG::TextControl::SetMinSize | ( | ) | const |
returns true iff the text control sets its MinSize() when the bounds of its text change because of a call to SetText() or SetTextFormat(); by default this is not done.
The minimum size of the control in each dimension will be the larger of the text size and the current MinSize(), if any has been set. Note that this operates independently of fit-to-text behavior, which sets the window size, not its minimum size.
void GG::TextControl::operator>> | ( | T & | t | ) | const [inline] |
sets the value of t to the interpreted value of the control's text.
If the control's text can be interpreted as an object of type T by boost::lexical_cast (and thus by a stringstream), then the >> operator will do so. Note that the return type is void, so multiple >> operations cannot be strung together. Also, because lexical_cast attempts to convert the entire contents of the string to a single value, a TextControl containing the string "4.15 3.8" will fill a float with 0.0 (the default construction of float), even though there is a perfectly valid 4.15 value that occurs first in the string.
Definition at line 190 of file TextControl.h.
References GG::Wnd::m_text.
T GG::TextControl::GetValue | ( | ) | const [inline] |
returns the value of the control's text, interpreted as an object of type T.
If the control's text can be interpreted as an object of type T by boost::lexical_cast (and thus by a stringstream), then GetValue() will do so. Because lexical_cast attempts to convert the entire contents of the string to a single value, a TextControl containing the string "4.15 3.8" will throw, even though there is a perfectly valid 4.15 value that occurs first in the string.
boost::bad_lexical_cast | boost::lexical_cast throws boost::bad_lexical_cast when it cannot perform a requested cast. This is handy for validating data in a dialog box; Otherwise, using operator>>(), you may get the default value, even though the text in the control may not be the default value at all, but garbage. |
Definition at line 200 of file TextControl.h.
References GG::Wnd::m_text.
GG::TextControl::operator const std::string & | ( | ) | const |
returns the control's text; allows TextControl's to be used as std::string's
bool GG::TextControl::Empty | ( | ) | const |
returns true when text string equals ""
int GG::TextControl::Length | ( | ) | const |
returns length of text string
Pt GG::TextControl::TextUpperLeft | ( | ) | const |
returns the upper-left corner of the text as it is would be rendered if it were not bound to the dimensions of this control.
Reimplemented in GG::StateButton.
Pt GG::TextControl::TextLowerRight | ( | ) | const |
returns the lower-right corner of the text as it is would be rendered if it were not bound to the dimensions of this control.
virtual void GG::TextControl::Render | ( | ) | [virtual] |
draws this Wnd.
Note that Wnds being dragged for a drag-and-drop operation are rendered twice -- once in-place as normal, once in the location of the drag operation, attached to the cursor. Such Wnds may wish to render themselves differently in those two cases. To determine which render is being performed, they can call GUI::GetGUI()->RenderingDragDropWnds().
Implements GG::Control.
Reimplemented in GG::Button, GG::StateButton, GG::Edit, and GG::MultiEdit.
virtual void GG::TextControl::SetText | ( | const std::string & | str | ) | [virtual] |
sets the text to str; may resize the window.
If the private member m_fit_to_text is true (i.e. if the second ctor type was used), calls to this function cause the window to be resized to whatever space the newly rendered text occupies.
Reimplemented from GG::Wnd.
Reimplemented in GG::Edit, and GG::MultiEdit.
Referenced by operator<<().
resizes and/or moves window to new upper-left and lower right boundaries
Reimplemented from GG::Wnd.
Reimplemented in GG::StateButton, and GG::MultiEdit.
Referenced by GG::Spin< T >::SizeMove().
void GG::TextControl::SetTextFormat | ( | Flags< TextFormat > | format | ) |
sets the text format; ensures that the flags are sane
void GG::TextControl::SetTextColor | ( | Clr | color | ) |
virtual void GG::TextControl::SetColor | ( | Clr | c | ) | [virtual] |
just like Control::SetColor(), except that this one also adjusts the text color
Reimplemented from GG::Control.
Reimplemented in GG::Button, GG::StateButton, and GG::Edit.
void GG::TextControl::ClipText | ( | bool | b | ) |
enables/disables text clipping to the client area
void GG::TextControl::SetMinSize | ( | bool | b | ) |
enables/disables setting the minimum size of the window to be the text size
void GG::TextControl::operator<< | ( | T | t | ) | [inline] |
Sets the value of the control's text to the stringified version of t.
If t can be converted to a string representation by a boost::lexical_cast (and thus by a stringstream), then the << operator will do so, eg double(4.15) to string("4.15"). Note that the return type is void, so multiple << operations cannot be strung together.
boost::bad_lexical_cast | boost::lexical_cast throws boost::bad_lexical_cast when it is confused. |
Definition at line 206 of file TextControl.h.
References SetText().
void GG::TextControl::operator+= | ( | const std::string & | str | ) |
appends str to text string by way of SetText()
void GG::TextControl::operator+= | ( | const char * | str | ) |
appends str to text string by way of SetText()
void GG::TextControl::operator+= | ( | char | ch | ) |
appends ch to text string by way of SetText()
void GG::TextControl::Clear | ( | ) |
sets text string to ""
void GG::TextControl::Insert | ( | int | pos, | |
char | ch | |||
) |
allows access to text string much as a std::string
void GG::TextControl::Erase | ( | int | pos, | |
int | num = 1 | |||
) |
allows access to text string much as a std::string
virtual void GG::TextControl::DefineAttributes | ( | WndEditor * | editor | ) | [virtual] |
provides the attributes of this object that are appropriate for a user to edit in a WndEditor; see WndEditor for details.
Reimplemented from GG::Control.
Reimplemented in GG::Button, GG::StateButton, GG::Edit, and GG::MultiEdit.