cangine
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | List of all members
cangine::TextRendererComponent Class Reference

Component that renders a text string, optionally over a background. More...

#include <textrenderer_component.hpp>

Inheritance diagram for cangine::TextRendererComponent:
Inheritance graph
[legend]
Collaboration diagram for cangine::TextRendererComponent:
Collaboration graph
[legend]

Public Member Functions

void firstFrame () override
 Called once before the first frame update.
 
void frame (double dt) override
 Called every frame to update the component.
 
Vector2 getSize ()
 Returns the rendered size of the current text.
 
void setFontHeight (int heightIn)
 Sets the font's pixel height (reloads the font).
 
int getFontHeight ()
 Returns the current font pixel height.
 
void setBackTexture (Texture *textureIn)
 Sets the background texture drawn behind the text.
 
Texture * getBackTexture () const
 Returns the background texture.
 
- Public Member Functions inherited from cangine::IComponent
 IComponent (GameObject *gameObject=nullptr)
 Constructs the component, optionally bound to a game object.
 
virtual ~IComponent ()
 
GameObject * getGameObject () const
 Returns the game object this component is attached to.
 
virtual void onMouseEvent (const MouseEvent *e)
 Called when a mouse event is dispatched to the owning object.
 

Public Attributes

Color color
 Text color.
 
Color backgroundColor
 Background fill color.
 
float backgroundPadding
 Padding between text and background edges.
 
float scale
 Scale factor applied to the text.
 
std::string text
 The string to render.
 
Rectangle rect
 Background rectangle geometry.
 
- Public Attributes inherited from cangine::IComponent
bool isUnique = true
 If true, only one of this component type may exist per object.
 

Protected Attributes

TextRenderer * tr
 Renderer used to draw the text.
 
std::string path
 Path of the loaded font file.
 
int fontHeight
 Pixel height the font is loaded at.
 
Font * font = nullptr
 Loaded font, or nullptr.
 
Texture * backTex = nullptr
 Optional background texture.
 

Detailed Description

Component that renders a text string, optionally over a background.

Loads a font, draws text each frame via the TextRenderer, and can paint a colored or textured background rectangle behind the text.

Member Function Documentation

◆ firstFrame()

void cangine::TextRendererComponent::firstFrame ( )
overridevirtual

Called once before the first frame update.

Reimplemented from cangine::IComponent.

◆ frame()

void cangine::TextRendererComponent::frame ( double  deltaTime)
overridevirtual

Called every frame to update the component.

Parameters
deltaTimeSeconds elapsed since the previous frame.

Reimplemented from cangine::IComponent.

◆ getBackTexture()

Texture * cangine::TextRendererComponent::getBackTexture ( ) const

Returns the background texture.

Returns
Background texture, or nullptr if unset.

◆ getFontHeight()

int cangine::TextRendererComponent::getFontHeight ( )

Returns the current font pixel height.

Returns
Font height in pixels.

◆ getSize()

Vector2 cangine::TextRendererComponent::getSize ( )

Returns the rendered size of the current text.

Returns
Width and height the text occupies.

◆ setBackTexture()

void cangine::TextRendererComponent::setBackTexture ( Texture *  textureIn)

Sets the background texture drawn behind the text.

Parameters
textureInTexture to use, or nullptr for none.

◆ setFontHeight()

void cangine::TextRendererComponent::setFontHeight ( int  heightIn)

Sets the font's pixel height (reloads the font).

Parameters
heightInNew pixel height.

Member Data Documentation

◆ backgroundColor

Color cangine::TextRendererComponent::backgroundColor

Background fill color.

◆ backgroundPadding

float cangine::TextRendererComponent::backgroundPadding

Padding between text and background edges.

◆ backTex

Texture* cangine::TextRendererComponent::backTex = nullptr
protected

Optional background texture.

◆ color

Color cangine::TextRendererComponent::color

Text color.

◆ font

Font* cangine::TextRendererComponent::font = nullptr
protected

Loaded font, or nullptr.

◆ fontHeight

int cangine::TextRendererComponent::fontHeight
protected

Pixel height the font is loaded at.

◆ path

std::string cangine::TextRendererComponent::path
protected

Path of the loaded font file.

◆ rect

Rectangle cangine::TextRendererComponent::rect

Background rectangle geometry.

◆ scale

float cangine::TextRendererComponent::scale

Scale factor applied to the text.

◆ text

std::string cangine::TextRendererComponent::text

The string to render.

◆ tr

TextRenderer* cangine::TextRendererComponent::tr
protected

Renderer used to draw the text.


The documentation for this class was generated from the following files: