#include <tb_text.h>
Public Member Functions | |
Text (const tbCore::tbString &text=tb_string(""), const float pointSize=kDefaultFontSize, const tbCore::tbString &fontFilepath=kDefaultFontFile) | |
virtual | ~Text (void) |
void | SetText (const tbCore::tbString &text, const float pointSize, const tbCore::tbString &fontFilepath) |
void | SetText (const tbCore::tbString &text) |
PixelSpace | GetWidth (void) const |
PixelSpace | GetHeight (void) const |
![]() | |
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) |
float | GetDepth (void) const |
void | SetDepth (const float newDepth) |
bool | IsRelative (void) const |
virtual void | SetColor (const tbGraphics::Color &newColor) |
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) |
const Color & | GetColor (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 |
PixelSpace TurtleBrains::Graphics::Text::GetHeight | ( | void | ) | const |
Returns the height of the text in PixelSpace which may include some padding around the edges.
PixelSpace TurtleBrains::Graphics::Text::GetWidth | ( | void | ) | const |
Returns the width of the text in PixelSpace which may include some padding around the edges.
|
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.
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.