SDL3pp
A slim C++ wrapper for SDL3
|
Text created with TextBase.TextBase() More...
Public Member Functions | |
void | DrawSurface (Point p, SurfaceRef surface) const |
Draw text to an SDL surface. | |
void | DrawRenderer (FPoint p) const |
Draw text to an SDL renderer. | |
GPUAtlasDrawSequence * | GetGPUDrawData () const |
Get the geometry data needed for drawing the text. | |
TextBase (TextEngineBase &engine, FontRef font, std::string_view text) | |
Create a text object from UTF-8 text and a text engine. | |
PropertiesRef | GetProperties () const |
Get the properties associated with a text object. | |
void | SetEngine (TextEngineBase &engine) |
Set the text engine used by a text object. | |
TextEngineRef | GetEngine () const |
Get the text engine used by a text object. | |
bool | SetFont (FontBase &font) |
Set the font used by a text object. | |
FontRef | GetFont () const |
Get the font used by a text object. | |
void | SetDirection (Direction direction) |
Set the direction to be used for text shaping a text object. | |
Direction | GetDirection () const |
Get the direction to be used for text shaping a text object. | |
void | SetScript (Uint32 script) |
Set the script to be used for text shaping a text object. | |
Uint32 | GetScript () const |
Get the script used for text shaping a text object. | |
void | SetColor (Color c) |
Set the color of a text object. | |
void | SetColor (FColor c) |
Set the color of a text object. | |
FColor | GetColor () const |
Get the color of a text object. | |
void | GetColor (Color *c) const |
Get the color of a text object. | |
void | GetColor (FColor *c) const |
Get the color of a text object. | |
void | GetColor (Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) const |
Get the color of a text object. | |
void | GetColor (float *r, float *g, float *b, float *a) const |
Get the color of a text object. | |
bool | SetPosition (Point p) |
Set the position of a text object. | |
Point | GetPosition () const |
Get the position of a text object. | |
bool | GetPosition (int *x, int *y) const |
Get the position of a text object. | |
void | SetWrapWidth (int wrap_width) |
Set whether wrapping is enabled on a text object. | |
int | GetWrapWidth () const |
Get whether wrapping is enabled on a text object. | |
void | SetWrapWhitespaceVisible (bool visible) |
Set whether whitespace should be visible when wrapping a text object. | |
bool | IsWrapWhitespaceVisible () const |
Return whether whitespace is shown when wrapping a text object. | |
void | SetString (std::string_view string) |
Set the UTF-8 text used by a text object. | |
void | InsertString (int offset, std::string_view string) |
Insert UTF-8 text into a text object. | |
void | AppendString (std::string_view string) |
Append UTF-8 text to a text object. | |
void | DeleteString (int offset, int length=-1) |
Delete UTF-8 text from a text object. | |
Point | GetSize () const |
Get the size of a text object. | |
void | GetSize (int *w, int *h) const |
Get the size of a text object. | |
void | GetSubString (int offset, SubString *substring) const |
Get the substring of a text object that surrounds a text offset. | |
SubStringIterator | begin () const |
Get iterator to first substring. | |
SubStringIterator | end () const |
Get iterator to one past last substring. | |
SubStringIterator | GetSubStringForLine (int line) const |
Get iterator to substring of a text object that contains the given line. | |
void | GetSubStringForLine (int line, SubString *substring) const |
Get the substring of a text object that contains the given line. | |
OwnArray< SubString * > | GetSubStrings () const |
Get all substrings of a text object. | |
OwnArray< SubString * > | GetSubStringsForRange (int offset, int length=-1) const |
Get the substrings of a text object that contain a range of text. | |
SubStringIterator | GetSubStringForPoint (Point p) const |
Get the portion of a text string that is closest to a point. | |
void | GetSubStringForPoint (Point p, SubString *substring) const |
Get the portion of a text string that is closest to a point. | |
void | GetPreviousSubString (const SubString &substring, SubString *previous) const |
Get the previous substring in a text object. | |
void | GetNextSubString (const SubString &substring, SubString *next) const |
Get the next substring in a text object. | |
void | Update () |
Update the layout of a text object. | |
const char * | GetText () const |
A copy of the UTF-8 string that this text object represents, useful for layout, debugging and retrieving substring text. | |
int | GetNumLines () const |
The number of lines in the text, 0 if it's empty. | |
constexpr | Resource (T resource={}) |
Constructs the underlying resource. | |
constexpr | Resource (std::nullptr_t) |
Equivalent to default ctor. | |
constexpr | Resource (std::nullopt_t) |
Equivalent to default ctor. | |
Resource (const Resource &other)=delete | |
Resource (Resource &&other)=delete | |
![]() | |
constexpr | Resource (TTF_Text * resource={}) |
Constructs the underlying resource. | |
constexpr | Resource (std::nullptr_t) |
Equivalent to default ctor. | |
constexpr | Resource (std::nullopt_t) |
Equivalent to default ctor. | |
Resource (const Resource &other)=delete | |
Resource (Resource &&other)=delete | |
Resource & | operator= (const Resource &other)=delete |
Resource & | operator= (Resource &&other)=delete |
constexpr | operator bool () const |
True if contains a valid resource. | |
constexpr bool | operator== (const Resource &other) const=default |
Comparison. | |
constexpr bool | operator== (std::nullopt_t) const |
Comparison. | |
constexpr bool | operator== (std::nullptr_t) const |
Comparison. | |
constexpr TTF_Text * | get () const |
Return contained resource;. | |
constexpr TTF_Text * | release (TTF_Text * newResource={}) |
Return contained resource and empties or replace value. | |
constexpr const TTF_Text * | operator-> () const |
Access to fields. | |
constexpr TTF_Text * | operator-> () |
Access to fields. | |
|
inline |
engine | the text engine to use when creating the text object, may be nullptr. |
font | the font to render with. |
text | the text to use, in UTF-8 encoding. |
|
inline |
This function may cause the internal text representation to be rebuilt.
string | the UTF-8 text to insert. |
Error | on failure. |
|
inline |
This function may cause the internal text representation to be rebuilt.
offset | the offset, in bytes, from the beginning of the string if >= 0, the offset from the end of the string if < 0. Note that this does not do UTF-8 validation, so you should only delete at UTF-8 sequence boundaries. |
length | the length of text to delete, in bytes, or -1 for the remainder of the string. |
Error | on failure. |
|
inline |
text
must have been created using a TextEngineBase from CreateRendererTextEngine(), and will draw using the renderer passed to that function.
p | the (x, y) coordinate in pixels, positive from the left edge towards the right and from the top edge towards the bottom. |
Error | on failure. |
|
inline |
text
must have been created using a TextEngineBase from CreateSurfaceTextEngine().
p | the (x, y) coordinate in pixels, positive from the left edge towards the right and from the top edge towards the bottom. |
surface | the surface to draw on. |
Error | on failure. |
|
inline |
Error | on failure. |
|
inline |
c | a pointer filled in with red color value in the range of 0-255, must not be nullptr. |
Error | on failure. |
|
inline |
c | a pointer filled in with red color value in the range of 0-1, must not be nullptr. |
Error | on failure. |
|
inline |
r | a pointer filled in with the red color value, normally in the range of 0-1, may be nullptr. |
g | a pointer filled in with the green color value, normally in the range of 0-1, may be nullptr. |
b | a pointer filled in with the blue color value, normally in the range of 0-1, may be nullptr. |
a | a pointer filled in with the alpha value in the range of 0-1, may be nullptr. |
Error | on failure. |
|
inline |
r | a pointer filled in with the red color value in the range of 0-255, may be nullptr. |
g | a pointer filled in with the green color value in the range of 0-255, may be nullptr. |
b | a pointer filled in with the blue color value in the range of 0-255, may be nullptr. |
a | a pointer filled in with the alpha value in the range of 0-255, may be nullptr. |
Error | on failure. |
|
inline |
This defaults to the direction of the font used by the text object.
|
inline |
Error | on failure. |
|
inline |
Error | on failure. |
|
inline |
text
must have been created using a TextEngineBase from CreateGPUTextEngine().
The positive X-axis is taken towards the right and the positive Y-axis is taken upwards for both the vertex and the texture coordinates, i.e, it follows the same convention used by the SDL_GPU API. If you want to use a different coordinate system you will need to transform the vertices yourself.
If the text looks blocky use linear filtering.
If called at the end of the text, this will return a zero length substring with the SUBSTRING_TEXT_END flag set.
substring | the SubString to query. |
next | a pointer filled in with the next substring. |
Error | on failure. |
|
inline |
Error | on failure. |
|
inline |
x | a pointer filled in with the x offset of the upper left corner of this text in pixels, may be nullptr. |
y | a pointer filled in with the y offset of the upper left corner of this text in pixels, may be nullptr. |
|
inline |
If called at the start of the text, this will return a zero length substring with the SUBSTRING_TEXT_START flag set.
substring | the SubString to query. |
previous | a pointer filled in with the previous substring. |
Error | on failure. |
|
inline |
Error | on failure. |
|
inline |
This defaults to the script of the font used by the text object.
|
inline |
The size of the text may change when the font or font style and size change.
|
inline |
The size of the text may change when the font or font style and size change.
w | a pointer filled in with the width of the text, in pixels, may be nullptr. |
h | a pointer filled in with the height of the text, in pixels, may be nullptr. |
Error | on failure. |
|
inline |
If offset
is less than 0, this will return a zero length substring at the beginning of the text with the SUBSTRING_TEXT_START flag set. If offset
is greater than or equal to the length of the text string, this will return a zero length substring at the end of the text with the SUBSTRING_TEXT_END flag set.
offset | a byte offset into the text string. |
substring | a pointer filled in with the substring containing the offset. |
Error | on failure. |
|
inline |
If line
is greater than or equal to text->num_lines
this will return an iterator equal to end().
line | a zero-based line index, in the range [0 .. text->num_lines-1]. |
|
inline |
If line
is less than 0, this will return a zero length substring at the beginning of the text with the SUBSTRING_TEXT_START flag set. If line
is greater than or equal to text->num_lines
this will return a zero length substring at the end of the text with the SUBSTRING_TEXT_END flag set.
line | a zero-based line index, in the range [0 .. text->num_lines-1]. |
substring | a pointer filled in with the substring containing the offset. |
Error | on failure. |
|
inline |
This will return the closest substring of text to the given point.
p | the coordinates relative to the top-left side of the text, may be outside the bounds of the text area. |
This will return the closest substring of text to the given point.
p | the coordinates relative to the top-left side of the text, may be outside the bounds of the text area. |
substring | a pointer filled in with the closest substring of text to the given point. |
Error | on failure. |
|
inline |
offset | a byte offset into the text string. |
length | the length of the range being queried, in bytes, or -1 for the remainder of the string. |
|
inline |
Error | on failure. |
|
inline |
This function may cause the internal text representation to be rebuilt.
offset | the offset, in bytes, from the beginning of the string if >= 0, the offset from the end of the string if < 0. Note that this does not do UTF-8 validation, so you should only insert at UTF-8 sequence boundaries. |
string | the UTF-8 text to insert. |
Error | on failure. |
|
inline |
|
inline |
The default text color is white (255, 255, 255, 255).
c | the color values in the range of 0-255. |
Error | on failure. |
|
inline |
The default text color is white (1.0f, 1.0f, 1.0f, 1.0f).
c | the color value, normally in the range of 0-1. |
Error | on failure. |
|
inline |
This function only supports left-to-right text shaping if SDL_ttf was not built with HarfBuzz support.
direction | the new direction for text to flow. |
Error | on failure. |
|
inline |
This function may cause the internal text representation to be rebuilt.
engine | the text engine to use for drawing. |
Error | on failure. |
|
inline |
When a text object has a font, any changes to the font will automatically regenerate the text. If you set the font to nullptr, the text will continue to render but changes to the font will no longer affect the text.
This function may cause the internal text representation to be rebuilt.
font | the font to use, may be nullptr. |
|
inline |
This can be used to position multiple text objects within a single wrapping text area.
This function may cause the internal text representation to be rebuilt.
p | the x, y offset of the upper left corner of this text in pixels. |
|
inline |
This returns false if SDL_ttf isn't built with HarfBuzz support.
script | an ISO 15924 code. |
Error | on failure. |
|
inline |
This function may cause the internal text representation to be rebuilt.
string | the UTF-8 text to use. |
Error | on failure. |
|
inline |
If the whitespace is visible, it will take up space for purposes of alignment and wrapping. This is good for editing, but looks better when centered or aligned if whitespace around line wrapping is hidden. This defaults false.
This function may cause the internal text representation to be rebuilt.
visible | true to show whitespace when wrapping text, false to hide it. |
Error | on failure. |
|
inline |
This function may cause the internal text representation to be rebuilt.
wrap_width | the maximum width in pixels, 0 to wrap on newline characters. |
Error | on failure. |
|
inline |
This is automatically done when the layout is requested or the text is rendered, but you can call this if you need more control over the timing of when the layout and text engine representation are updated.
Error | on failure. |