29 #include "nomlib/graphics/TrueTypeFont.hpp"
35 NOM_LOG_TRACE ( NOM );
42 this->text_alignment = TextAlignment::MiddleLeft;
43 this->rendering = RenderStyle::Solid;
44 this->style_options = 0;
49 if ( TTF_Init () == -1 )
51 NOM_LOG_ERR ( NOM, TTF_GetError() );
57 NOM_LOG_TRACE ( NOM );
68 return IFont::SharedPtr (
new TrueTypeFont ( *
this ), priv::Free_TrueTypeFont );
73 if ( this->
font.get() != nullptr )
95 return this->
coords.height;
103 const Color& TrueTypeFont::getColor (
void )
const
108 const Coords& TrueTypeFont::getPosition (
void )
const
125 IFont::TextAlignment TrueTypeFont::getTextJustification (
void )
const
127 return this->text_alignment;
130 void TrueTypeFont::setColor (
const Color& color )
135 void TrueTypeFont::setPosition (
const Coords& coords )
137 this->coords.x = coords.x;
138 this->coords.y = coords.y;
143 int32 original_font_size = this->
font_size;
147 if ( this->
rebuild() ==
false )
149 NOM_LOG_ERR ( NOM,
"Could not set new font size." );
160 case FontStyle::Regular:
162 TTF_SetFontStyle ( this->
font.get(), TTF_STYLE_NORMAL );
166 case FontStyle::Bold:
168 TTF_SetFontStyle ( this->
font.get(), TTF_STYLE_BOLD );
172 case FontStyle::Italic:
174 TTF_SetFontStyle ( this->
font.get(), TTF_STYLE_ITALIC );
178 case FontStyle::Underlined:
180 TTF_SetFontStyle ( this->
font.get(), TTF_STYLE_UNDERLINE );
185 case FontStyle::Faded:
188 this->style_options = options;
196 return TTF_GetFontOutline ( this->
font.get() );
201 TTF_SetFontOutline ( this->
font.get(), depth );
206 return this->rendering;
211 this->rendering = style;
216 if ( text.length() < 1 )
return;
223 NOM_LOG_ERR ( NOM,
"Failed to set font width & height." );
234 this->text_alignment = alignment;
241 this->
font = std::shared_ptr<TTF_Font> ( TTF_OpenFont ( filename.c_str(), this->
font_size ), nom::priv::TTF_FreeFont );
243 if ( this->
valid() ==
false )
245 NOM_LOG_ERR ( NOM,
"Could not load TTF file: " + filename );
264 if ( this->
getText().c_str() ==
nullptr )
return;
266 if ( this->rendering == RenderStyle::Shaded )
272 SDL_COLOR(this->
color),
276 SDL_COLOR (
Color ( 97, 97, 97 ) )
280 else if ( this->rendering == RenderStyle::Blended )
286 SDL_COLOR(this->
color)
296 SDL_COLOR(this->
color)
303 this->
font_buffer.set_alpha ( this->style_options );
327 NOM_LOG_ERR ( NOM,
"Could not rebuild font metrics." );
bool load(const std::string &filename, const Color &colorkey, bool use_cache=false)
Load a new font in from a file.
std::shared_ptr< TTF_Font > font
Font file data, used by SDL_ttf extension.
void draw(SDL_Renderer *target) const
Draw the set text string to the video surface.
void set_position(const Point2i &pos)
void setText(const std::string &text)
Set a new text string for drawing; defaults to \0.
int32 getFontHeight(void) const
Compute the height in pixels of the set text string; defaults to zero (0)
static const Color Black
Predefined color constants for convenience sake.
void setFontOutline(int32 depth)
Set a new vector outline – in pixels – for the loaded font.
const std::string & getText(void) const
Obtains set text string buffer; defaults to \0.
void setFontStyle(int32 style, uint8 options=150)
IFont::SharedPtr clone(void) const
Return a std::shared_ptr copy of this instance.
int32 getFontOutline(void) const
Getter for obtaining the vector outline of the loaded font.
RenderStyle
Text rendering qualities.
void draw(SDL_RENDERER::RawPtr target) const
int32 getFontWidth(void) const
Compute the width in pixels of the set text string; defaults to zero (0)
FontStyle text_style
Current text effect set.
~TrueTypeFont(void)
Default destructor; we shutdown the SDL_ttf extension here.
std::string filename
Store the file path so we can change font sizes on the fly.
Texture font_buffer
Surface where font for drawing is rendered to.
FontStyle
Text effect styling.
void setSpacing(uint32 spaces)
Not implemented.
uint32 getSpacing(void) const
Not implemented.
SDL_RENDERER::RawPtr renderer(void) const
Get a raw pointer to the SDL_Renderer in use.
Coords coords
Positioning coordinates (including width and height)
IFont::RenderStyle getRenderingStyle(void) const
Getter for obtaining the current font rendering style in use.
uint32 getNewline(void) const
Not implemented.
std::string text_buffer
holds contents of text as a string buffer
bool valid(void) const
Is this object initialized – not nullptr?
TrueTypeFont(void)
Default constructor; we initialize the SDL_ttf extension here.
bool valid(void) const
Is this object initialized – not nullptr?
Coordinate values (x, y, z, width, height ) wrapper.
bool initialize(SDL_SURFACE::RawPtr video_buffer)
bool use_cache
Whether or not to use caching features of nom::ObjectCache.
int32 font_size
Font point (pixel) size; defaults to 12.
void setTextJustification(IFont::TextAlignment alignment)
Not implemented.
Utility class container for RGBA colors.
void setRenderingStyle(IFont::RenderStyle)
Set a new font rendering style.
void setFontSize(int32 point_size)
Set a new text point size.