nomlib
Loading...
Searching...
No Matches
nom::Text Class Reference

#include <Text.hpp>

Inheritance diagram for nom::Text:
[legend]

Public Types

enum  Style : uint32 {
  Normal = 0 , Bold = 2 , Italic = 4 , Underline = 8 ,
  Strikethrough = 16
}
 Font face style; multiple styles can be combined from bitwise masks. More...
typedef Text self_type
typedef Transformable derived_type
Public Types inherited from nom::Transformable
typedef Transformable self_type
Public Types inherited from nom::IDrawable
typedef IDrawable self_type
typedef self_type * raw_ptr
 A type definition for a C pointer – raw pointer – to an IDrawable object.
typedef std::unique_ptr< self_type > unique_ptr
 A type definition for a C++11 std::unique_ptr to an IDrawable object.
typedef std::shared_ptr< self_type > shared_ptr
 A type definition for a C++11 std::shared_ptr to an IDrawable object.
typedef const RenderWindow RenderTarget
Public Types inherited from nom::IObject
typedef IObject self_type
typedef IObjectraw_ptr

Public Member Functions

 Text (void)
 Default constructor.
 ~Text (void)
 Destructor.
 Text (const std::string &text, const Font &font, uint character_size=nom::DEFAULT_FONT_SIZE, const Color4i &text_color=Color4i::White)
 Construct a Text, initializing it with a text string, a nom::Font object reference and character size.
 Text (const std::string &text, Font *font, uint character_size=nom::DEFAULT_FONT_SIZE, const Color4i &text_color=Color4i::White)
 Construct a Text, initializing it with a text string, a nom::Font object pointer and character size.
 Text (const self_type &rhs)
 Copy constructor.
self_type & operator= (const self_type &rhs)
 Copy assignment operator.
virtual void set_position (const Point2i &pos) override
 Set the position of the rendered text.
Textclone () const
 Implements the required IDrawable::clone method.
ObjectTypeInfo type () const override
 Re-implements the IObject::type method.
const Fontfont () const
Textureclone_texture () const
 Get a deep-copy instance of the underlying texture used for the text rendering.
bool valid (void) const
 Obtain validity of the Text object.
int text_width (const std::string &text_buffer) const
 Obtain the text width (in pixels) of the set text.
sint text_height (const std::string &text_string) const
 Obtain the text height in pixels of the set text.
const std::string & text (void) const
 Get text string.
const Color4i & color (void) const
 Get text color.
uint32 style (void) const
 Get text style.
uint text_size (void) const
 Get text character size (in pixels?).
void set_font (const Font &font)
 Set the font to use in rendering text.
void set_font (Font *font)
 Set the font to use in rendering text.
void set_text (const std::string &text)
 Set the text string to be rendered.
void set_text_size (uint character_size)
 Set the text's font point size.
void set_color (const Color4i &text_color)
 Set text's font color.
void set_style (uint32 style)
 Set the text's rendering style for the font.
void set_text_kerning (bool state)
 Set the use of rendering glyphs with respect to kerning offsets, when supported by the underlying font type.
void draw (RenderTarget &target) const override
Public Member Functions inherited from nom::Transformable
 Transformable (const Point2i &pos, const Size2i &size)
 Transformable (const IntRect &bounds)
 Construct an object using a complete set of coordinates (bounds).
ObjectTypeInfo type () const override
 Re-implements the IObject::type method.
const Point2i & position (void) const
 Getter for stored positioning coordinates.
const Size2i & size (void) const
 Getter for stored size dimensions.
virtual void set_size (const Size2i &size)
 Set the size dimensions– width & height rendering coordinates of the object.
virtual void set_bounds (const IntRect &bounds)
 Set the complete bounds of the object – position (X, Y) and size (width and height) dimensions.
void set_position (int x, int y)
void set_size (int w, int h)
virtual void translate (const Point2i &pos)
Public Member Functions inherited from nom::IDrawable
 IDrawable (void)
 Do nothing at all default constructor.
virtual ~IDrawable (void)
 Do nothing at all destructor.
Public Member Functions inherited from nom::IObject
 IObject (void)
 Default constructor.
virtual ~IObject (void)
 Virtual destructor.
virtual bool is_type (const ObjectTypeInfo &rhs) const
 Compare this object type with another object's type.

Private Member Functions

void render_text (RenderTarget &target) const
void update () override
 Apply requested transformations, styles, etc.
int width () const
 Get the current text width.
int height () const
 Get the current text height.
bool update_cache ()
int multiline_width (const std::string &text_buffer, nom::size_type pos) const

Private Attributes

Font font_
Texture glyphs_texture_
 A texture atlas created from the nom::Font instance that is referred to in rendering a text.
std::unique_ptr< Texturerendered_text_
 The texture containing the rendered text.
std::string text_
 Holds contents of text as a string buffer.
uint text_size_
Color4i color_
uint32 style_
 Current text effect set.
bool dirty_

Additional Inherited Members

Static Public Member Functions inherited from nom::IObject
template<typename Base, typename Derived>
static bool is_a (const Derived object)
 Compare two objects to determine if a derived class inherits from a base class object.
static void * operator new (nom::size_type mem)
static void operator delete (void *ptr)
Static Public Attributes inherited from nom::IObject
static uint64 total_alloc_bytes
static uint64 total_dealloc_bytes

Detailed Description

[TODO: DESCRIPTION]

Definition at line 45 of file Text.hpp.

Member Typedef Documentation

◆ derived_type

typedef Transformable nom::Text::derived_type

Definition at line 49 of file Text.hpp.

◆ self_type

typedef Text nom::Text::self_type

Definition at line 48 of file Text.hpp.

Member Enumeration Documentation

◆ Style

enum nom::Text::Style : uint32

Font face style; multiple styles can be combined from bitwise masks.

Remarks
Styles are only available with TrueType fonts. No action will result from using these styles with a bitmap font.
Todo
Implement styles for BitmapFont objects.
Enumerator
Bold 

Default.

Definition at line 58 of file Text.hpp.

Constructor & Destructor Documentation

◆ Text()

nom::Text::Text ( const self_type & rhs)

Copy constructor.

Remarks
This is necessary for the std::unique_ptr instance we use for the cached texture.

Member Function Documentation

◆ clone_texture()

Texture * nom::Text::clone_texture ( ) const

Get a deep-copy instance of the underlying texture used for the text rendering.

Returns
A raw pointer to a new nom::Texture instance of the rendered text. The returned pointer is owned by the caller.

◆ draw()

void nom::Text::draw ( RenderTarget & target) const
overridevirtual

Render text to a target

Todo
Test horizontal tabbing '\t'

Implements nom::IDrawable.

◆ operator=()

self_type & nom::Text::operator= ( const self_type & rhs)

Copy assignment operator.

Remarks
This is necessary for the std::unique_ptr instance we use for the cached texture.

◆ set_font() [1/2]

void nom::Text::set_font ( const Font & font)

Set the font to use in rendering text.

Remarks
You must ensure that you are passing a valid nom::Font object that has been loaded into memory with its appropriate ::load call.

◆ set_font() [2/2]

void nom::Text::set_font ( Font * font)

Set the font to use in rendering text.

Remarks
This method exists for the convenience of direct interfacing with the nom::IFont interface. You must ensure that you are passing a valid nom::IFont-derived object that has been loaded into memory with its appropriate ::load call.
Note
This method is used by nom::FontCache.

◆ set_position()

virtual void nom::Text::set_position ( const Point2i & pos)
overridevirtual

Set the position of the rendered text.

Remarks
Re-implements Transformable::set_position.

Reimplemented from nom::Transformable.

◆ set_style()

void nom::Text::set_style ( uint32 style)

Set the text's rendering style for the font.

See also
The nom::Text::Style enumeration.

◆ set_text_size()

void nom::Text::set_text_size ( uint character_size)

Set the text's font point size.

Remarks
This method rebuilds the texture atlas when the point size differs from the current set point size, and may be an expensive operation.
Note
The text's font must be set for this method call to succeed.

◆ text_height()

sint nom::Text::text_height ( const std::string & text_string) const

Obtain the text height in pixels of the set text.

Remarks
This calculation should mimic the rendering calculations precisely.
Returns
Non-negative integer value of the object's text string height, in pixels, on success. Zero (0) integer value on failure; a possible combination of: no font, bad font, no text string etc.

◆ text_width()

int nom::Text::text_width ( const std::string & text_buffer) const

Obtain the text width (in pixels) of the set text.

Remarks
This calculation should mimic the rendering calculations precisely.
Returns
Non-negative integer value of the object's text string width, in pixels, on success. Zero (0) integer value on failure; a possible combination of: no font, bad font, no text string etc.

◆ type()

ObjectTypeInfo nom::Text::type ( ) const
overridevirtual

Re-implements the IObject::type method.

Remarks
This uniquely identifies the object's type.

Reimplemented from nom::IDrawable.

◆ update()

void nom::Text::update ( )
overrideprivatevirtual

Apply requested transformations, styles, etc.

Remarks
This internal method takes care of updating the properties of the font in the correct order, so that the end-user (developer) does not need to worry about using the API in a particular order.
Note
Implements nom::IDrawable::update.

Implements nom::IDrawable.

Member Data Documentation

◆ color_

Color4i nom::Text::color_
private

Definition at line 252 of file Text.hpp.

◆ dirty_

bool nom::Text::dirty_
private
See also
nom::Text::update

Definition at line 258 of file Text.hpp.

◆ font_

Font nom::Text::font_
private

Definition at line 236 of file Text.hpp.

◆ glyphs_texture_

Texture nom::Text::glyphs_texture_
mutableprivate

A texture atlas created from the nom::Font instance that is referred to in rendering a text.

See also
::set_text_size, ::update, ::render_text

Definition at line 242 of file Text.hpp.

◆ rendered_text_

std::unique_ptr<Texture> nom::Text::rendered_text_
private

The texture containing the rendered text.

See also
::update_cache, ::texture, ::draw

Definition at line 247 of file Text.hpp.

◆ style_

uint32 nom::Text::style_
private

Current text effect set.

Definition at line 255 of file Text.hpp.

◆ text_

std::string nom::Text::text_
private

Holds contents of text as a string buffer.

Definition at line 250 of file Text.hpp.

◆ text_size_

uint nom::Text::text_size_
private

Definition at line 251 of file Text.hpp.


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