gui::text Class Reference

Used to draw some text on the screen. More...

#include <gui_text.hpp>

List of all members.

Classes

struct  format
 Contains information about the text at a given position. More...
struct  letter
 Holds the position, tex. coordinates and color of a character. More...
struct  line
 Contains a string that will be drawn on a line. More...

Public Types

enum  color_action { COLOR_ACTION_NONE, COLOR_ACTION_SET, COLOR_ACTION_RESET }
enum  alignment { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT }
enum  vertical_alignment { ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM }

Public Member Functions

 text (manager *pManager, const std::string &sFileName, float fSize)
 Constructor.
 ~text ()
 Destructor.
const std::string & get_font_name () const
 Returns the path to the .ttf file.
float get_font_size () const
 Returns the size of the font.
float get_line_height () const
 Returns the height of one line (constant).
void set_text (const std::string &sText)
 set_ the text to render.
const std::string & get_text () const
 Returns the text that will be rendered.
const utils::ustring & get_unicode_text () const
 Returns the text that will be rendered (unicode character set).
void set_color (const color &mColor, bool bForceColor=false)
 Sets this text's default color.
const colorget_color () const
 Returns this text's default color.
void set_dimensions (float fW, float fH)
 Sets the dimensions of the text box.
void set_box_width (float fBoxW)
 Sets the width of the text box.
void set_box_height (float fBoxH)
 Sets the height of the text box.
float get_width ()
 Returns the width of the rendered text.
float get_height ()
 Returns the height of the rendered text.
float get_box_width () const
 Returns the width of the text box.
float get_box_height () const
 Returns the height of the text box.
float get_text_width () const
 Returns the length of the text.
float get_string_width (const std::string &sString) const
 Returns the lenght of a provided string.
float get_string_width (const utils::ustring &sString) const
 Returns the lenght of a provided string.
float get_character_width (uint uiChar) const
 Returns the length of a single character.
float get_character_kerning (uint uiChar1, uint uiChar2) const
 Returns the kerning between two characters.
float get_text_height () const
 Returns the height of the text.
void set_alignment (const alignment &mAlign)
 Sets text alignment.
void set_vertical_alignment (const vertical_alignment &mVertAlign)
 Sets text vertical alignment.
const alignmentget_alignment () const
 Returns the text aligment.
const vertical_alignmentget_vertical_alignment () const
 Returns the text aligment.
void set_tracking (float fTracking)
 Sets this text's tracking.
float get_tracking () const
 Returns this text's tracking.
void set_line_spacing (float fLineSpacing)
 Sets this text's line spacing.
float get_line_spacing () const
 Returns this text's line spacing.
void set_remove_starting_spaces (bool bRemoveStartingSpaces)
 Allows removal of a line's starting spaces.
bool get_remove_starting_spaces () const
 Checks if starting spaces removing is active.
void enable_word_wrap (bool bWrap, bool bAddEllipsis)
 Allows word wrap when the line is too long for the text box.
bool is_word_wrap_enabled () const
 Checks if word wrap is enabled.
void enable_formatting (bool bFormatting)
 Enables color formatting.
void render (float fX, float fY)
 Renders this text at the given position.
void update ()
 updates this text's cache.
const std::vector< letter > & get_letter_cache ()
 Returns the cached letters (position, size, texture coordinates).
utils::refptr< spritecreate_sprite (uint uiChar) const
 Creates a sprite that contains the provided character.

Detailed Description

Used to draw some text on the screen.

Definition at line 22 of file gui_text.hpp.


Member Enumeration Documentation

Enumerator:
ALIGN_LEFT 
ALIGN_CENTER 
ALIGN_RIGHT 

Definition at line 50 of file gui_text.hpp.

Enumerator:
COLOR_ACTION_NONE 
COLOR_ACTION_SET 
COLOR_ACTION_RESET 

Definition at line 33 of file gui_text.hpp.

Enumerator:
ALIGN_TOP 
ALIGN_MIDDLE 
ALIGN_BOTTOM 

Definition at line 57 of file gui_text.hpp.


Constructor & Destructor Documentation

gui::text::text ( manager pManager,
const std::string &  sFileName,
float  fSize 
)

Constructor.

Parameters:
sFileName The path to the .ttf file to use
fSize The size of the font (in point)

Definition at line 17 of file gui_text.cpp.

gui::text::~text (  ) 

Destructor.

Definition at line 41 of file gui_text.cpp.


Member Function Documentation

utils::refptr< sprite > gui::text::create_sprite ( uint  uiChar  )  const

Creates a sprite that contains the provided character.

Parameters:
uiChar The character to draw
Note:
Uses this text's font texture.

Definition at line 924 of file gui_text.cpp.

void gui::text::enable_formatting ( bool  bFormatting  ) 

Enables color formatting.

Parameters:
bFormatting 'true' to enable color formatting
Note:
Enabled by default.
- "|cAARRGGBB" : sets text color (hexadecimal).
  • "|r" : sets text color to default.
  • "||" : writes "|".

Definition at line 338 of file gui_text.cpp.

void gui::text::enable_word_wrap ( bool  bWrap,
bool  bAddEllipsis 
)

Allows word wrap when the line is too long for the text box.

Parameters:
bWrap 'true' to enable word wrap
bAddEllipsis 'true' to put "..." at the end of a truncated line
Note:
Enabled by default.

Definition at line 323 of file gui_text.cpp.

const text::alignment & gui::text::get_alignment (  )  const

Returns the text aligment.

Returns:
The text alignment

Definition at line 271 of file gui_text.cpp.

float gui::text::get_box_height (  )  const

Returns the height of the text box.

Returns:
The height of the text box

Definition at line 141 of file gui_text.cpp.

float gui::text::get_box_width (  )  const

Returns the width of the text box.

Returns:
The width of the text box

Definition at line 136 of file gui_text.cpp.

float gui::text::get_character_kerning ( uint  uiChar1,
uint  uiChar2 
) const

Returns the kerning between two characters.

Parameters:
uiChar1 The first character
uiChar2 The second character
Returns:
The kerning between two characters
Note:
Kerning is a letter spacing adjustment that makes the text look more condensed : is you stick an A near a V, you can reduce the space between the two letters, but not if you put two Vs side to side.

Definition at line 248 of file gui_text.cpp.

float gui::text::get_character_width ( uint  uiChar  )  const

Returns the length of a single character.

Parameters:
uiChar The character to measure
Returns:
The lenght of this character

Definition at line 233 of file gui_text.cpp.

const color & gui::text::get_color (  )  const

Returns this text's default color.

Returns:
This text's default color

Definition at line 90 of file gui_text.cpp.

const std::string & gui::text::get_font_name (  )  const

Returns the path to the .ttf file.

Returns:
The path to the .ttf file

Definition at line 45 of file gui_text.cpp.

float gui::text::get_font_size (  )  const

Returns the size of the font.

Returns:
The size of the font

Definition at line 50 of file gui_text.cpp.

float gui::text::get_height (  ) 

Returns the height of the rendered text.

Returns:
The height of the rendered text
Note:
Takes the text box into account if any.

Definition at line 129 of file gui_text.cpp.

const std::vector< text::letter > & gui::text::get_letter_cache (  ) 

Returns the cached letters (position, size, texture coordinates).

Returns:
The cached letters
Note:
updates the letter cache if needed.

Definition at line 939 of file gui_text.cpp.

float gui::text::get_line_height (  )  const

Returns the height of one line (constant).

Returns:
The height of one line (constant)

Definition at line 55 of file gui_text.cpp.

float gui::text::get_line_spacing (  )  const

Returns this text's line spacing.

Returns:
This text's line spacing

Definition at line 304 of file gui_text.cpp.

bool gui::text::get_remove_starting_spaces (  )  const

Checks if starting spaces removing is active.

Returns:
'true' if starting spaces removing is active

Definition at line 318 of file gui_text.cpp.

float gui::text::get_string_width ( const utils::ustring &  sString  )  const

Returns the lenght of a provided string.

Parameters:
sString The string to measure
Returns:
The lenght of the provided string

Definition at line 198 of file gui_text.cpp.

float gui::text::get_string_width ( const std::string &  sString  )  const

Returns the lenght of a provided string.

Parameters:
sString The string to measure
Returns:
The lenght of the provided string

Definition at line 193 of file gui_text.cpp.

const std::string & gui::text::get_text (  )  const

Returns the text that will be rendered.

Returns:
The text that will be rendered
Note:
This string contains format tags.

Definition at line 70 of file gui_text.cpp.

float gui::text::get_text_height (  )  const

Returns the height of the text.

Returns:
The height of one text
Note:
Ignores the text box, but not manual line jumps.

Definition at line 176 of file gui_text.cpp.

float gui::text::get_text_width (  )  const

Returns the length of the text.

Returns:
The length of the text
Note:
Ignores the text box, but not manual line jumps.

Definition at line 146 of file gui_text.cpp.

float gui::text::get_tracking (  )  const

Returns this text's tracking.

Returns:
This text's tracking

Definition at line 290 of file gui_text.cpp.

const utils::ustring & gui::text::get_unicode_text (  )  const

Returns the text that will be rendered (unicode character set).

Returns:
The text that will be rendered (unicode character set)
Note:
This string contains format tags.

Definition at line 75 of file gui_text.cpp.

const text::vertical_alignment & gui::text::get_vertical_alignment (  )  const

Returns the text aligment.

Returns:
The text alignment

Definition at line 276 of file gui_text.cpp.

float gui::text::get_width (  ) 

Returns the width of the rendered text.

Returns:
The width of the rendered text
Note:
Takes the text box into account if any.

Definition at line 122 of file gui_text.cpp.

bool gui::text::is_word_wrap_enabled (  )  const

Checks if word wrap is enabled.

Returns:
'true' if word wrap is enabled

Definition at line 333 of file gui_text.cpp.

void gui::text::render ( float  fX,
float  fY 
)

Renders this text at the given position.

Parameters:
fX The horizontal position of the top left corner
fY The vertical position of the top left corner
Note:
Must be called between spriteManager::begin() and spriteManager::end().

Definition at line 347 of file gui_text.cpp.

void gui::text::set_alignment ( const alignment mAlign  ) 

Sets text alignment.

Parameters:
mAlign The new alignment

Definition at line 253 of file gui_text.cpp.

void gui::text::set_box_height ( float  fBoxH  ) 

Sets the height of the text box.

Parameters:
fBoxH The new height
Note:
To remove it, use 0.0f.

Definition at line 113 of file gui_text.cpp.

void gui::text::set_box_width ( float  fBoxW  ) 

Sets the width of the text box.

Parameters:
fBoxW The new witdh
Note:
To remove it, use 0.0f.

Definition at line 104 of file gui_text.cpp.

void gui::text::set_color ( const color mColor,
bool  bForceColor = false 
)

Sets this text's default color.

Parameters:
mColor The default color
bForceColor 'true' to ignore color tags

Definition at line 80 of file gui_text.cpp.

void gui::text::set_dimensions ( float  fW,
float  fH 
)

Sets the dimensions of the text box.

Parameters:
fW The new witdh
fH The new height
Note:
To remove the text box, use 0.0f.

Definition at line 95 of file gui_text.cpp.

void gui::text::set_line_spacing ( float  fLineSpacing  ) 

Sets this text's line spacing.

Parameters:
fLineSpacing The new line spacing
Note:
Line spacing is a coefficient that, multiplied by the height of a line, gives the space between two lines. Default is 1.5f.

Definition at line 295 of file gui_text.cpp.

void gui::text::set_remove_starting_spaces ( bool  bRemoveStartingSpaces  ) 

Allows removal of a line's starting spaces.

Parameters:
bRemoveStartingSpaces 'true' to remove them
Note:
The text box does word wrapping : it cuts too long lines only between words. But sometimes, the rendered text must be cut between several spaces. By default, the algorithm puts cuted spaces at the beginning of the next line. You can change this behavior by setting this function to 'true'.

Definition at line 309 of file gui_text.cpp.

void gui::text::set_text ( const std::string &  sText  ) 

set_ the text to render.

Parameters:
sText The text to render
Note:
This text can be formated :
  • "|cAARRGGBB" : sets text color (hexadecimal).
  • "|r" : sets text color to default.
  • "||" : writes "|".

Definition at line 60 of file gui_text.cpp.

void gui::text::set_tracking ( float  fTracking  ) 

Sets this text's tracking.

Parameters:
fTracking The new tracking
Note:
Tracking is the space between each character. Default is 0.

Definition at line 281 of file gui_text.cpp.

void gui::text::set_vertical_alignment ( const vertical_alignment mVertAlign  ) 

Sets text vertical alignment.

Parameters:
mVertAlign The new vertical alignment

Definition at line 262 of file gui_text.cpp.

void gui::text::update (  ) 

updates this text's cache.

Note:
Automatically done by render().
Only use this method if you need it to be Updated sooner.

Definition at line 416 of file gui_text.cpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Tue Jan 1 21:58:12 2013 for gui by  doxygen 1.6.1