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