ASGE
3.2.0
Simple Game Framework in GL
|
#include <Text.hpp>
Public Member Functions | |
Text (const Text &)=delete | |
Text & | operator= (const Text &)=delete |
Text (Text &&) noexcept | |
Text & | operator= (Text &&other) noexcept |
Text (const ASGE::Font &font_face) | |
Text (const ASGE::Font &font_face, std::string text) | |
Text (const ASGE::Font &font_face, const std::string &text, int x, int y) | |
Text (const ASGE::Font &font_face, std::string &&text, int x, int y) | |
Text (const ASGE::Font &font_face, const std::string &text, int x, int y, const ASGE::Colour &colour) | |
Text (const ASGE::Font &font_face, std::string &&text, int x, int y, const ASGE::Colour &colour) | |
bool | validFont () const noexcept |
int16_t | getZOrder () const noexcept |
int | getLineSpacing () const |
float | getHeight () const noexcept |
float | getOpacity () const noexcept |
float | getScale () const noexcept |
float | getWidth () const noexcept |
const Point2D & | getPosition () const noexcept |
const Colour & | getColour () const noexcept |
const std::string & | getString () const noexcept |
const Font & | getFont () const noexcept |
TextBounds | getWorldBounds () const |
TextBounds | getLocalBounds () const |
Text & | setZOrder (int16_t z_order) noexcept |
Text & | setScale (float scale) noexcept |
Text & | setOpacity (float opacity) noexcept |
Text & | setPositionX (float baseline_x) noexcept |
Text & | setPositionY (float baseline_y) noexcept |
Text & | setPosition (const Point2D &baseline) noexcept |
Text & | setPosition (Point2D &&baseline) noexcept |
Text & | setColour (const ASGE::Colour &colour) noexcept |
Text & | setString (const std::string &string) noexcept |
Text & | setString (std::string &&string) noexcept |
Text & | setFont (const Font &font_face) noexcept |
Text is designed to allow rendering of text to the screen.
Rendering text to a screen is not a simple process. There are lots of parameters involved, which can result in many different overloaded render functions. To resolve this, the ASGE::Text was created. All the information needed to successfully render text to the screen is stored within the struct. This includes positioning, colours, scaling, the text and even the font face to use.
Advantages of using this class allow a single instance to be constructed and used repeatedly as well as the ability to add additional features to the Text class without having to modify the renderer API.
Positioning
There are always a lot of questions around positioning of text on the screen. The issue comes from the x and y actually controlling the position of the baseline. The baseline is the point at which all characters should lay along and allows consistent positioning of text irrespective of the strings context.
Usage
|
explicit |
Constructor that takes a loaded font face
[in] | font_face | The font face to use for rendering. |
ASGE::Text::Text | ( | const ASGE::Font & | font_face, |
std::string | text | ||
) |
Constructs a simple text object capable of rendering a string.
[in] | font_face | The font face to use. |
[in] | text | The text to render or perform calculations on. |
ASGE::Text::Text | ( | const ASGE::Font & | font_face, |
const std::string & | text, | ||
int | x, | ||
int | y | ||
) |
Constructs a simple text object and positions it.
[in] | font_face | The font face to use. |
[in] | text | The text to render or perform calculations on. |
[in] | x | The x starting position of the baseline. |
[in] | y | The y position of the baseline. |
ASGE::Text::Text | ( | const ASGE::Font & | font_face, |
std::string && | text, | ||
int | x, | ||
int | y | ||
) |
Constructs a simple text object and positions it.
[in] | font_face | The font face to use. |
[in] | text | A temporary text object to store as the font's contents. |
[in] | x | The x starting position of the baseline. |
[in] | y | The y position of the baseline. |
ASGE::Text::Text | ( | const ASGE::Font & | font_face, |
const std::string & | text, | ||
int | x, | ||
int | y, | ||
const ASGE::Colour & | colour | ||
) |
Constructs a simple text object, set's it's colour and positions it.
[in] | font_face | The font face to use. |
[in] | text | The text to render or perform calculations on. |
[in] | x | The x starting position of the baseline. |
[in] | y | The y position of the baseline. |
[in] | colour | The colour to render the text. |
ASGE::Text::Text | ( | const ASGE::Font & | font_face, |
std::string && | text, | ||
int | x, | ||
int | y, | ||
const ASGE::Colour & | colour | ||
) |
Constructs a simple text object and positions it.
[in] | font_face | The font face to use. |
[in] | text | A temporary text object to store as the font's contents. |
[in] | x | The x starting position of the baseline. |
[in] | y | The y position of the baseline. |
[in] | colour | The colour to render the text. |
|
noexcept |
Retrieves the colour of the font.
|
noexcept |
Retrieves the font face currently assigned to the text object.
|
noexcept |
Calculates the max height of the stored text.
This is obviously font face dependent and also dependent on the scale factor applied to the font object. This can be used to calculate an offset in the Y when positioning the text on the screen.
int ASGE::Text::getLineSpacing | ( | ) | const |
Attempts to calculate the spacing between lines.
TextBounds ASGE::Text::getLocalBounds | ( | ) | const |
Returns the bounds of the rendered text in local space.
Whilst this does not provide the absolute positioning of the text in the game world, it does allow an easy way to calculate the bounding box dimensions of the rendered text i.e. how wide and tall it is.
|
noexcept |
The opacity of the font.
|
noexcept |
The position of the text's baseline.
|
noexcept |
The scale to apply to the text.
|
noexcept |
Retrieves the string to be rendered.
|
noexcept |
Calculates the width of the rendered string.
This is obviously font face dependent and also dependent on the scale factor applied to the font object. This can be used to calculate an offset in the x when positioning the text on the screen.
TextBounds ASGE::Text::getWorldBounds | ( | ) | const |
Returns the bounds of the rendered text in world space.
Calculates the width and height of the text in local space and then positions it within a bounding box that retains it's position in world space.
|
noexcept |
The z-order to control rendering.
Like any other renderable object, the z-order can be use to manipulate the rendering order. Text with lower values will be hidden by sprites with higher values.
|
noexcept |
Sets the colour to render the text in.
[in] | colour | The colour to render the text. |
Replaces the font face.
[in] | font_face | The font face to use for this text object. |
|
noexcept |
Sets the opacity of the rendered output (alpha channel).
[in] | opacity | The alpha channel level. |
Updates the baseline position used to control the text's location
[in] | baseline | The starting position for the text. |
Updates the baseline position used to control the text's location
[in] | baseline | The starting position for the text. |
|
noexcept |
Updates the baseline x starting position.
[in] | baseline_x | The starting position of the baseline on the X axis. |
|
noexcept |
Updates the baseline y starting position.
[in] | baseline_yThe | starting position of the baseline on the Y axis. |
|
noexcept |
Sets the scale factor of the rendered output.
[in] | scale | The scaling to apply. |
|
noexcept |
Replaces the text to be rendered using this object.
[in] | string | The replacement text. |
|
noexcept |
Replaces the text to be rendered using this object.
[in] | string | The replacement text. |
|
noexcept |
Sets the Z order of the rendered output.
[in] | z_order | The new z-order to apply. |
|
noexcept |
Checks to see if a valid font has been assigned.