author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1390 | e7cdf3ce0fb6 |
child 1806 | 5a55d508c23e |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1349
15979a2e9001
(svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents:
1348
diff
changeset
|
3 |
#include "spritecache.h" |
1309
4403a69da4f8
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1130
diff
changeset
|
4 |
#include "strings.h" |
0 | 5 |
#include "gfx.h" |
6 |
#include "table/palettes.h" |
|
7 |
#include "hal.h" |
|
8 |
||
1357 | 9 |
static void GfxMainBlitter(const Sprite *sprite, int x, int y, int mode); |
0 | 10 |
|
11 |
static int _stringwidth_out; |
|
12 |
static byte _cursor_backup[64*64]; |
|
13 |
static Rect _invalid_rect; |
|
1357 | 14 |
static const byte *_color_remap_ptr; |
0 | 15 |
static byte _string_colorremap[3]; |
16 |
||
17 |
#define DIRTY_BYTES_PER_LINE (MAX_SCREEN_WIDTH/64) |
|
18 |
static byte _dirty_blocks[DIRTY_BYTES_PER_LINE * MAX_SCREEN_HEIGHT / 8]; |
|
19 |
||
20 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
21 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
22 |
void memcpy_pitch(void *d, void *s, int w, int h, int spitch, int dpitch) |
0 | 23 |
{ |
24 |
byte *dp = (byte*)d; |
|
25 |
byte *sp = (byte*)s; |
|
26 |
||
27 |
assert(h >= 0); |
|
1056
24579058c082
(svn r1557) Replace strange if () do while () construct with a plain for ()
tron
parents:
1009
diff
changeset
|
28 |
for (; h != 0; --h) { |
0 | 29 |
memcpy(dp, sp, w); |
30 |
dp += dpitch; |
|
31 |
sp += spitch; |
|
1056
24579058c082
(svn r1557) Replace strange if () do while () construct with a plain for ()
tron
parents:
1009
diff
changeset
|
32 |
} |
0 | 33 |
} |
34 |
||
35 |
||
36 |
void GfxScroll(int left, int top, int width, int height, int xo, int yo) { |
|
37 |
byte *src, *dst; |
|
38 |
int p; |
|
39 |
int ht; |
|
40 |
||
41 |
if (xo == 0 && yo == 0) |
|
42 |
return; |
|
43 |
||
44 |
if (_cursor.visible) |
|
45 |
UndrawMouseCursor(); |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
46 |
UndrawTextMessage(); |
0 | 47 |
|
48 |
p = _screen.pitch; |
|
49 |
||
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
50 |
if (yo > 0) { |
0 | 51 |
// Calculate pointers |
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
52 |
dst = _screen.dst_ptr + (top + height - 1) * p + left; |
0 | 53 |
src = dst - yo * p; |
54 |
||
55 |
// Decrease height and increase top |
|
56 |
top += yo; |
|
57 |
height -= yo; |
|
58 |
assert(height > 0); |
|
59 |
||
60 |
// Adjust left & width |
|
61 |
if (xo >= 0) { |
|
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
62 |
dst += xo; |
0 | 63 |
left += xo; |
64 |
width -= xo; |
|
65 |
} else { |
|
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
66 |
src -= xo; |
0 | 67 |
width += xo; |
68 |
} |
|
69 |
||
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
70 |
for (ht = height; ht > 0; --ht) { |
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
71 |
memcpy(dst, src, width); |
0 | 72 |
src -= p; |
73 |
dst -= p; |
|
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
74 |
} |
0 | 75 |
} else { |
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
76 |
// Calculate pointers |
0 | 77 |
dst = _screen.dst_ptr + top * p + left; |
78 |
src = dst - yo * p; |
|
79 |
||
80 |
// Decrese height. (yo is <=0). |
|
81 |
height += yo; |
|
82 |
assert(height > 0); |
|
83 |
||
84 |
// Adjust left & width |
|
85 |
if (xo >= 0) { |
|
86 |
dst += xo; |
|
87 |
left += xo; |
|
88 |
width -= xo; |
|
89 |
} else { |
|
90 |
src -= xo; |
|
91 |
width += xo; |
|
92 |
} |
|
93 |
||
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
94 |
// the y-displacement may be 0 therefore we have to use memmove, |
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
95 |
// because source and destination may overlap |
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
96 |
for (ht = height; ht > 0; --ht) { |
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
97 |
memmove(dst, src, width); |
0 | 98 |
src += p; |
99 |
dst += p; |
|
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
100 |
} |
0 | 101 |
} |
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
102 |
// This part of the screen is now dirty. |
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
103 |
_video_driver->make_dirty(left, top, width, height); |
0 | 104 |
} |
105 |
||
106 |
||
107 |
void GfxFillRect(int left, int top, int right, int bottom, int color) { |
|
108 |
DrawPixelInfo *dpi = _cur_dpi; |
|
1357 | 109 |
byte *dst; |
332 | 110 |
const int otop = top; |
111 |
const int oleft = left; |
|
0 | 112 |
|
113 |
if (dpi->zoom != 0) |
|
114 |
return; |
|
115 |
||
116 |
if (left > right || top > bottom) |
|
117 |
return; |
|
118 |
||
119 |
if (right < dpi->left || left >= dpi->left + dpi->width) |
|
120 |
return; |
|
121 |
||
122 |
if (bottom < dpi->top || top >= dpi->top + dpi->height) |
|
123 |
return; |
|
124 |
||
125 |
if ( (left -= dpi->left) < 0) left = 0; |
|
126 |
right = right - dpi->left + 1; |
|
127 |
if (right > dpi->width) right=dpi->width; |
|
128 |
right -= left; |
|
129 |
assert(right > 0); |
|
130 |
||
131 |
if ( (top -= dpi->top) < 0) top = 0; |
|
132 |
bottom = bottom - dpi->top + 1; |
|
133 |
if (bottom > dpi->height) bottom=dpi->height; |
|
134 |
bottom -= top; |
|
135 |
assert(bottom > 0); |
|
136 |
||
137 |
dst = dpi->dst_ptr + top * dpi->pitch + left; |
|
138 |
||
139 |
if (!(color & 0x8000)) { |
|
140 |
if (!(color & 0x4000)) { |
|
141 |
do { |
|
142 |
memset(dst, color, right); |
|
143 |
dst += dpi->pitch; |
|
144 |
} while (--bottom); |
|
145 |
} else { |
|
146 |
/* use colortable mode */ |
|
1357 | 147 |
const byte* ctab = GetNonSprite(color & 0x3FFF) + 1; |
148 |
||
0 | 149 |
do { |
150 |
int i; |
|
151 |
for(i=0; i!=right;i++) |
|
152 |
dst[i] = ctab[dst[i]]; |
|
153 |
dst += dpi->pitch; |
|
154 |
} while (--bottom); |
|
155 |
} |
|
156 |
} else { |
|
332 | 157 |
byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1; |
0 | 158 |
do { |
159 |
int i; |
|
332 | 160 |
for (i = (bo ^= 1); i < right; i += 2) |
161 |
dst[i] = (byte)color; |
|
0 | 162 |
dst += dpi->pitch; |
332 | 163 |
} while (--bottom > 0); |
0 | 164 |
} |
165 |
} |
|
166 |
||
410 | 167 |
static void GfxSetPixel(int x, int y, int color) |
0 | 168 |
{ |
169 |
DrawPixelInfo *dpi = _cur_dpi; |
|
170 |
if ((x-=dpi->left) < 0 || x>=dpi->width || (y-=dpi->top)<0 || y>=dpi->height) |
|
171 |
return; |
|
172 |
dpi->dst_ptr[y*dpi->pitch+x] = color; |
|
173 |
} |
|
174 |
||
175 |
void GfxDrawLine(int x, int y, int x2, int y2, int color) |
|
176 |
{ |
|
177 |
int dy; |
|
178 |
int dx; |
|
179 |
int stepx, stepy; |
|
180 |
int frac; |
|
181 |
||
182 |
// Check clipping first |
|
183 |
{ |
|
184 |
DrawPixelInfo *dpi = _cur_dpi; |
|
185 |
int t; |
|
186 |
||
187 |
if (x < dpi->left && x2 < dpi->left) |
|
188 |
return; |
|
189 |
||
190 |
if (y < dpi->top && y2 < dpi->top) |
|
191 |
return; |
|
192 |
||
193 |
t = dpi->left + dpi->width; |
|
194 |
if (x > t && x2 > t) |
|
195 |
return; |
|
196 |
||
197 |
t = dpi->top + dpi->height; |
|
198 |
if (y > t && y2 > t) |
|
199 |
return; |
|
200 |
} |
|
201 |
||
202 |
dy = (y2 - y) * 2; |
|
203 |
if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; } |
|
204 |
||
205 |
dx = (x2 - x) * 2; |
|
206 |
if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; } |
|
207 |
||
208 |
GfxSetPixel(x, y, color); |
|
209 |
if (dx > dy) { |
|
210 |
frac = dy - (dx >> 1); |
|
211 |
while (x != x2) { |
|
212 |
if (frac >= 0) { |
|
213 |
y += stepy; |
|
214 |
frac -= dx; |
|
215 |
} |
|
216 |
x += stepx; |
|
217 |
frac += dy; |
|
218 |
GfxSetPixel(x, y, color); |
|
219 |
} |
|
220 |
} else { |
|
221 |
frac = dx - (dy >> 1); |
|
222 |
while (y != y2) { |
|
223 |
if (frac >= 0) { |
|
224 |
x += stepx; |
|
225 |
frac -= dy; |
|
226 |
} |
|
227 |
y += stepy; |
|
228 |
frac += dx; |
|
229 |
GfxSetPixel(x, y, color); |
|
230 |
} |
|
231 |
} |
|
232 |
} |
|
233 |
||
234 |
// ASSIGNMENT OF ASCII LETTERS < 32 |
|
235 |
// 0 - end of string |
|
236 |
// 1 - SETX <BYTE> |
|
237 |
// 2 - SETXY <BYTE> <BYTE> |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
238 |
// 3-7 - |
0 | 239 |
// 8 - TINYFONT |
240 |
// 9 - BIGFONT |
|
241 |
// 10 - newline |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
242 |
// 11-14 - |
0 | 243 |
// 15-31 - 17 colors |
244 |
||
245 |
||
246 |
enum { |
|
247 |
ASCII_SETX = 1, |
|
248 |
ASCII_SETXY = 2, |
|
249 |
||
250 |
ASCII_TINYFONT = 8, |
|
251 |
ASCII_BIGFONT = 9, |
|
252 |
ASCII_NL = 10, |
|
253 |
||
254 |
ASCII_COLORSTART = 15, |
|
255 |
}; |
|
256 |
||
257 |
||
258 |
/* returns right coordinate */ |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
259 |
int DrawString(int x, int y, uint16 str, uint16 color) |
0 | 260 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
261 |
char buffer[512]; |
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
262 |
|
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
263 |
GetString(buffer, str); |
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
264 |
return DoDrawString(buffer, x, y, color); |
0 | 265 |
} |
266 |
||
267 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
268 |
void DrawStringRightAligned(int x, int y, uint16 str, uint16 color) |
0 | 269 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
270 |
char buffer[512]; |
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
271 |
|
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
272 |
GetString(buffer, str); |
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
273 |
DoDrawString(buffer, x - GetStringWidth(buffer), y, color); |
0 | 274 |
} |
275 |
||
276 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
277 |
int DrawStringCentered(int x, int y, uint16 str, uint16 color) |
0 | 278 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
279 |
char buffer[512]; |
0 | 280 |
int w; |
281 |
||
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
282 |
GetString(buffer, str); |
0 | 283 |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
284 |
w = GetStringWidth(buffer); |
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
285 |
DoDrawString(buffer, x - w / 2, y, color); |
0 | 286 |
|
287 |
return w; |
|
288 |
} |
|
289 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
290 |
void DrawStringCenterUnderline(int x, int y, uint16 str, uint16 color) |
0 | 291 |
{ |
292 |
int w = DrawStringCentered(x, y, str, color); |
|
293 |
GfxFillRect(x-(w>>1), y+10, x-(w>>1)+w, y+10, _string_colorremap[1]); |
|
294 |
} |
|
295 |
||
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
296 |
static uint32 FormatStringLinebreaks(char *str, int maxw) |
1095 | 297 |
{ |
0 | 298 |
int num = 0; |
299 |
int base = _stringwidth_base; |
|
300 |
int w; |
|
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
301 |
char *last_space; |
0 | 302 |
byte c; |
303 |
||
304 |
for(;;) { |
|
305 |
w = 0; |
|
306 |
last_space = NULL; |
|
307 |
||
308 |
for(;;) { |
|
309 |
c = *str++; |
|
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1357
diff
changeset
|
310 |
if (c == ASCII_LETTERSTART) last_space = str; |
0 | 311 |
|
312 |
if (c >= ASCII_LETTERSTART) { |
|
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1357
diff
changeset
|
313 |
w += GetCharacterWidth(base + (byte)c); |
0 | 314 |
if (w > maxw) { |
315 |
str = last_space; |
|
316 |
if (str == NULL) |
|
317 |
return num + (base << 16); |
|
318 |
break; |
|
319 |
} |
|
320 |
} else { |
|
321 |
if (c == 0) return num + (base << 16); |
|
322 |
if (c == ASCII_NL) break; |
|
323 |
||
324 |
if (c == ASCII_SETX) str++; |
|
325 |
else if (c == ASCII_SETXY) str += 2; |
|
326 |
else if (c == ASCII_TINYFONT) base = 224; |
|
327 |
else if (c == ASCII_BIGFONT) base = 448; |
|
328 |
} |
|
329 |
} |
|
330 |
||
331 |
num++; |
|
332 |
str[-1] = 0; |
|
333 |
} |
|
334 |
} |
|
335 |
||
336 |
||
337 |
void DrawStringMultiCenter(int x, int y, uint16 str, int maxw) |
|
338 |
{ |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
339 |
char buffer[512]; |
0 | 340 |
uint32 tmp; |
341 |
int num, w, mt, t; |
|
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
342 |
const char *src; |
0 | 343 |
byte c; |
344 |
||
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
345 |
GetString(buffer, str); |
0 | 346 |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
347 |
tmp = FormatStringLinebreaks(buffer, maxw); |
0 | 348 |
num = (uint16)tmp; |
349 |
t = tmp >> 16; |
|
350 |
||
351 |
mt = 10; |
|
352 |
if (t != 0) { |
|
353 |
mt = 6; |
|
354 |
if (t != 244) mt = 18; |
|
355 |
} |
|
356 |
||
357 |
y -= (mt >> 1) * num; |
|
358 |
||
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
359 |
src = buffer; |
0 | 360 |
|
361 |
for(;;) { |
|
362 |
w = GetStringWidth(src); |
|
363 |
DoDrawString(src, x - (w>>1), y, 0xFE); |
|
364 |
_stringwidth_base = _stringwidth_out; |
|
365 |
||
366 |
for(;;) { |
|
367 |
c = *src++; |
|
368 |
if (c == 0) { |
|
369 |
y += mt; |
|
370 |
if (--num < 0) { |
|
371 |
_stringwidth_base = 0; |
|
372 |
return; |
|
373 |
} |
|
374 |
break; |
|
375 |
} else if (c == ASCII_SETX) { |
|
376 |
src++; |
|
377 |
} else if (c == ASCII_SETXY) { |
|
378 |
src+=2; |
|
379 |
} |
|
380 |
} |
|
381 |
} |
|
382 |
} |
|
383 |
||
384 |
void DrawStringMultiLine(int x, int y, uint16 str, int maxw) { |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
385 |
char buffer[512]; |
0 | 386 |
uint32 tmp; |
387 |
int num, w, mt, t; |
|
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
388 |
const char *src; |
0 | 389 |
byte c; |
390 |
||
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
391 |
GetString(buffer, str); |
0 | 392 |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
393 |
tmp = FormatStringLinebreaks(buffer, maxw); |
0 | 394 |
num = (uint16)tmp; |
395 |
t = tmp >> 16; |
|
396 |
mt = 10; |
|
397 |
if (t != 0) { |
|
398 |
mt = 6; |
|
399 |
if (t != 244) mt = 18; |
|
400 |
} |
|
401 |
||
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
402 |
src = buffer; |
0 | 403 |
|
404 |
for(;;) { |
|
405 |
w = GetStringWidth(src); |
|
406 |
DoDrawString(src, x, y, 0xFE); |
|
407 |
_stringwidth_base = _stringwidth_out; |
|
408 |
||
409 |
for(;;) { |
|
410 |
c = *src++; |
|
411 |
if (c == 0) { |
|
412 |
y += mt; |
|
413 |
if (--num < 0) { |
|
414 |
_stringwidth_base = 0; |
|
415 |
return; |
|
416 |
} |
|
417 |
break; |
|
418 |
} else if (c == ASCII_SETX) { |
|
419 |
src++; |
|
420 |
} else if (c == ASCII_SETXY) { |
|
421 |
src+=2; |
|
422 |
} |
|
423 |
} |
|
424 |
} |
|
425 |
} |
|
426 |
||
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
427 |
int GetStringWidth(const char *str) |
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
428 |
{ |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1357
diff
changeset
|
429 |
int w = 0; |
0 | 430 |
byte c; |
431 |
int base = _stringwidth_base; |
|
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1357
diff
changeset
|
432 |
for (c = *str; c != '\0'; c = *(++str)) { |
0 | 433 |
if (c >= ASCII_LETTERSTART) { |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1357
diff
changeset
|
434 |
w += GetCharacterWidth(base + c); |
0 | 435 |
} else { |
436 |
if (c == ASCII_SETX) str++; |
|
437 |
else if (c == ASCII_SETXY) str += 2; |
|
438 |
else if (c == ASCII_TINYFONT) base = 224; |
|
439 |
else if (c == ASCII_BIGFONT) base = 448; |
|
440 |
} |
|
441 |
} |
|
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1357
diff
changeset
|
442 |
return w; |
0 | 443 |
} |
444 |
||
445 |
void DrawFrameRect(int left, int top, int right, int bottom, int ctab, int flags) { |
|
446 |
byte color_2 = _color_list[ctab].window_color_1a; |
|
447 |
byte color_interior = _color_list[ctab].window_color_bga; |
|
448 |
byte color_3 = _color_list[ctab].window_color_bgb; |
|
449 |
byte color = _color_list[ctab].window_color_2; |
|
450 |
||
451 |
if (!(flags & 0x8)) { |
|
452 |
if (!(flags & 0x20)) { |
|
453 |
GfxFillRect(left, top, left, bottom-1, color); |
|
454 |
GfxFillRect(left+1, top, right-1, top, color); |
|
455 |
GfxFillRect(right, top, right, bottom-1, color_2); |
|
456 |
GfxFillRect(left, bottom, right, bottom, color_2); |
|
457 |
if (!(flags & 0x10)) { |
|
458 |
GfxFillRect(left+1, top+1, right-1, bottom-1, color_interior); |
|
459 |
} |
|
460 |
} else { |
|
461 |
GfxFillRect(left, top, left, bottom, color_2); |
|
462 |
GfxFillRect(left+1, top, right, top, color_2); |
|
463 |
GfxFillRect(right, top+1, right, bottom-1, color); |
|
464 |
GfxFillRect(left+1, bottom, right, bottom, color); |
|
465 |
if (!(flags & 0x10)) { |
|
466 |
GfxFillRect(left+1, top+1, right-1, bottom-1, |
|
467 |
flags&0x40 ? color_interior : color_3); |
|
468 |
} |
|
469 |
} |
|
470 |
} else if (flags & 0x1) { |
|
471 |
// transparency |
|
472 |
GfxFillRect(left, top, right, bottom, 0x4322); |
|
473 |
} else { |
|
474 |
GfxFillRect(left, top, right, bottom, color_interior); |
|
475 |
} |
|
476 |
} |
|
477 |
||
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
478 |
int DoDrawString(const char *string, int x, int y, uint16 real_color) |
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
479 |
{ |
0 | 480 |
DrawPixelInfo *dpi = _cur_dpi; |
481 |
int base = _stringwidth_base; |
|
509
3217af6d2d6a
(svn r819) Code cleanup: colors for langfile strings are now taken from a color table instead of a sprite
dominik
parents:
461
diff
changeset
|
482 |
byte c; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
483 |
byte color; |
0 | 484 |
int xo = x, yo = y; |
485 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
486 |
color = real_color & 0xFF; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
487 |
|
0 | 488 |
if (color != 0xFE) { |
489 |
if (x >= dpi->left + dpi->width || |
|
490 |
x + _screen.width*2 <= dpi->left || |
|
491 |
y >= dpi->top + dpi->height || |
|
492 |
y + _screen.height <= dpi->top) |
|
493 |
return x; |
|
494 |
||
495 |
if (color != 0xFF) { |
|
496 |
switch_color:; |
|
657
d4d36b4853ec
(svn r1091) Fix: Finally station names use 100% the correct color in transparent mode
dominik
parents:
619
diff
changeset
|
497 |
if (real_color & IS_PALETTE_COLOR) { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
498 |
_string_colorremap[1] = color; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
499 |
_string_colorremap[2] = 215; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
500 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
501 |
_string_colorremap[1] = _string_colormap[color].text; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
502 |
_string_colorremap[2] = _string_colormap[color].shadow; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
503 |
} |
0 | 504 |
_color_remap_ptr = _string_colorremap; |
505 |
} |
|
506 |
} |
|
507 |
||
508 |
check_bounds: |
|
509 |
if (y + 19 <= dpi->top || dpi->top + dpi->height <= y) { |
|
510 |
skip_char:; |
|
511 |
for(;;) { |
|
512 |
c = *string++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
513 |
if (c < ASCII_LETTERSTART) goto skip_cont; |
0 | 514 |
} |
515 |
} |
|
516 |
||
517 |
for(;;) { |
|
518 |
c = *string++; |
|
519 |
skip_cont:; |
|
520 |
if (c == 0) { |
|
521 |
_stringwidth_out = base; |
|
522 |
return x; |
|
523 |
} |
|
524 |
if (c >= ASCII_LETTERSTART) { |
|
525 |
if (x >= dpi->left + dpi->width) goto skip_char; |
|
526 |
if (x + 26 >= dpi->left) { |
|
1350
fd0136012af1
(svn r1854) Split GetSpritePtr() into GetSprite() for regular sprites (returning a Sprite*) and GetNonSprite() for "sprites" of type 0xFF (returning byte*)
tron
parents:
1349
diff
changeset
|
527 |
GfxMainBlitter(GetSprite(base + 2 + c - ASCII_LETTERSTART), x, y, 1); |
0 | 528 |
} |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1357
diff
changeset
|
529 |
x += GetCharacterWidth(base + c); |
0 | 530 |
} else if (c == ASCII_NL) { // newline = {} |
531 |
x = xo; |
|
532 |
y += 10; |
|
533 |
if (base != 0) { |
|
534 |
y -= 4; |
|
535 |
if (base != 0xE0) |
|
536 |
y += 12; |
|
537 |
} |
|
538 |
goto check_bounds; |
|
539 |
} else if (c >= ASCII_COLORSTART) { // change color? |
|
540 |
color = (byte)(c - ASCII_COLORSTART); |
|
541 |
goto switch_color; |
|
542 |
} else if (c == ASCII_SETX) { // {SETX} |
|
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
543 |
x = xo + (byte)*string++; |
0 | 544 |
} else if (c == ASCII_SETXY) {// {SETXY} |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
545 |
x = xo + (byte)*string++; |
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
546 |
y = yo + (byte)*string++; |
0 | 547 |
} else if (c == ASCII_TINYFONT) { // {TINYFONT} |
548 |
base = 0xE0; |
|
549 |
} else if (c == ASCII_BIGFONT) { // {BIGFONT} |
|
550 |
base = 0x1C0; |
|
551 |
} else { |
|
552 |
printf("Unknown string command character %d\n", c); |
|
553 |
} |
|
554 |
} |
|
555 |
} |
|
556 |
||
557 |
void DrawSprite(uint32 img, int x, int y) { |
|
558 |
if (img & 0x8000) { |
|
1350
fd0136012af1
(svn r1854) Split GetSpritePtr() into GetSprite() for regular sprites (returning a Sprite*) and GetNonSprite() for "sprites" of type 0xFF (returning byte*)
tron
parents:
1349
diff
changeset
|
559 |
_color_remap_ptr = GetNonSprite(img >> 16) + 1; |
fd0136012af1
(svn r1854) Split GetSpritePtr() into GetSprite() for regular sprites (returning a Sprite*) and GetNonSprite() for "sprites" of type 0xFF (returning byte*)
tron
parents:
1349
diff
changeset
|
560 |
GfxMainBlitter(GetSprite(img & 0x3FFF), x, y, 1); |
0 | 561 |
} else if (img & 0x4000) { |
1350
fd0136012af1
(svn r1854) Split GetSpritePtr() into GetSprite() for regular sprites (returning a Sprite*) and GetNonSprite() for "sprites" of type 0xFF (returning byte*)
tron
parents:
1349
diff
changeset
|
562 |
_color_remap_ptr = GetNonSprite(img >> 16) + 1; |
fd0136012af1
(svn r1854) Split GetSpritePtr() into GetSprite() for regular sprites (returning a Sprite*) and GetNonSprite() for "sprites" of type 0xFF (returning byte*)
tron
parents:
1349
diff
changeset
|
563 |
GfxMainBlitter(GetSprite(img & 0x3FFF), x, y, 2); |
0 | 564 |
} else { |
1350
fd0136012af1
(svn r1854) Split GetSpritePtr() into GetSprite() for regular sprites (returning a Sprite*) and GetNonSprite() for "sprites" of type 0xFF (returning byte*)
tron
parents:
1349
diff
changeset
|
565 |
GfxMainBlitter(GetSprite(img & 0x3FFF), x, y, 0); |
0 | 566 |
} |
567 |
} |
|
568 |
||
569 |
typedef struct BlitterParams { |
|
570 |
int start_x, start_y; |
|
1357 | 571 |
const byte* sprite; |
572 |
const byte* sprite_org; |
|
0 | 573 |
byte *dst; |
574 |
int mode; |
|
575 |
int width, height; |
|
576 |
int width_org, height_org; |
|
577 |
int pitch; |
|
578 |
byte info; |
|
579 |
} BlitterParams; |
|
580 |
||
581 |
static void GfxBlitTileZoomIn(BlitterParams *bp) |
|
582 |
{ |
|
1357 | 583 |
const byte* src_o = bp->sprite; |
584 |
const byte* src; |
|
0 | 585 |
int num, skip; |
586 |
byte done; |
|
1357 | 587 |
byte *dst; |
588 |
const byte* ctab; |
|
0 | 589 |
|
590 |
if (bp->mode & 1) { |
|
591 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
592 |
|
0 | 593 |
do { |
594 |
do { |
|
595 |
done = src_o[0]; |
|
596 |
num = done & 0x7F; |
|
597 |
skip = src_o[1]; |
|
598 |
src = src_o + 2; |
|
599 |
src_o += num + 2; |
|
600 |
||
601 |
dst = bp->dst; |
|
602 |
||
603 |
if ( (skip -= bp->start_x) > 0) { |
|
604 |
dst += skip; |
|
605 |
} else { |
|
606 |
src -= skip; |
|
607 |
num += skip; |
|
608 |
if (num <= 0) |
|
609 |
continue; |
|
610 |
skip = 0; |
|
611 |
} |
|
612 |
||
613 |
skip = skip + num - bp->width; |
|
614 |
if (skip > 0) { |
|
615 |
num -= skip; |
|
616 |
if (num <= 0) |
|
617 |
continue; |
|
618 |
} |
|
619 |
||
620 |
ctab = _color_remap_ptr; |
|
621 |
||
622 |
while (num >= 4) { |
|
623 |
dst[3] = ctab[src[3]]; |
|
624 |
dst[2] = ctab[src[2]]; |
|
625 |
dst[1] = ctab[src[1]]; |
|
626 |
dst[0] = ctab[src[0]]; |
|
627 |
dst += 4; |
|
628 |
src += 4; |
|
629 |
num -= 4; |
|
630 |
} |
|
631 |
while (num) { |
|
632 |
*dst++ = ctab[*src++]; |
|
633 |
num--; |
|
634 |
} |
|
635 |
} while (!(done & 0x80)); |
|
636 |
||
637 |
bp->dst += bp->pitch; |
|
638 |
} while (--bp->height); |
|
639 |
} else if (bp->mode & 2) { |
|
640 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
641 |
do { |
|
642 |
do { |
|
643 |
done = src_o[0]; |
|
644 |
num = done & 0x7F; |
|
645 |
skip = src_o[1]; |
|
646 |
src_o += num + 2; |
|
647 |
||
648 |
dst = bp->dst; |
|
649 |
||
650 |
if ( (skip -= bp->start_x) > 0) { |
|
651 |
dst += skip; |
|
652 |
} else { |
|
653 |
num += skip; |
|
654 |
if (num <= 0) |
|
655 |
continue; |
|
656 |
skip = 0; |
|
657 |
} |
|
658 |
||
659 |
skip = skip + num - bp->width; |
|
660 |
if (skip > 0) { |
|
661 |
num -= skip; |
|
662 |
if (num <= 0) |
|
663 |
continue; |
|
664 |
} |
|
665 |
||
666 |
ctab = _color_remap_ptr; |
|
667 |
while (num) { |
|
668 |
*dst = ctab[*dst]; |
|
669 |
dst++; |
|
670 |
num--; |
|
671 |
} |
|
672 |
} while (!(done & 0x80)); |
|
673 |
||
674 |
bp->dst += bp->pitch; |
|
675 |
} while (--bp->height); |
|
676 |
||
677 |
} else { |
|
678 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
679 |
do { |
|
680 |
do { |
|
681 |
done = src_o[0]; |
|
682 |
num = done & 0x7F; |
|
683 |
skip = src_o[1]; |
|
684 |
src = src_o + 2; |
|
685 |
src_o += num + 2; |
|
686 |
||
687 |
dst = bp->dst; |
|
688 |
||
689 |
if ( (skip -= bp->start_x) > 0) { |
|
690 |
dst += skip; |
|
691 |
} else { |
|
692 |
src -= skip; |
|
693 |
num += skip; |
|
694 |
if (num <= 0) |
|
695 |
continue; |
|
696 |
skip = 0; |
|
697 |
} |
|
698 |
||
699 |
skip = skip + num - bp->width; |
|
700 |
if (skip > 0) { |
|
701 |
num -= skip; |
|
702 |
if (num <= 0) |
|
703 |
continue; |
|
704 |
} |
|
705 |
#if defined(_WIN32) |
|
706 |
if (num & 1) *dst++ = *src++; |
|
707 |
if (num & 2) { *(uint16*)dst = *(uint16*)src; dst += 2; src += 2; } |
|
708 |
if (num >>= 2) { |
|
709 |
do { |
|
710 |
*(uint32*)dst = *(uint32*)src; |
|
711 |
dst += 4; |
|
712 |
src += 4; |
|
713 |
} while (--num); |
|
714 |
} |
|
715 |
#else |
|
716 |
memcpy(dst, src, num); |
|
717 |
#endif |
|
718 |
} while (!(done & 0x80)); |
|
719 |
||
720 |
bp->dst += bp->pitch; |
|
721 |
} while (--bp->height); |
|
722 |
} |
|
723 |
} |
|
724 |
||
725 |
static void GfxBlitZoomInUncomp(BlitterParams *bp) |
|
726 |
{ |
|
1357 | 727 |
const byte *src = bp->sprite; |
0 | 728 |
byte *dst = bp->dst; |
729 |
int height = bp->height; |
|
730 |
int width = bp->width; |
|
731 |
int i; |
|
732 |
||
733 |
assert(height > 0); |
|
734 |
assert(width > 0); |
|
735 |
||
736 |
if (bp->mode & 1) { |
|
737 |
if (bp->info & 1) { |
|
1357 | 738 |
const byte *ctab = _color_remap_ptr; |
0 | 739 |
byte b; |
740 |
||
741 |
do { |
|
742 |
for(i=0; i!=width; i++) { |
|
743 |
if ((b=ctab[src[i]]) != 0) |
|
744 |
dst[i] = b; |
|
745 |
} |
|
746 |
src += bp->width_org; |
|
747 |
dst += bp->pitch; |
|
748 |
} while (--height); |
|
749 |
} |
|
750 |
} else if (bp->mode & 2) { |
|
751 |
if (bp->info & 1) { |
|
1357 | 752 |
const byte *ctab = _color_remap_ptr; |
753 |
||
0 | 754 |
do { |
755 |
for(i=0; i!=width; i++) |
|
756 |
if (src[i]) |
|
757 |
dst[i] = ctab[dst[i]]; |
|
758 |
src += bp->width_org; |
|
759 |
dst += bp->pitch; |
|
760 |
} while (--height); |
|
761 |
} |
|
762 |
} else { |
|
763 |
if (!(bp->info & 1)) { |
|
764 |
do { |
|
765 |
memcpy(dst, src, width); |
|
766 |
src += bp->width_org; |
|
767 |
dst += bp->pitch; |
|
768 |
} while (--height); |
|
769 |
} else { |
|
770 |
do { |
|
771 |
int n = width; |
|
772 |
while (n >= 4) { |
|
773 |
if (src[0]) dst[0] = src[0]; |
|
774 |
if (src[1]) dst[1] = src[1]; |
|
775 |
if (src[2]) dst[2] = src[2]; |
|
776 |
if (src[3]) dst[3] = src[3]; |
|
777 |
||
778 |
dst += 4; |
|
779 |
src += 4; |
|
780 |
n -= 4; |
|
781 |
} |
|
782 |
||
783 |
while (n) { |
|
784 |
if (src[0]) dst[0] = src[0]; |
|
785 |
src++; |
|
786 |
dst++; |
|
787 |
n--; |
|
788 |
} |
|
789 |
||
790 |
src += bp->width_org - width; |
|
791 |
dst += bp->pitch - width; |
|
792 |
||
793 |
} while (--height); |
|
794 |
} |
|
795 |
} |
|
796 |
} |
|
797 |
||
798 |
static void GfxBlitTileZoomMedium(BlitterParams *bp) |
|
799 |
{ |
|
1357 | 800 |
const byte* src_o = bp->sprite; |
801 |
const byte* src; |
|
0 | 802 |
int num, skip; |
803 |
byte done; |
|
1357 | 804 |
byte *dst; |
805 |
const byte* ctab; |
|
0 | 806 |
|
807 |
if (bp->mode & 1) { |
|
808 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
809 |
do { |
|
810 |
do { |
|
811 |
done = src_o[0]; |
|
812 |
num = done & 0x7F; |
|
813 |
skip = src_o[1]; |
|
814 |
src = src_o + 2; |
|
815 |
src_o += num + 2; |
|
816 |
||
817 |
dst = bp->dst; |
|
818 |
||
819 |
if (skip & 1) { |
|
820 |
skip++; |
|
821 |
src++; |
|
822 |
if (!--num) |
|
823 |
continue; |
|
824 |
} |
|
825 |
||
826 |
if ( (skip -= bp->start_x) > 0) { |
|
827 |
dst += skip >> 1; |
|
828 |
} else { |
|
829 |
src -= skip; |
|
830 |
num += skip; |
|
831 |
if (num <= 0) |
|
832 |
continue; |
|
833 |
skip = 0; |
|
834 |
} |
|
835 |
||
836 |
skip = skip + num - bp->width; |
|
837 |
if (skip > 0) { |
|
838 |
num -= skip; |
|
839 |
if (num <= 0) |
|
840 |
continue; |
|
841 |
} |
|
842 |
||
843 |
ctab = _color_remap_ptr; |
|
844 |
num = (num + 1) >> 1; |
|
845 |
if (num) { |
|
846 |
do { |
|
847 |
*dst = ctab[*src]; |
|
848 |
dst++; |
|
849 |
src+=2; |
|
850 |
} while (--num); |
|
851 |
} |
|
852 |
} while (!(done & 0x80)); |
|
853 |
bp->dst += bp->pitch; |
|
854 |
if (!--bp->height) |
|
855 |
return; |
|
856 |
||
857 |
do { |
|
858 |
done = src_o[0]; |
|
859 |
src_o += (done & 0x7F) + 2; |
|
860 |
} while (!(done & 0x80)); |
|
861 |
} while (--bp->height); |
|
862 |
} else if (bp->mode & 2) { |
|
863 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
864 |
do { |
|
865 |
do { |
|
866 |
done = src_o[0]; |
|
867 |
num = done & 0x7F; |
|
868 |
skip = src_o[1]; |
|
869 |
src_o += num + 2; |
|
870 |
||
871 |
dst = bp->dst; |
|
872 |
||
873 |
if (skip & 1) { |
|
874 |
skip++; |
|
875 |
if (!--num) |
|
876 |
continue; |
|
877 |
} |
|
878 |
||
879 |
if ( (skip -= bp->start_x) > 0) { |
|
880 |
dst += skip >> 1; |
|
881 |
} else { |
|
882 |
num += skip; |
|
883 |
if (num <= 0) |
|
884 |
continue; |
|
885 |
skip = 0; |
|
886 |
} |
|
887 |
||
888 |
skip = skip + num - bp->width; |
|
889 |
if (skip > 0) { |
|
890 |
num -= skip; |
|
891 |
if (num <= 0) |
|
892 |
continue; |
|
893 |
} |
|
894 |
||
895 |
ctab = _color_remap_ptr; |
|
896 |
num = (num + 1) >> 1; |
|
897 |
if (num) { |
|
898 |
do { |
|
899 |
*dst = ctab[*dst]; |
|
900 |
dst++; |
|
901 |
} while (--num); |
|
902 |
} |
|
903 |
||
904 |
} while (!(done & 0x80)); |
|
905 |
bp->dst += bp->pitch; |
|
906 |
if (!--bp->height) |
|
907 |
return; |
|
908 |
||
909 |
do { |
|
910 |
done = src_o[0]; |
|
911 |
src_o += (done & 0x7F) + 2; |
|
912 |
} while (!(done & 0x80)); |
|
913 |
} while (--bp->height); |
|
914 |
||
915 |
} else { |
|
916 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
917 |
do { |
|
918 |
do { |
|
919 |
done = src_o[0]; |
|
920 |
num = done & 0x7F; |
|
921 |
skip = src_o[1]; |
|
922 |
src = src_o + 2; |
|
923 |
src_o += num + 2; |
|
924 |
||
925 |
dst = bp->dst; |
|
926 |
||
927 |
if (skip & 1) { |
|
928 |
skip++; |
|
929 |
src++; |
|
930 |
if (!--num) |
|
931 |
continue; |
|
932 |
} |
|
933 |
||
934 |
if ( (skip -= bp->start_x) > 0) { |
|
935 |
dst += skip >> 1; |
|
936 |
} else { |
|
937 |
src -= skip; |
|
938 |
num += skip; |
|
939 |
if (num <= 0) |
|
940 |
continue; |
|
941 |
skip = 0; |
|
942 |
} |
|
943 |
||
944 |
skip = skip + num - bp->width; |
|
945 |
if (skip > 0) { |
|
946 |
num -= skip; |
|
947 |
if (num <= 0) |
|
948 |
continue; |
|
949 |
} |
|
950 |
||
951 |
num = (num + 1) >> 1; |
|
952 |
||
953 |
if (num) { |
|
954 |
do { |
|
955 |
*dst = *src; |
|
956 |
dst++; |
|
957 |
src+=2; |
|
958 |
} while (--num); |
|
959 |
} |
|
960 |
||
961 |
} while (!(done & 0x80)); |
|
962 |
||
963 |
bp->dst += bp->pitch; |
|
964 |
if (!--bp->height) |
|
965 |
return; |
|
966 |
||
967 |
do { |
|
968 |
done = src_o[0]; |
|
969 |
src_o += (done & 0x7F) + 2; |
|
970 |
} while (!(done & 0x80)); |
|
971 |
||
972 |
} while (--bp->height); |
|
973 |
} |
|
974 |
} |
|
975 |
||
976 |
static void GfxBlitZoomMediumUncomp(BlitterParams *bp) |
|
977 |
{ |
|
1357 | 978 |
const byte *src = bp->sprite; |
0 | 979 |
byte *dst = bp->dst; |
980 |
int height = bp->height; |
|
981 |
int width = bp->width; |
|
982 |
int i; |
|
983 |
||
984 |
assert(height > 0); |
|
985 |
assert(width > 0); |
|
986 |
||
987 |
if (bp->mode & 1) { |
|
988 |
if (bp->info & 1) { |
|
1357 | 989 |
const byte *ctab = _color_remap_ptr; |
990 |
byte b; |
|
991 |
||
0 | 992 |
height >>= 1; |
993 |
if (height) do { |
|
994 |
for(i=0; i!=width>>1; i++) |
|
995 |
if ((b=ctab[src[i*2]]) != 0) |
|
996 |
dst[i] = b; |
|
997 |
src += bp->width_org * 2; |
|
998 |
dst += bp->pitch; |
|
999 |
} while (--height); |
|
1000 |
} |
|
1001 |
} else if (bp->mode & 2) { |
|
1002 |
if (bp->info & 1) { |
|
1357 | 1003 |
const byte *ctab = _color_remap_ptr; |
1004 |
||
0 | 1005 |
height >>= 1; |
1006 |
if (height) do { |
|
1007 |
for(i=0; i!=width>>1; i++) |
|
1008 |
if (src[i*2]) |
|
1009 |
dst[i] = ctab[dst[i]]; |
|
1010 |
src += bp->width_org * 2; |
|
1011 |
dst += bp->pitch; |
|
1012 |
} while (--height); |
|
1013 |
} |
|
1014 |
} else { |
|
1015 |
if (bp->info & 1) { |
|
1016 |
height >>= 1; |
|
1017 |
if (height) do { |
|
1018 |
for(i=0; i!=width>>1; i++) |
|
1019 |
if (src[i*2]) |
|
1020 |
dst[i] = src[i*2]; |
|
1021 |
src += bp->width_org * 2; |
|
1022 |
dst += bp->pitch; |
|
1023 |
} while (--height); |
|
1024 |
} |
|
1025 |
} |
|
1026 |
} |
|
1027 |
||
1028 |
static void GfxBlitTileZoomOut(BlitterParams *bp) |
|
1029 |
{ |
|
1357 | 1030 |
const byte* src_o = bp->sprite; |
1031 |
const byte* src; |
|
0 | 1032 |
int num, skip; |
1033 |
byte done; |
|
1357 | 1034 |
byte *dst; |
1035 |
const byte* ctab; |
|
0 | 1036 |
|
1037 |
if (bp->mode & 1) { |
|
1038 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
1039 |
for(;;) { |
|
1040 |
do { |
|
1041 |
done = src_o[0]; |
|
1042 |
num = done & 0x7F; |
|
1043 |
skip = src_o[1]; |
|
1044 |
src = src_o + 2; |
|
1045 |
src_o += num + 2; |
|
1046 |
||
1047 |
dst = bp->dst; |
|
1048 |
||
1049 |
if (skip & 1) { |
|
1050 |
skip++; |
|
1051 |
src++; |
|
1052 |
if (!--num) |
|
1053 |
continue; |
|
1054 |
} |
|
1055 |
||
1056 |
if (skip & 2) { |
|
1057 |
skip+=2; |
|
1058 |
src+=2; |
|
1059 |
if ((num-=2) <= 0) |
|
1060 |
continue; |
|
1061 |
} |
|
1062 |
||
1063 |
if ( (skip -= bp->start_x) > 0) { |
|
1064 |
dst += skip >> 2; |
|
1065 |
} else { |
|
1066 |
src -= skip; |
|
1067 |
num += skip; |
|
1068 |
if (num <= 0) |
|
1069 |
continue; |
|
1070 |
skip = 0; |
|
1071 |
} |
|
1072 |
||
1073 |
skip = skip + num - bp->width; |
|
1074 |
if (skip > 0) { |
|
1075 |
num -= skip; |
|
1076 |
if (num <= 0) |
|
1077 |
continue; |
|
1078 |
} |
|
1079 |
||
1080 |
ctab = _color_remap_ptr; |
|
1081 |
num = (num + 3) >> 2; |
|
1082 |
if (num) { |
|
1083 |
do { |
|
1084 |
*dst = ctab[*src]; |
|
1085 |
dst++; |
|
1086 |
src+=4; |
|
1087 |
} while (--num); |
|
1088 |
} |
|
1089 |
} while (!(done & 0x80)); |
|
1090 |
bp->dst += bp->pitch; |
|
1091 |
if (!--bp->height) |
|
1092 |
return; |
|
1093 |
||
1094 |
do { |
|
1095 |
done = src_o[0]; |
|
1096 |
src_o += (done & 0x7F) + 2; |
|
1097 |
} while (!(done & 0x80)); |
|
1098 |
if (!--bp->height) |
|
1099 |
return; |
|
1100 |
||
1101 |
do { |
|
1102 |
done = src_o[0]; |
|
1103 |
src_o += (done & 0x7F) + 2; |
|
1104 |
} while (!(done & 0x80)); |
|
1105 |
if (!--bp->height) |
|
1106 |
return; |
|
1107 |
||
1108 |
do { |
|
1109 |
done = src_o[0]; |
|
1110 |
src_o += (done & 0x7F) + 2; |
|
1111 |
} while (!(done & 0x80)); |
|
1112 |
if (!--bp->height) |
|
1113 |
return; |
|
1114 |
} |
|
1115 |
} else if (bp->mode & 2) { |
|
1116 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
1117 |
for(;;) { |
|
1118 |
do { |
|
1119 |
done = src_o[0]; |
|
1120 |
num = done & 0x7F; |
|
1121 |
skip = src_o[1]; |
|
1122 |
src_o += num + 2; |
|
1123 |
||
1124 |
dst = bp->dst; |
|
1125 |
||
1126 |
if (skip & 1) { |
|
1127 |
skip++; |
|
1128 |
if (!--num) |
|
1129 |
continue; |
|
1130 |
} |
|
1131 |
||
1132 |
if (skip & 2) { |
|
1133 |
skip+=2; |
|
1134 |
if ((num-=2) <= 0) |
|
1135 |
continue; |
|
1136 |
} |
|
1137 |
||
1138 |
if ( (skip -= bp->start_x) > 0) { |
|
1139 |
dst += skip >> 2; |
|
1140 |
} else { |
|
1141 |
num += skip; |
|
1142 |
if (num <= 0) |
|
1143 |
continue; |
|
1144 |
skip = 0; |
|
1145 |
} |
|
1146 |
||
1147 |
skip = skip + num - bp->width; |
|
1148 |
if (skip > 0) { |
|
1149 |
num -= skip; |
|
1150 |
if (num <= 0) |
|
1151 |
continue; |
|
1152 |
} |
|
1153 |
||
1154 |
ctab = _color_remap_ptr; |
|
1155 |
num = (num + 3) >> 2; |
|
1156 |
if (num) { |
|
1157 |
do { |
|
1158 |
*dst = ctab[*dst]; |
|
1159 |
dst++; |
|
1160 |
} while (--num); |
|
1161 |
} |
|
1162 |
||
1163 |
} while (!(done & 0x80)); |
|
1164 |
bp->dst += bp->pitch; |
|
1165 |
if (!--bp->height) |
|
1166 |
return; |
|
1167 |
||
1168 |
do { |
|
1169 |
done = src_o[0]; |
|
1170 |
src_o += (done & 0x7F) + 2; |
|
1171 |
} while (!(done & 0x80)); |
|
1172 |
if (!--bp->height) |
|
1173 |
return; |
|
1174 |
||
1175 |
do { |
|
1176 |
done = src_o[0]; |
|
1177 |
src_o += (done & 0x7F) + 2; |
|
1178 |
} while (!(done & 0x80)); |
|
1179 |
if (!--bp->height) |
|
1180 |
return; |
|
1181 |
||
1182 |
do { |
|
1183 |
done = src_o[0]; |
|
1184 |
src_o += (done & 0x7F) + 2; |
|
1185 |
} while (!(done & 0x80)); |
|
1186 |
if (!--bp->height) |
|
1187 |
return; |
|
1188 |
} |
|
1189 |
} else { |
|
1190 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
1191 |
for(;;) { |
|
1192 |
do { |
|
1193 |
done = src_o[0]; |
|
1194 |
num = done & 0x7F; |
|
1195 |
skip = src_o[1]; |
|
1196 |
src = src_o + 2; |
|
1197 |
src_o += num + 2; |
|
1198 |
||
1199 |
dst = bp->dst; |
|
1200 |
||
1201 |
if (skip & 1) { |
|
1202 |
skip++; |
|
1203 |
src++; |
|
1204 |
if (!--num) |
|
1205 |
continue; |
|
1206 |
} |
|
1207 |
||
1208 |
if (skip & 2) { |
|
1209 |
skip+=2; |
|
1210 |
src+=2; |
|
1211 |
if ((num-=2) <= 0) |
|
1212 |
continue; |
|
1213 |
} |
|
1214 |
||
1215 |
if ( (skip -= bp->start_x) > 0) { |
|
1216 |
dst += skip >> 2; |
|
1217 |
} else { |
|
1218 |
src -= skip; |
|
1219 |
num += skip; |
|
1220 |
if (num <= 0) |
|
1221 |
continue; |
|
1222 |
skip = 0; |
|
1223 |
} |
|
1224 |
||
1225 |
skip = skip + num - bp->width; |
|
1226 |
if (skip > 0) { |
|
1227 |
num -= skip; |
|
1228 |
if (num <= 0) |
|
1229 |
continue; |
|
1230 |
} |
|
1231 |
||
1232 |
num = (num + 3) >> 2; |
|
1233 |
||
1234 |
if (num) { |
|
1235 |
do { |
|
1236 |
*dst = *src; |
|
1237 |
dst++; |
|
1238 |
src+=4; |
|
1239 |
} while (--num); |
|
1240 |
} |
|
1241 |
||
1242 |
} while (!(done & 0x80)); |
|
1243 |
||
1244 |
bp->dst += bp->pitch; |
|
1245 |
if (!--bp->height) |
|
1246 |
return; |
|
1247 |
||
1248 |
do { |
|
1249 |
done = src_o[0]; |
|
1250 |
src_o += (done & 0x7F) + 2; |
|
1251 |
} while (!(done & 0x80)); |
|
1252 |
if (!--bp->height) |
|
1253 |
return; |
|
1254 |
||
1255 |
do { |
|
1256 |
done = src_o[0]; |
|
1257 |
src_o += (done & 0x7F) + 2; |
|
1258 |
} while (!(done & 0x80)); |
|
1259 |
if (!--bp->height) |
|
1260 |
return; |
|
1261 |
||
1262 |
do { |
|
1263 |
done = src_o[0]; |
|
1264 |
src_o += (done & 0x7F) + 2; |
|
1265 |
} while (!(done & 0x80)); |
|
1266 |
if (!--bp->height) |
|
1267 |
return; |
|
1268 |
} |
|
1269 |
} |
|
1270 |
} |
|
1271 |
||
1272 |
static void GfxBlitZoomOutUncomp(BlitterParams *bp) |
|
1273 |
{ |
|
1357 | 1274 |
const byte* src = bp->sprite; |
0 | 1275 |
byte *dst = bp->dst; |
1276 |
int height = bp->height; |
|
1277 |
int width = bp->width; |
|
1278 |
int i; |
|
1279 |
||
1280 |
assert(height > 0); |
|
1281 |
assert(width > 0); |
|
1282 |
||
1283 |
if (bp->mode & 1) { |
|
1284 |
if (bp->info & 1) { |
|
1357 | 1285 |
const byte *ctab = _color_remap_ptr; |
1286 |
byte b; |
|
1287 |
||
0 | 1288 |
height >>= 2; |
1289 |
if (height) do { |
|
1290 |
for(i=0; i!=width>>2; i++) |
|
1291 |
if ((b=ctab[src[i*4]]) != 0) |
|
1292 |
dst[i] = b; |
|
1293 |
src += bp->width_org * 4; |
|
1294 |
dst += bp->pitch; |
|
1295 |
} while (--height); |
|
1296 |
} |
|
1297 |
} else if (bp->mode & 2) { |
|
1298 |
if (bp->info & 1) { |
|
1357 | 1299 |
const byte *ctab = _color_remap_ptr; |
1300 |
||
0 | 1301 |
height >>= 2; |
1302 |
if (height) do { |
|
1303 |
for(i=0; i!=width>>2; i++) |
|
1304 |
if (src[i*4]) |
|
1305 |
dst[i] = ctab[dst[i]]; |
|
1306 |
src += bp->width_org * 4; |
|
1307 |
dst += bp->pitch; |
|
1308 |
} while (--height); |
|
1309 |
} |
|
1310 |
} else { |
|
1311 |
if (bp->info & 1) { |
|
1312 |
height >>= 2; |
|
1313 |
if (height) do { |
|
1314 |
for(i=0; i!=width>>2; i++) |
|
1315 |
if (src[i*4]) |
|
1316 |
dst[i] = src[i*4]; |
|
1317 |
src += bp->width_org * 4; |
|
1318 |
dst += bp->pitch; |
|
1319 |
} while (--height); |
|
1320 |
} |
|
1321 |
} |
|
1322 |
} |
|
1323 |
||
1324 |
typedef void (*BlitZoomFunc)(BlitterParams *bp); |
|
1325 |
||
1357 | 1326 |
static void GfxMainBlitter(const Sprite* sprite, int x, int y, int mode) |
0 | 1327 |
{ |
1328 |
DrawPixelInfo *dpi = _cur_dpi; |
|
1329 |
int start_x, start_y; |
|
1330 |
byte info; |
|
1331 |
BlitterParams bp; |
|
1332 |
int zoom_mask = ~((1 << (dpi->zoom))-1); |
|
1333 |
||
1334 |
static const BlitZoomFunc zf_tile[3] = |
|
1335 |
{ |
|
1336 |
GfxBlitTileZoomIn, |
|
1337 |
GfxBlitTileZoomMedium, |
|
1338 |
GfxBlitTileZoomOut |
|
1339 |
}; |
|
1340 |
static const BlitZoomFunc zf_uncomp[3] = |
|
1341 |
{ |
|
1342 |
GfxBlitZoomInUncomp, |
|
1343 |
GfxBlitZoomMediumUncomp, |
|
1344 |
GfxBlitZoomOutUncomp |
|
1345 |
}; |
|
1346 |
||
1347 |
/* decode sprite header */ |
|
1351
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1348 |
x += sprite->x_offs; |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1349 |
y += sprite->y_offs; |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1350 |
bp.width_org = bp.width = sprite->width; |
1348 | 1351 |
bp.height_org = bp.height = sprite->height; |
1352 |
info = sprite->info; |
|
0 | 1353 |
bp.info = info; |
1348 | 1354 |
bp.sprite_org = bp.sprite = sprite->data; |
0 | 1355 |
bp.dst = dpi->dst_ptr; |
1356 |
bp.mode = mode; |
|
1357 |
bp.pitch = dpi->pitch; |
|
1358 |
||
1359 |
assert(bp.height > 0); |
|
1360 |
assert(bp.width > 0); |
|
1361 |
||
1362 |
if (info & 8) { |
|
1363 |
/* tile blit */ |
|
1364 |
start_y = 0; |
|
1365 |
||
1366 |
if (dpi->zoom > 0) { |
|
1367 |
start_y += bp.height &~ zoom_mask; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
1368 |
bp.height &= zoom_mask; |
0 | 1369 |
if (bp.height == 0) return; |
1370 |
y&=zoom_mask; |
|
1371 |
} |
|
1372 |
||
1373 |
if ( (y -= dpi->top) < 0) { |
|
1374 |
if ((bp.height += y) <= 0) |
|
1375 |
return; |
|
1376 |
start_y -= y; |
|
1377 |
y = 0; |
|
1378 |
} else { |
|
1379 |
bp.dst += bp.pitch * (y>>(dpi->zoom)); |
|
1380 |
} |
|
1381 |
bp.start_y = start_y; |
|
1382 |
||
1383 |
if ( (y = y + bp.height - dpi->height) > 0) { |
|
1384 |
if ( (bp.height -= y) <= 0) |
|
1385 |
return; |
|
1386 |
} |
|
1387 |
||
1388 |
start_x = 0; |
|
1389 |
x &= zoom_mask; |
|
1390 |
if ( (x -= dpi->left) < 0) { |
|
1391 |
if ((bp.width += x) <= 0) |
|
1392 |
return; |
|
1393 |
start_x -= x; |
|
1394 |
x = 0; |
|
1395 |
} |
|
1396 |
bp.start_x = start_x; |
|
1397 |
bp.dst += x>>(dpi->zoom); |
|
1398 |
||
1399 |
if ( (x = x + bp.width - dpi->width) > 0) { |
|
1400 |
if ( (bp.width -= x) <= 0) |
|
1401 |
return; |
|
1402 |
} |
|
1403 |
||
1404 |
zf_tile[dpi->zoom](&bp); |
|
1405 |
} else { |
|
1406 |
||
1407 |
bp.sprite += bp.width * (bp.height & ~zoom_mask); |
|
1408 |
bp.height &= zoom_mask; |
|
1409 |
if (bp.height == 0) |
|
1410 |
return; |
|
1411 |
||
1412 |
y &= zoom_mask; |
|
1413 |
||
1414 |
if ( (y -= dpi->top) < 0) { |
|
1415 |
if ((bp.height += y) <= 0) |
|
1416 |
return; |
|
1417 |
bp.sprite -= bp.width * y; |
|
1418 |
y = 0; |
|
1419 |
} else { |
|
1420 |
bp.dst += bp.pitch * (y>>(dpi->zoom)); |
|
1421 |
} |
|
1422 |
||
1423 |
if ( (y = y + bp.height - dpi->height) > 0) { |
|
1424 |
if ( (bp.height -= y) <= 0) |
|
1425 |
return; |
|
1426 |
} |
|
1427 |
||
1428 |
start_x = 0; |
|
1429 |
||
1430 |
x &= zoom_mask; |
|
1431 |
||
1432 |
if ( (x -= dpi->left) < 0) { |
|
1433 |
if ((bp.width += x) <= 0) |
|
1434 |
return; |
|
1435 |
start_x -= x; |
|
1436 |
bp.sprite -= x; |
|
1437 |
x = 0; |
|
1438 |
} |
|
1439 |
bp.dst += x>>(dpi->zoom); |
|
1440 |
||
1441 |
if ( (x = x + bp.width - dpi->width) > 0) { |
|
1442 |
if ( (bp.width -= x) <= 0) |
|
1443 |
return; |
|
1444 |
start_x += x; |
|
1445 |
} |
|
1446 |
bp.start_x = start_x; |
|
1447 |
||
1448 |
if (info&2) { |
|
1449 |
int totpix = bp.height_org * bp.width_org; |
|
1450 |
byte *dst = (byte*)alloca(totpix); |
|
1357 | 1451 |
const byte *src = bp.sprite_org; |
0 | 1452 |
signed char b; |
1453 |
||
461
7fb521090180
(svn r679) Clarify bp.sprite assignment in GfxMainBlitter(). Pointed out by Oskar.
pasky
parents:
410
diff
changeset
|
1454 |
bp.sprite = dst + (bp.sprite - bp.sprite_org); |
0 | 1455 |
|
1456 |
while (totpix != 0) { |
|
1457 |
assert(totpix > 0); |
|
1458 |
b = *src++; |
|
1459 |
if (b >= 0) { |
|
1460 |
int i, count=b; |
|
1461 |
for(i=0; i!=count; i++) |
|
1462 |
dst[i] = src[i]; |
|
1463 |
dst += count; |
|
1464 |
src += count; |
|
1465 |
totpix -= count; |
|
1466 |
} else { |
|
1467 |
byte *tmp = dst- (((b&7)<<8)|(*src++)); |
|
1468 |
int i; |
|
1469 |
int count = -(b >> 3); |
|
1470 |
||
1471 |
for(i=0; i!=count; i++) |
|
1472 |
dst[i] = tmp[i]; |
|
1473 |
dst += count; |
|
1474 |
totpix -= count; |
|
1475 |
} |
|
1476 |
} |
|
1477 |
} |
|
1478 |
zf_uncomp[dpi->zoom](&bp); |
|
1479 |
} |
|
1480 |
} |
|
1481 |
||
798 | 1482 |
#if 0 |
410 | 1483 |
static void GfxScalePalette(int pal, byte scaling) |
0 | 1484 |
{ |
1485 |
byte *dst, *src; |
|
1486 |
size_t count; |
|
1487 |
||
1488 |
GfxInitPalettes(); |
|
1489 |
||
1490 |
dst = _cur_palette; |
|
1491 |
src = GET_PALETTE(pal); |
|
1492 |
count = 256; |
|
1493 |
do { |
|
1494 |
dst[0] = (byte)(src[0] * scaling >> 8); |
|
1495 |
dst[1] = (byte)(src[1] * scaling >> 8); |
|
1496 |
dst[2] = (byte)(src[2] * scaling >> 8); |
|
1497 |
dst += 3; |
|
1498 |
src += 3; |
|
1499 |
} while (--count); |
|
1500 |
} |
|
798 | 1501 |
#endif |
0 | 1502 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1503 |
void DoPaletteAnimations(void); |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1504 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1505 |
void GfxInitPalettes(void) |
0 | 1506 |
{ |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1507 |
int pal = _use_dos_palette?1:0; |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1508 |
memcpy(_cur_palette, _palettes[pal], 256*3); |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1509 |
|
0 | 1510 |
_pal_first_dirty = 0; |
1511 |
_pal_last_dirty = 255; |
|
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1512 |
DoPaletteAnimations(); |
0 | 1513 |
} |
1514 |
||
1515 |
#define EXTR(p,q) (((uint16)(_timer_counter * (p)) * (q)) >> 16) |
|
1516 |
#define EXTR2(p,q) (((uint16)(~_timer_counter * (p)) * (q)) >> 16) |
|
1517 |
#define COPY_TRIPLET do {d[0]=s[0+j]; d[1]=s[1+j]; d[2]=s[2+j];d+=3;}while(0) |
|
1518 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1519 |
void DoPaletteAnimations(void) |
0 | 1520 |
{ |
1521 |
const byte *s; |
|
1522 |
byte *d; |
|
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1523 |
/* Amount of colors to be rotated. |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1524 |
* A few more for the DOS palette, because the water colors are |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1525 |
* 245-254 for DOS and 217-226 for Windows. */ |
915 | 1526 |
int c = _use_dos_palette?38:28; |
0 | 1527 |
int j; |
1528 |
int i; |
|
1529 |
const ExtraPaletteValues *ev = &_extra_palette_values; |
|
619
abab6c8f1af7
(svn r1045) -Fix: OpenTTD compiles again under VC6 (sign_de)
truelight
parents:
614
diff
changeset
|
1530 |
byte old_val[114]; // max(c*(38:28)) = 114 |
0 | 1531 |
|
1532 |
d = _cur_palette + 217*3; |
|
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1533 |
memcpy(old_val, d, c*3); |
0 | 1534 |
|
1535 |
// Dark blue water |
|
1536 |
s = ev->a; |
|
1537 |
if (_opt.landscape == LT_CANDY) s = ev->ac; |
|
1538 |
j = EXTR(320,5) * 3; |
|
1539 |
for(i=0; i!=5; i++) { |
|
1540 |
COPY_TRIPLET; |
|
1541 |
j+=3; |
|
1542 |
if (j == 15) j = 0; |
|
1543 |
} |
|
1544 |
||
1545 |
// Glittery water |
|
1546 |
s = ev->b; |
|
1547 |
if (_opt.landscape == LT_CANDY) s = ev->bc; |
|
1548 |
j = EXTR(128, 15) * 3; |
|
1549 |
for(i=0; i!=5; i++) { |
|
1550 |
COPY_TRIPLET; |
|
1551 |
j += 9; |
|
1552 |
if (j >= 45) j -= 45; |
|
1553 |
} |
|
1554 |
||
1555 |
s = ev->e; |
|
1556 |
j = EXTR2(512, 5) * 3; |
|
1557 |
for(i=0; i!=5; i++) { |
|
1558 |
COPY_TRIPLET; |
|
1559 |
j += 3; |
|
1560 |
if (j == 3*5) j = 0; |
|
1561 |
} |
|
1562 |
||
1563 |
// Oil refinery fire animation |
|
1564 |
s = ev->oil_ref; |
|
1565 |
j = EXTR2(512, 7) * 3; |
|
1566 |
for(i=0; i!=7; i++) { |
|
1567 |
COPY_TRIPLET; |
|
1568 |
j += 3; |
|
1569 |
if (j == 3*7) j = 0; |
|
1570 |
} |
|
1571 |
||
1572 |
// Radio tower blinking |
|
1573 |
{ |
|
1574 |
byte i,v; |
|
1575 |
i = (_timer_counter >> 1) & 0x7F; |
|
1576 |
(v = 255, i < 0x3f) || |
|
1577 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
1578 |
(v = 20); |
|
1579 |
d[0] = v; |
|
1580 |
d[1] = d[2] = 0; |
|
1581 |
d += 3; |
|
1582 |
||
1583 |
i ^= 0x40; |
|
1584 |
(v = 255, i < 0x3f) || |
|
1585 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
1586 |
(v = 20); |
|
1587 |
d[0] = v; |
|
1588 |
||
1589 |
d[1] = d[2] = 0; |
|
1590 |
d += 3; |
|
1591 |
} |
|
1592 |
||
1593 |
// Handle lighthouse and stadium animation |
|
1594 |
s = ev->lighthouse; |
|
1595 |
j = EXTR(256, 4) * 3; |
|
1596 |
for(i=0; i!=4; i++) { |
|
1597 |
COPY_TRIPLET; |
|
1598 |
j += 3; |
|
1599 |
if (j == 3*4) j = 0; |
|
1600 |
} |
|
1601 |
||
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1602 |
// Animate water for old DOS graphics |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1603 |
if(_use_dos_palette) { |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1604 |
// Dark blue water DOS |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1605 |
s = ev->a; |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1606 |
if (_opt.landscape == LT_CANDY) s = ev->ac; |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1607 |
j = EXTR(320,5) * 3; |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1608 |
for(i=0; i!=5; i++) { |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1609 |
COPY_TRIPLET; |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1610 |
j+=3; |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1611 |
if (j == 15) j = 0; |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1612 |
} |
915 | 1613 |
|
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1614 |
// Glittery water DOS |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1615 |
s = ev->b; |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1616 |
if (_opt.landscape == LT_CANDY) s = ev->bc; |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1617 |
j = EXTR(128, 15) * 3; |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1618 |
for(i=0; i!=5; i++) { |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1619 |
COPY_TRIPLET; |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1620 |
j += 9; |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1621 |
if (j >= 45) j -= 45; |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1622 |
} |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1623 |
} |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1624 |
|
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1625 |
if (memcmp(old_val, _cur_palette + 217*3, c*3)) { |
0 | 1626 |
if (_pal_first_dirty > 217) _pal_first_dirty = 217; |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1627 |
if (_pal_last_dirty < 217+c) _pal_last_dirty = 217+c; |
0 | 1628 |
} |
1629 |
} |
|
1630 |
||
1631 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1632 |
void LoadStringWidthTable(void) |
0 | 1633 |
{ |
1634 |
int i; |
|
1635 |
byte *b; |
|
1636 |
||
1637 |
b = _stringwidth_table; |
|
1638 |
||
1639 |
// 2 equals space. |
|
1640 |
for(i=2; i != 0xE2; i++) { |
|
1351
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1641 |
*b++ = (byte)((i < 93 || i >= 129 || i == 98) ? GetSprite(i)->width : 0); |
0 | 1642 |
} |
1643 |
||
1644 |
for(i=0xE2; i != 0x1C2; i++) { |
|
1351
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1645 |
*b++ = (byte)((i < 317 || i >= 353) ? GetSprite(i)->width + 1 : 0); |
0 | 1646 |
} |
1647 |
||
1648 |
for(i=0x1C2; i != 0x2A2; i++) { |
|
1351
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1649 |
*b++ = (byte)((i < 541 || i >= 577) ? GetSprite(i)->width + 1 : 0); |
0 | 1650 |
} |
1651 |
} |
|
1652 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1653 |
void ScreenSizeChanged(void) |
0 | 1654 |
{ |
1655 |
// check the dirty rect |
|
1656 |
if (_invalid_rect.right >= _screen.width) _invalid_rect.right = _screen.width; |
|
1657 |
if (_invalid_rect.bottom >= _screen.height) _invalid_rect.bottom = _screen.height; |
|
1658 |
||
1659 |
// screen size changed and the old bitmap is invalid now, so we don't want to undraw it |
|
1660 |
_cursor.visible = false; |
|
1661 |
} |
|
1662 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1663 |
void UndrawMouseCursor(void) |
0 | 1664 |
{ |
1665 |
if (_cursor.visible) { |
|
1666 |
_cursor.visible = false; |
|
1667 |
memcpy_pitch( |
|
1668 |
_screen.dst_ptr + _cursor.draw_pos.x + _cursor.draw_pos.y * _screen.pitch, |
|
1669 |
_cursor_backup, |
|
1670 |
_cursor.draw_size.x, _cursor.draw_size.y, _cursor.draw_size.x, _screen.pitch); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
1671 |
|
0 | 1672 |
_video_driver->make_dirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y); |
1673 |
} |
|
1674 |
} |
|
1675 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1676 |
void DrawMouseCursor(void) |
0 | 1677 |
{ |
1678 |
int x,y,w,h; |
|
1679 |
||
1680 |
// Don't draw the mouse cursor if it's already drawn |
|
1681 |
if (_cursor.visible) { |
|
1682 |
if (!_cursor.dirty) |
|
1683 |
return; |
|
1684 |
UndrawMouseCursor(); |
|
1685 |
} |
|
1686 |
||
1687 |
w = _cursor.size.x; |
|
1688 |
x = _cursor.pos.x + _cursor.offs.x; |
|
1689 |
if (x < 0) { w += x; x=0; } |
|
1690 |
if (w>_screen.width-x) { w = _screen.width-x; } |
|
1691 |
if (w <= 0) return; |
|
1692 |
_cursor.draw_pos.x = x; |
|
1693 |
_cursor.draw_size.x = w; |
|
1694 |
||
1695 |
h = _cursor.size.y; |
|
1696 |
y = _cursor.pos.y + _cursor.offs.y; |
|
1697 |
if (y < 0) { h += y; y=0; } |
|
1698 |
if (h>_screen.height-y) { h = _screen.height-y; } |
|
1699 |
if (h <= 0) return; |
|
1700 |
_cursor.draw_pos.y = y; |
|
1701 |
_cursor.draw_size.y = h; |
|
1702 |
||
1130
2f1b7c54a12d
(svn r1631) A couple of fixes for the signed/unsigned warnings. Only train_cmd.c remains to need fixing...
dominik
parents:
1095
diff
changeset
|
1703 |
assert(w*h < (int) sizeof(_cursor_backup)); |
0 | 1704 |
|
1705 |
// Make backup of stuff below cursor |
|
1706 |
memcpy_pitch( |
|
1707 |
_cursor_backup, |
|
1708 |
_screen.dst_ptr + _cursor.draw_pos.x + _cursor.draw_pos.y * _screen.pitch, |
|
306
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
1709 |
_cursor.draw_size.x, _cursor.draw_size.y, _screen.pitch, _cursor.draw_size.x); |
0 | 1710 |
|
1711 |
// Draw cursor on screen |
|
1712 |
_cur_dpi = &_screen; |
|
1713 |
DrawSprite(_cursor.sprite, _cursor.pos.x, _cursor.pos.y); |
|
1714 |
||
1715 |
_video_driver->make_dirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y); |
|
1716 |
||
1717 |
_cursor.visible = true; |
|
1718 |
_cursor.dirty = false; |
|
1719 |
} |
|
1720 |
||
798 | 1721 |
#if defined(_DEBUG) |
410 | 1722 |
static void DbgScreenRect(int left, int top, int right, int bottom) |
0 | 1723 |
{ |
1724 |
DrawPixelInfo dp,*old; |
|
1725 |
||
1726 |
old = _cur_dpi; |
|
1727 |
_cur_dpi = &dp; |
|
1728 |
dp = _screen; |
|
1729 |
GfxFillRect(left, top, right-1, bottom-1, rand() & 255); |
|
1730 |
_cur_dpi = old; |
|
1731 |
} |
|
798 | 1732 |
#endif |
0 | 1733 |
|
1734 |
extern bool _dbg_screen_rect; |
|
1735 |
||
1736 |
void RedrawScreenRect(int left, int top, int right, int bottom) |
|
1737 |
{ |
|
1738 |
assert(right <= _screen.width && bottom <= _screen.height); |
|
1739 |
if (_cursor.visible) { |
|
1740 |
if (right > _cursor.draw_pos.x && |
|
1741 |
left < _cursor.draw_pos.x + _cursor.draw_size.x && |
|
1742 |
bottom > _cursor.draw_pos.y && |
|
1743 |
top < _cursor.draw_pos.y + _cursor.draw_size.y) { |
|
1744 |
UndrawMouseCursor(); |
|
1745 |
} |
|
1746 |
} |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1747 |
UndrawTextMessage(); |
0 | 1748 |
|
1749 |
#if defined(_DEBUG) |
|
1750 |
if (_dbg_screen_rect) |
|
1751 |
DbgScreenRect(left, top, right, bottom); |
|
1752 |
else |
|
1753 |
#endif |
|
1754 |
DrawOverlappedWindowForAll(left, top, right, bottom); |
|
1755 |
||
1756 |
_video_driver->make_dirty(left, top, right-left, bottom-top); |
|
1757 |
} |
|
1758 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1759 |
void DrawDirtyBlocks(void) |
0 | 1760 |
{ |
1761 |
byte *b = _dirty_blocks; |
|
1762 |
int x=0,y=0; |
|
306
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
1763 |
const int w = (_screen.width + 63) & ~63; |
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
1764 |
const int h = (_screen.height + 7) & ~7; |
0 | 1765 |
|
1766 |
do { |
|
1767 |
if (*b != 0) { |
|
1768 |
int left,top; |
|
1769 |
int right = x + 64; |
|
1770 |
int bottom = y; |
|
1771 |
byte *p = b; |
|
1772 |
int h2; |
|
1773 |
// First try coalescing downwards |
|
1774 |
do { |
|
1775 |
*p = 0; |
|
1776 |
p += DIRTY_BYTES_PER_LINE; |
|
1777 |
bottom += 8; |
|
1778 |
} while (bottom != h && *p); |
|
1779 |
||
1780 |
// Try coalescing to the right too. |
|
1781 |
h2 = (bottom - y) >> 3; |
|
1782 |
assert(h2>0); |
|
1783 |
p = b; |
|
1784 |
||
1785 |
while (right != w) { |
|
1786 |
byte *p2 = ++p; |
|
1787 |
int h = h2; |
|
1788 |
// Check if a full line of dirty flags is set. |
|
1789 |
do { |
|
1790 |
if (!*p2) goto no_more_coalesc; |
|
1791 |
p2 += DIRTY_BYTES_PER_LINE; |
|
1792 |
} while (--h); |
|
1793 |
||
1794 |
// Wohoo, can combine it one step to the right! |
|
1795 |
// Do that, and clear the bits. |
|
1796 |
right += 64; |
|
1797 |
||
1798 |
h = h2; |
|
1799 |
p2 = p; |
|
1800 |
do { |
|
1801 |
*p2 = 0; |
|
1802 |
p2 += DIRTY_BYTES_PER_LINE; |
|
1803 |
} while (--h); |
|
1804 |
} |
|
1805 |
no_more_coalesc:; |
|
1806 |
||
1807 |
left = x; |
|
1808 |
top = y; |
|
1809 |
||
1810 |
if (left < _invalid_rect.left)left = _invalid_rect.left; |
|
1811 |
if (top < _invalid_rect.top) top = _invalid_rect.top; |
|
1812 |
if (right > _invalid_rect.right)right = _invalid_rect.right; |
|
1813 |
if (bottom > _invalid_rect.bottom)bottom = _invalid_rect.bottom; |
|
1814 |
||
1815 |
if (left < right && top < bottom) { |
|
1816 |
RedrawScreenRect(left, top, right, bottom); |
|
1817 |
} |
|
1818 |
||
1819 |
} |
|
1820 |
} while (b++, (x+=64) != w || (x=0,b+=-(w>>6)+DIRTY_BYTES_PER_LINE,(y+=8) != h)); |
|
1821 |
||
1822 |
_invalid_rect.left = w; |
|
1823 |
_invalid_rect.top = h; |
|
1824 |
_invalid_rect.right = 0; |
|
1825 |
_invalid_rect.bottom = 0; |
|
1826 |
} |
|
1827 |
||
1828 |
||
1829 |
void SetDirtyBlocks(int left, int top, int right, int bottom) |
|
1830 |
{ |
|
1831 |
byte *b; |
|
1832 |
int width,height,i; |
|
1833 |
||
1834 |
if (left < 0) left = 0; |
|
1835 |
if (top < 0) top = 0; |
|
1836 |
if (right > _screen.width) right = _screen.width; |
|
1837 |
if (bottom > _screen.height) bottom = _screen.height; |
|
1838 |
||
1839 |
if (left >= right || top >= bottom) |
|
1840 |
return; |
|
1841 |
||
1842 |
if (left < _invalid_rect.left) _invalid_rect.left = left; |
|
1843 |
if (top < _invalid_rect.top) _invalid_rect.top = top; |
|
1844 |
if (right > _invalid_rect.right)_invalid_rect.right = right; |
|
1845 |
if (bottom > _invalid_rect.bottom)_invalid_rect.bottom = bottom; |
|
1846 |
||
1847 |
left >>= 6; |
|
1848 |
top >>= 3; |
|
1849 |
||
1850 |
b = _dirty_blocks + top * DIRTY_BYTES_PER_LINE + left; |
|
1851 |
||
1852 |
width = ((right-1) >> 6) - left + 1; |
|
1853 |
height = ((bottom-1) >> 3) - top + 1; |
|
1854 |
||
1855 |
assert(width > 0 && height > 0); |
|
1856 |
||
1857 |
do { |
|
1858 |
i=width; |
|
1859 |
do b[--i] = 0xFF; while (i); |
|
1860 |
||
1861 |
b += DIRTY_BYTES_PER_LINE; |
|
1862 |
} while (--height); |
|
1863 |
} |
|
1864 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1865 |
void MarkWholeScreenDirty(void) |
0 | 1866 |
{ |
1867 |
SetDirtyBlocks(0, 0, _screen.width, _screen.height); |
|
1868 |
} |
|
1869 |
||
1870 |
bool FillDrawPixelInfo(DrawPixelInfo *n, DrawPixelInfo *o, int left, int top, int width, int height) |
|
1871 |
{ |
|
1872 |
int t; |
|
1873 |
||
1874 |
if (o == NULL) |
|
1875 |
o = _cur_dpi; |
|
1876 |
||
1877 |
n->zoom = 0; |
|
1878 |
||
1879 |
assert(width > 0); |
|
1880 |
assert(height > 0); |
|
1881 |
||
1882 |
n->left = 0; |
|
1883 |
if ((left -= o->left) < 0) { |
|
1884 |
if ((width += left) < 0) |
|
1885 |
return false; |
|
1886 |
n->left = -left; |
|
1887 |
left = 0; |
|
1888 |
} |
|
1889 |
||
1890 |
if ((t=width + left - o->width) > 0) { |
|
1891 |
if ((width -= t) < 0) |
|
1892 |
return false; |
|
1893 |
} |
|
1894 |
n->width = width; |
|
1895 |
||
1896 |
n->top = 0; |
|
1897 |
if ((top -= o->top) < 0) { |
|
1898 |
if ((height += top) < 0) |
|
1899 |
return false; |
|
1900 |
n->top = -top; |
|
1901 |
top = 0; |
|
1902 |
} |
|
1903 |
||
1904 |
n->dst_ptr = o->dst_ptr + left + top * (n->pitch = o->pitch); |
|
1905 |
||
1906 |
if ((t=height + top - o->height) > 0) { |
|
1907 |
if ((height-=t) < 0) |
|
1908 |
return false; |
|
1909 |
} |
|
1910 |
n->height = height; |
|
1911 |
||
1912 |
||
1913 |
return true; |
|
1914 |
} |
|
1915 |
||
1916 |
static void SetCursorSprite(uint cursor) |
|
1917 |
{ |
|
1918 |
CursorVars *cv = &_cursor; |
|
1348 | 1919 |
const Sprite *p; |
0 | 1920 |
|
1921 |
if (cv->sprite == cursor) |
|
1922 |
return; |
|
1923 |
||
1350
fd0136012af1
(svn r1854) Split GetSpritePtr() into GetSprite() for regular sprites (returning a Sprite*) and GetNonSprite() for "sprites" of type 0xFF (returning byte*)
tron
parents:
1349
diff
changeset
|
1924 |
p = GetSprite(cursor & 0x3FFF); |
0 | 1925 |
cv->sprite = cursor; |
1348 | 1926 |
cv->size.y = p->height; |
1351
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1927 |
cv->size.x = p->width; |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1928 |
cv->offs.x = p->x_offs; |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1929 |
cv->offs.y = p->y_offs; |
0 | 1930 |
|
1931 |
cv->dirty = true; |
|
1932 |
} |
|
1933 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1934 |
static void SwitchAnimatedCursor(void) |
0 | 1935 |
{ |
1936 |
CursorVars *cv = &_cursor; |
|
1937 |
const uint16 *cur; |
|
1938 |
uint sprite; |
|
1939 |
||
1940 |
cur = cv->animate_cur; |
|
1941 |
if (cur == NULL || *cur == 0xFFFF) |
|
1942 |
cur = cv->animate_list; |
|
1943 |
sprite = cur[0]; |
|
1944 |
cv->animate_timeout = cur[1]; |
|
1945 |
cv->animate_cur = cur + 2; |
|
1946 |
||
1947 |
SetCursorSprite(sprite); |
|
1948 |
} |
|
1949 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1950 |
void CursorTick(void) |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1951 |
{ |
0 | 1952 |
CursorVars *cv = &_cursor; |
1953 |
if (cv->animate_timeout && !--cv->animate_timeout) |
|
1954 |
SwitchAnimatedCursor(); |
|
1955 |
} |
|
1956 |
||
1957 |
void SetMouseCursor(uint cursor) |
|
1958 |
{ |
|
1959 |
// Turn off animation |
|
1960 |
_cursor.animate_timeout = 0; |
|
1961 |
// Set cursor |
|
1962 |
SetCursorSprite(cursor); |
|
1963 |
} |
|
1964 |
||
1965 |
void SetAnimatedMouseCursor(const uint16 *table) |
|
1966 |
{ |
|
1967 |
_cursor.animate_list = table; |
|
1968 |
_cursor.animate_cur = NULL; |
|
1969 |
SwitchAnimatedCursor(); |
|
1970 |
} |
|
1971 |
||
1972 |
bool ChangeResInGame(int w, int h) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
1973 |
{ |
0 | 1974 |
if ((_screen.width != w || _screen.height != h) && !_video_driver->change_resolution(w, h)) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
1975 |
return false; |
0 | 1976 |
|
1977 |
_cur_resolution[0] = w; |
|
1978 |
_cur_resolution[1] = h; |
|
1979 |
return true; |
|
1980 |
} |
|
298
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1981 |
|
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1982 |
void ToggleFullScreen(const bool full_screen) |
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1983 |
{ |
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1984 |
_fullscreen = full_screen; |
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1985 |
/* use preset resolutions, not _screen.height and _screen.width. On windows for example |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1986 |
if Desktop-size is 1280x1024, and gamesize is also 1280x1024, _screen.height will be |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1987 |
only 1000 because of possible start-bar. For this reason you cannot switch to |
298
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1988 |
fullscreen mode from this resolution. Use of preset resolution will fix this */ |
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1989 |
if (!_video_driver->change_resolution(_cur_resolution[0], _cur_resolution[1])) |
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1990 |
_fullscreen ^= true; // switching resolution failed, put back full_screen to original status |
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1991 |
} |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1992 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1993 |
uint16 GetDrawStringPlayerColor(byte player) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1994 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1995 |
// Get the color for DrawString-subroutines which matches the color |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1996 |
// of the player |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1997 |
if (player == OWNER_SPECTATOR || player == OWNER_SPECTATOR - 1) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1998 |
return 1; |
657
d4d36b4853ec
(svn r1091) Fix: Finally station names use 100% the correct color in transparent mode
dominik
parents:
619
diff
changeset
|
1999 |
return (_color_list[_player_colors[player]].window_color_1b) | IS_PALETTE_COLOR; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
2000 |
} |