author | richk |
Tue, 17 Jun 2008 13:22:13 +0000 | |
branch | NewGRF_ports |
changeset 10994 | cd9968b6f96b |
parent 10991 | d8811e327d12 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10724
68a692eacf22
(svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents:
10274
diff
changeset
|
3 |
/** @file gfx.cpp Handling of drawing text and other gfx related stuff. */ |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1829
diff
changeset
|
6 |
#include "openttd.h" |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
7 |
#include "gfx_func.h" |
1349
07514c2cc6d1
(svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents:
1348
diff
changeset
|
8 |
#include "spritecache.h" |
2153
91e89aa8c299
(svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents:
2134
diff
changeset
|
9 |
#include "variables.h" |
5108
dc67d70b5a45
(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
|
10 |
#include "fontcache.h" |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
11 |
#include "genworld.h" |
5217
21c23507c002
(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
|
12 |
#include "debug.h" |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
13 |
#include "zoom_func.h" |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
14 |
#include "texteff.hpp" |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
15 |
#include "blitter/factory.hpp" |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
16 |
#include "video/video_driver.hpp" |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
17 |
#include "strings_func.h" |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
18 |
#include "core/math_func.hpp" |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
19 |
#include "settings_type.h" |
10274
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
20 |
#include "core/alloc_func.hpp" |
10994
cd9968b6f96b
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents:
10991
diff
changeset
|
21 |
#include "core/sort_func.hpp" |
10724
68a692eacf22
(svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents:
10274
diff
changeset
|
22 |
#include "landscape_type.h" |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
23 |
|
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
24 |
#include "table/palettes.h" |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
25 |
#include "table/sprites.h" |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
26 |
#include "table/control_codes.h" |
2649
7cd504bd4e51
(svn r3191) Move declaration and definition of _dbg_screen_rect to a place where it somewhat makes sense and wrap them in #ifdef _DEBUG
tron
parents:
2645
diff
changeset
|
27 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
28 |
byte _dirkeys; ///< 1 = left, 2 = up, 4 = right, 8 = down |
5887
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
29 |
bool _fullscreen; |
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
30 |
CursorVars _cursor; |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
31 |
bool _ctrl_pressed; ///< Is Ctrl pressed? |
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
32 |
bool _shift_pressed; ///< Is Shift pressed? |
5887
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
33 |
byte _fast_forward; |
10184
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
34 |
bool _left_button_down; ///< Is left mouse button pressed? |
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
35 |
bool _left_button_clicked; ///< Is left mouse button clicked? |
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
36 |
bool _right_button_down; ///< Is right mouse button pressed? |
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
37 |
bool _right_button_clicked; ///< Is right mouse button clicked? |
5887
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
38 |
DrawPixelInfo _screen; |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
39 |
bool _screen_disable_anim = false; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot) |
5887
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
40 |
bool _exit_game; |
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
41 |
bool _networking; ///< are we in networking mode? |
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
42 |
byte _game_mode; |
6878
7d1ff2f621c7
(svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents:
6872
diff
changeset
|
43 |
int8 _pause_game; |
5887
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
44 |
int _pal_first_dirty; |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
45 |
int _pal_count_dirty; |
5887
063ca43b682c
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5838
diff
changeset
|
46 |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
47 |
Colour _cur_palette[256]; |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
48 |
byte _stringwidth_table[FS_END][224]; |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
49 |
DrawPixelInfo *_cur_dpi; |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
50 |
byte _colour_gradient[16][8]; |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
51 |
bool _use_dos_palette; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
52 |
|
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
53 |
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = NULL); |
0 | 54 |
|
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
55 |
FontSize _cur_fontsize; |
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
56 |
static FontSize _last_fontsize; |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
57 |
static uint8 _cursor_backup[64 * 64 * 4]; |
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
58 |
|
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
59 |
/** |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
60 |
* The rect for repaint. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
61 |
* |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
62 |
* This rectangle defines the area which should be repaint by the video driver. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
63 |
* |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
64 |
* @ingroup dirty |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
65 |
*/ |
0 | 66 |
static Rect _invalid_rect; |
1357 | 67 |
static const byte *_color_remap_ptr; |
0 | 68 |
static byte _string_colorremap[3]; |
69 |
||
10274
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
70 |
enum { |
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
71 |
DIRTY_BLOCK_HEIGHT = 8, |
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
72 |
DIRTY_BLOCK_WIDTH = 64, |
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
73 |
}; |
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
74 |
static uint _dirty_bytes_per_line = 0; |
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
75 |
static byte *_dirty_blocks = NULL; |
0 | 76 |
|
2010 | 77 |
void GfxScroll(int left, int top, int width, int height, int xo, int yo) |
78 |
{ |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
79 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
0 | 80 |
|
2010 | 81 |
if (xo == 0 && yo == 0) return; |
0 | 82 |
|
2010 | 83 |
if (_cursor.visible) UndrawMouseCursor(); |
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
84 |
UndrawChatMessage(); |
0 | 85 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
86 |
blitter->ScrollBuffer(_screen.dst_ptr, left, top, width, height, xo, yo); |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
87 |
/* This part of the screen is now dirty. */ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
88 |
_video_driver->MakeDirty(left, top, width, height); |
0 | 89 |
} |
90 |
||
91 |
||
2010 | 92 |
void GfxFillRect(int left, int top, int right, int bottom, int color) |
93 |
{ |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
94 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
95 |
const DrawPixelInfo *dpi = _cur_dpi; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
96 |
void *dst; |
332 | 97 |
const int otop = top; |
98 |
const int oleft = left; |
|
0 | 99 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
100 |
if (dpi->zoom != ZOOM_LVL_NORMAL) return; |
2010 | 101 |
if (left > right || top > bottom) return; |
102 |
if (right < dpi->left || left >= dpi->left + dpi->width) return; |
|
103 |
if (bottom < dpi->top || top >= dpi->top + dpi->height) return; |
|
0 | 104 |
|
105 |
if ( (left -= dpi->left) < 0) left = 0; |
|
106 |
right = right - dpi->left + 1; |
|
2010 | 107 |
if (right > dpi->width) right = dpi->width; |
0 | 108 |
right -= left; |
109 |
assert(right > 0); |
|
110 |
||
111 |
if ( (top -= dpi->top) < 0) top = 0; |
|
112 |
bottom = bottom - dpi->top + 1; |
|
2010 | 113 |
if (bottom > dpi->height) bottom = dpi->height; |
0 | 114 |
bottom -= top; |
115 |
assert(bottom > 0); |
|
116 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
117 |
dst = blitter->MoveTo(dpi->dst_ptr, left, top); |
0 | 118 |
|
6871
5a9dc001e1ad
(svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents:
6870
diff
changeset
|
119 |
if (!HasBit(color, PALETTE_MODIFIER_GREYOUT)) { |
5a9dc001e1ad
(svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents:
6870
diff
changeset
|
120 |
if (!HasBit(color, USE_COLORTABLE)) { |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
121 |
blitter->DrawRect(dst, right, bottom, (uint8)color); |
0 | 122 |
} else { |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
123 |
blitter->DrawColorMappingRect(dst, right, bottom, GB(color, 0, PALETTE_WIDTH)); |
0 | 124 |
} |
125 |
} else { |
|
332 | 126 |
byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1; |
0 | 127 |
do { |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
128 |
for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8)color); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
129 |
dst = blitter->MoveTo(dst, 0, 1); |
332 | 130 |
} while (--bottom > 0); |
0 | 131 |
} |
132 |
} |
|
133 |
||
134 |
void GfxDrawLine(int x, int y, int x2, int y2, int color) |
|
135 |
{ |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
136 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
137 |
DrawPixelInfo *dpi = _cur_dpi; |
0 | 138 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
139 |
x -= dpi->left; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
140 |
x2 -= dpi->left; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
141 |
y -= dpi->top; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
142 |
y2 -= dpi->top; |
0 | 143 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
144 |
/* Check clipping */ |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
145 |
if (x < 0 && x2 < 0) return; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
146 |
if (y < 0 && y2 < 0) return; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
147 |
if (x > dpi->width && x2 > dpi->width) return; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
148 |
if (y > dpi->height && y2 > dpi->height) return; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
149 |
|
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
150 |
blitter->DrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, color); |
0 | 151 |
} |
152 |
||
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
153 |
void GfxDrawLineUnscaled(int x, int y, int x2, int y2, int color) |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
154 |
{ |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
155 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
156 |
DrawPixelInfo *dpi = _cur_dpi; |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
157 |
|
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
158 |
x -= dpi->left; |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
159 |
x2 -= dpi->left; |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
160 |
y -= dpi->top; |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
161 |
y2 -= dpi->top; |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
162 |
|
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
163 |
/* Check clipping */ |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
164 |
if (x < 0 && x2 < 0) return; |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
165 |
if (y < 0 && y2 < 0) return; |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
166 |
if (x > dpi->width && x2 > dpi->width) return; |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
167 |
if (y > dpi->height && y2 > dpi->height) return; |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
168 |
|
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
169 |
blitter->DrawLine(dpi->dst_ptr, UnScaleByZoom(x, dpi->zoom), UnScaleByZoom(y, dpi->zoom), |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
170 |
UnScaleByZoom(x2, dpi->zoom), UnScaleByZoom(y2, dpi->zoom), |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
171 |
UnScaleByZoom(dpi->width, dpi->zoom), UnScaleByZoom(dpi->height, dpi->zoom), color); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
172 |
} |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
173 |
|
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
174 |
/** |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
175 |
* Draws the projection of a parallelepiped. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
176 |
* This can be used to draw boxes in world coordinates. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
177 |
* |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
178 |
* @param x Screen X-coordinate of top front corner. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
179 |
* @param y Screen Y-coordinate of top front corner. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
180 |
* @param dx1 Screen X-length of first edge. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
181 |
* @param dy1 Screen Y-length of first edge. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
182 |
* @param dx2 Screen X-length of second edge. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
183 |
* @param dy2 Screen Y-length of second edge. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
184 |
* @param dx3 Screen X-length of third edge. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
185 |
* @param dy3 Screen Y-length of third edge. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
186 |
*/ |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
187 |
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3) |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
188 |
{ |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
189 |
/* .... |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
190 |
* .. .... |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
191 |
* .. .... |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
192 |
* .. ^ |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
193 |
* <--__(dx1,dy1) /(dx2,dy2) |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
194 |
* : --__ / : |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
195 |
* : --__ / : |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
196 |
* : *(x,y) : |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
197 |
* : | : |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
198 |
* : | .. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
199 |
* .... |(dx3,dy3) |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
200 |
* .... | .. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
201 |
* ....V. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
202 |
*/ |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
203 |
|
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
204 |
static const byte color = 255; |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
205 |
|
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
206 |
GfxDrawLineUnscaled(x, y, x + dx1, y + dy1, color); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
207 |
GfxDrawLineUnscaled(x, y, x + dx2, y + dy2, color); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
208 |
GfxDrawLineUnscaled(x, y, x + dx3, y + dy3, color); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
209 |
|
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
210 |
GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx2, y + dy1 + dy2, color); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
211 |
GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx3, y + dy1 + dy3, color); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
212 |
GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx1, y + dy2 + dy1, color); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
213 |
GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx3, y + dy2 + dy3, color); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
214 |
GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx1, y + dy3 + dy1, color); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
215 |
GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, color); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
216 |
} |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
217 |
|
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
218 |
|
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
219 |
/** Truncate a given string to a maximum width if neccessary. |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
220 |
* If the string is truncated, add three dots ('...') to show this. |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
221 |
* @param *str string that is checked and possibly truncated |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
222 |
* @param maxw maximum width in pixels of the string |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
223 |
* @return new width of (truncated) string */ |
2113
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
224 |
static int TruncateString(char *str, int maxw) |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
225 |
{ |
2113
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
226 |
int w = 0; |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
227 |
FontSize size = _cur_fontsize; |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
228 |
int ddd, ddd_w; |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
229 |
|
5108
dc67d70b5a45
(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
|
230 |
WChar c; |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
231 |
char *ddd_pos; |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
232 |
|
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
233 |
ddd_w = ddd = GetCharacterWidth(size, '.') * 3; |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
234 |
|
5108
dc67d70b5a45
(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
|
235 |
for (ddd_pos = str; (c = Utf8Consume((const char **)&str)) != '\0'; ) { |
dc67d70b5a45
(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
|
236 |
if (IsPrintable(c)) { |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
237 |
w += GetCharacterWidth(size, c); |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
238 |
|
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
239 |
if (w >= maxw) { |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
240 |
/* string got too big... insert dotdotdot */ |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
241 |
ddd_pos[0] = ddd_pos[1] = ddd_pos[2] = '.'; |
6541
ff575414f0d2
(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:
6505
diff
changeset
|
242 |
ddd_pos[3] = '\0'; |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
243 |
return ddd_w; |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
244 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
245 |
} else { |
5108
dc67d70b5a45
(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
|
246 |
if (c == SCC_SETX) str++; |
dc67d70b5a45
(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
|
247 |
else if (c == SCC_SETXY) str += 2; |
dc67d70b5a45
(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
|
248 |
else if (c == SCC_TINYFONT) { |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
249 |
size = FS_SMALL; |
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
250 |
ddd = GetCharacterWidth(size, '.') * 3; |
5108
dc67d70b5a45
(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
|
251 |
} else if (c == SCC_BIGFONT) { |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
252 |
size = FS_LARGE; |
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
253 |
ddd = GetCharacterWidth(size, '.') * 3; |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
254 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
255 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
256 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
257 |
/* Remember the last position where three dots fit. */ |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
258 |
if (w + ddd < maxw) { |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
259 |
ddd_w = w + ddd; |
2113
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
260 |
ddd_pos = str; |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
261 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
262 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
263 |
|
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
264 |
return w; |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
265 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
266 |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
267 |
static inline int TruncateStringID(StringID src, char *dest, int maxw, const char* last) |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
268 |
{ |
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
269 |
GetString(dest, src, last); |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
270 |
return TruncateString(dest, maxw); |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
271 |
} |
0 | 272 |
|
273 |
/* returns right coordinate */ |
|
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
274 |
int DrawString(int x, int y, StringID str, uint16 color) |
0 | 275 |
{ |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
276 |
char buffer[512]; |
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
277 |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
278 |
GetString(buffer, str, lastof(buffer)); |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
279 |
return DoDrawString(buffer, x, y, color); |
0 | 280 |
} |
281 |
||
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
282 |
int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw) |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
283 |
{ |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
284 |
char buffer[512]; |
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
285 |
TruncateStringID(str, buffer, maxw, lastof(buffer)); |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
286 |
return DoDrawString(buffer, x, y, color); |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
287 |
} |
0 | 288 |
|
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
289 |
|
4314
c7ded7546e7f
(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
|
290 |
int DrawStringRightAligned(int x, int y, StringID str, uint16 color) |
0 | 291 |
{ |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
292 |
char buffer[512]; |
4314
c7ded7546e7f
(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
|
293 |
int w; |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
294 |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
295 |
GetString(buffer, str, lastof(buffer)); |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
296 |
w = GetStringBoundingBox(buffer).width; |
4314
c7ded7546e7f
(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
|
297 |
DoDrawString(buffer, x - w, y, color); |
c7ded7546e7f
(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
|
298 |
|
c7ded7546e7f
(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
|
299 |
return w; |
0 | 300 |
} |
301 |
||
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
302 |
void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw) |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
303 |
{ |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
304 |
char buffer[512]; |
0 | 305 |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
306 |
TruncateStringID(str, buffer, maxw, lastof(buffer)); |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
307 |
DoDrawString(buffer, x - GetStringBoundingBox(buffer).width, y, color); |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
308 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
309 |
|
4314
c7ded7546e7f
(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
|
310 |
void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color) |
c7ded7546e7f
(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
|
311 |
{ |
c7ded7546e7f
(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
|
312 |
int w = DrawStringRightAligned(x, y, str, color); |
c7ded7546e7f
(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
|
313 |
GfxFillRect(x - w, y + 10, x, y + 10, _string_colorremap[1]); |
c7ded7546e7f
(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
|
314 |
} |
c7ded7546e7f
(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
|
315 |
|
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
316 |
|
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
317 |
int DrawStringCentered(int x, int y, StringID str, uint16 color) |
0 | 318 |
{ |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
319 |
char buffer[512]; |
0 | 320 |
int w; |
321 |
||
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
322 |
GetString(buffer, str, lastof(buffer)); |
0 | 323 |
|
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
324 |
w = GetStringBoundingBox(buffer).width; |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
325 |
DoDrawString(buffer, x - w / 2, y, color); |
0 | 326 |
|
327 |
return w; |
|
328 |
} |
|
329 |
||
2113
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
330 |
int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color) |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
331 |
{ |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
332 |
char buffer[512]; |
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
333 |
int w = TruncateStringID(str, buffer, xr - xl, lastof(buffer)); |
2113
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
334 |
return DoDrawString(buffer, (xl + xr - w) / 2, y, color); |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
335 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
336 |
|
2134 | 337 |
int DoDrawStringCentered(int x, int y, const char *str, uint16 color) |
338 |
{ |
|
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
339 |
int w = GetStringBoundingBox(str).width; |
2134 | 340 |
DoDrawString(str, x - w / 2, y, color); |
341 |
return w; |
|
342 |
} |
|
343 |
||
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
344 |
void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color) |
0 | 345 |
{ |
346 |
int w = DrawStringCentered(x, y, str, color); |
|
2010 | 347 |
GfxFillRect(x - (w >> 1), y + 10, x - (w >> 1) + w, y + 10, _string_colorremap[1]); |
0 | 348 |
} |
349 |
||
2113
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
350 |
void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color) |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
351 |
{ |
2113
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
352 |
int w = DrawStringCenteredTruncated(xl, xr, y, str, color); |
f228b399da01
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
353 |
GfxFillRect((xl + xr - w) / 2, y + 10, (xl + xr + w) / 2, y + 10, _string_colorremap[1]); |
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
354 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
355 |
|
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
356 |
/** |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
357 |
* 'Correct' a string to a maximum length. Longer strings will be cut into |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
358 |
* additional lines at whitespace characters if possible. The string parameter |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
359 |
* is modified with terminating characters mid-string which are the |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
360 |
* placeholders for the newlines. |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
361 |
* The string WILL be truncated if there was no whitespace for the current |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
362 |
* line's maximum width. |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
363 |
* |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
364 |
* @note To know if the terminating '\0' is the string end or just a |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
365 |
* newline, the returned 'num' value should be consulted. The num'th '\0', |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
366 |
* starting with index 0 is the real string end. |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
367 |
* |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
368 |
* @param str string to check and correct for length restrictions |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
369 |
* @param maxw the maximum width the string can have on one line |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
370 |
* @return return a 32bit wide number consisting of 2 packed values: |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
371 |
* 0 - 15 the number of lines ADDED to the string |
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
372 |
* 16 - 31 the fontsize in which the length calculation was done at |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
373 |
*/ |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
374 |
uint32 FormatStringLinebreaks(char *str, int maxw) |
1095 | 375 |
{ |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
376 |
FontSize size = _cur_fontsize; |
0 | 377 |
int num = 0; |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
378 |
|
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
379 |
assert(maxw > 0); |
0 | 380 |
|
2952 | 381 |
for (;;) { |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
382 |
char *last_space = NULL; |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
383 |
int w = 0; |
0 | 384 |
|
2952 | 385 |
for (;;) { |
5108
dc67d70b5a45
(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
|
386 |
WChar c = Utf8Consume((const char **)&str); |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
387 |
/* whitespace is where we will insert the line-break */ |
6541
ff575414f0d2
(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:
6505
diff
changeset
|
388 |
if (IsWhitespace(c)) last_space = str; |
0 | 389 |
|
5108
dc67d70b5a45
(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
|
390 |
if (IsPrintable(c)) { |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
391 |
w += GetCharacterWidth(size, c); |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
392 |
/* string is longer than maximum width so we need to decide what to |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
393 |
* do. We can do two things: |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
394 |
* 1. If no whitespace was found at all up until now (on this line) then |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
395 |
* we will truncate the string and bail out. |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
396 |
* 2. In all other cases force a linebreak at the last seen whitespace */ |
0 | 397 |
if (w > maxw) { |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
398 |
if (last_space == NULL) { |
6541
ff575414f0d2
(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:
6505
diff
changeset
|
399 |
*Utf8PrevChar(str) = '\0'; |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
400 |
return num + (size << 16); |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
401 |
} |
0 | 402 |
str = last_space; |
403 |
break; |
|
404 |
} |
|
405 |
} else { |
|
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
406 |
switch (c) { |
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
407 |
case '\0': return num + (size << 16); break; |
5108
dc67d70b5a45
(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
|
408 |
case SCC_SETX: str++; break; |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
409 |
case SCC_SETXY: str += 2; break; |
5108
dc67d70b5a45
(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
|
410 |
case SCC_TINYFONT: size = FS_SMALL; break; |
dc67d70b5a45
(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
|
411 |
case SCC_BIGFONT: size = FS_LARGE; break; |
dc67d70b5a45
(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
|
412 |
case '\n': goto end_of_inner_loop; |
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
413 |
} |
0 | 414 |
} |
415 |
} |
|
4954
d773d01b35f5
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
416 |
end_of_inner_loop: |
6541
ff575414f0d2
(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:
6505
diff
changeset
|
417 |
/* String didn't fit on line (or a '\n' was encountered), so 'dummy' terminate |
ff575414f0d2
(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:
6505
diff
changeset
|
418 |
* and increase linecount. We use Utf8PrevChar() as also non 1 char long |
ff575414f0d2
(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:
6505
diff
changeset
|
419 |
* whitespace seperators are supported */ |
0 | 420 |
num++; |
6541
ff575414f0d2
(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:
6505
diff
changeset
|
421 |
char *s = Utf8PrevChar(str); |
ff575414f0d2
(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:
6505
diff
changeset
|
422 |
*s++ = '\0'; |
ff575414f0d2
(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:
6505
diff
changeset
|
423 |
|
ff575414f0d2
(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:
6505
diff
changeset
|
424 |
/* In which case (see above) we will shift remainder to left and close the gap */ |
ff575414f0d2
(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:
6505
diff
changeset
|
425 |
if (str - s >= 1) { |
ff575414f0d2
(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:
6505
diff
changeset
|
426 |
for (; str[-1] != '\0';) *s++ = *str++; |
ff575414f0d2
(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:
6505
diff
changeset
|
427 |
} |
0 | 428 |
} |
429 |
} |
|
430 |
||
10731
67db0d431d5e
(svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents:
10724
diff
changeset
|
431 |
/** Draw a given string with the centre around the given (x,y) coordinates |
5579
be371346efae
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5568
diff
changeset
|
432 |
* @param x Centre the string around this pixel width |
10731
67db0d431d5e
(svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents:
10724
diff
changeset
|
433 |
* @param y Centre the string around this pixel height |
5579
be371346efae
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5568
diff
changeset
|
434 |
* @param str String to draw |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
435 |
* @param maxw Maximum width the string can have before it is wrapped */ |
2634
16334e1a4862
(svn r3176) Use proper types, not some variants of int
tron
parents:
2631
diff
changeset
|
436 |
void DrawStringMultiCenter(int x, int y, StringID str, int maxw) |
0 | 437 |
{ |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
438 |
char buffer[512]; |
0 | 439 |
uint32 tmp; |
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2548
diff
changeset
|
440 |
int num, w, mt; |
1323
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
441 |
const char *src; |
5108
dc67d70b5a45
(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
|
442 |
WChar c; |
0 | 443 |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
444 |
GetString(buffer, str, lastof(buffer)); |
0 | 445 |
|
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
446 |
tmp = FormatStringLinebreaks(buffer, maxw); |
2635 | 447 |
num = GB(tmp, 0, 16); |
0 | 448 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
449 |
mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16)); |
0 | 450 |
|
451 |
y -= (mt >> 1) * num; |
|
452 |
||
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
453 |
src = buffer; |
0 | 454 |
|
2952 | 455 |
for (;;) { |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
456 |
w = GetStringBoundingBox(src).width; |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
457 |
DoDrawString(src, x - (w >> 1), y, 0xFE); |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
458 |
_cur_fontsize = _last_fontsize; |
0 | 459 |
|
2952 | 460 |
for (;;) { |
5108
dc67d70b5a45
(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
|
461 |
c = Utf8Consume(&src); |
0 | 462 |
if (c == 0) { |
463 |
y += mt; |
|
464 |
if (--num < 0) { |
|
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
465 |
_cur_fontsize = FS_NORMAL; |
0 | 466 |
return; |
467 |
} |
|
468 |
break; |
|
5108
dc67d70b5a45
(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
|
469 |
} else if (c == SCC_SETX) { |
0 | 470 |
src++; |
5108
dc67d70b5a45
(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
|
471 |
} else if (c == SCC_SETXY) { |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
472 |
src += 2; |
0 | 473 |
} |
474 |
} |
|
475 |
} |
|
476 |
} |
|
477 |
||
4928
4cdb51b5db7b
(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
|
478 |
|
6703
9ddfcb1849e4
(svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents:
6683
diff
changeset
|
479 |
uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh) |
2010 | 480 |
{ |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
481 |
char buffer[512]; |
0 | 482 |
uint32 tmp; |
2753 | 483 |
int num, mt; |
4928
4cdb51b5db7b
(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
|
484 |
uint total_height; |
1323
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
485 |
const char *src; |
5108
dc67d70b5a45
(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
|
486 |
WChar c; |
0 | 487 |
|
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
488 |
GetString(buffer, str, lastof(buffer)); |
0 | 489 |
|
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
490 |
tmp = FormatStringLinebreaks(buffer, maxw); |
2635 | 491 |
num = GB(tmp, 0, 16); |
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2548
diff
changeset
|
492 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
493 |
mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16)); |
4928
4cdb51b5db7b
(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
|
494 |
total_height = (num + 1) * mt; |
0 | 495 |
|
6708
77b9506be3c3
(svn r9472) -Fix (r9449): num is the number of newlines in the string, not the number of lines. Also allow for maxh being negative.
maedhros
parents:
6703
diff
changeset
|
496 |
if (maxh != -1 && (int)total_height > maxh) { |
77b9506be3c3
(svn r9472) -Fix (r9449): num is the number of newlines in the string, not the number of lines. Also allow for maxh being negative.
maedhros
parents:
6703
diff
changeset
|
497 |
/* Check there's room enough for at least one line. */ |
77b9506be3c3
(svn r9472) -Fix (r9449): num is the number of newlines in the string, not the number of lines. Also allow for maxh being negative.
maedhros
parents:
6703
diff
changeset
|
498 |
if (maxh < mt) return 0; |
77b9506be3c3
(svn r9472) -Fix (r9449): num is the number of newlines in the string, not the number of lines. Also allow for maxh being negative.
maedhros
parents:
6703
diff
changeset
|
499 |
|
6703
9ddfcb1849e4
(svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents:
6683
diff
changeset
|
500 |
num = maxh / mt - 1; |
9ddfcb1849e4
(svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents:
6683
diff
changeset
|
501 |
total_height = (num + 1) * mt; |
9ddfcb1849e4
(svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents:
6683
diff
changeset
|
502 |
} |
9ddfcb1849e4
(svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents:
6683
diff
changeset
|
503 |
|
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
504 |
src = buffer; |
0 | 505 |
|
2952 | 506 |
for (;;) { |
0 | 507 |
DoDrawString(src, x, y, 0xFE); |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
508 |
_cur_fontsize = _last_fontsize; |
0 | 509 |
|
2952 | 510 |
for (;;) { |
5108
dc67d70b5a45
(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
|
511 |
c = Utf8Consume(&src); |
0 | 512 |
if (c == 0) { |
513 |
y += mt; |
|
514 |
if (--num < 0) { |
|
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
515 |
_cur_fontsize = FS_NORMAL; |
4928
4cdb51b5db7b
(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
|
516 |
return total_height; |
0 | 517 |
} |
518 |
break; |
|
5108
dc67d70b5a45
(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
|
519 |
} else if (c == SCC_SETX) { |
0 | 520 |
src++; |
5108
dc67d70b5a45
(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
|
521 |
} else if (c == SCC_SETXY) { |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
522 |
src += 2; |
0 | 523 |
} |
524 |
} |
|
525 |
} |
|
526 |
} |
|
527 |
||
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
528 |
/** Return the string dimension in pixels. The height and width are returned |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
529 |
* in a single Dimension value. TINYFONT, BIGFONT modifiers are only |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
530 |
* supported as the first character of the string. The returned dimensions |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
531 |
* are therefore a rough estimation correct for all the current strings |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
532 |
* but not every possible combination |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
533 |
* @param str string to calculate pixel-width |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
534 |
* @return string width and height in pixels */ |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
535 |
Dimension GetStringBoundingBox(const char *str) |
1323
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
536 |
{ |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
537 |
FontSize size = _cur_fontsize; |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
538 |
Dimension br; |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
539 |
int max_width; |
5108
dc67d70b5a45
(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
|
540 |
WChar c; |
4557
112872feb6fd
(svn r6404) -Fix: GetStringWidth failed to calculate correct string width if the string
Darkvater
parents:
4525
diff
changeset
|
541 |
|
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
542 |
br.width = br.height = max_width = 0; |
5108
dc67d70b5a45
(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
|
543 |
for (;;) { |
dc67d70b5a45
(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
|
544 |
c = Utf8Consume(&str); |
dc67d70b5a45
(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
|
545 |
if (c == 0) break; |
dc67d70b5a45
(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
|
546 |
if (IsPrintable(c)) { |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
547 |
br.width += GetCharacterWidth(size, c); |
0 | 548 |
} else { |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
549 |
switch (c) { |
5579
be371346efae
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5568
diff
changeset
|
550 |
case SCC_SETX: br.width += (byte)*str++; break; |
5108
dc67d70b5a45
(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
|
551 |
case SCC_SETXY: |
5579
be371346efae
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5568
diff
changeset
|
552 |
br.width += (byte)*str++; |
be371346efae
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5568
diff
changeset
|
553 |
br.height += (byte)*str++; |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
554 |
break; |
5108
dc67d70b5a45
(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
|
555 |
case SCC_TINYFONT: size = FS_SMALL; break; |
dc67d70b5a45
(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
|
556 |
case SCC_BIGFONT: size = FS_LARGE; break; |
dc67d70b5a45
(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
|
557 |
case '\n': |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
558 |
br.height += GetCharacterHeight(size); |
4610
45ac1d25fd62
(svn r6463) -Fix (r6462): Reset the string width to zero on every new line of course...
Darkvater
parents:
4609
diff
changeset
|
559 |
if (br.width > max_width) max_width = br.width; |
45ac1d25fd62
(svn r6463) -Fix (r6462): Reset the string width to zero on every new line of course...
Darkvater
parents:
4609
diff
changeset
|
560 |
br.width = 0; |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
561 |
break; |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
562 |
} |
0 | 563 |
} |
564 |
} |
|
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
565 |
br.height += GetCharacterHeight(size); |
4557
112872feb6fd
(svn r6404) -Fix: GetStringWidth failed to calculate correct string width if the string
Darkvater
parents:
4525
diff
changeset
|
566 |
|
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
567 |
br.width = max(br.width, max_width); |
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
568 |
return br; |
0 | 569 |
} |
570 |
||
10184
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
571 |
void DrawCharCentered(WChar c, int x, int y, uint16 real_color) |
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
572 |
{ |
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
573 |
FontSize size = FS_NORMAL; |
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
574 |
byte color = real_color & 0xFF; |
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
575 |
uint palette = _use_dos_palette ? 1 : 0; |
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
576 |
int w = GetCharacterWidth(size, c); |
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
577 |
|
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
578 |
_string_colorremap[1] = _string_colormap[palette][color].text; |
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
579 |
_string_colorremap[2] = _string_colormap[palette][color].shadow; |
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
580 |
_color_remap_ptr = _string_colorremap; |
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
581 |
|
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
582 |
GfxMainBlitter(GetGlyph(size, c), x - w / 2, y, BM_COLOUR_REMAP); |
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
583 |
} |
fcf5fb2548eb
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents:
6878
diff
changeset
|
584 |
|
4949
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
585 |
/** Draw a string at the given coordinates with the given colour |
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
586 |
* @param string the string to draw |
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
587 |
* @param x offset from left side of the screen, if negative offset from the right side |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
588 |
* @param y offset from top side of the screen, if negative offset from the bottom |
4949
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
589 |
* @param real_color colour of the string, see _string_colormap in |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
590 |
* table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h |
4949
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
591 |
* @return the x-coordinates where the drawing has finished. If nothing is drawn |
fa564e9c2aea
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4928
diff
changeset
|
592 |
* the originally passed x-coordinate is returned */ |
1323
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
593 |
int DoDrawString(const char *string, int x, int y, uint16 real_color) |
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
594 |
{ |
4522 | 595 |
DrawPixelInfo *dpi = _cur_dpi; |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
596 |
FontSize size = _cur_fontsize; |
5108
dc67d70b5a45
(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
|
597 |
WChar c; |
0 | 598 |
int xo = x, yo = y; |
599 |
||
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
600 |
byte color = real_color & 0xFF; |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
601 |
byte previous_color = color; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
602 |
|
0 | 603 |
if (color != 0xFE) { |
604 |
if (x >= dpi->left + dpi->width || |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
605 |
x + _screen.width * 2 <= dpi->left || |
0 | 606 |
y >= dpi->top + dpi->height || |
607 |
y + _screen.height <= dpi->top) |
|
608 |
return x; |
|
609 |
||
610 |
if (color != 0xFF) { |
|
611 |
switch_color:; |
|
657
40a9032b454b
(svn r1091) Fix: Finally station names use 100% the correct color in transparent mode
dominik
parents:
619
diff
changeset
|
612 |
if (real_color & IS_PALETTE_COLOR) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
613 |
_string_colorremap[1] = color; |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
614 |
_string_colorremap[2] = _use_dos_palette ? 1 : 215; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
615 |
} else { |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
616 |
uint palette = _use_dos_palette ? 1 : 0; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
617 |
_string_colorremap[1] = _string_colormap[palette][color].text; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
618 |
_string_colorremap[2] = _string_colormap[palette][color].shadow; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
619 |
} |
0 | 620 |
_color_remap_ptr = _string_colorremap; |
621 |
} |
|
622 |
} |
|
623 |
||
624 |
check_bounds: |
|
625 |
if (y + 19 <= dpi->top || dpi->top + dpi->height <= y) { |
|
626 |
skip_char:; |
|
2952 | 627 |
for (;;) { |
5108
dc67d70b5a45
(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
|
628 |
c = Utf8Consume(&string); |
dc67d70b5a45
(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
|
629 |
if (!IsPrintable(c)) goto skip_cont; |
0 | 630 |
} |
631 |
} |
|
632 |
||
2952 | 633 |
for (;;) { |
5108
dc67d70b5a45
(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
|
634 |
c = Utf8Consume(&string); |
0 | 635 |
skip_cont:; |
636 |
if (c == 0) { |
|
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
637 |
_last_fontsize = size; |
0 | 638 |
return x; |
639 |
} |
|
5108
dc67d70b5a45
(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
|
640 |
if (IsPrintable(c)) { |
0 | 641 |
if (x >= dpi->left + dpi->width) goto skip_char; |
642 |
if (x + 26 >= dpi->left) { |
|
5818
f0cccdf91665
(svn r7982) -Codechange: Enumify graphics blitter modes.
peter1138
parents:
5726
diff
changeset
|
643 |
GfxMainBlitter(GetGlyph(size, c), x, y, BM_COLOUR_REMAP); |
0 | 644 |
} |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
645 |
x += GetCharacterWidth(size, c); |
5108
dc67d70b5a45
(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
|
646 |
} else if (c == '\n') { // newline = {} |
0 | 647 |
x = xo; |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
648 |
y += GetCharacterHeight(size); |
0 | 649 |
goto check_bounds; |
5108
dc67d70b5a45
(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
|
650 |
} else if (c >= SCC_BLUE && c <= SCC_BLACK) { // change color? |
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
651 |
previous_color = color; |
5108
dc67d70b5a45
(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
|
652 |
color = (byte)(c - SCC_BLUE); |
0 | 653 |
goto switch_color; |
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
654 |
} else if (c == SCC_PREVIOUS_COLOUR) { // revert to the previous color |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
655 |
Swap(color, previous_color); |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
656 |
goto switch_color; |
5108
dc67d70b5a45
(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
|
657 |
} else if (c == SCC_SETX) { // {SETX} |
1323
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
658 |
x = xo + (byte)*string++; |
5108
dc67d70b5a45
(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
|
659 |
} else if (c == SCC_SETXY) {// {SETXY} |
1323
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
660 |
x = xo + (byte)*string++; |
41397685320a
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
661 |
y = yo + (byte)*string++; |
5108
dc67d70b5a45
(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
|
662 |
} else if (c == SCC_TINYFONT) { // {TINYFONT} |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
663 |
size = FS_SMALL; |
5108
dc67d70b5a45
(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
|
664 |
} else if (c == SCC_BIGFONT) { // {BIGFONT} |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
665 |
size = FS_LARGE; |
0 | 666 |
} else { |
5579
be371346efae
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5568
diff
changeset
|
667 |
DEBUG(misc, 0, "[utf8] unknown string command character %d", c); |
0 | 668 |
} |
669 |
} |
|
670 |
} |
|
671 |
||
2097
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
672 |
int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw) |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
673 |
{ |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
674 |
char buffer[512]; |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
675 |
ttd_strlcpy(buffer, str, sizeof(buffer)); |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
676 |
TruncateString(buffer, maxw); |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
677 |
return DoDrawString(buffer, x, y, color); |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
678 |
} |
82b1e11883fd
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
679 |
|
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
680 |
void DrawSprite(SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub) |
2010 | 681 |
{ |
6871
5a9dc001e1ad
(svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents:
6870
diff
changeset
|
682 |
if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
683 |
_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH)) + 1; |
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
684 |
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_TRANSPARENT, sub); |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
685 |
} else if (pal != PAL_NONE) { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
686 |
_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH)) + 1; |
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
687 |
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_COLOUR_REMAP, sub); |
0 | 688 |
} else { |
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
689 |
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_NORMAL, sub); |
0 | 690 |
} |
691 |
} |
|
692 |
||
10994
cd9968b6f96b
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents:
10991
diff
changeset
|
693 |
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub) |
0 | 694 |
{ |
4171 | 695 |
const DrawPixelInfo *dpi = _cur_dpi; |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
696 |
Blitter::BlitterParams bp; |
0 | 697 |
|
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
698 |
/* Amount of pixels to clip from the source sprite */ |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
699 |
int clip_left = (sub != NULL ? max(0, -sprite->x_offs + sub->left ) : 0); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
700 |
int clip_top = (sub != NULL ? max(0, -sprite->y_offs + sub->top ) : 0); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
701 |
int clip_right = (sub != NULL ? max(0, sprite->width - (-sprite->x_offs + sub->right + 1)) : 0); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
702 |
int clip_bottom = (sub != NULL ? max(0, sprite->height - (-sprite->y_offs + sub->bottom + 1)) : 0); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
703 |
|
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
704 |
if (clip_left + clip_right >= sprite->width) return; |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
705 |
if (clip_top + clip_bottom >= sprite->height) return; |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
706 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
707 |
/* Move to the correct offset */ |
1351
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
708 |
x += sprite->x_offs; |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
709 |
y += sprite->y_offs; |
0 | 710 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
711 |
/* Copy the main data directly from the sprite */ |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
712 |
bp.sprite = sprite->data; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
713 |
bp.sprite_width = sprite->width; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
714 |
bp.sprite_height = sprite->height; |
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
715 |
bp.width = UnScaleByZoom(sprite->width - clip_left - clip_right, dpi->zoom); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
716 |
bp.height = UnScaleByZoom(sprite->height - clip_top - clip_bottom, dpi->zoom); |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
717 |
bp.top = 0; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
718 |
bp.left = 0; |
10994
cd9968b6f96b
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents:
10991
diff
changeset
|
719 |
bp.skip_left = UnScaleByZoomLower(clip_left, dpi->zoom); |
cd9968b6f96b
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents:
10991
diff
changeset
|
720 |
bp.skip_top = UnScaleByZoomLower(clip_top, dpi->zoom); |
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
721 |
|
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
722 |
x += ScaleByZoom(bp.skip_left, dpi->zoom); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
723 |
y += ScaleByZoom(bp.skip_top, dpi->zoom); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
724 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
725 |
bp.dst = dpi->dst_ptr; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
726 |
bp.pitch = dpi->pitch; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
727 |
bp.remap = _color_remap_ptr; |
0 | 728 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
729 |
assert(sprite->width > 0); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
730 |
assert(sprite->height > 0); |
0 | 731 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
732 |
if (bp.width <= 0) return; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
733 |
if (bp.height <= 0) return; |
0 | 734 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
735 |
y -= dpi->top; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
736 |
/* Check for top overflow */ |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
737 |
if (y < 0) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
738 |
bp.height -= -UnScaleByZoom(y, dpi->zoom); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
739 |
if (bp.height <= 0) return; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
740 |
bp.skip_top += -UnScaleByZoom(y, dpi->zoom); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
741 |
y = 0; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
742 |
} else { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
743 |
bp.top = UnScaleByZoom(y, dpi->zoom); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
744 |
} |
0 | 745 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
746 |
/* Check for bottom overflow */ |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
747 |
y += ScaleByZoom(bp.height, dpi->zoom) - dpi->height; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
748 |
if (y > 0) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
749 |
bp.height -= UnScaleByZoom(y, dpi->zoom); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
750 |
if (bp.height <= 0) return; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
751 |
} |
0 | 752 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
753 |
x -= dpi->left; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
754 |
/* Check for left overflow */ |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
755 |
if (x < 0) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
756 |
bp.width -= -UnScaleByZoom(x, dpi->zoom); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
757 |
if (bp.width <= 0) return; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
758 |
bp.skip_left += -UnScaleByZoom(x, dpi->zoom); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
759 |
x = 0; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
760 |
} else { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
761 |
bp.left = UnScaleByZoom(x, dpi->zoom); |
0 | 762 |
} |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
763 |
|
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
764 |
/* Check for right overflow */ |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
765 |
x += ScaleByZoom(bp.width, dpi->zoom) - dpi->width; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
766 |
if (x > 0) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
767 |
bp.width -= UnScaleByZoom(x, dpi->zoom); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
768 |
if (bp.width <= 0) return; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
769 |
} |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
770 |
|
10994
cd9968b6f96b
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents:
10991
diff
changeset
|
771 |
assert(bp.skip_left + bp.width <= UnScaleByZoom(sprite->width, dpi->zoom)); |
cd9968b6f96b
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents:
10991
diff
changeset
|
772 |
assert(bp.skip_top + bp.height <= UnScaleByZoom(sprite->height, dpi->zoom)); |
cd9968b6f96b
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents:
10991
diff
changeset
|
773 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
774 |
BlitterFactoryBase::GetCurrentBlitter()->Draw(&bp, mode, dpi->zoom); |
0 | 775 |
} |
776 |
||
6573 | 777 |
void DoPaletteAnimations(); |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
778 |
|
6573 | 779 |
void GfxInitPalettes() |
0 | 780 |
{ |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
781 |
memcpy(_cur_palette, _palettes[_use_dos_palette ? 1 : 0], sizeof(_cur_palette)); |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
782 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
783 |
DoPaletteAnimations(); |
0 | 784 |
_pal_first_dirty = 0; |
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
785 |
_pal_count_dirty = 256; |
0 | 786 |
} |
787 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
788 |
#define EXTR(p, q) (((uint16)(_palette_animation_counter * (p)) * (q)) >> 16) |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
789 |
#define EXTR2(p, q) (((uint16)(~_palette_animation_counter * (p)) * (q)) >> 16) |
0 | 790 |
|
6573 | 791 |
void DoPaletteAnimations() |
0 | 792 |
{ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
793 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
4171 | 794 |
const Colour *s; |
795 |
Colour *d; |
|
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
796 |
/* Amount of colors to be rotated. |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
797 |
* A few more for the DOS palette, because the water colors are |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
798 |
* 245-254 for DOS and 217-226 for Windows. */ |
0 | 799 |
const ExtraPaletteValues *ev = &_extra_palette_values; |
2005 | 800 |
int c = _use_dos_palette ? 38 : 28; |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
801 |
Colour old_val[38]; |
2005 | 802 |
uint i; |
803 |
uint j; |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
804 |
uint old_tc = _palette_animation_counter; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
805 |
|
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
806 |
if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
807 |
_palette_animation_counter = 0; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
808 |
} |
0 | 809 |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
810 |
d = &_cur_palette[217]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
811 |
memcpy(old_val, d, c * sizeof(*old_val)); |
0 | 812 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
813 |
/* Dark blue water */ |
10991
d8811e327d12
(svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents:
10731
diff
changeset
|
814 |
s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->ac : ev->a; |
2005 | 815 |
j = EXTR(320, 5); |
816 |
for (i = 0; i != 5; i++) { |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
817 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
818 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
819 |
if (j == 5) j = 0; |
0 | 820 |
} |
821 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
822 |
/* Glittery water */ |
10991
d8811e327d12
(svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents:
10731
diff
changeset
|
823 |
s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->bc : ev->b; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
824 |
j = EXTR(128, 15); |
2005 | 825 |
for (i = 0; i != 5; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
826 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
827 |
j += 3; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
828 |
if (j >= 15) j -= 15; |
0 | 829 |
} |
830 |
||
831 |
s = ev->e; |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
832 |
j = EXTR2(512, 5); |
2005 | 833 |
for (i = 0; i != 5; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
834 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
835 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
836 |
if (j == 5) j = 0; |
0 | 837 |
} |
838 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
839 |
/* Oil refinery fire animation */ |
0 | 840 |
s = ev->oil_ref; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
841 |
j = EXTR2(512, 7); |
2005 | 842 |
for (i = 0; i != 7; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
843 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
844 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
845 |
if (j == 7) j = 0; |
0 | 846 |
} |
847 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
848 |
/* Radio tower blinking */ |
0 | 849 |
{ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
850 |
byte i = (_palette_animation_counter >> 1) & 0x7F; |
2005 | 851 |
byte v; |
852 |
||
0 | 853 |
(v = 255, i < 0x3f) || |
854 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
855 |
(v = 20); |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
856 |
d->r = v; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
857 |
d->g = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
858 |
d->b = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
859 |
d++; |
0 | 860 |
|
861 |
i ^= 0x40; |
|
862 |
(v = 255, i < 0x3f) || |
|
863 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
864 |
(v = 20); |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
865 |
d->r = v; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
866 |
d->g = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
867 |
d->b = 0; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
868 |
d++; |
0 | 869 |
} |
870 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
871 |
/* Handle lighthouse and stadium animation */ |
0 | 872 |
s = ev->lighthouse; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
873 |
j = EXTR(256, 4); |
2005 | 874 |
for (i = 0; i != 4; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
875 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
876 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
877 |
if (j == 4) j = 0; |
0 | 878 |
} |
879 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
880 |
/* Animate water for old DOS graphics */ |
2005 | 881 |
if (_use_dos_palette) { |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
882 |
/* Dark blue water DOS */ |
10991
d8811e327d12
(svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents:
10731
diff
changeset
|
883 |
s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->ac : ev->a; |
2005 | 884 |
j = EXTR(320, 5); |
885 |
for (i = 0; i != 5; i++) { |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
886 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
887 |
j++; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
888 |
if (j == 5) j = 0; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
889 |
} |
915 | 890 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
891 |
/* Glittery water DOS */ |
10991
d8811e327d12
(svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents:
10731
diff
changeset
|
892 |
s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->bc : ev->b; |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
893 |
j = EXTR(128, 15); |
2005 | 894 |
for (i = 0; i != 5; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
895 |
*d++ = s[j]; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
896 |
j += 3; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
897 |
if (j >= 15) j -= 15; |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
898 |
} |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
899 |
} |
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
900 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
901 |
if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
902 |
_palette_animation_counter = old_tc; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
903 |
} else { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
904 |
if (memcmp(old_val, &_cur_palette[217], c * sizeof(*old_val)) != 0) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
905 |
_pal_first_dirty = 217; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
906 |
_pal_count_dirty = c; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
907 |
} |
0 | 908 |
} |
909 |
} |
|
910 |
||
911 |
||
6573 | 912 |
void LoadStringWidthTable() |
0 | 913 |
{ |
2005 | 914 |
uint i; |
0 | 915 |
|
3797
86749951a1bf
(svn r4793) - Replace list of magic numbers (characters that don't exist) with a call to SpriteExists(), when building the character width cache.
peter1138
parents:
3312
diff
changeset
|
916 |
/* Normal font */ |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
917 |
for (i = 0; i != 224; i++) { |
5108
dc67d70b5a45
(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
|
918 |
_stringwidth_table[FS_NORMAL][i] = GetGlyphWidth(FS_NORMAL, i + 32); |
0 | 919 |
} |
920 |
||
3797
86749951a1bf
(svn r4793) - Replace list of magic numbers (characters that don't exist) with a call to SpriteExists(), when building the character width cache.
peter1138
parents:
3312
diff
changeset
|
921 |
/* Small font */ |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
922 |
for (i = 0; i != 224; i++) { |
5108
dc67d70b5a45
(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
|
923 |
_stringwidth_table[FS_SMALL][i] = GetGlyphWidth(FS_SMALL, i + 32); |
0 | 924 |
} |
925 |
||
3797
86749951a1bf
(svn r4793) - Replace list of magic numbers (characters that don't exist) with a call to SpriteExists(), when building the character width cache.
peter1138
parents:
3312
diff
changeset
|
926 |
/* Large font */ |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
927 |
for (i = 0; i != 224; i++) { |
5108
dc67d70b5a45
(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
|
928 |
_stringwidth_table[FS_LARGE][i] = GetGlyphWidth(FS_LARGE, i + 32); |
0 | 929 |
} |
930 |
} |
|
931 |
||
5108
dc67d70b5a45
(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
|
932 |
|
dc67d70b5a45
(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
|
933 |
byte GetCharacterWidth(FontSize size, WChar key) |
dc67d70b5a45
(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
|
934 |
{ |
dc67d70b5a45
(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
|
935 |
if (key >= 32 && key < 256) return _stringwidth_table[size][key - 32]; |
dc67d70b5a45
(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
|
936 |
|
dc67d70b5a45
(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
|
937 |
return GetGlyphWidth(size, key); |
dc67d70b5a45
(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
|
938 |
} |
dc67d70b5a45
(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
|
939 |
|
dc67d70b5a45
(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
|
940 |
|
6573 | 941 |
void ScreenSizeChanged() |
0 | 942 |
{ |
10274
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
943 |
_dirty_bytes_per_line = (_screen.width + DIRTY_BLOCK_WIDTH - 1) / DIRTY_BLOCK_WIDTH; |
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
944 |
_dirty_blocks = ReallocT<byte>(_dirty_blocks, _dirty_bytes_per_line * ((_screen.height + DIRTY_BLOCK_HEIGHT - 1) / DIRTY_BLOCK_HEIGHT)); |
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
945 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
946 |
/* check the dirty rect */ |
0 | 947 |
if (_invalid_rect.right >= _screen.width) _invalid_rect.right = _screen.width; |
948 |
if (_invalid_rect.bottom >= _screen.height) _invalid_rect.bottom = _screen.height; |
|
949 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
950 |
/* screen size changed and the old bitmap is invalid now, so we don't want to undraw it */ |
0 | 951 |
_cursor.visible = false; |
952 |
} |
|
953 |
||
6573 | 954 |
void UndrawMouseCursor() |
0 | 955 |
{ |
956 |
if (_cursor.visible) { |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
957 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
0 | 958 |
_cursor.visible = false; |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
959 |
blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
960 |
_video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y); |
0 | 961 |
} |
962 |
} |
|
963 |
||
6573 | 964 |
void DrawMouseCursor() |
0 | 965 |
{ |
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
966 |
#if defined(WINCE) |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
967 |
/* Don't ever draw the mouse for WinCE, as we work with a stylus */ |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
968 |
return; |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
969 |
#endif |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
970 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
971 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
2010 | 972 |
int x; |
973 |
int y; |
|
974 |
int w; |
|
975 |
int h; |
|
0 | 976 |
|
3312
593789444b01
(svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents:
3252
diff
changeset
|
977 |
/* Redraw mouse cursor but only when it's inside the window */ |
593789444b01
(svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents:
3252
diff
changeset
|
978 |
if (!_cursor.in_window) return; |
593789444b01
(svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents:
3252
diff
changeset
|
979 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
980 |
/* Don't draw the mouse cursor if it's already drawn */ |
0 | 981 |
if (_cursor.visible) { |
2010 | 982 |
if (!_cursor.dirty) return; |
0 | 983 |
UndrawMouseCursor(); |
984 |
} |
|
985 |
||
986 |
w = _cursor.size.x; |
|
987 |
x = _cursor.pos.x + _cursor.offs.x; |
|
2010 | 988 |
if (x < 0) { |
989 |
w += x; |
|
990 |
x = 0; |
|
991 |
} |
|
992 |
if (w > _screen.width - x) w = _screen.width - x; |
|
0 | 993 |
if (w <= 0) return; |
994 |
_cursor.draw_pos.x = x; |
|
995 |
_cursor.draw_size.x = w; |
|
996 |
||
997 |
h = _cursor.size.y; |
|
998 |
y = _cursor.pos.y + _cursor.offs.y; |
|
2010 | 999 |
if (y < 0) { |
1000 |
h += y; |
|
1001 |
y = 0; |
|
1002 |
} |
|
1003 |
if (h > _screen.height - y) h = _screen.height - y; |
|
0 | 1004 |
if (h <= 0) return; |
1005 |
_cursor.draw_pos.y = y; |
|
1006 |
_cursor.draw_size.y = h; |
|
1007 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1008 |
assert(blitter->BufferSize(w, h) < (int)sizeof(_cursor_backup)); |
0 | 1009 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1010 |
/* Make backup of stuff below cursor */ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1011 |
blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y); |
0 | 1012 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1013 |
/* Draw cursor on screen */ |
0 | 1014 |
_cur_dpi = &_screen; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
1015 |
DrawSprite(_cursor.sprite, _cursor.pal, _cursor.pos.x, _cursor.pos.y); |
0 | 1016 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1017 |
_video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y); |
0 | 1018 |
|
1019 |
_cursor.visible = true; |
|
1020 |
_cursor.dirty = false; |
|
1021 |
} |
|
1022 |
||
1023 |
void RedrawScreenRect(int left, int top, int right, int bottom) |
|
1024 |
{ |
|
1025 |
assert(right <= _screen.width && bottom <= _screen.height); |
|
1026 |
if (_cursor.visible) { |
|
1027 |
if (right > _cursor.draw_pos.x && |
|
1028 |
left < _cursor.draw_pos.x + _cursor.draw_size.x && |
|
1029 |
bottom > _cursor.draw_pos.y && |
|
1030 |
top < _cursor.draw_pos.y + _cursor.draw_size.y) { |
|
1031 |
UndrawMouseCursor(); |
|
1032 |
} |
|
1033 |
} |
|
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
1034 |
UndrawChatMessage(); |
0 | 1035 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1036 |
DrawOverlappedWindowForAll(left, top, right, bottom); |
0 | 1037 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1038 |
_video_driver->MakeDirty(left, top, right - left, bottom - top); |
0 | 1039 |
} |
1040 |
||
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1041 |
/*! |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1042 |
* Repaints the rectangle blocks which are marked as 'dirty'. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1043 |
* |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1044 |
* @see SetDirtyBlocks |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1045 |
*/ |
6573 | 1046 |
void DrawDirtyBlocks() |
0 | 1047 |
{ |
1048 |
byte *b = _dirty_blocks; |
|
10274
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1049 |
const int w = Align(_screen.width, DIRTY_BLOCK_WIDTH); |
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1050 |
const int h = Align(_screen.height, DIRTY_BLOCK_HEIGHT); |
2025 | 1051 |
int x; |
1052 |
int y; |
|
0 | 1053 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1054 |
if (IsGeneratingWorld() && !IsGeneratingWorldReadyForPaint()) return; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1055 |
|
2025 | 1056 |
y = 0; |
0 | 1057 |
do { |
2025 | 1058 |
x = 0; |
1059 |
do { |
|
1060 |
if (*b != 0) { |
|
1061 |
int left; |
|
1062 |
int top; |
|
10274
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1063 |
int right = x + DIRTY_BLOCK_WIDTH; |
2025 | 1064 |
int bottom = y; |
1065 |
byte *p = b; |
|
1066 |
int h2; |
|
0 | 1067 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1068 |
/* First try coalescing downwards */ |
0 | 1069 |
do { |
2025 | 1070 |
*p = 0; |
10274
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1071 |
p += _dirty_bytes_per_line; |
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1072 |
bottom += DIRTY_BLOCK_HEIGHT; |
2025 | 1073 |
} while (bottom != h && *p != 0); |
0 | 1074 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1075 |
/* Try coalescing to the right too. */ |
10274
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1076 |
h2 = (bottom - y) / DIRTY_BLOCK_HEIGHT; |
2025 | 1077 |
assert(h2 > 0); |
1078 |
p = b; |
|
0 | 1079 |
|
2025 | 1080 |
while (right != w) { |
1081 |
byte *p2 = ++p; |
|
1082 |
int h = h2; |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1083 |
/* Check if a full line of dirty flags is set. */ |
2025 | 1084 |
do { |
1085 |
if (!*p2) goto no_more_coalesc; |
|
10274
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1086 |
p2 += _dirty_bytes_per_line; |
2025 | 1087 |
} while (--h != 0); |
1088 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1089 |
/* Wohoo, can combine it one step to the right! |
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1090 |
* Do that, and clear the bits. */ |
10274
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1091 |
right += DIRTY_BLOCK_WIDTH; |
2025 | 1092 |
|
1093 |
h = h2; |
|
1094 |
p2 = p; |
|
1095 |
do { |
|
1096 |
*p2 = 0; |
|
10274
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1097 |
p2 += _dirty_bytes_per_line; |
2025 | 1098 |
} while (--h != 0); |
1099 |
} |
|
1100 |
no_more_coalesc: |
|
1101 |
||
1102 |
left = x; |
|
1103 |
top = y; |
|
1104 |
||
1105 |
if (left < _invalid_rect.left ) left = _invalid_rect.left; |
|
1106 |
if (top < _invalid_rect.top ) top = _invalid_rect.top; |
|
1107 |
if (right > _invalid_rect.right ) right = _invalid_rect.right; |
|
1108 |
if (bottom > _invalid_rect.bottom) bottom = _invalid_rect.bottom; |
|
1109 |
||
1110 |
if (left < right && top < bottom) { |
|
1111 |
RedrawScreenRect(left, top, right, bottom); |
|
1112 |
} |
|
1113 |
||
0 | 1114 |
} |
10274
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1115 |
} while (b++, (x += DIRTY_BLOCK_WIDTH) != w); |
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1116 |
} while (b += -(w / DIRTY_BLOCK_WIDTH) + _dirty_bytes_per_line, (y += DIRTY_BLOCK_HEIGHT) != h); |
0 | 1117 |
|
1118 |
_invalid_rect.left = w; |
|
1119 |
_invalid_rect.top = h; |
|
1120 |
_invalid_rect.right = 0; |
|
1121 |
_invalid_rect.bottom = 0; |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1122 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1123 |
/* If we are generating a world, and waiting for a paint run, mark it here |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1124 |
* as done painting, so we can continue generating. */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1125 |
if (IsGeneratingWorld() && IsGeneratingWorldReadyForPaint()) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1126 |
SetGeneratingWorldPaintStatus(false); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1127 |
} |
0 | 1128 |
} |
1129 |
||
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1130 |
/*! |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1131 |
* This function extends the internal _invalid_rect rectangle as it |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1132 |
* now contains the rectangle defined by the given parameters. Note |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1133 |
* the point (0,0) is top left. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1134 |
* |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1135 |
* @param left The left edge of the rectangle |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1136 |
* @param top The top edge of the rectangle |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1137 |
* @param right The right edge of the rectangle |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1138 |
* @param bottom The bottm edge of the rectangle |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1139 |
* @see DrawDirtyBlocks |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1140 |
* |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1141 |
* @todo The name of the function should be called like @c AddDirtyBlock as |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1142 |
* it neither set a dirty rect nor add several dirty rects although |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1143 |
* the function name is in plural. (Progman) |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1144 |
*/ |
0 | 1145 |
void SetDirtyBlocks(int left, int top, int right, int bottom) |
1146 |
{ |
|
1147 |
byte *b; |
|
2010 | 1148 |
int width; |
1149 |
int height; |
|
0 | 1150 |
|
1151 |
if (left < 0) left = 0; |
|
1152 |
if (top < 0) top = 0; |
|
1153 |
if (right > _screen.width) right = _screen.width; |
|
1154 |
if (bottom > _screen.height) bottom = _screen.height; |
|
1155 |
||
2010 | 1156 |
if (left >= right || top >= bottom) return; |
0 | 1157 |
|
2010 | 1158 |
if (left < _invalid_rect.left ) _invalid_rect.left = left; |
1159 |
if (top < _invalid_rect.top ) _invalid_rect.top = top; |
|
1160 |
if (right > _invalid_rect.right ) _invalid_rect.right = right; |
|
1161 |
if (bottom > _invalid_rect.bottom) _invalid_rect.bottom = bottom; |
|
0 | 1162 |
|
10274
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1163 |
left /= DIRTY_BLOCK_WIDTH; |
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1164 |
top /= DIRTY_BLOCK_HEIGHT; |
0 | 1165 |
|
10274
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1166 |
b = _dirty_blocks + top * _dirty_bytes_per_line + left; |
0 | 1167 |
|
10274
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1168 |
width = ((right - 1) / DIRTY_BLOCK_WIDTH) - left + 1; |
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1169 |
height = ((bottom - 1) / DIRTY_BLOCK_HEIGHT) - top + 1; |
0 | 1170 |
|
1171 |
assert(width > 0 && height > 0); |
|
1172 |
||
1173 |
do { |
|
2010 | 1174 |
int i = width; |
1175 |
||
0 | 1176 |
do b[--i] = 0xFF; while (i); |
1177 |
||
10274
b3c58f3df92b
(svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents:
10184
diff
changeset
|
1178 |
b += _dirty_bytes_per_line; |
2010 | 1179 |
} while (--height != 0); |
0 | 1180 |
} |
1181 |
||
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1182 |
/*! |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1183 |
* This function mark the whole screen as dirty. This results in repainting |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1184 |
* the whole screen. Use this with care as this function will break the |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1185 |
* idea about marking only parts of the screen as 'dirty'. |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1186 |
*/ |
6573 | 1187 |
void MarkWholeScreenDirty() |
0 | 1188 |
{ |
1189 |
SetDirtyBlocks(0, 0, _screen.width, _screen.height); |
|
1190 |
} |
|
1191 |
||
4958 | 1192 |
/** Set up a clipping area for only drawing into a certain area. To do this, |
1193 |
* Fill a DrawPixelInfo object with the supplied relative rectangle, backup |
|
1194 |
* the original (calling) _cur_dpi and assign the just returned DrawPixelInfo |
|
1195 |
* _cur_dpi. When you are done, give restore _cur_dpi's original value |
|
1196 |
* @param *n the DrawPixelInfo that will be the clipping rectangle box allowed |
|
1197 |
* for drawing |
|
1198 |
* @param left,top,width,height the relative coordinates of the clipping |
|
1199 |
* rectangle relative to the current _cur_dpi. This will most likely be the |
|
1200 |
* offset from the calling window coordinates |
|
1201 |
* @return return false if the requested rectangle is not possible with the |
|
1202 |
* current dpi pointer. Only continue of the return value is true, or you'll |
|
1203 |
* get some nasty results */ |
|
4429
1bb01569940c
(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
|
1204 |
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height) |
0 | 1205 |
{ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1206 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
4429
1bb01569940c
(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
|
1207 |
const DrawPixelInfo *o = _cur_dpi; |
0 | 1208 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6708
diff
changeset
|
1209 |
n->zoom = ZOOM_LVL_NORMAL; |
0 | 1210 |
|
1211 |
assert(width > 0); |
|
1212 |
assert(height > 0); |
|
1213 |
||
1214 |
if ((left -= o->left) < 0) { |
|
2010 | 1215 |
width += left; |
4525
fa3aabcd12bc
(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
|
1216 |
if (width <= 0) return false; |
0 | 1217 |
n->left = -left; |
1218 |
left = 0; |
|
4429
1bb01569940c
(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
|
1219 |
} else { |
1bb01569940c
(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
|
1220 |
n->left = 0; |
0 | 1221 |
} |
1222 |
||
4429
1bb01569940c
(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
|
1223 |
if (width > o->width - left) { |
1bb01569940c
(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
|
1224 |
width = o->width - left; |
4525
fa3aabcd12bc
(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
|
1225 |
if (width <= 0) return false; |
0 | 1226 |
} |
1227 |
n->width = width; |
|
1228 |
||
1229 |
if ((top -= o->top) < 0) { |
|
2010 | 1230 |
height += top; |
4525
fa3aabcd12bc
(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
|
1231 |
if (height <= 0) return false; |
0 | 1232 |
n->top = -top; |
1233 |
top = 0; |
|
4429
1bb01569940c
(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
|
1234 |
} else { |
1bb01569940c
(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
|
1235 |
n->top = 0; |
0 | 1236 |
} |
1237 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1238 |
n->dst_ptr = blitter->MoveTo(o->dst_ptr, left, top); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1239 |
n->pitch = o->pitch; |
0 | 1240 |
|
4429
1bb01569940c
(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
|
1241 |
if (height > o->height - top) { |
1bb01569940c
(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
|
1242 |
height = o->height - top; |
4525
fa3aabcd12bc
(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
|
1243 |
if (height <= 0) return false; |
0 | 1244 |
} |
1245 |
n->height = height; |
|
1246 |
||
1247 |
return true; |
|
1248 |
} |
|
1249 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
1250 |
static void SetCursorSprite(SpriteID cursor, SpriteID pal) |
0 | 1251 |
{ |
1252 |
CursorVars *cv = &_cursor; |
|
1348 | 1253 |
const Sprite *p; |
0 | 1254 |
|
2010 | 1255 |
if (cv->sprite == cursor) return; |
0 | 1256 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
1257 |
p = GetSprite(GB(cursor, 0, SPRITE_WIDTH)); |
0 | 1258 |
cv->sprite = cursor; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
1259 |
cv->pal = pal; |
1348 | 1260 |
cv->size.y = p->height; |
1351
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1261 |
cv->size.x = p->width; |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1262 |
cv->offs.x = p->x_offs; |
3e7aa0d35f8f
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1263 |
cv->offs.y = p->y_offs; |
0 | 1264 |
|
1265 |
cv->dirty = true; |
|
1266 |
} |
|
1267 |
||
6573 | 1268 |
static void SwitchAnimatedCursor() |
0 | 1269 |
{ |
6464
1c3515433409
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5919
diff
changeset
|
1270 |
const AnimCursor *cur = _cursor.animate_cur; |
0 | 1271 |
|
6464
1c3515433409
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5919
diff
changeset
|
1272 |
if (cur == NULL || cur->sprite == AnimCursor::LAST) cur = _cursor.animate_list; |
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1273 |
|
6464
1c3515433409
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5919
diff
changeset
|
1274 |
SetCursorSprite(cur->sprite, _cursor.pal); |
0 | 1275 |
|
6464
1c3515433409
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5919
diff
changeset
|
1276 |
_cursor.animate_timeout = cur->display_time; |
1c3515433409
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5919
diff
changeset
|
1277 |
_cursor.animate_cur = cur + 1; |
0 | 1278 |
} |
1279 |
||
6573 | 1280 |
void CursorTick() |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1281 |
{ |
2010 | 1282 |
if (_cursor.animate_timeout != 0 && --_cursor.animate_timeout == 0) |
0 | 1283 |
SwitchAnimatedCursor(); |
1284 |
} |
|
1285 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
1286 |
void SetMouseCursor(SpriteID sprite, SpriteID pal) |
0 | 1287 |
{ |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1288 |
/* Turn off animation */ |
0 | 1289 |
_cursor.animate_timeout = 0; |
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6464
diff
changeset
|
1290 |
/* Set cursor */ |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
1291 |
SetCursorSprite(sprite, pal); |
0 | 1292 |
} |
1293 |
||
6464
1c3515433409
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5919
diff
changeset
|
1294 |
void SetAnimatedMouseCursor(const AnimCursor *table) |
0 | 1295 |
{ |
1296 |
_cursor.animate_list = table; |
|
1297 |
_cursor.animate_cur = NULL; |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5887
diff
changeset
|
1298 |
_cursor.pal = PAL_NONE; |
0 | 1299 |
SwitchAnimatedCursor(); |
1300 |
} |
|
1301 |
||
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1302 |
bool ChangeResInGame(int width, int height) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
1303 |
{ |
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1304 |
return (_screen.width == width && _screen.height == height) || _video_driver->ChangeResolution(width, height); |
0 | 1305 |
} |
298
b3e83b94be19
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1306 |
|
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
1307 |
bool ToggleFullScreen(bool fs) |
5217
21c23507c002
(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
|
1308 |
{ |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
1309 |
bool result = _video_driver->ToggleFullscreen(fs); |
5217
21c23507c002
(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
|
1310 |
if (_fullscreen != fs && _num_resolutions == 0) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5217
diff
changeset
|
1311 |
DEBUG(driver, 0, "Could not find a suitable fullscreen resolution"); |
5217
21c23507c002
(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
|
1312 |
} |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
1313 |
return result; |
5217
21c23507c002
(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
|
1314 |
} |
1829
0b6de3b4458a
(svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents:
1806
diff
changeset
|
1315 |
|
10994
cd9968b6f96b
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents:
10991
diff
changeset
|
1316 |
static int CDECL compare_res(const Dimension *pa, const Dimension *pb) |
298
b3e83b94be19
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1317 |
{ |
10994
cd9968b6f96b
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents:
10991
diff
changeset
|
1318 |
int x = pa->width - pb->width; |
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1319 |
if (x != 0) return x; |
10994
cd9968b6f96b
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents:
10991
diff
changeset
|
1320 |
return pa->height - pb->height; |
1806
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1321 |
} |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1322 |
|
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1323 |
void SortResolutions(int count) |
75dc9c737892
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1324 |
{ |
10994
cd9968b6f96b
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents:
10991
diff
changeset
|
1325 |
QSortT(_resolutions, count, &compare_res); |
298
b3e83b94be19
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1326 |
} |