annotate src/dmtext_ttf.c @ 2294:7f6ba3b32f54

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 03 Jul 2019 10:28:43 +0300
parents b91d54a37b6b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
64
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * DMLib
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * -- Bitmap and TTF text & font support
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * Programmed and designed by Matti 'ccr' Hamalainen
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 * (C) Copyright 2012 Tecnic Software productions (TNSP)
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 */
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "dmtext.h"
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
1952
b91d54a37b6b Constify more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1611
diff changeset
10 void dmDrawTTFTextConst(SDL_Surface *screen, TTF_Font *font,
b91d54a37b6b Constify more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1611
diff changeset
11 SDL_Color col, const int xc, const int yc, const char *fmt)
64
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 {
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 SDL_Surface *text = TTF_RenderText_Blended(font, fmt, col);
1611
3571d4670964 NULL check.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
14 if (text != NULL)
64
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 {
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 SDL_Rect rect;
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 rect.x = xc;
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 rect.y = yc;
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 rect.w = text->w;
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 rect.h = text->h;
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 SDL_BlitSurface(text, NULL, screen, &rect);
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 SDL_FreeSurface(text);
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 }
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 }
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25
1952
b91d54a37b6b Constify more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1611
diff changeset
26
b91d54a37b6b Constify more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1611
diff changeset
27 void dmDrawTTFTextVA(SDL_Surface *screen, TTF_Font *font,
b91d54a37b6b Constify more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1611
diff changeset
28 SDL_Color col, const int xc, const int yc, const char *fmt, va_list ap)
64
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 {
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 char *tmp = dm_strdup_vprintf(fmt, ap);
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 if (tmp != NULL)
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 {
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 dmDrawTTFTextConst(screen, font, col, xc, yc, tmp);
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 dmFree(tmp);
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 }
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 }
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
1952
b91d54a37b6b Constify more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1611
diff changeset
38
b91d54a37b6b Constify more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1611
diff changeset
39 void dmDrawTTFText(SDL_Surface *screen, TTF_Font *font,
b91d54a37b6b Constify more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1611
diff changeset
40 SDL_Color col, const int xc, const int yc, const char *fmt, ...)
64
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 {
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 va_list ap;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
43
64
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 va_start(ap, fmt);
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 dmDrawTTFTextVA(screen, font, col, xc, yc, fmt, ap);
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 va_end(ap);
ad1ef3f0d474 More work on the text subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 }