ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
Text.c File Reference
#include <assert.h>
#include <math.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "Colors.h"
#include "Text.h"

Go to the source code of this file.

Data Structures

struct  CharInfo
 Character position and color for one visible character in a color-escaped string. More...
 

Macros

#define _Class   _Text
 

Functions

Class * _Text (void)
 
static void applyStyle (View *self, const Style *style)
 
static void awakeWithDictionary (View *self, const Dictionary *dictionary)
 
static CharInfobuildCharInfo (const Font *font, const char *text, SDL_Color defaultColor, int wrapWidth, int *outCount)
 Builds a CharInfo table for text containing color escape sequences.
 
static void colorize (SDL_Surface *surface, const CharInfo *info, float scale)
 Colorizes a character's rect on a locked SDL_Surface.
 
static void dealloc (Object *self)
 
static String * description (const Object *self)
 
static Viewinit (View *self)
 
static void initialize (Class *clazz)
 
static TextinitWithText (Text *self, const char *text, Font *font)
 
static SDL_Size naturalSize (const Text *self)
 
static void render (View *self, Renderer *renderer)
 
static void renderDeviceDidReset (View *self)
 
static void renderDeviceWillReset (View *self)
 
static SDL_Surface * renderWithColorEscapes (const Text *self, int wrapWidth)
 Renders text with color escape sequences applied to an SDL_Surface.
 
static void setFont (Text *self, Font *font)
 
static void setText (Text *self, const char *text)
 
static void setTextWithFormat (Text *self, const char *fmt,...)
 
static SDL_Size sizeThatFits (const View *self)
 
static void sizeWithColorEscapes (const Text *self, int *w, int *h)
 Resolves the rendered size of this Text's content, stripping color escapes.
 
static char * stripColors (const char *text)
 Strips color escape sequences from text, returning a newly allocated string.
 
static float view_pixel_density (SDL_Window *window)
 

Variables

SDL_Color TextEscapeColors []
 

Macro Definition Documentation

◆ _Class

#define _Class   _Text

Definition at line 38 of file Text.c.

Function Documentation

◆ _Text()

Class * _Text ( void  )

Definition at line 602 of file Text.c.

602 {
603 static Class *clazz;
604 static Once once;
605
606 do_once(&once, {
607 clazz = _initialize(&(const ClassDef) {
608 .name = "Text",
609 .superclass = _View(),
610 .instanceSize = sizeof(Text),
611 .interfaceOffset = offsetof(Text, interface),
612 .interfaceSize = sizeof(TextInterface),
614 });
615 });
616
617 return clazz;
618}
static void initialize(Class *clazz)
Definition Text.c:578
Class * _View(void)
Definition View.c:2067
Text rendered with TrueType fonts.
Definition Text.h:69

◆ applyStyle()

static void applyStyle ( View self,
const Style style 
)
static
See also
View::applyStyle(View *, const Style *)

Definition at line 278 of file Text.c.

278 {
279
280 super(View, self, applyStyle, style);
281
282 Text *this = (Text *) self;
283
284 const Inlet colorInlets[] = MakeInlets(
285 MakeInlet("color", InletTypeColor, &this->color, NULL)
286 );
287
288 if ($(self, bind, colorInlets, style->attributes)) {
289 this->texture = release(this->texture);
290 this->textureSize = MakeSize(0, 0);
291 }
292
293 char *fontFamily = NULL;
294 int fontSize = -1, fontStyle = -1;
295
296 const Inlet fontInlets[] = MakeInlets(
297 MakeInlet("font-family", InletTypeCharacters, &fontFamily, NULL),
298 MakeInlet("font-size", InletTypeInteger, &fontSize, NULL),
299 MakeInlet("font-style", InletTypeEnum, &fontStyle, (ident) FontStyleNames)
300 );
301
302 if ($(self, bind, fontInlets, style->attributes)) {
303
304 Font *font = $$(Font, cachedFont, fontFamily , fontSize, fontStyle);
305 assert(font);
306
307 $(this, setFont, font);
308
309 if (fontFamily) {
310 free(fontFamily);
311 }
312 }
313}
static Font * cachedFont(const char *family, int size, int style)
Definition Font.c:126
const EnumName FontStyleNames[]
Definition Font.c:40
static void setFont(Text *self, Font *font)
Definition Text.c:512
static void applyStyle(View *self, const Style *style)
Definition Text.c:278
@ InletTypeEnum
Definition View+JSON.h:75
@ InletTypeCharacters
Definition View+JSON.h:52
@ InletTypeInteger
Definition View+JSON.h:95
@ InletTypeColor
Definition View+JSON.h:62
#define MakeInlets(...)
Creates a null-termianted array of Inlets.
Definition View+JSON.h:221
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
Definition View+JSON.h:216
TrueType fonts.
Definition Font.h:63
Inlets enable inbound data binding of View attributes through JSON.
Definition View+JSON.h:155
Dictionary * attributes
Definition Style.h:59
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition View.h:134

◆ awakeWithDictionary()

static void awakeWithDictionary ( View self,
const Dictionary *  dictionary 
)
static
See also
View::awakeWithDictionary(View *, const Dictionary *)

Definition at line 318 of file Text.c.

318 {
319
320 super(View, self, awakeWithDictionary, dictionary);
321
322 Text *this = (Text *) self;
323
324 const Inlet inlets[] = MakeInlets(
325 MakeInlet("color", InletTypeColor, &this->color, NULL),
326 MakeInlet("colorEscapes", InletTypeBool, &this->colorEscapes, NULL),
327 MakeInlet("font", InletTypeFont, &this->font, NULL),
328 MakeInlet("lineWrap", InletTypeBool, &this->lineWrap, NULL),
329 MakeInlet("text", InletTypeCharacters, &this->text, NULL)
330 );
331
332 $(self, bind, inlets, dictionary);
333
334 $(self, sizeToFit);
335}
static void awakeWithDictionary(View *self, const Dictionary *dictionary)
Definition Text.c:318
@ InletTypeBool
Definition View+JSON.h:46
@ InletTypeFont
Definition View+JSON.h:85
static void sizeToFit(View *self)
Definition View.c:1767

◆ buildCharInfo()

static CharInfo * buildCharInfo ( const Font font,
const char *  text,
SDL_Color  defaultColor,
int  wrapWidth,
int *  outCount 
)
static

Builds a CharInfo table for text containing color escape sequences.

For each visible character, calls TTF_GetStringSizeWrapped on the stripped prefix up through that character to detect line breaks via height changes, then measures x from the line-start byte with TTF_GetStringSize. SDL_ttf owns all word-wrap decisions.

Definition at line 128 of file Text.c.

129 {
130
131 if (!text || !*text) {
132 *outCount = 0;
133 return NULL;
134 }
135
136 char *stripped = stripColors(text);
137 if (!stripped || !*stripped) {
138 free(stripped);
139 *outCount = 0;
140 return NULL;
141 }
142
143 const size_t strippedLen = strlen(stripped);
144 CharInfo *chars = malloc(sizeof(CharInfo) * strippedLen);
145
146 const int scaledWrapWidth = wrapWidth ? (int) (wrapWidth * font->scale) : 0;
147
148 int lineHeight;
149 $(font, sizeCharacters, "A", NULL, &lineHeight);
150
151 SDL_Color currentColor = defaultColor;
152 int charIdx = 0;
153 int lineStartByte = 0;
154 int prevH = 0;
155
156 for (const char *p = text; *p; p++) {
157 if (p[0] == '^' && p[1] >= '0' && p[1] <= '9') {
158 currentColor = TextEscapeColors[p[1] - '0'];
159 p++;
160 continue;
161 }
162
163 int currH;
164 if (scaledWrapWidth) {
165 TTF_GetStringSizeWrapped(font->font, stripped, charIdx + 1, scaledWrapWidth, NULL, &currH);
166 } else {
167 TTF_GetStringSize(font->font, stripped, charIdx + 1, NULL, &currH);
168 }
169
170 if (currH > prevH) {
171 lineStartByte = charIdx;
172 prevH = currH;
173 }
174
175 int lineX = 0;
176 if (charIdx > lineStartByte) {
177 TTF_GetStringSize(font->font, stripped + lineStartByte, charIdx - lineStartByte, &lineX, NULL);
178 }
179
180 int charW;
181 TTF_GetStringSize(font->font, stripped + charIdx, 1, &charW, NULL);
182
183 chars[charIdx].rect.x = (int) (lineX / font->scale);
184 chars[charIdx].rect.y = (int) (currH / font->scale) - lineHeight;
185 chars[charIdx].rect.w = (int) (charW / font->scale);
186 chars[charIdx].rect.h = lineHeight;
187 chars[charIdx].color = currentColor;
188
189 charIdx++;
190 }
191
192 free(stripped);
193 *outCount = charIdx;
194 return chars;
195}
static void sizeCharacters(const Font *self, const char *chars, int *w, int *h)
Definition Font.c:273
SDL_Color TextEscapeColors[]
Definition Text.c:42
static char * stripColors(const char *text)
Strips color escape sequences from text, returning a newly allocated string.
Definition Text.c:58
Character position and color for one visible character in a color-escaped string.
Definition Text.c:80
SDL_Rect rect
Definition Text.c:81
SDL_Color color
Definition Text.c:82
float scale
The display pixel density scale (e.g. 2.0 on Retina). Updated by callers via the scale field before i...
Definition Font.h:100
TTF_Font * font
The backing font.
Definition Font.h:89

◆ colorize()

static void colorize ( SDL_Surface *  surface,
const CharInfo info,
float  scale 
)
static

Colorizes a character's rect on a locked SDL_Surface.

Definition at line 88 of file Text.c.

88 {
89
90 const float fx = floorf(info->rect.x * scale);
91 const float fy = floorf(info->rect.y * scale);
92 const float fw = ceilf(info->rect.w * scale);
93 const float fh = ceilf(info->rect.h * scale);
94
95 int x = (int) fx - 1;
96 int y = (int) fy - 1;
97 int w = (int) fw + 2;
98 int h = (int) fh + 2;
99
100 if (w <= 0 || h <= 0) {
101 return;
102 }
103
104 if (x < 0) { w += x; x = 0; }
105 if (y < 0) { h += y; y = 0; }
106
107 uint32_t *pixels = (uint32_t *) surface->pixels;
108 const int pitch = surface->pitch / 4;
109 const SDL_Color color = info->color;
110
111 for (int row = y; row < y + h && row < surface->h; row++) {
112 for (int col = x; col < x + w && col < surface->w; col++) {
113 SDL_Color *c = (SDL_Color *) &pixels[row * pitch + col];
114 c->r = (int) (c->r * color.r / 255.0f);
115 c->g = (int) (c->g * color.g / 255.0f);
116 c->b = (int) (c->b * color.b / 255.0f);
117 }
118 }
119}

◆ dealloc()

static void dealloc ( Object *  self)
static
See also
Object::dealloc(Object *)

Definition at line 240 of file Text.c.

240 {
241
242 Text *this = (Text *) self;
243
244 release(this->font);
245
246 free(this->text);
247
248 this->texture = release(this->texture);
249
250 super(Object, self, dealloc);
251}
static void dealloc(Object *self)
Definition Text.c:240

◆ description()

static String * description ( const Object *  self)
static
See also
Object::description(const Object *)

Definition at line 256 of file Text.c.

256 {
257
258 View *this = (View *) self;
259 const SDL_Rect bounds = $(this, bounds);
260
261 String *classNames = $((Object *) this->classNames, description);
262 String *description = str("%s@%p \"%s\" %s [%d, %d, %d, %d]",
263 this->identifier ?: classnameof(self),
264 self,
265 ((Text *) self)->text,
266 classNames->chars,
267 bounds.x, bounds.y, bounds.w, bounds.h);
268
269 release(classNames);
270 return description;
271}
static String * description(const Object *self)
Definition Text.c:256
static SDL_Rect bounds(const View *self)
Definition View.c:492

◆ init()

static View * init ( View self)
static
See also
View::init(View *)

Definition at line 340 of file Text.c.

340 {
341 return (View *) $((Text *) self, initWithText, NULL, NULL);
342}
static Text * initWithText(Text *self, const char *text, Font *font)
Definition Text.c:476

◆ initialize()

static void initialize ( Class *  clazz)
static
See also
Class::initialize(Class *)

Definition at line 578 of file Text.c.

578 {
579
580 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
581 ((ObjectInterface *) clazz->interface)->description = description;
582
583 ((ViewInterface *) clazz->interface)->applyStyle = applyStyle;
584 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
585 ((ViewInterface *) clazz->interface)->init = init;
586 ((ViewInterface *) clazz->interface)->render = render;
587 ((ViewInterface *) clazz->interface)->renderDeviceDidReset = renderDeviceDidReset;
588 ((ViewInterface *) clazz->interface)->renderDeviceWillReset = renderDeviceWillReset;
589 ((ViewInterface *) clazz->interface)->sizeThatFits = sizeThatFits;
590
591 ((TextInterface *) clazz->interface)->initWithText = initWithText;
592 ((TextInterface *) clazz->interface)->naturalSize = naturalSize;
593 ((TextInterface *) clazz->interface)->setFont = setFont;
594 ((TextInterface *) clazz->interface)->setText = setText;
595 ((TextInterface *) clazz->interface)->setTextWithFormat = setTextWithFormat;
596}
static void setTextWithFormat(Text *self, const char *fmt,...)
Definition Text.c:558
static View * init(View *self)
Definition Text.c:340
static void setText(Text *self, const char *text)
Definition Text.c:532
static SDL_Size sizeThatFits(const View *self)
Definition Text.c:466
static SDL_Size naturalSize(const Text *self)
Definition Text.c:491
static void render(View *self, Renderer *renderer)
Definition Text.c:347
static void renderDeviceWillReset(View *self)
Definition Text.c:453
static void renderDeviceDidReset(View *self)
Definition Text.c:440
SDL_Size naturalSize(const Text *self)
Resolves the rendered size of this Text.
Definition Text.c:491
void render(View *self, Renderer *renderer)
Renders this View using the given renderer.
Definition Control.c:179

◆ initWithText()

static Text * initWithText ( Text self,
const char *  text,
Font font 
)
static

Definition at line 476 of file Text.c.

476 {
477
478 self = (Text *) super(View, self, initWithFrame, NULL);
479 if (self) {
480 $(self, setFont, font);
481 $(self, setText, text);
482 }
483
484 return self;
485}
static Box * initWithFrame(Box *self, const SDL_Rect *frame)
Definition Box.c:92

◆ naturalSize()

static SDL_Size naturalSize ( const Text self)
static

Definition at line 491 of file Text.c.

491 {
492
493 SDL_Size size = MakeSize(0, 0);
494
495 if (self->font) {
496 const char *text = self->text ?: "";
497
498 if (self->colorEscapes) {
499 sizeWithColorEscapes(self, &size.w, &size.h);
500 } else {
501 $(self->font, sizeCharacters, text, &size.w, &size.h);
502 }
503 }
504
505 return size;
506}
static SDL_Size size(const Image *self)
Definition Image.c:181
static void sizeWithColorEscapes(const Text *self, int *w, int *h)
Resolves the rendered size of this Text's content, stripping color escapes.
Definition Text.c:228
bool colorEscapes
If true, render text with color escape sequence support (^0-^7).
Definition Text.h:101
Font * font
The Font.
Definition Text.h:92
char * text
The text.
Definition Text.h:113

◆ render()

static void render ( View self,
Renderer renderer 
)
static
See also
View::render(View *, Renderer *)

Definition at line 347 of file Text.c.

347 {
348
349 super(View, self, render, renderer);
350
351 Text *this = (Text *) self;
352
353 assert(this->font);
354
355 const float scale = view_pixel_density(self->window);
356
357 if (this->font->scale != scale) {
358 this->font->scale = scale;
359 $(this->font, renderDeviceDidReset);
360 this->texture = release(this->texture);
361 this->textureSize = MakeSize(0, 0);
362 }
363
364 if (this->text) {
365
366 const SDL_Rect frame = $(self, renderFrame);
367
368 if (this->texture == NULL) {
369 SDL_Surface *surface;
370
371 if (this->colorEscapes) {
372 surface = renderWithColorEscapes(this, this->lineWrap ? frame.w : 0);
373 } else {
374 surface = $(this->font, renderCharacters,
375 this->text,
376 this->color,
377 this->lineWrap ? frame.w : 0);
378 }
379
380 assert(surface);
381
382 const float textureWidth = roundf(surface->w / scale);
383 const float textureHeight = roundf(surface->h / scale);
384
385 this->textureSize.w = (int) textureWidth;
386 this->textureSize.h = (int) textureHeight;
387
388 SDL_Surface *upload = surface;
389 SDL_Surface *converted = NULL;
390
391 if (SDL_BYTESPERPIXEL(surface->format) == 1) {
392 converted = SDL_CreateSurface(surface->w, surface->h, SDL_PIXELFORMAT_RGBA32);
393 assert(converted);
394 const SDL_PixelFormatDetails *details = SDL_GetPixelFormatDetails(SDL_PIXELFORMAT_RGBA32);
395 assert(details);
396 const Uint8 *src = (const Uint8 *) surface->pixels;
397 Uint32 *dst = (Uint32 *) converted->pixels;
398 for (int y = 0; y < surface->h; y++) {
399 for (int x = 0; x < surface->w; x++) {
400 const Uint8 a = src[y * surface->pitch + x];
401 dst[y * surface->w + x] = SDL_MapRGBA(details, NULL, 255, 255, 255, a);
402 }
403 }
404 upload = converted;
405 } else if (surface->format != SDL_PIXELFORMAT_RGBA32) {
406 converted = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_RGBA32);
407 assert(converted);
408 upload = converted;
409 }
410
411 const SDL_GPUTextureCreateInfo texInfo = {
412 .type = SDL_GPU_TEXTURETYPE_2D,
413 .format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM,
414 .usage = SDL_GPU_TEXTUREUSAGE_SAMPLER,
415 .width = (Uint32) upload->w,
416 .height = (Uint32) upload->h,
417 .layer_count_or_depth = 1,
418 .num_levels = 1,
419 };
420
421 this->texture = $(renderer->device, createTexture, &texInfo, upload->pixels);
422
423 if (converted) {
424 SDL_DestroySurface(converted);
425 }
426
427 SDL_DestroySurface(surface);
428 }
429
430 assert(this->texture);
431
432 const SDL_Rect draw_rect = { frame.x, frame.y, this->textureSize.w, this->textureSize.h };
433 $(renderer, drawTexture, this->texture, &draw_rect, &Colors.White);
434 }
435}
static SDL_Surface * renderCharacters(const Font *self, const char *chars, SDL_Color color, int wrapWidth)
Definition Font.c:223
static void drawTexture(const Renderer *self, Texture *texture, const SDL_Rect *rect, const SDL_Color *color)
Definition Renderer.c:211
static SDL_Surface * renderWithColorEscapes(const Text *self, int wrapWidth)
Renders text with color escape sequences applied to an SDL_Surface.
Definition Text.c:200
static float view_pixel_density(SDL_Window *window)
Definition Text.c:34
static SDL_Rect renderFrame(const View *self)
Definition View.c:1455
W3C Color constants.
Definition Colors.h:37
SDL_Color White
Definition Colors.h:185
RenderDevice * device
The backing RenderDevice.
Definition Renderer.h:92
SDL_Window * window
The window.
Definition View.h:277

◆ renderDeviceDidReset()

static void renderDeviceDidReset ( View self)
static
See also
View::renderDeviceDidReset(View *)

Definition at line 440 of file Text.c.

440 {
441
442 Text *this = (Text *) self;
443
444 this->font->scale = view_pixel_density(self->window);
445 $(this->font, renderDeviceDidReset);
446
447 super(View, self, renderDeviceDidReset);
448}

◆ renderDeviceWillReset()

static void renderDeviceWillReset ( View self)
static
See also
View::renderDeviceWillReset(View *)

Definition at line 453 of file Text.c.

453 {
454
455 Text *this = (Text *) self;
456
457 this->texture = release(this->texture);
458 this->textureSize = MakeSize(0, 0);
459
460 super(View, self, renderDeviceWillReset);
461}

◆ renderWithColorEscapes()

static SDL_Surface * renderWithColorEscapes ( const Text self,
int  wrapWidth 
)
static

Renders text with color escape sequences applied to an SDL_Surface.

Definition at line 200 of file Text.c.

200 {
201
202 char *stripped = stripColors(self->text);
203 SDL_Surface *surface = $(self->font, renderCharacters, stripped, self->color, wrapWidth);
204 free(stripped);
205
206 if (!surface) {
207 return NULL;
208 }
209
210 int charCount = 0;
211 CharInfo *charInfo = buildCharInfo(self->font, self->text, self->color, wrapWidth, &charCount);
212
213 if (charInfo) {
214 SDL_LockSurface(surface);
215 for (int i = 0; i < charCount; i++) {
216 colorize(surface, &charInfo[i], self->font->scale);
217 }
218 SDL_UnlockSurface(surface);
219 free(charInfo);
220 }
221
222 return surface;
223}
static CharInfo * buildCharInfo(const Font *font, const char *text, SDL_Color defaultColor, int wrapWidth, int *outCount)
Builds a CharInfo table for text containing color escape sequences.
Definition Text.c:128
static void colorize(SDL_Surface *surface, const CharInfo *info, float scale)
Colorizes a character's rect on a locked SDL_Surface.
Definition Text.c:88
SDL_Color color
The text color.
Definition Text.h:85

◆ setFont()

static void setFont ( Text self,
Font font 
)
static

Definition at line 512 of file Text.c.

512 {
513
514 font = font ?: $$(Font, defaultFont);
515
516 if (font != self->font) {
517
518 release(self->font);
519 self->font = retain(font);
520
521 self->texture = release(self->texture);
522 self->textureSize = MakeSize(0, 0);
523
524 $((View *) self, sizeToFit);
525 }
526}
static Font * defaultFont(void)
Definition Font.c:177
SDL_Size textureSize
The logical draw dimensions of the texture (surface size / pixel density).
Definition Text.h:126
Texture * texture
The rendered GPU texture.
Definition Text.h:119

◆ setText()

static void setText ( Text self,
const char *  text 
)
static

Definition at line 532 of file Text.c.

532 {
533
534 if (strcmp(self->text ?: "", text ?: "")) {
535
536 free(self->text);
537
538 if (text && strlen(text)) {
539 self->text = strdup(text);
540 } else {
541 self->text = NULL;
542 }
543
544 self->texture = release(self->texture);
545 self->textureSize = MakeSize(0, 0);
546
547 $((View *) self, sizeToFit);
548 }
549}

◆ setTextWithFormat()

static void setTextWithFormat ( Text self,
const char *  fmt,
  ... 
)
static

Definition at line 558 of file Text.c.

558 {
559
560 va_list args;
561 va_start(args, fmt);
562
563 char *text;
564 const int len = vasprintf(&text, fmt, args);
565 if (len >= 0) {
566 $(self, setText, text);
567 }
568
569 free(text);
570 va_end(args);
571}

◆ sizeThatFits()

static SDL_Size sizeThatFits ( const View self)
static
See also
View::sizeThatFits(View *)

Definition at line 466 of file Text.c.

466 {
467 return $((Text *) self, naturalSize);
468}

◆ sizeWithColorEscapes()

static void sizeWithColorEscapes ( const Text self,
int *  w,
int *  h 
)
static

Resolves the rendered size of this Text's content, stripping color escapes.

Definition at line 228 of file Text.c.

228 {
229
230 char *stripped = stripColors(self->text ?: "");
231 $(self->font, sizeCharacters, stripped, w, h);
232 free(stripped);
233}

◆ stripColors()

static char * stripColors ( const char *  text)
static

Strips color escape sequences from text, returning a newly allocated string.

Definition at line 58 of file Text.c.

58 {
59
60 assert(text);
61
62 char *stripped = malloc(strlen(text) + 1);
63 int idx = 0;
64
65 for (const char *p = text; *p; p++) {
66 if (p[0] == '^' && p[1] >= '0' && p[1] <= '9') {
67 p++;
68 } else {
69 stripped[idx++] = *p;
70 }
71 }
72
73 stripped[idx] = '\0';
74 return stripped;
75}

◆ view_pixel_density()

static float view_pixel_density ( SDL_Window *  window)
inlinestatic

Definition at line 34 of file Text.c.

34 {
35 return window ? SDL_GetWindowPixelDensity(window) : 1.0f;
36}

Variable Documentation

◆ TextEscapeColors

SDL_Color TextEscapeColors[]
Initial value:
= {
{ 0x00, 0x00, 0x00, 0xFF },
{ 0xFF, 0x00, 0x00, 0xFF },
{ 0x00, 0xFF, 0x00, 0xFF },
{ 0xFF, 0xFF, 0x00, 0xFF },
{ 0x00, 0x00, 0xFF, 0xFF },
{ 0xFF, 0x00, 0xFF, 0xFF },
{ 0x00, 0xFF, 0xFF, 0xFF },
{ 0xFF, 0xFF, 0xFF, 0xFF },
{ 0xFF, 0x80, 0x00, 0xFF },
{ 0x80, 0x80, 0x80, 0xFF }
}

Definition at line 42 of file Text.c.

42 {
43 { 0x00, 0x00, 0x00, 0xFF }, // ^0 Black
44 { 0xFF, 0x00, 0x00, 0xFF }, // ^1 Red
45 { 0x00, 0xFF, 0x00, 0xFF }, // ^2 Green
46 { 0xFF, 0xFF, 0x00, 0xFF }, // ^3 Yellow
47 { 0x00, 0x00, 0xFF, 0xFF }, // ^4 Blue
48 { 0xFF, 0x00, 0xFF, 0xFF }, // ^5 Magenta
49 { 0x00, 0xFF, 0xFF, 0xFF }, // ^6 Cyan
50 { 0xFF, 0xFF, 0xFF, 0xFF }, // ^7 White
51 { 0xFF, 0x80, 0x00, 0xFF }, // ^8 Orange
52 { 0x80, 0x80, 0x80, 0xFF } // ^9 Grey
53};