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