author | belugas |
Thu, 22 Mar 2007 03:42:43 +0000 | |
changeset 6357 | f0f5e7d1713c |
parent 6248 | e4a2ed7e5613 |
child 6377 | c1bc323eaf0c |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
3 |
/** @file gfx.cpp */ |
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1829
diff
changeset
|
6 |
#include "openttd.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2154
diff
changeset
|
7 |
#include "functions.h" |
4428
6d9fab57f2af
(svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents:
4425
diff
changeset
|
8 |
#include "macros.h" |
1349
15979a2e9001
(svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents:
1348
diff
changeset
|
9 |
#include "spritecache.h" |
1309
4403a69da4f8
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1130
diff
changeset
|
10 |
#include "strings.h" |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
11 |
#include "string.h" |
0 | 12 |
#include "gfx.h" |
13 |
#include "table/palettes.h" |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
14 |
#include "table/sprites.h" |
0 | 15 |
#include "hal.h" |
2153
ecfc674410b4
(svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents:
2134
diff
changeset
|
16 |
#include "variables.h" |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
17 |
#include "table/control_codes.h" |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
18 |
#include "fontcache.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
19 |
#include "genworld.h" |
5217
7a9e91919a93
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
20 |
#include "debug.h" |
0 | 21 |
|
2649
1392cd1a60cc
(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
|
22 |
#ifdef _DEBUG |
1392cd1a60cc
(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
|
23 |
bool _dbg_screen_rect; |
1392cd1a60cc
(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
|
24 |
#endif |
1392cd1a60cc
(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
|
25 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
26 |
byte _dirkeys; ///< 1 = left, 2 = up, 4 = right, 8 = down |
5636
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
27 |
bool _fullscreen; |
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
28 |
CursorVars _cursor; |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
29 |
bool _ctrl_pressed; ///< Is Ctrl pressed? |
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
30 |
bool _shift_pressed; ///< Is Shift pressed? |
5636
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
31 |
byte _fast_forward; |
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
32 |
bool _left_button_down; |
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
33 |
bool _left_button_clicked; |
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
34 |
bool _right_button_down; |
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
35 |
bool _right_button_clicked; |
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
36 |
DrawPixelInfo _screen; |
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
37 |
bool _exit_game; |
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
38 |
bool _networking; ///< are we in networking mode? |
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
39 |
byte _game_mode; |
6231
ff7454d35935
(svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents:
6215
diff
changeset
|
40 |
byte _pause_game; |
5636
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
41 |
int _pal_first_dirty; |
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
42 |
int _pal_last_dirty; |
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
43 |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
44 |
Colour _cur_palette[256]; |
3798
b1f5290b36b1
(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
|
45 |
byte _stringwidth_table[FS_END][224]; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
46 |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
47 |
enum BlitterMode { |
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
48 |
BM_NORMAL, |
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
49 |
BM_COLOUR_REMAP, |
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
50 |
BM_TRANSPARENT, |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
51 |
}; |
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
52 |
|
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
53 |
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode); |
0 | 54 |
|
3798
b1f5290b36b1
(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
|
55 |
FontSize _cur_fontsize; |
b1f5290b36b1
(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
|
56 |
static FontSize _last_fontsize; |
2062 | 57 |
static Pixel _cursor_backup[64 * 64]; |
0 | 58 |
static Rect _invalid_rect; |
1357 | 59 |
static const byte *_color_remap_ptr; |
0 | 60 |
static byte _string_colorremap[3]; |
61 |
||
2010 | 62 |
#define DIRTY_BYTES_PER_LINE (MAX_SCREEN_WIDTH / 64) |
0 | 63 |
static byte _dirty_blocks[DIRTY_BYTES_PER_LINE * MAX_SCREEN_HEIGHT / 8]; |
64 |
||
4949
6bf60913767f
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
65 |
void memcpy_pitch(void *dst, void *src, int w, int h, int srcpitch, int dstpitch) |
0 | 66 |
{ |
4949
6bf60913767f
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
67 |
byte *dstp = (byte*)dst; |
6bf60913767f
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
68 |
byte *srcp = (byte*)src; |
0 | 69 |
|
70 |
assert(h >= 0); |
|
1056
24579058c082
(svn r1557) Replace strange if () do while () construct with a plain for ()
tron
parents:
1009
diff
changeset
|
71 |
for (; h != 0; --h) { |
4949
6bf60913767f
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
72 |
memcpy(dstp, srcp, w); |
6bf60913767f
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
73 |
dstp += dstpitch; |
6bf60913767f
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
74 |
srcp += srcpitch; |
1056
24579058c082
(svn r1557) Replace strange if () do while () construct with a plain for ()
tron
parents:
1009
diff
changeset
|
75 |
} |
0 | 76 |
} |
77 |
||
2010 | 78 |
void GfxScroll(int left, int top, int width, int height, int xo, int yo) |
79 |
{ |
|
2062 | 80 |
const Pixel *src; |
81 |
Pixel *dst; |
|
0 | 82 |
int p; |
83 |
int ht; |
|
84 |
||
2010 | 85 |
if (xo == 0 && yo == 0) return; |
0 | 86 |
|
2010 | 87 |
if (_cursor.visible) UndrawMouseCursor(); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
88 |
UndrawTextMessage(); |
0 | 89 |
|
90 |
p = _screen.pitch; |
|
91 |
||
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
92 |
if (yo > 0) { |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
93 |
/*Calculate pointers */ |
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
94 |
dst = _screen.dst_ptr + (top + height - 1) * p + left; |
0 | 95 |
src = dst - yo * p; |
96 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
97 |
/* Decrease height and increase top */ |
0 | 98 |
top += yo; |
99 |
height -= yo; |
|
100 |
assert(height > 0); |
|
101 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
102 |
/* Adjust left & width */ |
0 | 103 |
if (xo >= 0) { |
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
104 |
dst += xo; |
0 | 105 |
left += xo; |
106 |
width -= xo; |
|
107 |
} else { |
|
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
108 |
src -= xo; |
0 | 109 |
width += xo; |
110 |
} |
|
111 |
||
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
112 |
for (ht = height; ht > 0; --ht) { |
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
113 |
memcpy(dst, src, width); |
0 | 114 |
src -= p; |
115 |
dst -= p; |
|
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
116 |
} |
0 | 117 |
} else { |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
118 |
/* Calculate pointers */ |
0 | 119 |
dst = _screen.dst_ptr + top * p + left; |
120 |
src = dst - yo * p; |
|
121 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
122 |
/* Decrese height. (yo is <=0). */ |
0 | 123 |
height += yo; |
124 |
assert(height > 0); |
|
125 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
126 |
/* Adjust left & width */ |
0 | 127 |
if (xo >= 0) { |
128 |
dst += xo; |
|
129 |
left += xo; |
|
130 |
width -= xo; |
|
131 |
} else { |
|
132 |
src -= xo; |
|
133 |
width += xo; |
|
134 |
} |
|
135 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
136 |
/* the y-displacement may be 0 therefore we have to use memmove, |
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
137 |
* because source and destination may overlap */ |
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
138 |
for (ht = height; ht > 0; --ht) { |
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
139 |
memmove(dst, src, width); |
0 | 140 |
src += p; |
141 |
dst += p; |
|
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
142 |
} |
0 | 143 |
} |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
144 |
/* This part of the screen is now dirty. */ |
375
52d7a943c1e7
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
tron
parents:
332
diff
changeset
|
145 |
_video_driver->make_dirty(left, top, width, height); |
0 | 146 |
} |
147 |
||
148 |
||
2010 | 149 |
void GfxFillRect(int left, int top, int right, int bottom, int color) |
150 |
{ |
|
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2436
diff
changeset
|
151 |
const DrawPixelInfo* dpi = _cur_dpi; |
2062 | 152 |
Pixel *dst; |
332 | 153 |
const int otop = top; |
154 |
const int oleft = left; |
|
0 | 155 |
|
2010 | 156 |
if (dpi->zoom != 0) return; |
157 |
if (left > right || top > bottom) return; |
|
158 |
if (right < dpi->left || left >= dpi->left + dpi->width) return; |
|
159 |
if (bottom < dpi->top || top >= dpi->top + dpi->height) return; |
|
0 | 160 |
|
161 |
if ( (left -= dpi->left) < 0) left = 0; |
|
162 |
right = right - dpi->left + 1; |
|
2010 | 163 |
if (right > dpi->width) right = dpi->width; |
0 | 164 |
right -= left; |
165 |
assert(right > 0); |
|
166 |
||
167 |
if ( (top -= dpi->top) < 0) top = 0; |
|
168 |
bottom = bottom - dpi->top + 1; |
|
2010 | 169 |
if (bottom > dpi->height) bottom = dpi->height; |
0 | 170 |
bottom -= top; |
171 |
assert(bottom > 0); |
|
172 |
||
173 |
dst = dpi->dst_ptr + top * dpi->pitch + left; |
|
174 |
||
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
175 |
if (!HASBIT(color, PALETTE_MODIFIER_GREYOUT)) { |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
176 |
if (!HASBIT(color, USE_COLORTABLE)) { |
0 | 177 |
do { |
178 |
memset(dst, color, right); |
|
179 |
dst += dpi->pitch; |
|
180 |
} while (--bottom); |
|
181 |
} else { |
|
182 |
/* use colortable mode */ |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
183 |
const byte* ctab = GetNonSprite(GB(color, 0, PALETTE_WIDTH)) + 1; |
1357 | 184 |
|
0 | 185 |
do { |
186 |
int i; |
|
2005 | 187 |
for (i = 0; i != right; i++) dst[i] = ctab[dst[i]]; |
0 | 188 |
dst += dpi->pitch; |
189 |
} while (--bottom); |
|
190 |
} |
|
191 |
} else { |
|
332 | 192 |
byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1; |
0 | 193 |
do { |
194 |
int i; |
|
2005 | 195 |
for (i = (bo ^= 1); i < right; i += 2) dst[i] = (byte)color; |
0 | 196 |
dst += dpi->pitch; |
332 | 197 |
} while (--bottom > 0); |
0 | 198 |
} |
199 |
} |
|
200 |
||
410 | 201 |
static void GfxSetPixel(int x, int y, int color) |
0 | 202 |
{ |
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2436
diff
changeset
|
203 |
const DrawPixelInfo* dpi = _cur_dpi; |
0 | 204 |
if ((x-=dpi->left) < 0 || x>=dpi->width || (y-=dpi->top)<0 || y>=dpi->height) |
205 |
return; |
|
2010 | 206 |
dpi->dst_ptr[y * dpi->pitch + x] = color; |
0 | 207 |
} |
208 |
||
209 |
void GfxDrawLine(int x, int y, int x2, int y2, int color) |
|
210 |
{ |
|
211 |
int dy; |
|
212 |
int dx; |
|
2010 | 213 |
int stepx; |
214 |
int stepy; |
|
0 | 215 |
int frac; |
216 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
217 |
/* Check clipping first */ |
0 | 218 |
{ |
4522 | 219 |
DrawPixelInfo *dpi = _cur_dpi; |
0 | 220 |
int t; |
221 |
||
2010 | 222 |
if (x < dpi->left && x2 < dpi->left) return; |
0 | 223 |
|
2010 | 224 |
if (y < dpi->top && y2 < dpi->top) return; |
0 | 225 |
|
226 |
t = dpi->left + dpi->width; |
|
2010 | 227 |
if (x > t && x2 > t) return; |
0 | 228 |
|
229 |
t = dpi->top + dpi->height; |
|
2010 | 230 |
if (y > t && y2 > t) return; |
0 | 231 |
} |
232 |
||
233 |
dy = (y2 - y) * 2; |
|
2010 | 234 |
if (dy < 0) { |
235 |
dy = -dy; |
|
236 |
stepy = -1; |
|
237 |
} else { |
|
238 |
stepy = 1; |
|
239 |
} |
|
0 | 240 |
|
241 |
dx = (x2 - x) * 2; |
|
2010 | 242 |
if (dx < 0) { |
243 |
dx = -dx; |
|
244 |
stepx = -1; |
|
245 |
} else { |
|
246 |
stepx = 1; |
|
247 |
} |
|
0 | 248 |
|
249 |
GfxSetPixel(x, y, color); |
|
250 |
if (dx > dy) { |
|
251 |
frac = dy - (dx >> 1); |
|
252 |
while (x != x2) { |
|
253 |
if (frac >= 0) { |
|
254 |
y += stepy; |
|
255 |
frac -= dx; |
|
256 |
} |
|
257 |
x += stepx; |
|
258 |
frac += dy; |
|
259 |
GfxSetPixel(x, y, color); |
|
260 |
} |
|
261 |
} else { |
|
262 |
frac = dx - (dy >> 1); |
|
263 |
while (y != y2) { |
|
264 |
if (frac >= 0) { |
|
265 |
x += stepx; |
|
266 |
frac -= dy; |
|
267 |
} |
|
268 |
y += stepy; |
|
269 |
frac += dx; |
|
270 |
GfxSetPixel(x, y, color); |
|
271 |
} |
|
272 |
} |
|
273 |
} |
|
274 |
||
3798
b1f5290b36b1
(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
|
275 |
|
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
276 |
/** Truncate a given string to a maximum width if neccessary. |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
277 |
* If the string is truncated, add three dots ('...') to show this. |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
278 |
* @param *dest string that is checked and possibly truncated |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
279 |
* @param maxw maximum width in pixels of the string |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
280 |
* @return new width of (truncated) string */ |
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
281 |
static int TruncateString(char *str, int maxw) |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
282 |
{ |
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
283 |
int w = 0; |
3798
b1f5290b36b1
(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
|
284 |
FontSize size = _cur_fontsize; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
285 |
int ddd, ddd_w; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
286 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
287 |
WChar c; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
288 |
char *ddd_pos; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
289 |
|
3798
b1f5290b36b1
(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
|
290 |
ddd_w = ddd = GetCharacterWidth(size, '.') * 3; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
291 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
292 |
for (ddd_pos = str; (c = Utf8Consume((const char **)&str)) != '\0'; ) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
293 |
if (IsPrintable(c)) { |
3798
b1f5290b36b1
(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
|
294 |
w += GetCharacterWidth(size, c); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
295 |
|
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
296 |
if (w >= maxw) { |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
297 |
/* string got too big... insert dotdotdot */ |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
298 |
ddd_pos[0] = ddd_pos[1] = ddd_pos[2] = '.'; |
6215
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
299 |
ddd_pos[3] = '\0'; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
300 |
return ddd_w; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
301 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
302 |
} else { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
303 |
if (c == SCC_SETX) str++; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
304 |
else if (c == SCC_SETXY) str += 2; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
305 |
else if (c == SCC_TINYFONT) { |
3798
b1f5290b36b1
(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
|
306 |
size = FS_SMALL; |
b1f5290b36b1
(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
|
307 |
ddd = GetCharacterWidth(size, '.') * 3; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
308 |
} else if (c == SCC_BIGFONT) { |
3798
b1f5290b36b1
(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
|
309 |
size = FS_LARGE; |
b1f5290b36b1
(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
|
310 |
ddd = GetCharacterWidth(size, '.') * 3; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
311 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
312 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
313 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
314 |
/* Remember the last position where three dots fit. */ |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
315 |
if (w + ddd < maxw) { |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
316 |
ddd_w = w + ddd; |
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
317 |
ddd_pos = str; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
318 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
319 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
320 |
|
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
321 |
return w; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
322 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
323 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
324 |
static inline int TruncateStringID(StringID src, char *dest, int maxw, const char* last) |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
325 |
{ |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
326 |
GetString(dest, src, last); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
327 |
return TruncateString(dest, maxw); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
328 |
} |
0 | 329 |
|
330 |
/* returns right coordinate */ |
|
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
331 |
int DrawString(int x, int y, StringID str, uint16 color) |
0 | 332 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
333 |
char buffer[512]; |
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
334 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
335 |
GetString(buffer, str, lastof(buffer)); |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
336 |
return DoDrawString(buffer, x, y, color); |
0 | 337 |
} |
338 |
||
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
339 |
int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw) |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
340 |
{ |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
341 |
char buffer[512]; |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
342 |
TruncateStringID(str, buffer, maxw, lastof(buffer)); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
343 |
return DoDrawString(buffer, x, y, color); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
344 |
} |
0 | 345 |
|
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
346 |
|
4314
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
347 |
int DrawStringRightAligned(int x, int y, StringID str, uint16 color) |
0 | 348 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
349 |
char buffer[512]; |
4314
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
350 |
int w; |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
351 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
352 |
GetString(buffer, str, lastof(buffer)); |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
353 |
w = GetStringBoundingBox(buffer).width; |
4314
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
354 |
DoDrawString(buffer, x - w, y, color); |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
355 |
|
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
356 |
return w; |
0 | 357 |
} |
358 |
||
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
359 |
void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw) |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
360 |
{ |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
361 |
char buffer[512]; |
0 | 362 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
363 |
TruncateStringID(str, buffer, maxw, lastof(buffer)); |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
364 |
DoDrawString(buffer, x - GetStringBoundingBox(buffer).width, y, color); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
365 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
366 |
|
4314
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
367 |
void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color) |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
368 |
{ |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
369 |
int w = DrawStringRightAligned(x, y, str, color); |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
370 |
GfxFillRect(x - w, y + 10, x, y + 10, _string_colorremap[1]); |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
371 |
} |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
372 |
|
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
373 |
|
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
374 |
int DrawStringCentered(int x, int y, StringID str, uint16 color) |
0 | 375 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
376 |
char buffer[512]; |
0 | 377 |
int w; |
378 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
379 |
GetString(buffer, str, lastof(buffer)); |
0 | 380 |
|
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
381 |
w = GetStringBoundingBox(buffer).width; |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
382 |
DoDrawString(buffer, x - w / 2, y, color); |
0 | 383 |
|
384 |
return w; |
|
385 |
} |
|
386 |
||
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
387 |
int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color) |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
388 |
{ |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
389 |
char buffer[512]; |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
390 |
int w = TruncateStringID(str, buffer, xr - xl, lastof(buffer)); |
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
391 |
return DoDrawString(buffer, (xl + xr - w) / 2, y, color); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
392 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
393 |
|
2134 | 394 |
int DoDrawStringCentered(int x, int y, const char *str, uint16 color) |
395 |
{ |
|
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
396 |
int w = GetStringBoundingBox(str).width; |
2134 | 397 |
DoDrawString(str, x - w / 2, y, color); |
398 |
return w; |
|
399 |
} |
|
400 |
||
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
401 |
void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color) |
0 | 402 |
{ |
403 |
int w = DrawStringCentered(x, y, str, color); |
|
2010 | 404 |
GfxFillRect(x - (w >> 1), y + 10, x - (w >> 1) + w, y + 10, _string_colorremap[1]); |
0 | 405 |
} |
406 |
||
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
407 |
void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color) |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
408 |
{ |
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
409 |
int w = DrawStringCenteredTruncated(xl, xr, y, str, color); |
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
410 |
GfxFillRect((xl + xr - w) / 2, y + 10, (xl + xr + w) / 2, y + 10, _string_colorremap[1]); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
411 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
412 |
|
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
413 |
/** 'Correct' a string to a maximum length. Longer strings will be cut into |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
414 |
* additional lines at whitespace characters if possible. The string parameter |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
415 |
* is modified with terminating characters mid-string which are the |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
416 |
* placeholders for the newlines.<br/> |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
417 |
* The string WILL be truncated if there was no whitespace for the current |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
418 |
* line's maximum width. |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
419 |
* |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
420 |
* @note To know if the the terminating '\0' is the string end or just a |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
421 |
* newline, the returned 'num' value should be consulted. The num'th '\0', |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
422 |
* starting with index 0 is the real string end. |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
423 |
* |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
424 |
* @param str string to check and correct for length restrictions |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
425 |
* @param maxw the maximum width the string can have on one line |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
426 |
* @return return a 32bit wide number consisting of 2 packed values: |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
427 |
* 0 - 15 the number of lines ADDED to the string |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
428 |
* 16 - 31 the fontsize in which the length calculation was done at */ |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
429 |
uint32 FormatStringLinebreaks(char *str, int maxw) |
1095 | 430 |
{ |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
431 |
FontSize size = _cur_fontsize; |
0 | 432 |
int num = 0; |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
433 |
|
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
434 |
assert(maxw > 0); |
0 | 435 |
|
2952 | 436 |
for (;;) { |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
437 |
char *last_space = NULL; |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
438 |
int w = 0; |
0 | 439 |
|
2952 | 440 |
for (;;) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
441 |
WChar c = Utf8Consume((const char **)&str); |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
442 |
/* whitespace is where we will insert the line-break */ |
6215
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
443 |
if (IsWhitespace(c)) last_space = str; |
0 | 444 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
445 |
if (IsPrintable(c)) { |
3798
b1f5290b36b1
(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
|
446 |
w += GetCharacterWidth(size, c); |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
447 |
/* string is longer than maximum width so we need to decide what to |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
448 |
* do. We can do two things: |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
449 |
* 1. If no whitespace was found at all up until now (on this line) then |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
450 |
* we will truncate the string and bail out. |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
451 |
* 2. In all other cases force a linebreak at the last seen whitespace */ |
0 | 452 |
if (w > maxw) { |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
453 |
if (last_space == NULL) { |
6215
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
454 |
*Utf8PrevChar(str) = '\0'; |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
455 |
return num + (size << 16); |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
456 |
} |
0 | 457 |
str = last_space; |
458 |
break; |
|
459 |
} |
|
460 |
} else { |
|
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
461 |
switch (c) { |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
462 |
case '\0': return num + (size << 16); break; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
463 |
case SCC_SETX: str++; break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
464 |
case SCC_SETXY: str +=2; break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
465 |
case SCC_TINYFONT: size = FS_SMALL; break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
466 |
case SCC_BIGFONT: size = FS_LARGE; break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
467 |
case '\n': goto end_of_inner_loop; |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
468 |
} |
0 | 469 |
} |
470 |
} |
|
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
471 |
end_of_inner_loop: |
6215
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
472 |
/* String didn't fit on line (or a '\n' was encountered), so 'dummy' terminate |
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
473 |
* and increase linecount. We use Utf8PrevChar() as also non 1 char long |
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
474 |
* whitespace seperators are supported */ |
0 | 475 |
num++; |
6215
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
476 |
char *s = Utf8PrevChar(str); |
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
477 |
*s++ = '\0'; |
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
478 |
|
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
479 |
/* In which case (see above) we will shift remainder to left and close the gap */ |
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
480 |
if (str - s >= 1) { |
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
481 |
for (; str[-1] != '\0';) *s++ = *str++; |
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
482 |
} |
0 | 483 |
} |
484 |
} |
|
485 |
||
5391
18028f19893d
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5380
diff
changeset
|
486 |
/** Draw a given string with the centre around the given x coordinates |
18028f19893d
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5380
diff
changeset
|
487 |
* @param x Centre the string around this pixel width |
18028f19893d
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5380
diff
changeset
|
488 |
* @param y Draw the string at this pixel height (first line's bottom) |
18028f19893d
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5380
diff
changeset
|
489 |
* @param str String to draw |
18028f19893d
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5380
diff
changeset
|
490 |
* @param max Maximum width the string can have before it is wrapped */ |
2634
0df9396b0067
(svn r3176) Use proper types, not some variants of int
tron
parents:
2631
diff
changeset
|
491 |
void DrawStringMultiCenter(int x, int y, StringID str, int maxw) |
0 | 492 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
493 |
char buffer[512]; |
0 | 494 |
uint32 tmp; |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2548
diff
changeset
|
495 |
int num, w, mt; |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
496 |
const char *src; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
497 |
WChar c; |
0 | 498 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
499 |
GetString(buffer, str, lastof(buffer)); |
0 | 500 |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
501 |
tmp = FormatStringLinebreaks(buffer, maxw); |
2635 | 502 |
num = GB(tmp, 0, 16); |
0 | 503 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
504 |
mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16)); |
0 | 505 |
|
506 |
y -= (mt >> 1) * num; |
|
507 |
||
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
508 |
src = buffer; |
0 | 509 |
|
2952 | 510 |
for (;;) { |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
511 |
w = GetStringBoundingBox(src).width; |
0 | 512 |
DoDrawString(src, x - (w>>1), y, 0xFE); |
3798
b1f5290b36b1
(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
|
513 |
_cur_fontsize = _last_fontsize; |
0 | 514 |
|
2952 | 515 |
for (;;) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
516 |
c = Utf8Consume(&src); |
0 | 517 |
if (c == 0) { |
518 |
y += mt; |
|
519 |
if (--num < 0) { |
|
3798
b1f5290b36b1
(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
|
520 |
_cur_fontsize = FS_NORMAL; |
0 | 521 |
return; |
522 |
} |
|
523 |
break; |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
524 |
} else if (c == SCC_SETX) { |
0 | 525 |
src++; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
526 |
} else if (c == SCC_SETXY) { |
0 | 527 |
src+=2; |
528 |
} |
|
529 |
} |
|
530 |
} |
|
531 |
} |
|
532 |
||
4928
ff53f78c5a87
(svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents:
4912
diff
changeset
|
533 |
|
ff53f78c5a87
(svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents:
4912
diff
changeset
|
534 |
uint DrawStringMultiLine(int x, int y, StringID str, int maxw) |
2010 | 535 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
536 |
char buffer[512]; |
0 | 537 |
uint32 tmp; |
2753 | 538 |
int num, mt; |
4928
ff53f78c5a87
(svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents:
4912
diff
changeset
|
539 |
uint total_height; |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
540 |
const char *src; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
541 |
WChar c; |
0 | 542 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
543 |
GetString(buffer, str, lastof(buffer)); |
0 | 544 |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
545 |
tmp = FormatStringLinebreaks(buffer, maxw); |
2635 | 546 |
num = GB(tmp, 0, 16); |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2548
diff
changeset
|
547 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
548 |
mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16)); |
4928
ff53f78c5a87
(svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents:
4912
diff
changeset
|
549 |
total_height = (num + 1) * mt; |
0 | 550 |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
551 |
src = buffer; |
0 | 552 |
|
2952 | 553 |
for (;;) { |
0 | 554 |
DoDrawString(src, x, y, 0xFE); |
3798
b1f5290b36b1
(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
|
555 |
_cur_fontsize = _last_fontsize; |
0 | 556 |
|
2952 | 557 |
for (;;) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
558 |
c = Utf8Consume(&src); |
0 | 559 |
if (c == 0) { |
560 |
y += mt; |
|
561 |
if (--num < 0) { |
|
3798
b1f5290b36b1
(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
|
562 |
_cur_fontsize = FS_NORMAL; |
4928
ff53f78c5a87
(svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents:
4912
diff
changeset
|
563 |
return total_height; |
0 | 564 |
} |
565 |
break; |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
566 |
} else if (c == SCC_SETX) { |
0 | 567 |
src++; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
568 |
} else if (c == SCC_SETXY) { |
0 | 569 |
src+=2; |
570 |
} |
|
571 |
} |
|
572 |
} |
|
573 |
} |
|
574 |
||
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
575 |
/** Return the string dimension in pixels. The height and width are returned |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
576 |
* in a single BoundingRect value. TINYFONT, BIGFONT modifiers are only |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
577 |
* supported as the first character of the string. The returned dimensions |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
578 |
* are therefore a rough estimation correct for all the current strings |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
579 |
* but not every possible combination |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
580 |
* @param str string to calculate pixel-width |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
581 |
* @return string width and height in pixels */ |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
582 |
BoundingRect GetStringBoundingBox(const char *str) |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
583 |
{ |
3798
b1f5290b36b1
(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
|
584 |
FontSize size = _cur_fontsize; |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
585 |
BoundingRect br; |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
586 |
int max_width; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
587 |
WChar c; |
4557
fe3fbd6204aa
(svn r6404) -Fix: GetStringWidth failed to calculate correct string width if the string
Darkvater
parents:
4525
diff
changeset
|
588 |
|
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
589 |
br.width = br.height = max_width = 0; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
590 |
for (;;) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
591 |
c = Utf8Consume(&str); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
592 |
if (c == 0) break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
593 |
if (IsPrintable(c)) { |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
594 |
br.width += GetCharacterWidth(size, c); |
0 | 595 |
} else { |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
596 |
switch (c) { |
5391
18028f19893d
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5380
diff
changeset
|
597 |
case SCC_SETX: br.width += (byte)*str++; break; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
598 |
case SCC_SETXY: |
5391
18028f19893d
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5380
diff
changeset
|
599 |
br.width += (byte)*str++; |
18028f19893d
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5380
diff
changeset
|
600 |
br.height += (byte)*str++; |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
601 |
break; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
602 |
case SCC_TINYFONT: size = FS_SMALL; break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
603 |
case SCC_BIGFONT: size = FS_LARGE; break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
604 |
case '\n': |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
605 |
br.height += GetCharacterHeight(size); |
4610
f264efbf7f4f
(svn r6463) -Fix (r6462): Reset the string width to zero on every new line of course...
Darkvater
parents:
4609
diff
changeset
|
606 |
if (br.width > max_width) max_width = br.width; |
f264efbf7f4f
(svn r6463) -Fix (r6462): Reset the string width to zero on every new line of course...
Darkvater
parents:
4609
diff
changeset
|
607 |
br.width = 0; |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
608 |
break; |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
609 |
} |
0 | 610 |
} |
611 |
} |
|
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
612 |
br.height += GetCharacterHeight(size); |
4557
fe3fbd6204aa
(svn r6404) -Fix: GetStringWidth failed to calculate correct string width if the string
Darkvater
parents:
4525
diff
changeset
|
613 |
|
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
614 |
br.width = max(br.width, max_width); |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
615 |
return br; |
0 | 616 |
} |
617 |
||
4949
6bf60913767f
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
618 |
/** Draw a string at the given coordinates with the given colour |
6bf60913767f
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
619 |
* @param string the string to draw |
6bf60913767f
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
620 |
* @param x offset from left side of the screen, if negative offset from the right side |
6bf60913767f
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
621 |
* @param x offset from top side of the screen, if negative offset from the bottom |
6bf60913767f
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
622 |
* @param real_color colour of the string, see _string_colormap in |
6bf60913767f
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
623 |
* table/palettes.h or docs/ottd-colourtext-palette.png |
6bf60913767f
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
624 |
* @return the x-coordinates where the drawing has finished. If nothing is drawn |
6bf60913767f
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
625 |
* the originally passed x-coordinate is returned */ |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
626 |
int DoDrawString(const char *string, int x, int y, uint16 real_color) |
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
627 |
{ |
4522 | 628 |
DrawPixelInfo *dpi = _cur_dpi; |
3798
b1f5290b36b1
(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
|
629 |
FontSize size = _cur_fontsize; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
630 |
WChar c; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
631 |
byte color; |
0 | 632 |
int xo = x, yo = y; |
633 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
634 |
color = real_color & 0xFF; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
635 |
|
0 | 636 |
if (color != 0xFE) { |
637 |
if (x >= dpi->left + dpi->width || |
|
638 |
x + _screen.width*2 <= dpi->left || |
|
639 |
y >= dpi->top + dpi->height || |
|
640 |
y + _screen.height <= dpi->top) |
|
641 |
return x; |
|
642 |
||
643 |
if (color != 0xFF) { |
|
644 |
switch_color:; |
|
657
d4d36b4853ec
(svn r1091) Fix: Finally station names use 100% the correct color in transparent mode
dominik
parents:
619
diff
changeset
|
645 |
if (real_color & IS_PALETTE_COLOR) { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
646 |
_string_colorremap[1] = color; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
647 |
_string_colorremap[2] = 215; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
648 |
} else { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
649 |
_string_colorremap[1] = _string_colormap[color].text; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
650 |
_string_colorremap[2] = _string_colormap[color].shadow; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
651 |
} |
0 | 652 |
_color_remap_ptr = _string_colorremap; |
653 |
} |
|
654 |
} |
|
655 |
||
656 |
check_bounds: |
|
657 |
if (y + 19 <= dpi->top || dpi->top + dpi->height <= y) { |
|
658 |
skip_char:; |
|
2952 | 659 |
for (;;) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
660 |
c = Utf8Consume(&string); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
661 |
if (!IsPrintable(c)) goto skip_cont; |
0 | 662 |
} |
663 |
} |
|
664 |
||
2952 | 665 |
for (;;) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
666 |
c = Utf8Consume(&string); |
0 | 667 |
skip_cont:; |
668 |
if (c == 0) { |
|
3798
b1f5290b36b1
(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
|
669 |
_last_fontsize = size; |
0 | 670 |
return x; |
671 |
} |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
672 |
if (IsPrintable(c)) { |
0 | 673 |
if (x >= dpi->left + dpi->width) goto skip_char; |
674 |
if (x + 26 >= dpi->left) { |
|
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
675 |
GfxMainBlitter(GetGlyph(size, c), x, y, BM_COLOUR_REMAP); |
0 | 676 |
} |
3798
b1f5290b36b1
(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
|
677 |
x += GetCharacterWidth(size, c); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
678 |
} else if (c == '\n') { // newline = {} |
0 | 679 |
x = xo; |
3798
b1f5290b36b1
(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
|
680 |
y += GetCharacterHeight(size); |
0 | 681 |
goto check_bounds; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
682 |
} else if (c >= SCC_BLUE && c <= SCC_BLACK) { // change color? |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
683 |
color = (byte)(c - SCC_BLUE); |
0 | 684 |
goto switch_color; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
685 |
} else if (c == SCC_SETX) { // {SETX} |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
686 |
x = xo + (byte)*string++; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
687 |
} else if (c == SCC_SETXY) {// {SETXY} |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
688 |
x = xo + (byte)*string++; |
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
689 |
y = yo + (byte)*string++; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
690 |
} else if (c == SCC_TINYFONT) { // {TINYFONT} |
3798
b1f5290b36b1
(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
|
691 |
size = FS_SMALL; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
692 |
} else if (c == SCC_BIGFONT) { // {BIGFONT} |
3798
b1f5290b36b1
(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
|
693 |
size = FS_LARGE; |
0 | 694 |
} else { |
5391
18028f19893d
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5380
diff
changeset
|
695 |
DEBUG(misc, 0, "[utf8] unknown string command character %d", c); |
0 | 696 |
} |
697 |
} |
|
698 |
} |
|
699 |
||
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
700 |
int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw) |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
701 |
{ |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
702 |
char buffer[512]; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
703 |
ttd_strlcpy(buffer, str, sizeof(buffer)); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
704 |
TruncateString(buffer, maxw); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
705 |
return DoDrawString(buffer, x, y, color); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
706 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
707 |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
708 |
void DrawSprite(SpriteID img, SpriteID pal, int x, int y) |
2010 | 709 |
{ |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
710 |
if (HASBIT(img, PALETTE_MODIFIER_TRANSPARENT)) { |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
711 |
_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH)) + 1; |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
712 |
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_TRANSPARENT); |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
713 |
} else if (pal != PAL_NONE) { |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
714 |
_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH)) + 1; |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
715 |
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_COLOUR_REMAP); |
0 | 716 |
} else { |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
717 |
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_NORMAL); |
0 | 718 |
} |
719 |
} |
|
720 |
||
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
721 |
struct BlitterParams { |
0 | 722 |
int start_x, start_y; |
4171 | 723 |
const byte *sprite; |
2062 | 724 |
Pixel *dst; |
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
725 |
BlitterMode mode; |
0 | 726 |
int width, height; |
2010 | 727 |
int width_org; |
0 | 728 |
int pitch; |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
729 |
}; |
0 | 730 |
|
731 |
static void GfxBlitTileZoomIn(BlitterParams *bp) |
|
732 |
{ |
|
4171 | 733 |
const byte *src_o = bp->sprite; |
734 |
const byte *src; |
|
0 | 735 |
int num, skip; |
736 |
byte done; |
|
2062 | 737 |
Pixel *dst; |
4171 | 738 |
const byte *ctab; |
0 | 739 |
|
4516 | 740 |
src_o += ReadLE16Aligned(src_o + bp->start_y * 2); |
741 |
switch (bp->mode) { |
|
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
742 |
case BM_COLOUR_REMAP: |
0 | 743 |
do { |
4516 | 744 |
do { |
745 |
done = src_o[0]; |
|
746 |
num = done & 0x7F; |
|
747 |
skip = src_o[1]; |
|
748 |
src = src_o + 2; |
|
749 |
src_o += num + 2; |
|
0 | 750 |
|
4516 | 751 |
dst = bp->dst; |
0 | 752 |
|
4516 | 753 |
if ( (skip -= bp->start_x) > 0) { |
754 |
dst += skip; |
|
755 |
} else { |
|
756 |
src -= skip; |
|
757 |
num += skip; |
|
758 |
if (num <= 0) continue; |
|
759 |
skip = 0; |
|
760 |
} |
|
0 | 761 |
|
4516 | 762 |
skip = skip + num - bp->width; |
763 |
if (skip > 0) { |
|
764 |
num -= skip; |
|
765 |
if (num <= 0) continue; |
|
766 |
} |
|
0 | 767 |
|
4516 | 768 |
ctab = _color_remap_ptr; |
769 |
||
770 |
for (; num >= 4; num -=4) { |
|
771 |
dst[3] = ctab[src[3]]; |
|
772 |
dst[2] = ctab[src[2]]; |
|
773 |
dst[1] = ctab[src[1]]; |
|
774 |
dst[0] = ctab[src[0]]; |
|
0 | 775 |
dst += 4; |
776 |
src += 4; |
|
4516 | 777 |
} |
778 |
for (; num != 0; num--) *dst++ = ctab[*src++]; |
|
779 |
} while (!(done & 0x80)); |
|
780 |
||
781 |
bp->dst += bp->pitch; |
|
782 |
} while (--bp->height != 0); |
|
783 |
break; |
|
784 |
||
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
785 |
case BM_TRANSPARENT: |
4516 | 786 |
do { |
787 |
do { |
|
788 |
done = src_o[0]; |
|
789 |
num = done & 0x7F; |
|
790 |
skip = src_o[1]; |
|
791 |
src_o += num + 2; |
|
792 |
||
793 |
dst = bp->dst; |
|
794 |
||
795 |
if ( (skip -= bp->start_x) > 0) { |
|
796 |
dst += skip; |
|
797 |
} else { |
|
798 |
num += skip; |
|
799 |
if (num <= 0) continue; |
|
800 |
skip = 0; |
|
801 |
} |
|
802 |
||
803 |
skip = skip + num - bp->width; |
|
804 |
if (skip > 0) { |
|
805 |
num -= skip; |
|
806 |
if (num <= 0) continue; |
|
807 |
} |
|
808 |
||
809 |
ctab = _color_remap_ptr; |
|
810 |
for (; num != 0; num--) { |
|
811 |
*dst = ctab[*dst]; |
|
812 |
dst++; |
|
813 |
} |
|
814 |
} while (!(done & 0x80)); |
|
815 |
||
816 |
bp->dst += bp->pitch; |
|
817 |
} while (--bp->height != 0); |
|
818 |
break; |
|
819 |
||
820 |
default: |
|
821 |
do { |
|
822 |
do { |
|
823 |
done = src_o[0]; |
|
824 |
num = done & 0x7F; |
|
825 |
skip = src_o[1]; |
|
826 |
src = src_o + 2; |
|
827 |
src_o += num + 2; |
|
828 |
||
829 |
dst = bp->dst; |
|
830 |
||
831 |
if ( (skip -= bp->start_x) > 0) { |
|
832 |
dst += skip; |
|
833 |
} else { |
|
834 |
src -= skip; |
|
835 |
num += skip; |
|
836 |
if (num <= 0) continue; |
|
837 |
skip = 0; |
|
838 |
} |
|
839 |
||
840 |
skip = skip + num - bp->width; |
|
841 |
if (skip > 0) { |
|
842 |
num -= skip; |
|
843 |
if (num <= 0) continue; |
|
844 |
} |
|
845 |
#if defined(_WIN32) |
|
846 |
if (num & 1) *dst++ = *src++; |
|
847 |
if (num & 2) { *(uint16*)dst = *(uint16*)src; dst += 2; src += 2; } |
|
848 |
if (num >>= 2) { |
|
849 |
do { |
|
850 |
*(uint32*)dst = *(uint32*)src; |
|
851 |
dst += 4; |
|
852 |
src += 4; |
|
853 |
} while (--num != 0); |
|
854 |
} |
|
0 | 855 |
#else |
4516 | 856 |
memcpy(dst, src, num); |
0 | 857 |
#endif |
4516 | 858 |
} while (!(done & 0x80)); |
0 | 859 |
|
4516 | 860 |
bp->dst += bp->pitch; |
861 |
} while (--bp->height != 0); |
|
862 |
break; |
|
0 | 863 |
} |
864 |
} |
|
865 |
||
866 |
static void GfxBlitZoomInUncomp(BlitterParams *bp) |
|
867 |
{ |
|
1357 | 868 |
const byte *src = bp->sprite; |
2062 | 869 |
Pixel *dst = bp->dst; |
0 | 870 |
int height = bp->height; |
871 |
int width = bp->width; |
|
872 |
int i; |
|
873 |
||
874 |
assert(height > 0); |
|
875 |
assert(width > 0); |
|
876 |
||
4516 | 877 |
switch (bp->mode) { |
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
878 |
case BM_COLOUR_REMAP: { |
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
879 |
const byte *ctab = _color_remap_ptr; |
2004 | 880 |
|
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
881 |
do { |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
882 |
for (i = 0; i != width; i++) { |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
883 |
byte b = ctab[src[i]]; |
0 | 884 |
|
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
885 |
if (b != 0) dst[i] = b; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
886 |
} |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
887 |
src += bp->width_org; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
888 |
dst += bp->pitch; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
889 |
} while (--height != 0); |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
890 |
break; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
891 |
} |
0 | 892 |
|
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
893 |
case BM_TRANSPARENT: { |
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
894 |
const byte *ctab = _color_remap_ptr; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
895 |
|
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
896 |
do { |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
897 |
for (i = 0; i != width; i++) |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
898 |
if (src[i] != 0) dst[i] = ctab[dst[i]]; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
899 |
src += bp->width_org; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
900 |
dst += bp->pitch; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
901 |
} while (--height != 0); |
4516 | 902 |
break; |
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
903 |
} |
4516 | 904 |
|
905 |
default: |
|
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
906 |
do { |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
907 |
int n = width; |
4516 | 908 |
|
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
909 |
for (; n >= 4; n -= 4) { |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
910 |
if (src[0] != 0) dst[0] = src[0]; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
911 |
if (src[1] != 0) dst[1] = src[1]; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
912 |
if (src[2] != 0) dst[2] = src[2]; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
913 |
if (src[3] != 0) dst[3] = src[3]; |
4516 | 914 |
|
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
915 |
dst += 4; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
916 |
src += 4; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
917 |
} |
4516 | 918 |
|
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
919 |
for (; n != 0; n--) { |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
920 |
if (src[0] != 0) dst[0] = src[0]; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
921 |
src++; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
922 |
dst++; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
923 |
} |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
924 |
|
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
925 |
src += bp->width_org - width; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
926 |
dst += bp->pitch - width; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
927 |
} while (--height != 0); |
4516 | 928 |
break; |
0 | 929 |
} |
930 |
} |
|
931 |
||
932 |
static void GfxBlitTileZoomMedium(BlitterParams *bp) |
|
933 |
{ |
|
4171 | 934 |
const byte *src_o = bp->sprite; |
935 |
const byte *src; |
|
0 | 936 |
int num, skip; |
937 |
byte done; |
|
2062 | 938 |
Pixel *dst; |
4171 | 939 |
const byte *ctab; |
0 | 940 |
|
4516 | 941 |
src_o += ReadLE16Aligned(src_o + bp->start_y * 2); |
942 |
switch (bp->mode) { |
|
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
943 |
case BM_COLOUR_REMAP: |
0 | 944 |
do { |
4516 | 945 |
do { |
946 |
done = src_o[0]; |
|
947 |
num = done & 0x7F; |
|
948 |
skip = src_o[1]; |
|
949 |
src = src_o + 2; |
|
950 |
src_o += num + 2; |
|
0 | 951 |
|
4516 | 952 |
dst = bp->dst; |
0 | 953 |
|
4516 | 954 |
if (skip & 1) { |
955 |
skip++; |
|
956 |
src++; |
|
957 |
if (--num == 0) continue; |
|
958 |
} |
|
0 | 959 |
|
4516 | 960 |
if ( (skip -= bp->start_x) > 0) { |
961 |
dst += skip >> 1; |
|
962 |
} else { |
|
963 |
src -= skip; |
|
964 |
num += skip; |
|
965 |
if (num <= 0) continue; |
|
966 |
skip = 0; |
|
967 |
} |
|
0 | 968 |
|
4516 | 969 |
skip = skip + num - bp->width; |
970 |
if (skip > 0) { |
|
971 |
num -= skip; |
|
972 |
if (num <= 0) continue; |
|
973 |
} |
|
0 | 974 |
|
4516 | 975 |
ctab = _color_remap_ptr; |
976 |
num = (num + 1) >> 1; |
|
977 |
for (; num != 0; num--) { |
|
978 |
*dst = ctab[*src]; |
|
979 |
dst++; |
|
980 |
src += 2; |
|
981 |
} |
|
982 |
} while (!(done & 0x80)); |
|
983 |
bp->dst += bp->pitch; |
|
984 |
if (--bp->height == 0) return; |
|
0 | 985 |
|
4516 | 986 |
do { |
987 |
done = src_o[0]; |
|
988 |
src_o += (done & 0x7F) + 2; |
|
989 |
} while (!(done & 0x80)); |
|
990 |
} while (--bp->height != 0); |
|
991 |
break; |
|
992 |
||
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
993 |
case BM_TRANSPARENT: |
0 | 994 |
do { |
4516 | 995 |
do { |
996 |
done = src_o[0]; |
|
997 |
num = done & 0x7F; |
|
998 |
skip = src_o[1]; |
|
999 |
src_o += num + 2; |
|
1000 |
||
1001 |
dst = bp->dst; |
|
1002 |
||
1003 |
if (skip & 1) { |
|
1004 |
skip++; |
|
1005 |
if (--num == 0) continue; |
|
1006 |
} |
|
1007 |
||
1008 |
if ( (skip -= bp->start_x) > 0) { |
|
1009 |
dst += skip >> 1; |
|
1010 |
} else { |
|
1011 |
num += skip; |
|
1012 |
if (num <= 0) continue; |
|
1013 |
skip = 0; |
|
1014 |
} |
|
1015 |
||
1016 |
skip = skip + num - bp->width; |
|
1017 |
if (skip > 0) { |
|
1018 |
num -= skip; |
|
1019 |
if (num <= 0) continue; |
|
1020 |
} |
|
1021 |
||
1022 |
ctab = _color_remap_ptr; |
|
1023 |
num = (num + 1) >> 1; |
|
1024 |
for (; num != 0; num--) { |
|
1025 |
*dst = ctab[*dst]; |
|
1026 |
dst++; |
|
1027 |
} |
|
1028 |
} while (!(done & 0x80)); |
|
1029 |
bp->dst += bp->pitch; |
|
1030 |
if (--bp->height == 0) return; |
|
1031 |
||
1032 |
do { |
|
1033 |
done = src_o[0]; |
|
1034 |
src_o += (done & 0x7F) + 2; |
|
1035 |
} while (!(done & 0x80)); |
|
1036 |
} while (--bp->height != 0); |
|
1037 |
break; |
|
1038 |
||
1039 |
default: |
|
1040 |
do { |
|
1041 |
do { |
|
1042 |
done = src_o[0]; |
|
1043 |
num = done & 0x7F; |
|
1044 |
skip = src_o[1]; |
|
1045 |
src = src_o + 2; |
|
1046 |
src_o += num + 2; |
|
1047 |
||
1048 |
dst = bp->dst; |
|
1049 |
||
1050 |
if (skip & 1) { |
|
1051 |
skip++; |
|
1052 |
src++; |
|
1053 |
if (--num == 0) continue; |
|
1054 |
} |
|
1055 |
||
1056 |
if ( (skip -= bp->start_x) > 0) { |
|
1057 |
dst += skip >> 1; |
|
1058 |
} else { |
|
1059 |
src -= skip; |
|
1060 |
num += skip; |
|
1061 |
if (num <= 0) continue; |
|
1062 |
skip = 0; |
|
1063 |
} |
|
1064 |
||
1065 |
skip = skip + num - bp->width; |
|
1066 |
if (skip > 0) { |
|
1067 |
num -= skip; |
|
1068 |
if (num <= 0) continue; |
|
1069 |
} |
|
1070 |
||
1071 |
num = (num + 1) >> 1; |
|
1072 |
||
1073 |
for (; num != 0; num--) { |
|
1074 |
*dst = *src; |
|
1075 |
dst++; |
|
1076 |
src += 2; |
|
1077 |
} |
|
1078 |
||
1079 |
} while (!(done & 0x80)); |
|
1080 |
||
1081 |
bp->dst += bp->pitch; |
|
1082 |
if (--bp->height == 0) return; |
|
1083 |
||
1084 |
do { |
|
1085 |
done = src_o[0]; |
|
1086 |
src_o += (done & 0x7F) + 2; |
|
1087 |
} while (!(done & 0x80)); |
|
1088 |
} while (--bp->height != 0); |
|
1089 |
break; |
|
0 | 1090 |
} |
1091 |
} |
|
1092 |
||
1093 |
static void GfxBlitZoomMediumUncomp(BlitterParams *bp) |
|
1094 |
{ |
|
1357 | 1095 |
const byte *src = bp->sprite; |
2062 | 1096 |
Pixel *dst = bp->dst; |
0 | 1097 |
int height = bp->height; |
1098 |
int width = bp->width; |
|
1099 |
int i; |
|
1100 |
||
1101 |
assert(height > 0); |
|
1102 |
assert(width > 0); |
|
1103 |
||
4516 | 1104 |
switch (bp->mode) { |
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
1105 |
case BM_COLOUR_REMAP: { |
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1106 |
const byte *ctab = _color_remap_ptr; |
1357 | 1107 |
|
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1108 |
for (height >>= 1; height != 0; height--) { |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1109 |
for (i = 0; i != width >> 1; i++) { |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1110 |
byte b = ctab[src[i * 2]]; |
1996 | 1111 |
|
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1112 |
if (b != 0) dst[i] = b; |
1996 | 1113 |
} |
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1114 |
src += bp->width_org * 2; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1115 |
dst += bp->pitch; |
1996 | 1116 |
} |
4516 | 1117 |
break; |
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1118 |
} |
4516 | 1119 |
|
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
1120 |
case BM_TRANSPARENT: { |
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1121 |
const byte *ctab = _color_remap_ptr; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1122 |
|
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1123 |
for (height >>= 1; height != 0; height--) { |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1124 |
for (i = 0; i != width >> 1; i++) |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1125 |
if (src[i * 2] != 0) dst[i] = ctab[dst[i]]; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1126 |
src += bp->width_org * 2; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1127 |
dst += bp->pitch; |
1996 | 1128 |
} |
4516 | 1129 |
break; |
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1130 |
} |
4516 | 1131 |
|
1132 |
default: |
|
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1133 |
for (height >>= 1; height != 0; height--) { |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1134 |
for (i = 0; i != width >> 1; i++) |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1135 |
if (src[i * 2] != 0) dst[i] = src[i * 2]; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1136 |
src += bp->width_org * 2; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1137 |
dst += bp->pitch; |
1996 | 1138 |
} |
4516 | 1139 |
break; |
0 | 1140 |
} |
1141 |
} |
|
1142 |
||
1143 |
static void GfxBlitTileZoomOut(BlitterParams *bp) |
|
1144 |
{ |
|
4171 | 1145 |
const byte *src_o = bp->sprite; |
1146 |
const byte *src; |
|
0 | 1147 |
int num, skip; |
1148 |
byte done; |
|
2062 | 1149 |
Pixel *dst; |
4171 | 1150 |
const byte *ctab; |
0 | 1151 |
|
4516 | 1152 |
src_o += ReadLE16Aligned(src_o + bp->start_y * 2); |
1153 |
switch (bp->mode) { |
|
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
1154 |
case BM_COLOUR_REMAP: |
4516 | 1155 |
for (;;) { |
1156 |
do { |
|
1157 |
done = src_o[0]; |
|
1158 |
num = done & 0x7F; |
|
1159 |
skip = src_o[1]; |
|
1160 |
src = src_o + 2; |
|
1161 |
src_o += num + 2; |
|
0 | 1162 |
|
4516 | 1163 |
dst = bp->dst; |
0 | 1164 |
|
4516 | 1165 |
if (skip & 1) { |
1166 |
skip++; |
|
1167 |
src++; |
|
1168 |
if (--num == 0) continue; |
|
1169 |
} |
|
0 | 1170 |
|
4516 | 1171 |
if (skip & 2) { |
1172 |
skip += 2; |
|
1173 |
src += 2; |
|
1174 |
num -= 2; |
|
1175 |
if (num <= 0) continue; |
|
1176 |
} |
|
0 | 1177 |
|
4516 | 1178 |
if ( (skip -= bp->start_x) > 0) { |
1179 |
dst += skip >> 2; |
|
1180 |
} else { |
|
1181 |
src -= skip; |
|
1182 |
num += skip; |
|
1183 |
if (num <= 0) continue; |
|
1184 |
skip = 0; |
|
1185 |
} |
|
0 | 1186 |
|
4516 | 1187 |
skip = skip + num - bp->width; |
1188 |
if (skip > 0) { |
|
1189 |
num -= skip; |
|
1190 |
if (num <= 0) continue; |
|
1191 |
} |
|
0 | 1192 |
|
4516 | 1193 |
ctab = _color_remap_ptr; |
1194 |
num = (num + 3) >> 2; |
|
1195 |
for (; num != 0; num--) { |
|
1196 |
*dst = ctab[*src]; |
|
1197 |
dst++; |
|
1198 |
src += 4; |
|
1199 |
} |
|
1200 |
} while (!(done & 0x80)); |
|
1201 |
bp->dst += bp->pitch; |
|
1202 |
if (--bp->height == 0) return; |
|
1203 |
||
1204 |
do { |
|
1205 |
done = src_o[0]; |
|
1206 |
src_o += (done & 0x7F) + 2; |
|
1207 |
} while (!(done & 0x80)); |
|
1208 |
if (--bp->height == 0) return; |
|
1209 |
||
1210 |
do { |
|
1211 |
done = src_o[0]; |
|
1212 |
src_o += (done & 0x7F) + 2; |
|
1213 |
} while (!(done & 0x80)); |
|
1214 |
if (--bp->height == 0) return; |
|
1215 |
||
1216 |
do { |
|
1217 |
done = src_o[0]; |
|
1218 |
src_o += (done & 0x7F) + 2; |
|
1219 |
} while (!(done & 0x80)); |
|
1220 |
if (--bp->height == 0) return; |
|
1221 |
} |
|
1222 |
break; |
|
1223 |
||
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
1224 |
case BM_TRANSPARENT: |
4516 | 1225 |
for (;;) { |
1226 |
do { |
|
1227 |
done = src_o[0]; |
|
1228 |
num = done & 0x7F; |
|
1229 |
skip = src_o[1]; |
|
1230 |
src_o += num + 2; |
|
1231 |
||
1232 |
dst = bp->dst; |
|
1233 |
||
1234 |
if (skip & 1) { |
|
1235 |
skip++; |
|
1236 |
if (--num == 0) continue; |
|
1237 |
} |
|
1238 |
||
1239 |
if (skip & 2) { |
|
1240 |
skip += 2; |
|
1241 |
num -= 2; |
|
1242 |
if (num <= 0) continue; |
|
1243 |
} |
|
1244 |
||
1245 |
if ( (skip -= bp->start_x) > 0) { |
|
1246 |
dst += skip >> 2; |
|
1247 |
} else { |
|
1248 |
num += skip; |
|
1249 |
if (num <= 0) continue; |
|
1250 |
skip = 0; |
|
1251 |
} |
|
1252 |
||
1253 |
skip = skip + num - bp->width; |
|
1254 |
if (skip > 0) { |
|
1255 |
num -= skip; |
|
1256 |
if (num <= 0) continue; |
|
1257 |
} |
|
1258 |
||
1259 |
ctab = _color_remap_ptr; |
|
1260 |
num = (num + 3) >> 2; |
|
1261 |
for (; num != 0; num--) { |
|
1262 |
*dst = ctab[*dst]; |
|
1263 |
dst++; |
|
1264 |
} |
|
1265 |
||
1266 |
} while (!(done & 0x80)); |
|
1267 |
bp->dst += bp->pitch; |
|
1268 |
if (--bp->height == 0) return; |
|
1269 |
||
1270 |
do { |
|
1271 |
done = src_o[0]; |
|
1272 |
src_o += (done & 0x7F) + 2; |
|
1273 |
} while (!(done & 0x80)); |
|
1274 |
if (--bp->height == 0) return; |
|
1275 |
||
1276 |
do { |
|
1277 |
done = src_o[0]; |
|
1278 |
src_o += (done & 0x7F) + 2; |
|
1279 |
} while (!(done & 0x80)); |
|
1280 |
if (--bp->height == 0) return; |
|
1281 |
||
1282 |
do { |
|
1283 |
done = src_o[0]; |
|
1284 |
src_o += (done & 0x7F) + 2; |
|
1285 |
} while (!(done & 0x80)); |
|
1286 |
if (--bp->height == 0) return; |
|
1287 |
} |
|
1288 |
break; |
|
1289 |
||
1290 |
default: |
|
1291 |
for (;;) { |
|
1292 |
do { |
|
1293 |
done = src_o[0]; |
|
1294 |
num = done & 0x7F; |
|
1295 |
skip = src_o[1]; |
|
1296 |
src = src_o + 2; |
|
1297 |
src_o += num + 2; |
|
1298 |
||
1299 |
dst = bp->dst; |
|
1300 |
||
1301 |
if (skip & 1) { |
|
1302 |
skip++; |
|
1303 |
src++; |
|
1304 |
if (--num == 0) continue; |
|
1305 |
} |
|
1306 |
||
1307 |
if (skip & 2) { |
|
1308 |
skip += 2; |
|
1309 |
src += 2; |
|
1310 |
num -= 2; |
|
1311 |
if (num <= 0) continue; |
|
1312 |
} |
|
1313 |
||
1314 |
if ( (skip -= bp->start_x) > 0) { |
|
1315 |
dst += skip >> 2; |
|
1316 |
} else { |
|
1317 |
src -= skip; |
|
1318 |
num += skip; |
|
1319 |
if (num <= 0) continue; |
|
1320 |
skip = 0; |
|
1321 |
} |
|
1322 |
||
1323 |
skip = skip + num - bp->width; |
|
1324 |
if (skip > 0) { |
|
1325 |
num -= skip; |
|
1326 |
if (num <= 0) continue; |
|
1327 |
} |
|
1328 |
||
1329 |
num = (num + 3) >> 2; |
|
1330 |
||
1331 |
for (; num != 0; num--) { |
|
1332 |
*dst = *src; |
|
1333 |
dst++; |
|
1334 |
src += 4; |
|
1335 |
} |
|
1336 |
} while (!(done & 0x80)); |
|
1337 |
||
1338 |
bp->dst += bp->pitch; |
|
1339 |
if (--bp->height == 0) return; |
|
1340 |
||
1341 |
do { |
|
1342 |
done = src_o[0]; |
|
1343 |
src_o += (done & 0x7F) + 2; |
|
1344 |
} while (!(done & 0x80)); |
|
1345 |
if (--bp->height == 0) return; |
|
1346 |
||
1347 |
do { |
|
1348 |
done = src_o[0]; |
|
1349 |
src_o += (done & 0x7F) + 2; |
|
1350 |
} while (!(done & 0x80)); |
|
1351 |
if (--bp->height == 0) return; |
|
1352 |
||
1353 |
do { |
|
1354 |
done = src_o[0]; |
|
1355 |
src_o += (done & 0x7F) + 2; |
|
1356 |
} while (!(done & 0x80)); |
|
1357 |
if (--bp->height == 0) return; |
|
1358 |
} |
|
1359 |
break; |
|
0 | 1360 |
} |
1361 |
} |
|
1362 |
||
1363 |
static void GfxBlitZoomOutUncomp(BlitterParams *bp) |
|
1364 |
{ |
|
4171 | 1365 |
const byte *src = bp->sprite; |
2062 | 1366 |
Pixel *dst = bp->dst; |
0 | 1367 |
int height = bp->height; |
1368 |
int width = bp->width; |
|
1369 |
int i; |
|
1370 |
||
1371 |
assert(height > 0); |
|
1372 |
assert(width > 0); |
|
1373 |
||
4516 | 1374 |
switch (bp->mode) { |
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
1375 |
case BM_COLOUR_REMAP: { |
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1376 |
const byte *ctab = _color_remap_ptr; |
1357 | 1377 |
|
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1378 |
for (height >>= 2; height != 0; height--) { |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1379 |
for (i = 0; i != width >> 2; i++) { |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1380 |
byte b = ctab[src[i * 4]]; |
1996 | 1381 |
|
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1382 |
if (b != 0) dst[i] = b; |
1996 | 1383 |
} |
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1384 |
src += bp->width_org * 4; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1385 |
dst += bp->pitch; |
1996 | 1386 |
} |
4516 | 1387 |
break; |
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1388 |
} |
4516 | 1389 |
|
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
1390 |
case BM_TRANSPARENT: { |
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1391 |
const byte *ctab = _color_remap_ptr; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1392 |
|
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1393 |
for (height >>= 2; height != 0; height--) { |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1394 |
for (i = 0; i != width >> 2; i++) |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1395 |
if (src[i * 4] != 0) dst[i] = ctab[dst[i]]; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1396 |
src += bp->width_org * 4; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1397 |
dst += bp->pitch; |
1996 | 1398 |
} |
4516 | 1399 |
break; |
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1400 |
} |
4516 | 1401 |
|
1402 |
default: |
|
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1403 |
for (height >>= 2; height != 0; height--) { |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1404 |
for (i = 0; i != width >> 2; i++) |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1405 |
if (src[i * 4] != 0) dst[i] = src[i * 4]; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1406 |
src += bp->width_org * 4; |
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1407 |
dst += bp->pitch; |
1996 | 1408 |
} |
4516 | 1409 |
break; |
0 | 1410 |
} |
1411 |
} |
|
1412 |
||
1413 |
||
5567
fe00ab53909b
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5475
diff
changeset
|
1414 |
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode) |
0 | 1415 |
{ |
4171 | 1416 |
const DrawPixelInfo *dpi = _cur_dpi; |
0 | 1417 |
int start_x, start_y; |
1418 |
BlitterParams bp; |
|
2005 | 1419 |
int zoom_mask = ~((1 << dpi->zoom) - 1); |
0 | 1420 |
|
1421 |
/* decode sprite header */ |
|
1351
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1422 |
x += sprite->x_offs; |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1423 |
y += sprite->y_offs; |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1424 |
bp.width_org = bp.width = sprite->width; |
4518 | 1425 |
bp.height = sprite->height; |
1426 |
bp.sprite = sprite->data; |
|
0 | 1427 |
bp.dst = dpi->dst_ptr; |
1428 |
bp.mode = mode; |
|
1429 |
bp.pitch = dpi->pitch; |
|
1430 |
||
1431 |
assert(bp.height > 0); |
|
1432 |
assert(bp.width > 0); |
|
1433 |
||
4517
2ec69fcbafa8
(svn r6302) -Codechange: Remove dead code paths, because the lowest bit of Sprite::info is never unset
tron
parents:
4516
diff
changeset
|
1434 |
if (sprite->info & 8) { |
0 | 1435 |
/* tile blit */ |
1436 |
start_y = 0; |
|
1437 |
||
1438 |
if (dpi->zoom > 0) { |
|
2005 | 1439 |
start_y += bp.height & ~zoom_mask; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
1440 |
bp.height &= zoom_mask; |
0 | 1441 |
if (bp.height == 0) return; |
2005 | 1442 |
y &= zoom_mask; |
0 | 1443 |
} |
1444 |
||
1445 |
if ( (y -= dpi->top) < 0) { |
|
2005 | 1446 |
bp.height += y; |
1447 |
if (bp.height <= 0) return; |
|
0 | 1448 |
start_y -= y; |
1449 |
y = 0; |
|
1450 |
} else { |
|
2005 | 1451 |
bp.dst += bp.pitch * (y >> dpi->zoom); |
0 | 1452 |
} |
1453 |
bp.start_y = start_y; |
|
1454 |
||
1455 |
if ( (y = y + bp.height - dpi->height) > 0) { |
|
2005 | 1456 |
bp.height -= y; |
1457 |
if (bp.height <= 0) return; |
|
0 | 1458 |
} |
1459 |
||
1460 |
start_x = 0; |
|
1461 |
x &= zoom_mask; |
|
1462 |
if ( (x -= dpi->left) < 0) { |
|
2005 | 1463 |
bp.width += x; |
1464 |
if (bp.width <= 0) return; |
|
0 | 1465 |
start_x -= x; |
1466 |
x = 0; |
|
1467 |
} |
|
1468 |
bp.start_x = start_x; |
|
2005 | 1469 |
bp.dst += x >> dpi->zoom; |
0 | 1470 |
|
1471 |
if ( (x = x + bp.width - dpi->width) > 0) { |
|
2005 | 1472 |
bp.width -= x; |
1473 |
if (bp.width <= 0) return; |
|
0 | 1474 |
} |
1475 |
||
4425
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1476 |
switch (dpi->zoom) { |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1477 |
default: NOT_REACHED(); |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1478 |
case 0: GfxBlitTileZoomIn(&bp); break; |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1479 |
case 1: GfxBlitTileZoomMedium(&bp); break; |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1480 |
case 2: GfxBlitTileZoomOut(&bp); break; |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1481 |
} |
0 | 1482 |
} else { |
1483 |
bp.sprite += bp.width * (bp.height & ~zoom_mask); |
|
1484 |
bp.height &= zoom_mask; |
|
2005 | 1485 |
if (bp.height == 0) return; |
0 | 1486 |
|
1487 |
y &= zoom_mask; |
|
1488 |
||
1489 |
if ( (y -= dpi->top) < 0) { |
|
2005 | 1490 |
bp.height += y; |
1491 |
if (bp.height <= 0) return; |
|
0 | 1492 |
bp.sprite -= bp.width * y; |
1493 |
y = 0; |
|
1494 |
} else { |
|
2005 | 1495 |
bp.dst += bp.pitch * (y >> dpi->zoom); |
0 | 1496 |
} |
1497 |
||
2037
1e138067c272
(svn r2546) Don't calculate a value which never gets used and simplify some calculations
tron
parents:
2025
diff
changeset
|
1498 |
if (bp.height > dpi->height - y) { |
1e138067c272
(svn r2546) Don't calculate a value which never gets used and simplify some calculations
tron
parents:
2025
diff
changeset
|
1499 |
bp.height = dpi->height - y; |
2005 | 1500 |
if (bp.height <= 0) return; |
0 | 1501 |
} |
1502 |
||
1503 |
x &= zoom_mask; |
|
1504 |
||
1505 |
if ( (x -= dpi->left) < 0) { |
|
2005 | 1506 |
bp.width += x; |
1507 |
if (bp.width <= 0) return; |
|
0 | 1508 |
bp.sprite -= x; |
1509 |
x = 0; |
|
1510 |
} |
|
2005 | 1511 |
bp.dst += x >> dpi->zoom; |
0 | 1512 |
|
2037
1e138067c272
(svn r2546) Don't calculate a value which never gets used and simplify some calculations
tron
parents:
2025
diff
changeset
|
1513 |
if (bp.width > dpi->width - x) { |
1e138067c272
(svn r2546) Don't calculate a value which never gets used and simplify some calculations
tron
parents:
2025
diff
changeset
|
1514 |
bp.width = dpi->width - x; |
2005 | 1515 |
if (bp.width <= 0) return; |
0 | 1516 |
} |
1517 |
||
4425
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1518 |
switch (dpi->zoom) { |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1519 |
default: NOT_REACHED(); |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1520 |
case 0: GfxBlitZoomInUncomp(&bp); break; |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1521 |
case 1: GfxBlitZoomMediumUncomp(&bp); break; |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1522 |
case 2: GfxBlitZoomOutUncomp(&bp); break; |
f15ad32f87e5
(svn r6180) Use a switch instead of function pointers to choose the blitter
tron
parents:
4344
diff
changeset
|
1523 |
} |
0 | 1524 |
} |
1525 |
} |
|
1526 |
||
6247 | 1527 |
void DoPaletteAnimations(); |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1528 |
|
6247 | 1529 |
void GfxInitPalettes() |
0 | 1530 |
{ |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1531 |
memcpy(_cur_palette, _palettes[_use_dos_palette ? 1 : 0], sizeof(_cur_palette)); |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1532 |
|
0 | 1533 |
_pal_first_dirty = 0; |
1534 |
_pal_last_dirty = 255; |
|
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1535 |
DoPaletteAnimations(); |
0 | 1536 |
} |
1537 |
||
2010 | 1538 |
#define EXTR(p, q) (((uint16)(_timer_counter * (p)) * (q)) >> 16) |
1539 |
#define EXTR2(p, q) (((uint16)(~_timer_counter * (p)) * (q)) >> 16) |
|
0 | 1540 |
|
6247 | 1541 |
void DoPaletteAnimations() |
0 | 1542 |
{ |
4171 | 1543 |
const Colour *s; |
1544 |
Colour *d; |
|
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1545 |
/* Amount of colors to be rotated. |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1546 |
* A few more for the DOS palette, because the water colors are |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1547 |
* 245-254 for DOS and 217-226 for Windows. */ |
0 | 1548 |
const ExtraPaletteValues *ev = &_extra_palette_values; |
2005 | 1549 |
int c = _use_dos_palette ? 38 : 28; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1550 |
Colour old_val[38]; // max(38, 28) |
2005 | 1551 |
uint i; |
1552 |
uint j; |
|
0 | 1553 |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1554 |
d = &_cur_palette[217]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1555 |
memcpy(old_val, d, c * sizeof(*old_val)); |
0 | 1556 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1557 |
/* Dark blue water */ |
6357
f0f5e7d1713c
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6248
diff
changeset
|
1558 |
s = (_opt.landscape == LT_TOYLAND) ? ev->ac : ev->a; |
2005 | 1559 |
j = EXTR(320, 5); |
1560 |
for (i = 0; i != 5; i++) { |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1561 |
*d++ = s[j]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1562 |
j++; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1563 |
if (j == 5) j = 0; |
0 | 1564 |
} |
1565 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1566 |
/* Glittery water */ |
6357
f0f5e7d1713c
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6248
diff
changeset
|
1567 |
s = (_opt.landscape == LT_TOYLAND) ? ev->bc : ev->b; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1568 |
j = EXTR(128, 15); |
2005 | 1569 |
for (i = 0; i != 5; i++) { |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1570 |
*d++ = s[j]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1571 |
j += 3; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1572 |
if (j >= 15) j -= 15; |
0 | 1573 |
} |
1574 |
||
1575 |
s = ev->e; |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1576 |
j = EXTR2(512, 5); |
2005 | 1577 |
for (i = 0; i != 5; i++) { |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1578 |
*d++ = s[j]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1579 |
j++; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1580 |
if (j == 5) j = 0; |
0 | 1581 |
} |
1582 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1583 |
/* Oil refinery fire animation */ |
0 | 1584 |
s = ev->oil_ref; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1585 |
j = EXTR2(512, 7); |
2005 | 1586 |
for (i = 0; i != 7; i++) { |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1587 |
*d++ = s[j]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1588 |
j++; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1589 |
if (j == 7) j = 0; |
0 | 1590 |
} |
1591 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1592 |
/* Radio tower blinking */ |
0 | 1593 |
{ |
2005 | 1594 |
byte i = (_timer_counter >> 1) & 0x7F; |
1595 |
byte v; |
|
1596 |
||
0 | 1597 |
(v = 255, i < 0x3f) || |
1598 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
1599 |
(v = 20); |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1600 |
d->r = v; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1601 |
d->g = 0; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1602 |
d->b = 0; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1603 |
d++; |
0 | 1604 |
|
1605 |
i ^= 0x40; |
|
1606 |
(v = 255, i < 0x3f) || |
|
1607 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
1608 |
(v = 20); |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1609 |
d->r = v; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1610 |
d->g = 0; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1611 |
d->b = 0; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1612 |
d++; |
0 | 1613 |
} |
1614 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1615 |
/* Handle lighthouse and stadium animation */ |
0 | 1616 |
s = ev->lighthouse; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1617 |
j = EXTR(256, 4); |
2005 | 1618 |
for (i = 0; i != 4; i++) { |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1619 |
*d++ = s[j]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1620 |
j++; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1621 |
if (j == 4) j = 0; |
0 | 1622 |
} |
1623 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1624 |
/* Animate water for old DOS graphics */ |
2005 | 1625 |
if (_use_dos_palette) { |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1626 |
/* Dark blue water DOS */ |
6357
f0f5e7d1713c
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6248
diff
changeset
|
1627 |
s = (_opt.landscape == LT_TOYLAND) ? ev->ac : ev->a; |
2005 | 1628 |
j = EXTR(320, 5); |
1629 |
for (i = 0; i != 5; i++) { |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1630 |
*d++ = s[j]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1631 |
j++; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1632 |
if (j == 5) j = 0; |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1633 |
} |
915 | 1634 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1635 |
/* Glittery water DOS */ |
6357
f0f5e7d1713c
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6248
diff
changeset
|
1636 |
s = (_opt.landscape == LT_TOYLAND) ? ev->bc : ev->b; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1637 |
j = EXTR(128, 15); |
2005 | 1638 |
for (i = 0; i != 5; i++) { |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1639 |
*d++ = s[j]; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1640 |
j += 3; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1641 |
if (j >= 15) j -= 15; |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1642 |
} |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1643 |
} |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1644 |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1645 |
if (memcmp(old_val, &_cur_palette[217], c * sizeof(*old_val)) != 0) { |
0 | 1646 |
if (_pal_first_dirty > 217) _pal_first_dirty = 217; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1647 |
if (_pal_last_dirty < 217 + c) _pal_last_dirty = 217 + c; |
0 | 1648 |
} |
1649 |
} |
|
1650 |
||
1651 |
||
6247 | 1652 |
void LoadStringWidthTable() |
0 | 1653 |
{ |
2005 | 1654 |
uint i; |
0 | 1655 |
|
3797
db2306464bbe
(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
|
1656 |
/* Normal font */ |
3798
b1f5290b36b1
(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
|
1657 |
for (i = 0; i != 224; i++) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1658 |
_stringwidth_table[FS_NORMAL][i] = GetGlyphWidth(FS_NORMAL, i + 32); |
0 | 1659 |
} |
1660 |
||
3797
db2306464bbe
(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
|
1661 |
/* Small font */ |
3798
b1f5290b36b1
(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
|
1662 |
for (i = 0; i != 224; i++) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1663 |
_stringwidth_table[FS_SMALL][i] = GetGlyphWidth(FS_SMALL, i + 32); |
0 | 1664 |
} |
1665 |
||
3797
db2306464bbe
(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
|
1666 |
/* Large font */ |
3798
b1f5290b36b1
(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
|
1667 |
for (i = 0; i != 224; i++) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1668 |
_stringwidth_table[FS_LARGE][i] = GetGlyphWidth(FS_LARGE, i + 32); |
0 | 1669 |
} |
1670 |
} |
|
1671 |
||
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1672 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1673 |
byte GetCharacterWidth(FontSize size, WChar key) |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1674 |
{ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1675 |
if (key >= 32 && key < 256) return _stringwidth_table[size][key - 32]; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1676 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1677 |
return GetGlyphWidth(size, key); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1678 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1679 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1680 |
|
6247 | 1681 |
void ScreenSizeChanged() |
0 | 1682 |
{ |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1683 |
/* check the dirty rect */ |
0 | 1684 |
if (_invalid_rect.right >= _screen.width) _invalid_rect.right = _screen.width; |
1685 |
if (_invalid_rect.bottom >= _screen.height) _invalid_rect.bottom = _screen.height; |
|
1686 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1687 |
/* screen size changed and the old bitmap is invalid now, so we don't want to undraw it */ |
0 | 1688 |
_cursor.visible = false; |
1689 |
} |
|
1690 |
||
6247 | 1691 |
void UndrawMouseCursor() |
0 | 1692 |
{ |
1693 |
if (_cursor.visible) { |
|
1694 |
_cursor.visible = false; |
|
1695 |
memcpy_pitch( |
|
1696 |
_screen.dst_ptr + _cursor.draw_pos.x + _cursor.draw_pos.y * _screen.pitch, |
|
1697 |
_cursor_backup, |
|
1698 |
_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
|
1699 |
|
0 | 1700 |
_video_driver->make_dirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y); |
1701 |
} |
|
1702 |
} |
|
1703 |
||
6247 | 1704 |
void DrawMouseCursor() |
0 | 1705 |
{ |
2010 | 1706 |
int x; |
1707 |
int y; |
|
1708 |
int w; |
|
1709 |
int h; |
|
0 | 1710 |
|
3312
d28f88dc5587
(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
|
1711 |
/* Redraw mouse cursor but only when it's inside the window */ |
d28f88dc5587
(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
|
1712 |
if (!_cursor.in_window) return; |
d28f88dc5587
(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
|
1713 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1714 |
/* Don't draw the mouse cursor if it's already drawn */ |
0 | 1715 |
if (_cursor.visible) { |
2010 | 1716 |
if (!_cursor.dirty) return; |
0 | 1717 |
UndrawMouseCursor(); |
1718 |
} |
|
1719 |
||
1720 |
w = _cursor.size.x; |
|
1721 |
x = _cursor.pos.x + _cursor.offs.x; |
|
2010 | 1722 |
if (x < 0) { |
1723 |
w += x; |
|
1724 |
x = 0; |
|
1725 |
} |
|
1726 |
if (w > _screen.width - x) w = _screen.width - x; |
|
0 | 1727 |
if (w <= 0) return; |
1728 |
_cursor.draw_pos.x = x; |
|
1729 |
_cursor.draw_size.x = w; |
|
1730 |
||
1731 |
h = _cursor.size.y; |
|
1732 |
y = _cursor.pos.y + _cursor.offs.y; |
|
2010 | 1733 |
if (y < 0) { |
1734 |
h += y; |
|
1735 |
y = 0; |
|
1736 |
} |
|
1737 |
if (h > _screen.height - y) h = _screen.height - y; |
|
0 | 1738 |
if (h <= 0) return; |
1739 |
_cursor.draw_pos.y = y; |
|
1740 |
_cursor.draw_size.y = h; |
|
1741 |
||
2010 | 1742 |
assert(w * h < (int)sizeof(_cursor_backup)); |
0 | 1743 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1744 |
/* Make backup of stuff below cursor */ |
0 | 1745 |
memcpy_pitch( |
1746 |
_cursor_backup, |
|
1747 |
_screen.dst_ptr + _cursor.draw_pos.x + _cursor.draw_pos.y * _screen.pitch, |
|
306
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
1748 |
_cursor.draw_size.x, _cursor.draw_size.y, _screen.pitch, _cursor.draw_size.x); |
0 | 1749 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1750 |
/* Draw cursor on screen */ |
0 | 1751 |
_cur_dpi = &_screen; |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
1752 |
DrawSprite(_cursor.sprite, _cursor.pal, _cursor.pos.x, _cursor.pos.y); |
0 | 1753 |
|
1754 |
_video_driver->make_dirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y); |
|
1755 |
||
1756 |
_cursor.visible = true; |
|
1757 |
_cursor.dirty = false; |
|
1758 |
} |
|
1759 |
||
798 | 1760 |
#if defined(_DEBUG) |
410 | 1761 |
static void DbgScreenRect(int left, int top, int right, int bottom) |
0 | 1762 |
{ |
2010 | 1763 |
DrawPixelInfo dp; |
4171 | 1764 |
DrawPixelInfo *old; |
0 | 1765 |
|
1766 |
old = _cur_dpi; |
|
1767 |
_cur_dpi = &dp; |
|
1768 |
dp = _screen; |
|
2010 | 1769 |
GfxFillRect(left, top, right - 1, bottom - 1, rand() & 255); |
0 | 1770 |
_cur_dpi = old; |
1771 |
} |
|
798 | 1772 |
#endif |
0 | 1773 |
|
1774 |
void RedrawScreenRect(int left, int top, int right, int bottom) |
|
1775 |
{ |
|
1776 |
assert(right <= _screen.width && bottom <= _screen.height); |
|
1777 |
if (_cursor.visible) { |
|
1778 |
if (right > _cursor.draw_pos.x && |
|
1779 |
left < _cursor.draw_pos.x + _cursor.draw_size.x && |
|
1780 |
bottom > _cursor.draw_pos.y && |
|
1781 |
top < _cursor.draw_pos.y + _cursor.draw_size.y) { |
|
1782 |
UndrawMouseCursor(); |
|
1783 |
} |
|
1784 |
} |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
1785 |
UndrawTextMessage(); |
0 | 1786 |
|
1787 |
#if defined(_DEBUG) |
|
1788 |
if (_dbg_screen_rect) |
|
1789 |
DbgScreenRect(left, top, right, bottom); |
|
1790 |
else |
|
1791 |
#endif |
|
1792 |
DrawOverlappedWindowForAll(left, top, right, bottom); |
|
1793 |
||
2010 | 1794 |
_video_driver->make_dirty(left, top, right - left, bottom - top); |
0 | 1795 |
} |
1796 |
||
6247 | 1797 |
void DrawDirtyBlocks() |
0 | 1798 |
{ |
1799 |
byte *b = _dirty_blocks; |
|
2398
912f16512ce2
(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
|
1800 |
const int w = ALIGN(_screen.width, 64); |
912f16512ce2
(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
|
1801 |
const int h = ALIGN(_screen.height, 8); |
2025 | 1802 |
int x; |
1803 |
int y; |
|
0 | 1804 |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1805 |
if (IsGeneratingWorld() && !IsGeneratingWorldReadyForPaint()) return; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1806 |
|
2025 | 1807 |
y = 0; |
0 | 1808 |
do { |
2025 | 1809 |
x = 0; |
1810 |
do { |
|
1811 |
if (*b != 0) { |
|
1812 |
int left; |
|
1813 |
int top; |
|
1814 |
int right = x + 64; |
|
1815 |
int bottom = y; |
|
1816 |
byte *p = b; |
|
1817 |
int h2; |
|
0 | 1818 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1819 |
/* First try coalescing downwards */ |
0 | 1820 |
do { |
2025 | 1821 |
*p = 0; |
1822 |
p += DIRTY_BYTES_PER_LINE; |
|
1823 |
bottom += 8; |
|
1824 |
} while (bottom != h && *p != 0); |
|
0 | 1825 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1826 |
/* Try coalescing to the right too. */ |
2025 | 1827 |
h2 = (bottom - y) >> 3; |
1828 |
assert(h2 > 0); |
|
1829 |
p = b; |
|
0 | 1830 |
|
2025 | 1831 |
while (right != w) { |
1832 |
byte *p2 = ++p; |
|
1833 |
int h = h2; |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1834 |
/* Check if a full line of dirty flags is set. */ |
2025 | 1835 |
do { |
1836 |
if (!*p2) goto no_more_coalesc; |
|
1837 |
p2 += DIRTY_BYTES_PER_LINE; |
|
1838 |
} while (--h != 0); |
|
1839 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1840 |
/* Wohoo, can combine it one step to the right! |
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1841 |
* Do that, and clear the bits. */ |
2025 | 1842 |
right += 64; |
1843 |
||
1844 |
h = h2; |
|
1845 |
p2 = p; |
|
1846 |
do { |
|
1847 |
*p2 = 0; |
|
1848 |
p2 += DIRTY_BYTES_PER_LINE; |
|
1849 |
} while (--h != 0); |
|
1850 |
} |
|
1851 |
no_more_coalesc: |
|
1852 |
||
1853 |
left = x; |
|
1854 |
top = y; |
|
1855 |
||
1856 |
if (left < _invalid_rect.left ) left = _invalid_rect.left; |
|
1857 |
if (top < _invalid_rect.top ) top = _invalid_rect.top; |
|
1858 |
if (right > _invalid_rect.right ) right = _invalid_rect.right; |
|
1859 |
if (bottom > _invalid_rect.bottom) bottom = _invalid_rect.bottom; |
|
1860 |
||
1861 |
if (left < right && top < bottom) { |
|
1862 |
RedrawScreenRect(left, top, right, bottom); |
|
1863 |
} |
|
1864 |
||
0 | 1865 |
} |
2025 | 1866 |
} while (b++, (x += 64) != w); |
1867 |
} while (b += -(w >> 6) + DIRTY_BYTES_PER_LINE, (y += 8) != h); |
|
0 | 1868 |
|
1869 |
_invalid_rect.left = w; |
|
1870 |
_invalid_rect.top = h; |
|
1871 |
_invalid_rect.right = 0; |
|
1872 |
_invalid_rect.bottom = 0; |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1873 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1874 |
/* If we are generating a world, and waiting for a paint run, mark it here |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1875 |
* as done painting, so we can continue generating. */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1876 |
if (IsGeneratingWorld() && IsGeneratingWorldReadyForPaint()) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1877 |
SetGeneratingWorldPaintStatus(false); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1878 |
} |
0 | 1879 |
} |
1880 |
||
1881 |
||
1882 |
void SetDirtyBlocks(int left, int top, int right, int bottom) |
|
1883 |
{ |
|
1884 |
byte *b; |
|
2010 | 1885 |
int width; |
1886 |
int height; |
|
0 | 1887 |
|
1888 |
if (left < 0) left = 0; |
|
1889 |
if (top < 0) top = 0; |
|
1890 |
if (right > _screen.width) right = _screen.width; |
|
1891 |
if (bottom > _screen.height) bottom = _screen.height; |
|
1892 |
||
2010 | 1893 |
if (left >= right || top >= bottom) return; |
0 | 1894 |
|
2010 | 1895 |
if (left < _invalid_rect.left ) _invalid_rect.left = left; |
1896 |
if (top < _invalid_rect.top ) _invalid_rect.top = top; |
|
1897 |
if (right > _invalid_rect.right ) _invalid_rect.right = right; |
|
1898 |
if (bottom > _invalid_rect.bottom) _invalid_rect.bottom = bottom; |
|
0 | 1899 |
|
1900 |
left >>= 6; |
|
2010 | 1901 |
top >>= 3; |
0 | 1902 |
|
1903 |
b = _dirty_blocks + top * DIRTY_BYTES_PER_LINE + left; |
|
1904 |
||
2010 | 1905 |
width = ((right - 1) >> 6) - left + 1; |
1906 |
height = ((bottom - 1) >> 3) - top + 1; |
|
0 | 1907 |
|
1908 |
assert(width > 0 && height > 0); |
|
1909 |
||
1910 |
do { |
|
2010 | 1911 |
int i = width; |
1912 |
||
0 | 1913 |
do b[--i] = 0xFF; while (i); |
1914 |
||
1915 |
b += DIRTY_BYTES_PER_LINE; |
|
2010 | 1916 |
} while (--height != 0); |
0 | 1917 |
} |
1918 |
||
6247 | 1919 |
void MarkWholeScreenDirty() |
0 | 1920 |
{ |
1921 |
SetDirtyBlocks(0, 0, _screen.width, _screen.height); |
|
1922 |
} |
|
1923 |
||
4958 | 1924 |
/** Set up a clipping area for only drawing into a certain area. To do this, |
1925 |
* Fill a DrawPixelInfo object with the supplied relative rectangle, backup |
|
1926 |
* the original (calling) _cur_dpi and assign the just returned DrawPixelInfo |
|
1927 |
* _cur_dpi. When you are done, give restore _cur_dpi's original value |
|
1928 |
* @param *n the DrawPixelInfo that will be the clipping rectangle box allowed |
|
1929 |
* for drawing |
|
1930 |
* @param left,top,width,height the relative coordinates of the clipping |
|
1931 |
* rectangle relative to the current _cur_dpi. This will most likely be the |
|
1932 |
* offset from the calling window coordinates |
|
1933 |
* @return return false if the requested rectangle is not possible with the |
|
1934 |
* current dpi pointer. Only continue of the return value is true, or you'll |
|
1935 |
* get some nasty results */ |
|
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1936 |
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height) |
0 | 1937 |
{ |
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1938 |
const DrawPixelInfo *o = _cur_dpi; |
0 | 1939 |
|
1940 |
n->zoom = 0; |
|
1941 |
||
1942 |
assert(width > 0); |
|
1943 |
assert(height > 0); |
|
1944 |
||
1945 |
if ((left -= o->left) < 0) { |
|
2010 | 1946 |
width += left; |
4525
d12168a85134
(svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents:
4522
diff
changeset
|
1947 |
if (width <= 0) return false; |
0 | 1948 |
n->left = -left; |
1949 |
left = 0; |
|
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1950 |
} else { |
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1951 |
n->left = 0; |
0 | 1952 |
} |
1953 |
||
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1954 |
if (width > o->width - left) { |
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1955 |
width = o->width - left; |
4525
d12168a85134
(svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents:
4522
diff
changeset
|
1956 |
if (width <= 0) return false; |
0 | 1957 |
} |
1958 |
n->width = width; |
|
1959 |
||
1960 |
if ((top -= o->top) < 0) { |
|
2010 | 1961 |
height += top; |
4525
d12168a85134
(svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents:
4522
diff
changeset
|
1962 |
if (height <= 0) return false; |
0 | 1963 |
n->top = -top; |
1964 |
top = 0; |
|
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1965 |
} else { |
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1966 |
n->top = 0; |
0 | 1967 |
} |
1968 |
||
1969 |
n->dst_ptr = o->dst_ptr + left + top * (n->pitch = o->pitch); |
|
1970 |
||
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1971 |
if (height > o->height - top) { |
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1972 |
height = o->height - top; |
4525
d12168a85134
(svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents:
4522
diff
changeset
|
1973 |
if (height <= 0) return false; |
0 | 1974 |
} |
1975 |
n->height = height; |
|
1976 |
||
1977 |
return true; |
|
1978 |
} |
|
1979 |
||
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
1980 |
static void SetCursorSprite(SpriteID cursor, SpriteID pal) |
0 | 1981 |
{ |
1982 |
CursorVars *cv = &_cursor; |
|
1348 | 1983 |
const Sprite *p; |
0 | 1984 |
|
2010 | 1985 |
if (cv->sprite == cursor) return; |
0 | 1986 |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
1987 |
p = GetSprite(GB(cursor, 0, SPRITE_WIDTH)); |
0 | 1988 |
cv->sprite = cursor; |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
1989 |
cv->pal = pal; |
1348 | 1990 |
cv->size.y = p->height; |
1351
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1991 |
cv->size.x = p->width; |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1992 |
cv->offs.x = p->x_offs; |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1993 |
cv->offs.y = p->y_offs; |
0 | 1994 |
|
1995 |
cv->dirty = true; |
|
1996 |
} |
|
1997 |
||
6247 | 1998 |
static void SwitchAnimatedCursor() |
0 | 1999 |
{ |
6138
f1196498ef66
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5668
diff
changeset
|
2000 |
const AnimCursor *cur = _cursor.animate_cur; |
0 | 2001 |
|
6138
f1196498ef66
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5668
diff
changeset
|
2002 |
if (cur == NULL || cur->sprite == AnimCursor::LAST) cur = _cursor.animate_list; |
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
2003 |
|
6138
f1196498ef66
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5668
diff
changeset
|
2004 |
SetCursorSprite(cur->sprite, _cursor.pal); |
0 | 2005 |
|
6138
f1196498ef66
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5668
diff
changeset
|
2006 |
_cursor.animate_timeout = cur->display_time; |
f1196498ef66
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5668
diff
changeset
|
2007 |
_cursor.animate_cur = cur + 1; |
0 | 2008 |
} |
2009 |
||
6247 | 2010 |
void CursorTick() |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
2011 |
{ |
2010 | 2012 |
if (_cursor.animate_timeout != 0 && --_cursor.animate_timeout == 0) |
0 | 2013 |
SwitchAnimatedCursor(); |
2014 |
} |
|
2015 |
||
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
2016 |
void SetMouseCursor(SpriteID sprite, SpriteID pal) |
0 | 2017 |
{ |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
2018 |
/* Turn off animation */ |
0 | 2019 |
_cursor.animate_timeout = 0; |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
2020 |
/* Set cursor */ |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
2021 |
SetCursorSprite(sprite, pal); |
0 | 2022 |
} |
2023 |
||
6138
f1196498ef66
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5668
diff
changeset
|
2024 |
void SetAnimatedMouseCursor(const AnimCursor *table) |
0 | 2025 |
{ |
2026 |
_cursor.animate_list = table; |
|
2027 |
_cursor.animate_cur = NULL; |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
2028 |
_cursor.pal = PAL_NONE; |
0 | 2029 |
SwitchAnimatedCursor(); |
2030 |
} |
|
2031 |
||
2032 |
bool ChangeResInGame(int w, int h) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
2033 |
{ |
2645
841087328e0e
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents:
2639
diff
changeset
|
2034 |
return |
841087328e0e
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents:
2639
diff
changeset
|
2035 |
(_screen.width == w && _screen.height == h) || |
841087328e0e
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents:
2639
diff
changeset
|
2036 |
_video_driver->change_resolution(w, h); |
0 | 2037 |
} |
298
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
2038 |
|
5217
7a9e91919a93
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
2039 |
void ToggleFullScreen(bool fs) |
7a9e91919a93
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
2040 |
{ |
7a9e91919a93
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
2041 |
_video_driver->toggle_fullscreen(fs); |
7a9e91919a93
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
2042 |
if (_fullscreen != fs && _num_resolutions == 0) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5217
diff
changeset
|
2043 |
DEBUG(driver, 0, "Could not find a suitable fullscreen resolution"); |
5217
7a9e91919a93
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
2044 |
} |
7a9e91919a93
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
2045 |
} |
1829
e90fe433fa7d
(svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents:
1806
diff
changeset
|
2046 |
|
1806
5a55d508c23e
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
2047 |
static int CDECL compare_res(const void *pa, const void *pb) |
298
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
2048 |
{ |
1806
5a55d508c23e
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
2049 |
int x = ((const uint16*)pa)[0] - ((const uint16*)pb)[0]; |
5a55d508c23e
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
2050 |
if (x != 0) return x; |
5a55d508c23e
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
2051 |
return ((const uint16*)pa)[1] - ((const uint16*)pb)[1]; |
5a55d508c23e
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
2052 |
} |
5a55d508c23e
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
2053 |
|
5a55d508c23e
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
2054 |
void SortResolutions(int count) |
5a55d508c23e
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
2055 |
{ |
5a55d508c23e
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
2056 |
qsort(_resolutions, count, sizeof(_resolutions[0]), compare_res); |
298
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
2057 |
} |