![]() |
Gorgon Game Engine
|
This text renderer can style text according to the set parameters. More...
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... | |
GlyphRenderer & | GetGlyphRenderer () |
virtual const GlyphRenderer & | GetGlyphRenderer () 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... | |
![]() | |
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... | |
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.
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.
|
default |
void AlignCenter | ( | ) |
Aligns the text to the center, removes justify.
References Gorgon::Graphics::Center.
void AlignLeft | ( | ) |
Aligns the text to the left, removes justify.
References Gorgon::Graphics::Left.
void AlignRight | ( | ) |
Aligns the text to the right, removes justify.
References Gorgon::Graphics::Right.
void DisableShadow | ( | ) |
Disables text shadow.
References TextShadow::None.
|
overridevirtual |
Get the distance of baseline from the top of the text.
Implements TextRenderer.
References GlyphRenderer::GetBaseLine().
|
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().
|
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.
RGBAf GetColor | ( | ) | const |
Returns color of the text.
TextAlignment GetDefaultAlign | ( | ) | const |
Returns the default alignment for the text.
|
overridevirtual |
GlyphRenderer& GetGlyphRenderer | ( | ) |
|
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.
|
overridevirtual |
Get the distance of baseline from the top of the text.
Implements TextRenderer.
References GlyphRenderer::GetHeight().
bool GetJustify | ( | ) | const |
Returns whether the text would be justified.
int GetLetterSpacing | ( | ) | const |
Returns the spacing between the letters in pixels.
float GetLineSpacing | ( | ) | const |
Returns the line spacing as percentage of line gap.
int GetLineSpacingPixels | ( | ) | const |
Returns the line spacing in pixels.
References GlyphRenderer::GetHeight().
int GetParagraphSpacing | ( | ) | const |
Get the space between paragraphs in pixels.
|
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().
|
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.
TextShadow GetShadow | ( | ) | const |
Returns text shadow.
|
overridevirtual |
Returns the size of the given text.
Implements TextRenderer.
References GlyphRenderer::GetLineGap(), GlyphRenderer::NeedsPrepare(), GlyphRenderer::Prepare(), and Gorgon::Graphics::internal::simpleprint().
|
overridevirtual |
Returns the size of the given text.
Implements TextRenderer.
References Gorgon::begin(), Gorgon::Graphics::internal::boundedprint(), Gorgon::end(), GlyphRenderer::NeedsPrepare(), and GlyphRenderer::Prepare().
bool GetStrike | ( | ) | const |
Returns whether the text would stroked.
int GetStrikePosition | ( | ) | const |
Returns current strike position.
References GlyphRenderer::GetHeight(), and GlyphRenderer::GetLineThickness().
int GetTabWidth | ( | ) | const |
Returns tab width in pixels.
bool GetUnderline | ( | ) | const |
Returns whether the text is underlined.
|
overridevirtual |
Whether the render can render text.
Implements TextRenderer.
void JustifyCenter | ( | ) |
Aligns the text to the center, sets justify.
References Gorgon::Graphics::Center.
void JustifyLeft | ( | ) |
Aligns the text to the left, sets justify.
References Gorgon::Graphics::Left.
void JustifyRight | ( | ) |
Aligns the text to the right, sets justify.
References Gorgon::Graphics::Right.
|
overrideprotectedvirtual |
Implements TextRenderer.
|
overrideprotectedvirtual |
Implements TextRenderer.
References StyledRenderer::print().
|
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.
|
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().
|
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.
void ResetStrikeColor | ( | ) |
Sets strike color to match with text color.
void ResetUnderlineColor | ( | ) |
Sets underline color to match with text color.
void SetColor | ( | RGBAf | value | ) |
Changes the color of the text.
void SetDefaultAlign | ( | TextAlignment | value | ) |
Sets the default alignment for the text.
void SetGlyphRenderer | ( | GlyphRenderer & | renderer | ) |
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.
void SetLetterSpacing | ( | int | value | ) |
Spacing between letters of the text, in pixels.
This is in addition to the regular character spacing.
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.
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().
void SetParagraphSpacing | ( | int | value | ) |
Changes the additional space between paragraphs.
A paragraph is stared by a manual line break. This distance is in pixels.
void SetShadow | ( | TextShadow | value | ) |
Changes text shadow.
void SetStrike | ( | bool | value | ) |
Sets whether the text would be stroked.
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
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
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.
void SetTabWidthInLetters | ( | float | value | ) |
Sets the tab width in digit widths.
References GlyphRenderer::GetCursorAdvance().
void SetUnderline | ( | bool | value | ) |
Sets underlining for the text.
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
void Strike | ( | ) |
Strikes the text.
void Strike | ( | RGBAf | color | ) |
Strikes the text with the given color.
void Underline | ( | ) |
Underlines the text.
void Underline | ( | RGBAf | color | ) |
Underlines the text with the given color.
void UseFlatShadow | ( | RGBAf | color, |
Geometry::Pointf | offset = {1.f, 1.f} |
||
) |
Uses flat shadow for text.