forked from albertz/commandergenius
/
font.cpp
171 lines (148 loc) · 4.55 KB
/
font.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* OpenTyrian Classic: A modern cross-platform port of Tyrian
* Copyright (C) 2007-2009 The OpenTyrian Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "font.h"
#include "fonthand.h"
#include "sprite.h"
// like JE_dString() if (black == false && shadow_dist == 2 && hue == 15)
// like JE_textShade() with PART_SHADE if (black == true && shadow_dist == 1)
// like JE_outTextAndDarken() if (black == false && shadow_dist == 1)
// like JE_outTextAdjust() with shadow if (black == false && shadow_dist == 2)
void draw_font_hv_shadow( SDL_Surface *surface, int x, int y, const char *text, Font font, FontAlignment alignment, Uint8 hue, Sint8 value, bool black, int shadow_dist )
{
draw_font_dark(surface, x + shadow_dist, y + shadow_dist, text, font, alignment, black);
draw_font_hv(surface, x, y, text, font, alignment, hue, value);
}
// like JE_textShade() with FULL_SHADE if (black == true && shadow_dist == 1)
void draw_font_hv_full_shadow( SDL_Surface *surface, int x, int y, const char *text, Font font, FontAlignment alignment, Uint8 hue, Sint8 value, bool black, int shadow_dist )
{
draw_font_dark(surface, x, y - shadow_dist, text, font, alignment, black);
draw_font_dark(surface, x + shadow_dist, y, text, font, alignment, black);
draw_font_dark(surface, x, y + shadow_dist, text, font, alignment, black);
draw_font_dark(surface, x - shadow_dist, y, text, font, alignment, black);
draw_font_hv(surface, x, y, text, font, alignment, hue, value);
}
// like JE_outText() with (brightness >= 0)
// like JE_outTextAdjust() without shadow
void draw_font_hv( SDL_Surface *surface, int x, int y, const char *text, Font font, FontAlignment alignment, Uint8 hue, Sint8 value )
{
switch (alignment)
{
case left_aligned:
break;
case centered:
x -= JE_textWidth(text, font) / 2;
break;
case right_aligned:
x -= JE_textWidth(text, font);
break;
}
bool highlight = false;
for (; *text != '\0'; ++text)
{
int sprite_id = font_ascii[(unsigned char)*text];
switch (*text)
{
case ' ':
x += 6;
break;
case '~':
highlight = !highlight;
if (highlight)
value += 4;
else
value -= 4;
break;
default:
if (sprite_id != -1 && sprite_exists(font, sprite_id))
{
blit_sprite_hv(surface, x, y, font, sprite_id, hue, value);
x += sprite(font, sprite_id)->width + 1;
}
break;
}
}
}
// like JE_outTextModify()
void draw_font_hv_blend( SDL_Surface *surface, int x, int y, const char *text, Font font, FontAlignment alignment, Uint8 hue, Sint8 value )
{
switch (alignment)
{
case left_aligned:
break;
case centered:
x -= JE_textWidth(text, font) / 2;
break;
case right_aligned:
x -= JE_textWidth(text, font);
break;
}
for (; *text != '\0'; ++text)
{
int sprite_id = font_ascii[(unsigned char)*text];
switch (*text)
{
case ' ':
x += 6;
break;
case '~':
break;
default:
if (sprite_id != -1 && sprite_exists(font, sprite_id))
{
blit_sprite_hv_blend(surface, x, y, font, sprite_id, hue, value);
x += sprite(font, sprite_id)->width + 1;
}
break;
}
}
}
// like JE_outText() with (brightness < 0) if (black == true)
void draw_font_dark( SDL_Surface *surface, int x, int y, const char *text, Font font, FontAlignment alignment, bool black )
{
switch (alignment)
{
case left_aligned:
break;
case centered:
x -= JE_textWidth(text, font) / 2;
break;
case right_aligned:
x -= JE_textWidth(text, font);
break;
}
for (; *text != '\0'; ++text)
{
int sprite_id = font_ascii[(unsigned char)*text];
switch (*text)
{
case ' ':
x += 6;
break;
case '~':
break;
default:
if (sprite_id != -1 && sprite_exists(font, sprite_id))
{
blit_sprite_dark(surface, x, y, font, sprite_id, black);
x += sprite(font, sprite_id)->width + 1;
}
break;
}
}
}