Text2D Class Reference

#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
}
 
- Public Types inherited from Render2D
enum  RenderMode {
  Normal,
  Translucent,
  None
}
 
- Public Types inherited from Component
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 ()
 
- Functions inherited from Render2D
std::vector< Renderer::Vertex2D > GetVertices () const
 
Renderer::Polygon GetPolygon () const
 
- Functions inherited from Component
std::string GetTag ()
 
EntityGetHost () 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
 
- Properties inherited from Render2D
RenderMode mode
 
bool absolute
 

Additional Inherited Members

- Protected Member Functions inherited from Component
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

enum SpacingMode
strong

The mode by which text should be rendered.

Enumerator
Kerned 

Attempts to produce the most natural spacing between text by taking into account any special character spacing rules determined by the font. This is the default.

Monospace 

Space among characters is distributed uniformly regardless of input text. This is typically preferred for performance and for ease of determining space usage.

Bitmap 

Spcifies space to be determined by the actual character extents only. This is at times useful, but may cause awkward spacing with certain fonts.

Member Function Documentation

void SetFont ( AssetID  font)

Sets the active font to be the AssetID given.

Parameters
fontThe font to render text with. There is no default font.
void SetFontSize ( int  size)

Sets the render resolution of the font.

Parameters
sizeThe size that the font should be displayed as.
void SetSpacingMode ( SpacingMode  mode)

Sets the mode to render text against when drawn.

Parameters
modeThe 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
charBeginThe first character to apply the color change to.
charEndThe last character to apply the change to. All characters in between have the change applied to it.
colorThe 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
iThe 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.

void OnDraw ( )
virtual

Function that is called upon each Draw iteration. Component Draw()s are run before the entity's draw function.

Reimplemented from Component.

std::string GetInfo ( )
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