|
ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
|
Text rendered with TrueType fonts. More...
#include <SDL3/SDL_gpu.h>#include <ObjectivelyMVC/Font.h>#include <ObjectivelyMVC/ImageAtlas.h>#include <ObjectivelyMVC/View.h>Go to the source code of this file.
Data Structures | |
| struct | Text |
| Text rendered with TrueType fonts. More... | |
| struct | TextRun |
One quad of a rendered TrueType Text: a region of its texture, in texels, drawn in color, or, when icon is set, that icon drawn as a square of the line height within it. More... | |
| struct | TextSpan |
One span of a laid-out string, in bytes of the layout string MVC_LayoutText returns: either the characters drawn in color, or a placeholder standing in for icon. More... | |
Enumerations | |
| enum | TextTransform { TextTransformNone , TextTransformUppercase , TextTransformLowercase , TextTransformCapitalize } |
| Case transforms a Text applies when drawing, leaving Text::text as set. More... | |
Functions | |
| OBJECTIVELYMVC_EXPORT Class * | _Text (void) |
| OBJECTIVELYMVC_EXPORT bool | MVC_HasColorEscapes (const char *text) |
| OBJECTIVELYMVC_EXPORT size_t | MVC_IconEscapeLength (const char *chars, const ImageAtlas *icons, AtlasImage **image) |
Parses an icon escape at the start of chars: :name:, where name is one or more of [A-Za-z0-9_-] and under 64 bytes, and is registered in icons. An unregistered name is not an escape, so 12:30:45 stays literal unless someone registers an icon called 30. | |
| OBJECTIVELYMVC_EXPORT char * | MVC_LayoutText (const Font *font, const char *text, SDL_Color color, const ImageAtlas *icons, TextSpan **spans, size_t *count) |
Resolves the escapes in text into the string to lay out and the spans to draw it as. | |
| OBJECTIVELYMVC_EXPORT char * | MVC_StripColorEscapes (const char *text) |
Strips color escape sequences from the given text: ^0 through ^9 are removed, and ^^ collapses to ^. | |
Variables | |
| OBJECTIVELYMVC_EXPORT SDL_Color | TextEscapeColors [10] |
Color palette for text escape sequences (^0 through ^9). | |
| OBJECTIVELYMVC_EXPORT const EnumName | TextTransformNames [] |
| enum TextTransform |
Case transforms a Text applies when drawing, leaving Text::text as set.
ASCII letters only; multi-byte UTF-8 sequences and color escapes pass through unchanged. Resolved :icon: escapes also pass through unchanged, so icon names keep their case.
| Enumerator | |
|---|---|
| TextTransformNone | |
| TextTransformUppercase | |
| TextTransformLowercase | |
| TextTransformCapitalize | |
Definition at line 67 of file Text.h.
| OBJECTIVELYMVC_EXPORT Class * _Text | ( | void | ) |
Definition at line 988 of file Text.c.
| OBJECTIVELYMVC_EXPORT bool MVC_HasColorEscapes | ( | const char * | text | ) |
| text | The text, or NULL. |
text contains a color escape (^0 through ^9, or ^^). Definition at line 65 of file Text.c.
| OBJECTIVELYMVC_EXPORT size_t MVC_IconEscapeLength | ( | const char * | chars, |
| const ImageAtlas * | icons, | ||
| AtlasImage ** | image | ||
| ) |
Parses an icon escape at the start of chars: :name:, where name is one or more of [A-Za-z0-9_-] and under 64 bytes, and is registered in icons. An unregistered name is not an escape, so 12:30:45 stays literal unless someone registers an icon called 30.
| chars | The text, positioned at a candidate :. |
| icons | The icon ImageAtlas, or NULL for none. |
| image | If not NULL, receives the icon, or NULL. |
0 if chars does not start with one. Definition at line 104 of file Text.c.
| OBJECTIVELYMVC_EXPORT char * MVC_LayoutText | ( | const Font * | font, |
| const char * | text, | ||
| SDL_Color | color, | ||
| const ImageAtlas * | icons, | ||
| TextSpan ** | spans, | ||
| size_t * | count | ||
| ) |
Resolves the escapes in text into the string to lay out and the spans to draw it as.
^N selects a color for what follows, ^^ becomes ^, and a registered :icon: becomes a run of placeholder characters at least a line height wide, for the icon to be drawn over. The placeholder is never a line-break opportunity, so an icon stays with its word. With no icons, and spans NULL, the result is that of MVC_StripColorEscapes.
| font | The Font the text will be laid out in. |
| text | The text. |
| color | The color in effect at the start of text. |
| icons | The icon ImageAtlas, or NULL for none. |
| spans | If not NULL, receives the spans, which the caller MUST free. |
| count | If not NULL, receives the number of spans; meaningful only with spans. |
Definition at line 220 of file Text.c.
| OBJECTIVELYMVC_EXPORT char * MVC_StripColorEscapes | ( | const char * | text | ) |
Strips color escape sequences from the given text: ^0 through ^9 are removed, and ^^ collapses to ^.
| text | The text. |
text without escape sequences. The caller must free it. Definition at line 83 of file Text.c.
| OBJECTIVELYMVC_EXPORT SDL_Color TextEscapeColors[10] |
Color palette for text escape sequences (^0 through ^9).
Escapes are always interpreted, on every Text: ^N selects TextEscapeColors[N] for the characters that follow, and ^^ renders a literal ^. Embedding applications MAY customize this array at runtime, before rendering.
Default mapping: ^0 Black, ^1 Red, ^2 Green, ^3 Yellow, ^4 Blue, ^5 Magenta, ^6 Cyan, ^7 White, ^8 Orange, ^9 Grey.
| OBJECTIVELYMVC_EXPORT const EnumName TextTransformNames[] |