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