#include <tb_text.hpp>
Public Types | |
| enum class | BaselineFrom { Top , Center , Bottom } |
Public Member Functions | |
| Text (const String &text=tb_string(""), const FontSize pointSize=DefaultFontSize(), const String &fontFilepath=DefaultFontFile()) | |
| virtual | ~Text (void) |
| String | GetText (void) const |
| String | GetFont (void) const |
| FontSize | GetPointSize (void) const |
| float | Unstable_GetBaseline (const BaselineFrom from=BaselineFrom::Top) const |
| float | Unstable_GetScaledBaseline (const BaselineFrom from=BaselineFrom::Top) const |
| void | SetText (const String &text, const tbGraphics::AnchorLocation &alignment, const FontSize pointSize, const String &fontFilepath) |
| void | SetText (const String &text, const FontSize pointSize, const String &fontFilepath) |
| void | SetText (const String &text, const FontSize pointSize) |
| void | SetText (const String &text) |
| void | SetAlignment (const AnchorLocation &alignment) |
| virtual void | SetColor (const Color &newColor) override |
| void | SetColor (const Color &topColor, const Color &bottomColor) |
| const Color & | GetOutlineColor (void) const |
| void | SetOutlineColor (const Color &outlineColor) |
| float | GetOutlineThickness (void) const |
| void | SetOutlineThickness (const float thickness) |
| const Color & | GetShadowColor (void) const |
| void | SetShadowColor (const Color &shadowColor) |
| Math::Vector2 | GetShadowOffset (void) const |
| void | SetShadowOffset (const Math::Vector2 &shadowOffset) |
| void | SetShadowOffset (const float offsetX, const float offsetY) |
| virtual PixelSpace | GetPixelWidth (void) const override |
| virtual PixelSpace | GetPixelHeight (void) const override |
Public Member Functions inherited from TurtleBrains::Graphics::Graphic | |
| Graphic (void) | |
| Graphic (const Graphic &other)=default | |
| virtual | ~Graphic (void)=default |
| Graphic & | operator= (const Graphic &other)=default |
| bool | IsActive (void) const |
| void | SetActive (const bool isActive) |
| void | Update (const float deltaTime) |
| bool | IsVisible (void) const |
| void | SetVisible (const bool isVisible) |
| void | Render (void) const |
| const tbMath::Vector2 & | GetPosition (void) const |
| void | SetPosition (const float x, const float y) |
| void | SetPosition (const tbMath::Vector2 &position) |
| const tbMath::Vector2 & | GetOrigin (void) const |
| void | SetOrigin (const AnchorLocation &anchor, const float offsetX, const float offsetY) |
| void | SetOrigin (const AnchorLocation &anchor, const tbMath::Vector2 &offset=tbMath::Vector2::Zero()) |
| void | SetOrigin (const float originX, const float originY) |
| void | SetOrigin (const tbMath::Vector2 &origin) |
| float | GetDepth (void) const |
| void | SetDepth (const float newDepth) |
| const tbMath::Vector2 & | GetScale (void) const |
| void | SetScale (const float scale) |
| void | SetScale (const tbMath::Vector2 &scale) |
| void | SetScale (const float scaleX, const float scaleY) |
| tbMath::Angle | GetRotation (void) const |
| void | SetRotation (const tbMath::Angle &angle) |
| void | SetScroll (const float scroll) |
| void | SetScroll (const float scrollX, const float scrollY) |
| bool | IsRelative (void) const |
| const Color & | GetColor (void) const |
| float | GetWidth (void) const |
| float | GetHeight (void) const |
| float | GetScaledWidth (void) const |
| float | GetScaledHeight (void) const |
| tbMath::Vector2 | GetAnchorPosition (const tbGraphics::AnchorLocation &anchor, const float offsetX, const float offsetY) const |
| tbMath::Vector2 | GetAnchorPosition (const tbGraphics::AnchorLocation &anchor, const tbMath::Vector2 &offset=tbMath::Vector2::Zero()) const |
| bool | UnstableIsPointContained (const tbMath::Vector2 &point) const |
Static Public Member Functions | |
| static FontSize | DefaultFontSize (void) |
| static const String & | DefaultFontFile (void) |
| static void | SetLineHeightForFont (const String &fontFilepath, const float multiplier) |
| static void | CreateGraphicsContext (void) |
| static void | DestroyGraphicsContext (void) |
Protected Member Functions | |
| virtual void | OnRender (void) const override |
Protected Member Functions inherited from TurtleBrains::Graphics::Graphic | |
| virtual void | OnUpdate (const float deltaTime) |
| virtual void | ApplyTransform (void) const |
| virtual void | PopTransform (void) const |
The basic TextObject provides a minimalistic, but powerful true-type font api, each instance of the TextObject creates a GL texture that will be rendered to the screen as appropriate. It does take a little overhead to create the TextObject, so don't create a bunch of them over and over each frame.
class MySpecialTextObject : public TextObject { public: MySpecialText(const String& text) : TextObject(text, "Path/To/Some/Font.ttf", 20.0f) { } }
|
explicit |
This constructor does all the heavy lifting for the TextObject. If the font specified by fontFilepath is not loaded, it will be loaded, and then a small GL texture will be rasterized and stored to be used by the Draw() method. There are several ways the constructor can fail, and if it does fail the tb_error_if behavior will be invoked, either throwing exceptions, asserts, or other.
| text | A string representing the actual letters/symbols to be displayed by the object. |
| fontFilepath | The filepath to the truetype-font to use for this text object, file must exist or an error condition will be triggered. Set as kDefaultFontFile, the font will be the default font as supplied by TurtleBrains. |
| pointSize | How large this TextObject should be rasterized at. |
|
virtual |
|
static |
TODO: TurtleBrains: Documentation: Find a better name and teach the user how to use this.
|
static |
The default font file automatically created by TurtleBrains if a Text object is created with default.
|
static |
the default font size for a Text object created without specifying a size.
|
inline |
Returns the filepath of the font being used to display the text.
| const Color& TurtleBrains::Graphics::Text::GetOutlineColor | ( | void | ) | const |
|
overridevirtual |
Returns the height of the text in PixelSpace which may include some padding around the edges.
Reimplemented from TurtleBrains::Graphics::Graphic.
|
overridevirtual |
@end of set
Returns the width of the text in PixelSpace which may include some padding around the edges.
Reimplemented from TurtleBrains::Graphics::Graphic.
|
inline |
Returns the size of the font being displayed.
|
inline |
Returns the string that the text object is displaying.
|
overrideprotectedvirtual |
Draws the precomputed image from the constructor to the screen. The location of the TextObject is determined by the last call to SetPosition(), as is the color with SetColor().
Implements TurtleBrains::Graphics::Graphic.
|
overridevirtual |
Change the color of the sprite so it can fade in/out with alpha, or modify the color for other effects.
Reimplemented from TurtleBrains::Graphics::Graphic.
|
static |
Change the line-height of a Font underneath ALL text objects that use that font. This only effects Text objects that have multiple lines in their string, separated by '
'.
| multiplier | is 1.0 to represent the line height directly from ttf font file, smaller will make the lines scrunch up and larger spaces them out even further. This effects ALL text objects with the font. |
| void TurtleBrains::Graphics::Text::SetText | ( | const String & | text | ) |
| void TurtleBrains::Graphics::Text::SetText | ( | const String & | text, |
| const FontSize | pointSize | ||
| ) |
| void TurtleBrains::Graphics::Text::SetText | ( | const String & | text, |
| const FontSize | pointSize, | ||
| const String & | fontFilepath | ||
| ) |
| void TurtleBrains::Graphics::Text::SetText | ( | const String & | text, |
| const tbGraphics::AnchorLocation & | alignment, | ||
| const FontSize | pointSize, | ||
| const String & | fontFilepath | ||
| ) |
SetText is the heavy lifter of the object, it actually creates the small GL texture for of the rasterized letters/symbols from the true-type font and prepares everything to be displayed. It can be a fairly expensive call, so avoid changing the text, size or font when possible.
| text | the string of letters to display when rendered. |
| pointSize | is optional to change the size of the text should when rasterized. This will effect the width and height of the displayed text. |
| fontFilepath | is optional to change the font of the text object. If supplied an empty string "" will use the kDefaultFontFile. |
| float TurtleBrains::Graphics::Text::Unstable_GetBaseline | ( | const BaselineFrom | from = BaselineFrom::Top | ) | const |