-
Notifications
You must be signed in to change notification settings - Fork 2
/
lettering.c
203 lines (184 loc) · 5.2 KB
/
lettering.c
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.
Alternatively, the contents of this file may be used under the terms
of the GNU Lesser General Public license (the "LGPL License"), in which case the
provisions of LGPL License are applicable instead of those
above.
For feedback and questions about my Files and Projects please mail me,
Alexander Matthes (Ziz) , zizsdl_at_googlemail.com
*/
#include "lettering.h"
#include <stdlib.h>
#include <string.h>
plettering first_lettering = NULL;
void add_lettering(char* text,spFontPointer font)
{
//Create
plettering lettering = (plettering)malloc(sizeof(tlettering));
lettering->text = (char*)malloc(strlen(text)+1);
sprintf(lettering->text,"%s",text);
lettering->age = LETTERING_TIMEOUT;
lettering->y = spGetWindowSurface()->h/20;
lettering->font = font;
lettering->next = first_lettering;
first_lettering = lettering;
//Recalculate the y-values
lettering = first_lettering->next;
while (lettering)
{
lettering->y += first_lettering->font->maxheight;
lettering = lettering->next;
}
}
void add_line()
{
//Create
plettering lettering = (plettering)malloc(sizeof(tlettering));
lettering->text = NULL;
lettering->age = LETTERING_TIMEOUT;
lettering->y = spGetWindowSurface()->h/16;
lettering->font = NULL;
lettering->next = first_lettering;
first_lettering = lettering;
//Recalculate the y-values
lettering = first_lettering->next;
while (lettering)
{
lettering->y += spGetWindowSurface()->h/32;
lettering = lettering->next;
}
}
void calc_lettering(int steps)
{
plettering lettering = first_lettering;
plettering last_lettering = NULL;
//Adding
while (lettering)
{
lettering->age -= steps;
if (lettering->age<=0 || lettering->y > spGetWindowSurface()->h)
break;
last_lettering = lettering;
lettering = lettering->next;
}
//Deleting if too old or to low (y)
while (lettering)
{
plettering next = lettering->next;
if (lettering->text)
free(lettering->text);
free(lettering);
lettering = next;
}
if (last_lettering)
last_lettering->next = NULL;
else
first_lettering = NULL;
}
void delete_all_lettering()
{
while (first_lettering)
{
plettering next = first_lettering->next;
if (first_lettering->text)
free(first_lettering->text);
free(first_lettering);
first_lettering = next;
}
}
plettering get_first_lettering()
{
return first_lettering;
}
pbordering first_bordering = NULL;
#define DO_BORDERING_STUFF(line,x,y) \
if (line[(y)][(x)] == -1) \
line[(y)][(x)] = color; \
else \
line[(y)][(x)] = -1;
//#define DO_BORDERING_STUFF(line,x,y) line[(y)][(x)] = color;
void add_bordering(pwinsituation winsituation,Uint16 color)
{
//Create
pbordering bordering = (pbordering)malloc(sizeof(tbordering));
bordering->age = BORDERING_TIMEOUT;
bordering->alpha = SP_ONE;
bordering->next = first_bordering;
first_bordering = bordering;
//Marking the hor & ver lines out of the winsituation
char was_already[7][16];
memset(was_already,0,7*16);
int x,y;
for (x = 0; x < 16; x++)
{
for (y = 0; y < 7; y++)
{
bordering->horizental_line[y][x] = -1;
bordering->vertical_line[y][x] = -1;
}
bordering->horizental_line[7][x] = -1;
}
while (winsituation)
{
if (!was_already[winsituation->y][winsituation->x])
{
DO_BORDERING_STUFF(bordering->horizental_line,winsituation->x,winsituation->y);
DO_BORDERING_STUFF(bordering->vertical_line,winsituation->x,winsituation->y);
DO_BORDERING_STUFF(bordering->horizental_line,winsituation->x,winsituation->y+1);
int x_plus_one = winsituation->x+1;
if (x_plus_one >= 16)
x_plus_one-=16;
DO_BORDERING_STUFF(bordering->vertical_line,x_plus_one,winsituation->y);
was_already[winsituation->y][winsituation->x] = 1;
}
else
printf("Double! That shouldn't be: %i:%i\n",winsituation->x,winsituation->y);
winsituation = winsituation->next;
}
}
void calc_bordering(int steps)
{
pbordering bordering = first_bordering;
pbordering last_bordering = NULL;
//Adding
while (bordering)
{
bordering->age -= steps;
bordering->alpha = bordering->age*SP_ONE/BORDERING_TIMEOUT;
if (bordering->age<=0)
break;
last_bordering = bordering;
bordering = bordering->next;
}
//Deleting if too old or to low (y)
while (bordering)
{
pbordering next = bordering->next;
free(bordering);
bordering = next;
}
if (last_bordering)
last_bordering->next = NULL;
else
first_bordering = NULL;
}
void delete_all_bordering()
{
while (first_bordering)
{
pbordering next = first_bordering->next;
free(first_bordering);
first_bordering = next;
}
}
pbordering get_first_bordering()
{
return first_bordering;
}