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