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