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