author | tron |
Thu, 30 Jun 2005 19:49:01 +0000 | |
changeset 1996 | beb1489efefd |
parent 1991 | f3d5e35731a2 |
child 1997 | 91085465f12b |
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 |
||
624 |
while (num >= 4) { |
|
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 |
num -= 4; |
|
632 |
} |
|
633 |
while (num) { |
|
634 |
*dst++ = ctab[*src++]; |
|
635 |
num--; |
|
636 |
} |
|
637 |
} while (!(done & 0x80)); |
|
638 |
||
639 |
bp->dst += bp->pitch; |
|
640 |
} while (--bp->height); |
|
641 |
} else if (bp->mode & 2) { |
|
642 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
643 |
do { |
|
644 |
do { |
|
645 |
done = src_o[0]; |
|
646 |
num = done & 0x7F; |
|
647 |
skip = src_o[1]; |
|
648 |
src_o += num + 2; |
|
649 |
||
650 |
dst = bp->dst; |
|
651 |
||
652 |
if ( (skip -= bp->start_x) > 0) { |
|
653 |
dst += skip; |
|
654 |
} else { |
|
655 |
num += skip; |
|
656 |
if (num <= 0) |
|
657 |
continue; |
|
658 |
skip = 0; |
|
659 |
} |
|
660 |
||
661 |
skip = skip + num - bp->width; |
|
662 |
if (skip > 0) { |
|
663 |
num -= skip; |
|
664 |
if (num <= 0) |
|
665 |
continue; |
|
666 |
} |
|
667 |
||
668 |
ctab = _color_remap_ptr; |
|
669 |
while (num) { |
|
670 |
*dst = ctab[*dst]; |
|
671 |
dst++; |
|
672 |
num--; |
|
673 |
} |
|
674 |
} while (!(done & 0x80)); |
|
675 |
||
676 |
bp->dst += bp->pitch; |
|
677 |
} while (--bp->height); |
|
678 |
||
679 |
} else { |
|
680 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
681 |
do { |
|
682 |
do { |
|
683 |
done = src_o[0]; |
|
684 |
num = done & 0x7F; |
|
685 |
skip = src_o[1]; |
|
686 |
src = src_o + 2; |
|
687 |
src_o += num + 2; |
|
688 |
||
689 |
dst = bp->dst; |
|
690 |
||
691 |
if ( (skip -= bp->start_x) > 0) { |
|
692 |
dst += skip; |
|
693 |
} else { |
|
694 |
src -= skip; |
|
695 |
num += skip; |
|
696 |
if (num <= 0) |
|
697 |
continue; |
|
698 |
skip = 0; |
|
699 |
} |
|
700 |
||
701 |
skip = skip + num - bp->width; |
|
702 |
if (skip > 0) { |
|
703 |
num -= skip; |
|
704 |
if (num <= 0) |
|
705 |
continue; |
|
706 |
} |
|
707 |
#if defined(_WIN32) |
|
708 |
if (num & 1) *dst++ = *src++; |
|
709 |
if (num & 2) { *(uint16*)dst = *(uint16*)src; dst += 2; src += 2; } |
|
710 |
if (num >>= 2) { |
|
711 |
do { |
|
712 |
*(uint32*)dst = *(uint32*)src; |
|
713 |
dst += 4; |
|
714 |
src += 4; |
|
715 |
} while (--num); |
|
716 |
} |
|
717 |
#else |
|
718 |
memcpy(dst, src, num); |
|
719 |
#endif |
|
720 |
} while (!(done & 0x80)); |
|
721 |
||
722 |
bp->dst += bp->pitch; |
|
723 |
} while (--bp->height); |
|
724 |
} |
|
725 |
} |
|
726 |
||
727 |
static void GfxBlitZoomInUncomp(BlitterParams *bp) |
|
728 |
{ |
|
1357 | 729 |
const byte *src = bp->sprite; |
0 | 730 |
byte *dst = bp->dst; |
731 |
int height = bp->height; |
|
732 |
int width = bp->width; |
|
733 |
int i; |
|
734 |
||
735 |
assert(height > 0); |
|
736 |
assert(width > 0); |
|
737 |
||
738 |
if (bp->mode & 1) { |
|
739 |
if (bp->info & 1) { |
|
1357 | 740 |
const byte *ctab = _color_remap_ptr; |
0 | 741 |
|
742 |
do { |
|
1996 | 743 |
for (i = 0; i != width; i++) { |
744 |
byte b = ctab[src[i]]; |
|
745 |
||
746 |
if (b != 0) dst[i] = b; |
|
0 | 747 |
} |
748 |
src += bp->width_org; |
|
749 |
dst += bp->pitch; |
|
750 |
} while (--height); |
|
751 |
} |
|
752 |
} else if (bp->mode & 2) { |
|
753 |
if (bp->info & 1) { |
|
1357 | 754 |
const byte *ctab = _color_remap_ptr; |
755 |
||
0 | 756 |
do { |
1996 | 757 |
for (i = 0; i != width; i++) |
758 |
if (src[i] != 0) dst[i] = ctab[dst[i]]; |
|
0 | 759 |
src += bp->width_org; |
760 |
dst += bp->pitch; |
|
761 |
} while (--height); |
|
762 |
} |
|
763 |
} else { |
|
764 |
if (!(bp->info & 1)) { |
|
765 |
do { |
|
766 |
memcpy(dst, src, width); |
|
767 |
src += bp->width_org; |
|
768 |
dst += bp->pitch; |
|
769 |
} while (--height); |
|
770 |
} else { |
|
771 |
do { |
|
772 |
int n = width; |
|
773 |
while (n >= 4) { |
|
1996 | 774 |
if (src[0] != 0) dst[0] = src[0]; |
775 |
if (src[1] != 0) dst[1] = src[1]; |
|
776 |
if (src[2] != 0) dst[2] = src[2]; |
|
777 |
if (src[3] != 0) dst[3] = src[3]; |
|
0 | 778 |
|
779 |
dst += 4; |
|
780 |
src += 4; |
|
781 |
n -= 4; |
|
782 |
} |
|
783 |
||
784 |
while (n) { |
|
1996 | 785 |
if (src[0] != 0) dst[0] = src[0]; |
0 | 786 |
src++; |
787 |
dst++; |
|
788 |
n--; |
|
789 |
} |
|
790 |
||
791 |
src += bp->width_org - width; |
|
792 |
dst += bp->pitch - width; |
|
793 |
||
794 |
} while (--height); |
|
795 |
} |
|
796 |
} |
|
797 |
} |
|
798 |
||
799 |
static void GfxBlitTileZoomMedium(BlitterParams *bp) |
|
800 |
{ |
|
1357 | 801 |
const byte* src_o = bp->sprite; |
802 |
const byte* src; |
|
0 | 803 |
int num, skip; |
804 |
byte done; |
|
1357 | 805 |
byte *dst; |
806 |
const byte* ctab; |
|
0 | 807 |
|
808 |
if (bp->mode & 1) { |
|
809 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
810 |
do { |
|
811 |
do { |
|
812 |
done = src_o[0]; |
|
813 |
num = done & 0x7F; |
|
814 |
skip = src_o[1]; |
|
815 |
src = src_o + 2; |
|
816 |
src_o += num + 2; |
|
817 |
||
818 |
dst = bp->dst; |
|
819 |
||
820 |
if (skip & 1) { |
|
821 |
skip++; |
|
822 |
src++; |
|
823 |
if (!--num) |
|
824 |
continue; |
|
825 |
} |
|
826 |
||
827 |
if ( (skip -= bp->start_x) > 0) { |
|
828 |
dst += skip >> 1; |
|
829 |
} else { |
|
830 |
src -= skip; |
|
831 |
num += skip; |
|
832 |
if (num <= 0) |
|
833 |
continue; |
|
834 |
skip = 0; |
|
835 |
} |
|
836 |
||
837 |
skip = skip + num - bp->width; |
|
838 |
if (skip > 0) { |
|
839 |
num -= skip; |
|
840 |
if (num <= 0) |
|
841 |
continue; |
|
842 |
} |
|
843 |
||
844 |
ctab = _color_remap_ptr; |
|
845 |
num = (num + 1) >> 1; |
|
846 |
if (num) { |
|
847 |
do { |
|
848 |
*dst = ctab[*src]; |
|
849 |
dst++; |
|
850 |
src+=2; |
|
851 |
} while (--num); |
|
852 |
} |
|
853 |
} while (!(done & 0x80)); |
|
854 |
bp->dst += bp->pitch; |
|
855 |
if (!--bp->height) |
|
856 |
return; |
|
857 |
||
858 |
do { |
|
859 |
done = src_o[0]; |
|
860 |
src_o += (done & 0x7F) + 2; |
|
861 |
} while (!(done & 0x80)); |
|
862 |
} while (--bp->height); |
|
863 |
} else if (bp->mode & 2) { |
|
864 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
865 |
do { |
|
866 |
do { |
|
867 |
done = src_o[0]; |
|
868 |
num = done & 0x7F; |
|
869 |
skip = src_o[1]; |
|
870 |
src_o += num + 2; |
|
871 |
||
872 |
dst = bp->dst; |
|
873 |
||
874 |
if (skip & 1) { |
|
875 |
skip++; |
|
876 |
if (!--num) |
|
877 |
continue; |
|
878 |
} |
|
879 |
||
880 |
if ( (skip -= bp->start_x) > 0) { |
|
881 |
dst += skip >> 1; |
|
882 |
} else { |
|
883 |
num += skip; |
|
884 |
if (num <= 0) |
|
885 |
continue; |
|
886 |
skip = 0; |
|
887 |
} |
|
888 |
||
889 |
skip = skip + num - bp->width; |
|
890 |
if (skip > 0) { |
|
891 |
num -= skip; |
|
892 |
if (num <= 0) |
|
893 |
continue; |
|
894 |
} |
|
895 |
||
896 |
ctab = _color_remap_ptr; |
|
897 |
num = (num + 1) >> 1; |
|
898 |
if (num) { |
|
899 |
do { |
|
900 |
*dst = ctab[*dst]; |
|
901 |
dst++; |
|
902 |
} while (--num); |
|
903 |
} |
|
904 |
||
905 |
} while (!(done & 0x80)); |
|
906 |
bp->dst += bp->pitch; |
|
907 |
if (!--bp->height) |
|
908 |
return; |
|
909 |
||
910 |
do { |
|
911 |
done = src_o[0]; |
|
912 |
src_o += (done & 0x7F) + 2; |
|
913 |
} while (!(done & 0x80)); |
|
914 |
} while (--bp->height); |
|
915 |
||
916 |
} else { |
|
917 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
918 |
do { |
|
919 |
do { |
|
920 |
done = src_o[0]; |
|
921 |
num = done & 0x7F; |
|
922 |
skip = src_o[1]; |
|
923 |
src = src_o + 2; |
|
924 |
src_o += num + 2; |
|
925 |
||
926 |
dst = bp->dst; |
|
927 |
||
928 |
if (skip & 1) { |
|
929 |
skip++; |
|
930 |
src++; |
|
931 |
if (!--num) |
|
932 |
continue; |
|
933 |
} |
|
934 |
||
935 |
if ( (skip -= bp->start_x) > 0) { |
|
936 |
dst += skip >> 1; |
|
937 |
} else { |
|
938 |
src -= skip; |
|
939 |
num += skip; |
|
940 |
if (num <= 0) |
|
941 |
continue; |
|
942 |
skip = 0; |
|
943 |
} |
|
944 |
||
945 |
skip = skip + num - bp->width; |
|
946 |
if (skip > 0) { |
|
947 |
num -= skip; |
|
948 |
if (num <= 0) |
|
949 |
continue; |
|
950 |
} |
|
951 |
||
952 |
num = (num + 1) >> 1; |
|
953 |
||
954 |
if (num) { |
|
955 |
do { |
|
956 |
*dst = *src; |
|
957 |
dst++; |
|
958 |
src+=2; |
|
959 |
} while (--num); |
|
960 |
} |
|
961 |
||
962 |
} while (!(done & 0x80)); |
|
963 |
||
964 |
bp->dst += bp->pitch; |
|
965 |
if (!--bp->height) |
|
966 |
return; |
|
967 |
||
968 |
do { |
|
969 |
done = src_o[0]; |
|
970 |
src_o += (done & 0x7F) + 2; |
|
971 |
} while (!(done & 0x80)); |
|
972 |
||
973 |
} while (--bp->height); |
|
974 |
} |
|
975 |
} |
|
976 |
||
977 |
static void GfxBlitZoomMediumUncomp(BlitterParams *bp) |
|
978 |
{ |
|
1357 | 979 |
const byte *src = bp->sprite; |
0 | 980 |
byte *dst = bp->dst; |
981 |
int height = bp->height; |
|
982 |
int width = bp->width; |
|
983 |
int i; |
|
984 |
||
985 |
assert(height > 0); |
|
986 |
assert(width > 0); |
|
987 |
||
988 |
if (bp->mode & 1) { |
|
989 |
if (bp->info & 1) { |
|
1357 | 990 |
const byte *ctab = _color_remap_ptr; |
991 |
||
1996 | 992 |
for (height >>= 1; height != 0; height--) { |
993 |
for (i = 0; i != width >> 1; i++) { |
|
994 |
byte b = ctab[src[i * 2]]; |
|
995 |
||
996 |
if (b != 0) dst[i] = b; |
|
997 |
} |
|
0 | 998 |
src += bp->width_org * 2; |
999 |
dst += bp->pitch; |
|
1996 | 1000 |
} |
0 | 1001 |
} |
1002 |
} else if (bp->mode & 2) { |
|
1003 |
if (bp->info & 1) { |
|
1357 | 1004 |
const byte *ctab = _color_remap_ptr; |
1005 |
||
1996 | 1006 |
for (height >>= 1; height != 0; height--) { |
1007 |
for (i = 0; i != width >> 1; i++) |
|
1008 |
if (src[i * 2] != 0) dst[i] = ctab[dst[i]]; |
|
0 | 1009 |
src += bp->width_org * 2; |
1010 |
dst += bp->pitch; |
|
1996 | 1011 |
} |
0 | 1012 |
} |
1013 |
} else { |
|
1014 |
if (bp->info & 1) { |
|
1996 | 1015 |
for (height >>= 1; height != 0; height--) { |
1016 |
for (i = 0; i != width >> 1; i++) |
|
1017 |
if (src[i * 2] != 0) dst[i] = src[i * 2]; |
|
0 | 1018 |
src += bp->width_org * 2; |
1019 |
dst += bp->pitch; |
|
1996 | 1020 |
} |
0 | 1021 |
} |
1022 |
} |
|
1023 |
} |
|
1024 |
||
1025 |
static void GfxBlitTileZoomOut(BlitterParams *bp) |
|
1026 |
{ |
|
1357 | 1027 |
const byte* src_o = bp->sprite; |
1028 |
const byte* src; |
|
0 | 1029 |
int num, skip; |
1030 |
byte done; |
|
1357 | 1031 |
byte *dst; |
1032 |
const byte* ctab; |
|
0 | 1033 |
|
1034 |
if (bp->mode & 1) { |
|
1035 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
1036 |
for(;;) { |
|
1037 |
do { |
|
1038 |
done = src_o[0]; |
|
1039 |
num = done & 0x7F; |
|
1040 |
skip = src_o[1]; |
|
1041 |
src = src_o + 2; |
|
1042 |
src_o += num + 2; |
|
1043 |
||
1044 |
dst = bp->dst; |
|
1045 |
||
1046 |
if (skip & 1) { |
|
1047 |
skip++; |
|
1048 |
src++; |
|
1049 |
if (!--num) |
|
1050 |
continue; |
|
1051 |
} |
|
1052 |
||
1053 |
if (skip & 2) { |
|
1054 |
skip+=2; |
|
1055 |
src+=2; |
|
1056 |
if ((num-=2) <= 0) |
|
1057 |
continue; |
|
1058 |
} |
|
1059 |
||
1060 |
if ( (skip -= bp->start_x) > 0) { |
|
1061 |
dst += skip >> 2; |
|
1062 |
} else { |
|
1063 |
src -= skip; |
|
1064 |
num += skip; |
|
1065 |
if (num <= 0) |
|
1066 |
continue; |
|
1067 |
skip = 0; |
|
1068 |
} |
|
1069 |
||
1070 |
skip = skip + num - bp->width; |
|
1071 |
if (skip > 0) { |
|
1072 |
num -= skip; |
|
1073 |
if (num <= 0) |
|
1074 |
continue; |
|
1075 |
} |
|
1076 |
||
1077 |
ctab = _color_remap_ptr; |
|
1078 |
num = (num + 3) >> 2; |
|
1079 |
if (num) { |
|
1080 |
do { |
|
1081 |
*dst = ctab[*src]; |
|
1082 |
dst++; |
|
1083 |
src+=4; |
|
1084 |
} while (--num); |
|
1085 |
} |
|
1086 |
} while (!(done & 0x80)); |
|
1087 |
bp->dst += bp->pitch; |
|
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 |
do { |
|
1099 |
done = src_o[0]; |
|
1100 |
src_o += (done & 0x7F) + 2; |
|
1101 |
} while (!(done & 0x80)); |
|
1102 |
if (!--bp->height) |
|
1103 |
return; |
|
1104 |
||
1105 |
do { |
|
1106 |
done = src_o[0]; |
|
1107 |
src_o += (done & 0x7F) + 2; |
|
1108 |
} while (!(done & 0x80)); |
|
1109 |
if (!--bp->height) |
|
1110 |
return; |
|
1111 |
} |
|
1112 |
} else if (bp->mode & 2) { |
|
1113 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
1114 |
for(;;) { |
|
1115 |
do { |
|
1116 |
done = src_o[0]; |
|
1117 |
num = done & 0x7F; |
|
1118 |
skip = src_o[1]; |
|
1119 |
src_o += num + 2; |
|
1120 |
||
1121 |
dst = bp->dst; |
|
1122 |
||
1123 |
if (skip & 1) { |
|
1124 |
skip++; |
|
1125 |
if (!--num) |
|
1126 |
continue; |
|
1127 |
} |
|
1128 |
||
1129 |
if (skip & 2) { |
|
1130 |
skip+=2; |
|
1131 |
if ((num-=2) <= 0) |
|
1132 |
continue; |
|
1133 |
} |
|
1134 |
||
1135 |
if ( (skip -= bp->start_x) > 0) { |
|
1136 |
dst += skip >> 2; |
|
1137 |
} else { |
|
1138 |
num += skip; |
|
1139 |
if (num <= 0) |
|
1140 |
continue; |
|
1141 |
skip = 0; |
|
1142 |
} |
|
1143 |
||
1144 |
skip = skip + num - bp->width; |
|
1145 |
if (skip > 0) { |
|
1146 |
num -= skip; |
|
1147 |
if (num <= 0) |
|
1148 |
continue; |
|
1149 |
} |
|
1150 |
||
1151 |
ctab = _color_remap_ptr; |
|
1152 |
num = (num + 3) >> 2; |
|
1153 |
if (num) { |
|
1154 |
do { |
|
1155 |
*dst = ctab[*dst]; |
|
1156 |
dst++; |
|
1157 |
} while (--num); |
|
1158 |
} |
|
1159 |
||
1160 |
} while (!(done & 0x80)); |
|
1161 |
bp->dst += bp->pitch; |
|
1162 |
if (!--bp->height) |
|
1163 |
return; |
|
1164 |
||
1165 |
do { |
|
1166 |
done = src_o[0]; |
|
1167 |
src_o += (done & 0x7F) + 2; |
|
1168 |
} while (!(done & 0x80)); |
|
1169 |
if (!--bp->height) |
|
1170 |
return; |
|
1171 |
||
1172 |
do { |
|
1173 |
done = src_o[0]; |
|
1174 |
src_o += (done & 0x7F) + 2; |
|
1175 |
} while (!(done & 0x80)); |
|
1176 |
if (!--bp->height) |
|
1177 |
return; |
|
1178 |
||
1179 |
do { |
|
1180 |
done = src_o[0]; |
|
1181 |
src_o += (done & 0x7F) + 2; |
|
1182 |
} while (!(done & 0x80)); |
|
1183 |
if (!--bp->height) |
|
1184 |
return; |
|
1185 |
} |
|
1186 |
} else { |
|
1187 |
src_o += READ_LE_UINT16(src_o + bp->start_y * 2); |
|
1188 |
for(;;) { |
|
1189 |
do { |
|
1190 |
done = src_o[0]; |
|
1191 |
num = done & 0x7F; |
|
1192 |
skip = src_o[1]; |
|
1193 |
src = src_o + 2; |
|
1194 |
src_o += num + 2; |
|
1195 |
||
1196 |
dst = bp->dst; |
|
1197 |
||
1198 |
if (skip & 1) { |
|
1199 |
skip++; |
|
1200 |
src++; |
|
1201 |
if (!--num) |
|
1202 |
continue; |
|
1203 |
} |
|
1204 |
||
1205 |
if (skip & 2) { |
|
1206 |
skip+=2; |
|
1207 |
src+=2; |
|
1208 |
if ((num-=2) <= 0) |
|
1209 |
continue; |
|
1210 |
} |
|
1211 |
||
1212 |
if ( (skip -= bp->start_x) > 0) { |
|
1213 |
dst += skip >> 2; |
|
1214 |
} else { |
|
1215 |
src -= skip; |
|
1216 |
num += skip; |
|
1217 |
if (num <= 0) |
|
1218 |
continue; |
|
1219 |
skip = 0; |
|
1220 |
} |
|
1221 |
||
1222 |
skip = skip + num - bp->width; |
|
1223 |
if (skip > 0) { |
|
1224 |
num -= skip; |
|
1225 |
if (num <= 0) |
|
1226 |
continue; |
|
1227 |
} |
|
1228 |
||
1229 |
num = (num + 3) >> 2; |
|
1230 |
||
1231 |
if (num) { |
|
1232 |
do { |
|
1233 |
*dst = *src; |
|
1234 |
dst++; |
|
1235 |
src+=4; |
|
1236 |
} while (--num); |
|
1237 |
} |
|
1238 |
||
1239 |
} while (!(done & 0x80)); |
|
1240 |
||
1241 |
bp->dst += bp->pitch; |
|
1242 |
if (!--bp->height) |
|
1243 |
return; |
|
1244 |
||
1245 |
do { |
|
1246 |
done = src_o[0]; |
|
1247 |
src_o += (done & 0x7F) + 2; |
|
1248 |
} while (!(done & 0x80)); |
|
1249 |
if (!--bp->height) |
|
1250 |
return; |
|
1251 |
||
1252 |
do { |
|
1253 |
done = src_o[0]; |
|
1254 |
src_o += (done & 0x7F) + 2; |
|
1255 |
} while (!(done & 0x80)); |
|
1256 |
if (!--bp->height) |
|
1257 |
return; |
|
1258 |
||
1259 |
do { |
|
1260 |
done = src_o[0]; |
|
1261 |
src_o += (done & 0x7F) + 2; |
|
1262 |
} while (!(done & 0x80)); |
|
1263 |
if (!--bp->height) |
|
1264 |
return; |
|
1265 |
} |
|
1266 |
} |
|
1267 |
} |
|
1268 |
||
1269 |
static void GfxBlitZoomOutUncomp(BlitterParams *bp) |
|
1270 |
{ |
|
1357 | 1271 |
const byte* src = bp->sprite; |
0 | 1272 |
byte *dst = bp->dst; |
1273 |
int height = bp->height; |
|
1274 |
int width = bp->width; |
|
1275 |
int i; |
|
1276 |
||
1277 |
assert(height > 0); |
|
1278 |
assert(width > 0); |
|
1279 |
||
1280 |
if (bp->mode & 1) { |
|
1281 |
if (bp->info & 1) { |
|
1357 | 1282 |
const byte *ctab = _color_remap_ptr; |
1283 |
||
1996 | 1284 |
for (height >>= 2; height != 0; height--) { |
1285 |
for (i = 0; i != width >> 2; i++) { |
|
1286 |
byte b = ctab[src[i * 4]]; |
|
1287 |
||
1288 |
if (b != 0) dst[i] = b; |
|
1289 |
} |
|
0 | 1290 |
src += bp->width_org * 4; |
1291 |
dst += bp->pitch; |
|
1996 | 1292 |
} |
0 | 1293 |
} |
1294 |
} else if (bp->mode & 2) { |
|
1295 |
if (bp->info & 1) { |
|
1357 | 1296 |
const byte *ctab = _color_remap_ptr; |
1297 |
||
1996 | 1298 |
for (height >>= 2; height != 0; height--) { |
1299 |
for (i = 0; i != width >> 2; i++) |
|
1300 |
if (src[i * 4] != 0) dst[i] = ctab[dst[i]]; |
|
0 | 1301 |
src += bp->width_org * 4; |
1302 |
dst += bp->pitch; |
|
1996 | 1303 |
} |
0 | 1304 |
} |
1305 |
} else { |
|
1306 |
if (bp->info & 1) { |
|
1996 | 1307 |
for (height >>= 2; height != 0; height--) { |
1308 |
for (i = 0; i != width >> 2; i++) |
|
1309 |
if (src[i * 4] != 0) dst[i] = src[i * 4]; |
|
0 | 1310 |
src += bp->width_org * 4; |
1311 |
dst += bp->pitch; |
|
1996 | 1312 |
} |
0 | 1313 |
} |
1314 |
} |
|
1315 |
} |
|
1316 |
||
1317 |
typedef void (*BlitZoomFunc)(BlitterParams *bp); |
|
1318 |
||
1357 | 1319 |
static void GfxMainBlitter(const Sprite* sprite, int x, int y, int mode) |
0 | 1320 |
{ |
1321 |
DrawPixelInfo *dpi = _cur_dpi; |
|
1322 |
int start_x, start_y; |
|
1323 |
byte info; |
|
1324 |
BlitterParams bp; |
|
1325 |
int zoom_mask = ~((1 << (dpi->zoom))-1); |
|
1326 |
||
1327 |
static const BlitZoomFunc zf_tile[3] = |
|
1328 |
{ |
|
1329 |
GfxBlitTileZoomIn, |
|
1330 |
GfxBlitTileZoomMedium, |
|
1331 |
GfxBlitTileZoomOut |
|
1332 |
}; |
|
1333 |
static const BlitZoomFunc zf_uncomp[3] = |
|
1334 |
{ |
|
1335 |
GfxBlitZoomInUncomp, |
|
1336 |
GfxBlitZoomMediumUncomp, |
|
1337 |
GfxBlitZoomOutUncomp |
|
1338 |
}; |
|
1339 |
||
1340 |
/* 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
|
1341 |
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
|
1342 |
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
|
1343 |
bp.width_org = bp.width = sprite->width; |
1348 | 1344 |
bp.height_org = bp.height = sprite->height; |
1345 |
info = sprite->info; |
|
0 | 1346 |
bp.info = info; |
1348 | 1347 |
bp.sprite_org = bp.sprite = sprite->data; |
0 | 1348 |
bp.dst = dpi->dst_ptr; |
1349 |
bp.mode = mode; |
|
1350 |
bp.pitch = dpi->pitch; |
|
1351 |
||
1352 |
assert(bp.height > 0); |
|
1353 |
assert(bp.width > 0); |
|
1354 |
||
1355 |
if (info & 8) { |
|
1356 |
/* tile blit */ |
|
1357 |
start_y = 0; |
|
1358 |
||
1359 |
if (dpi->zoom > 0) { |
|
1360 |
start_y += bp.height &~ zoom_mask; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
1361 |
bp.height &= zoom_mask; |
0 | 1362 |
if (bp.height == 0) return; |
1363 |
y&=zoom_mask; |
|
1364 |
} |
|
1365 |
||
1366 |
if ( (y -= dpi->top) < 0) { |
|
1367 |
if ((bp.height += y) <= 0) |
|
1368 |
return; |
|
1369 |
start_y -= y; |
|
1370 |
y = 0; |
|
1371 |
} else { |
|
1372 |
bp.dst += bp.pitch * (y>>(dpi->zoom)); |
|
1373 |
} |
|
1374 |
bp.start_y = start_y; |
|
1375 |
||
1376 |
if ( (y = y + bp.height - dpi->height) > 0) { |
|
1377 |
if ( (bp.height -= y) <= 0) |
|
1378 |
return; |
|
1379 |
} |
|
1380 |
||
1381 |
start_x = 0; |
|
1382 |
x &= zoom_mask; |
|
1383 |
if ( (x -= dpi->left) < 0) { |
|
1384 |
if ((bp.width += x) <= 0) |
|
1385 |
return; |
|
1386 |
start_x -= x; |
|
1387 |
x = 0; |
|
1388 |
} |
|
1389 |
bp.start_x = start_x; |
|
1390 |
bp.dst += x>>(dpi->zoom); |
|
1391 |
||
1392 |
if ( (x = x + bp.width - dpi->width) > 0) { |
|
1393 |
if ( (bp.width -= x) <= 0) |
|
1394 |
return; |
|
1395 |
} |
|
1396 |
||
1397 |
zf_tile[dpi->zoom](&bp); |
|
1398 |
} else { |
|
1399 |
||
1400 |
bp.sprite += bp.width * (bp.height & ~zoom_mask); |
|
1401 |
bp.height &= zoom_mask; |
|
1402 |
if (bp.height == 0) |
|
1403 |
return; |
|
1404 |
||
1405 |
y &= zoom_mask; |
|
1406 |
||
1407 |
if ( (y -= dpi->top) < 0) { |
|
1408 |
if ((bp.height += y) <= 0) |
|
1409 |
return; |
|
1410 |
bp.sprite -= bp.width * y; |
|
1411 |
y = 0; |
|
1412 |
} else { |
|
1413 |
bp.dst += bp.pitch * (y>>(dpi->zoom)); |
|
1414 |
} |
|
1415 |
||
1416 |
if ( (y = y + bp.height - dpi->height) > 0) { |
|
1417 |
if ( (bp.height -= y) <= 0) |
|
1418 |
return; |
|
1419 |
} |
|
1420 |
||
1421 |
start_x = 0; |
|
1422 |
||
1423 |
x &= zoom_mask; |
|
1424 |
||
1425 |
if ( (x -= dpi->left) < 0) { |
|
1426 |
if ((bp.width += x) <= 0) |
|
1427 |
return; |
|
1428 |
start_x -= x; |
|
1429 |
bp.sprite -= x; |
|
1430 |
x = 0; |
|
1431 |
} |
|
1432 |
bp.dst += x>>(dpi->zoom); |
|
1433 |
||
1434 |
if ( (x = x + bp.width - dpi->width) > 0) { |
|
1435 |
if ( (bp.width -= x) <= 0) |
|
1436 |
return; |
|
1437 |
start_x += x; |
|
1438 |
} |
|
1439 |
bp.start_x = start_x; |
|
1440 |
||
1441 |
if (info&2) { |
|
1442 |
int totpix = bp.height_org * bp.width_org; |
|
1443 |
byte *dst = (byte*)alloca(totpix); |
|
1357 | 1444 |
const byte *src = bp.sprite_org; |
0 | 1445 |
signed char b; |
1446 |
||
461
9129fe36ef0d
(svn r679) Clarify bp.sprite assignment in GfxMainBlitter(). Pointed out by Oskar.
pasky
parents:
410
diff
changeset
|
1447 |
bp.sprite = dst + (bp.sprite - bp.sprite_org); |
0 | 1448 |
|
1449 |
while (totpix != 0) { |
|
1450 |
assert(totpix > 0); |
|
1451 |
b = *src++; |
|
1452 |
if (b >= 0) { |
|
1453 |
int i, count=b; |
|
1454 |
for(i=0; i!=count; i++) |
|
1455 |
dst[i] = src[i]; |
|
1456 |
dst += count; |
|
1457 |
src += count; |
|
1458 |
totpix -= count; |
|
1459 |
} else { |
|
1460 |
byte *tmp = dst- (((b&7)<<8)|(*src++)); |
|
1461 |
int i; |
|
1462 |
int count = -(b >> 3); |
|
1463 |
||
1464 |
for(i=0; i!=count; i++) |
|
1465 |
dst[i] = tmp[i]; |
|
1466 |
dst += count; |
|
1467 |
totpix -= count; |
|
1468 |
} |
|
1469 |
} |
|
1470 |
} |
|
1471 |
zf_uncomp[dpi->zoom](&bp); |
|
1472 |
} |
|
1473 |
} |
|
1474 |
||
798 | 1475 |
#if 0 |
410 | 1476 |
static void GfxScalePalette(int pal, byte scaling) |
0 | 1477 |
{ |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1478 |
const Colour* src; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1479 |
uint i; |
0 | 1480 |
|
1481 |
GfxInitPalettes(); |
|
1482 |
||
1483 |
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
|
1484 |
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
|
1485 |
_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
|
1486 |
_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
|
1487 |
_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
|
1488 |
} |
0 | 1489 |
} |
798 | 1490 |
#endif |
0 | 1491 |
|
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
|
1492 |
void DoPaletteAnimations(void); |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1493 |
|
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
|
1494 |
void GfxInitPalettes(void) |
0 | 1495 |
{ |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1496 |
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
|
1497 |
|
0 | 1498 |
_pal_first_dirty = 0; |
1499 |
_pal_last_dirty = 255; |
|
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1500 |
DoPaletteAnimations(); |
0 | 1501 |
} |
1502 |
||
1503 |
#define EXTR(p,q) (((uint16)(_timer_counter * (p)) * (q)) >> 16) |
|
1504 |
#define EXTR2(p,q) (((uint16)(~_timer_counter * (p)) * (q)) >> 16) |
|
1505 |
||
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
|
1506 |
void DoPaletteAnimations(void) |
0 | 1507 |
{ |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1508 |
const Colour* s; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1509 |
Colour* d; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1510 |
/* 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
|
1511 |
* 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
|
1512 |
* 245-254 for DOS and 217-226 for Windows. */ |
915 | 1513 |
int c = _use_dos_palette?38:28; |
0 | 1514 |
int j; |
1515 |
int i; |
|
1516 |
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
|
1517 |
Colour old_val[38]; // max(38, 28) |
0 | 1518 |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1519 |
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
|
1520 |
memcpy(old_val, d, c * sizeof(*old_val)); |
0 | 1521 |
|
1522 |
// Dark blue water |
|
1523 |
s = ev->a; |
|
1524 |
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
|
1525 |
j = EXTR(320,5); |
0 | 1526 |
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
|
1527 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1528 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1529 |
if (j == 5) j = 0; |
0 | 1530 |
} |
1531 |
||
1532 |
// Glittery water |
|
1533 |
s = ev->b; |
|
1534 |
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
|
1535 |
j = EXTR(128, 15); |
0 | 1536 |
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
|
1537 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1538 |
j += 3; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1539 |
if (j >= 15) j -= 15; |
0 | 1540 |
} |
1541 |
||
1542 |
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
|
1543 |
j = EXTR2(512, 5); |
0 | 1544 |
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
|
1545 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1546 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1547 |
if (j == 5) j = 0; |
0 | 1548 |
} |
1549 |
||
1550 |
// Oil refinery fire animation |
|
1551 |
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
|
1552 |
j = EXTR2(512, 7); |
0 | 1553 |
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
|
1554 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1555 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1556 |
if (j == 7) j = 0; |
0 | 1557 |
} |
1558 |
||
1559 |
// Radio tower blinking |
|
1560 |
{ |
|
1561 |
byte i,v; |
|
1562 |
i = (_timer_counter >> 1) & 0x7F; |
|
1563 |
(v = 255, i < 0x3f) || |
|
1564 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
1565 |
(v = 20); |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1566 |
d->r = v; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1567 |
d->g = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1568 |
d->b = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1569 |
d++; |
0 | 1570 |
|
1571 |
i ^= 0x40; |
|
1572 |
(v = 255, i < 0x3f) || |
|
1573 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
1574 |
(v = 20); |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1575 |
d->r = v; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1576 |
d->g = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1577 |
d->b = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1578 |
d++; |
0 | 1579 |
} |
1580 |
||
1581 |
// Handle lighthouse and stadium animation |
|
1582 |
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
|
1583 |
j = EXTR(256, 4); |
0 | 1584 |
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
|
1585 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1586 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1587 |
if (j == 4) j = 0; |
0 | 1588 |
} |
1589 |
||
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1590 |
// 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
|
1591 |
if(_use_dos_palette) { |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1592 |
// Dark blue water DOS |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1593 |
s = ev->a; |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1594 |
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
|
1595 |
j = EXTR(320,5); |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1596 |
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
|
1597 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1598 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1599 |
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
|
1600 |
} |
915 | 1601 |
|
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1602 |
// Glittery water DOS |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1603 |
s = ev->b; |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1604 |
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
|
1605 |
j = EXTR(128, 15); |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1606 |
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
|
1607 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1608 |
j += 3; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1609 |
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
|
1610 |
} |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1611 |
} |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1612 |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1613 |
if (memcmp(old_val, &_cur_palette[217], c * sizeof(*old_val)) != 0) { |
0 | 1614 |
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
|
1615 |
if (_pal_last_dirty < 217 + c) _pal_last_dirty = 217 + c; |
0 | 1616 |
} |
1617 |
} |
|
1618 |
||
1619 |
||
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
|
1620 |
void LoadStringWidthTable(void) |
0 | 1621 |
{ |
1622 |
int i; |
|
1623 |
byte *b; |
|
1624 |
||
1625 |
b = _stringwidth_table; |
|
1626 |
||
1627 |
// 2 equals space. |
|
1628 |
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
|
1629 |
*b++ = (byte)((i < 93 || i >= 129 || i == 98) ? GetSprite(i)->width : 0); |
0 | 1630 |
} |
1631 |
||
1632 |
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
|
1633 |
*b++ = (byte)((i < 317 || i >= 353) ? GetSprite(i)->width + 1 : 0); |
0 | 1634 |
} |
1635 |
||
1636 |
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
|
1637 |
*b++ = (byte)((i < 541 || i >= 577) ? GetSprite(i)->width + 1 : 0); |
0 | 1638 |
} |
1639 |
} |
|
1640 |
||
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
|
1641 |
void ScreenSizeChanged(void) |
0 | 1642 |
{ |
1643 |
// check the dirty rect |
|
1644 |
if (_invalid_rect.right >= _screen.width) _invalid_rect.right = _screen.width; |
|
1645 |
if (_invalid_rect.bottom >= _screen.height) _invalid_rect.bottom = _screen.height; |
|
1646 |
||
1647 |
// screen size changed and the old bitmap is invalid now, so we don't want to undraw it |
|
1648 |
_cursor.visible = false; |
|
1649 |
} |
|
1650 |
||
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
|
1651 |
void UndrawMouseCursor(void) |
0 | 1652 |
{ |
1653 |
if (_cursor.visible) { |
|
1654 |
_cursor.visible = false; |
|
1655 |
memcpy_pitch( |
|
1656 |
_screen.dst_ptr + _cursor.draw_pos.x + _cursor.draw_pos.y * _screen.pitch, |
|
1657 |
_cursor_backup, |
|
1658 |
_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
|
1659 |
|
0 | 1660 |
_video_driver->make_dirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y); |
1661 |
} |
|
1662 |
} |
|
1663 |
||
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
|
1664 |
void DrawMouseCursor(void) |
0 | 1665 |
{ |
1666 |
int x,y,w,h; |
|
1667 |
||
1668 |
// Don't draw the mouse cursor if it's already drawn |
|
1669 |
if (_cursor.visible) { |
|
1670 |
if (!_cursor.dirty) |
|
1671 |
return; |
|
1672 |
UndrawMouseCursor(); |
|
1673 |
} |
|
1674 |
||
1675 |
w = _cursor.size.x; |
|
1676 |
x = _cursor.pos.x + _cursor.offs.x; |
|
1677 |
if (x < 0) { w += x; x=0; } |
|
1678 |
if (w>_screen.width-x) { w = _screen.width-x; } |
|
1679 |
if (w <= 0) return; |
|
1680 |
_cursor.draw_pos.x = x; |
|
1681 |
_cursor.draw_size.x = w; |
|
1682 |
||
1683 |
h = _cursor.size.y; |
|
1684 |
y = _cursor.pos.y + _cursor.offs.y; |
|
1685 |
if (y < 0) { h += y; y=0; } |
|
1686 |
if (h>_screen.height-y) { h = _screen.height-y; } |
|
1687 |
if (h <= 0) return; |
|
1688 |
_cursor.draw_pos.y = y; |
|
1689 |
_cursor.draw_size.y = h; |
|
1690 |
||
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
|
1691 |
assert(w*h < (int) sizeof(_cursor_backup)); |
0 | 1692 |
|
1693 |
// Make backup of stuff below cursor |
|
1694 |
memcpy_pitch( |
|
1695 |
_cursor_backup, |
|
1696 |
_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
|
1697 |
_cursor.draw_size.x, _cursor.draw_size.y, _screen.pitch, _cursor.draw_size.x); |
0 | 1698 |
|
1699 |
// Draw cursor on screen |
|
1700 |
_cur_dpi = &_screen; |
|
1701 |
DrawSprite(_cursor.sprite, _cursor.pos.x, _cursor.pos.y); |
|
1702 |
||
1703 |
_video_driver->make_dirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y); |
|
1704 |
||
1705 |
_cursor.visible = true; |
|
1706 |
_cursor.dirty = false; |
|
1707 |
} |
|
1708 |
||
798 | 1709 |
#if defined(_DEBUG) |
410 | 1710 |
static void DbgScreenRect(int left, int top, int right, int bottom) |
0 | 1711 |
{ |
1712 |
DrawPixelInfo dp,*old; |
|
1713 |
||
1714 |
old = _cur_dpi; |
|
1715 |
_cur_dpi = &dp; |
|
1716 |
dp = _screen; |
|
1717 |
GfxFillRect(left, top, right-1, bottom-1, rand() & 255); |
|
1718 |
_cur_dpi = old; |
|
1719 |
} |
|
798 | 1720 |
#endif |
0 | 1721 |
|
1722 |
extern bool _dbg_screen_rect; |
|
1723 |
||
1724 |
void RedrawScreenRect(int left, int top, int right, int bottom) |
|
1725 |
{ |
|
1726 |
assert(right <= _screen.width && bottom <= _screen.height); |
|
1727 |
if (_cursor.visible) { |
|
1728 |
if (right > _cursor.draw_pos.x && |
|
1729 |
left < _cursor.draw_pos.x + _cursor.draw_size.x && |
|
1730 |
bottom > _cursor.draw_pos.y && |
|
1731 |
top < _cursor.draw_pos.y + _cursor.draw_size.y) { |
|
1732 |
UndrawMouseCursor(); |
|
1733 |
} |
|
1734 |
} |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1735 |
UndrawTextMessage(); |
0 | 1736 |
|
1737 |
#if defined(_DEBUG) |
|
1738 |
if (_dbg_screen_rect) |
|
1739 |
DbgScreenRect(left, top, right, bottom); |
|
1740 |
else |
|
1741 |
#endif |
|
1742 |
DrawOverlappedWindowForAll(left, top, right, bottom); |
|
1743 |
||
1744 |
_video_driver->make_dirty(left, top, right-left, bottom-top); |
|
1745 |
} |
|
1746 |
||
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
|
1747 |
void DrawDirtyBlocks(void) |
0 | 1748 |
{ |
1749 |
byte *b = _dirty_blocks; |
|
1750 |
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
|
1751 |
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
|
1752 |
const int h = (_screen.height + 7) & ~7; |
0 | 1753 |
|
1754 |
do { |
|
1755 |
if (*b != 0) { |
|
1756 |
int left,top; |
|
1757 |
int right = x + 64; |
|
1758 |
int bottom = y; |
|
1759 |
byte *p = b; |
|
1760 |
int h2; |
|
1761 |
// First try coalescing downwards |
|
1762 |
do { |
|
1763 |
*p = 0; |
|
1764 |
p += DIRTY_BYTES_PER_LINE; |
|
1765 |
bottom += 8; |
|
1766 |
} while (bottom != h && *p); |
|
1767 |
||
1768 |
// Try coalescing to the right too. |
|
1769 |
h2 = (bottom - y) >> 3; |
|
1770 |
assert(h2>0); |
|
1771 |
p = b; |
|
1772 |
||
1773 |
while (right != w) { |
|
1774 |
byte *p2 = ++p; |
|
1775 |
int h = h2; |
|
1776 |
// Check if a full line of dirty flags is set. |
|
1777 |
do { |
|
1778 |
if (!*p2) goto no_more_coalesc; |
|
1779 |
p2 += DIRTY_BYTES_PER_LINE; |
|
1780 |
} while (--h); |
|
1781 |
||
1782 |
// Wohoo, can combine it one step to the right! |
|
1783 |
// Do that, and clear the bits. |
|
1784 |
right += 64; |
|
1785 |
||
1786 |
h = h2; |
|
1787 |
p2 = p; |
|
1788 |
do { |
|
1789 |
*p2 = 0; |
|
1790 |
p2 += DIRTY_BYTES_PER_LINE; |
|
1791 |
} while (--h); |
|
1792 |
} |
|
1793 |
no_more_coalesc:; |
|
1794 |
||
1795 |
left = x; |
|
1796 |
top = y; |
|
1797 |
||
1798 |
if (left < _invalid_rect.left)left = _invalid_rect.left; |
|
1799 |
if (top < _invalid_rect.top) top = _invalid_rect.top; |
|
1800 |
if (right > _invalid_rect.right)right = _invalid_rect.right; |
|
1801 |
if (bottom > _invalid_rect.bottom)bottom = _invalid_rect.bottom; |
|
1802 |
||
1803 |
if (left < right && top < bottom) { |
|
1804 |
RedrawScreenRect(left, top, right, bottom); |
|
1805 |
} |
|
1806 |
||
1807 |
} |
|
1808 |
} while (b++, (x+=64) != w || (x=0,b+=-(w>>6)+DIRTY_BYTES_PER_LINE,(y+=8) != h)); |
|
1809 |
||
1810 |
_invalid_rect.left = w; |
|
1811 |
_invalid_rect.top = h; |
|
1812 |
_invalid_rect.right = 0; |
|
1813 |
_invalid_rect.bottom = 0; |
|
1814 |
} |
|
1815 |
||
1816 |
||
1817 |
void SetDirtyBlocks(int left, int top, int right, int bottom) |
|
1818 |
{ |
|
1819 |
byte *b; |
|
1820 |
int width,height,i; |
|
1821 |
||
1822 |
if (left < 0) left = 0; |
|
1823 |
if (top < 0) top = 0; |
|
1824 |
if (right > _screen.width) right = _screen.width; |
|
1825 |
if (bottom > _screen.height) bottom = _screen.height; |
|
1826 |
||
1827 |
if (left >= right || top >= bottom) |
|
1828 |
return; |
|
1829 |
||
1830 |
if (left < _invalid_rect.left) _invalid_rect.left = left; |
|
1831 |
if (top < _invalid_rect.top) _invalid_rect.top = top; |
|
1832 |
if (right > _invalid_rect.right)_invalid_rect.right = right; |
|
1833 |
if (bottom > _invalid_rect.bottom)_invalid_rect.bottom = bottom; |
|
1834 |
||
1835 |
left >>= 6; |
|
1836 |
top >>= 3; |
|
1837 |
||
1838 |
b = _dirty_blocks + top * DIRTY_BYTES_PER_LINE + left; |
|
1839 |
||
1840 |
width = ((right-1) >> 6) - left + 1; |
|
1841 |
height = ((bottom-1) >> 3) - top + 1; |
|
1842 |
||
1843 |
assert(width > 0 && height > 0); |
|
1844 |
||
1845 |
do { |
|
1846 |
i=width; |
|
1847 |
do b[--i] = 0xFF; while (i); |
|
1848 |
||
1849 |
b += DIRTY_BYTES_PER_LINE; |
|
1850 |
} while (--height); |
|
1851 |
} |
|
1852 |
||
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
|
1853 |
void MarkWholeScreenDirty(void) |
0 | 1854 |
{ |
1855 |
SetDirtyBlocks(0, 0, _screen.width, _screen.height); |
|
1856 |
} |
|
1857 |
||
1858 |
bool FillDrawPixelInfo(DrawPixelInfo *n, DrawPixelInfo *o, int left, int top, int width, int height) |
|
1859 |
{ |
|
1860 |
int t; |
|
1861 |
||
1862 |
if (o == NULL) |
|
1863 |
o = _cur_dpi; |
|
1864 |
||
1865 |
n->zoom = 0; |
|
1866 |
||
1867 |
assert(width > 0); |
|
1868 |
assert(height > 0); |
|
1869 |
||
1870 |
n->left = 0; |
|
1871 |
if ((left -= o->left) < 0) { |
|
1872 |
if ((width += left) < 0) |
|
1873 |
return false; |
|
1874 |
n->left = -left; |
|
1875 |
left = 0; |
|
1876 |
} |
|
1877 |
||
1878 |
if ((t=width + left - o->width) > 0) { |
|
1879 |
if ((width -= t) < 0) |
|
1880 |
return false; |
|
1881 |
} |
|
1882 |
n->width = width; |
|
1883 |
||
1884 |
n->top = 0; |
|
1885 |
if ((top -= o->top) < 0) { |
|
1886 |
if ((height += top) < 0) |
|
1887 |
return false; |
|
1888 |
n->top = -top; |
|
1889 |
top = 0; |
|
1890 |
} |
|
1891 |
||
1892 |
n->dst_ptr = o->dst_ptr + left + top * (n->pitch = o->pitch); |
|
1893 |
||
1894 |
if ((t=height + top - o->height) > 0) { |
|
1895 |
if ((height-=t) < 0) |
|
1896 |
return false; |
|
1897 |
} |
|
1898 |
n->height = height; |
|
1899 |
||
1900 |
||
1901 |
return true; |
|
1902 |
} |
|
1903 |
||
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1904 |
static void SetCursorSprite(CursorID cursor) |
0 | 1905 |
{ |
1906 |
CursorVars *cv = &_cursor; |
|
1348 | 1907 |
const Sprite *p; |
0 | 1908 |
|
1909 |
if (cv->sprite == cursor) |
|
1910 |
return; |
|
1911 |
||
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
|
1912 |
p = GetSprite(cursor & 0x3FFF); |
0 | 1913 |
cv->sprite = cursor; |
1348 | 1914 |
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
|
1915 |
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
|
1916 |
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
|
1917 |
cv->offs.y = p->y_offs; |
0 | 1918 |
|
1919 |
cv->dirty = true; |
|
1920 |
} |
|
1921 |
||
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
|
1922 |
static void SwitchAnimatedCursor(void) |
0 | 1923 |
{ |
1924 |
CursorVars *cv = &_cursor; |
|
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1925 |
const CursorID *cur = cv->animate_cur; |
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1926 |
CursorID sprite; |
0 | 1927 |
|
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1928 |
// ANIM_CURSOR_END is 0xFFFF in table/animcursors.h |
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1929 |
if (cur == NULL || *cur == 0xFFFF) cur = cv->animate_list; |
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1930 |
|
0 | 1931 |
sprite = cur[0]; |
1932 |
cv->animate_timeout = cur[1]; |
|
1933 |
cv->animate_cur = cur + 2; |
|
1934 |
||
1935 |
SetCursorSprite(sprite); |
|
1936 |
} |
|
1937 |
||
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
|
1938 |
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
|
1939 |
{ |
0 | 1940 |
CursorVars *cv = &_cursor; |
1941 |
if (cv->animate_timeout && !--cv->animate_timeout) |
|
1942 |
SwitchAnimatedCursor(); |
|
1943 |
} |
|
1944 |
||
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1945 |
void SetMouseCursor(CursorID cursor) |
0 | 1946 |
{ |
1947 |
// Turn off animation |
|
1948 |
_cursor.animate_timeout = 0; |
|
1949 |
// Set cursor |
|
1950 |
SetCursorSprite(cursor); |
|
1951 |
} |
|
1952 |
||
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1953 |
void SetAnimatedMouseCursor(const CursorID *table) |
0 | 1954 |
{ |
1955 |
_cursor.animate_list = table; |
|
1956 |
_cursor.animate_cur = NULL; |
|
1957 |
SwitchAnimatedCursor(); |
|
1958 |
} |
|
1959 |
||
1960 |
bool ChangeResInGame(int w, int h) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
1961 |
{ |
0 | 1962 |
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
|
1963 |
return false; |
0 | 1964 |
|
1965 |
_cur_resolution[0] = w; |
|
1966 |
_cur_resolution[1] = h; |
|
1967 |
return true; |
|
1968 |
} |
|
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
|
1969 |
|
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
|
1970 |
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
|
1971 |
|
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
|
1972 |
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
|
1973 |
{ |
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
|
1974 |
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
|
1975 |
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
|
1976 |
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
|
1977 |
} |
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
|
1978 |
|
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
|
1979 |
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
|
1980 |
{ |
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
|
1981 |
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
|
1982 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1983 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1984 |
uint16 GetDrawStringPlayerColor(byte player) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1985 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1986 |
// 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
|
1987 |
// of the player |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1988 |
if (player == OWNER_SPECTATOR || player == OWNER_SPECTATOR - 1) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1989 |
return 1; |
657
40a9032b454b
(svn r1091) Fix: Finally station names use 100% the correct color in transparent mode
dominik
parents:
619
diff
changeset
|
1990 |
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
|
1991 |
} |