author | KUDr |
Sat, 21 Apr 2007 08:23:57 +0000 | |
branch | cpp_gui |
changeset 6308 | 646711c5feaa |
parent 6307 | f40e88cff863 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
6263
diff
changeset
|
3 |
/** @file viewport.cpp */ |
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
6263
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1864
diff
changeset
|
6 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1172
diff
changeset
|
7 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
8 |
#include "functions.h" |
2662
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
9 |
#include "gui.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:
1309
diff
changeset
|
10 |
#include "spritecache.h" |
1309
dab90d4cbf2d
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1299
diff
changeset
|
11 |
#include "strings.h" |
1363
01d3de5d8039
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1349
diff
changeset
|
12 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
500
diff
changeset
|
13 |
#include "table/strings.h" |
6307 | 14 |
#include "landscape.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
657
diff
changeset
|
15 |
#include "map.h" |
0 | 16 |
#include "viewport.h" |
17 |
#include "window.h" |
|
18 |
#include "vehicle.h" |
|
19 |
#include "station.h" |
|
20 |
#include "gfx.h" |
|
21 |
#include "town.h" |
|
988
2482369a61ff
(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
981
diff
changeset
|
22 |
#include "signs.h" |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
23 |
#include "waypoint.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2125
diff
changeset
|
24 |
#include "variables.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2662
diff
changeset
|
25 |
#include "train.h" |
0 | 26 |
|
133
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
27 |
#define VIEWPORT_DRAW_MEM (65536 * 2) |
0 | 28 |
|
6307 | 29 |
/* XXX - maximum viewports is maximum windows - 2 (main toolbar + status bar) */ |
5122
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
30 |
static ViewPort _viewports[25 - 2]; |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
31 |
static uint32 _active_viewports; ///< bitmasked variable where each bit signifies if a viewport is in use or not |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
32 |
assert_compile(lengthof(_viewports) < sizeof(_active_viewports) * 8); |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
33 |
|
0 | 34 |
static bool _added_tile_sprite; |
35 |
static bool _offset_ground_sprites; |
|
36 |
||
4186
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
37 |
/* The in-game coordiante system looks like this * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
38 |
* * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
39 |
* ^ Z * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
40 |
* | * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
41 |
* | * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
42 |
* | * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
43 |
* | * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
44 |
* / \ * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
45 |
* / \ * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
46 |
* / \ * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
47 |
* / \ * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
48 |
* X < > Y * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
49 |
*/ |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
50 |
|
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
51 |
struct StringSpriteToDraw { |
0 | 52 |
uint16 string; |
53 |
uint16 color; |
|
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
54 |
StringSpriteToDraw *next; |
849
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
55 |
int32 x; |
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
56 |
int32 y; |
5026
c8b7148798ac
(svn r7067) Remove the unused parameter params_3 from AddStringToDraw()
tron
parents:
5025
diff
changeset
|
57 |
uint32 params[2]; |
0 | 58 |
uint16 width; |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
59 |
}; |
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
60 |
|
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
61 |
struct TileSpriteToDraw { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
62 |
SpriteID image; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
63 |
SpriteID pal; |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
64 |
TileSpriteToDraw *next; |
849
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
65 |
int32 x; |
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
66 |
int32 y; |
0 | 67 |
byte z; |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
68 |
}; |
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
69 |
|
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
70 |
struct ChildScreenSpriteToDraw { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
71 |
SpriteID image; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
72 |
SpriteID pal; |
849
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
73 |
int32 x; |
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
74 |
int32 y; |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
75 |
ChildScreenSpriteToDraw *next; |
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
76 |
}; |
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
77 |
|
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
78 |
struct ParentSpriteToDraw { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
79 |
SpriteID image; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
80 |
SpriteID pal; |
849
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
81 |
int32 left; |
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
82 |
int32 top; |
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
83 |
int32 right; |
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
84 |
int32 bottom; |
4186
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
85 |
int32 xmin; |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
86 |
int32 ymin; |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
87 |
int32 xmax; |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
88 |
int32 ymax; |
0 | 89 |
ChildScreenSpriteToDraw *child; |
90 |
byte unk16; |
|
4186
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
91 |
byte zmin; |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
92 |
byte zmax; |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
93 |
}; |
0 | 94 |
|
6307 | 95 |
/* Quick hack to know how much memory to reserve when allocating from the spritelist |
96 |
* to prevent a buffer overflow. */ |
|
2109
c3202f3988df
(svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents:
2085
diff
changeset
|
97 |
#define LARGEST_SPRITELIST_STRUCT ParentSpriteToDraw |
c3202f3988df
(svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents:
2085
diff
changeset
|
98 |
|
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
99 |
struct ViewportDrawer { |
0 | 100 |
DrawPixelInfo dpi; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
101 |
|
2116 | 102 |
byte *spritelist_mem; |
103 |
const byte *eof_spritelist_mem; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
104 |
|
0 | 105 |
StringSpriteToDraw **last_string, *first_string; |
106 |
TileSpriteToDraw **last_tile, *first_tile; |
|
107 |
||
108 |
ChildScreenSpriteToDraw **last_child; |
|
109 |
||
110 |
ParentSpriteToDraw **parent_list; |
|
2116 | 111 |
ParentSpriteToDraw * const *eof_parent_list; |
0 | 112 |
|
113 |
byte combine_sprites; |
|
114 |
||
115 |
int offs_x, offs_y; // used when drawing ground sprites relative |
|
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
116 |
}; |
0 | 117 |
|
118 |
static ViewportDrawer *_cur_vd; |
|
119 |
||
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
120 |
TileHighlightData _thd; |
0 | 121 |
static TileInfo *_cur_ti; |
122 |
||
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
123 |
extern void SmallMapCenterOnCurrentPos(BaseWindow *w); |
0 | 124 |
|
2116 | 125 |
static Point MapXYZToViewport(const ViewPort *vp, uint x, uint y, uint z) |
0 | 126 |
{ |
127 |
Point p = RemapCoords(x, y, z); |
|
2116 | 128 |
p.x -= vp->virtual_width / 2; |
129 |
p.y -= vp->virtual_height / 2; |
|
0 | 130 |
return p; |
131 |
} |
|
132 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
133 |
void InitViewports() { |
5122
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
134 |
memset(_viewports, 0, sizeof(_viewports)); |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
135 |
_active_viewports = 0; |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
136 |
} |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
137 |
|
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
138 |
void DeleteWindowViewport(BaseWindow *w) |
5122
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
139 |
{ |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
140 |
CLRBIT(_active_viewports, w->viewport - _viewports); |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
141 |
w->viewport->width = 0; |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
142 |
w->viewport = NULL; |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
143 |
} |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
144 |
|
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
145 |
void AssignWindowViewport(BaseWindow *w, int x, int y, |
0 | 146 |
int width, int height, uint32 follow_flags, byte zoom) |
147 |
{ |
|
148 |
ViewPort *vp; |
|
149 |
Point pt; |
|
150 |
uint32 bit; |
|
151 |
||
5122
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
152 |
for (vp = _viewports, bit = 0; ; vp++, bit++) { |
2116 | 153 |
assert(vp != endof(_viewports)); |
154 |
if (vp->width == 0) break; |
|
0 | 155 |
} |
5122
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
156 |
SETBIT(_active_viewports, bit); |
0 | 157 |
|
6263
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
158 |
vp->left = x + w->Left(); |
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
159 |
vp->top = y + w->Top(); |
0 | 160 |
vp->width = width; |
161 |
vp->height = height; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
162 |
|
0 | 163 |
vp->zoom = zoom; |
164 |
||
165 |
vp->virtual_width = width << zoom; |
|
166 |
vp->virtual_height = height << zoom; |
|
167 |
||
168 |
if (follow_flags & 0x80000000) { |
|
2116 | 169 |
const Vehicle *veh; |
170 |
||
171 |
WP(w, vp_d).follow_vehicle = (VehicleID)(follow_flags & 0xFFFF); |
|
172 |
veh = GetVehicle(WP(w, vp_d).follow_vehicle); |
|
0 | 173 |
pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos); |
174 |
} else { |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
175 |
uint x = TileX(follow_flags) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
176 |
uint y = TileY(follow_flags) * TILE_SIZE; |
2116 | 177 |
|
178 |
WP(w, vp_d).follow_vehicle = INVALID_VEHICLE; |
|
179 |
pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y)); |
|
0 | 180 |
} |
181 |
||
2116 | 182 |
WP(w, vp_d).scrollpos_x = pt.x; |
183 |
WP(w, vp_d).scrollpos_y = pt.y; |
|
0 | 184 |
w->viewport = vp; |
185 |
vp->virtual_left = 0;//pt.x; |
|
186 |
vp->virtual_top = 0;//pt.y; |
|
187 |
} |
|
188 |
||
189 |
static Point _vp_move_offs; |
|
190 |
||
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6206
diff
changeset
|
191 |
static void DoSetViewportPosition(WindowList::Iterator vit, int left, int top, int width, int height) |
0 | 192 |
{ |
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
193 |
//BaseWindow *w = (*wit).w; |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
194 |
|
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
195 |
for (WindowList::Iterator wit = vit; wit != BaseWindow::s_list.m_list.end(); wit++) { |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
196 |
const BaseWindow *w = (*wit).w; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
197 |
|
6263
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
198 |
if (left + width > w->Left() && |
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
199 |
w->Left() + w->Width() > left && |
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
200 |
top + height > w->Top() && |
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
201 |
w->Top() + w->Height() > top) { |
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
202 |
|
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
203 |
if (left < w->Left()) { |
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
204 |
DoSetViewportPosition(wit, left, top, w->Left() - left, height); |
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
205 |
DoSetViewportPosition(wit, left + (w->Left() - left), top, width - (w->Left() - left), height); |
0 | 206 |
return; |
207 |
} |
|
208 |
||
6263
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
209 |
if (left + width > w->Left() + w->Width()) { |
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
210 |
DoSetViewportPosition(wit, left, top, (w->Left() + w->Width() - left), height); |
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
211 |
DoSetViewportPosition(wit, left + (w->Left() + w->Width() - left), top, width - (w->Left() + w->Width() - left) , height); |
0 | 212 |
return; |
213 |
} |
|
214 |
||
6263
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
215 |
if (top < w->Top()) { |
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
216 |
DoSetViewportPosition(wit, left, top, width, (w->Top() - top)); |
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
217 |
DoSetViewportPosition(wit, left, top + (w->Top() - top), width, height - (w->Top() - top)); |
0 | 218 |
return; |
219 |
} |
|
220 |
||
6263
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
221 |
if (top + height > w->Top() + w->Height()) { |
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
222 |
DoSetViewportPosition(wit, left, top, width, (w->Top() + w->Height() - top)); |
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
223 |
DoSetViewportPosition(wit, left, top + (w->Top() + w->Height() - top), width , height - (w->Top() + w->Height() - top)); |
0 | 224 |
return; |
225 |
} |
|
226 |
||
227 |
return; |
|
228 |
} |
|
229 |
} |
|
230 |
||
231 |
{ |
|
232 |
int xo = _vp_move_offs.x; |
|
233 |
int yo = _vp_move_offs.y; |
|
234 |
||
235 |
if (abs(xo) >= width || abs(yo) >= height) { |
|
236 |
/* fully_outside */ |
|
2116 | 237 |
RedrawScreenRect(left, top, left + width, top + height); |
0 | 238 |
return; |
239 |
} |
|
240 |
||
241 |
GfxScroll(left, top, width, height, xo, yo); |
|
242 |
||
243 |
if (xo > 0) { |
|
244 |
RedrawScreenRect(left, top, xo + left, top + height); |
|
245 |
left += xo; |
|
246 |
width -= xo; |
|
247 |
} else if (xo < 0) { |
|
248 |
RedrawScreenRect(left+width+xo, top, left+width, top + height); |
|
249 |
width += xo; |
|
250 |
} |
|
251 |
||
252 |
if (yo > 0) { |
|
253 |
RedrawScreenRect(left, top, width+left, top + yo); |
|
254 |
} else if (yo < 0) { |
|
255 |
RedrawScreenRect(left, top + height + yo, width+left, top + height); |
|
256 |
} |
|
257 |
} |
|
258 |
} |
|
259 |
||
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
260 |
static void SetViewportPosition(BaseWindow *w, int x, int y) |
0 | 261 |
{ |
262 |
ViewPort *vp = w->viewport; |
|
263 |
int old_left = vp->virtual_left; |
|
264 |
int old_top = vp->virtual_top; |
|
265 |
int i; |
|
266 |
int left, top, width, height; |
|
267 |
||
268 |
vp->virtual_left = x; |
|
269 |
vp->virtual_top = y; |
|
270 |
||
271 |
old_left >>= vp->zoom; |
|
272 |
old_top >>= vp->zoom; |
|
273 |
x >>= vp->zoom; |
|
274 |
y >>= vp->zoom; |
|
275 |
||
276 |
old_left -= x; |
|
277 |
old_top -= y; |
|
278 |
||
2116 | 279 |
if (old_top == 0 && old_left == 0) return; |
0 | 280 |
|
281 |
_vp_move_offs.x = old_left; |
|
282 |
_vp_move_offs.y = old_top; |
|
283 |
||
284 |
left = vp->left; |
|
285 |
top = vp->top; |
|
286 |
width = vp->width; |
|
287 |
height = vp->height; |
|
288 |
||
289 |
if (left < 0) { |
|
290 |
width += left; |
|
291 |
left = 0; |
|
292 |
} |
|
293 |
||
2116 | 294 |
i = left + width - _screen.width; |
295 |
if (i >= 0) width -= i; |
|
0 | 296 |
|
297 |
if (width > 0) { |
|
298 |
if (top < 0) { |
|
299 |
height += top; |
|
300 |
top = 0; |
|
301 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
302 |
|
2116 | 303 |
i = top + height - _screen.height; |
304 |
if (i >= 0) height -= i; |
|
0 | 305 |
|
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
306 |
WindowList::Iterator it = BaseWindow::s_list.Find(w); |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6206
diff
changeset
|
307 |
if (height > 0) DoSetViewportPosition(++it, left, top, width, height); |
0 | 308 |
} |
309 |
} |
|
310 |
||
311 |
||
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
312 |
ViewPort *IsPtInWindowViewport(const BaseWindow *w, int x, int y) |
0 | 313 |
{ |
314 |
ViewPort *vp = w->viewport; |
|
2116 | 315 |
|
0 | 316 |
if (vp != NULL && |
317 |
IS_INT_INSIDE(x, vp->left, vp->left + vp->width) && |
|
318 |
IS_INT_INSIDE(y, vp->top, vp->top + vp->height)) |
|
319 |
return vp; |
|
320 |
||
321 |
return NULL; |
|
322 |
} |
|
323 |
||
2116 | 324 |
static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y) |
1095 | 325 |
{ |
0 | 326 |
Point pt; |
327 |
int a,b; |
|
5014
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
328 |
uint z; |
0 | 329 |
|
330 |
if ( (uint)(x -= vp->left) >= (uint)vp->width || |
|
331 |
(uint)(y -= vp->top) >= (uint)vp->height) { |
|
6259
0f36789984b1
(svn r8803) [cpp_gui] -Codechange: point structures (Point, Point16) made compatible
KUDr
parents:
6258
diff
changeset
|
332 |
Point pt(-1, -1); |
0 | 333 |
return pt; |
334 |
} |
|
335 |
||
336 |
x = ((x << vp->zoom) + vp->virtual_left) >> 2; |
|
337 |
y = ((y << vp->zoom) + vp->virtual_top) >> 1; |
|
338 |
||
339 |
a = y-x; |
|
340 |
b = y+x; |
|
341 |
||
5014
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
342 |
/* we need to move variables in to the valid range, as the |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
343 |
* GetTileZoomCenterWindow() function can call here with invalid x and/or y, |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
344 |
* when the user tries to zoom out along the sides of the map */ |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
345 |
a = clamp(a, 0, (int)(MapMaxX() * TILE_SIZE) - 1); |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
346 |
b = clamp(b, 0, (int)(MapMaxY() * TILE_SIZE) - 1); |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
347 |
|
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
348 |
z = GetSlopeZ(a, b ) / 2; |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
349 |
z = GetSlopeZ(a + z, b + z) / 2; |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
350 |
z = GetSlopeZ(a + z, b + z) / 2; |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
351 |
z = GetSlopeZ(a + z, b + z) / 2; |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
352 |
z = GetSlopeZ(a + z, b + z) / 2; |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
353 |
|
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
354 |
pt.x = a + z; |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
355 |
pt.y = b + z; |
0 | 356 |
|
357 |
return pt; |
|
358 |
} |
|
359 |
||
981
25c7b445dcb8
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
360 |
/* When used for zooming, check area below current coordinates (x,y) |
25c7b445dcb8
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
361 |
* and return the tile of the zoomed out/in position (zoom_x, zoom_y) |
25c7b445dcb8
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
362 |
* when you just want the tile, make x = zoom_x and y = zoom_y */ |
25c7b445dcb8
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
363 |
static Point GetTileFromScreenXY(int x, int y, int zoom_x, int zoom_y) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
364 |
{ |
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
365 |
BaseWindow *w; |
0 | 366 |
ViewPort *vp; |
367 |
Point pt; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
368 |
|
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
369 |
if ( (w = BaseWindow::FindFromPt(x, y)) != NULL && |
0 | 370 |
(vp = IsPtInWindowViewport(w, x, y)) != NULL) |
981
25c7b445dcb8
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
371 |
return TranslateXYToTileCoord(vp, zoom_x, zoom_y); |
0 | 372 |
|
373 |
pt.y = pt.x = -1; |
|
374 |
return pt; |
|
375 |
} |
|
376 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
377 |
Point GetTileBelowCursor() |
0 | 378 |
{ |
981
25c7b445dcb8
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
379 |
return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, _cursor.pos.x, _cursor.pos.y); |
0 | 380 |
} |
381 |
||
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
382 |
|
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
383 |
Point GetTileZoomCenterWindow(bool in, BaseWindow * w) |
0 | 384 |
{ |
385 |
int x, y; |
|
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
386 |
ViewPort * vp; |
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
387 |
|
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
388 |
vp = w->viewport; |
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
389 |
|
2026 | 390 |
if (in) { |
2116 | 391 |
x = ((_cursor.pos.x - vp->left) >> 1) + (vp->width >> 2); |
392 |
y = ((_cursor.pos.y - vp->top) >> 1) + (vp->height >> 2); |
|
393 |
} else { |
|
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
394 |
x = vp->width - (_cursor.pos.x - vp->left); |
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
395 |
y = vp->height - (_cursor.pos.y - vp->top); |
0 | 396 |
} |
981
25c7b445dcb8
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
397 |
/* Get the tile below the cursor and center on the zoomed-out center */ |
25c7b445dcb8
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
398 |
return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, x + vp->left, y + vp->top); |
0 | 399 |
} |
400 |
||
5045
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
401 |
/** Update the status of the zoom-buttons according to the zoom-level |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
402 |
* of the viewport. This will update their status and invalidate accordingly |
6307 | 403 |
* @param w Window pointer to the window that has the zoom buttons |
5045
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
404 |
* @param vp pointer to the viewport whose zoom-level the buttons represent |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
405 |
* @param widget_zoom_in widget index for window with zoom-in button |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
406 |
* @param widget_zoom_out widget index for window with zoom-out button */ |
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
407 |
void HandleZoomMessage(BaseWindow *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out) |
5045
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
408 |
{ |
6246
2a4c2c4d66f0
(svn r8713) [cpp_gui] -Codechange: SetWindowWidgetDisabledState turned into Window method
KUDr
parents:
6245
diff
changeset
|
409 |
w->SetWidgetDisabledState(widget_zoom_in, vp->zoom == 0); |
6237
bce32e54c993
(svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents:
6235
diff
changeset
|
410 |
w->InvalidateWidget(widget_zoom_in); |
5045
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
411 |
|
6246
2a4c2c4d66f0
(svn r8713) [cpp_gui] -Codechange: SetWindowWidgetDisabledState turned into Window method
KUDr
parents:
6245
diff
changeset
|
412 |
w->SetWidgetDisabledState(widget_zoom_out, vp->zoom == 2); |
6237
bce32e54c993
(svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents:
6235
diff
changeset
|
413 |
w->InvalidateWidget(widget_zoom_out); |
5045
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
414 |
} |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
415 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
416 |
void DrawGroundSpriteAt(SpriteID image, SpriteID pal, int32 x, int32 y, byte z) |
0 | 417 |
{ |
418 |
ViewportDrawer *vd = _cur_vd; |
|
419 |
TileSpriteToDraw *ts; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
420 |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
421 |
assert((image & SPRITE_MASK) < MAX_SPRITES); |
0 | 422 |
|
2116 | 423 |
if (vd->spritelist_mem >= vd->eof_spritelist_mem) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5137
diff
changeset
|
424 |
DEBUG(sprite, 0, "Out of sprite memory"); |
0 | 425 |
return; |
426 |
} |
|
2116 | 427 |
ts = (TileSpriteToDraw*)vd->spritelist_mem; |
0 | 428 |
|
429 |
vd->spritelist_mem += sizeof(TileSpriteToDraw); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
430 |
|
0 | 431 |
ts->image = image; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
432 |
ts->pal = pal; |
0 | 433 |
ts->next = NULL; |
434 |
ts->x = x; |
|
435 |
ts->y = y; |
|
436 |
ts->z = z; |
|
437 |
*vd->last_tile = ts; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
438 |
vd->last_tile = &ts->next; |
0 | 439 |
} |
440 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
441 |
void DrawGroundSprite(SpriteID image, SpriteID pal) |
0 | 442 |
{ |
443 |
if (_offset_ground_sprites) { |
|
6307 | 444 |
/* offset ground sprite because of foundation? */ |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
445 |
AddChildSpriteScreen(image, pal, _cur_vd->offs_x, _cur_vd->offs_y); |
0 | 446 |
} else { |
1083
2e9d525af38d
(svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents:
1070
diff
changeset
|
447 |
_added_tile_sprite = true; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
448 |
DrawGroundSpriteAt(image, pal, _cur_ti->x, _cur_ti->y, _cur_ti->z); |
0 | 449 |
} |
450 |
} |
|
451 |
||
452 |
||
453 |
void OffsetGroundSprite(int x, int y) |
|
454 |
{ |
|
455 |
_cur_vd->offs_x = x; |
|
456 |
_cur_vd->offs_y = y; |
|
457 |
_offset_ground_sprites = true; |
|
458 |
} |
|
459 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
460 |
static void AddCombinedSprite(SpriteID image, SpriteID pal, int x, int y, byte z) |
0 | 461 |
{ |
2116 | 462 |
const ViewportDrawer *vd = _cur_vd; |
0 | 463 |
Point pt = RemapCoords(x, y, z); |
2319
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
464 |
const Sprite* spr = GetSprite(image & SPRITE_MASK); |
0 | 465 |
|
2319
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
466 |
if (pt.x + spr->x_offs >= vd->dpi.left + vd->dpi.width || |
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
467 |
pt.x + spr->x_offs + spr->width <= vd->dpi.left || |
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
468 |
pt.y + spr->y_offs >= vd->dpi.top + vd->dpi.height || |
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
469 |
pt.y + spr->y_offs + spr->height <= vd->dpi.top) |
0 | 470 |
return; |
471 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
472 |
AddChildSpriteScreen(image, pal, pt.x - vd->parent_list[-1]->left, pt.y - vd->parent_list[-1]->top); |
0 | 473 |
} |
474 |
||
475 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
476 |
void AddSortableSpriteToDraw(SpriteID image, SpriteID pal, int x, int y, int w, int h, byte dz, byte z) |
0 | 477 |
{ |
478 |
ViewportDrawer *vd = _cur_vd; |
|
479 |
ParentSpriteToDraw *ps; |
|
4171 | 480 |
const Sprite *spr; |
0 | 481 |
Point pt; |
482 |
||
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
483 |
assert((image & SPRITE_MASK) < MAX_SPRITES); |
0 | 484 |
|
485 |
if (vd->combine_sprites == 2) { |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
486 |
AddCombinedSprite(image, pal, x, y, z); |
0 | 487 |
return; |
488 |
} |
|
489 |
||
490 |
vd->last_child = NULL; |
|
491 |
||
2116 | 492 |
if (vd->spritelist_mem >= vd->eof_spritelist_mem) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5137
diff
changeset
|
493 |
DEBUG(sprite, 0, "Out of sprite memory"); |
0 | 494 |
return; |
495 |
} |
|
2116 | 496 |
ps = (ParentSpriteToDraw*)vd->spritelist_mem; |
497 |
||
133
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
498 |
if (vd->parent_list >= vd->eof_parent_list) { |
6307 | 499 |
/* This can happen rarely, mostly when you zoom out completely |
500 |
* and have a lot of stuff that moves (and is added to the |
|
501 |
* sort-list, this function). To solve it, increase |
|
502 |
* parent_list somewhere below to a higher number. |
|
503 |
* This can not really hurt you, it just gives some black |
|
504 |
* spots on the screen ;) */ |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5137
diff
changeset
|
505 |
DEBUG(sprite, 0, "Out of sprite memory (parent_list)"); |
133
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
506 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
507 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
508 |
|
4189
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
509 |
pt = RemapCoords(x, y, z); |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
510 |
spr = GetSprite(image & SPRITE_MASK); |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
511 |
if ((ps->left = (pt.x += spr->x_offs)) >= vd->dpi.left + vd->dpi.width || |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
512 |
(ps->right = (pt.x + spr->width )) <= vd->dpi.left || |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
513 |
(ps->top = (pt.y += spr->y_offs)) >= vd->dpi.top + vd->dpi.height || |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
514 |
(ps->bottom = (pt.y + spr->height)) <= vd->dpi.top) { |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
515 |
return; |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
516 |
} |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
517 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
518 |
vd->spritelist_mem += sizeof(ParentSpriteToDraw); |
0 | 519 |
|
520 |
ps->image = image; |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
521 |
ps->pal = pal; |
4186
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
522 |
ps->xmin = x; |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
523 |
ps->xmax = x + w - 1; |
0 | 524 |
|
4186
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
525 |
ps->ymin = y; |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
526 |
ps->ymax = y + h - 1; |
0 | 527 |
|
4186
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
528 |
ps->zmin = z; |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
529 |
ps->zmax = z + dz - 1; |
0 | 530 |
|
531 |
ps->unk16 = 0; |
|
532 |
ps->child = NULL; |
|
533 |
vd->last_child = &ps->child; |
|
534 |
||
535 |
*vd->parent_list++ = ps; |
|
536 |
||
2116 | 537 |
if (vd->combine_sprites == 1) vd->combine_sprites = 2; |
0 | 538 |
} |
539 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
540 |
void StartSpriteCombine() |
0 | 541 |
{ |
542 |
_cur_vd->combine_sprites = 1; |
|
543 |
} |
|
544 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
545 |
void EndSpriteCombine() |
0 | 546 |
{ |
547 |
_cur_vd->combine_sprites = 0; |
|
548 |
} |
|
549 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
550 |
void AddChildSpriteScreen(SpriteID image, SpriteID pal, int x, int y) |
0 | 551 |
{ |
552 |
ViewportDrawer *vd = _cur_vd; |
|
553 |
ChildScreenSpriteToDraw *cs; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
554 |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
555 |
assert((image & SPRITE_MASK) < MAX_SPRITES); |
0 | 556 |
|
2116 | 557 |
if (vd->spritelist_mem >= vd->eof_spritelist_mem) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5137
diff
changeset
|
558 |
DEBUG(sprite, 0, "Out of sprite memory"); |
0 | 559 |
return; |
560 |
} |
|
2116 | 561 |
cs = (ChildScreenSpriteToDraw*)vd->spritelist_mem; |
0 | 562 |
|
2116 | 563 |
if (vd->last_child == NULL) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
564 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
565 |
vd->spritelist_mem += sizeof(ChildScreenSpriteToDraw); |
0 | 566 |
|
567 |
*vd->last_child = cs; |
|
568 |
vd->last_child = &cs->next; |
|
569 |
||
570 |
cs->image = image; |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
571 |
cs->pal = pal; |
0 | 572 |
cs->x = x; |
573 |
cs->y = y; |
|
574 |
cs->next = NULL; |
|
575 |
} |
|
576 |
||
577 |
/* Returns a StringSpriteToDraw */ |
|
5026
c8b7148798ac
(svn r7067) Remove the unused parameter params_3 from AddStringToDraw()
tron
parents:
5025
diff
changeset
|
578 |
void *AddStringToDraw(int x, int y, StringID string, uint32 params_1, uint32 params_2) |
0 | 579 |
{ |
580 |
ViewportDrawer *vd = _cur_vd; |
|
581 |
StringSpriteToDraw *ss; |
|
582 |
||
2116 | 583 |
if (vd->spritelist_mem >= vd->eof_spritelist_mem) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5137
diff
changeset
|
584 |
DEBUG(sprite, 0, "Out of sprite memory"); |
0 | 585 |
return NULL; |
586 |
} |
|
2116 | 587 |
ss = (StringSpriteToDraw*)vd->spritelist_mem; |
0 | 588 |
|
589 |
vd->spritelist_mem += sizeof(StringSpriteToDraw); |
|
590 |
||
591 |
ss->string = string; |
|
592 |
ss->next = NULL; |
|
593 |
ss->x = x; |
|
594 |
ss->y = y; |
|
595 |
ss->params[0] = params_1; |
|
596 |
ss->params[1] = params_2; |
|
597 |
ss->width = 0; |
|
598 |
||
599 |
*vd->last_string = ss; |
|
600 |
vd->last_string = &ss->next; |
|
601 |
||
602 |
return ss; |
|
603 |
} |
|
604 |
||
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3809
diff
changeset
|
605 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
606 |
static void DrawSelectionSprite(SpriteID image, SpriteID pal, const TileInfo *ti) |
0 | 607 |
{ |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
608 |
if (_added_tile_sprite && !(_thd.drawstyle & HT_LINE)) { // draw on real ground |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
609 |
DrawGroundSpriteAt(image, pal, ti->x, ti->y, ti->z + 7); |
1083
2e9d525af38d
(svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents:
1070
diff
changeset
|
610 |
} else { // draw on top of foundation |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
611 |
AddSortableSpriteToDraw(image, pal, ti->x, ti->y, 0x10, 0x10, 1, ti->z + 7); |
1083
2e9d525af38d
(svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents:
1070
diff
changeset
|
612 |
} |
0 | 613 |
} |
614 |
||
615 |
static bool IsPartOfAutoLine(int px, int py) |
|
616 |
{ |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
617 |
px -= _thd.selstart.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
618 |
py -= _thd.selstart.y; |
0 | 619 |
|
2952 | 620 |
switch (_thd.drawstyle) { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
621 |
case HT_LINE | HT_DIR_X: return py == 0; // x direction |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
622 |
case HT_LINE | HT_DIR_Y: return px == 0; // y direction |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
623 |
case HT_LINE | HT_DIR_HU: return px == -py || px == -py - 16; // horizontal upper |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
624 |
case HT_LINE | HT_DIR_HL: return px == -py || px == -py + 16; // horizontal lower |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
625 |
case HT_LINE | HT_DIR_VL: return px == py || px == py + 16; // vertival left |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
626 |
case HT_LINE | HT_DIR_VR: return px == py || px == py - 16; // vertical right |
0 | 627 |
default: |
628 |
NOT_REACHED(); |
|
629 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
630 |
|
0 | 631 |
/* useless, but avoids compiler warning this way */ |
632 |
return 0; |
|
633 |
} |
|
634 |
||
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
635 |
// [direction][side] |
2710
e144188c1fdb
(svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents:
2676
diff
changeset
|
636 |
static const int _AutorailType[6][2] = { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
637 |
{ HT_DIR_X, HT_DIR_X }, |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
638 |
{ HT_DIR_Y, HT_DIR_Y }, |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
639 |
{ HT_DIR_HU, HT_DIR_HL }, |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
640 |
{ HT_DIR_HL, HT_DIR_HU }, |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
641 |
{ HT_DIR_VL, HT_DIR_VR }, |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
642 |
{ HT_DIR_VR, HT_DIR_VL } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
643 |
}; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
644 |
|
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
645 |
#include "table/autorail.h" |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
646 |
|
0 | 647 |
static void DrawTileSelection(const TileInfo *ti) |
648 |
{ |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
649 |
SpriteID image; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
650 |
SpriteID pal; |
0 | 651 |
|
6307 | 652 |
/* Draw a red error square? */ |
3281
0f3d836e35b1
(svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents:
3279
diff
changeset
|
653 |
if (_thd.redsq != 0 && _thd.redsq == ti->tile) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
654 |
DrawSelectionSprite(SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh], PALETTE_TILE_RED_PULSATING, ti); |
0 | 655 |
return; |
656 |
} |
|
657 |
||
6307 | 658 |
/* no selection active? */ |
2116 | 659 |
if (_thd.drawstyle == 0) return; |
0 | 660 |
|
6307 | 661 |
/* Inside the inner area? */ |
2116 | 662 |
if (IS_INSIDE_1D(ti->x, _thd.pos.x, _thd.size.x) && |
663 |
IS_INSIDE_1D(ti->y, _thd.pos.y, _thd.size.y)) { |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
664 |
if (_thd.drawstyle & HT_RECT) { |
1864
83c91b158180
(svn r2370) Replace some magic numbers with symbolic names
tron
parents:
1863
diff
changeset
|
665 |
image = SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh]; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
666 |
DrawSelectionSprite(image, _thd.make_square_red ? PALETTE_SEL_TILE_RED : PAL_NONE, ti); |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
667 |
} else if (_thd.drawstyle & HT_POINT) { |
6307 | 668 |
/* Figure out the Z coordinate for the single dot. */ |
0 | 669 |
byte z = ti->z; |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3609
diff
changeset
|
670 |
if (ti->tileh & SLOPE_N) { |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
671 |
z += TILE_HEIGHT; |
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
672 |
if (ti->tileh == SLOPE_STEEP_N) z += TILE_HEIGHT; |
0 | 673 |
} |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
674 |
DrawGroundSpriteAt(_cur_dpi->zoom != 2 ? SPR_DOT : SPR_DOT_SMALL, PAL_NONE, ti->x, ti->y, z); |
2116 | 675 |
} else if (_thd.drawstyle & HT_RAIL /*&& _thd.place_mode == VHM_RAIL*/) { |
6307 | 676 |
/* autorail highlight piece under cursor */ |
2116 | 677 |
uint type = _thd.drawstyle & 0xF; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
678 |
int offset; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
679 |
|
2116 | 680 |
assert(type <= 5); |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
681 |
|
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
682 |
offset = _AutorailTilehSprite[ti->tileh][_AutorailType[type][0]]; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
683 |
if (offset >= 0) { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
684 |
image = SPR_AUTORAIL_BASE + offset; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
685 |
pal = PAL_NONE; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
686 |
} else { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
687 |
image = SPR_AUTORAIL_BASE - offset; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
688 |
pal = PALETTE_TO_RED; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
689 |
} |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
690 |
|
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
691 |
DrawSelectionSprite(image, _thd.make_square_red ? PALETTE_SEL_TILE_RED : pal, ti); |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
692 |
|
2116 | 693 |
} else if (IsPartOfAutoLine(ti->x, ti->y)) { |
6307 | 694 |
/* autorail highlighting long line */ |
2116 | 695 |
int dir = _thd.drawstyle & ~0xF0; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
696 |
int offset; |
2116 | 697 |
uint side; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
698 |
|
2116 | 699 |
if (dir < 2) { |
700 |
side = 0; |
|
701 |
} else { |
|
702 |
TileIndex start = TileVirtXY(_thd.selstart.x, _thd.selstart.y); |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
703 |
side = delta(delta(TileX(start), TileX(ti->tile)), delta(TileY(start), TileY(ti->tile))); |
2116 | 704 |
} |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
705 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
706 |
offset = _AutorailTilehSprite[ti->tileh][_AutorailType[dir][side]]; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
707 |
if (offset >= 0) { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
708 |
image = SPR_AUTORAIL_BASE + offset; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
709 |
pal = PAL_NONE; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
710 |
} else { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
711 |
image = SPR_AUTORAIL_BASE - offset; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
712 |
pal = PALETTE_TO_RED; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
713 |
} |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
714 |
|
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
715 |
DrawSelectionSprite(image, _thd.make_square_red ? PALETTE_SEL_TILE_RED : pal, ti); |
2116 | 716 |
} |
0 | 717 |
return; |
718 |
} |
|
719 |
||
6307 | 720 |
/* Check if it's inside the outer area? */ |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
721 |
if (_thd.outersize.x && |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
722 |
_thd.size.x < _thd.size.x + _thd.outersize.x && |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
723 |
IS_INSIDE_1D(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) && |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
724 |
IS_INSIDE_1D(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) { |
6307 | 725 |
/* Draw a blue rect. */ |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
726 |
DrawSelectionSprite(SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh], PALETTE_SEL_TILE_BLUE, ti); |
0 | 727 |
return; |
728 |
} |
|
729 |
} |
|
730 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
731 |
static void ViewportAddLandscape() |
0 | 732 |
{ |
733 |
ViewportDrawer *vd = _cur_vd; |
|
734 |
int x, y, width, height; |
|
735 |
TileInfo ti; |
|
736 |
bool direction; |
|
737 |
||
738 |
_cur_ti = &ti; |
|
739 |
||
6307 | 740 |
/* Transform into tile coordinates and round to closest full tile */ |
0 | 741 |
x = ((vd->dpi.top >> 1) - (vd->dpi.left >> 2)) & ~0xF; |
742 |
y = ((vd->dpi.top >> 1) + (vd->dpi.left >> 2) - 0x10) & ~0xF; |
|
5752
7e417aab8074
(svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents:
5726
diff
changeset
|
743 |
|
6307 | 744 |
/* determine size of area */ |
0 | 745 |
{ |
746 |
Point pt = RemapCoords(x, y, 241); |
|
747 |
width = (vd->dpi.left + vd->dpi.width - pt.x + 95) >> 6; |
|
748 |
height = (vd->dpi.top + vd->dpi.height - pt.y) >> 5 << 1; |
|
749 |
} |
|
750 |
||
751 |
assert(width > 0); |
|
752 |
assert(height > 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
753 |
|
0 | 754 |
direction = false; |
755 |
||
756 |
do { |
|
757 |
int width_cur = width; |
|
758 |
int x_cur = x; |
|
759 |
int y_cur = y; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
760 |
|
0 | 761 |
do { |
4238
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
762 |
TileType tt; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
763 |
|
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
764 |
ti.x = x_cur; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
765 |
ti.y = y_cur; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
766 |
if (0 <= x_cur && x_cur < (int)MapMaxX() * TILE_SIZE && |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
767 |
0 <= y_cur && y_cur < (int)MapMaxY() * TILE_SIZE) { |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
768 |
TileIndex tile = TileVirtXY(x_cur, y_cur); |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
769 |
|
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
770 |
ti.tile = tile; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
771 |
ti.tileh = GetTileSlope(tile, &ti.z); |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
772 |
tt = GetTileType(tile); |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
773 |
} else { |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
774 |
ti.tileh = SLOPE_FLAT; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
775 |
ti.tile = 0; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
776 |
ti.z = 0; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
777 |
tt = MP_VOID; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
778 |
} |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
779 |
|
0 | 780 |
y_cur += 0x10; |
781 |
x_cur -= 0x10; |
|
5752
7e417aab8074
(svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents:
5726
diff
changeset
|
782 |
|
0 | 783 |
_added_tile_sprite = false; |
784 |
_offset_ground_sprites = false; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
785 |
|
4238
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
786 |
_tile_type_procs[tt]->draw_tile_proc(&ti); |
0 | 787 |
DrawTileSelection(&ti); |
788 |
} while (--width_cur); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
789 |
|
5752
7e417aab8074
(svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents:
5726
diff
changeset
|
790 |
if ((direction ^= 1) != 0) { |
0 | 791 |
y += 0x10; |
5752
7e417aab8074
(svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents:
5726
diff
changeset
|
792 |
} else { |
0 | 793 |
x += 0x10; |
5752
7e417aab8074
(svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents:
5726
diff
changeset
|
794 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
795 |
} while (--height); |
0 | 796 |
} |
797 |
||
798 |
||
410 | 799 |
static void ViewportAddTownNames(DrawPixelInfo *dpi) |
0 | 800 |
{ |
801 |
Town *t; |
|
802 |
int left, top, right, bottom; |
|
803 |
||
804 |
if (!(_display_opt & DO_SHOW_TOWN_NAMES) || _game_mode == GM_MENU) |
|
805 |
return; |
|
806 |
||
807 |
left = dpi->left; |
|
808 |
top = dpi->top; |
|
809 |
right = left + dpi->width; |
|
810 |
bottom = top + dpi->height; |
|
811 |
||
5027 | 812 |
switch (dpi->zoom) { |
813 |
case 0: |
|
814 |
FOR_ALL_TOWNS(t) { |
|
815 |
if (bottom > t->sign.top && |
|
816 |
top < t->sign.top + 12 && |
|
817 |
right > t->sign.left && |
|
818 |
left < t->sign.left + t->sign.width_1) { |
|
819 |
AddStringToDraw(t->sign.left + 1, t->sign.top + 1, |
|
820 |
_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL, |
|
821 |
t->index, t->population); |
|
822 |
} |
|
0 | 823 |
} |
5027 | 824 |
break; |
825 |
||
826 |
case 1: |
|
827 |
right += 2; |
|
828 |
bottom += 2; |
|
829 |
||
830 |
FOR_ALL_TOWNS(t) { |
|
831 |
if (bottom > t->sign.top && |
|
832 |
top < t->sign.top + 24 && |
|
833 |
right > t->sign.left && |
|
834 |
left < t->sign.left + t->sign.width_1*2) { |
|
835 |
AddStringToDraw(t->sign.left + 1, t->sign.top + 1, |
|
836 |
_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL, |
|
837 |
t->index, t->population); |
|
838 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
839 |
} |
5027 | 840 |
break; |
841 |
||
842 |
default: NOT_REACHED(); |
|
843 |
case 2: |
|
844 |
right += 4; |
|
845 |
bottom += 5; |
|
846 |
||
847 |
FOR_ALL_TOWNS(t) { |
|
848 |
if (bottom > t->sign.top && |
|
849 |
top < t->sign.top + 24 && |
|
850 |
right > t->sign.left && |
|
851 |
left < t->sign.left + t->sign.width_2*4) { |
|
852 |
AddStringToDraw(t->sign.left + 5, t->sign.top + 1, STR_TOWN_LABEL_TINY_BLACK, t->index, 0); |
|
853 |
AddStringToDraw(t->sign.left + 1, t->sign.top - 3, STR_TOWN_LABEL_TINY_WHITE, t->index, 0); |
|
854 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
855 |
} |
5027 | 856 |
break; |
0 | 857 |
} |
858 |
} |
|
859 |
||
5025 | 860 |
|
861 |
static void AddStation(const Station *st, StringID str, uint16 width) |
|
862 |
{ |
|
863 |
StringSpriteToDraw *sstd; |
|
864 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
865 |
sstd = (StringSpriteToDraw*)AddStringToDraw(st->sign.left + 1, st->sign.top + 1, str, st->index, st->facilities); |
5025 | 866 |
if (sstd != NULL) { |
867 |
sstd->color = (st->owner == OWNER_NONE || st->facilities == 0) ? 0xE : _player_colors[st->owner]; |
|
868 |
sstd->width = width; |
|
869 |
} |
|
870 |
} |
|
871 |
||
872 |
||
410 | 873 |
static void ViewportAddStationNames(DrawPixelInfo *dpi) |
0 | 874 |
{ |
875 |
int left, top, right, bottom; |
|
5025 | 876 |
const Station *st; |
0 | 877 |
|
878 |
if (!(_display_opt & DO_SHOW_STATION_NAMES) || _game_mode == GM_MENU) |
|
879 |
return; |
|
880 |
||
881 |
left = dpi->left; |
|
882 |
top = dpi->top; |
|
883 |
right = left + dpi->width; |
|
884 |
bottom = top + dpi->height; |
|
885 |
||
5027 | 886 |
switch (dpi->zoom) { |
887 |
case 0: |
|
888 |
FOR_ALL_STATIONS(st) { |
|
889 |
if (bottom > st->sign.top && |
|
890 |
top < st->sign.top + 12 && |
|
891 |
right > st->sign.left && |
|
892 |
left < st->sign.left + st->sign.width_1) { |
|
893 |
AddStation(st, STR_305C_0, st->sign.width_1); |
|
894 |
} |
|
0 | 895 |
} |
5027 | 896 |
break; |
897 |
||
898 |
case 1: |
|
899 |
right += 2; |
|
900 |
bottom += 2; |
|
901 |
FOR_ALL_STATIONS(st) { |
|
902 |
if (bottom > st->sign.top && |
|
903 |
top < st->sign.top + 24 && |
|
904 |
right > st->sign.left && |
|
905 |
left < st->sign.left + st->sign.width_1*2) { |
|
906 |
AddStation(st, STR_305C_0, st->sign.width_1); |
|
907 |
} |
|
0 | 908 |
} |
5027 | 909 |
break; |
910 |
||
911 |
default: NOT_REACHED(); |
|
912 |
case 2: |
|
913 |
right += 4; |
|
914 |
bottom += 5; |
|
915 |
FOR_ALL_STATIONS(st) { |
|
916 |
if (bottom > st->sign.top && |
|
917 |
top < st->sign.top + 24 && |
|
918 |
right > st->sign.left && |
|
919 |
left < st->sign.left + st->sign.width_2*4) { |
|
920 |
AddStation(st, STR_STATION_SIGN_TINY, st->sign.width_2 | 0x8000); |
|
921 |
} |
|
0 | 922 |
} |
5027 | 923 |
break; |
0 | 924 |
} |
925 |
} |
|
926 |
||
5025 | 927 |
|
928 |
static void AddSign(const Sign *si, StringID str, uint16 width) |
|
929 |
{ |
|
930 |
StringSpriteToDraw *sstd; |
|
931 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
932 |
sstd = (StringSpriteToDraw*)AddStringToDraw(si->sign.left + 1, si->sign.top + 1, str, si->str, 0); |
5025 | 933 |
if (sstd != NULL) { |
934 |
sstd->color = (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner]; |
|
935 |
sstd->width = width; |
|
936 |
} |
|
937 |
} |
|
938 |
||
939 |
||
410 | 940 |
static void ViewportAddSigns(DrawPixelInfo *dpi) |
0 | 941 |
{ |
5025 | 942 |
const Sign *si; |
0 | 943 |
int left, top, right, bottom; |
944 |
||
945 |
if (!(_display_opt & DO_SHOW_SIGNS)) |
|
946 |
return; |
|
947 |
||
948 |
left = dpi->left; |
|
949 |
top = dpi->top; |
|
950 |
right = left + dpi->width; |
|
951 |
bottom = top + dpi->height; |
|
952 |
||
5027 | 953 |
switch (dpi->zoom) { |
954 |
case 0: |
|
955 |
FOR_ALL_SIGNS(si) { |
|
956 |
if (bottom > si->sign.top && |
|
957 |
top < si->sign.top + 12 && |
|
958 |
right > si->sign.left && |
|
959 |
left < si->sign.left + si->sign.width_1) { |
|
960 |
AddSign(si, STR_2806, si->sign.width_1); |
|
961 |
} |
|
0 | 962 |
} |
5027 | 963 |
break; |
964 |
||
965 |
case 1: |
|
966 |
right += 2; |
|
967 |
bottom += 2; |
|
968 |
FOR_ALL_SIGNS(si) { |
|
969 |
if (bottom > si->sign.top && |
|
970 |
top < si->sign.top + 24 && |
|
971 |
right > si->sign.left && |
|
972 |
left < si->sign.left + si->sign.width_1 * 2) { |
|
973 |
AddSign(si, STR_2806, si->sign.width_1); |
|
974 |
} |
|
0 | 975 |
} |
5027 | 976 |
break; |
977 |
||
978 |
default: NOT_REACHED(); |
|
979 |
case 2: |
|
980 |
right += 4; |
|
981 |
bottom += 5; |
|
982 |
FOR_ALL_SIGNS(si) { |
|
983 |
if (bottom > si->sign.top && |
|
984 |
top < si->sign.top + 24 && |
|
985 |
right > si->sign.left && |
|
986 |
left < si->sign.left + si->sign.width_2 * 4) { |
|
987 |
AddSign(si, STR_2002, si->sign.width_2 | 0x8000); |
|
988 |
} |
|
0 | 989 |
} |
5027 | 990 |
break; |
0 | 991 |
} |
992 |
} |
|
993 |
||
5025 | 994 |
|
995 |
static void AddWaypoint(const Waypoint *wp, StringID str, uint16 width) |
|
996 |
{ |
|
997 |
StringSpriteToDraw *sstd; |
|
998 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
999 |
sstd = (StringSpriteToDraw*)AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, str, wp->index, 0); |
5025 | 1000 |
if (sstd != NULL) { |
1001 |
sstd->color = (wp->deleted ? 0xE : 11); |
|
1002 |
sstd->width = width; |
|
1003 |
} |
|
1004 |
} |
|
1005 |
||
1006 |
||
410 | 1007 |
static void ViewportAddWaypoints(DrawPixelInfo *dpi) |
0 | 1008 |
{ |
5025 | 1009 |
const Waypoint *wp; |
0 | 1010 |
int left, top, right, bottom; |
1011 |
||
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
193
diff
changeset
|
1012 |
if (!(_display_opt & DO_WAYPOINTS)) |
0 | 1013 |
return; |
1014 |
||
1015 |
left = dpi->left; |
|
1016 |
top = dpi->top; |
|
1017 |
right = left + dpi->width; |
|
1018 |
bottom = top + dpi->height; |
|
1019 |
||
5027 | 1020 |
switch (dpi->zoom) { |
1021 |
case 0: |
|
1022 |
FOR_ALL_WAYPOINTS(wp) { |
|
1023 |
if (bottom > wp->sign.top && |
|
1024 |
top < wp->sign.top + 12 && |
|
1025 |
right > wp->sign.left && |
|
1026 |
left < wp->sign.left + wp->sign.width_1) { |
|
1027 |
AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1); |
|
1028 |
} |
|
0 | 1029 |
} |
5027 | 1030 |
break; |
1031 |
||
1032 |
case 1: |
|
1033 |
right += 2; |
|
1034 |
bottom += 2; |
|
1035 |
FOR_ALL_WAYPOINTS(wp) { |
|
1036 |
if (bottom > wp->sign.top && |
|
1037 |
top < wp->sign.top + 24 && |
|
1038 |
right > wp->sign.left && |
|
1039 |
left < wp->sign.left + wp->sign.width_1*2) { |
|
1040 |
AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1); |
|
1041 |
} |
|
0 | 1042 |
} |
5027 | 1043 |
break; |
1044 |
||
1045 |
default: NOT_REACHED(); |
|
1046 |
case 2: |
|
1047 |
right += 4; |
|
1048 |
bottom += 5; |
|
1049 |
FOR_ALL_WAYPOINTS(wp) { |
|
1050 |
if (bottom > wp->sign.top && |
|
1051 |
top < wp->sign.top + 24 && |
|
1052 |
right > wp->sign.left && |
|
1053 |
left < wp->sign.left + wp->sign.width_2*4) { |
|
1054 |
AddWaypoint(wp, STR_WAYPOINT_VIEWPORT_TINY, wp->sign.width_2 | 0x8000); |
|
1055 |
} |
|
0 | 1056 |
} |
5027 | 1057 |
break; |
0 | 1058 |
} |
1059 |
} |
|
1060 |
||
1061 |
void UpdateViewportSignPos(ViewportSign *sign, int left, int top, StringID str) |
|
1062 |
{ |
|
1063 |
char buffer[128]; |
|
2116 | 1064 |
uint w; |
0 | 1065 |
|
1066 |
sign->top = top; |
|
1067 |
||
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4885
diff
changeset
|
1068 |
GetString(buffer, str, lastof(buffer)); |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4539
diff
changeset
|
1069 |
w = GetStringBoundingBox(buffer).width + 3; |
0 | 1070 |
sign->width_1 = w; |
2116 | 1071 |
sign->left = left - w / 2; |
0 | 1072 |
|
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4539
diff
changeset
|
1073 |
/* zoomed out version */ |
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:
3645
diff
changeset
|
1074 |
_cur_fontsize = FS_SMALL; |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4539
diff
changeset
|
1075 |
w = GetStringBoundingBox(buffer).width + 3; |
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:
3645
diff
changeset
|
1076 |
_cur_fontsize = FS_NORMAL; |
1390
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1363
diff
changeset
|
1077 |
sign->width_2 = w; |
0 | 1078 |
} |
1079 |
||
1080 |
||
410 | 1081 |
static void ViewportDrawTileSprites(TileSpriteToDraw *ts) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1082 |
{ |
0 | 1083 |
do { |
1084 |
Point pt = RemapCoords(ts->x, ts->y, ts->z); |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
1085 |
DrawSprite(ts->image, ts->pal, pt.x, pt.y); |
2116 | 1086 |
ts = ts->next; |
1087 |
} while (ts != NULL); |
|
0 | 1088 |
} |
1089 |
||
4171 | 1090 |
static void ViewportSortParentSprites(ParentSpriteToDraw *psd[]) |
0 | 1091 |
{ |
2116 | 1092 |
while (*psd != NULL) { |
1093 |
ParentSpriteToDraw* ps = *psd; |
|
0 | 1094 |
|
1095 |
if (!(ps->unk16 & 1)) { |
|
2116 | 1096 |
ParentSpriteToDraw** psd2 = psd; |
1097 |
||
0 | 1098 |
ps->unk16 |= 1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1099 |
|
2116 | 1100 |
while (*++psd2 != NULL) { |
1101 |
ParentSpriteToDraw* ps2 = *psd2; |
|
4188 | 1102 |
ParentSpriteToDraw** psd3; |
1934
b3d568113d4d
(svn r2440) - Fix: [newgrf] Fix the spritesorter to handle overlapping sprites properly, this fixes display problems with really short wagons. (algorithm by patchman, ported by therax)
hackykid
parents:
1932
diff
changeset
|
1103 |
|
2116 | 1104 |
if (ps2->unk16 & 1) continue; |
0 | 1105 |
|
4187
50b94420d9a2
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1106 |
/* Decide which comparator to use, based on whether the bounding |
50b94420d9a2
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1107 |
* boxes overlap |
50b94420d9a2
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1108 |
*/ |
50b94420d9a2
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1109 |
if (ps->xmax > ps2->xmin && ps->xmin < ps2->xmax && // overlap in X? |
50b94420d9a2
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1110 |
ps->ymax > ps2->ymin && ps->ymin < ps2->ymax && // overlap in Y? |
50b94420d9a2
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1111 |
ps->zmax > ps2->zmin && ps->zmin < ps2->zmax) { // overlap in Z? |
4188 | 1112 |
/* Use X+Y+Z as the sorting order, so sprites closer to the bottom of |
1113 |
* the screen and with higher Z elevation, are drawn in front. |
|
1114 |
* Here X,Y,Z are the coordinates of the "center of mass" of the sprite, |
|
1115 |
* i.e. X=(left+right)/2, etc. |
|
1116 |
* However, since we only care about order, don't actually divide / 2 |
|
1117 |
*/ |
|
1118 |
if (ps->xmin + ps->xmax + ps->ymin + ps->ymax + ps->zmin + ps->zmax <= |
|
1119 |
ps2->xmin + ps2->xmax + ps2->ymin + ps2->ymax + ps2->zmin + ps2->zmax) { |
|
1120 |
continue; |
|
1121 |
} |
|
1934
b3d568113d4d
(svn r2440) - Fix: [newgrf] Fix the spritesorter to handle overlapping sprites properly, this fixes display problems with really short wagons. (algorithm by patchman, ported by therax)
hackykid
parents:
1932
diff
changeset
|
1122 |
} else { |
4188 | 1123 |
if (ps->xmax < ps2->xmin || |
1124 |
ps->ymax < ps2->ymin || |
|
1125 |
ps->zmax < ps2->zmin || ( |
|
1126 |
ps->xmin < ps2->xmax && |
|
1127 |
ps->ymin < ps2->ymax && |
|
1128 |
ps->zmin < ps2->zmax |
|
1129 |
)) { |
|
1130 |
continue; |
|
1131 |
} |
|
1934
b3d568113d4d
(svn r2440) - Fix: [newgrf] Fix the spritesorter to handle overlapping sprites properly, this fixes display problems with really short wagons. (algorithm by patchman, ported by therax)
hackykid
parents:
1932
diff
changeset
|
1132 |
} |
2116 | 1133 |
|
6307 | 1134 |
/* Swap the two sprites ps and ps2 using bubble-sort algorithm. */ |
4188 | 1135 |
psd3 = psd; |
1136 |
do { |
|
1137 |
ParentSpriteToDraw* temp = *psd3; |
|
1138 |
*psd3 = ps2; |
|
1139 |
ps2 = temp; |
|
0 | 1140 |
|
4188 | 1141 |
psd3++; |
1142 |
} while (psd3 <= psd2); |
|
0 | 1143 |
} |
1144 |
} else { |
|
1145 |
psd++; |
|
1146 |
} |
|
1147 |
} |
|
1148 |
} |
|
1149 |
||
2116 | 1150 |
static void ViewportDrawParentSprites(ParentSpriteToDraw *psd[]) |
0 | 1151 |
{ |
2116 | 1152 |
for (; *psd != NULL; psd++) { |
1153 |
const ParentSpriteToDraw* ps = *psd; |
|
4186
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
1154 |
Point pt = RemapCoords(ps->xmin, ps->ymin, ps->zmin); |
2116 | 1155 |
const ChildScreenSpriteToDraw* cs; |
0 | 1156 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
1157 |
DrawSprite(ps->image, ps->pal, pt.x, pt.y); |
0 | 1158 |
|
2116 | 1159 |
for (cs = ps->child; cs != NULL; cs = cs->next) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
1160 |
DrawSprite(cs->image, cs->pal, ps->left + cs->x, ps->top + cs->y); |
0 | 1161 |
} |
1162 |
} |
|
1163 |
} |
|
1164 |
||
2116 | 1165 |
static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDraw *ss) |
0 | 1166 |
{ |
1167 |
DrawPixelInfo dp; |
|
1168 |
byte zoom; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1169 |
|
0 | 1170 |
_cur_dpi = &dp; |
1171 |
dp = *dpi; |
|
1172 |
||
2116 | 1173 |
zoom = dp.zoom; |
0 | 1174 |
dp.zoom = 0; |
1175 |
||
1176 |
dp.left >>= zoom; |
|
1177 |
dp.top >>= zoom; |
|
1178 |
dp.width >>= zoom; |
|
1179 |
dp.height >>= zoom; |
|
1180 |
||
1181 |
do { |
|
5025 | 1182 |
uint16 colour; |
1183 |
||
0 | 1184 |
if (ss->width != 0) { |
2116 | 1185 |
int x = (ss->x >> zoom) - 1; |
1186 |
int y = (ss->y >> zoom) - 1; |
|
1187 |
int bottom = y + 11; |
|
1188 |
int w = ss->width; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1189 |
|
0 | 1190 |
if (w & 0x8000) { |
1191 |
w &= ~0x8000; |
|
1192 |
y--; |
|
1193 |
bottom -= 6; |
|
1194 |
w -= 3; |
|
1195 |
} |
|
1196 |
||
2116 | 1197 |
/* Draw the rectangle if 'tranparent station signs' is off, |
1198 |
* or if we are drawing a general text sign (STR_2806) */ |
|
6307 | 1199 |
if (!HASBIT(_transparent_opt, TO_SIGNS) || ss->string == STR_2806) { |
2116 | 1200 |
DrawFrameRect( |
1201 |
x, y, x + w, bottom, ss->color, |
|
6307 | 1202 |
HASBIT(_transparent_opt, TO_SIGNS) ? FR_TRANSPARENT : FR_NONE |
2116 | 1203 |
); |
6307 | 1204 |
} |
0 | 1205 |
} |
1206 |
||
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1207 |
SetDParam(0, ss->params[0]); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1208 |
SetDParam(1, ss->params[1]); |
2116 | 1209 |
/* if we didn't draw a rectangle, or if transparant building is on, |
1210 |
* draw the text in the color the rectangle would have */ |
|
6307 | 1211 |
if (HASBIT(_transparent_opt, TO_SIGNS) && ss->string != STR_2806 && ss->width != 0) { |
2116 | 1212 |
/* Real colors need the IS_PALETTE_COLOR flag |
1213 |
* otherwise colors from _string_colormap are assumed. */ |
|
5025 | 1214 |
colour = _colour_gradient[ss->color][6] | IS_PALETTE_COLOR; |
0 | 1215 |
} else { |
5025 | 1216 |
colour = 16; |
0 | 1217 |
} |
5025 | 1218 |
DrawString( |
1219 |
ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0), |
|
1220 |
ss->string, colour |
|
1221 |
); |
|
2116 | 1222 |
|
1223 |
ss = ss->next; |
|
1224 |
} while (ss != NULL); |
|
0 | 1225 |
} |
1226 |
||
430 | 1227 |
void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom) |
0 | 1228 |
{ |
1229 |
ViewportDrawer vd; |
|
1230 |
int mask; |
|
2116 | 1231 |
int x; |
1232 |
int y; |
|
0 | 1233 |
DrawPixelInfo *old_dpi; |
1234 |
||
1235 |
byte mem[VIEWPORT_DRAW_MEM]; |
|
137
73f897e1bf4a
(svn r138) -Add: 64x64 stations are now nicely painted (increased size of
truelight
parents:
133
diff
changeset
|
1236 |
ParentSpriteToDraw *parent_list[6144]; |
0 | 1237 |
|
1238 |
_cur_vd = &vd; |
|
1239 |
||
1240 |
old_dpi = _cur_dpi; |
|
1241 |
_cur_dpi = &vd.dpi; |
|
1242 |
||
1243 |
vd.dpi.zoom = vp->zoom; |
|
1244 |
mask = (-1) << vp->zoom; |
|
1245 |
||
1246 |
vd.combine_sprites = 0; |
|
1247 |
||
1248 |
vd.dpi.width = (right - left) & mask; |
|
1249 |
vd.dpi.height = (bottom - top) & mask; |
|
1250 |
vd.dpi.left = left & mask; |
|
1251 |
vd.dpi.top = top & mask; |
|
1252 |
vd.dpi.pitch = old_dpi->pitch; |
|
1253 |
||
1254 |
x = ((vd.dpi.left - (vp->virtual_left&mask)) >> vp->zoom) + vp->left; |
|
1255 |
y = ((vd.dpi.top - (vp->virtual_top&mask)) >> vp->zoom) + vp->top; |
|
1256 |
||
1257 |
vd.dpi.dst_ptr = old_dpi->dst_ptr + x - old_dpi->left + (y - old_dpi->top) * old_dpi->pitch; |
|
1258 |
||
1259 |
vd.parent_list = parent_list; |
|
2116 | 1260 |
vd.eof_parent_list = endof(parent_list); |
0 | 1261 |
vd.spritelist_mem = mem; |
2116 | 1262 |
vd.eof_spritelist_mem = endof(mem) - sizeof(LARGEST_SPRITELIST_STRUCT); |
0 | 1263 |
vd.last_string = &vd.first_string; |
1264 |
vd.first_string = NULL; |
|
1265 |
vd.last_tile = &vd.first_tile; |
|
1266 |
vd.first_tile = NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1267 |
|
0 | 1268 |
ViewportAddLandscape(); |
1269 |
ViewportAddVehicles(&vd.dpi); |
|
1270 |
DrawTextEffects(&vd.dpi); |
|
1271 |
||
1272 |
ViewportAddTownNames(&vd.dpi); |
|
1273 |
ViewportAddStationNames(&vd.dpi); |
|
1274 |
ViewportAddSigns(&vd.dpi); |
|
395
4c990f33dab7
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
193
diff
changeset
|
1275 |
ViewportAddWaypoints(&vd.dpi); |
0 | 1276 |
|
6307 | 1277 |
/* This assert should never happen (because the length of the parent_list |
1278 |
* is checked) */ |
|
979
f12f96116cdd
(svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
1279 |
assert(vd.parent_list <= endof(parent_list)); |
133
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
1280 |
|
2116 | 1281 |
if (vd.first_tile != NULL) ViewportDrawTileSprites(vd.first_tile); |
0 | 1282 |
|
1283 |
/* null terminate parent sprite list */ |
|
1284 |
*vd.parent_list = NULL; |
|
1285 |
||
1286 |
ViewportSortParentSprites(parent_list); |
|
1287 |
ViewportDrawParentSprites(parent_list); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1288 |
|
2116 | 1289 |
if (vd.first_string != NULL) ViewportDrawStrings(&vd.dpi, vd.first_string); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1290 |
|
0 | 1291 |
_cur_dpi = old_dpi; |
1292 |
} |
|
1293 |
||
6307 | 1294 |
/** Make sure we don't draw a too big area at a time. |
1295 |
* If we do, the sprite memory will overflow. */ |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5045
diff
changeset
|
1296 |
static void ViewportDrawChk(const ViewPort *vp, int left, int top, int right, int bottom) |
0 | 1297 |
{ |
5924
077448ca4bf2
(svn r8133) -Fix [FS#535]: "out of sprite memory" warning messages due to incorrect assumption of requested memory for sprites (smatz)
Darkvater
parents:
5919
diff
changeset
|
1298 |
if (((bottom - top) * (right - left) << (2 * vp->zoom)) > 180000) { |
0 | 1299 |
if ((bottom - top) > (right - left)) { |
1300 |
int t = (top + bottom) >> 1; |
|
1301 |
ViewportDrawChk(vp, left, top, right, t); |
|
1302 |
ViewportDrawChk(vp, left, t, right, bottom); |
|
1303 |
} else { |
|
1304 |
int t = (left + right) >> 1; |
|
1305 |
ViewportDrawChk(vp, left, top, t, bottom); |
|
1306 |
ViewportDrawChk(vp, t, top, right, bottom); |
|
1307 |
} |
|
1308 |
} else { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1309 |
ViewportDoDraw(vp, |
0 | 1310 |
((left - vp->left) << vp->zoom) + vp->virtual_left, |
1311 |
((top - vp->top) << vp->zoom) + vp->virtual_top, |
|
1312 |
((right - vp->left) << vp->zoom) + vp->virtual_left, |
|
1313 |
((bottom - vp->top) << vp->zoom) + vp->virtual_top |
|
1314 |
); |
|
1315 |
} |
|
1316 |
} |
|
1317 |
||
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5045
diff
changeset
|
1318 |
static inline void ViewportDraw(const ViewPort *vp, int left, int top, int right, int bottom) |
0 | 1319 |
{ |
2116 | 1320 |
if (right <= vp->left || bottom <= vp->top) return; |
0 | 1321 |
|
2116 | 1322 |
if (left >= vp->left + vp->width) return; |
0 | 1323 |
|
1324 |
if (left < vp->left) left = vp->left; |
|
2116 | 1325 |
if (right > vp->left + vp->width) right = vp->left + vp->width; |
0 | 1326 |
|
2116 | 1327 |
if (top >= vp->top + vp->height) return; |
0 | 1328 |
|
1329 |
if (top < vp->top) top = vp->top; |
|
2116 | 1330 |
if (bottom > vp->top + vp->height) bottom = vp->top + vp->height; |
0 | 1331 |
|
1332 |
ViewportDrawChk(vp, left, top, right, bottom); |
|
1333 |
} |
|
1334 |
||
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
1335 |
void BaseWindow::DrawViewport() const |
2116 | 1336 |
{ |
0 | 1337 |
DrawPixelInfo *dpi = _cur_dpi; |
1338 |
||
6263
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
1339 |
dpi->left += Left(); |
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
1340 |
dpi->top += Top(); |
6244
4b42fb40e6d2
(svn r8710) [cpp_gui] -Codechange: yet another two functions are turned into Window methods
bjarni
parents:
6237
diff
changeset
|
1341 |
|
4b42fb40e6d2
(svn r8710) [cpp_gui] -Codechange: yet another two functions are turned into Window methods
bjarni
parents:
6237
diff
changeset
|
1342 |
ViewportDraw(viewport, dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height); |
4b42fb40e6d2
(svn r8710) [cpp_gui] -Codechange: yet another two functions are turned into Window methods
bjarni
parents:
6237
diff
changeset
|
1343 |
|
6263
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
1344 |
dpi->left -= Left(); |
19dab6a68886
(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents:
6259
diff
changeset
|
1345 |
dpi->top -= Top(); |
0 | 1346 |
} |
1347 |
||
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
1348 |
void UpdateViewportPosition(BaseWindow *w) |
0 | 1349 |
{ |
2116 | 1350 |
const ViewPort *vp = w->viewport; |
0 | 1351 |
|
2116 | 1352 |
if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE) { |
1353 |
const Vehicle* veh = GetVehicle(WP(w,vp_d).follow_vehicle); |
|
1354 |
Point pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos); |
|
0 | 1355 |
|
1356 |
SetViewportPosition(w, pt.x, pt.y); |
|
1357 |
} else { |
|
632
0e71f12b846b
(svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents:
534
diff
changeset
|
1358 |
int x; |
0e71f12b846b
(svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents:
534
diff
changeset
|
1359 |
int y; |
0e71f12b846b
(svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents:
534
diff
changeset
|
1360 |
int vx; |
0e71f12b846b
(svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents:
534
diff
changeset
|
1361 |
int vy; |
0e71f12b846b
(svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents:
534
diff
changeset
|
1362 |
|
6307 | 1363 |
/* Center of the viewport is hot spot */ |
632
0e71f12b846b
(svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents:
534
diff
changeset
|
1364 |
x = WP(w,vp_d).scrollpos_x + vp->virtual_width / 2; |
0e71f12b846b
(svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents:
534
diff
changeset
|
1365 |
y = WP(w,vp_d).scrollpos_y + vp->virtual_height / 2; |
6307 | 1366 |
/* Convert viewport coordinates to map coordinates |
1367 |
* Calculation is scaled by 4 to avoid rounding errors */ |
|
632
0e71f12b846b
(svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents:
534
diff
changeset
|
1368 |
vx = -x + y * 2; |
0e71f12b846b
(svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents:
534
diff
changeset
|
1369 |
vy = x + y * 2; |
6307 | 1370 |
/* clamp to size of map */ |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1371 |
vx = clamp(vx, 0 * 4, MapMaxX() * TILE_SIZE * 4); |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1372 |
vy = clamp(vy, 0 * 4, MapMaxY() * TILE_SIZE * 4); |
6307 | 1373 |
/* Convert map coordinates to viewport coordinates */ |
632
0e71f12b846b
(svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents:
534
diff
changeset
|
1374 |
x = (-vx + vy) / 2; |
0e71f12b846b
(svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents:
534
diff
changeset
|
1375 |
y = ( vx + vy) / 4; |
6307 | 1376 |
/* Set position */ |
2116 | 1377 |
WP(w, vp_d).scrollpos_x = x - vp->virtual_width / 2; |
1378 |
WP(w, vp_d).scrollpos_y = y - vp->virtual_height / 2; |
|
632
0e71f12b846b
(svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents:
534
diff
changeset
|
1379 |
|
2116 | 1380 |
SetViewportPosition(w, WP(w, vp_d).scrollpos_x, WP(w, vp_d).scrollpos_y); |
0 | 1381 |
} |
1382 |
} |
|
1383 |
||
2116 | 1384 |
static void MarkViewportDirty(const ViewPort *vp, int left, int top, int right, int bottom) |
0 | 1385 |
{ |
2116 | 1386 |
right -= vp->virtual_left; |
1387 |
if (right <= 0) return; |
|
0 | 1388 |
|
2116 | 1389 |
bottom -= vp->virtual_top; |
1390 |
if (bottom <= 0) return; |
|
0 | 1391 |
|
2116 | 1392 |
left = max(0, left - vp->virtual_left); |
0 | 1393 |
|
2116 | 1394 |
if (left >= vp->virtual_width) return; |
0 | 1395 |
|
2116 | 1396 |
top = max(0, top - vp->virtual_top); |
1397 |
||
1398 |
if (top >= vp->virtual_height) return; |
|
0 | 1399 |
|
1400 |
SetDirtyBlocks( |
|
1401 |
(left >> vp->zoom) + vp->left, |
|
1402 |
(top >> vp->zoom) + vp->top, |
|
1403 |
(right >> vp->zoom) + vp->left, |
|
1404 |
(bottom >> vp->zoom) + vp->top |
|
1405 |
); |
|
1406 |
} |
|
1407 |
||
1408 |
void MarkAllViewportsDirty(int left, int top, int right, int bottom) |
|
1409 |
{ |
|
2116 | 1410 |
const ViewPort *vp = _viewports; |
0 | 1411 |
uint32 act = _active_viewports; |
1412 |
do { |
|
1413 |
if (act & 1) { |
|
1414 |
assert(vp->width != 0); |
|
1415 |
MarkViewportDirty(vp, left, top, right, bottom); |
|
1416 |
} |
|
1417 |
} while (vp++,act>>=1); |
|
1418 |
} |
|
1419 |
||
2116 | 1420 |
void MarkTileDirtyByTile(TileIndex tile) |
1421 |
{ |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1422 |
Point pt = RemapCoords(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, GetTileZ(tile)); |
0 | 1423 |
MarkAllViewportsDirty( |
1424 |
pt.x - 31, |
|
1425 |
pt.y - 122, |
|
1426 |
pt.x - 31 + 67, |
|
1427 |
pt.y - 122 + 154 |
|
1428 |
); |
|
1429 |
} |
|
1430 |
||
1431 |
void MarkTileDirty(int x, int y) |
|
1432 |
{ |
|
2116 | 1433 |
uint z = 0; |
0 | 1434 |
Point pt; |
2116 | 1435 |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1436 |
if (IS_INT_INSIDE(x, 0, MapSizeX() * TILE_SIZE) && |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1437 |
IS_INT_INSIDE(y, 0, MapSizeY() * TILE_SIZE)) |
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1438 |
z = GetTileZ(TileVirtXY(x, y)); |
0 | 1439 |
pt = RemapCoords(x, y, z); |
1440 |
||
1441 |
MarkAllViewportsDirty( |
|
1442 |
pt.x - 31, |
|
1443 |
pt.y - 122, |
|
1444 |
pt.x - 31 + 67, |
|
1445 |
pt.y - 122 + 154 |
|
1446 |
); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1447 |
} |
0 | 1448 |
|
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
1449 |
static void SetSelectionTilesDirty() |
0 | 1450 |
{ |
1451 |
int y_size, x_size; |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1452 |
int x = _thd.pos.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1453 |
int y = _thd.pos.y; |
0 | 1454 |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1455 |
x_size = _thd.size.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1456 |
y_size = _thd.size.y; |
0 | 1457 |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1458 |
if (_thd.outersize.x) { |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1459 |
x_size += _thd.outersize.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1460 |
x += _thd.offs.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1461 |
y_size += _thd.outersize.y; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1462 |
y += _thd.offs.y; |
0 | 1463 |
} |
1464 |
||
1465 |
assert(x_size > 0); |
|
1466 |
assert(y_size > 0); |
|
1467 |
||
1468 |
x_size += x; |
|
1469 |
y_size += y; |
|
1470 |
||
1471 |
do { |
|
1472 |
int y_bk = y; |
|
1473 |
do { |
|
1474 |
MarkTileDirty(x, y); |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1475 |
} while ( (y += TILE_SIZE) != y_size); |
0 | 1476 |
y = y_bk; |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1477 |
} while ( (x += TILE_SIZE) != x_size); |
0 | 1478 |
} |
1479 |
||
1480 |
||
1990
90eb49e87b90
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1481 |
void SetSelectionRed(bool b) |
90eb49e87b90
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1482 |
{ |
90eb49e87b90
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1483 |
_thd.make_square_red = b; |
90eb49e87b90
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1484 |
SetSelectionTilesDirty(); |
90eb49e87b90
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1485 |
} |
90eb49e87b90
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1486 |
|
90eb49e87b90
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1487 |
|
2116 | 1488 |
static bool CheckClickOnTown(const ViewPort *vp, int x, int y) |
0 | 1489 |
{ |
2116 | 1490 |
const Town *t; |
0 | 1491 |
|
2116 | 1492 |
if (!(_display_opt & DO_SHOW_TOWN_NAMES)) return false; |
0 | 1493 |
|
4471 | 1494 |
switch (vp->zoom) { |
1495 |
case 0: |
|
1496 |
x = x - vp->left + vp->virtual_left; |
|
1497 |
y = y - vp->top + vp->virtual_top; |
|
1498 |
FOR_ALL_TOWNS(t) { |
|
1499 |
if (y >= t->sign.top && |
|
1500 |
y < t->sign.top + 12 && |
|
1501 |
x >= t->sign.left && |
|
1502 |
x < t->sign.left + t->sign.width_1) { |
|
1503 |
ShowTownViewWindow(t->index); |
|
1504 |
return true; |
|
1505 |
} |
|
0 | 1506 |
} |
4471 | 1507 |
break; |
1508 |
||
1509 |
case 1: |
|
1510 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
|
1511 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
|
1512 |
FOR_ALL_TOWNS(t) { |
|
1513 |
if (y >= t->sign.top && |
|
1514 |
y < t->sign.top + 24 && |
|
1515 |
x >= t->sign.left && |
|
1516 |
x < t->sign.left + t->sign.width_1 * 2) { |
|
1517 |
ShowTownViewWindow(t->index); |
|
1518 |
return true; |
|
1519 |
} |
|
0 | 1520 |
} |
4471 | 1521 |
break; |
1522 |
||
1523 |
default: |
|
1524 |
x = (x - vp->left + 3) * 4 + vp->virtual_left; |
|
1525 |
y = (y - vp->top + 3) * 4 + vp->virtual_top; |
|
1526 |
FOR_ALL_TOWNS(t) { |
|
1527 |
if (y >= t->sign.top && |
|
1528 |
y < t->sign.top + 24 && |
|
1529 |
x >= t->sign.left && |
|
1530 |
x < t->sign.left + t->sign.width_2 * 4) { |
|
1531 |
ShowTownViewWindow(t->index); |
|
1532 |
return true; |
|
1533 |
} |
|
0 | 1534 |
} |
4471 | 1535 |
break; |
0 | 1536 |
} |
1537 |
||
1538 |
return false; |
|
1539 |
} |
|
1540 |
||
4471 | 1541 |
|
2116 | 1542 |
static bool CheckClickOnStation(const ViewPort *vp, int x, int y) |
0 | 1543 |
{ |
2116 | 1544 |
const Station *st; |
0 | 1545 |
|
2116 | 1546 |
if (!(_display_opt & DO_SHOW_STATION_NAMES)) return false; |
0 | 1547 |
|
4471 | 1548 |
switch (vp->zoom) { |
1549 |
case 0: |
|
1550 |
x = x - vp->left + vp->virtual_left; |
|
1551 |
y = y - vp->top + vp->virtual_top; |
|
1552 |
FOR_ALL_STATIONS(st) { |
|
1553 |
if (y >= st->sign.top && |
|
1554 |
y < st->sign.top + 12 && |
|
1555 |
x >= st->sign.left && |
|
1556 |
x < st->sign.left + st->sign.width_1) { |
|
1557 |
ShowStationViewWindow(st->index); |
|
1558 |
return true; |
|
1559 |
} |
|
0 | 1560 |
} |
4471 | 1561 |
break; |
1562 |
||
1563 |
case 1: |
|
1564 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
|
1565 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
|
1566 |
FOR_ALL_STATIONS(st) { |
|
1567 |
if (y >= st->sign.top && |
|
1568 |
y < st->sign.top + 24 && |
|
1569 |
x >= st->sign.left && |
|
1570 |
x < st->sign.left + st->sign.width_1 * 2) { |
|
1571 |
ShowStationViewWindow(st->index); |
|
1572 |
return true; |
|
1573 |
} |
|
0 | 1574 |
} |
4471 | 1575 |
break; |
1576 |
||
1577 |
default: |
|
1578 |
x = (x - vp->left + 3) * 4 + vp->virtual_left; |
|
1579 |
y = (y - vp->top + 3) * 4 + vp->virtual_top; |
|
1580 |
FOR_ALL_STATIONS(st) { |
|
1581 |
if (y >= st->sign.top && |
|
1582 |
y < st->sign.top + 24 && |
|
1583 |
x >= st->sign.left && |
|
1584 |
x < st->sign.left + st->sign.width_2 * 4) { |
|
1585 |
ShowStationViewWindow(st->index); |
|
1586 |
return true; |
|
1587 |
} |
|
0 | 1588 |
} |
4471 | 1589 |
break; |
0 | 1590 |
} |
1591 |
||
1592 |
return false; |
|
1593 |
} |
|
1594 |
||
4471 | 1595 |
|
2116 | 1596 |
static bool CheckClickOnSign(const ViewPort *vp, int x, int y) |
0 | 1597 |
{ |
4349
2fc39ff2626e
(svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents:
4346
diff
changeset
|
1598 |
const Sign *si; |
0 | 1599 |
|
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
6263
diff
changeset
|
1600 |
if (!(_display_opt & DO_SHOW_SIGNS) || _current_player == PLAYER_SPECTATOR) return false; |
0 | 1601 |
|
4471 | 1602 |
switch (vp->zoom) { |
1603 |
case 0: |
|
1604 |
x = x - vp->left + vp->virtual_left; |
|
1605 |
y = y - vp->top + vp->virtual_top; |
|
1606 |
FOR_ALL_SIGNS(si) { |
|
1607 |
if (y >= si->sign.top && |
|
1608 |
y < si->sign.top + 12 && |
|
1609 |
x >= si->sign.left && |
|
1610 |
x < si->sign.left + si->sign.width_1) { |
|
1611 |
ShowRenameSignWindow(si); |
|
1612 |
return true; |
|
1613 |
} |
|
0 | 1614 |
} |
4471 | 1615 |
break; |
1616 |
||
1617 |
case 1: |
|
1618 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
|
1619 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
|
1620 |
FOR_ALL_SIGNS(si) { |
|
1621 |
if (y >= si->sign.top && |
|
1622 |
y < si->sign.top + 24 && |
|
1623 |
x >= si->sign.left && |
|
1624 |
x < si->sign.left + si->sign.width_1 * 2) { |
|
1625 |
ShowRenameSignWindow(si); |
|
1626 |
return true; |
|
1627 |
} |
|
0 | 1628 |
} |
4471 | 1629 |
break; |
1630 |
||
1631 |
default: |
|
1632 |
x = (x - vp->left + 3) * 4 + vp->virtual_left; |
|
1633 |
y = (y - vp->top + 3) * 4 + vp->virtual_top; |
|
1634 |
FOR_ALL_SIGNS(si) { |
|
1635 |
if (y >= si->sign.top && |
|
1636 |
y < si->sign.top + 24 && |
|
1637 |
x >= si->sign.left && |
|
1638 |
x < si->sign.left + si->sign.width_2 * 4) { |
|
1639 |
ShowRenameSignWindow(si); |
|
1640 |
return true; |
|
1641 |
} |
|
0 | 1642 |
} |
4471 | 1643 |
break; |
0 | 1644 |
} |
1645 |
||
1646 |
return false; |
|
1647 |
} |
|
1648 |
||
4471 | 1649 |
|
2116 | 1650 |
static bool CheckClickOnWaypoint(const ViewPort *vp, int x, int y) |
0 | 1651 |
{ |
2116 | 1652 |
const Waypoint *wp; |
0 | 1653 |
|
2116 | 1654 |
if (!(_display_opt & DO_WAYPOINTS)) return false; |
0 | 1655 |
|
4471 | 1656 |
switch (vp->zoom) { |
1657 |
case 0: |
|
1658 |
x = x - vp->left + vp->virtual_left; |
|
1659 |
y = y - vp->top + vp->virtual_top; |
|
1660 |
FOR_ALL_WAYPOINTS(wp) { |
|
1661 |
if (y >= wp->sign.top && |
|
1662 |
y < wp->sign.top + 12 && |
|
1663 |
x >= wp->sign.left && |
|
1664 |
x < wp->sign.left + wp->sign.width_1) { |
|
1665 |
ShowRenameWaypointWindow(wp); |
|
1666 |
return true; |
|
1667 |
} |
|
0 | 1668 |
} |
4471 | 1669 |
break; |
1670 |
||
1671 |
case 1: |
|
1672 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
|
1673 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
|
1674 |
FOR_ALL_WAYPOINTS(wp) { |
|
1675 |
if (y >= wp->sign.top && |
|
1676 |
y < wp->sign.top + 24 && |
|
1677 |
x >= wp->sign.left && |
|
1678 |
x < wp->sign.left + wp->sign.width_1 * 2) { |
|
1679 |
ShowRenameWaypointWindow(wp); |
|
1680 |
return true; |
|
1681 |
} |
|
0 | 1682 |
} |
4471 | 1683 |
break; |
1684 |
||
1685 |
default: |
|
1686 |
x = (x - vp->left + 3) * 4 + vp->virtual_left; |
|
1687 |
y = (y - vp->top + 3) * 4 + vp->virtual_top; |
|
1688 |
FOR_ALL_WAYPOINTS(wp) { |
|
1689 |
if (y >= wp->sign.top && |
|
1690 |
y < wp->sign.top + 24 && |
|
1691 |
x >= wp->sign.left && |
|
1692 |
x < wp->sign.left + wp->sign.width_2 * 4) { |
|
1693 |
ShowRenameWaypointWindow(wp); |
|
1694 |
return true; |
|
1695 |
} |
|
0 | 1696 |
} |
4471 | 1697 |
break; |
0 | 1698 |
} |
1699 |
||
1700 |
return false; |
|
1701 |
} |
|
1702 |
||
1703 |
||
2116 | 1704 |
static void CheckClickOnLandscape(const ViewPort *vp, int x, int y) |
0 | 1705 |
{ |
2116 | 1706 |
Point pt = TranslateXYToTileCoord(vp, x, y); |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1964
diff
changeset
|
1707 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1708 |
if (pt.x != -1) ClickTile(TileVirtXY(pt.x, pt.y)); |
0 | 1709 |
} |
1710 |
||
2662
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1711 |
|
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1712 |
static void SafeShowTrainViewWindow(const Vehicle* v) |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1713 |
{ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1714 |
if (!IsFrontEngine(v)) v = GetFirstVehicleInChain(v); |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1715 |
ShowTrainViewWindow(v); |
2662
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1716 |
} |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1717 |
|
4171 | 1718 |
static void Nop(const Vehicle *v) {} |
2662
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1719 |
|
4171 | 1720 |
typedef void OnVehicleClickProc(const Vehicle *v); |
2662
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1721 |
static OnVehicleClickProc* const _on_vehicle_click_proc[] = { |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1722 |
SafeShowTrainViewWindow, |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1723 |
ShowRoadVehViewWindow, |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1724 |
ShowShipViewWindow, |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1725 |
ShowAircraftViewWindow, |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1726 |
Nop, // Special vehicles |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1727 |
Nop // Disaster vehicles |
0 | 1728 |
}; |
1729 |
||
2116 | 1730 |
void HandleViewportClicked(const ViewPort *vp, int x, int y) |
0 | 1731 |
{ |
4171 | 1732 |
const Vehicle *v; |
0 | 1733 |
|
2116 | 1734 |
if (CheckClickOnTown(vp, x, y)) return; |
1735 |
if (CheckClickOnStation(vp, x, y)) return; |
|
1736 |
if (CheckClickOnSign(vp, x, y)) return; |
|
1737 |
if (CheckClickOnWaypoint(vp, x, y)) return; |
|
0 | 1738 |
CheckClickOnLandscape(vp, x, y); |
1739 |
||
2116 | 1740 |
v = CheckClickOnVehicle(vp, x, y); |
3809
cff6d5e916f7
(svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents:
3798
diff
changeset
|
1741 |
if (v != NULL) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5137
diff
changeset
|
1742 |
DEBUG(misc, 2, "Vehicle %d (index %d) at %p", v->unitnumber, v->index, v); |
6206
67358999d80d
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
6144
diff
changeset
|
1743 |
_on_vehicle_click_proc[v->type](v); |
3809
cff6d5e916f7
(svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents:
3798
diff
changeset
|
1744 |
} |
0 | 1745 |
} |
1746 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
1747 |
Vehicle *CheckMouseOverVehicle() |
0 | 1748 |
{ |
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
1749 |
const BaseWindow *w; |
4171 | 1750 |
const ViewPort *vp; |
0 | 1751 |
|
1752 |
int x = _cursor.pos.x; |
|
1753 |
int y = _cursor.pos.y; |
|
1754 |
||
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
1755 |
w = BaseWindow::FindFromPt(x, y); |
2116 | 1756 |
if (w == NULL) return NULL; |
0 | 1757 |
|
1758 |
vp = IsPtInWindowViewport(w, x, y); |
|
2116 | 1759 |
return (vp != NULL) ? CheckClickOnVehicle(vp, x, y) : NULL; |
0 | 1760 |
} |
1761 |
||
1762 |
||
1763 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
1764 |
void PlaceObject() |
0 | 1765 |
{ |
1766 |
Point pt; |
|
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
1767 |
BaseWindow *w; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1768 |
|
0 | 1769 |
pt = GetTileBelowCursor(); |
2116 | 1770 |
if (pt.x == -1) return; |
0 | 1771 |
|
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1772 |
if (_thd.place_mode == VHM_POINT) { |
0 | 1773 |
pt.x += 8; |
1774 |
pt.y += 8; |
|
1775 |
} |
|
1776 |
||
1777 |
_tile_fract_coords.x = pt.x & 0xF; |
|
1778 |
_tile_fract_coords.y = pt.y & 0xF; |
|
1779 |
||
2116 | 1780 |
w = GetCallbackWnd(); |
1781 |
if (w != NULL) { |
|
1782 |
WindowEvent e; |
|
1783 |
||
0 | 1784 |
e.event = WE_PLACE_OBJ; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
1785 |
e.we.place.pt = pt; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
1786 |
e.we.place.tile = TileVirtXY(pt.x, pt.y); |
0 | 1787 |
w->wndproc(w, &e); |
1788 |
} |
|
1789 |
} |
|
1790 |
||
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1791 |
|
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1792 |
/* scrolls the viewport in a window to a given location */ |
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
1793 |
bool ScrollWindowTo(int x , int y, BaseWindow *w) |
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1794 |
{ |
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1795 |
Point pt; |
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1796 |
|
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1797 |
pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y)); |
2116 | 1798 |
WP(w, vp_d).follow_vehicle = INVALID_VEHICLE; |
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1799 |
|
2116 | 1800 |
if (WP(w, vp_d).scrollpos_x == pt.x && WP(w, vp_d).scrollpos_y == pt.y) |
1801 |
return false; |
|
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1802 |
|
2116 | 1803 |
WP(w, vp_d).scrollpos_x = pt.x; |
1804 |
WP(w, vp_d).scrollpos_y = pt.y; |
|
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1805 |
return true; |
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1806 |
} |
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1807 |
|
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1808 |
|
0 | 1809 |
bool ScrollMainWindowTo(int x, int y) |
1810 |
{ |
|
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
1811 |
BaseWindow *w; |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
1812 |
bool res = ScrollWindowTo(x, y, BaseWindow::FindById(WC_MAIN_WINDOW, 0)); |
4339
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1813 |
|
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1814 |
/* If a user scrolls to a tile (via what way what so ever) and already is on |
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1815 |
* that tile (e.g.: pressed twice), move the smallmap to that location, |
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1816 |
* so you directly see where you are on the smallmap. */ |
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1817 |
|
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1818 |
if (res) return res; |
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1819 |
|
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
1820 |
w = BaseWindow::FindById(WC_SMALLMAP, 0); |
4339
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1821 |
if (w == NULL) return res; |
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1822 |
|
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1823 |
SmallMapCenterOnCurrentPos(w); |
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1824 |
|
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1825 |
return res; |
0 | 1826 |
} |
1827 |
||
1828 |
||
1829 |
bool ScrollMainWindowToTile(TileIndex tile) |
|
1830 |
{ |
|
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
1831 |
return ScrollMainWindowTo(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2); |
0 | 1832 |
} |
1833 |
||
1834 |
void SetRedErrorSquare(TileIndex tile) |
|
1835 |
{ |
|
1836 |
TileIndex old; |
|
1837 |
||
1838 |
old = _thd.redsq; |
|
1839 |
_thd.redsq = tile; |
|
1840 |
||
1841 |
if (tile != old) { |
|
3281
0f3d836e35b1
(svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents:
3279
diff
changeset
|
1842 |
if (tile != 0) MarkTileDirtyByTile(tile); |
0f3d836e35b1
(svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents:
3279
diff
changeset
|
1843 |
if (old != 0) MarkTileDirtyByTile(old); |
0 | 1844 |
} |
1845 |
} |
|
1846 |
||
1847 |
void SetTileSelectSize(int w, int h) |
|
1848 |
{ |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1849 |
_thd.new_size.x = w * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1850 |
_thd.new_size.y = h * TILE_SIZE; |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1851 |
_thd.new_outersize.x = 0; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1852 |
_thd.new_outersize.y = 0; |
0 | 1853 |
} |
1854 |
||
2116 | 1855 |
void SetTileSelectBigSize(int ox, int oy, int sx, int sy) |
1856 |
{ |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1857 |
_thd.offs.x = ox * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1858 |
_thd.offs.y = oy * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1859 |
_thd.new_outersize.x = sx * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1860 |
_thd.new_outersize.y = sy * TILE_SIZE; |
0 | 1861 |
} |
1862 |
||
6307 | 1863 |
/** returns the best autorail highlight type from map coordinates */ |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1864 |
static byte GetAutorailHT(int x, int y) |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1865 |
{ |
2710
e144188c1fdb
(svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents:
2676
diff
changeset
|
1866 |
return HT_RAIL | _AutorailPiece[x & 0xF][y & 0xF]; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1867 |
} |
0 | 1868 |
|
6307 | 1869 |
/** called regular to update tile highlighting in all cases */ |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
1870 |
void UpdateTileSelection() |
0 | 1871 |
{ |
2116 | 1872 |
int x1; |
1873 |
int y1; |
|
0 | 1874 |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1875 |
_thd.new_drawstyle = 0; |
0 | 1876 |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1877 |
if (_thd.place_mode == VHM_SPECIAL) { |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1878 |
x1 = _thd.selend.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1879 |
y1 = _thd.selend.y; |
0 | 1880 |
if (x1 != -1) { |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1881 |
int x2 = _thd.selstart.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1882 |
int y2 = _thd.selstart.y; |
0 | 1883 |
x1 &= ~0xF; |
1884 |
y1 &= ~0xF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1885 |
|
6268
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
6263
diff
changeset
|
1886 |
if (x1 >= x2) Swap(x1, x2); |
4b5241e5dd10
(svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents:
6263
diff
changeset
|
1887 |
if (y1 >= y2) Swap(y1, y2); |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1888 |
_thd.new_pos.x = x1; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1889 |
_thd.new_pos.y = y1; |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1890 |
_thd.new_size.x = x2 - x1 + TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1891 |
_thd.new_size.y = y2 - y1 + TILE_SIZE; |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1892 |
_thd.new_drawstyle = _thd.next_drawstyle; |
0 | 1893 |
} |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1894 |
} else if (_thd.place_mode != VHM_NONE) { |
2116 | 1895 |
Point pt = GetTileBelowCursor(); |
0 | 1896 |
x1 = pt.x; |
1897 |
y1 = pt.y; |
|
1898 |
if (x1 != -1) { |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1899 |
switch (_thd.place_mode) { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1900 |
case VHM_RECT: |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1901 |
_thd.new_drawstyle = HT_RECT; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1902 |
break; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1903 |
case VHM_POINT: |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1904 |
_thd.new_drawstyle = HT_POINT; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1905 |
x1 += 8; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1906 |
y1 += 8; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1907 |
break; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1908 |
case VHM_RAIL: |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1909 |
_thd.new_drawstyle = GetAutorailHT(pt.x, pt.y); // draw one highlighted tile |
0 | 1910 |
} |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1911 |
_thd.new_pos.x = x1 & ~0xF; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1912 |
_thd.new_pos.y = y1 & ~0xF; |
0 | 1913 |
} |
1914 |
} |
|
1915 |
||
6307 | 1916 |
/* redraw selection */ |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1917 |
if (_thd.drawstyle != _thd.new_drawstyle || |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1918 |
_thd.pos.x != _thd.new_pos.x || _thd.pos.y != _thd.new_pos.y || |
4539
0b13858554fb
(svn r6368) -Fix [FS#136]: Station catchment area persists after switching tools. The
Darkvater
parents:
4523
diff
changeset
|
1919 |
_thd.size.x != _thd.new_size.x || _thd.size.y != _thd.new_size.y || |
0b13858554fb
(svn r6368) -Fix [FS#136]: Station catchment area persists after switching tools. The
Darkvater
parents:
4523
diff
changeset
|
1920 |
_thd.outersize.x != _thd.new_outersize.x || |
0b13858554fb
(svn r6368) -Fix [FS#136]: Station catchment area persists after switching tools. The
Darkvater
parents:
4523
diff
changeset
|
1921 |
_thd.outersize.y != _thd.new_outersize.y) { |
6307 | 1922 |
/* clear the old selection? */ |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1923 |
if (_thd.drawstyle) SetSelectionTilesDirty(); |
0 | 1924 |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1925 |
_thd.drawstyle = _thd.new_drawstyle; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1926 |
_thd.pos = _thd.new_pos; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1927 |
_thd.size = _thd.new_size; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1928 |
_thd.outersize = _thd.new_outersize; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1929 |
_thd.dirty = 0xff; |
0 | 1930 |
|
6307 | 1931 |
/* draw the new selection? */ |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1932 |
if (_thd.new_drawstyle) SetSelectionTilesDirty(); |
0 | 1933 |
} |
1934 |
} |
|
1935 |
||
6307 | 1936 |
/** highlighting tiles while only going over them with the mouse */ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1964
diff
changeset
|
1937 |
void VpStartPlaceSizing(TileIndex tile, int user) |
0 | 1938 |
{ |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1939 |
_thd.userdata = user; |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1940 |
_thd.selend.x = TileX(tile) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1941 |
_thd.selstart.x = TileX(tile) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1942 |
_thd.selend.y = TileY(tile) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1943 |
_thd.selstart.y = TileY(tile) * TILE_SIZE; |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1944 |
if (_thd.place_mode == VHM_RECT) { |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1945 |
_thd.place_mode = VHM_SPECIAL; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1946 |
_thd.next_drawstyle = HT_RECT; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1947 |
} else if (_thd.place_mode == VHM_RAIL) { // autorail one piece |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1948 |
_thd.place_mode = VHM_SPECIAL; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1949 |
_thd.next_drawstyle = _thd.drawstyle; |
0 | 1950 |
} else { |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1951 |
_thd.place_mode = VHM_SPECIAL; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1952 |
_thd.next_drawstyle = HT_POINT; |
0 | 1953 |
} |
1954 |
_special_mouse_mode = WSM_SIZING; |
|
1955 |
} |
|
1956 |
||
1957 |
void VpSetPlaceSizingLimit(int limit) |
|
1958 |
{ |
|
1959 |
_thd.sizelimit = limit; |
|
1960 |
} |
|
1961 |
||
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1962 |
/** |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1963 |
* Highlights all tiles between a set of two tiles. Used in dock and tunnel placement |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1964 |
* @param from TileIndex of the first tile to highlight |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1965 |
* @param to TileIndex of the last tile to highlight */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1966 |
void VpSetPresizeRange(TileIndex from, TileIndex to) |
0 | 1967 |
{ |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1968 |
uint distance = DistanceManhattan(from, to) + 1; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1969 |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1970 |
_thd.selend.x = TileX(to) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1971 |
_thd.selend.y = TileY(to) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1972 |
_thd.selstart.x = TileX(from) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1973 |
_thd.selstart.y = TileY(from) * TILE_SIZE; |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1974 |
_thd.next_drawstyle = HT_RECT; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1975 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1976 |
/* show measurement only if there is any length to speak of */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1977 |
if (distance > 1) GuiShowTooltipsWithArgs(STR_MEASURE_LENGTH, 1, &distance); |
0 | 1978 |
} |
1979 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
1980 |
static void VpStartPreSizing() |
0 | 1981 |
{ |
1982 |
_thd.selend.x = -1; |
|
1983 |
_special_mouse_mode = WSM_PRESIZE; |
|
1984 |
} |
|
1985 |
||
6307 | 1986 |
/** returns information about the 2x1 piece to be build. |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1987 |
* The lower bits (0-3) are the track type. */ |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1988 |
static byte Check2x1AutoRail(int mode) |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1989 |
{ |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1990 |
int fxpy = _tile_fract_coords.x + _tile_fract_coords.y; |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1991 |
int sxpy = (_thd.selend.x & 0xF) + (_thd.selend.y & 0xF); |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1992 |
int fxmy = _tile_fract_coords.x - _tile_fract_coords.y; |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1993 |
int sxmy = (_thd.selend.x & 0xF) - (_thd.selend.y & 0xF); |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1994 |
|
2952 | 1995 |
switch (mode) { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1996 |
case 0: // end piece is lower right |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1997 |
if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1998 |
if (fxmy < -3 && sxmy > 3) {/* DoRailroadTrack(0); */return 5; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1999 |
return 1; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2000 |
|
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2001 |
case 1: |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2002 |
if (fxmy > 3 && sxmy < -3) { /*SwapSelection(); DoRailroadTrack(0); */return 4; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2003 |
if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2004 |
return 1; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2005 |
|
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2006 |
case 2: |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2007 |
if (fxmy > 3 && sxmy < -3) { /*DoRailroadTrack(3);*/ return 4; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2008 |
if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2009 |
return 0; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2010 |
|
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2011 |
case 3: |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2012 |
if (fxmy < -3 && sxmy > 3) { /*SwapSelection(); DoRailroadTrack(3);*/ return 5; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2013 |
if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2014 |
return 0; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2015 |
} |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2016 |
|
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2017 |
return 0; // avoids compiler warnings |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2018 |
} |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2019 |
|
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2020 |
/** Check if the direction of start and end tile should be swapped based on |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2021 |
* the dragging-style. Default directions are: |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2022 |
* in the case of a line (HT_RAIL, HT_LINE): DIR_NE, DIR_NW, DIR_N, DIR_E |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2023 |
* in the case of a rect (HT_RECT, HT_POINT): DIR_S, DIR_E |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2024 |
* For example dragging a rectangle area from south to north should be swapped to |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2025 |
* north-south (DIR_S) to obtain the same results with less code. This is what |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2026 |
* the return value signifies. |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2027 |
* @param style HighLightStyle dragging style |
6308 | 2028 |
* @param start_tile start tile of drag |
2029 |
* @param end_tile end tile of drag |
|
2030 |
* @return boolean value which when true means start/end should be swapped */ |
|
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2031 |
static bool SwapDirection(HighLightStyle style, TileIndex start_tile, TileIndex end_tile) |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2032 |
{ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2033 |
uint start_x = TileX(start_tile); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2034 |
uint start_y = TileY(start_tile); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2035 |
uint end_x = TileX(end_tile); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2036 |
uint end_y = TileY(end_tile); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2037 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2038 |
switch (style & HT_DRAG_MASK) { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2039 |
case HT_RAIL: |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2040 |
case HT_LINE: return (end_x > start_x || (end_x == start_x && end_y > start_y)); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2041 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2042 |
case HT_RECT: |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2043 |
case HT_POINT: return (end_x != start_x && end_y < start_y); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2044 |
default: NOT_REACHED(); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2045 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2046 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2047 |
return false; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2048 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2049 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2050 |
/** Calculates height difference between one tile and another |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2051 |
* Multiplies the result to suit the standard given by minimap - 50 meters high |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2052 |
* To correctly get the height difference we need the direction we are dragging |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2053 |
* in, as well as with what kind of tool we are dragging. For example a horizontal |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2054 |
* autorail tool that starts in bottom and ends at the top of a tile will need the |
6308 | 2055 |
* maximum of SW, S and SE, N corners respectively. This is handled by the lookup table below |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2056 |
* See _tileoffs_by_dir in map.c for the direction enums if you can't figure out |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2057 |
* the values yourself. |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2058 |
* @param style HightlightStyle of drag. This includes direction and style (autorail, rect, etc.) |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2059 |
* @param distance amount of tiles dragged, important for horizontal/vertical drags |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2060 |
* ignored for others |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2061 |
* @param start_tile, end_tile start and end tile of drag operation |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2062 |
* @return height difference between two tiles. Tile measurement tool utilizes |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2063 |
* this value in its tooltips */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2064 |
static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_tile, TileIndex end_tile) |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2065 |
{ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2066 |
bool swap = SwapDirection(style, start_tile, end_tile); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2067 |
byte style_t; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2068 |
uint h0, h1, ht; // start heigth, end height, and temp variable |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2069 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2070 |
if (start_tile == end_tile) return 0; |
5984 | 2071 |
if (swap) Swap(start_tile, end_tile); |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2072 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2073 |
switch (style & HT_DRAG_MASK) { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2074 |
case HT_RECT: { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2075 |
static const TileIndexDiffC heightdiff_area_by_dir[] = { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2076 |
/* Start */ {1, 0}, /* Dragging east */ {0, 0}, /* Dragging south */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2077 |
/* End */ {0, 1}, /* Dragging east */ {1, 1} /* Dragging south */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2078 |
}; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2079 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2080 |
/* In the case of an area we can determine whether we were dragging south or |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2081 |
* east by checking the X-coordinates of the tiles */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2082 |
style_t = (byte)(TileX(end_tile) > TileX(start_tile)); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2083 |
start_tile = TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_area_by_dir[style_t])); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2084 |
end_tile = TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_area_by_dir[2 + style_t])); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2085 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2086 |
/* Fallthrough */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2087 |
case HT_POINT: |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2088 |
h0 = TileHeight(start_tile); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2089 |
h1 = TileHeight(end_tile); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2090 |
break; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2091 |
default: { /* All other types, this is mostly only line/autorail */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2092 |
static const HighLightStyle flip_style_direction[] = { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2093 |
HT_DIR_X, HT_DIR_Y, HT_DIR_HL, HT_DIR_HU, HT_DIR_VR, HT_DIR_VL |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2094 |
}; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2095 |
static const TileIndexDiffC heightdiff_line_by_dir[] = { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2096 |
/* Start */ {1, 0}, {1, 1}, /* HT_DIR_X */ {0, 1}, {1, 1}, /* HT_DIR_Y */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2097 |
/* Start */ {1, 0}, {0, 0}, /* HT_DIR_HU */ {1, 0}, {1, 1}, /* HT_DIR_HL */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2098 |
/* Start */ {1, 0}, {1, 1}, /* HT_DIR_VL */ {0, 1}, {1, 1}, /* HT_DIR_VR */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2099 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2100 |
/* Start */ {0, 1}, {0, 0}, /* HT_DIR_X */ {1, 0}, {0, 0}, /* HT_DIR_Y */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2101 |
/* End */ {0, 1}, {0, 0}, /* HT_DIR_HU */ {1, 1}, {0, 1}, /* HT_DIR_HL */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2102 |
/* End */ {1, 0}, {0, 0}, /* HT_DIR_VL */ {0, 0}, {0, 1}, /* HT_DIR_VR */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2103 |
}; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2104 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2105 |
distance %= 2; // we're only interested if the distance is even or uneven |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2106 |
style &= HT_DIR_MASK; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2107 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2108 |
/* To handle autorail, we do some magic to be able to use a lookup table. |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2109 |
* Firstly if we drag the other way around, we switch start&end, and if needed |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2110 |
* also flip the drag-position. Eg if it was on the left, and the distance is even |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2111 |
* that means the end, which is now the start is on the right */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2112 |
if (swap && distance == 0) style = flip_style_direction[style]; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2113 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2114 |
/* Use lookup table for start-tile based on HighLightStyle direction */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2115 |
style_t = style * 2; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2116 |
assert(style_t < lengthof(heightdiff_line_by_dir) - 13); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2117 |
h0 = TileHeight(TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_line_by_dir[style_t]))); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2118 |
ht = TileHeight(TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_line_by_dir[style_t + 1]))); |
5852
cb3f71b16e1a
(svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents:
5838
diff
changeset
|
2119 |
h0 = max(h0, ht); |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2120 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2121 |
/* Use lookup table for end-tile based on HighLightStyle direction |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2122 |
* flip around side (lower/upper, left/right) based on distance */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2123 |
if (distance == 0) style_t = flip_style_direction[style] * 2; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2124 |
assert(style_t < lengthof(heightdiff_line_by_dir) - 13); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2125 |
h1 = TileHeight(TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_line_by_dir[12 + style_t]))); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2126 |
ht = TileHeight(TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_line_by_dir[12 + style_t + 1]))); |
5852
cb3f71b16e1a
(svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents:
5838
diff
changeset
|
2127 |
h1 = max(h1, ht); |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2128 |
} break; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2129 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2130 |
|
5984 | 2131 |
if (swap) Swap(h0, h1); |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2132 |
/* Minimap shows height in intervals of 50 meters, let's do the same */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2133 |
return (int)(h1 - h0) * 50; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2134 |
} |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2135 |
|
4885
c9fe8c52fd50
(svn r6822) -Fix r6821: add type for measure_strings_length[]
glx
parents:
4884
diff
changeset
|
2136 |
static const StringID measure_strings_length[] = {STR_NULL, STR_MEASURE_LENGTH, STR_MEASURE_LENGTH_HEIGHTDIFF}; |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2137 |
|
6307 | 2138 |
/** while dragging */ |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2139 |
static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int method) |
0 | 2140 |
{ |
4799
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2141 |
HighLightStyle b; |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2142 |
uint w, h; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2143 |
|
4799
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2144 |
int dx = thd->selstart.x - (thd->selend.x & ~0xF); |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2145 |
int dy = thd->selstart.y - (thd->selend.y & ~0xF); |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2146 |
w = myabs(dx) + 16; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2147 |
h = myabs(dy) + 16; |
0 | 2148 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
2149 |
if (TileVirtXY(thd->selstart.x, thd->selstart.y) == TileVirtXY(x, y)) { // check if we're only within one tile |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2150 |
if (method == VPM_RAILDIRS) { |
2116 | 2151 |
b = GetAutorailHT(x, y); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2152 |
} else { // rect for autosignals on one tile |
2116 | 2153 |
b = HT_RECT; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2154 |
} |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2155 |
} else if (h == 16) { // Is this in X direction? |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2156 |
if (dx == 16) { // 2x1 special handling |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2157 |
b = (Check2x1AutoRail(3)) | HT_LINE; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2158 |
} else if (dx == -16) { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2159 |
b = (Check2x1AutoRail(2)) | HT_LINE; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2160 |
} else { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2161 |
b = HT_LINE | HT_DIR_X; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2162 |
} |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2163 |
y = thd->selstart.y; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2164 |
} else if (w == 16) { // Or Y direction? |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2165 |
if (dy == 16) { // 2x1 special handling |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2166 |
b = (Check2x1AutoRail(1)) | HT_LINE; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2167 |
} else if (dy == -16) { // 2x1 other direction |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2168 |
b = (Check2x1AutoRail(0)) | HT_LINE; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2169 |
} else { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2170 |
b = HT_LINE | HT_DIR_Y; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2171 |
} |
0 | 2172 |
x = thd->selstart.x; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2173 |
} else if (w > h * 2) { // still count as x dir? |
2116 | 2174 |
b = HT_LINE | HT_DIR_X; |
0 | 2175 |
y = thd->selstart.y; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2176 |
} else if (h > w * 2) { // still count as y dir? |
2116 | 2177 |
b = HT_LINE | HT_DIR_Y; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2178 |
x = thd->selstart.x; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2179 |
} else { // complicated direction |
4799
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2180 |
int d = w - h; |
2116 | 2181 |
thd->selend.x = thd->selend.x & ~0xF; |
2182 |
thd->selend.y = thd->selend.y & ~0xF; |
|
0 | 2183 |
|
2184 |
// four cases. |
|
2185 |
if (x > thd->selstart.x) { |
|
2186 |
if (y > thd->selstart.y) { |
|
2187 |
// south |
|
2116 | 2188 |
if (d == 0) { |
2189 |
b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR; |
|
2190 |
} else if (d >= 0) { |
|
2191 |
x = thd->selstart.x + h; |
|
2192 |
b = HT_LINE | HT_DIR_VL; |
|
2193 |
// return px == py || px == py + 16; |
|
2194 |
} else { |
|
2195 |
y = thd->selstart.y + w; |
|
2196 |
b = HT_LINE | HT_DIR_VR; |
|
2197 |
} // return px == py || px == py - 16; |
|
0 | 2198 |
} else { |
2199 |
// west |
|
2116 | 2200 |
if (d == 0) { |
2201 |
b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU; |
|
2202 |
} else if (d >= 0) { |
|
2203 |
x = thd->selstart.x + h; |
|
2204 |
b = HT_LINE | HT_DIR_HL; |
|
2205 |
} else { |
|
2206 |
y = thd->selstart.y - w; |
|
2207 |
b = HT_LINE | HT_DIR_HU; |
|
2208 |
} |
|
0 | 2209 |
} |
2210 |
} else { |
|
2211 |
if (y > thd->selstart.y) { |
|
2212 |
// east |
|
2116 | 2213 |
if (d == 0) { |
2214 |
b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU; |
|
2215 |
} else if (d >= 0) { |
|
2216 |
x = thd->selstart.x - h; |
|
2217 |
b = HT_LINE | HT_DIR_HU; |
|
2218 |
// return px == -py || px == -py - 16; |
|
2219 |
} else { |
|
2220 |
y = thd->selstart.y + w; |
|
2221 |
b = HT_LINE | HT_DIR_HL; |
|
2222 |
} // return px == -py || px == -py + 16; |
|
0 | 2223 |
} else { |
2224 |
// north |
|
2116 | 2225 |
if (d == 0) { |
2226 |
b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR; |
|
2227 |
} else if (d >= 0) { |
|
2228 |
x = thd->selstart.x - h; |
|
2229 |
b = HT_LINE | HT_DIR_VR; |
|
2230 |
// return px == py || px == py - 16; |
|
2231 |
} else { |
|
2232 |
y = thd->selstart.y - w; |
|
2233 |
b = HT_LINE | HT_DIR_VL; |
|
2234 |
} //return px == py || px == py + 16; |
|
0 | 2235 |
} |
2236 |
} |
|
2237 |
} |
|
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2238 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2239 |
if (_patches.measure_tooltip) { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2240 |
TileIndex t0 = TileVirtXY(thd->selstart.x, thd->selstart.y); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2241 |
TileIndex t1 = TileVirtXY(x, y); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2242 |
uint distance = DistanceManhattan(t0, t1) + 1; |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2243 |
byte index = 0; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2244 |
uint params[2]; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2245 |
|
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2246 |
if (distance != 1) { |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2247 |
int heightdiff = CalcHeightdiff(b, distance, t0, t1); |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2248 |
/* If we are showing a tooltip for horizontal or vertical drags, |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2249 |
* 2 tiles have a length of 1. To bias towards the ceiling we add |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2250 |
* one before division. It feels more natural to count 3 lengths as 2 */ |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2251 |
if ((b & HT_DIR_MASK) != HT_DIR_X && (b & HT_DIR_MASK) != HT_DIR_Y) { |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2252 |
distance = (distance + 1) / 2; |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2253 |
} |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2254 |
|
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2255 |
params[index++] = distance; |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2256 |
if (heightdiff != 0) params[index++] = heightdiff; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2257 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2258 |
|
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2259 |
GuiShowTooltipsWithArgs(measure_strings_length[index], index, params); |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2260 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2261 |
|
0 | 2262 |
thd->selend.x = x; |
2263 |
thd->selend.y = y; |
|
2264 |
thd->next_drawstyle = b; |
|
2265 |
} |
|
2266 |
||
4799
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2267 |
/** |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2268 |
* Selects tiles while dragging |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2269 |
* @param x X coordinate of end of selection |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2270 |
* @param y Y coordinate of end of selection |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2271 |
* @param method modifies the way tiles are selected. Possible |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2272 |
* methods are VPM_* in viewport.h */ |
0 | 2273 |
void VpSelectTilesWithMethod(int x, int y, int method) |
2274 |
{ |
|
4799
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2275 |
int sx, sy; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2276 |
HighLightStyle style; |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2277 |
|
0 | 2278 |
if (x == -1) { |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2279 |
_thd.selend.x = -1; |
0 | 2280 |
return; |
2281 |
} |
|
2282 |
||
4799
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2283 |
/* Special handling of drag in any (8-way) direction */ |
58
b9fdcc9b5c90
(svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents:
0
diff
changeset
|
2284 |
if (method == VPM_RAILDIRS || method == VPM_SIGNALDIRS) { |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2285 |
_thd.selend.x = x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2286 |
_thd.selend.y = y; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2287 |
CalcRaildirsDrawstyle(&_thd, x, y, method); |
0 | 2288 |
return; |
2289 |
} |
|
2290 |
||
2116 | 2291 |
if (_thd.next_drawstyle == HT_POINT) { |
4799
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2292 |
x += TILE_SIZE / 2; |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2293 |
y += TILE_SIZE / 2; |
2116 | 2294 |
} |
0 | 2295 |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2296 |
sx = _thd.selstart.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2297 |
sy = _thd.selstart.y; |
0 | 2298 |
|
2116 | 2299 |
switch (method) { |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2300 |
case VPM_X_OR_Y: /* drag in X or Y direction */ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2301 |
if (myabs(sy - y) < myabs(sx - x)) { |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2302 |
y = sy; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2303 |
style = HT_DIR_X; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2304 |
} else { |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2305 |
x = sx; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2306 |
style = HT_DIR_Y; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2307 |
} |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2308 |
goto calc_heightdiff_single_direction; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2309 |
case VPM_FIX_X: /* drag in Y direction */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2310 |
x = sx; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2311 |
style = HT_DIR_Y; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2312 |
goto calc_heightdiff_single_direction; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2313 |
case VPM_FIX_Y: /* drag in X direction */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2314 |
y = sy; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2315 |
style = HT_DIR_X; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2316 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2317 |
calc_heightdiff_single_direction:; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2318 |
if (_patches.measure_tooltip) { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2319 |
TileIndex t0 = TileVirtXY(sx, sy); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2320 |
TileIndex t1 = TileVirtXY(x, y); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2321 |
uint distance = DistanceManhattan(t0, t1) + 1; |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2322 |
byte index = 0; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2323 |
uint params[2]; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2324 |
|
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2325 |
if (distance != 1) { |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2326 |
/* With current code passing a HT_LINE style to calculate the height |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2327 |
* difference is enough. However if/when a point-tool is created |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2328 |
* with this method, function should be called with new_style (below) |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2329 |
* instead of HT_LINE | style case HT_POINT is handled specially |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2330 |
* new_style := (_thd.next_drawstyle & HT_RECT) ? HT_LINE | style : _thd.next_drawstyle; */ |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2331 |
int heightdiff = CalcHeightdiff(HT_LINE | style, 0, t0, t1); |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2332 |
|
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2333 |
params[index++] = distance; |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2334 |
if (heightdiff != 0) params[index++] = heightdiff; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2335 |
} |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2336 |
|
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2337 |
GuiShowTooltipsWithArgs(measure_strings_length[index], index, params); |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2338 |
} break; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2339 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2340 |
case VPM_X_AND_Y_LIMITED: { /* drag an X by Y constrained rect area */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2341 |
int limit = (_thd.sizelimit - 1) * TILE_SIZE; |
2116 | 2342 |
x = sx + clamp(x - sx, -limit, limit); |
2343 |
y = sy + clamp(y - sy, -limit, limit); |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2344 |
} /* Fallthrough */ |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2345 |
case VPM_X_AND_Y: { /* drag an X by Y area */ |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2346 |
if (_patches.measure_tooltip) { |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2347 |
static const StringID measure_strings_area[] = { |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2348 |
STR_NULL, STR_NULL, STR_MEASURE_AREA, STR_MEASURE_AREA_HEIGHTDIFF |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2349 |
}; |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2350 |
|
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2351 |
TileIndex t0 = TileVirtXY(sx, sy); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2352 |
TileIndex t1 = TileVirtXY(x, y); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2353 |
uint dx = delta(TileX(t0), TileX(t1)) + 1; |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2354 |
uint dy = delta(TileY(t0), TileY(t1)) + 1; |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2355 |
byte index = 0; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2356 |
uint params[3]; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2357 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2358 |
/* If dragging an area (eg dynamite tool) and it is actually a single |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2359 |
* row/column, change the type to 'line' to get proper calculation for height */ |
4838
d7570b95d5f8
(svn r6764) -Fix (r6758): Wrong height difference calculated because invalid drag-type
Darkvater
parents:
4834
diff
changeset
|
2360 |
style = _thd.next_drawstyle; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2361 |
if (style & HT_RECT) { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2362 |
if (dx == 1) { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2363 |
style = HT_LINE | HT_DIR_Y; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2364 |
} else if (dy == 1) { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2365 |
style = HT_LINE | HT_DIR_X; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2366 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2367 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2368 |
|
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2369 |
if (dx != 1 || dy != 1) { |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2370 |
int heightdiff = CalcHeightdiff(style, 0, t0, t1); |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2371 |
|
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2372 |
params[index++] = dx; |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2373 |
params[index++] = dy; |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2374 |
if (heightdiff != 0) params[index++] = heightdiff; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2375 |
} |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2376 |
|
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2377 |
GuiShowTooltipsWithArgs(measure_strings_area[index], index, params); |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2378 |
} |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2379 |
break; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2380 |
|
2116 | 2381 |
} |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2382 |
default: NOT_REACHED(); |
0 | 2383 |
} |
2384 |
||
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2385 |
_thd.selend.x = x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2386 |
_thd.selend.y = y; |
0 | 2387 |
} |
2388 |
||
6307 | 2389 |
/** while dragging */ |
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
2390 |
bool VpHandlePlaceSizingDrag() |
0 | 2391 |
{ |
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
2392 |
BaseWindow *w; |
0 | 2393 |
WindowEvent e; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2394 |
|
2116 | 2395 |
if (_special_mouse_mode != WSM_SIZING) return true; |
0 | 2396 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
2397 |
e.we.place.userdata = _thd.userdata; |
0 | 2398 |
|
6307 | 2399 |
/* stop drag mode if the window has been closed */ |
6308 | 2400 |
w = BaseWindow::FindById(_thd.window_class, _thd.window_number); |
0 | 2401 |
if (w == NULL) { |
2402 |
ResetObjectToPlace(); |
|
2403 |
return false; |
|
2404 |
} |
|
2405 |
||
6307 | 2406 |
/* while dragging execute the drag procedure of the corresponding window (mostly VpSelectTilesWithMethod() ) */ |
0 | 2407 |
if (_left_button_down) { |
2408 |
e.event = WE_PLACE_DRAG; |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
2409 |
e.we.place.pt = GetTileBelowCursor(); |
0 | 2410 |
w->wndproc(w, &e); |
2411 |
return false; |
|
2412 |
} |
|
2413 |
||
6307 | 2414 |
/* mouse button released.. |
2415 |
* keep the selected tool, but reset it to the original mode. */ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2416 |
_special_mouse_mode = WSM_NONE; |
2116 | 2417 |
if (_thd.next_drawstyle == HT_RECT) { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2418 |
_thd.place_mode = VHM_RECT; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
2419 |
} else if ((e.we.place.userdata & 0xF) == VPM_SIGNALDIRS) { // some might call this a hack... -- Dominik |
2116 | 2420 |
_thd.place_mode = VHM_RECT; |
2421 |
} else if (_thd.next_drawstyle & HT_LINE) { |
|
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2422 |
_thd.place_mode = VHM_RAIL; |
2116 | 2423 |
} else if (_thd.next_drawstyle & HT_RAIL) { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2424 |
_thd.place_mode = VHM_RAIL; |
2116 | 2425 |
} else { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2426 |
_thd.place_mode = VHM_POINT; |
2116 | 2427 |
} |
0 | 2428 |
SetTileSelectSize(1, 1); |
2429 |
||
6307 | 2430 |
/* and call the mouseup event. */ |
0 | 2431 |
e.event = WE_PLACE_MOUSEUP; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
2432 |
e.we.place.pt = _thd.selend; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
2433 |
e.we.place.tile = TileVirtXY(e.we.place.pt.x, e.we.place.pt.y); |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
2434 |
e.we.place.starttile = TileVirtXY(_thd.selstart.x, _thd.selstart.y); |
0 | 2435 |
w->wndproc(w, &e); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2436 |
|
0 | 2437 |
return false; |
2438 |
} |
|
2439 |
||
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
2440 |
void SetObjectToPlaceWnd(CursorID icon, SpriteID pal, byte mode, BaseWindow *w) |
0 | 2441 |
{ |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
2442 |
SetObjectToPlace(icon, pal, mode, w->window_class, w->window_number); |
0 | 2443 |
} |
2444 |
||
2445 |
#include "table/animcursors.h" |
|
2446 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
2447 |
void SetObjectToPlace(CursorID icon, SpriteID pal, byte mode, WindowClass window_class, WindowNumber window_num) |
0 | 2448 |
{ |
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
2449 |
BaseWindow *w; |
0 | 2450 |
|
6307 | 2451 |
/* undo clicking on button */ |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2452 |
if (_thd.place_mode != 0) { |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2453 |
_thd.place_mode = 0; |
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
6246
diff
changeset
|
2454 |
w = BaseWindow::FindById(_thd.window_class, _thd.window_number); |
6245
6fa82c6ee8ca
(svn r8711) [cpp_gui] -Codechange: even more funktion->method conversions
bjarni
parents:
6244
diff
changeset
|
2455 |
if (w != NULL) w->CallEventNP(WE_ABORT_PLACE_OBJ); |
0 | 2456 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2457 |
|
0 | 2458 |
SetTileSelectSize(1, 1); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2459 |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2460 |
_thd.make_square_red = false; |
0 | 2461 |
|
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2462 |
if (mode == VHM_DRAG) { // mode 4 is for dragdropping trains in the depot window |
0 | 2463 |
mode = 0; |
2464 |
_special_mouse_mode = WSM_DRAGDROP; |
|
2465 |
} else { |
|
2466 |
_special_mouse_mode = WSM_NONE; |
|
2467 |
} |
|
2468 |
||
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2469 |
_thd.place_mode = mode; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2470 |
_thd.window_class = window_class; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2471 |
_thd.window_number = window_num; |
0 | 2472 |
|
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2473 |
if (mode == VHM_SPECIAL) // special tools, like tunnels or docks start with presizing mode |
0 | 2474 |
VpStartPreSizing(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2475 |
|
0 | 2476 |
if ( (int)icon < 0) |
4334
75322a204d0c
(svn r6035) -Revert r5900 which supposedly fixed an invalid warning caused by buggy MS software
Darkvater
parents:
4272
diff
changeset
|
2477 |
SetAnimatedMouseCursor(_animcursors[~icon]); |
0 | 2478 |
else |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5853
diff
changeset
|
2479 |
SetMouseCursor(icon, pal); |
0 | 2480 |
} |
2481 |
||
6298
c30fe89622df
(svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents:
6268
diff
changeset
|
2482 |
void ResetObjectToPlace() |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
2483 |
{ |
6144
5a0ffbf27ced
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5984
diff
changeset
|
2484 |
SetObjectToPlace(SPR_CURSOR_MOUSE, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0); |
0 | 2485 |
} |