Gorgon Game Engine
StyledRenderer Class Reference

This text renderer can style text according to the set parameters. More...

Inheritance diagram for StyledRenderer:
[legend]

Public Member Functions

 StyledRenderer ()=default
 
 StyledRenderer (GlyphRenderer &renderer, RGBAf color=1.f, TextShadow shadow={})
 Renderer must be ready in order to calculate spacings correctly. More...
 
void AlignCenter ()
 Aligns the text to the center, removes justify. More...
 
void AlignLeft ()
 Aligns the text to the left, removes justify. More...
 
void AlignRight ()
 Aligns the text to the right, removes justify. More...
 
void DisableShadow ()
 Disables text shadow. More...
 
virtual float GetBaseLine () const override
 Get the distance of baseline from the top of the text. More...
 
virtual int GetCharacterIndex (const std::string &text, Geometry::Point location) const override
 Returns the character index of glyph immediately after the given location. This function is Unicode aware. More...
 
virtual int GetCharacterIndex (const std::string &text, int w, Geometry::Point location, bool wrap=true) const override
 Returns the character index of glyph immediately after the given location. This function is Unicode aware. More...
 
RGBAf GetColor () const
 Returns color of the text. More...
 
TextAlignment GetDefaultAlign () const
 Returns the default alignment for the text. More...
 
virtual int GetEMSize () const override
 Returns the size of the EM dash. More...
 
GlyphRendererGetGlyphRenderer ()
 
virtual const GlyphRendererGetGlyphRenderer () const override
 Returns the glyphrenderer that is used by this text renderer. More...
 
virtual int GetHeight () const override
 Get the distance of baseline from the top of the text. More...
 
bool GetJustify () const
 Returns whether the text would be justified. More...
 
int GetLetterSpacing () const
 Returns the spacing between the letters in pixels. More...
 
float GetLineSpacing () const
 Returns the line spacing as percentage of line gap. More...
 
int GetLineSpacingPixels () const
 Returns the line spacing in pixels. More...
 
int GetParagraphSpacing () const
 Get the space between paragraphs in pixels. More...
 
virtual Geometry::Rectangle GetPosition (const std::string &text, int index) const override
 Returns the position of the glyph at the character index. More...
 
virtual Geometry::Rectangle GetPosition (const std::string &text, int w, int index, bool wrap=true) const override
 Returns the position of the glyph at the character index. More...
 
TextShadow GetShadow () const
 Returns text shadow. More...
 
virtual Geometry::Size GetSize (const std::string &text) const override
 Returns the size of the given text. More...
 
virtual Geometry::Size GetSize (const std::string &text, int width) const override
 Returns the size of the given text. More...
 
bool GetStrike () const
 Returns whether the text would stroked. More...
 
RGBAf GetStrikeColor () const
 Returns the current strike color. More...
 
int GetStrikePosition () const
 Returns current strike position. More...
 
int GetTabWidth () const
 Returns tab width in pixels. More...
 
bool GetUnderline () const
 Returns whether the text is underlined. More...
 
RGBAf GetUnderlineColor () const
 Returns the current underline color. More...
 
virtual bool IsReady () const override
 Whether the render can render text. More...
 
void JustifyCenter ()
 Aligns the text to the center, sets justify. More...
 
void JustifyLeft ()
 Aligns the text to the left, sets justify. More...
 
void JustifyRight ()
 Aligns the text to the right, sets justify. More...
 
void ResetStrikeColor ()
 Sets strike color to match with text color. More...
 
void ResetUnderlineColor ()
 Sets underline color to match with text color. More...
 
void SetColor (RGBAf value)
 Changes the color of the text. More...
 
void SetDefaultAlign (TextAlignment value)
 Sets the default alignment for the text. More...
 
void SetGlyphRenderer (GlyphRenderer &renderer)
 
void SetJustify (bool value)
 Sets whether the text would be justified. More...
 
void SetLetterSpacing (int value)
 Spacing between letters of the text, in pixels. More...
 
void SetLineSpacing (float value)
 Sets the line spacing as percentage of line gap. More...
 
void SetLineSpacingPixels (int value)
 Sets the line spacing in pixels, this spacing is the space between two lines, from the descender of the first line to the ascender of the second. More...
 
void SetParagraphSpacing (int value)
 Changes the additional space between paragraphs. More...
 
void SetShadow (TextShadow value)
 Changes text shadow. More...
 
void SetStrike (bool value)
 Sets whether the text would be stroked. More...
 
void SetStrikeColor (RGBAf value)
 Changes the strike color of the text. More...
 
void SetStrikePosition (int value)
 Changes the strike position to the given value. More...
 
void SetTabWidth (int value)
 Distance between tab stops. More...
 
void SetTabWidthInLetters (float value)
 Sets the tab width in digit widths. More...
 
void SetUnderline (bool value)
 Sets underlining for the text. More...
 
void SetUnderlineColor (RGBAf value)
 Changes the underline color of the text. More...
 
void Strike ()
 Strikes the text. More...
 
void Strike (RGBAf color)
 Strikes the text with the given color. More...
 
void Underline ()
 Underlines the text. More...
 
void Underline (RGBAf color)
 Underlines the text with the given color. More...
 
void UseFlatShadow (RGBAf color, Geometry::Pointf offset={1.f, 1.f})
 Uses flat shadow for text. More...
 
- Public Member Functions inherited from TextRenderer
virtual ~TextRenderer ()
 
void Print (TextureTarget &target, const std::string &text)
 
void Print (TextureTarget &target, const std::string &text, Geometry::Point location) const
 
void Print (TextureTarget &target, const std::string &text, Geometry::Point location, int w) const
 
void Print (TextureTarget &target, const std::string &text, Geometry::Point location, int w, TextAlignment align_override) const
 
void Print (TextureTarget &target, const std::string &text, Geometry::Pointf location) const
 Prints the given text to the target. More...
 
void Print (TextureTarget &target, const std::string &text, int x, int y) const
 
void Print (TextureTarget &target, const std::string &text, int x, int y, int w) const
 
void Print (TextureTarget &target, const std::string &text, int x, int y, int w, TextAlignment align_override) const
 
void PrintNoWrap (TextureTarget &target, const std::string &text, Geometry::Point location, int w) const
 
void PrintNoWrap (TextureTarget &target, const std::string &text, Geometry::Point location, int w, TextAlignment align_override) const
 
void PrintNoWrap (TextureTarget &target, const std::string &text, int x, int y, int w) const
 
void PrintNoWrap (TextureTarget &target, const std::string &text, int x, int y, int w, TextAlignment align_override) const
 

Protected Member Functions

virtual void print (TextureTarget &target, const std::string &text, Geometry::Point location) const override
 
virtual void print (TextureTarget &target, const std::string &text, Geometry::Rectangle location) const override
 
virtual void print (TextureTarget &target, const std::string &text, Geometry::Rectangle location, TextAlignment align_override) const override
 Should print the given text to the specified location and color. More...
 
virtual void printnowrap (TextureTarget &target, const std::string &text, Geometry::Rectangle location) const override
 Should print the given text to the specified location and color. More...
 
virtual void printnowrap (TextureTarget &target, const std::string &text, Geometry::Rectangle location, TextAlignment align) const override
 Should print the given text to the specified location and color. More...
 

Detailed Description

This text renderer can style text according to the set parameters.

It can draw shadow modify spacings and tabwidth and is capable of rendering underline. This object is not heavy, and could be copied. When setting up spacing, try to avoid non-integer values, as they would cause text to blur.

Constructor & Destructor Documentation

◆ StyledRenderer() [1/2]

StyledRenderer ( GlyphRenderer renderer,
RGBAf  color = 1.f,
TextShadow  shadow = {} 
)

Renderer must be ready in order to calculate spacings correctly.

If it will be initialized later, call ResetSpacing to reset all to defaults.

◆ StyledRenderer() [2/2]

StyledRenderer ( )
default

Member Function Documentation

◆ AlignCenter()

void AlignCenter ( )

Aligns the text to the center, removes justify.

References Gorgon::Graphics::Center.

◆ AlignLeft()

void AlignLeft ( )

Aligns the text to the left, removes justify.

References Gorgon::Graphics::Left.

◆ AlignRight()

void AlignRight ( )

Aligns the text to the right, removes justify.

References Gorgon::Graphics::Right.

◆ DisableShadow()

void DisableShadow ( )

Disables text shadow.

References TextShadow::None.

◆ GetBaseLine()

virtual float GetBaseLine ( ) const
overridevirtual

Get the distance of baseline from the top of the text.

Implements TextRenderer.

References GlyphRenderer::GetBaseLine().

◆ GetCharacterIndex() [1/2]

int GetCharacterIndex ( const std::string &  text,
Geometry::Point  location 
) const
overridevirtual

Returns the character index of glyph immediately after the given location. This function is Unicode aware.

Implements TextRenderer.

References GlyphRenderer::NeedsPrepare(), GlyphRenderer::Prepare(), and Gorgon::Graphics::internal::simplelayout().

◆ GetCharacterIndex() [2/2]

int GetCharacterIndex ( const std::string &  text,
int  w,
Geometry::Point  location,
bool  wrap = true 
) const
overridevirtual

Returns the character index of glyph immediately after the given location. This function is Unicode aware.

Implements TextRenderer.

References Gorgon::begin(), Gorgon::Graphics::internal::boundedlayout(), Gorgon::end(), GlyphRenderer::NeedsPrepare(), GlyphRenderer::Prepare(), Gorgon::Input::Keyboard::Keycodes::Right, and basic_Point< T_ >::X.

◆ GetColor()

RGBAf GetColor ( ) const

Returns color of the text.

◆ GetDefaultAlign()

TextAlignment GetDefaultAlign ( ) const

Returns the default alignment for the text.

◆ GetEMSize()

virtual int GetEMSize ( ) const
overridevirtual

Returns the size of the EM dash.

Implements TextRenderer.

References GlyphRenderer::GetEMSize().

◆ GetGlyphRenderer() [1/2]

GlyphRenderer& GetGlyphRenderer ( )

◆ GetGlyphRenderer() [2/2]

virtual const GlyphRenderer& GetGlyphRenderer ( ) const
overridevirtual

Returns the glyphrenderer that is used by this text renderer.

It might be the text renderer itself. It is only safe to call this function if IsReady function has returned true.

Implements TextRenderer.

◆ GetHeight()

virtual int GetHeight ( ) const
overridevirtual

Get the distance of baseline from the top of the text.

Implements TextRenderer.

References GlyphRenderer::GetHeight().

◆ GetJustify()

bool GetJustify ( ) const

Returns whether the text would be justified.

◆ GetLetterSpacing()

int GetLetterSpacing ( ) const

Returns the spacing between the letters in pixels.

◆ GetLineSpacing()

float GetLineSpacing ( ) const

Returns the line spacing as percentage of line gap.

◆ GetLineSpacingPixels()

int GetLineSpacingPixels ( ) const

Returns the line spacing in pixels.

References GlyphRenderer::GetHeight().

◆ GetParagraphSpacing()

int GetParagraphSpacing ( ) const

Get the space between paragraphs in pixels.

◆ GetPosition() [1/2]

Geometry::Rectangle GetPosition ( const std::string &  text,
int  index 
) const
overridevirtual

Returns the position of the glyph at the character index.

If the character is not found, this will return std::numeric_limit<int>::min for x and y position. Size could be 0 if it cannot be determined.

Implements TextRenderer.

References GlyphRenderer::NeedsPrepare(), GlyphRenderer::Prepare(), and Gorgon::Graphics::internal::simplelayout().

◆ GetPosition() [2/2]

Geometry::Rectangle GetPosition ( const std::string &  text,
int  w,
int  index,
bool  wrap = true 
) const
overridevirtual

Returns the position of the glyph at the character index.

If the character is not found, this will return std::numeric_limit<int>::min for x and y position. Size could be 0 if it cannot be determined.

Implements TextRenderer.

References Gorgon::begin(), Gorgon::Graphics::internal::boundedlayout(), Gorgon::end(), GlyphRenderer::NeedsPrepare(), GlyphRenderer::Prepare(), and Gorgon::Input::Keyboard::Keycodes::Right.

◆ GetShadow()

TextShadow GetShadow ( ) const

Returns text shadow.

◆ GetSize() [1/2]

Geometry::Size GetSize ( const std::string &  text) const
overridevirtual

◆ GetSize() [2/2]

Geometry::Size GetSize ( const std::string &  text,
int  width 
) const
overridevirtual

◆ GetStrike()

bool GetStrike ( ) const

Returns whether the text would stroked.

◆ GetStrikeColor()

RGBAf GetStrikeColor ( ) const

Returns the current strike color.

References RGBAf::R.

◆ GetStrikePosition()

int GetStrikePosition ( ) const

Returns current strike position.

References GlyphRenderer::GetHeight(), and GlyphRenderer::GetLineThickness().

◆ GetTabWidth()

int GetTabWidth ( ) const

Returns tab width in pixels.

◆ GetUnderline()

bool GetUnderline ( ) const

Returns whether the text is underlined.

◆ GetUnderlineColor()

RGBAf GetUnderlineColor ( ) const

Returns the current underline color.

References RGBAf::R.

◆ IsReady()

virtual bool IsReady ( ) const
overridevirtual

Whether the render can render text.

Implements TextRenderer.

◆ JustifyCenter()

void JustifyCenter ( )

Aligns the text to the center, sets justify.

References Gorgon::Graphics::Center.

◆ JustifyLeft()

void JustifyLeft ( )

Aligns the text to the left, sets justify.

References Gorgon::Graphics::Left.

◆ JustifyRight()

void JustifyRight ( )

Aligns the text to the right, sets justify.

References Gorgon::Graphics::Right.

◆ print() [1/3]

void print ( TextureTarget target,
const std::string &  text,
Geometry::Point  location 
) const
overrideprotectedvirtual

Implements TextRenderer.

◆ print() [2/3]

virtual void print ( TextureTarget target,
const std::string &  text,
Geometry::Rectangle  location 
) const
overrideprotectedvirtual

Implements TextRenderer.

References StyledRenderer::print().

◆ print() [3/3]

void print ( TextureTarget target,
const std::string &  text,
Geometry::Rectangle  location,
TextAlignment  align_override 
) const
overrideprotectedvirtual

Should print the given text to the specified location and color.

Width should be used to align the text. Unless width is 0, text should be wrapped. Even if width is 0, the alignment should be respected. For instance if width is 0 and align is right, text should end at the given location. Height of the rectangle can be left 0, thus unless explicitly requested, it should be ignored.

Implements TextRenderer.

◆ printnowrap() [1/2]

virtual void printnowrap ( TextureTarget target,
const std::string &  text,
Geometry::Rectangle  location 
) const
overrideprotectedvirtual

Should print the given text to the specified location and color.

Width should be used to align the text. Automatic wrapping should not be used.

Implements TextRenderer.

References StyledRenderer::printnowrap().

◆ printnowrap() [2/2]

void printnowrap ( TextureTarget target,
const std::string &  text,
Geometry::Rectangle  location,
TextAlignment  align_override 
) const
overrideprotectedvirtual

Should print the given text to the specified location and color.

Width should be used to align the text. Automatic wrapping should not be used.

Implements TextRenderer.

References basic_Rectangle< T_ >::Height, Gorgon::Input::Keyboard::Keycodes::Left, Gorgon::Input::Keyboard::Keycodes::Right, basic_Rectangle< T_ >::TopLeft(), basic_Rectangle< T_ >::Width, basic_Rectangle< T_ >::X, and basic_Rectangle< T_ >::Y.

◆ ResetStrikeColor()

void ResetStrikeColor ( )

Sets strike color to match with text color.

◆ ResetUnderlineColor()

void ResetUnderlineColor ( )

Sets underline color to match with text color.

◆ SetColor()

void SetColor ( RGBAf  value)

Changes the color of the text.

◆ SetDefaultAlign()

void SetDefaultAlign ( TextAlignment  value)

Sets the default alignment for the text.

◆ SetGlyphRenderer()

void SetGlyphRenderer ( GlyphRenderer renderer)

◆ SetJustify()

void SetJustify ( bool  value)

Sets whether the text would be justified.

Justify will not affect single line text as well last line of a paragraph.

◆ SetLetterSpacing()

void SetLetterSpacing ( int  value)

Spacing between letters of the text, in pixels.

This is in addition to the regular character spacing.

◆ SetLineSpacing()

void SetLineSpacing ( float  value)

Sets the line spacing as percentage of line gap.

A value of one will use the default state by the font, where as a value of two will leave a large gap between two lines. This will round the final result to the nearest pixel.

◆ SetLineSpacingPixels()

void SetLineSpacingPixels ( int  value)

Sets the line spacing in pixels, this spacing is the space between two lines, from the descender of the first line to the ascender of the second.

References GlyphRenderer::GetHeight().

◆ SetParagraphSpacing()

void SetParagraphSpacing ( int  value)

Changes the additional space between paragraphs.

A paragraph is stared by a manual line break. This distance is in pixels.

◆ SetShadow()

void SetShadow ( TextShadow  value)

Changes text shadow.

◆ SetStrike()

void SetStrike ( bool  value)

Sets whether the text would be stroked.

◆ SetStrikeColor()

void SetStrikeColor ( RGBAf  value)

Changes the strike color of the text.

By default strike color will be the same as text color. To get default value, use ResetStrikeColor function

◆ SetStrikePosition()

void SetStrikePosition ( int  value)

Changes the strike position to the given value.

Default value for strike position is automatically calculated, use ResetStrikePosition to get back to the default

◆ SetTabWidth()

void SetTabWidth ( int  value)

Distance between tab stops.

This value is in pixels. Default value is 8 * A width. Tabbing is only fully effective when text is left aligned.

◆ SetTabWidthInLetters()

void SetTabWidthInLetters ( float  value)

Sets the tab width in digit widths.

References GlyphRenderer::GetCursorAdvance().

◆ SetUnderline()

void SetUnderline ( bool  value)

Sets underlining for the text.

◆ SetUnderlineColor()

void SetUnderlineColor ( RGBAf  value)

Changes the underline color of the text.

By default underline color will be the same as text color. To get default value, use ResetUnderlineColor function

◆ Strike() [1/2]

void Strike ( )

Strikes the text.

◆ Strike() [2/2]

void Strike ( RGBAf  color)

Strikes the text with the given color.

◆ Underline() [1/2]

void Underline ( )

Underlines the text.

◆ Underline() [2/2]

void Underline ( RGBAf  color)

Underlines the text with the given color.

◆ UseFlatShadow()

void UseFlatShadow ( RGBAf  color,
Geometry::Pointf  offset = {1.f, 1.f} 
)

Uses flat shadow for text.


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