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