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