Wasabi
Public Member Functions | Protected Attributes | List of all members
WTextComponent Class Reference

#include <WText.hpp>

Public Member Functions

 WTextComponent (class Wasabi *app)
 
void AddFontDirectory (std::string dir)
 
WError Initialize ()
 
WError CreateTextFont (uint32_t ID, std::string fontName)
 
WError DestroyFont (uint32_t ID)
 
WError SetTextColor (WColor col)
 
WError SetFont (uint32_t ID)
 
WError RenderText (std::string text, float x, float y, float fHeight)
 
WError RenderText (std::string text, float x, float y, float fHeight, uint32_t fontID)
 
WError RenderText (std::string text, float x, float y, float fHeight, uint32_t fontID, WColor col)
 
void Render (class WRenderTarget *rt)
 
float GetTextWidth (std::string text, float fHeight, uint32_t fontID=0)
 

Protected Attributes

class Wasabim_app
 
std::vector< std::string > m_directories
 
std::map< uint32_t, W_FONT_OBJECTm_fonts
 
uint32_t m_curFont
 
WColor m_curColor
 
class WEffectm_textEffect
 

Detailed Description

A WTextComponent provides an interface to allow text rendering.

Member Function Documentation

◆ AddFontDirectory()

void WTextComponent::AddFontDirectory ( std::string  dir)

Adds a directory from which fonts can be loaded.

Parameters
dirNew directory to load fonts from

◆ CreateTextFont()

WError WTextComponent::CreateTextFont ( uint32_t  ID,
std::string  fontName 
)

Creates a new font.

Parameters
IDID to assign the font to. The ID must be unique
fontNameFilename of the font (.ttf file), which can be relative to any of the added font directories (see AddFontDirectory())
Returns
Error code, see WError.h

◆ DestroyFont()

WError WTextComponent::DestroyFont ( uint32_t  ID)

Destroys a font.

Parameters
IDID of the font to destroy
Returns
Error code, see WError.h

◆ GetTextWidth()

float WTextComponent::GetTextWidth ( std::string  text,
float  fHeight,
uint32_t  fontID = 0 
)

Retrieves the width that would be occupied by a text if it was to render.

Parameters
textText to check its width
fHeightHeight that will be used for the render call
fontIDFont that will be used for the render call, -1 for default
Returns
Width, in pixels, of the text if it was to render using the specified parameters

◆ Initialize()

WError WTextComponent::Initialize ( )

Initializes the text component and all its resources.

Returns
Error code, see WError.h

◆ Render()

void WTextComponent::Render ( class WRenderTarget rt)

Renders all text onto the render target.

Parameters
rtRender target to render to

◆ RenderText() [1/3]

WError WTextComponent::RenderText ( std::string  text,
float  x,
float  y,
float  fHeight 
)

Adds text to be rendered on the next frame.

Parameters
textText to render
xX-coordinate to render at
yY-coordinate to render at
fHeightHeight of a text character
Returns
Error code, see WError.h

◆ RenderText() [2/3]

WError WTextComponent::RenderText ( std::string  text,
float  x,
float  y,
float  fHeight,
uint32_t  fontID 
)

Adds text to be rendered on the next frame.

Parameters
textText to render
xX-coordinate to render at
yY-coordinate to render at
fHeightHeight of a text character
fontIDID of the font to use
Returns
Error code, see WError.h

◆ RenderText() [3/3]

WError WTextComponent::RenderText ( std::string  text,
float  x,
float  y,
float  fHeight,
uint32_t  fontID,
WColor  col 
)

Adds text to be rendered on the next frame.

Parameters
textText to render
xX-coordinate to render at
yY-coordinate to render at
fHeightHeight of a text character
fontIDID of the font to use
colColor to use for rendering
Returns
Error code, see WError.h

◆ SetFont()

WError WTextComponent::SetFont ( uint32_t  ID)

Sets the default font ID for the following text renders (if not specified in the render call).

Parameters
IDID of the font to set default
Returns
Error code, see WError.h

◆ SetTextColor()

WError WTextComponent::SetTextColor ( WColor  col)

Sets the default color for the following text renders (if not specified in the render call).

Parameters
colNew color to set
Returns
Error code, see WError.h

Member Data Documentation

◆ m_app

class Wasabi* WTextComponent::m_app
protected

Pointer to the Wasabi class

◆ m_curColor

WColor WTextComponent::m_curColor
protected

Current (Default) color

◆ m_curFont

uint32_t WTextComponent::m_curFont
protected

Current (default) font ID

◆ m_directories

std::vector<std::string> WTextComponent::m_directories
protected

List of directories in which fonts could be found

◆ m_fonts

std::map<uint32_t, W_FONT_OBJECT> WTextComponent::m_fonts
protected

A hashtable for the fonts, mapping ID -> font

◆ m_textEffect

class WEffect* WTextComponent::m_textEffect
protected

Effect to use for rendering texts


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