Rose
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
rose::Text Class Reference

Encapsulation of code for rendering Text. More...

#include <Text.h>

Inheritance diagram for rose::Text:
Inheritance graph
[legend]
Collaboration diagram for rose::Text:
Collaboration graph
[legend]

Public Types

enum  RenderStyle { Blended, Shaded, Solid }
 
enum  Status {
  OK, TextEmpty, FontError, SurfaceError,
  TextureError
}
 

Public Member Functions

 Text (const Text &)=delete
 
 Text (Text &&)=delete
 
Textoperator= (const Text &)=delete
 
Textoperator= (Text &&)=delete
 
Status createTextureBlended (gm::Context &context)
 Create a Blended Texture from text. More...
 
void setPointSize (int pointSize)
 Set the font point size.
 
void setFontName (const std::string &fontName)
 Set the font name.
 
bool setText (const std::string &text)
 Set the text displayed. More...
 
bool textUpdated ()
 
void setSuffix (const std::string &suffix)
 
void setTextMaxSize (int maxSize, char em='\0')
 
void setTextValidationPattern (const std::string &regex)
 

Protected Member Functions

void setEditingMode (bool editing, int carret)
 Set the editing mode.
 

Protected Attributes

std::string mText {}
 The UTF8 or ASCII text to render.
 
std::string mSuffix {}
 The UTF8 or ASCII suffix.
 
color::RGBA mTextFgColor
 The foreground color to use.
 
color::RGBA mTextBgColor
 The background color to use if rendering Shaded.
 
color::RGBA mCaretColor {}
 The color of the caret when editing.
 
color::RGBA mRegexFail {}
 The text colour for regex validation failure.
 
color::RGBA mDataSaved {}
 The text colour when the data has been saved to settings.
 
float mCaretAlpha {0.f}
 The alpha value of the caret during animation.
 
RenderStyle mRenderStyle {Blended}
 The style of rendering Solid, Shaded, or Blended.
 
std::string mFontName
 The name of the True Type Font to use.
 
std::shared_ptr< _TTF_Font > mFont {}
 The cached font used.
 
int mPointSize
 The point (pixel) size of the font.
 
gm::Texture mTexture {}
 The generated Texture.
 
Size mTextSize {}
 The size of the Texture in pixels.
 
Status mStatus {OK}
 The Status of the last operation.
 
int mCaretLocation {0}
 The location of the caret.
 
bool mEditingActive {false}
 True when the text is being edited.
 
bool mEditable {false}
 The label text is editable.
 
bool mTextValidated {true}
 Ture when the content validates by mValidationPatter.
 
bool mSaveToSettings {false}
 Set to true when modifications have been saved.
 
int mMaxSize {0}
 The maximum number of characters to be held, 0 indicates variable.
 
char eM {'N'}
 The character used to compute the maximum screen rectangle width.
 
std::unique_ptr< std::regex > mValidationPattern {}
 Regular expression to validate content.
 

Detailed Description

Encapsulation of code for rendering Text.

Member Enumeration Documentation

◆ RenderStyle

Enumerator
Blended 

Render text blended on a transparent background.

Shaded 

Render text shaded on a solid background.

Solid 

Render text without blending or shading. Fastest but lowest quality.

◆ Status

Enumerator
OK 

Operation succeeded.

TextEmpty 

The text to be rendered was empty.

FontError 

The Font was not found.

SurfaceError 

The API returned a nullptr Surface.

TextureError 

The API returned a nullptr Texture.

Member Function Documentation

◆ createTextureBlended()

Text::Status rose::Text::createTextureBlended ( gm::Context context)

Create a Blended Texture from text.

Fetches the Font corresponding to mFontName and mPointSize, then renders the text in mText as UTF8 to mTexture. The foreground color is set to mTextFgColor. If mRenderStyle is set to Shaded the background color is set to mTextBgColor. The size of the Texture is placed in mTextSize.

If the requested font is not found, or mText is empty any mTexture is reset and mTextSize is set to Zero.

Parameters
contextThe graphics Context.
Returns
The Status of the operation.

◆ setText()

bool rose::Text::setText ( const std::string &  text)
inline

Set the text displayed.

Parameters
textThe new text.
Returns
True if the text has changed, false otherwise.

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