#include <Text2D.h>
Description
Aspect2D class that handles text rendering.
The Text2D class allows you to render text strings onto the 2D context. Since it inherits from Aspect2D, all transformation attributes are compatible are reflect text rendering operations as if it were a whole image.
Note: If you with to render text in a 3D context, consider capturing rendered results through World::DrawToImage() function.
Public Types | |
enum | SpacingMode { Kerned, Monospace, Bitmap } |
![]() | |
enum | RenderMode { Normal, Translucent, None } |
![]() | |
using | EventHandler = bool(*)(void *, Component *component, Entity::ID self, Entity::ID source, const std::vector< std::string > &args) |
Functions | |
void | SetFont (AssetID font) |
void | SetFontSize (int size) |
void | SetSpacingMode (SpacingMode mode) |
void | SetTextColor (int charBegin, int charEnd, const Color &color) |
Vector | GetCharPosition (int i) |
Vector | GetDimensions () |
Vector | GetDimensions (const std::string &) |
void | OnDraw () |
std::string | GetInfo () |
![]() | |
std::vector< Renderer::Vertex2D > | GetVertices () const |
Renderer::Polygon | GetPolygon () const |
![]() | |
std::string | GetTag () |
Entity * | GetHost () const |
template<typename T > | |
T * | GetHostAs () const |
Entity::ID | GetHostID () const |
bool | EmitEvent (const std::string &eventName, Entity::ID source=Entity::ID(), const std::vector< std::string > &args={}) |
bool | CanHandleEvent (const std::string &eventName) |
void | InstallHook (const std::string &eventName, EventHandler, void *data=nullptr) |
void | UninstallHook (const std::string &eventName, EventHandler) |
void | InstallHandler (const std::string &eventName, EventHandler, void *data=nullptr) |
void | UninstallHandler (const std::string &eventName, EventHandler) |
std::vector< std::string > | GetKnownEvents () const |
Properties | |
std::string | text |
![]() | |
RenderMode | mode |
bool | absolute |
Additional Inherited Members | |
![]() | |
virtual void | OnStep () |
virtual void | OnAttach () |
void | InstallEvent (const std::string &eventName, EventHandler mainHandler=nullptr, void *data=nullptr) |
void | UninstallEvent (const std::string &) |
Member Enumeration Documentation
|
strong |
The mode by which text should be rendered.
Member Function Documentation
void SetFont | ( | AssetID | font | ) |
Sets the active font to be the AssetID given.
- Parameters
-
font The font to render text with. There is no default font.
void SetFontSize | ( | int | size | ) |
Sets the render resolution of the font.
- Parameters
-
size The size that the font should be displayed as.
void SetSpacingMode | ( | SpacingMode | mode | ) |
Sets the mode to render text against when drawn.
- Parameters
-
mode The spacing mode of the text.
void SetTextColor | ( | int | charBegin, |
int | charEnd, | ||
const Color & | color | ||
) |
Sets the character indices to be the colors specified. This setting persists across strings, so until another setting is specified, charBegin thru charEnd will be posted with the specified color. By default all text is white.
- Parameters
-
charBegin The first character to apply the color change to. charEnd The last character to apply the change to. All characters in between have the change applied to it. color The color to change to.
Vector GetCharPosition | ( | int | i | ) |
Returns the pixel position of the i'th character in the stored string.
Often, it is useful to get the extents of the the text that you wish to render. This will tell you at what pixel offset from the aspect's position the character's top-left corner will be. The first character is always (0, 0).
- Parameters
-
i The index of the character to get the position of.
Vector GetDimensions | ( | ) |
Returns the bounding box dimensions of the rendered text in pixels.
Vector GetDimensions | ( | const std::string & | ) |
Returns a simulated boundings box for the given string if it were set as the text for this component. When calculating spacing, this is much more efficient than rerendering and getting dimensions.
|
virtual |
|
virtual |
Returns a string containing human-readable information on the state of the component.
Reimplemented from Component.
Field Documentation
std::string text |
The text that should be drawn.
The documentation for this class was generated from the following file:
- /home/jc/git/Dynacoe/DynacoeSrc/includes/Dynacoe/Components/Text2D.h