author | tron |
Sun, 03 Jul 2005 10:22:20 +0000 | |
changeset 2004 | 6b975f28c351 |
parent 1997 | 91085465f12b |
child 2005 | 8331cf472aea |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1829
diff
changeset
|
2 |
#include "openttd.h" |
1349
07514c2cc6d1
(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
dab90d4cbf2d
(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
f3d5e35731a2
(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]; |
f3d5e35731a2
(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
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
23 |
|
e3b43338096b
(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
ff3cfd9042a3
(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
ff3cfd9042a3
(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
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
48 |
UndrawTextMessage(); |
0 | 49 |
|
50 |
p = _screen.pitch; |
|
51 |
||
375
6a1e279049d2
(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
6a1e279049d2
(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
6a1e279049d2
(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
6a1e279049d2
(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
6a1e279049d2
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
72 |
for (ht = height; ht > 0; --ht) { |
6a1e279049d2
(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
6a1e279049d2
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
76 |
} |
0 | 77 |
} else { |
375
6a1e279049d2
(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
6a1e279049d2
(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, |
6a1e279049d2
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
97 |
// because source and destination may overlap |
6a1e279049d2
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
98 |
for (ht = height; ht > 0; --ht) { |
6a1e279049d2
(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
6a1e279049d2
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
102 |
} |
0 | 103 |
} |
375
6a1e279049d2
(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. |
6a1e279049d2
(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
e3b43338096b
(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
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
263 |
char buffer[512]; |
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
264 |
|
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
265 |
GetString(buffer, str); |
c9e6b766bf21
(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
e3b43338096b
(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
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
272 |
char buffer[512]; |
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
273 |
|
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
274 |
GetString(buffer, str); |
c9e6b766bf21
(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
e3b43338096b
(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
c9e6b766bf21
(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
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
284 |
GetString(buffer, str); |
0 | 285 |
|
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
286 |
w = GetStringWidth(buffer); |
c9e6b766bf21
(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
e3b43338096b
(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
41397685320a
(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
41397685320a
(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
53a5713cf3f9
(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
53a5713cf3f9
(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
c9e6b766bf21
(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
41397685320a
(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
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
347 |
GetString(buffer, str); |
0 | 348 |
|
1336
c9e6b766bf21
(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
c9e6b766bf21
(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
c9e6b766bf21
(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
41397685320a
(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
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
393 |
GetString(buffer, str); |
0 | 394 |
|
1336
c9e6b766bf21
(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
c9e6b766bf21
(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
41397685320a
(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) |
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
430 |
{ |
1390
53a5713cf3f9
(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
53a5713cf3f9
(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
53a5713cf3f9
(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
53a5713cf3f9
(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
41397685320a
(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) |
41397685320a
(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
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
|
484 |
byte c; |
543
e3b43338096b
(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
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
488 |
color = real_color & 0xFF; |
e3b43338096b
(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
40a9032b454b
(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
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
500 |
_string_colorremap[1] = color; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
501 |
_string_colorremap[2] = 215; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
502 |
} else { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
503 |
_string_colorremap[1] = _string_colormap[color].text; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
504 |
_string_colorremap[2] = _string_colormap[color].shadow; |
e3b43338096b
(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
067b22970f19
(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
53a5713cf3f9
(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
41397685320a
(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
41397685320a
(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++; |
41397685320a
(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
067b22970f19
(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; |
067b22970f19
(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
067b22970f19
(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; |
067b22970f19
(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
067b22970f19
(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; |
|
2004 | 768 |
|
769 |
for (; n >= 4; n -= 4) { |
|
1996 | 770 |
if (src[0] != 0) dst[0] = src[0]; |
771 |
if (src[1] != 0) dst[1] = src[1]; |
|
772 |
if (src[2] != 0) dst[2] = src[2]; |
|
773 |
if (src[3] != 0) dst[3] = src[3]; |
|
0 | 774 |
|
775 |
dst += 4; |
|
776 |
src += 4; |
|
777 |
} |
|
778 |
||
2004 | 779 |
for (; n != 0; n--) { |
1996 | 780 |
if (src[0] != 0) dst[0] = src[0]; |
0 | 781 |
src++; |
782 |
dst++; |
|
783 |
} |
|
784 |
||
785 |
src += bp->width_org - width; |
|
786 |
dst += bp->pitch - width; |
|
787 |
} while (--height); |
|
788 |
} |
|
789 |
} |
|
790 |
} |
|
791 |
||
792 |
static void GfxBlitTileZoomMedium(BlitterParams *bp) |
|
793 |
{ |
|
1357 | 794 |
const byte* src_o = bp->sprite; |
795 |
const byte* src; |
|
0 | 796 |
int num, skip; |
797 |
byte done; |
|
1357 | 798 |
byte *dst; |
799 |
const byte* ctab; |
|
0 | 800 |
|
801 |
if (bp->mode & 1) { |
|
802 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
803 |
do { |
|
804 |
do { |
|
805 |
done = src_o[0]; |
|
806 |
num = done & 0x7F; |
|
807 |
skip = src_o[1]; |
|
808 |
src = src_o + 2; |
|
809 |
src_o += num + 2; |
|
810 |
||
811 |
dst = bp->dst; |
|
812 |
||
813 |
if (skip & 1) { |
|
814 |
skip++; |
|
815 |
src++; |
|
2004 | 816 |
if (--num == 0) continue; |
0 | 817 |
} |
818 |
||
819 |
if ( (skip -= bp->start_x) > 0) { |
|
820 |
dst += skip >> 1; |
|
821 |
} else { |
|
822 |
src -= skip; |
|
823 |
num += skip; |
|
824 |
if (num <= 0) |
|
825 |
continue; |
|
826 |
skip = 0; |
|
827 |
} |
|
828 |
||
829 |
skip = skip + num - bp->width; |
|
830 |
if (skip > 0) { |
|
831 |
num -= skip; |
|
832 |
if (num <= 0) |
|
833 |
continue; |
|
834 |
} |
|
835 |
||
836 |
ctab = _color_remap_ptr; |
|
837 |
num = (num + 1) >> 1; |
|
1997 | 838 |
for (; num != 0; num--) { |
0 | 839 |
*dst = ctab[*src]; |
840 |
dst++; |
|
1997 | 841 |
src += 2; |
0 | 842 |
} |
843 |
} while (!(done & 0x80)); |
|
844 |
bp->dst += bp->pitch; |
|
2004 | 845 |
if (--bp->height == 0) return; |
0 | 846 |
|
847 |
do { |
|
848 |
done = src_o[0]; |
|
849 |
src_o += (done & 0x7F) + 2; |
|
850 |
} while (!(done & 0x80)); |
|
851 |
} while (--bp->height); |
|
852 |
} else if (bp->mode & 2) { |
|
853 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
854 |
do { |
|
855 |
do { |
|
856 |
done = src_o[0]; |
|
857 |
num = done & 0x7F; |
|
858 |
skip = src_o[1]; |
|
859 |
src_o += num + 2; |
|
860 |
||
861 |
dst = bp->dst; |
|
862 |
||
863 |
if (skip & 1) { |
|
864 |
skip++; |
|
2004 | 865 |
if (--num == 0) continue; |
0 | 866 |
} |
867 |
||
868 |
if ( (skip -= bp->start_x) > 0) { |
|
869 |
dst += skip >> 1; |
|
870 |
} else { |
|
871 |
num += skip; |
|
872 |
if (num <= 0) |
|
873 |
continue; |
|
874 |
skip = 0; |
|
875 |
} |
|
876 |
||
877 |
skip = skip + num - bp->width; |
|
878 |
if (skip > 0) { |
|
879 |
num -= skip; |
|
880 |
if (num <= 0) |
|
881 |
continue; |
|
882 |
} |
|
883 |
||
884 |
ctab = _color_remap_ptr; |
|
885 |
num = (num + 1) >> 1; |
|
1997 | 886 |
for (; num != 0; num--) { |
0 | 887 |
*dst = ctab[*dst]; |
888 |
dst++; |
|
889 |
} |
|
890 |
} while (!(done & 0x80)); |
|
891 |
bp->dst += bp->pitch; |
|
2004 | 892 |
if (--bp->height == 0) return; |
0 | 893 |
|
894 |
do { |
|
895 |
done = src_o[0]; |
|
896 |
src_o += (done & 0x7F) + 2; |
|
897 |
} while (!(done & 0x80)); |
|
898 |
} while (--bp->height); |
|
899 |
||
900 |
} else { |
|
901 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
902 |
do { |
|
903 |
do { |
|
904 |
done = src_o[0]; |
|
905 |
num = done & 0x7F; |
|
906 |
skip = src_o[1]; |
|
907 |
src = src_o + 2; |
|
908 |
src_o += num + 2; |
|
909 |
||
910 |
dst = bp->dst; |
|
911 |
||
912 |
if (skip & 1) { |
|
913 |
skip++; |
|
914 |
src++; |
|
2004 | 915 |
if (--num == 0) continue; |
0 | 916 |
} |
917 |
||
918 |
if ( (skip -= bp->start_x) > 0) { |
|
919 |
dst += skip >> 1; |
|
920 |
} else { |
|
921 |
src -= skip; |
|
922 |
num += skip; |
|
923 |
if (num <= 0) |
|
924 |
continue; |
|
925 |
skip = 0; |
|
926 |
} |
|
927 |
||
928 |
skip = skip + num - bp->width; |
|
929 |
if (skip > 0) { |
|
930 |
num -= skip; |
|
931 |
if (num <= 0) |
|
932 |
continue; |
|
933 |
} |
|
934 |
||
935 |
num = (num + 1) >> 1; |
|
936 |
||
1997 | 937 |
for (; num != 0; num--) { |
0 | 938 |
*dst = *src; |
939 |
dst++; |
|
1997 | 940 |
src += 2; |
0 | 941 |
} |
942 |
||
943 |
} while (!(done & 0x80)); |
|
944 |
||
945 |
bp->dst += bp->pitch; |
|
2004 | 946 |
if (--bp->height == 0) return; |
0 | 947 |
|
948 |
do { |
|
949 |
done = src_o[0]; |
|
950 |
src_o += (done & 0x7F) + 2; |
|
951 |
} while (!(done & 0x80)); |
|
952 |
||
953 |
} while (--bp->height); |
|
954 |
} |
|
955 |
} |
|
956 |
||
957 |
static void GfxBlitZoomMediumUncomp(BlitterParams *bp) |
|
958 |
{ |
|
1357 | 959 |
const byte *src = bp->sprite; |
0 | 960 |
byte *dst = bp->dst; |
961 |
int height = bp->height; |
|
962 |
int width = bp->width; |
|
963 |
int i; |
|
964 |
||
965 |
assert(height > 0); |
|
966 |
assert(width > 0); |
|
967 |
||
968 |
if (bp->mode & 1) { |
|
969 |
if (bp->info & 1) { |
|
1357 | 970 |
const byte *ctab = _color_remap_ptr; |
971 |
||
1996 | 972 |
for (height >>= 1; height != 0; height--) { |
973 |
for (i = 0; i != width >> 1; i++) { |
|
974 |
byte b = ctab[src[i * 2]]; |
|
975 |
||
976 |
if (b != 0) dst[i] = b; |
|
977 |
} |
|
0 | 978 |
src += bp->width_org * 2; |
979 |
dst += bp->pitch; |
|
1996 | 980 |
} |
0 | 981 |
} |
982 |
} else if (bp->mode & 2) { |
|
983 |
if (bp->info & 1) { |
|
1357 | 984 |
const byte *ctab = _color_remap_ptr; |
985 |
||
1996 | 986 |
for (height >>= 1; height != 0; height--) { |
987 |
for (i = 0; i != width >> 1; i++) |
|
988 |
if (src[i * 2] != 0) dst[i] = ctab[dst[i]]; |
|
0 | 989 |
src += bp->width_org * 2; |
990 |
dst += bp->pitch; |
|
1996 | 991 |
} |
0 | 992 |
} |
993 |
} else { |
|
994 |
if (bp->info & 1) { |
|
1996 | 995 |
for (height >>= 1; height != 0; height--) { |
996 |
for (i = 0; i != width >> 1; i++) |
|
997 |
if (src[i * 2] != 0) dst[i] = src[i * 2]; |
|
0 | 998 |
src += bp->width_org * 2; |
999 |
dst += bp->pitch; |
|
1996 | 1000 |
} |
0 | 1001 |
} |
1002 |
} |
|
1003 |
} |
|
1004 |
||
1005 |
static void GfxBlitTileZoomOut(BlitterParams *bp) |
|
1006 |
{ |
|
1357 | 1007 |
const byte* src_o = bp->sprite; |
1008 |
const byte* src; |
|
0 | 1009 |
int num, skip; |
1010 |
byte done; |
|
1357 | 1011 |
byte *dst; |
1012 |
const byte* ctab; |
|
0 | 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++; |
|
2004 | 1029 |
if (--num == 0) continue; |
0 | 1030 |
} |
1031 |
||
1032 |
if (skip & 2) { |
|
2004 | 1033 |
skip += 2; |
1034 |
src += 2; |
|
1035 |
num -= 2; |
|
1036 |
if (num <= 0) continue; |
|
0 | 1037 |
} |
1038 |
||
1039 |
if ( (skip -= bp->start_x) > 0) { |
|
1040 |
dst += skip >> 2; |
|
1041 |
} else { |
|
1042 |
src -= skip; |
|
1043 |
num += skip; |
|
2004 | 1044 |
if (num <= 0) continue; |
0 | 1045 |
skip = 0; |
1046 |
} |
|
1047 |
||
1048 |
skip = skip + num - bp->width; |
|
1049 |
if (skip > 0) { |
|
1050 |
num -= skip; |
|
2004 | 1051 |
if (num <= 0) continue; |
0 | 1052 |
} |
1053 |
||
1054 |
ctab = _color_remap_ptr; |
|
1055 |
num = (num + 3) >> 2; |
|
1997 | 1056 |
for (; num != 0; num--) { |
0 | 1057 |
*dst = ctab[*src]; |
1058 |
dst++; |
|
1997 | 1059 |
src += 4; |
0 | 1060 |
} |
1061 |
} while (!(done & 0x80)); |
|
1062 |
bp->dst += bp->pitch; |
|
2004 | 1063 |
if (--bp->height == 0) return; |
0 | 1064 |
|
1065 |
do { |
|
1066 |
done = src_o[0]; |
|
1067 |
src_o += (done & 0x7F) + 2; |
|
1068 |
} while (!(done & 0x80)); |
|
2004 | 1069 |
if (--bp->height == 0) return; |
0 | 1070 |
|
1071 |
do { |
|
1072 |
done = src_o[0]; |
|
1073 |
src_o += (done & 0x7F) + 2; |
|
1074 |
} while (!(done & 0x80)); |
|
2004 | 1075 |
if (--bp->height == 0) return; |
0 | 1076 |
|
1077 |
do { |
|
1078 |
done = src_o[0]; |
|
1079 |
src_o += (done & 0x7F) + 2; |
|
1080 |
} while (!(done & 0x80)); |
|
2004 | 1081 |
if (--bp->height == 0) return; |
0 | 1082 |
} |
1083 |
} else if (bp->mode & 2) { |
|
1084 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
1085 |
for(;;) { |
|
1086 |
do { |
|
1087 |
done = src_o[0]; |
|
1088 |
num = done & 0x7F; |
|
1089 |
skip = src_o[1]; |
|
1090 |
src_o += num + 2; |
|
1091 |
||
1092 |
dst = bp->dst; |
|
1093 |
||
1094 |
if (skip & 1) { |
|
1095 |
skip++; |
|
2004 | 1096 |
if (--num == 0) continue; |
0 | 1097 |
} |
1098 |
||
1099 |
if (skip & 2) { |
|
2004 | 1100 |
skip += 2; |
1101 |
num -= 2; |
|
1102 |
if (num <= 0) continue; |
|
0 | 1103 |
} |
1104 |
||
1105 |
if ( (skip -= bp->start_x) > 0) { |
|
1106 |
dst += skip >> 2; |
|
1107 |
} else { |
|
1108 |
num += skip; |
|
2004 | 1109 |
if (num <= 0) continue; |
0 | 1110 |
skip = 0; |
1111 |
} |
|
1112 |
||
1113 |
skip = skip + num - bp->width; |
|
1114 |
if (skip > 0) { |
|
1115 |
num -= skip; |
|
2004 | 1116 |
if (num <= 0) continue; |
0 | 1117 |
} |
1118 |
||
1119 |
ctab = _color_remap_ptr; |
|
1120 |
num = (num + 3) >> 2; |
|
1997 | 1121 |
for (; num != 0; num--) { |
0 | 1122 |
*dst = ctab[*dst]; |
1123 |
dst++; |
|
1124 |
} |
|
1125 |
||
1126 |
} while (!(done & 0x80)); |
|
1127 |
bp->dst += bp->pitch; |
|
2004 | 1128 |
if (--bp->height == 0) return; |
0 | 1129 |
|
1130 |
do { |
|
1131 |
done = src_o[0]; |
|
1132 |
src_o += (done & 0x7F) + 2; |
|
1133 |
} while (!(done & 0x80)); |
|
2004 | 1134 |
if (--bp->height == 0) return; |
0 | 1135 |
|
1136 |
do { |
|
1137 |
done = src_o[0]; |
|
1138 |
src_o += (done & 0x7F) + 2; |
|
1139 |
} while (!(done & 0x80)); |
|
2004 | 1140 |
if (--bp->height == 0) return; |
0 | 1141 |
|
1142 |
do { |
|
1143 |
done = src_o[0]; |
|
1144 |
src_o += (done & 0x7F) + 2; |
|
1145 |
} while (!(done & 0x80)); |
|
2004 | 1146 |
if (--bp->height == 0) return; |
0 | 1147 |
} |
1148 |
} else { |
|
1149 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
1150 |
for(;;) { |
|
1151 |
do { |
|
1152 |
done = src_o[0]; |
|
1153 |
num = done & 0x7F; |
|
1154 |
skip = src_o[1]; |
|
1155 |
src = src_o + 2; |
|
1156 |
src_o += num + 2; |
|
1157 |
||
1158 |
dst = bp->dst; |
|
1159 |
||
1160 |
if (skip & 1) { |
|
1161 |
skip++; |
|
1162 |
src++; |
|
2004 | 1163 |
if (--num == 0) continue; |
0 | 1164 |
} |
1165 |
||
1166 |
if (skip & 2) { |
|
2004 | 1167 |
skip += 2; |
1168 |
src += 2; |
|
1169 |
num -= 2; |
|
1170 |
if (num <= 0) continue; |
|
0 | 1171 |
} |
1172 |
||
1173 |
if ( (skip -= bp->start_x) > 0) { |
|
1174 |
dst += skip >> 2; |
|
1175 |
} else { |
|
1176 |
src -= skip; |
|
1177 |
num += skip; |
|
2004 | 1178 |
if (num <= 0) continue; |
0 | 1179 |
skip = 0; |
1180 |
} |
|
1181 |
||
1182 |
skip = skip + num - bp->width; |
|
1183 |
if (skip > 0) { |
|
1184 |
num -= skip; |
|
2004 | 1185 |
if (num <= 0) continue; |
0 | 1186 |
} |
1187 |
||
1188 |
num = (num + 3) >> 2; |
|
1189 |
||
1997 | 1190 |
for (; num != 0; num--) { |
0 | 1191 |
*dst = *src; |
1192 |
dst++; |
|
1997 | 1193 |
src += 4; |
0 | 1194 |
} |
1195 |
} while (!(done & 0x80)); |
|
1196 |
||
1197 |
bp->dst += bp->pitch; |
|
2004 | 1198 |
if (--bp->height == 0) return; |
0 | 1199 |
|
1200 |
do { |
|
1201 |
done = src_o[0]; |
|
1202 |
src_o += (done & 0x7F) + 2; |
|
1203 |
} while (!(done & 0x80)); |
|
2004 | 1204 |
if (--bp->height == 0) return; |
0 | 1205 |
|
1206 |
do { |
|
1207 |
done = src_o[0]; |
|
1208 |
src_o += (done & 0x7F) + 2; |
|
1209 |
} while (!(done & 0x80)); |
|
2004 | 1210 |
if (--bp->height == 0) return; |
0 | 1211 |
|
1212 |
do { |
|
1213 |
done = src_o[0]; |
|
1214 |
src_o += (done & 0x7F) + 2; |
|
1215 |
} while (!(done & 0x80)); |
|
2004 | 1216 |
if (--bp->height == 0) return; |
0 | 1217 |
} |
1218 |
} |
|
1219 |
} |
|
1220 |
||
1221 |
static void GfxBlitZoomOutUncomp(BlitterParams *bp) |
|
1222 |
{ |
|
1357 | 1223 |
const byte* src = bp->sprite; |
0 | 1224 |
byte *dst = bp->dst; |
1225 |
int height = bp->height; |
|
1226 |
int width = bp->width; |
|
1227 |
int i; |
|
1228 |
||
1229 |
assert(height > 0); |
|
1230 |
assert(width > 0); |
|
1231 |
||
1232 |
if (bp->mode & 1) { |
|
1233 |
if (bp->info & 1) { |
|
1357 | 1234 |
const byte *ctab = _color_remap_ptr; |
1235 |
||
1996 | 1236 |
for (height >>= 2; height != 0; height--) { |
1237 |
for (i = 0; i != width >> 2; i++) { |
|
1238 |
byte b = ctab[src[i * 4]]; |
|
1239 |
||
1240 |
if (b != 0) dst[i] = b; |
|
1241 |
} |
|
0 | 1242 |
src += bp->width_org * 4; |
1243 |
dst += bp->pitch; |
|
1996 | 1244 |
} |
0 | 1245 |
} |
1246 |
} else if (bp->mode & 2) { |
|
1247 |
if (bp->info & 1) { |
|
1357 | 1248 |
const byte *ctab = _color_remap_ptr; |
1249 |
||
1996 | 1250 |
for (height >>= 2; height != 0; height--) { |
1251 |
for (i = 0; i != width >> 2; i++) |
|
1252 |
if (src[i * 4] != 0) dst[i] = ctab[dst[i]]; |
|
0 | 1253 |
src += bp->width_org * 4; |
1254 |
dst += bp->pitch; |
|
1996 | 1255 |
} |
0 | 1256 |
} |
1257 |
} else { |
|
1258 |
if (bp->info & 1) { |
|
1996 | 1259 |
for (height >>= 2; height != 0; height--) { |
1260 |
for (i = 0; i != width >> 2; i++) |
|
1261 |
if (src[i * 4] != 0) dst[i] = src[i * 4]; |
|
0 | 1262 |
src += bp->width_org * 4; |
1263 |
dst += bp->pitch; |
|
1996 | 1264 |
} |
0 | 1265 |
} |
1266 |
} |
|
1267 |
} |
|
1268 |
||
1269 |
typedef void (*BlitZoomFunc)(BlitterParams *bp); |
|
1270 |
||
1357 | 1271 |
static void GfxMainBlitter(const Sprite* sprite, int x, int y, int mode) |
0 | 1272 |
{ |
1273 |
DrawPixelInfo *dpi = _cur_dpi; |
|
1274 |
int start_x, start_y; |
|
1275 |
byte info; |
|
1276 |
BlitterParams bp; |
|
1277 |
int zoom_mask = ~((1 << (dpi->zoom))-1); |
|
1278 |
||
1279 |
static const BlitZoomFunc zf_tile[3] = |
|
1280 |
{ |
|
1281 |
GfxBlitTileZoomIn, |
|
1282 |
GfxBlitTileZoomMedium, |
|
1283 |
GfxBlitTileZoomOut |
|
1284 |
}; |
|
1285 |
static const BlitZoomFunc zf_uncomp[3] = |
|
1286 |
{ |
|
1287 |
GfxBlitZoomInUncomp, |
|
1288 |
GfxBlitZoomMediumUncomp, |
|
1289 |
GfxBlitZoomOutUncomp |
|
1290 |
}; |
|
1291 |
||
1292 |
/* decode sprite header */ |
|
1351
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1293 |
x += sprite->x_offs; |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1294 |
y += sprite->y_offs; |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1295 |
bp.width_org = bp.width = sprite->width; |
1348 | 1296 |
bp.height_org = bp.height = sprite->height; |
1297 |
info = sprite->info; |
|
0 | 1298 |
bp.info = info; |
1348 | 1299 |
bp.sprite_org = bp.sprite = sprite->data; |
0 | 1300 |
bp.dst = dpi->dst_ptr; |
1301 |
bp.mode = mode; |
|
1302 |
bp.pitch = dpi->pitch; |
|
1303 |
||
1304 |
assert(bp.height > 0); |
|
1305 |
assert(bp.width > 0); |
|
1306 |
||
1307 |
if (info & 8) { |
|
1308 |
/* tile blit */ |
|
1309 |
start_y = 0; |
|
1310 |
||
1311 |
if (dpi->zoom > 0) { |
|
1312 |
start_y += bp.height &~ zoom_mask; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
1313 |
bp.height &= zoom_mask; |
0 | 1314 |
if (bp.height == 0) return; |
1315 |
y&=zoom_mask; |
|
1316 |
} |
|
1317 |
||
1318 |
if ( (y -= dpi->top) < 0) { |
|
1319 |
if ((bp.height += y) <= 0) |
|
1320 |
return; |
|
1321 |
start_y -= y; |
|
1322 |
y = 0; |
|
1323 |
} else { |
|
1324 |
bp.dst += bp.pitch * (y>>(dpi->zoom)); |
|
1325 |
} |
|
1326 |
bp.start_y = start_y; |
|
1327 |
||
1328 |
if ( (y = y + bp.height - dpi->height) > 0) { |
|
1329 |
if ( (bp.height -= y) <= 0) |
|
1330 |
return; |
|
1331 |
} |
|
1332 |
||
1333 |
start_x = 0; |
|
1334 |
x &= zoom_mask; |
|
1335 |
if ( (x -= dpi->left) < 0) { |
|
1336 |
if ((bp.width += x) <= 0) |
|
1337 |
return; |
|
1338 |
start_x -= x; |
|
1339 |
x = 0; |
|
1340 |
} |
|
1341 |
bp.start_x = start_x; |
|
1342 |
bp.dst += x>>(dpi->zoom); |
|
1343 |
||
1344 |
if ( (x = x + bp.width - dpi->width) > 0) { |
|
1345 |
if ( (bp.width -= x) <= 0) |
|
1346 |
return; |
|
1347 |
} |
|
1348 |
||
1349 |
zf_tile[dpi->zoom](&bp); |
|
1350 |
} else { |
|
1351 |
||
1352 |
bp.sprite += bp.width * (bp.height & ~zoom_mask); |
|
1353 |
bp.height &= zoom_mask; |
|
1354 |
if (bp.height == 0) |
|
1355 |
return; |
|
1356 |
||
1357 |
y &= zoom_mask; |
|
1358 |
||
1359 |
if ( (y -= dpi->top) < 0) { |
|
1360 |
if ((bp.height += y) <= 0) |
|
1361 |
return; |
|
1362 |
bp.sprite -= bp.width * y; |
|
1363 |
y = 0; |
|
1364 |
} else { |
|
1365 |
bp.dst += bp.pitch * (y>>(dpi->zoom)); |
|
1366 |
} |
|
1367 |
||
1368 |
if ( (y = y + bp.height - dpi->height) > 0) { |
|
1369 |
if ( (bp.height -= y) <= 0) |
|
1370 |
return; |
|
1371 |
} |
|
1372 |
||
1373 |
start_x = 0; |
|
1374 |
||
1375 |
x &= zoom_mask; |
|
1376 |
||
1377 |
if ( (x -= dpi->left) < 0) { |
|
1378 |
if ((bp.width += x) <= 0) |
|
1379 |
return; |
|
1380 |
start_x -= x; |
|
1381 |
bp.sprite -= x; |
|
1382 |
x = 0; |
|
1383 |
} |
|
1384 |
bp.dst += x>>(dpi->zoom); |
|
1385 |
||
1386 |
if ( (x = x + bp.width - dpi->width) > 0) { |
|
1387 |
if ( (bp.width -= x) <= 0) |
|
1388 |
return; |
|
1389 |
start_x += x; |
|
1390 |
} |
|
1391 |
bp.start_x = start_x; |
|
1392 |
||
1393 |
if (info&2) { |
|
1394 |
int totpix = bp.height_org * bp.width_org; |
|
1395 |
byte *dst = (byte*)alloca(totpix); |
|
1357 | 1396 |
const byte *src = bp.sprite_org; |
0 | 1397 |
|
461
9129fe36ef0d
(svn r679) Clarify bp.sprite assignment in GfxMainBlitter(). Pointed out by Oskar.
pasky
parents:
410
diff
changeset
|
1398 |
bp.sprite = dst + (bp.sprite - bp.sprite_org); |
0 | 1399 |
|
1400 |
while (totpix != 0) { |
|
2004 | 1401 |
signed char b; |
1402 |
||
0 | 1403 |
assert(totpix > 0); |
2004 | 1404 |
|
0 | 1405 |
b = *src++; |
1406 |
if (b >= 0) { |
|
2004 | 1407 |
uint count = b; |
1408 |
uint i; |
|
1409 |
||
1410 |
for (i = 0; i != count; i++) dst[i] = src[i]; |
|
0 | 1411 |
dst += count; |
1412 |
src += count; |
|
1413 |
totpix -= count; |
|
1414 |
} else { |
|
2004 | 1415 |
const byte *tmp = dst - (((b & 7) << 8) | *src++); |
1416 |
uint count = -(b >> 3); |
|
1417 |
uint i; |
|
0 | 1418 |
|
2004 | 1419 |
for (i = 0; i != count; i++) dst[i] = tmp[i]; |
0 | 1420 |
dst += count; |
1421 |
totpix -= count; |
|
1422 |
} |
|
1423 |
} |
|
1424 |
} |
|
1425 |
zf_uncomp[dpi->zoom](&bp); |
|
1426 |
} |
|
1427 |
} |
|
1428 |
||
798 | 1429 |
#if 0 |
410 | 1430 |
static void GfxScalePalette(int pal, byte scaling) |
0 | 1431 |
{ |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1432 |
const Colour* src; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1433 |
uint i; |
0 | 1434 |
|
1435 |
GfxInitPalettes(); |
|
1436 |
||
1437 |
src = GET_PALETTE(pal); |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1438 |
for (i = 0; i < lengthof(_cur_palette); i++) { |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1439 |
_cur_palette[i].r = src[i].r * scaling >> 8; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1440 |
_cur_palette[i].g = src[i].g * scaling >> 8; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1441 |
_cur_palette[i].b = src[i].b * scaling >> 8; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1442 |
} |
0 | 1443 |
} |
798 | 1444 |
#endif |
0 | 1445 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1446 |
void DoPaletteAnimations(void); |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1447 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1448 |
void GfxInitPalettes(void) |
0 | 1449 |
{ |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1450 |
memcpy(_cur_palette, _palettes[_use_dos_palette ? 1 : 0], sizeof(_cur_palette)); |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1451 |
|
0 | 1452 |
_pal_first_dirty = 0; |
1453 |
_pal_last_dirty = 255; |
|
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1454 |
DoPaletteAnimations(); |
0 | 1455 |
} |
1456 |
||
1457 |
#define EXTR(p,q) (((uint16)(_timer_counter * (p)) * (q)) >> 16) |
|
1458 |
#define EXTR2(p,q) (((uint16)(~_timer_counter * (p)) * (q)) >> 16) |
|
1459 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1460 |
void DoPaletteAnimations(void) |
0 | 1461 |
{ |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1462 |
const Colour* s; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1463 |
Colour* d; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1464 |
/* Amount of colors to be rotated. |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1465 |
* A few more for the DOS palette, because the water colors are |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1466 |
* 245-254 for DOS and 217-226 for Windows. */ |
915 | 1467 |
int c = _use_dos_palette?38:28; |
0 | 1468 |
int j; |
1469 |
int i; |
|
1470 |
const ExtraPaletteValues *ev = &_extra_palette_values; |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1471 |
Colour old_val[38]; // max(38, 28) |
0 | 1472 |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1473 |
d = &_cur_palette[217]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1474 |
memcpy(old_val, d, c * sizeof(*old_val)); |
0 | 1475 |
|
1476 |
// Dark blue water |
|
1477 |
s = ev->a; |
|
1478 |
if (_opt.landscape == LT_CANDY) s = ev->ac; |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1479 |
j = EXTR(320,5); |
0 | 1480 |
for(i=0; i!=5; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1481 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1482 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1483 |
if (j == 5) j = 0; |
0 | 1484 |
} |
1485 |
||
1486 |
// Glittery water |
|
1487 |
s = ev->b; |
|
1488 |
if (_opt.landscape == LT_CANDY) s = ev->bc; |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1489 |
j = EXTR(128, 15); |
0 | 1490 |
for(i=0; i!=5; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1491 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1492 |
j += 3; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1493 |
if (j >= 15) j -= 15; |
0 | 1494 |
} |
1495 |
||
1496 |
s = ev->e; |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1497 |
j = EXTR2(512, 5); |
0 | 1498 |
for(i=0; i!=5; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1499 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1500 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1501 |
if (j == 5) j = 0; |
0 | 1502 |
} |
1503 |
||
1504 |
// Oil refinery fire animation |
|
1505 |
s = ev->oil_ref; |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1506 |
j = EXTR2(512, 7); |
0 | 1507 |
for(i=0; i!=7; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1508 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1509 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1510 |
if (j == 7) j = 0; |
0 | 1511 |
} |
1512 |
||
1513 |
// Radio tower blinking |
|
1514 |
{ |
|
1515 |
byte i,v; |
|
1516 |
i = (_timer_counter >> 1) & 0x7F; |
|
1517 |
(v = 255, i < 0x3f) || |
|
1518 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
1519 |
(v = 20); |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1520 |
d->r = v; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1521 |
d->g = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1522 |
d->b = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1523 |
d++; |
0 | 1524 |
|
1525 |
i ^= 0x40; |
|
1526 |
(v = 255, i < 0x3f) || |
|
1527 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
1528 |
(v = 20); |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1529 |
d->r = v; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1530 |
d->g = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1531 |
d->b = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1532 |
d++; |
0 | 1533 |
} |
1534 |
||
1535 |
// Handle lighthouse and stadium animation |
|
1536 |
s = ev->lighthouse; |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1537 |
j = EXTR(256, 4); |
0 | 1538 |
for(i=0; i!=4; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1539 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1540 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1541 |
if (j == 4) j = 0; |
0 | 1542 |
} |
1543 |
||
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1544 |
// Animate water for old DOS graphics |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1545 |
if(_use_dos_palette) { |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1546 |
// Dark blue water DOS |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1547 |
s = ev->a; |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1548 |
if (_opt.landscape == LT_CANDY) s = ev->ac; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1549 |
j = EXTR(320,5); |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1550 |
for(i=0; i!=5; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1551 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1552 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1553 |
if (j == 5) j = 0; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1554 |
} |
915 | 1555 |
|
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1556 |
// Glittery water DOS |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1557 |
s = ev->b; |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1558 |
if (_opt.landscape == LT_CANDY) s = ev->bc; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1559 |
j = EXTR(128, 15); |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1560 |
for(i=0; i!=5; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1561 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1562 |
j += 3; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1563 |
if (j >= 15) j -= 15; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1564 |
} |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1565 |
} |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1566 |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1567 |
if (memcmp(old_val, &_cur_palette[217], c * sizeof(*old_val)) != 0) { |
0 | 1568 |
if (_pal_first_dirty > 217) _pal_first_dirty = 217; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1569 |
if (_pal_last_dirty < 217 + c) _pal_last_dirty = 217 + c; |
0 | 1570 |
} |
1571 |
} |
|
1572 |
||
1573 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1574 |
void LoadStringWidthTable(void) |
0 | 1575 |
{ |
1576 |
int i; |
|
1577 |
byte *b; |
|
1578 |
||
1579 |
b = _stringwidth_table; |
|
1580 |
||
1581 |
// 2 equals space. |
|
1582 |
for(i=2; i != 0xE2; i++) { |
|
1351
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1583 |
*b++ = (byte)((i < 93 || i >= 129 || i == 98) ? GetSprite(i)->width : 0); |
0 | 1584 |
} |
1585 |
||
1586 |
for(i=0xE2; i != 0x1C2; i++) { |
|
1351
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1587 |
*b++ = (byte)((i < 317 || i >= 353) ? GetSprite(i)->width + 1 : 0); |
0 | 1588 |
} |
1589 |
||
1590 |
for(i=0x1C2; i != 0x2A2; i++) { |
|
1351
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1591 |
*b++ = (byte)((i < 541 || i >= 577) ? GetSprite(i)->width + 1 : 0); |
0 | 1592 |
} |
1593 |
} |
|
1594 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1595 |
void ScreenSizeChanged(void) |
0 | 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 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1605 |
void UndrawMouseCursor(void) |
0 | 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 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1618 |
void DrawMouseCursor(void) |
0 | 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 |
||
1130
236aa7efbe7a
(svn r1631) A couple of fixes for the signed/unsigned warnings. Only train_cmd.c remains to need fixing...
dominik
parents:
1095
diff
changeset
|
1645 |
assert(w*h < (int) sizeof(_cursor_backup)); |
0 | 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 |
||
798 | 1663 |
#if defined(_DEBUG) |
410 | 1664 |
static void DbgScreenRect(int left, int top, int right, int bottom) |
0 | 1665 |
{ |
1666 |
DrawPixelInfo dp,*old; |
|
1667 |
||
1668 |
old = _cur_dpi; |
|
1669 |
_cur_dpi = &dp; |
|
1670 |
dp = _screen; |
|
1671 |
GfxFillRect(left, top, right-1, bottom-1, rand() & 255); |
|
1672 |
_cur_dpi = old; |
|
1673 |
} |
|
798 | 1674 |
#endif |
0 | 1675 |
|
1676 |
extern bool _dbg_screen_rect; |
|
1677 |
||
1678 |
void RedrawScreenRect(int left, int top, int right, int bottom) |
|
1679 |
{ |
|
1680 |
assert(right <= _screen.width && bottom <= _screen.height); |
|
1681 |
if (_cursor.visible) { |
|
1682 |
if (right > _cursor.draw_pos.x && |
|
1683 |
left < _cursor.draw_pos.x + _cursor.draw_size.x && |
|
1684 |
bottom > _cursor.draw_pos.y && |
|
1685 |
top < _cursor.draw_pos.y + _cursor.draw_size.y) { |
|
1686 |
UndrawMouseCursor(); |
|
1687 |
} |
|
1688 |
} |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1689 |
UndrawTextMessage(); |
0 | 1690 |
|
1691 |
#if defined(_DEBUG) |
|
1692 |
if (_dbg_screen_rect) |
|
1693 |
DbgScreenRect(left, top, right, bottom); |
|
1694 |
else |
|
1695 |
#endif |
|
1696 |
DrawOverlappedWindowForAll(left, top, right, bottom); |
|
1697 |
||
1698 |
_video_driver->make_dirty(left, top, right-left, bottom-top); |
|
1699 |
} |
|
1700 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1701 |
void DrawDirtyBlocks(void) |
0 | 1702 |
{ |
1703 |
byte *b = _dirty_blocks; |
|
1704 |
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
|
1705 |
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
|
1706 |
const int h = (_screen.height + 7) & ~7; |
0 | 1707 |
|
1708 |
do { |
|
1709 |
if (*b != 0) { |
|
1710 |
int left,top; |
|
1711 |
int right = x + 64; |
|
1712 |
int bottom = y; |
|
1713 |
byte *p = b; |
|
1714 |
int h2; |
|
1715 |
// First try coalescing downwards |
|
1716 |
do { |
|
1717 |
*p = 0; |
|
1718 |
p += DIRTY_BYTES_PER_LINE; |
|
1719 |
bottom += 8; |
|
1720 |
} while (bottom != h && *p); |
|
1721 |
||
1722 |
// Try coalescing to the right too. |
|
1723 |
h2 = (bottom - y) >> 3; |
|
1724 |
assert(h2>0); |
|
1725 |
p = b; |
|
1726 |
||
1727 |
while (right != w) { |
|
1728 |
byte *p2 = ++p; |
|
1729 |
int h = h2; |
|
1730 |
// Check if a full line of dirty flags is set. |
|
1731 |
do { |
|
1732 |
if (!*p2) goto no_more_coalesc; |
|
1733 |
p2 += DIRTY_BYTES_PER_LINE; |
|
1734 |
} while (--h); |
|
1735 |
||
1736 |
// Wohoo, can combine it one step to the right! |
|
1737 |
// Do that, and clear the bits. |
|
1738 |
right += 64; |
|
1739 |
||
1740 |
h = h2; |
|
1741 |
p2 = p; |
|
1742 |
do { |
|
1743 |
*p2 = 0; |
|
1744 |
p2 += DIRTY_BYTES_PER_LINE; |
|
1745 |
} while (--h); |
|
1746 |
} |
|
1747 |
no_more_coalesc:; |
|
1748 |
||
1749 |
left = x; |
|
1750 |
top = y; |
|
1751 |
||
1752 |
if (left < _invalid_rect.left)left = _invalid_rect.left; |
|
1753 |
if (top < _invalid_rect.top) top = _invalid_rect.top; |
|
1754 |
if (right > _invalid_rect.right)right = _invalid_rect.right; |
|
1755 |
if (bottom > _invalid_rect.bottom)bottom = _invalid_rect.bottom; |
|
1756 |
||
1757 |
if (left < right && top < bottom) { |
|
1758 |
RedrawScreenRect(left, top, right, bottom); |
|
1759 |
} |
|
1760 |
||
1761 |
} |
|
1762 |
} while (b++, (x+=64) != w || (x=0,b+=-(w>>6)+DIRTY_BYTES_PER_LINE,(y+=8) != h)); |
|
1763 |
||
1764 |
_invalid_rect.left = w; |
|
1765 |
_invalid_rect.top = h; |
|
1766 |
_invalid_rect.right = 0; |
|
1767 |
_invalid_rect.bottom = 0; |
|
1768 |
} |
|
1769 |
||
1770 |
||
1771 |
void SetDirtyBlocks(int left, int top, int right, int bottom) |
|
1772 |
{ |
|
1773 |
byte *b; |
|
1774 |
int width,height,i; |
|
1775 |
||
1776 |
if (left < 0) left = 0; |
|
1777 |
if (top < 0) top = 0; |
|
1778 |
if (right > _screen.width) right = _screen.width; |
|
1779 |
if (bottom > _screen.height) bottom = _screen.height; |
|
1780 |
||
1781 |
if (left >= right || top >= bottom) |
|
1782 |
return; |
|
1783 |
||
1784 |
if (left < _invalid_rect.left) _invalid_rect.left = left; |
|
1785 |
if (top < _invalid_rect.top) _invalid_rect.top = top; |
|
1786 |
if (right > _invalid_rect.right)_invalid_rect.right = right; |
|
1787 |
if (bottom > _invalid_rect.bottom)_invalid_rect.bottom = bottom; |
|
1788 |
||
1789 |
left >>= 6; |
|
1790 |
top >>= 3; |
|
1791 |
||
1792 |
b = _dirty_blocks + top * DIRTY_BYTES_PER_LINE + left; |
|
1793 |
||
1794 |
width = ((right-1) >> 6) - left + 1; |
|
1795 |
height = ((bottom-1) >> 3) - top + 1; |
|
1796 |
||
1797 |
assert(width > 0 && height > 0); |
|
1798 |
||
1799 |
do { |
|
1800 |
i=width; |
|
1801 |
do b[--i] = 0xFF; while (i); |
|
1802 |
||
1803 |
b += DIRTY_BYTES_PER_LINE; |
|
1804 |
} while (--height); |
|
1805 |
} |
|
1806 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1807 |
void MarkWholeScreenDirty(void) |
0 | 1808 |
{ |
1809 |
SetDirtyBlocks(0, 0, _screen.width, _screen.height); |
|
1810 |
} |
|
1811 |
||
1812 |
bool FillDrawPixelInfo(DrawPixelInfo *n, DrawPixelInfo *o, int left, int top, int width, int height) |
|
1813 |
{ |
|
1814 |
int t; |
|
1815 |
||
1816 |
if (o == NULL) |
|
1817 |
o = _cur_dpi; |
|
1818 |
||
1819 |
n->zoom = 0; |
|
1820 |
||
1821 |
assert(width > 0); |
|
1822 |
assert(height > 0); |
|
1823 |
||
1824 |
n->left = 0; |
|
1825 |
if ((left -= o->left) < 0) { |
|
1826 |
if ((width += left) < 0) |
|
1827 |
return false; |
|
1828 |
n->left = -left; |
|
1829 |
left = 0; |
|
1830 |
} |
|
1831 |
||
1832 |
if ((t=width + left - o->width) > 0) { |
|
1833 |
if ((width -= t) < 0) |
|
1834 |
return false; |
|
1835 |
} |
|
1836 |
n->width = width; |
|
1837 |
||
1838 |
n->top = 0; |
|
1839 |
if ((top -= o->top) < 0) { |
|
1840 |
if ((height += top) < 0) |
|
1841 |
return false; |
|
1842 |
n->top = -top; |
|
1843 |
top = 0; |
|
1844 |
} |
|
1845 |
||
1846 |
n->dst_ptr = o->dst_ptr + left + top * (n->pitch = o->pitch); |
|
1847 |
||
1848 |
if ((t=height + top - o->height) > 0) { |
|
1849 |
if ((height-=t) < 0) |
|
1850 |
return false; |
|
1851 |
} |
|
1852 |
n->height = height; |
|
1853 |
||
1854 |
||
1855 |
return true; |
|
1856 |
} |
|
1857 |
||
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1858 |
static void SetCursorSprite(CursorID cursor) |
0 | 1859 |
{ |
1860 |
CursorVars *cv = &_cursor; |
|
1348 | 1861 |
const Sprite *p; |
0 | 1862 |
|
1863 |
if (cv->sprite == cursor) |
|
1864 |
return; |
|
1865 |
||
1350
067b22970f19
(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
|
1866 |
p = GetSprite(cursor & 0x3FFF); |
0 | 1867 |
cv->sprite = cursor; |
1348 | 1868 |
cv->size.y = p->height; |
1351
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1869 |
cv->size.x = p->width; |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1870 |
cv->offs.x = p->x_offs; |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1871 |
cv->offs.y = p->y_offs; |
0 | 1872 |
|
1873 |
cv->dirty = true; |
|
1874 |
} |
|
1875 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1876 |
static void SwitchAnimatedCursor(void) |
0 | 1877 |
{ |
1878 |
CursorVars *cv = &_cursor; |
|
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1879 |
const CursorID *cur = cv->animate_cur; |
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1880 |
CursorID sprite; |
0 | 1881 |
|
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1882 |
// ANIM_CURSOR_END is 0xFFFF in table/animcursors.h |
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1883 |
if (cur == NULL || *cur == 0xFFFF) cur = cv->animate_list; |
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1884 |
|
0 | 1885 |
sprite = cur[0]; |
1886 |
cv->animate_timeout = cur[1]; |
|
1887 |
cv->animate_cur = cur + 2; |
|
1888 |
||
1889 |
SetCursorSprite(sprite); |
|
1890 |
} |
|
1891 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1892 |
void CursorTick(void) |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1893 |
{ |
0 | 1894 |
CursorVars *cv = &_cursor; |
1895 |
if (cv->animate_timeout && !--cv->animate_timeout) |
|
1896 |
SwitchAnimatedCursor(); |
|
1897 |
} |
|
1898 |
||
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1899 |
void SetMouseCursor(CursorID cursor) |
0 | 1900 |
{ |
1901 |
// Turn off animation |
|
1902 |
_cursor.animate_timeout = 0; |
|
1903 |
// Set cursor |
|
1904 |
SetCursorSprite(cursor); |
|
1905 |
} |
|
1906 |
||
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1907 |
void SetAnimatedMouseCursor(const CursorID *table) |
0 | 1908 |
{ |
1909 |
_cursor.animate_list = table; |
|
1910 |
_cursor.animate_cur = NULL; |
|
1911 |
SwitchAnimatedCursor(); |
|
1912 |
} |
|
1913 |
||
1914 |
bool ChangeResInGame(int w, int h) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
1915 |
{ |
0 | 1916 |
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
|
1917 |
return false; |
0 | 1918 |
|
1919 |
_cur_resolution[0] = w; |
|
1920 |
_cur_resolution[1] = h; |
|
1921 |
return true; |
|
1922 |
} |
|
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
|
1923 |
|
1829
0b6de3b4458a
(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
|
1924 |
void ToggleFullScreen(bool fs) {_video_driver->toggle_fullscreen(fs);} |
0b6de3b4458a
(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
|
1925 |
|
1806
75dc9c737892
(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
|
1926 |
static int CDECL compare_res(const void *pa, const void *pb) |
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
|
1927 |
{ |
1806
75dc9c737892
(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
|
1928 |
int x = ((const uint16*)pa)[0] - ((const uint16*)pb)[0]; |
75dc9c737892
(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
|
1929 |
if (x != 0) return x; |
75dc9c737892
(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
|
1930 |
return ((const uint16*)pa)[1] - ((const uint16*)pb)[1]; |
75dc9c737892
(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
|
1931 |
} |
75dc9c737892
(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
|
1932 |
|
75dc9c737892
(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
|
1933 |
void SortResolutions(int count) |
75dc9c737892
(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
|
1934 |
{ |
75dc9c737892
(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
|
1935 |
qsort(_resolutions, count, sizeof(_resolutions[0]), compare_res); |
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
|
1936 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1937 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1938 |
uint16 GetDrawStringPlayerColor(byte player) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1939 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1940 |
// Get the color for DrawString-subroutines which matches the color |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1941 |
// of the player |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1942 |
if (player == OWNER_SPECTATOR || player == OWNER_SPECTATOR - 1) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1943 |
return 1; |
657
40a9032b454b
(svn r1091) Fix: Finally station names use 100% the correct color in transparent mode
dominik
parents:
619
diff
changeset
|
1944 |
return (_color_list[_player_colors[player]].window_color_1b) | IS_PALETTE_COLOR; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1945 |
} |