#include <tb_text.hpp>
Public Member Functions | |
Text (const tbCore::tbString &text=tb_string(""), const float pointSize=kDefaultFontSize, const tbCore::tbString &fontFilepath=kDefaultFontFile) | |
virtual | ~Text (void) |
tbCore::tbString | GetText (void) const |
tbCore::tbString | GetFont (void) const |
float | GetPointSize (void) const |
void | SetText (const tbCore::tbString &text, const float pointSize, const tbCore::tbString &fontFilepath) |
void | SetText (const tbCore::tbString &text) |
virtual void | SetColor (const tbGraphics::Color &newColor) override |
void | SetColor (const tbGraphics::Color &topColor, const tbGraphics::Color &bottomColor) |
virtual PixelSpace | GetPixelWidth (void) const override |
virtual PixelSpace | GetPixelHeight (void) const override |
![]() | |
Graphic (void) | |
Graphic (const Graphic &other) | |
virtual | ~Graphic (void) |
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 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) |
float | GetRotation (void) const |
void | SetRotation (const float rotation) |
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 |
bool | UnstableIsPointContained (const tbMath::Vector2 &point) const |
Static Public Member Functions | |
static void | CreateGraphicsContext (void) |
static void | DestroyGraphicsContext (void) |
Static Public Attributes | |
static const float | kDefaultFontSize |
static const tbCore::tbString | kDefaultFontFile |
Protected Member Functions | |
virtual void | OnRender (void) const override |
![]() | |
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 tbString& 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.
|
inline |
Returns the filepath of the font being used to display the text.
|
overridevirtual |
Returns the height of the text in PixelSpace which may include some padding around the edges.
Reimplemented from TurtleBrains::Graphics::Graphic.
|
overridevirtual |
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.
void TurtleBrains::Graphics::Text::SetText | ( | const tbCore::tbString & | text, |
const float | pointSize, | ||
const tbCore::tbString & | 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. |
void TurtleBrains::Graphics::Text::SetText | ( | const tbCore::tbString & | text | ) |
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. |
|
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.