ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
Text.h
Go to the documentation of this file.
1/*
2 * ObjectivelyMVC: Object oriented MVC framework for SDL3 and C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#pragma once
25
26#include <SDL3/SDL_gpu.h>
27
28#include <ObjectivelyMVC/Font.h>
30#include <ObjectivelyMVC/View.h>
31
47
52OBJECTIVELYMVC_EXPORT bool MVC_HasColorEscapes(const char *text);
53
60OBJECTIVELYMVC_EXPORT char *MVC_StripColorEscapes(const char *text);
61
73
75
86
91typedef struct {
92 int offset;
93 int length;
94 SDL_Color color;
96} TextSpan;
97
112OBJECTIVELYMVC_EXPORT char *MVC_LayoutText(const Font *font, const char *text, SDL_Color color, const ImageAtlas *icons, TextSpan **spans, size_t *count);
113
118typedef struct {
119 SDL_Rect src;
120 SDL_Color color;
122} TextRun;
123
124typedef struct Text Text;
125typedef struct TextInterface TextInterface;
126
131struct Text {
132
137
142 TextInterface *interface[0];
143
148 SDL_Color color;
149
158
163
169 struct {
170 SDL_Size size;
173 } naturalSizeCache;
174
180 struct {
182 unsigned generation;
183 } icons;
184
191
196 size_t runCount;
197
203 char *text;
204
209 Texture *texture;
210
219
224 char *transformed;
225
226};
227
231struct TextInterface {
232
236 ViewInterface viewInterface;
237
247 Text *(*initWithText)(Text *self, const char *text, Font *font);
248
255 SDL_Size (*naturalSize)(const Text *self);
256
266 SDL_Size (*sizeText)(const Text *self, const char *text);
267
275 void (*setFont)(Text *self, Font *font);
276
284 void (*setText)(Text *self, const char *text);
285
293 void (*setTextWithFormat)(Text *self, const char *fmt, ...);
294
302 void (*setTransform)(Text *self, TextTransform transform);
303};
304
305OBJECTIVELYMVC_EXPORT Class *_Text(void);
TrueType fonts.
Packs many Images into one sheet, backed by one Texture.
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 u...
Definition Text.c:104
OBJECTIVELYMVC_EXPORT SDL_Color TextEscapeColors[10]
Color palette for text escape sequences (^0 through ^9).
Definition Text.h:46
OBJECTIVELYMVC_EXPORT Class * _Text(void)
Definition Text.c:988
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.
Definition Text.c:220
TextTransform
Case transforms a Text applies when drawing, leaving Text::text as set.
Definition Text.h:67
@ TextTransformUppercase
Definition Text.h:69
@ TextTransformCapitalize
Definition Text.h:71
@ TextTransformLowercase
Definition Text.h:70
@ TextTransformNone
Definition Text.h:68
OBJECTIVELYMVC_EXPORT char * MVC_StripColorEscapes(const char *text)
Strips color escape sequences from the given text: ^0 through ^9 are removed, and ^^ collapses to ^.
Definition Text.c:83
OBJECTIVELYMVC_EXPORT const EnumName TextTransformNames[]
Definition Text.h:74
OBJECTIVELYMVC_EXPORT bool MVC_HasColorEscapes(const char *text)
Definition Text.c:65
static ImageAtlas * icons(Theme *self)
Definition Theme.c:144
static Font * font(Theme *self, const FontAttributes *attributes, float pixelDensity)
Definition Theme.c:108
static Image * image(Theme *self, const char *name, float pixelDensity)
Definition Theme.c:82
#define OBJECTIVELYMVC_EXPORT
Definition Types.h:40
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
An Image packed into an ImageAtlas.
Definition AtlasImage.h:41
TrueType fonts.
Definition Font.h:88
Packs many Images into one sheet, backed by one Texture.
Definition ImageAtlas.h:49
Text rendered with TrueType fonts.
Definition Text.h:131
TextTransform transform
The case transform applied when drawing: the text-transform style attribute, or textTransform in JSON...
Definition Text.h:218
TextInterface * interface[0]
The interface type.
Definition Text.h:142
Texture * texture
The rendered GPU texture.
Definition Text.h:209
float pixelDensity
Definition Text.h:171
const ImageAtlas * atlas
Definition Text.h:181
TextRun * runs
The runs of texture, one textured quad each, when the text contains escapes; otherwise NULL,...
Definition Text.h:190
bool lineWrap
If true, wrap text along word boundaries to fit this Text's width.
Definition Text.h:162
SDL_Size size
Definition Text.h:170
View view
The superclass.
Definition Text.h:136
SDL_Color color
The text color.
Definition Text.h:148
bool isValid
Definition Text.h:172
Font * font
The Font. A fixed-width Font carries a bitmap, and is drawn as one quad per glyph from its glyph shee...
Definition Text.h:157
size_t runCount
The number of entries in runs.
Definition Text.h:196
char * text
The text.
Definition Text.h:203
unsigned generation
Definition Text.h:182
One quad of a rendered TrueType Text: a region of its texture, in texels, drawn in color,...
Definition Text.h:118
AtlasImage * icon
Definition Text.h:121
SDL_Color color
Definition Text.h:120
SDL_Rect src
Definition Text.h:119
One span of a laid-out string, in bytes of the layout string MVC_LayoutText returns: either the chara...
Definition Text.h:91
int length
Definition Text.h:93
SDL_Color color
Definition Text.h:94
AtlasImage * icon
Definition Text.h:95
int offset
Definition Text.h:92
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition View.h:225