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