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