author | tron |
Sat, 05 Aug 2006 16:57:39 +0000 | |
changeset 4226 | 10d7608f4c6c |
parent 4189 | fcc29d7b6722 |
child 4231 | 2823b3643862 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1864
diff
changeset
|
4 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1172
diff
changeset
|
5 |
#include "debug.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
6 |
#include "functions.h" |
2662
8b46824bd821
(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
|
7 |
#include "gui.h" |
1349
15979a2e9001
(svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents:
1309
diff
changeset
|
8 |
#include "spritecache.h" |
1309
4403a69da4f8
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1299
diff
changeset
|
9 |
#include "strings.h" |
1363
775a7ee52369
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1349
diff
changeset
|
10 |
#include "table/sprites.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
500
diff
changeset
|
11 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
657
diff
changeset
|
12 |
#include "map.h" |
0 | 13 |
#include "viewport.h" |
14 |
#include "window.h" |
|
15 |
#include "vehicle.h" |
|
16 |
#include "station.h" |
|
17 |
#include "gfx.h" |
|
18 |
#include "town.h" |
|
988
4304525d1b8b
(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
981
diff
changeset
|
19 |
#include "signs.h" |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
20 |
#include "waypoint.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2125
diff
changeset
|
21 |
#include "variables.h" |
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2662
diff
changeset
|
22 |
#include "train.h" |
0 | 23 |
|
133
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
24 |
#define VIEWPORT_DRAW_MEM (65536 * 2) |
0 | 25 |
|
26 |
static bool _added_tile_sprite; |
|
27 |
static bool _offset_ground_sprites; |
|
28 |
||
4186
6e55c6f0908b
(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
|
29 |
/* The in-game coordiante system looks like this * |
6e55c6f0908b
(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
|
30 |
* * |
6e55c6f0908b
(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
|
31 |
* ^ Z * |
6e55c6f0908b
(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
|
32 |
* | * |
6e55c6f0908b
(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
|
33 |
* | * |
6e55c6f0908b
(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
|
34 |
* | * |
6e55c6f0908b
(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
|
35 |
* | * |
6e55c6f0908b
(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
|
36 |
* / \ * |
6e55c6f0908b
(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 |
* / \ * |
6e55c6f0908b
(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 |
* / \ * |
6e55c6f0908b
(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 |
* / \ * |
6e55c6f0908b
(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 |
* X < > Y * |
6e55c6f0908b
(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 |
*/ |
6e55c6f0908b
(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 |
|
0 | 43 |
typedef struct StringSpriteToDraw { |
44 |
uint16 string; |
|
45 |
uint16 color; |
|
46 |
struct StringSpriteToDraw *next; |
|
849
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
47 |
int32 x; |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
48 |
int32 y; |
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
679
diff
changeset
|
49 |
uint32 params[3]; |
0 | 50 |
uint16 width; |
51 |
} StringSpriteToDraw; |
|
52 |
||
53 |
typedef struct TileSpriteToDraw { |
|
54 |
uint32 image; |
|
55 |
struct TileSpriteToDraw *next; |
|
849
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
56 |
int32 x; |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
57 |
int32 y; |
0 | 58 |
byte z; |
59 |
} TileSpriteToDraw; |
|
60 |
||
61 |
typedef struct ChildScreenSpriteToDraw { |
|
62 |
uint32 image; |
|
849
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
63 |
int32 x; |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
64 |
int32 y; |
0 | 65 |
struct ChildScreenSpriteToDraw *next; |
66 |
} ChildScreenSpriteToDraw; |
|
67 |
||
68 |
typedef struct ParentSpriteToDraw { |
|
69 |
uint32 image; |
|
849
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
70 |
int32 left; |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
71 |
int32 top; |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
72 |
int32 right; |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
73 |
int32 bottom; |
4186
6e55c6f0908b
(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
|
74 |
int32 xmin; |
6e55c6f0908b
(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
|
75 |
int32 ymin; |
6e55c6f0908b
(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
|
76 |
int32 xmax; |
6e55c6f0908b
(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
|
77 |
int32 ymax; |
0 | 78 |
ChildScreenSpriteToDraw *child; |
79 |
byte unk16; |
|
4186
6e55c6f0908b
(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
|
80 |
byte zmin; |
6e55c6f0908b
(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
|
81 |
byte zmax; |
0 | 82 |
} ParentSpriteToDraw; |
83 |
||
2109
545d8173eebe
(svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents:
2085
diff
changeset
|
84 |
// Quick hack to know how much memory to reserve when allocating from the spritelist |
545d8173eebe
(svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents:
2085
diff
changeset
|
85 |
// to prevent a buffer overflow. |
545d8173eebe
(svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents:
2085
diff
changeset
|
86 |
#define LARGEST_SPRITELIST_STRUCT ParentSpriteToDraw |
545d8173eebe
(svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents:
2085
diff
changeset
|
87 |
|
0 | 88 |
typedef struct ViewportDrawer { |
89 |
DrawPixelInfo dpi; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
90 |
|
2116 | 91 |
byte *spritelist_mem; |
92 |
const byte *eof_spritelist_mem; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
93 |
|
0 | 94 |
StringSpriteToDraw **last_string, *first_string; |
95 |
TileSpriteToDraw **last_tile, *first_tile; |
|
96 |
||
97 |
ChildScreenSpriteToDraw **last_child; |
|
98 |
||
99 |
ParentSpriteToDraw **parent_list; |
|
2116 | 100 |
ParentSpriteToDraw * const *eof_parent_list; |
0 | 101 |
|
102 |
byte combine_sprites; |
|
103 |
||
104 |
int offs_x, offs_y; // used when drawing ground sprites relative |
|
105 |
} ViewportDrawer; |
|
106 |
||
107 |
static ViewportDrawer *_cur_vd; |
|
108 |
||
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
109 |
TileHighlightData _thd; |
0 | 110 |
static TileInfo *_cur_ti; |
111 |
||
112 |
||
2116 | 113 |
static Point MapXYZToViewport(const ViewPort *vp, uint x, uint y, uint z) |
0 | 114 |
{ |
115 |
Point p = RemapCoords(x, y, z); |
|
2116 | 116 |
p.x -= vp->virtual_width / 2; |
117 |
p.y -= vp->virtual_height / 2; |
|
0 | 118 |
return p; |
119 |
} |
|
120 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
121 |
void AssignWindowViewport(Window *w, int x, int y, |
0 | 122 |
int width, int height, uint32 follow_flags, byte zoom) |
123 |
{ |
|
124 |
ViewPort *vp; |
|
125 |
Point pt; |
|
126 |
uint32 bit; |
|
127 |
||
2116 | 128 |
for (vp = _viewports, bit = 1; ; vp++, bit <<= 1) { |
129 |
assert(vp != endof(_viewports)); |
|
130 |
if (vp->width == 0) break; |
|
0 | 131 |
} |
132 |
_active_viewports |= bit; |
|
133 |
||
134 |
vp->left = x + w->left; |
|
135 |
vp->top = y + w->top; |
|
136 |
vp->width = width; |
|
137 |
vp->height = height; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
138 |
|
0 | 139 |
vp->zoom = zoom; |
140 |
||
141 |
vp->virtual_width = width << zoom; |
|
142 |
vp->virtual_height = height << zoom; |
|
143 |
||
144 |
if (follow_flags & 0x80000000) { |
|
2116 | 145 |
const Vehicle *veh; |
146 |
||
147 |
WP(w, vp_d).follow_vehicle = (VehicleID)(follow_flags & 0xFFFF); |
|
148 |
veh = GetVehicle(WP(w, vp_d).follow_vehicle); |
|
0 | 149 |
pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos); |
150 |
} else { |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
151 |
uint x = TileX(follow_flags) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
152 |
uint y = TileY(follow_flags) * TILE_SIZE; |
2116 | 153 |
|
154 |
WP(w, vp_d).follow_vehicle = INVALID_VEHICLE; |
|
155 |
pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y)); |
|
0 | 156 |
} |
157 |
||
2116 | 158 |
WP(w, vp_d).scrollpos_x = pt.x; |
159 |
WP(w, vp_d).scrollpos_y = pt.y; |
|
0 | 160 |
w->viewport = vp; |
161 |
vp->virtual_left = 0;//pt.x; |
|
162 |
vp->virtual_top = 0;//pt.y; |
|
163 |
} |
|
164 |
||
165 |
static Point _vp_move_offs; |
|
166 |
||
167 |
static void DoSetViewportPosition(Window *w, int left, int top, int width, int height) |
|
168 |
{ |
|
169 |
for (; w < _last_window; w++) { |
|
170 |
if (left + width > w->left && |
|
2116 | 171 |
w->left + w->width > left && |
0 | 172 |
top + height > w->top && |
2116 | 173 |
w->top + w->height > top) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
174 |
|
0 | 175 |
if (left < w->left) { |
176 |
DoSetViewportPosition(w, left, top, w->left - left, height); |
|
177 |
DoSetViewportPosition(w, left + (w->left - left), top, width - (w->left - left), height); |
|
178 |
return; |
|
179 |
} |
|
180 |
||
181 |
if (left + width > w->left + w->width) { |
|
182 |
DoSetViewportPosition(w, left, top, (w->left + w->width - left), height); |
|
183 |
DoSetViewportPosition(w, left + (w->left + w->width - left), top, width - (w->left + w->width - left) , height); |
|
184 |
return; |
|
185 |
} |
|
186 |
||
187 |
if (top < w->top) { |
|
188 |
DoSetViewportPosition(w, left, top, width, (w->top - top)); |
|
189 |
DoSetViewportPosition(w, left, top + (w->top - top), width, height - (w->top - top)); |
|
190 |
return; |
|
191 |
} |
|
192 |
||
193 |
if (top + height > w->top + w->height) { |
|
194 |
DoSetViewportPosition(w, left, top, width, (w->top + w->height - top)); |
|
195 |
DoSetViewportPosition(w, left, top + (w->top + w->height - top), width , height - (w->top + w->height - top)); |
|
196 |
return; |
|
197 |
} |
|
198 |
||
199 |
return; |
|
200 |
} |
|
201 |
} |
|
202 |
||
203 |
{ |
|
204 |
int xo = _vp_move_offs.x; |
|
205 |
int yo = _vp_move_offs.y; |
|
206 |
||
207 |
if (abs(xo) >= width || abs(yo) >= height) { |
|
208 |
/* fully_outside */ |
|
2116 | 209 |
RedrawScreenRect(left, top, left + width, top + height); |
0 | 210 |
return; |
211 |
} |
|
212 |
||
213 |
GfxScroll(left, top, width, height, xo, yo); |
|
214 |
||
215 |
if (xo > 0) { |
|
216 |
RedrawScreenRect(left, top, xo + left, top + height); |
|
217 |
left += xo; |
|
218 |
width -= xo; |
|
219 |
} else if (xo < 0) { |
|
220 |
RedrawScreenRect(left+width+xo, top, left+width, top + height); |
|
221 |
width += xo; |
|
222 |
} |
|
223 |
||
224 |
if (yo > 0) { |
|
225 |
RedrawScreenRect(left, top, width+left, top + yo); |
|
226 |
} else if (yo < 0) { |
|
227 |
RedrawScreenRect(left, top + height + yo, width+left, top + height); |
|
228 |
} |
|
229 |
} |
|
230 |
} |
|
231 |
||
4171 | 232 |
static void SetViewportPosition(Window *w, int x, int y) |
0 | 233 |
{ |
234 |
ViewPort *vp = w->viewport; |
|
235 |
int old_left = vp->virtual_left; |
|
236 |
int old_top = vp->virtual_top; |
|
237 |
int i; |
|
238 |
int left, top, width, height; |
|
239 |
||
240 |
vp->virtual_left = x; |
|
241 |
vp->virtual_top = y; |
|
242 |
||
243 |
old_left >>= vp->zoom; |
|
244 |
old_top >>= vp->zoom; |
|
245 |
x >>= vp->zoom; |
|
246 |
y >>= vp->zoom; |
|
247 |
||
248 |
old_left -= x; |
|
249 |
old_top -= y; |
|
250 |
||
2116 | 251 |
if (old_top == 0 && old_left == 0) return; |
0 | 252 |
|
253 |
_vp_move_offs.x = old_left; |
|
254 |
_vp_move_offs.y = old_top; |
|
255 |
||
256 |
left = vp->left; |
|
257 |
top = vp->top; |
|
258 |
width = vp->width; |
|
259 |
height = vp->height; |
|
260 |
||
261 |
if (left < 0) { |
|
262 |
width += left; |
|
263 |
left = 0; |
|
264 |
} |
|
265 |
||
2116 | 266 |
i = left + width - _screen.width; |
267 |
if (i >= 0) width -= i; |
|
0 | 268 |
|
269 |
if (width > 0) { |
|
270 |
if (top < 0) { |
|
271 |
height += top; |
|
272 |
top = 0; |
|
273 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
274 |
|
2116 | 275 |
i = top + height - _screen.height; |
276 |
if (i >= 0) height -= i; |
|
0 | 277 |
|
2116 | 278 |
if (height > 0) DoSetViewportPosition(w + 1, left, top, width, height); |
0 | 279 |
} |
280 |
} |
|
281 |
||
282 |
||
2116 | 283 |
ViewPort *IsPtInWindowViewport(const Window *w, int x, int y) |
0 | 284 |
{ |
285 |
ViewPort *vp = w->viewport; |
|
2116 | 286 |
|
0 | 287 |
if (vp != NULL && |
288 |
IS_INT_INSIDE(x, vp->left, vp->left + vp->width) && |
|
289 |
IS_INT_INSIDE(y, vp->top, vp->top + vp->height)) |
|
290 |
return vp; |
|
291 |
||
292 |
return NULL; |
|
293 |
} |
|
294 |
||
2116 | 295 |
static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y) |
1095 | 296 |
{ |
0 | 297 |
int z; |
298 |
Point pt; |
|
299 |
int a,b; |
|
300 |
||
301 |
if ( (uint)(x -= vp->left) >= (uint)vp->width || |
|
302 |
(uint)(y -= vp->top) >= (uint)vp->height) { |
|
303 |
Point pt = {-1, -1}; |
|
304 |
return pt; |
|
305 |
} |
|
306 |
||
307 |
x = ((x << vp->zoom) + vp->virtual_left) >> 2; |
|
308 |
y = ((y << vp->zoom) + vp->virtual_top) >> 1; |
|
309 |
||
310 |
#if !defined(NEW_ROTATION) |
|
311 |
a = y-x; |
|
312 |
b = y+x; |
|
313 |
#else |
|
314 |
a = x+y; |
|
315 |
b = x-y; |
|
316 |
#endif |
|
317 |
z = GetSlopeZ(a, b) >> 1; |
|
318 |
z = GetSlopeZ(a+z, b+z) >> 1; |
|
319 |
z = GetSlopeZ(a+z, b+z) >> 1; |
|
320 |
z = GetSlopeZ(a+z, b+z) >> 1; |
|
321 |
z = GetSlopeZ(a+z, b+z) >> 1; |
|
322 |
||
323 |
pt.x = a+z; |
|
324 |
pt.y = b+z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
325 |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
326 |
if ((uint)pt.x >= MapMaxX() * TILE_SIZE || (uint)pt.y >= MapMaxY() * TILE_SIZE) { |
0 | 327 |
pt.x = pt.y = -1; |
328 |
} |
|
329 |
||
330 |
return pt; |
|
331 |
} |
|
332 |
||
981
f74abee65b7b
(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
|
333 |
/* When used for zooming, check area below current coordinates (x,y) |
f74abee65b7b
(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
|
334 |
* and return the tile of the zoomed out/in position (zoom_x, zoom_y) |
f74abee65b7b
(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
|
335 |
* when you just want the tile, make x = zoom_x and y = zoom_y */ |
f74abee65b7b
(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
|
336 |
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
|
337 |
{ |
0 | 338 |
Window *w; |
339 |
ViewPort *vp; |
|
340 |
Point pt; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
341 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
342 |
if ( (w = FindWindowFromPt(x, y)) != NULL && |
0 | 343 |
(vp = IsPtInWindowViewport(w, x, y)) != NULL) |
981
f74abee65b7b
(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
|
344 |
return TranslateXYToTileCoord(vp, zoom_x, zoom_y); |
0 | 345 |
|
346 |
pt.y = pt.x = -1; |
|
347 |
return pt; |
|
348 |
} |
|
349 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
350 |
Point GetTileBelowCursor(void) |
0 | 351 |
{ |
981
f74abee65b7b
(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
|
352 |
return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, _cursor.pos.x, _cursor.pos.y); |
0 | 353 |
} |
354 |
||
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
|
355 |
|
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
|
356 |
Point GetTileZoomCenterWindow(bool in, Window * w) |
0 | 357 |
{ |
358 |
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
|
359 |
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
|
360 |
|
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
|
361 |
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
|
362 |
|
2026 | 363 |
if (in) { |
2116 | 364 |
x = ((_cursor.pos.x - vp->left) >> 1) + (vp->width >> 2); |
365 |
y = ((_cursor.pos.y - vp->top) >> 1) + (vp->height >> 2); |
|
366 |
} 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
|
367 |
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
|
368 |
y = vp->height - (_cursor.pos.y - vp->top); |
0 | 369 |
} |
981
f74abee65b7b
(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
|
370 |
/* Get the tile below the cursor and center on the zoomed-out center */ |
f74abee65b7b
(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 GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, x + vp->left, y + vp->top); |
0 | 372 |
} |
373 |
||
849
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
374 |
void DrawGroundSpriteAt(uint32 image, int32 x, int32 y, byte z) |
0 | 375 |
{ |
376 |
ViewportDrawer *vd = _cur_vd; |
|
377 |
TileSpriteToDraw *ts; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
378 |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
379 |
assert((image & SPRITE_MASK) < MAX_SPRITES); |
0 | 380 |
|
2116 | 381 |
if (vd->spritelist_mem >= vd->eof_spritelist_mem) { |
2013
c83b52340eee
(svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents:
1990
diff
changeset
|
382 |
DEBUG(misc, 0) ("Out of sprite mem"); |
0 | 383 |
return; |
384 |
} |
|
2116 | 385 |
ts = (TileSpriteToDraw*)vd->spritelist_mem; |
0 | 386 |
|
387 |
vd->spritelist_mem += sizeof(TileSpriteToDraw); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
388 |
|
0 | 389 |
ts->image = image; |
390 |
ts->next = NULL; |
|
391 |
ts->x = x; |
|
392 |
ts->y = y; |
|
393 |
ts->z = z; |
|
394 |
*vd->last_tile = ts; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
395 |
vd->last_tile = &ts->next; |
0 | 396 |
} |
397 |
||
398 |
void DrawGroundSprite(uint32 image) |
|
399 |
{ |
|
400 |
if (_offset_ground_sprites) { |
|
401 |
// offset ground sprite because of foundation? |
|
402 |
AddChildSpriteScreen(image, _cur_vd->offs_x, _cur_vd->offs_y); |
|
403 |
} else { |
|
1083
8e64dc3ed29f
(svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents:
1070
diff
changeset
|
404 |
_added_tile_sprite = true; |
0 | 405 |
DrawGroundSpriteAt(image, _cur_ti->x, _cur_ti->y, _cur_ti->z); |
406 |
} |
|
407 |
} |
|
408 |
||
409 |
||
410 |
void OffsetGroundSprite(int x, int y) |
|
411 |
{ |
|
412 |
_cur_vd->offs_x = x; |
|
413 |
_cur_vd->offs_y = y; |
|
414 |
_offset_ground_sprites = true; |
|
415 |
} |
|
416 |
||
417 |
static void AddCombinedSprite(uint32 image, int x, int y, byte z) |
|
418 |
{ |
|
2116 | 419 |
const ViewportDrawer *vd = _cur_vd; |
0 | 420 |
Point pt = RemapCoords(x, y, z); |
2319
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
421 |
const Sprite* spr = GetSprite(image & SPRITE_MASK); |
0 | 422 |
|
2319
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
423 |
if (pt.x + spr->x_offs >= vd->dpi.left + vd->dpi.width || |
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
424 |
pt.x + spr->x_offs + spr->width <= vd->dpi.left || |
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
425 |
pt.y + spr->y_offs >= vd->dpi.top + vd->dpi.height || |
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
426 |
pt.y + spr->y_offs + spr->height <= vd->dpi.top) |
0 | 427 |
return; |
428 |
||
2116 | 429 |
AddChildSpriteScreen(image, pt.x - vd->parent_list[-1]->left, pt.y - vd->parent_list[-1]->top); |
0 | 430 |
} |
431 |
||
432 |
||
433 |
void AddSortableSpriteToDraw(uint32 image, int x, int y, int w, int h, byte dz, byte z) |
|
434 |
{ |
|
435 |
ViewportDrawer *vd = _cur_vd; |
|
436 |
ParentSpriteToDraw *ps; |
|
4171 | 437 |
const Sprite *spr; |
0 | 438 |
Point pt; |
439 |
||
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
440 |
assert((image & SPRITE_MASK) < MAX_SPRITES); |
0 | 441 |
|
442 |
if (vd->combine_sprites == 2) { |
|
443 |
AddCombinedSprite(image, x, y, z); |
|
444 |
return; |
|
445 |
} |
|
446 |
||
447 |
vd->last_child = NULL; |
|
448 |
||
2116 | 449 |
if (vd->spritelist_mem >= vd->eof_spritelist_mem) { |
2013
c83b52340eee
(svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents:
1990
diff
changeset
|
450 |
DEBUG(misc, 0) ("Out of sprite mem"); |
0 | 451 |
return; |
452 |
} |
|
2116 | 453 |
ps = (ParentSpriteToDraw*)vd->spritelist_mem; |
454 |
||
133
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
455 |
if (vd->parent_list >= vd->eof_parent_list) { |
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
456 |
// This can happen rarely, mostly when you zoom out completely |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
457 |
// and have a lot of stuff that moves (and is added to the |
133
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
458 |
// sort-list, this function). To solve it, increase |
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
459 |
// parent_list somewhere below to a higher number. |
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
460 |
// This can not really hurt you, it just gives some black |
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
461 |
// spots on the screen ;) |
2013
c83b52340eee
(svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents:
1990
diff
changeset
|
462 |
DEBUG(misc, 0) ("Out of sprite mem (parent_list)"); |
133
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
463 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
464 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
465 |
|
4189
fcc29d7b6722
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
466 |
pt = RemapCoords(x, y, z); |
fcc29d7b6722
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
467 |
spr = GetSprite(image & SPRITE_MASK); |
fcc29d7b6722
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
468 |
if ((ps->left = (pt.x += spr->x_offs)) >= vd->dpi.left + vd->dpi.width || |
fcc29d7b6722
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
469 |
(ps->right = (pt.x + spr->width )) <= vd->dpi.left || |
fcc29d7b6722
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
470 |
(ps->top = (pt.y += spr->y_offs)) >= vd->dpi.top + vd->dpi.height || |
fcc29d7b6722
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
471 |
(ps->bottom = (pt.y + spr->height)) <= vd->dpi.top) { |
fcc29d7b6722
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
472 |
return; |
fcc29d7b6722
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
473 |
} |
fcc29d7b6722
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
474 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
475 |
vd->spritelist_mem += sizeof(ParentSpriteToDraw); |
0 | 476 |
|
477 |
ps->image = image; |
|
4186
6e55c6f0908b
(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
|
478 |
ps->xmin = x; |
6e55c6f0908b
(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
|
479 |
ps->xmax = x + w - 1; |
0 | 480 |
|
4186
6e55c6f0908b
(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
|
481 |
ps->ymin = y; |
6e55c6f0908b
(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
|
482 |
ps->ymax = y + h - 1; |
0 | 483 |
|
4186
6e55c6f0908b
(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
|
484 |
ps->zmin = z; |
6e55c6f0908b
(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
|
485 |
ps->zmax = z + dz - 1; |
0 | 486 |
|
487 |
ps->unk16 = 0; |
|
488 |
ps->child = NULL; |
|
489 |
vd->last_child = &ps->child; |
|
490 |
||
491 |
*vd->parent_list++ = ps; |
|
492 |
||
2116 | 493 |
if (vd->combine_sprites == 1) vd->combine_sprites = 2; |
0 | 494 |
} |
495 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
496 |
void StartSpriteCombine(void) |
0 | 497 |
{ |
498 |
_cur_vd->combine_sprites = 1; |
|
499 |
} |
|
500 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
501 |
void EndSpriteCombine(void) |
0 | 502 |
{ |
503 |
_cur_vd->combine_sprites = 0; |
|
504 |
} |
|
505 |
||
506 |
void AddChildSpriteScreen(uint32 image, int x, int y) |
|
507 |
{ |
|
508 |
ViewportDrawer *vd = _cur_vd; |
|
509 |
ChildScreenSpriteToDraw *cs; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
510 |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
511 |
assert((image & SPRITE_MASK) < MAX_SPRITES); |
0 | 512 |
|
2116 | 513 |
if (vd->spritelist_mem >= vd->eof_spritelist_mem) { |
2013
c83b52340eee
(svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents:
1990
diff
changeset
|
514 |
DEBUG(misc, 0) ("Out of sprite mem"); |
0 | 515 |
return; |
516 |
} |
|
2116 | 517 |
cs = (ChildScreenSpriteToDraw*)vd->spritelist_mem; |
0 | 518 |
|
2116 | 519 |
if (vd->last_child == NULL) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
520 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
521 |
vd->spritelist_mem += sizeof(ChildScreenSpriteToDraw); |
0 | 522 |
|
523 |
*vd->last_child = cs; |
|
524 |
vd->last_child = &cs->next; |
|
525 |
||
526 |
cs->image = image; |
|
527 |
cs->x = x; |
|
528 |
cs->y = y; |
|
529 |
cs->next = NULL; |
|
530 |
} |
|
531 |
||
532 |
/* Returns a StringSpriteToDraw */ |
|
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
679
diff
changeset
|
533 |
void *AddStringToDraw(int x, int y, StringID string, uint32 params_1, uint32 params_2, uint32 params_3) |
0 | 534 |
{ |
535 |
ViewportDrawer *vd = _cur_vd; |
|
536 |
StringSpriteToDraw *ss; |
|
537 |
||
2116 | 538 |
if (vd->spritelist_mem >= vd->eof_spritelist_mem) { |
2013
c83b52340eee
(svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents:
1990
diff
changeset
|
539 |
DEBUG(misc, 0) ("Out of sprite mem"); |
0 | 540 |
return NULL; |
541 |
} |
|
2116 | 542 |
ss = (StringSpriteToDraw*)vd->spritelist_mem; |
0 | 543 |
|
544 |
vd->spritelist_mem += sizeof(StringSpriteToDraw); |
|
545 |
||
546 |
ss->string = string; |
|
547 |
ss->next = NULL; |
|
548 |
ss->x = x; |
|
549 |
ss->y = y; |
|
550 |
ss->params[0] = params_1; |
|
551 |
ss->params[1] = params_2; |
|
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
679
diff
changeset
|
552 |
ss->params[2] = params_3; |
0 | 553 |
ss->width = 0; |
554 |
||
555 |
*vd->last_string = ss; |
|
556 |
vd->last_string = &ss->next; |
|
557 |
||
558 |
return ss; |
|
559 |
} |
|
560 |
||
4000
4009d092b306
(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
|
561 |
|
0 | 562 |
static void DrawSelectionSprite(uint32 image, const TileInfo *ti) |
563 |
{ |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
564 |
if (_added_tile_sprite && !(_thd.drawstyle & HT_LINE)) { // draw on real ground |
1083
8e64dc3ed29f
(svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents:
1070
diff
changeset
|
565 |
DrawGroundSpriteAt(image, ti->x, ti->y, ti->z + 7); |
8e64dc3ed29f
(svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents:
1070
diff
changeset
|
566 |
} else { // draw on top of foundation |
8e64dc3ed29f
(svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents:
1070
diff
changeset
|
567 |
AddSortableSpriteToDraw(image, ti->x, ti->y, 0x10, 0x10, 1, ti->z + 7); |
8e64dc3ed29f
(svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents:
1070
diff
changeset
|
568 |
} |
0 | 569 |
} |
570 |
||
571 |
static bool IsPartOfAutoLine(int px, int py) |
|
572 |
{ |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
573 |
px -= _thd.selstart.x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
574 |
py -= _thd.selstart.y; |
0 | 575 |
|
2952 | 576 |
switch (_thd.drawstyle) { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
577 |
case HT_LINE | HT_DIR_X: return py == 0; // x direction |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
578 |
case HT_LINE | HT_DIR_Y: return px == 0; // y direction |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
579 |
case HT_LINE | HT_DIR_HU: return px == -py || px == -py - 16; // horizontal upper |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
580 |
case HT_LINE | HT_DIR_HL: return px == -py || px == -py + 16; // horizontal lower |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
581 |
case HT_LINE | HT_DIR_VL: return px == py || px == py + 16; // vertival left |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
582 |
case HT_LINE | HT_DIR_VR: return px == py || px == py - 16; // vertical right |
0 | 583 |
default: |
584 |
NOT_REACHED(); |
|
585 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
586 |
|
0 | 587 |
/* useless, but avoids compiler warning this way */ |
588 |
return 0; |
|
589 |
} |
|
590 |
||
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
591 |
// [direction][side] |
2710
44278abd3ef9
(svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents:
2676
diff
changeset
|
592 |
static const int _AutorailType[6][2] = { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
593 |
{ HT_DIR_X, HT_DIR_X }, |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
594 |
{ HT_DIR_Y, HT_DIR_Y }, |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
595 |
{ HT_DIR_HU, HT_DIR_HL }, |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
596 |
{ HT_DIR_HL, HT_DIR_HU }, |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
597 |
{ HT_DIR_VL, HT_DIR_VR }, |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
598 |
{ HT_DIR_VR, HT_DIR_VL } |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
599 |
}; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
600 |
|
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
601 |
#include "table/autorail.h" |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
602 |
|
0 | 603 |
static void DrawTileSelection(const TileInfo *ti) |
604 |
{ |
|
605 |
uint32 image; |
|
606 |
||
607 |
// Draw a red error square? |
|
3281
757d7da49445
(svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents:
3279
diff
changeset
|
608 |
if (_thd.redsq != 0 && _thd.redsq == ti->tile) { |
1864
80e13d54b061
(svn r2370) Replace some magic numbers with symbolic names
tron
parents:
1863
diff
changeset
|
609 |
DrawSelectionSprite(PALETTE_TILE_RED_PULSATING | (SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh]), ti); |
0 | 610 |
return; |
611 |
} |
|
612 |
||
613 |
// no selection active? |
|
2116 | 614 |
if (_thd.drawstyle == 0) return; |
0 | 615 |
|
616 |
// Inside the inner area? |
|
2116 | 617 |
if (IS_INSIDE_1D(ti->x, _thd.pos.x, _thd.size.x) && |
618 |
IS_INSIDE_1D(ti->y, _thd.pos.y, _thd.size.y)) { |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
619 |
if (_thd.drawstyle & HT_RECT) { |
1864
80e13d54b061
(svn r2370) Replace some magic numbers with symbolic names
tron
parents:
1863
diff
changeset
|
620 |
image = SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh]; |
80e13d54b061
(svn r2370) Replace some magic numbers with symbolic names
tron
parents:
1863
diff
changeset
|
621 |
if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED; |
0 | 622 |
DrawSelectionSprite(image, ti); |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
623 |
} else if (_thd.drawstyle & HT_POINT) { |
0 | 624 |
// Figure out the Z coordinate for the single dot. |
625 |
byte z = ti->z; |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3609
diff
changeset
|
626 |
if (ti->tileh & SLOPE_N) { |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
627 |
z += TILE_HEIGHT; |
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
628 |
if (ti->tileh == SLOPE_STEEP_N) z += TILE_HEIGHT; |
0 | 629 |
} |
1864
80e13d54b061
(svn r2370) Replace some magic numbers with symbolic names
tron
parents:
1863
diff
changeset
|
630 |
DrawGroundSpriteAt(_cur_dpi->zoom != 2 ? SPR_DOT : SPR_DOT_SMALL, ti->x, ti->y, z); |
2116 | 631 |
} else if (_thd.drawstyle & HT_RAIL /*&& _thd.place_mode == VHM_RAIL*/) { |
632 |
// autorail highlight piece under cursor |
|
633 |
uint type = _thd.drawstyle & 0xF; |
|
634 |
assert(type <= 5); |
|
2710
44278abd3ef9
(svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents:
2676
diff
changeset
|
635 |
image = SPR_AUTORAIL_BASE + _AutorailTilehSprite[ti->tileh][_AutorailType[type][0]]; |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
636 |
|
1864
80e13d54b061
(svn r2370) Replace some magic numbers with symbolic names
tron
parents:
1863
diff
changeset
|
637 |
if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED; |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
638 |
DrawSelectionSprite(image, ti); |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
639 |
|
2116 | 640 |
} else if (IsPartOfAutoLine(ti->x, ti->y)) { |
641 |
// autorail highlighting long line |
|
642 |
int dir = _thd.drawstyle & ~0xF0; |
|
643 |
uint side; |
|
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
644 |
|
2116 | 645 |
if (dir < 2) { |
646 |
side = 0; |
|
647 |
} else { |
|
648 |
TileIndex start = TileVirtXY(_thd.selstart.x, _thd.selstart.y); |
|
649 |
int diffx = myabs(TileX(start) - TileX(ti->tile)); |
|
650 |
int diffy = myabs(TileY(start) - TileY(ti->tile)); |
|
651 |
side = myabs(diffx - diffy); |
|
652 |
} |
|
1109
ecb98f43ba2c
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
653 |
|
2710
44278abd3ef9
(svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents:
2676
diff
changeset
|
654 |
image = SPR_AUTORAIL_BASE + _AutorailTilehSprite[ti->tileh][_AutorailType[dir][side]]; |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
655 |
|
2116 | 656 |
if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED; |
657 |
DrawSelectionSprite(image, ti); |
|
658 |
} |
|
0 | 659 |
return; |
660 |
} |
|
661 |
||
662 |
// Check if it's inside the outer area? |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
663 |
if (_thd.outersize.x && |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
664 |
_thd.size.x < _thd.size.x + _thd.outersize.x && |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
665 |
IS_INSIDE_1D(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) && |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
666 |
IS_INSIDE_1D(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) { |
0 | 667 |
// Draw a blue rect. |
1864
80e13d54b061
(svn r2370) Replace some magic numbers with symbolic names
tron
parents:
1863
diff
changeset
|
668 |
DrawSelectionSprite(PALETTE_SEL_TILE_BLUE | (SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh]), ti); |
0 | 669 |
return; |
670 |
} |
|
671 |
} |
|
672 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
673 |
static void ViewportAddLandscape(void) |
0 | 674 |
{ |
675 |
ViewportDrawer *vd = _cur_vd; |
|
676 |
int x, y, width, height; |
|
677 |
TileInfo ti; |
|
678 |
bool direction; |
|
679 |
||
680 |
_cur_ti = &ti; |
|
681 |
||
682 |
// Transform into tile coordinates and round to closest full tile |
|
683 |
#if !defined(NEW_ROTATION) |
|
684 |
x = ((vd->dpi.top >> 1) - (vd->dpi.left >> 2)) & ~0xF; |
|
685 |
y = ((vd->dpi.top >> 1) + (vd->dpi.left >> 2) - 0x10) & ~0xF; |
|
686 |
#else |
|
687 |
x = ((vd->dpi.top >> 1) + (vd->dpi.left >> 2) - 0x10) & ~0xF; |
|
688 |
y = ((vd->dpi.left >> 2) - (vd->dpi.top >> 1)) & ~0xF; |
|
689 |
#endif |
|
690 |
// determine size of area |
|
691 |
{ |
|
692 |
Point pt = RemapCoords(x, y, 241); |
|
693 |
width = (vd->dpi.left + vd->dpi.width - pt.x + 95) >> 6; |
|
694 |
height = (vd->dpi.top + vd->dpi.height - pt.y) >> 5 << 1; |
|
695 |
} |
|
696 |
||
697 |
assert(width > 0); |
|
698 |
assert(height > 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
699 |
|
0 | 700 |
direction = false; |
701 |
||
702 |
do { |
|
703 |
int width_cur = width; |
|
704 |
int x_cur = x; |
|
705 |
int y_cur = y; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
706 |
|
0 | 707 |
do { |
708 |
FindLandscapeHeight(&ti, x_cur, y_cur); |
|
709 |
#if !defined(NEW_ROTATION) |
|
710 |
y_cur += 0x10; |
|
711 |
x_cur -= 0x10; |
|
712 |
#else |
|
713 |
y_cur += 0x10; |
|
714 |
x_cur += 0x10; |
|
715 |
#endif |
|
716 |
_added_tile_sprite = false; |
|
717 |
_offset_ground_sprites = false; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
718 |
|
0 | 719 |
DrawTile(&ti); |
720 |
DrawTileSelection(&ti); |
|
721 |
} while (--width_cur); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
722 |
|
0 | 723 |
#if !defined(NEW_ROTATION) |
724 |
if ( (direction^=1) != 0) |
|
725 |
y += 0x10; |
|
726 |
else |
|
727 |
x += 0x10; |
|
728 |
#else |
|
729 |
if ( (direction^=1) != 0) |
|
730 |
x += 0x10; |
|
731 |
else |
|
732 |
y -= 0x10; |
|
733 |
#endif |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
734 |
} while (--height); |
0 | 735 |
} |
736 |
||
737 |
||
410 | 738 |
static void ViewportAddTownNames(DrawPixelInfo *dpi) |
0 | 739 |
{ |
740 |
Town *t; |
|
741 |
int left, top, right, bottom; |
|
742 |
||
743 |
if (!(_display_opt & DO_SHOW_TOWN_NAMES) || _game_mode == GM_MENU) |
|
744 |
return; |
|
745 |
||
746 |
left = dpi->left; |
|
747 |
top = dpi->top; |
|
748 |
right = left + dpi->width; |
|
749 |
bottom = top + dpi->height; |
|
750 |
||
751 |
if (dpi->zoom < 1) { |
|
752 |
FOR_ALL_TOWNS(t) { |
|
753 |
if (t->xy && |
|
754 |
bottom > t->sign.top && |
|
755 |
top < t->sign.top + 12 && |
|
756 |
right > t->sign.left && |
|
757 |
left < t->sign.left + t->sign.width_1) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
758 |
|
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2026
diff
changeset
|
759 |
AddStringToDraw(t->sign.left + 1, t->sign.top + 1, |
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2026
diff
changeset
|
760 |
_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL, |
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2026
diff
changeset
|
761 |
t->index, t->population, 0); |
0 | 762 |
} |
763 |
} |
|
764 |
} else if (dpi->zoom == 1) { |
|
765 |
right += 2; |
|
766 |
bottom += 2; |
|
767 |
||
768 |
FOR_ALL_TOWNS(t) { |
|
769 |
if (t->xy && |
|
770 |
bottom > t->sign.top && |
|
771 |
top < t->sign.top + 24 && |
|
772 |
right > t->sign.left && |
|
773 |
left < t->sign.left + t->sign.width_1*2) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
774 |
|
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2026
diff
changeset
|
775 |
AddStringToDraw(t->sign.left + 1, t->sign.top + 1, |
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2026
diff
changeset
|
776 |
_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL, |
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2026
diff
changeset
|
777 |
t->index, t->population, 0); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
778 |
} |
0 | 779 |
} |
780 |
} else { |
|
781 |
right += 4; |
|
782 |
bottom += 5; |
|
783 |
||
784 |
assert(dpi->zoom == 2); |
|
785 |
FOR_ALL_TOWNS(t) { |
|
786 |
if (t->xy && |
|
787 |
bottom > t->sign.top && |
|
788 |
top < t->sign.top + 24 && |
|
789 |
right > t->sign.left && |
|
790 |
left < t->sign.left + t->sign.width_2*4) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
791 |
|
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2026
diff
changeset
|
792 |
AddStringToDraw(t->sign.left + 5, t->sign.top + 1, STR_TOWN_LABEL_TINY_BLACK, t->index, 0, 0); |
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2026
diff
changeset
|
793 |
AddStringToDraw(t->sign.left + 1, t->sign.top - 3, STR_TOWN_LABEL_TINY_WHITE, t->index, 0, 0); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
794 |
} |
0 | 795 |
} |
796 |
} |
|
797 |
} |
|
798 |
||
410 | 799 |
static void ViewportAddStationNames(DrawPixelInfo *dpi) |
0 | 800 |
{ |
801 |
int left, top, right, bottom; |
|
802 |
Station *st; |
|
803 |
StringSpriteToDraw *sstd; |
|
804 |
||
805 |
if (!(_display_opt & DO_SHOW_STATION_NAMES) || _game_mode == GM_MENU) |
|
806 |
return; |
|
807 |
||
808 |
left = dpi->left; |
|
809 |
top = dpi->top; |
|
810 |
right = left + dpi->width; |
|
811 |
bottom = top + dpi->height; |
|
812 |
||
813 |
if (dpi->zoom < 1) { |
|
814 |
FOR_ALL_STATIONS(st) { |
|
815 |
if (st->xy && |
|
816 |
bottom > st->sign.top && |
|
817 |
top < st->sign.top + 12 && |
|
818 |
right > st->sign.left && |
|
819 |
left < st->sign.left + st->sign.width_1) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
820 |
|
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
679
diff
changeset
|
821 |
sstd=AddStringToDraw(st->sign.left + 1, st->sign.top + 1, STR_305C_0, st->index, st->facilities, 0); |
0 | 822 |
if (sstd != NULL) { |
823 |
sstd->color = (st->owner == OWNER_NONE || !st->facilities) ? 0xE : _player_colors[st->owner]; |
|
824 |
sstd->width = st->sign.width_1; |
|
825 |
} |
|
826 |
} |
|
827 |
} |
|
828 |
} else if (dpi->zoom == 1) { |
|
829 |
right += 2; |
|
830 |
bottom += 2; |
|
831 |
||
832 |
FOR_ALL_STATIONS(st) { |
|
833 |
if (st->xy && |
|
834 |
bottom > st->sign.top && |
|
835 |
top < st->sign.top + 24 && |
|
836 |
right > st->sign.left && |
|
837 |
left < st->sign.left + st->sign.width_1*2) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
838 |
|
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
679
diff
changeset
|
839 |
sstd=AddStringToDraw(st->sign.left + 1, st->sign.top + 1, STR_305C_0, st->index, st->facilities, 0); |
0 | 840 |
if (sstd != NULL) { |
841 |
sstd->color = (st->owner == OWNER_NONE || !st->facilities) ? 0xE : _player_colors[st->owner]; |
|
842 |
sstd->width = st->sign.width_1; |
|
843 |
} |
|
844 |
} |
|
845 |
} |
|
846 |
||
847 |
} else { |
|
848 |
assert(dpi->zoom == 2); |
|
849 |
||
850 |
right += 4; |
|
851 |
bottom += 5; |
|
852 |
||
853 |
FOR_ALL_STATIONS(st) { |
|
854 |
if (st->xy && |
|
855 |
bottom > st->sign.top && |
|
856 |
top < st->sign.top + 24 && |
|
857 |
right > st->sign.left && |
|
858 |
left < st->sign.left + st->sign.width_2*4) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
859 |
|
1964
6f9acf485026
(svn r2470) - Fix: Display station signs correctly in smallest zoom level in transparent buildings or tranparant station signs mode. (Peter1138)
hackykid
parents:
1959
diff
changeset
|
860 |
sstd=AddStringToDraw(st->sign.left + 1, st->sign.top + 1, STR_STATION_SIGN_TINY, st->index, st->facilities, 0); |
0 | 861 |
if (sstd != NULL) { |
862 |
sstd->color = (st->owner == OWNER_NONE || !st->facilities) ? 0xE : _player_colors[st->owner]; |
|
863 |
sstd->width = st->sign.width_2 | 0x8000; |
|
864 |
} |
|
865 |
} |
|
866 |
} |
|
867 |
} |
|
868 |
} |
|
869 |
||
410 | 870 |
static void ViewportAddSigns(DrawPixelInfo *dpi) |
0 | 871 |
{ |
872 |
SignStruct *ss; |
|
873 |
int left, top, right, bottom; |
|
874 |
StringSpriteToDraw *sstd; |
|
875 |
||
876 |
if (!(_display_opt & DO_SHOW_SIGNS)) |
|
877 |
return; |
|
878 |
||
879 |
left = dpi->left; |
|
880 |
top = dpi->top; |
|
881 |
right = left + dpi->width; |
|
882 |
bottom = top + dpi->height; |
|
883 |
||
884 |
if (dpi->zoom < 1) { |
|
988
4304525d1b8b
(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
981
diff
changeset
|
885 |
FOR_ALL_SIGNS(ss) { |
0 | 886 |
if (ss->str && |
887 |
bottom > ss->sign.top && |
|
888 |
top < ss->sign.top + 12 && |
|
889 |
right > ss->sign.left && |
|
890 |
left < ss->sign.left + ss->sign.width_1) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
891 |
|
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
679
diff
changeset
|
892 |
sstd=AddStringToDraw(ss->sign.left + 1, ss->sign.top + 1, STR_2806, ss->str, 0, 0); |
0 | 893 |
if (sstd != NULL) { |
894 |
sstd->width = ss->sign.width_1; |
|
1165
8fa7d3e235c6
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1109
diff
changeset
|
895 |
sstd->color = (ss->owner==OWNER_NONE)?14:_player_colors[ss->owner]; |
0 | 896 |
} |
897 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
898 |
} |
0 | 899 |
} else if (dpi->zoom == 1) { |
900 |
right += 2; |
|
901 |
bottom += 2; |
|
988
4304525d1b8b
(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
981
diff
changeset
|
902 |
FOR_ALL_SIGNS(ss) { |
0 | 903 |
if (ss->str && |
904 |
bottom > ss->sign.top && |
|
905 |
top < ss->sign.top + 24 && |
|
906 |
right > ss->sign.left && |
|
907 |
left < ss->sign.left + ss->sign.width_1*2) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
908 |
|
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
679
diff
changeset
|
909 |
sstd=AddStringToDraw(ss->sign.left + 1, ss->sign.top + 1, STR_2806, ss->str, 0, 0); |
0 | 910 |
if (sstd != NULL) { |
911 |
sstd->width = ss->sign.width_1; |
|
1172
01e589b4a31f
(svn r1674) - Fix: Signs are now displayed in the correct color at all zoom levels
dominik
parents:
1165
diff
changeset
|
912 |
sstd->color = (ss->owner==OWNER_NONE)?14:_player_colors[ss->owner]; |
0 | 913 |
} |
914 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
915 |
} |
0 | 916 |
} else { |
917 |
right += 4; |
|
918 |
bottom += 5; |
|
919 |
||
988
4304525d1b8b
(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
981
diff
changeset
|
920 |
FOR_ALL_SIGNS(ss) { |
0 | 921 |
if (ss->str && |
922 |
bottom > ss->sign.top && |
|
923 |
top < ss->sign.top + 24 && |
|
924 |
right > ss->sign.left && |
|
925 |
left < ss->sign.left + ss->sign.width_2*4) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
926 |
|
1172
01e589b4a31f
(svn r1674) - Fix: Signs are now displayed in the correct color at all zoom levels
dominik
parents:
1165
diff
changeset
|
927 |
sstd=AddStringToDraw(ss->sign.left + 1, ss->sign.top + 1, STR_2002, ss->str, 0, 0); |
0 | 928 |
if (sstd != NULL) { |
929 |
sstd->width = ss->sign.width_2 | 0x8000; |
|
1172
01e589b4a31f
(svn r1674) - Fix: Signs are now displayed in the correct color at all zoom levels
dominik
parents:
1165
diff
changeset
|
930 |
sstd->color = (ss->owner==OWNER_NONE)?14:_player_colors[ss->owner]; |
0 | 931 |
} |
932 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
933 |
} |
0 | 934 |
} |
935 |
} |
|
936 |
||
410 | 937 |
static void ViewportAddWaypoints(DrawPixelInfo *dpi) |
0 | 938 |
{ |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
939 |
Waypoint *wp; |
0 | 940 |
|
941 |
int left, top, right, bottom; |
|
942 |
StringSpriteToDraw *sstd; |
|
943 |
||
395
788a9bba0889
(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
|
944 |
if (!(_display_opt & DO_WAYPOINTS)) |
0 | 945 |
return; |
946 |
||
947 |
left = dpi->left; |
|
948 |
top = dpi->top; |
|
949 |
right = left + dpi->width; |
|
950 |
bottom = top + dpi->height; |
|
951 |
||
952 |
if (dpi->zoom < 1) { |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
953 |
FOR_ALL_WAYPOINTS(wp) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
954 |
if (wp->xy && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
955 |
bottom > wp->sign.top && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
956 |
top < wp->sign.top + 12 && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
957 |
right > wp->sign.left && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
958 |
left < wp->sign.left + wp->sign.width_1) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
959 |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
960 |
sstd = AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, STR_WAYPOINT_VIEWPORT, wp->index, 0, 0); |
0 | 961 |
if (sstd != NULL) { |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
962 |
sstd->width = wp->sign.width_1; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
963 |
sstd->color = (wp->deleted ? 0xE : 11); |
0 | 964 |
} |
965 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
966 |
} |
0 | 967 |
} else if (dpi->zoom == 1) { |
968 |
right += 2; |
|
969 |
bottom += 2; |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
970 |
FOR_ALL_WAYPOINTS(wp) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
971 |
if (wp->xy && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
972 |
bottom > wp->sign.top && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
973 |
top < wp->sign.top + 24 && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
974 |
right > wp->sign.left && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
975 |
left < wp->sign.left + wp->sign.width_1*2) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
976 |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
977 |
sstd = AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, STR_WAYPOINT_VIEWPORT, wp->index, 0, 0); |
0 | 978 |
if (sstd != NULL) { |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
979 |
sstd->width = wp->sign.width_1; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
980 |
sstd->color = (wp->deleted ? 0xE : 11); |
0 | 981 |
} |
982 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
983 |
} |
0 | 984 |
} else { |
985 |
right += 4; |
|
986 |
bottom += 5; |
|
987 |
||
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
988 |
FOR_ALL_WAYPOINTS(wp) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
989 |
if (wp->xy && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
990 |
bottom > wp->sign.top && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
991 |
top < wp->sign.top + 24 && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
992 |
right > wp->sign.left && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
993 |
left < wp->sign.left + wp->sign.width_2*4) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
994 |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
995 |
sstd = AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, STR_WAYPOINT_VIEWPORT_TINY, wp->index, 0, 0); |
0 | 996 |
if (sstd != NULL) { |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
997 |
sstd->width = wp->sign.width_2 | 0x8000; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
998 |
sstd->color = (wp->deleted ? 0xE : 11); |
0 | 999 |
} |
1000 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1001 |
} |
0 | 1002 |
} |
1003 |
} |
|
1004 |
||
1005 |
void UpdateViewportSignPos(ViewportSign *sign, int left, int top, StringID str) |
|
1006 |
{ |
|
1007 |
char buffer[128]; |
|
2116 | 1008 |
uint w; |
0 | 1009 |
|
1010 |
sign->top = top; |
|
1011 |
||
1012 |
GetString(buffer, str); |
|
1013 |
w = GetStringWidth(buffer) + 3; |
|
1014 |
sign->width_1 = w; |
|
2116 | 1015 |
sign->left = left - w / 2; |
0 | 1016 |
|
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1363
diff
changeset
|
1017 |
// zoomed out version |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3645
diff
changeset
|
1018 |
_cur_fontsize = FS_SMALL; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1363
diff
changeset
|
1019 |
w = GetStringWidth(buffer) + 3; |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3645
diff
changeset
|
1020 |
_cur_fontsize = FS_NORMAL; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1363
diff
changeset
|
1021 |
sign->width_2 = w; |
0 | 1022 |
} |
1023 |
||
1024 |
||
410 | 1025 |
static void ViewportDrawTileSprites(TileSpriteToDraw *ts) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1026 |
{ |
0 | 1027 |
do { |
1028 |
Point pt = RemapCoords(ts->x, ts->y, ts->z); |
|
1029 |
DrawSprite(ts->image, pt.x, pt.y); |
|
2116 | 1030 |
ts = ts->next; |
1031 |
} while (ts != NULL); |
|
0 | 1032 |
} |
1033 |
||
4171 | 1034 |
static void ViewportSortParentSprites(ParentSpriteToDraw *psd[]) |
0 | 1035 |
{ |
2116 | 1036 |
while (*psd != NULL) { |
1037 |
ParentSpriteToDraw* ps = *psd; |
|
0 | 1038 |
|
1039 |
if (!(ps->unk16 & 1)) { |
|
2116 | 1040 |
ParentSpriteToDraw** psd2 = psd; |
1041 |
||
0 | 1042 |
ps->unk16 |= 1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1043 |
|
2116 | 1044 |
while (*++psd2 != NULL) { |
1045 |
ParentSpriteToDraw* ps2 = *psd2; |
|
4188 | 1046 |
ParentSpriteToDraw** psd3; |
1934
b27bc12822cd
(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
|
1047 |
|
2116 | 1048 |
if (ps2->unk16 & 1) continue; |
0 | 1049 |
|
4187
4eaf57b951c8
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1050 |
/* Decide which comparator to use, based on whether the bounding |
4eaf57b951c8
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1051 |
* boxes overlap |
4eaf57b951c8
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1052 |
*/ |
4eaf57b951c8
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1053 |
if (ps->xmax > ps2->xmin && ps->xmin < ps2->xmax && // overlap in X? |
4eaf57b951c8
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1054 |
ps->ymax > ps2->ymin && ps->ymin < ps2->ymax && // overlap in Y? |
4eaf57b951c8
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1055 |
ps->zmax > ps2->zmin && ps->zmin < ps2->zmax) { // overlap in Z? |
4188 | 1056 |
/* Use X+Y+Z as the sorting order, so sprites closer to the bottom of |
1057 |
* the screen and with higher Z elevation, are drawn in front. |
|
1058 |
* Here X,Y,Z are the coordinates of the "center of mass" of the sprite, |
|
1059 |
* i.e. X=(left+right)/2, etc. |
|
1060 |
* However, since we only care about order, don't actually divide / 2 |
|
1061 |
*/ |
|
1062 |
if (ps->xmin + ps->xmax + ps->ymin + ps->ymax + ps->zmin + ps->zmax <= |
|
1063 |
ps2->xmin + ps2->xmax + ps2->ymin + ps2->ymax + ps2->zmin + ps2->zmax) { |
|
1064 |
continue; |
|
1065 |
} |
|
1934
b27bc12822cd
(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
|
1066 |
} else { |
4188 | 1067 |
if (ps->xmax < ps2->xmin || |
1068 |
ps->ymax < ps2->ymin || |
|
1069 |
ps->zmax < ps2->zmin || ( |
|
1070 |
ps->xmin < ps2->xmax && |
|
1071 |
ps->ymin < ps2->ymax && |
|
1072 |
ps->zmin < ps2->zmax |
|
1073 |
)) { |
|
1074 |
continue; |
|
1075 |
} |
|
1934
b27bc12822cd
(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
|
1076 |
} |
2116 | 1077 |
|
4188 | 1078 |
// Swap the two sprites ps and ps2 using bubble-sort algorithm. |
1079 |
psd3 = psd; |
|
1080 |
do { |
|
1081 |
ParentSpriteToDraw* temp = *psd3; |
|
1082 |
*psd3 = ps2; |
|
1083 |
ps2 = temp; |
|
0 | 1084 |
|
4188 | 1085 |
psd3++; |
1086 |
} while (psd3 <= psd2); |
|
0 | 1087 |
} |
1088 |
} else { |
|
1089 |
psd++; |
|
1090 |
} |
|
1091 |
} |
|
1092 |
} |
|
1093 |
||
2116 | 1094 |
static void ViewportDrawParentSprites(ParentSpriteToDraw *psd[]) |
0 | 1095 |
{ |
2116 | 1096 |
for (; *psd != NULL; psd++) { |
1097 |
const ParentSpriteToDraw* ps = *psd; |
|
4186
6e55c6f0908b
(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
|
1098 |
Point pt = RemapCoords(ps->xmin, ps->ymin, ps->zmin); |
2116 | 1099 |
const ChildScreenSpriteToDraw* cs; |
0 | 1100 |
|
1101 |
DrawSprite(ps->image, pt.x, pt.y); |
|
1102 |
||
2116 | 1103 |
for (cs = ps->child; cs != NULL; cs = cs->next) { |
0 | 1104 |
DrawSprite(cs->image, ps->left + cs->x, ps->top + cs->y); |
1105 |
} |
|
1106 |
} |
|
1107 |
} |
|
1108 |
||
2116 | 1109 |
static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDraw *ss) |
0 | 1110 |
{ |
1111 |
DrawPixelInfo dp; |
|
1112 |
byte zoom; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1113 |
|
0 | 1114 |
_cur_dpi = &dp; |
1115 |
dp = *dpi; |
|
1116 |
||
2116 | 1117 |
zoom = dp.zoom; |
0 | 1118 |
dp.zoom = 0; |
1119 |
||
1120 |
dp.left >>= zoom; |
|
1121 |
dp.top >>= zoom; |
|
1122 |
dp.width >>= zoom; |
|
1123 |
dp.height >>= zoom; |
|
1124 |
||
1125 |
do { |
|
1126 |
if (ss->width != 0) { |
|
2116 | 1127 |
int x = (ss->x >> zoom) - 1; |
1128 |
int y = (ss->y >> zoom) - 1; |
|
1129 |
int bottom = y + 11; |
|
1130 |
int w = ss->width; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1131 |
|
0 | 1132 |
if (w & 0x8000) { |
1133 |
w &= ~0x8000; |
|
1134 |
y--; |
|
1135 |
bottom -= 6; |
|
1136 |
w -= 3; |
|
1137 |
} |
|
1138 |
||
2116 | 1139 |
/* Draw the rectangle if 'tranparent station signs' is off, |
1140 |
* or if we are drawing a general text sign (STR_2806) */ |
|
1141 |
if (!(_display_opt & DO_TRANS_SIGNS) || ss->string == STR_2806) |
|
1142 |
DrawFrameRect( |
|
1143 |
x, y, x + w, bottom, ss->color, |
|
1144 |
(_display_opt & DO_TRANS_BUILDINGS) ? FR_TRANSPARENT | FR_NOBORDER : 0 |
|
1145 |
); |
|
0 | 1146 |
} |
1147 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1148 |
SetDParam(0, ss->params[0]); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1149 |
SetDParam(1, ss->params[1]); |
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
679
diff
changeset
|
1150 |
SetDParam(2, ss->params[2]); |
2116 | 1151 |
/* if we didn't draw a rectangle, or if transparant building is on, |
1152 |
* draw the text in the color the rectangle would have */ |
|
1153 |
if (( |
|
1154 |
(_display_opt & DO_TRANS_BUILDINGS) || |
|
1155 |
(_display_opt & DO_TRANS_SIGNS && ss->string != STR_2806) |
|
1156 |
) && ss->width != 0) { |
|
1157 |
/* Real colors need the IS_PALETTE_COLOR flag |
|
1158 |
* otherwise colors from _string_colormap are assumed. */ |
|
1159 |
DrawString( |
|
1160 |
ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0), |
|
1161 |
ss->string, (_color_list[ss->color].window_color_bgb | IS_PALETTE_COLOR) |
|
1162 |
); |
|
0 | 1163 |
} else { |
2116 | 1164 |
DrawString( |
1165 |
ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0), |
|
1166 |
ss->string, 16 |
|
1167 |
); |
|
0 | 1168 |
} |
2116 | 1169 |
|
1170 |
ss = ss->next; |
|
1171 |
} while (ss != NULL); |
|
0 | 1172 |
|
1173 |
_cur_dpi = dpi; |
|
1174 |
} |
|
1175 |
||
430 | 1176 |
void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom) |
0 | 1177 |
{ |
1178 |
ViewportDrawer vd; |
|
1179 |
int mask; |
|
2116 | 1180 |
int x; |
1181 |
int y; |
|
0 | 1182 |
DrawPixelInfo *old_dpi; |
1183 |
||
1184 |
byte mem[VIEWPORT_DRAW_MEM]; |
|
137
73f897e1bf4a
(svn r138) -Add: 64x64 stations are now nicely painted (increased size of
truelight
parents:
133
diff
changeset
|
1185 |
ParentSpriteToDraw *parent_list[6144]; |
0 | 1186 |
|
1187 |
_cur_vd = &vd; |
|
1188 |
||
1189 |
old_dpi = _cur_dpi; |
|
1190 |
_cur_dpi = &vd.dpi; |
|
1191 |
||
1192 |
vd.dpi.zoom = vp->zoom; |
|
1193 |
mask = (-1) << vp->zoom; |
|
1194 |
||
1195 |
vd.combine_sprites = 0; |
|
1196 |
||
1197 |
vd.dpi.width = (right - left) & mask; |
|
1198 |
vd.dpi.height = (bottom - top) & mask; |
|
1199 |
vd.dpi.left = left & mask; |
|
1200 |
vd.dpi.top = top & mask; |
|
1201 |
vd.dpi.pitch = old_dpi->pitch; |
|
1202 |
||
1203 |
x = ((vd.dpi.left - (vp->virtual_left&mask)) >> vp->zoom) + vp->left; |
|
1204 |
y = ((vd.dpi.top - (vp->virtual_top&mask)) >> vp->zoom) + vp->top; |
|
1205 |
||
1206 |
vd.dpi.dst_ptr = old_dpi->dst_ptr + x - old_dpi->left + (y - old_dpi->top) * old_dpi->pitch; |
|
1207 |
||
1208 |
vd.parent_list = parent_list; |
|
2116 | 1209 |
vd.eof_parent_list = endof(parent_list); |
0 | 1210 |
vd.spritelist_mem = mem; |
2116 | 1211 |
vd.eof_spritelist_mem = endof(mem) - sizeof(LARGEST_SPRITELIST_STRUCT); |
0 | 1212 |
vd.last_string = &vd.first_string; |
1213 |
vd.first_string = NULL; |
|
1214 |
vd.last_tile = &vd.first_tile; |
|
1215 |
vd.first_tile = NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1216 |
|
0 | 1217 |
ViewportAddLandscape(); |
1218 |
#if !defined(NEW_ROTATION) |
|
1219 |
ViewportAddVehicles(&vd.dpi); |
|
1220 |
DrawTextEffects(&vd.dpi); |
|
1221 |
||
1222 |
ViewportAddTownNames(&vd.dpi); |
|
1223 |
ViewportAddStationNames(&vd.dpi); |
|
1224 |
ViewportAddSigns(&vd.dpi); |
|
395
788a9bba0889
(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
|
1225 |
ViewportAddWaypoints(&vd.dpi); |
0 | 1226 |
#endif |
1227 |
||
133
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
1228 |
// This assert should never happen (because the length of the parent_list |
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
1229 |
// is checked) |
979
11ea18598e16
(svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
1230 |
assert(vd.parent_list <= endof(parent_list)); |
133
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
1231 |
|
2116 | 1232 |
if (vd.first_tile != NULL) ViewportDrawTileSprites(vd.first_tile); |
0 | 1233 |
|
1234 |
/* null terminate parent sprite list */ |
|
1235 |
*vd.parent_list = NULL; |
|
1236 |
||
1237 |
ViewportSortParentSprites(parent_list); |
|
1238 |
ViewportDrawParentSprites(parent_list); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1239 |
|
2116 | 1240 |
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
|
1241 |
|
0 | 1242 |
_cur_dpi = old_dpi; |
1243 |
} |
|
1244 |
||
1245 |
// Make sure we don't draw a too big area at a time. |
|
1246 |
// If we do, the sprite memory will overflow. |
|
1247 |
static void ViewportDrawChk(ViewPort *vp, int left, int top, int right, int bottom) |
|
1248 |
{ |
|
1249 |
if (((bottom - top) * (right - left) << vp->zoom) > 180000) { |
|
1250 |
if ((bottom - top) > (right - left)) { |
|
1251 |
int t = (top + bottom) >> 1; |
|
1252 |
ViewportDrawChk(vp, left, top, right, t); |
|
1253 |
ViewportDrawChk(vp, left, t, right, bottom); |
|
1254 |
} else { |
|
1255 |
int t = (left + right) >> 1; |
|
1256 |
ViewportDrawChk(vp, left, top, t, bottom); |
|
1257 |
ViewportDrawChk(vp, t, top, right, bottom); |
|
1258 |
} |
|
1259 |
} else { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1260 |
ViewportDoDraw(vp, |
0 | 1261 |
((left - vp->left) << vp->zoom) + vp->virtual_left, |
1262 |
((top - vp->top) << vp->zoom) + vp->virtual_top, |
|
1263 |
((right - vp->left) << vp->zoom) + vp->virtual_left, |
|
1264 |
((bottom - vp->top) << vp->zoom) + vp->virtual_top |
|
1265 |
); |
|
1266 |
} |
|
1267 |
} |
|
1268 |
||
500
8e52f7797b48
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
497
diff
changeset
|
1269 |
static inline void ViewportDraw(ViewPort *vp, int left, int top, int right, int bottom) |
0 | 1270 |
{ |
2116 | 1271 |
if (right <= vp->left || bottom <= vp->top) return; |
0 | 1272 |
|
2116 | 1273 |
if (left >= vp->left + vp->width) return; |
0 | 1274 |
|
1275 |
if (left < vp->left) left = vp->left; |
|
2116 | 1276 |
if (right > vp->left + vp->width) right = vp->left + vp->width; |
0 | 1277 |
|
2116 | 1278 |
if (top >= vp->top + vp->height) return; |
0 | 1279 |
|
1280 |
if (top < vp->top) top = vp->top; |
|
2116 | 1281 |
if (bottom > vp->top + vp->height) bottom = vp->top + vp->height; |
0 | 1282 |
|
1283 |
ViewportDrawChk(vp, left, top, right, bottom); |
|
1284 |
} |
|
1285 |
||
2116 | 1286 |
void DrawWindowViewport(Window *w) |
1287 |
{ |
|
0 | 1288 |
DrawPixelInfo *dpi = _cur_dpi; |
1289 |
||
1290 |
dpi->left += w->left; |
|
1291 |
dpi->top += w->top; |
|
1292 |
||
1293 |
ViewportDraw(w->viewport, dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height); |
|
1294 |
||
1295 |
dpi->left -= w->left; |
|
1296 |
dpi->top -= w->top; |
|
1297 |
} |
|
1298 |
||
1299 |
void UpdateViewportPosition(Window *w) |
|
1300 |
{ |
|
2116 | 1301 |
const ViewPort *vp = w->viewport; |
0 | 1302 |
|
2116 | 1303 |
if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE) { |
1304 |
const Vehicle* veh = GetVehicle(WP(w,vp_d).follow_vehicle); |
|
1305 |
Point pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos); |
|
0 | 1306 |
|
1307 |
SetViewportPosition(w, pt.x, pt.y); |
|
1308 |
} else { |
|
632
6528428cbebb
(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
|
1309 |
#if !defined(NEW_ROTATION) |
6528428cbebb
(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
|
1310 |
int x; |
6528428cbebb
(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
|
1311 |
int y; |
6528428cbebb
(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
|
1312 |
int vx; |
6528428cbebb
(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
|
1313 |
int vy; |
6528428cbebb
(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
|
1314 |
|
6528428cbebb
(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
|
1315 |
// Center of the viewport is hot spot |
6528428cbebb
(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
|
1316 |
x = WP(w,vp_d).scrollpos_x + vp->virtual_width / 2; |
6528428cbebb
(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
|
1317 |
y = WP(w,vp_d).scrollpos_y + vp->virtual_height / 2; |
6528428cbebb
(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
|
1318 |
// Convert viewport coordinates to map coordinates |
6528428cbebb
(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
|
1319 |
// Calculation is scaled by 4 to avoid rounding errors |
6528428cbebb
(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
|
1320 |
vx = -x + y * 2; |
6528428cbebb
(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
|
1321 |
vy = x + y * 2; |
6528428cbebb
(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
|
1322 |
// clamp to size of map |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1323 |
vx = clamp(vx, 0 * 4, MapMaxX() * TILE_SIZE * 4); |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1324 |
vy = clamp(vy, 0 * 4, MapMaxY() * TILE_SIZE * 4); |
632
6528428cbebb
(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
|
1325 |
// Convert map coordinates to viewport coordinates |
6528428cbebb
(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
|
1326 |
x = (-vx + vy) / 2; |
6528428cbebb
(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
|
1327 |
y = ( vx + vy) / 4; |
6528428cbebb
(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
|
1328 |
// Set position |
2116 | 1329 |
WP(w, vp_d).scrollpos_x = x - vp->virtual_width / 2; |
1330 |
WP(w, vp_d).scrollpos_y = y - vp->virtual_height / 2; |
|
632
6528428cbebb
(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
|
1331 |
#else |
0 | 1332 |
int x,y,t; |
1333 |
int err; |
|
1334 |
||
1335 |
x = WP(w,vp_d).scrollpos_x >> 2; |
|
1336 |
y = WP(w,vp_d).scrollpos_y >> 1; |
|
1337 |
||
1338 |
t = x; |
|
1339 |
x = x + y; |
|
1340 |
y = x - y; |
|
1341 |
err= 0; |
|
1342 |
||
1343 |
if (err != 0) { |
|
1344 |
/* coordinate remap */ |
|
1345 |
Point pt = RemapCoords(x, y, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1346 |
t = (-1) << vp->zoom; |
0 | 1347 |
WP(w,vp_d).scrollpos_x = pt.x & t; |
1348 |
WP(w,vp_d).scrollpos_y = pt.y & t; |
|
1349 |
} |
|
632
6528428cbebb
(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
|
1350 |
#endif |
6528428cbebb
(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
|
1351 |
|
2116 | 1352 |
SetViewportPosition(w, WP(w, vp_d).scrollpos_x, WP(w, vp_d).scrollpos_y); |
0 | 1353 |
} |
1354 |
} |
|
1355 |
||
2116 | 1356 |
static void MarkViewportDirty(const ViewPort *vp, int left, int top, int right, int bottom) |
0 | 1357 |
{ |
2116 | 1358 |
right -= vp->virtual_left; |
1359 |
if (right <= 0) return; |
|
0 | 1360 |
|
2116 | 1361 |
bottom -= vp->virtual_top; |
1362 |
if (bottom <= 0) return; |
|
0 | 1363 |
|
2116 | 1364 |
left = max(0, left - vp->virtual_left); |
0 | 1365 |
|
2116 | 1366 |
if (left >= vp->virtual_width) return; |
0 | 1367 |
|
2116 | 1368 |
top = max(0, top - vp->virtual_top); |
1369 |
||
1370 |
if (top >= vp->virtual_height) return; |
|
0 | 1371 |
|
1372 |
SetDirtyBlocks( |
|
1373 |
(left >> vp->zoom) + vp->left, |
|
1374 |
(top >> vp->zoom) + vp->top, |
|
1375 |
(right >> vp->zoom) + vp->left, |
|
1376 |
(bottom >> vp->zoom) + vp->top |
|
1377 |
); |
|
1378 |
} |
|
1379 |
||
1380 |
void MarkAllViewportsDirty(int left, int top, int right, int bottom) |
|
1381 |
{ |
|
2116 | 1382 |
const ViewPort *vp = _viewports; |
0 | 1383 |
uint32 act = _active_viewports; |
1384 |
do { |
|
1385 |
if (act & 1) { |
|
1386 |
assert(vp->width != 0); |
|
1387 |
MarkViewportDirty(vp, left, top, right, bottom); |
|
1388 |
} |
|
1389 |
} while (vp++,act>>=1); |
|
1390 |
} |
|
1391 |
||
2116 | 1392 |
void MarkTileDirtyByTile(TileIndex tile) |
1393 |
{ |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1394 |
Point pt = RemapCoords(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, GetTileZ(tile)); |
0 | 1395 |
MarkAllViewportsDirty( |
1396 |
pt.x - 31, |
|
1397 |
pt.y - 122, |
|
1398 |
pt.x - 31 + 67, |
|
1399 |
pt.y - 122 + 154 |
|
1400 |
); |
|
1401 |
} |
|
1402 |
||
1403 |
void MarkTileDirty(int x, int y) |
|
1404 |
{ |
|
2116 | 1405 |
uint z = 0; |
0 | 1406 |
Point pt; |
2116 | 1407 |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1408 |
if (IS_INT_INSIDE(x, 0, MapSizeX() * TILE_SIZE) && |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1409 |
IS_INT_INSIDE(y, 0, MapSizeY() * TILE_SIZE)) |
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1410 |
z = GetTileZ(TileVirtXY(x, y)); |
0 | 1411 |
pt = RemapCoords(x, y, z); |
1412 |
||
1413 |
MarkAllViewportsDirty( |
|
1414 |
pt.x - 31, |
|
1415 |
pt.y - 122, |
|
1416 |
pt.x - 31 + 67, |
|
1417 |
pt.y - 122 + 154 |
|
1418 |
); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1419 |
} |
0 | 1420 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
1421 |
static void SetSelectionTilesDirty(void) |
0 | 1422 |
{ |
1423 |
int y_size, x_size; |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1424 |
int x = _thd.pos.x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1425 |
int y = _thd.pos.y; |
0 | 1426 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1427 |
x_size = _thd.size.x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1428 |
y_size = _thd.size.y; |
0 | 1429 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1430 |
if (_thd.outersize.x) { |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1431 |
x_size += _thd.outersize.x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1432 |
x += _thd.offs.x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1433 |
y_size += _thd.outersize.y; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1434 |
y += _thd.offs.y; |
0 | 1435 |
} |
1436 |
||
1437 |
assert(x_size > 0); |
|
1438 |
assert(y_size > 0); |
|
1439 |
||
1440 |
x_size += x; |
|
1441 |
y_size += y; |
|
1442 |
||
1443 |
do { |
|
1444 |
int y_bk = y; |
|
1445 |
do { |
|
1446 |
MarkTileDirty(x, y); |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1447 |
} while ( (y += TILE_SIZE) != y_size); |
0 | 1448 |
y = y_bk; |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1449 |
} while ( (x += TILE_SIZE) != x_size); |
0 | 1450 |
} |
1451 |
||
1452 |
||
1990
efb67f977138
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1453 |
void SetSelectionRed(bool b) |
efb67f977138
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1454 |
{ |
efb67f977138
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1455 |
_thd.make_square_red = b; |
efb67f977138
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1456 |
SetSelectionTilesDirty(); |
efb67f977138
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1457 |
} |
efb67f977138
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1458 |
|
efb67f977138
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1459 |
|
2116 | 1460 |
static bool CheckClickOnTown(const ViewPort *vp, int x, int y) |
0 | 1461 |
{ |
2116 | 1462 |
const Town *t; |
0 | 1463 |
|
2116 | 1464 |
if (!(_display_opt & DO_SHOW_TOWN_NAMES)) return false; |
0 | 1465 |
|
1466 |
if (vp->zoom < 1) { |
|
1467 |
x = x - vp->left + vp->virtual_left; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1468 |
y = y - vp->top + vp->virtual_top; |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1469 |
|
0 | 1470 |
FOR_ALL_TOWNS(t) { |
1471 |
if (t->xy && |
|
1472 |
y >= t->sign.top && |
|
1473 |
y < t->sign.top + 12 && |
|
1474 |
x >= t->sign.left && |
|
1475 |
x < t->sign.left + t->sign.width_1) { |
|
1476 |
ShowTownViewWindow(t->index); |
|
1477 |
return true; |
|
1478 |
} |
|
1479 |
} |
|
1480 |
} else if (vp->zoom == 1) { |
|
1481 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1482 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
0 | 1483 |
FOR_ALL_TOWNS(t) { |
1484 |
if (t->xy && |
|
1485 |
y >= t->sign.top && |
|
1486 |
y < t->sign.top + 24 && |
|
1487 |
x >= t->sign.left && |
|
1488 |
x < t->sign.left + t->sign.width_1 * 2) { |
|
1489 |
ShowTownViewWindow(t->index); |
|
1490 |
return true; |
|
1491 |
} |
|
1492 |
} |
|
1493 |
} else { |
|
1494 |
x = (x - vp->left + 3) * 4 + vp->virtual_left; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1495 |
y = (y - vp->top + 3) * 4 + vp->virtual_top; |
0 | 1496 |
FOR_ALL_TOWNS(t) { |
1497 |
if (t->xy && |
|
1498 |
y >= t->sign.top && |
|
1499 |
y < t->sign.top + 24 && |
|
1500 |
x >= t->sign.left && |
|
1501 |
x < t->sign.left + t->sign.width_2 * 4) { |
|
1502 |
ShowTownViewWindow(t->index); |
|
1503 |
return true; |
|
1504 |
} |
|
1505 |
} |
|
1506 |
} |
|
1507 |
||
1508 |
return false; |
|
1509 |
} |
|
1510 |
||
2116 | 1511 |
static bool CheckClickOnStation(const ViewPort *vp, int x, int y) |
0 | 1512 |
{ |
2116 | 1513 |
const Station *st; |
0 | 1514 |
|
2116 | 1515 |
if (!(_display_opt & DO_SHOW_STATION_NAMES)) return false; |
0 | 1516 |
|
1517 |
if (vp->zoom < 1) { |
|
1518 |
x = x - vp->left + vp->virtual_left; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1519 |
y = y - vp->top + vp->virtual_top; |
0 | 1520 |
|
1521 |
FOR_ALL_STATIONS(st) { |
|
1522 |
if (st->xy && |
|
1523 |
y >= st->sign.top && |
|
1524 |
y < st->sign.top + 12 && |
|
1525 |
x >= st->sign.left && |
|
1526 |
x < st->sign.left + st->sign.width_1) { |
|
1527 |
ShowStationViewWindow(st->index); |
|
1528 |
return true; |
|
1529 |
} |
|
1530 |
} |
|
1531 |
} else if (vp->zoom == 1) { |
|
1532 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1533 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
0 | 1534 |
FOR_ALL_STATIONS(st) { |
1535 |
if (st->xy && |
|
1536 |
y >= st->sign.top && |
|
1537 |
y < st->sign.top + 24 && |
|
1538 |
x >= st->sign.left && |
|
1539 |
x < st->sign.left + st->sign.width_1 * 2) { |
|
1540 |
ShowStationViewWindow(st->index); |
|
1541 |
return true; |
|
1542 |
} |
|
1543 |
} |
|
1544 |
} else { |
|
1545 |
x = (x - vp->left + 3) * 4 + vp->virtual_left; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1546 |
y = (y - vp->top + 3) * 4 + vp->virtual_top; |
0 | 1547 |
FOR_ALL_STATIONS(st) { |
1548 |
if (st->xy && |
|
1549 |
y >= st->sign.top && |
|
1550 |
y < st->sign.top + 24 && |
|
1551 |
x >= st->sign.left && |
|
1552 |
x < st->sign.left + st->sign.width_2 * 4) { |
|
1553 |
ShowStationViewWindow(st->index); |
|
1554 |
return true; |
|
1555 |
} |
|
1556 |
} |
|
1557 |
} |
|
1558 |
||
1559 |
return false; |
|
1560 |
} |
|
1561 |
||
2116 | 1562 |
static bool CheckClickOnSign(const ViewPort *vp, int x, int y) |
0 | 1563 |
{ |
2116 | 1564 |
const SignStruct *ss; |
0 | 1565 |
|
2116 | 1566 |
if (!(_display_opt & DO_SHOW_SIGNS)) return false; |
0 | 1567 |
|
1568 |
if (vp->zoom < 1) { |
|
1569 |
x = x - vp->left + vp->virtual_left; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1570 |
y = y - vp->top + vp->virtual_top; |
0 | 1571 |
|
988
4304525d1b8b
(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
981
diff
changeset
|
1572 |
FOR_ALL_SIGNS(ss) { |
0 | 1573 |
if (ss->str && |
1574 |
y >= ss->sign.top && |
|
1575 |
y < ss->sign.top + 12 && |
|
1576 |
x >= ss->sign.left && |
|
1577 |
x < ss->sign.left + ss->sign.width_1) { |
|
1578 |
ShowRenameSignWindow(ss); |
|
1579 |
return true; |
|
1580 |
} |
|
1581 |
} |
|
1582 |
} else if (vp->zoom == 1) { |
|
1583 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1584 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
988
4304525d1b8b
(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
981
diff
changeset
|
1585 |
FOR_ALL_SIGNS(ss) { |
0 | 1586 |
if (ss->str && |
1587 |
y >= ss->sign.top && |
|
1588 |
y < ss->sign.top + 24 && |
|
1589 |
x >= ss->sign.left && |
|
1590 |
x < ss->sign.left + ss->sign.width_1 * 2) { |
|
1591 |
ShowRenameSignWindow(ss); |
|
1592 |
return true; |
|
1593 |
} |
|
1594 |
} |
|
1595 |
} else { |
|
1596 |
x = (x - vp->left + 3) * 4 + vp->virtual_left; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1597 |
y = (y - vp->top + 3) * 4 + vp->virtual_top; |
988
4304525d1b8b
(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
981
diff
changeset
|
1598 |
FOR_ALL_SIGNS(ss) { |
0 | 1599 |
if (ss->str && |
1600 |
y >= ss->sign.top && |
|
1601 |
y < ss->sign.top + 24 && |
|
1602 |
x >= ss->sign.left && |
|
1603 |
x < ss->sign.left + ss->sign.width_2 * 4) { |
|
1604 |
ShowRenameSignWindow(ss); |
|
1605 |
return true; |
|
1606 |
} |
|
1607 |
} |
|
1608 |
} |
|
1609 |
||
1610 |
return false; |
|
1611 |
} |
|
1612 |
||
2116 | 1613 |
static bool CheckClickOnWaypoint(const ViewPort *vp, int x, int y) |
0 | 1614 |
{ |
2116 | 1615 |
const Waypoint *wp; |
0 | 1616 |
|
2116 | 1617 |
if (!(_display_opt & DO_WAYPOINTS)) return false; |
0 | 1618 |
|
1619 |
if (vp->zoom < 1) { |
|
1620 |
x = x - vp->left + vp->virtual_left; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1621 |
y = y - vp->top + vp->virtual_top; |
0 | 1622 |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1623 |
FOR_ALL_WAYPOINTS(wp) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1624 |
if (wp->xy && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1625 |
y >= wp->sign.top && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1626 |
y < wp->sign.top + 12 && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1627 |
x >= wp->sign.left && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1628 |
x < wp->sign.left + wp->sign.width_1) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1629 |
ShowRenameWaypointWindow(wp); |
0 | 1630 |
return true; |
1631 |
} |
|
1632 |
} |
|
1633 |
} else if (vp->zoom == 1) { |
|
1634 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1635 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1636 |
FOR_ALL_WAYPOINTS(wp) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1637 |
if (wp->xy && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1638 |
y >= wp->sign.top && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1639 |
y < wp->sign.top + 24 && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1640 |
x >= wp->sign.left && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1641 |
x < wp->sign.left + wp->sign.width_1 * 2) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1642 |
ShowRenameWaypointWindow(wp); |
0 | 1643 |
return true; |
1644 |
} |
|
1645 |
} |
|
1646 |
} else { |
|
1647 |
x = (x - vp->left + 3) * 4 + vp->virtual_left; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1648 |
y = (y - vp->top + 3) * 4 + vp->virtual_top; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1649 |
FOR_ALL_WAYPOINTS(wp) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1650 |
if (wp->xy && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1651 |
y >= wp->sign.top && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1652 |
y < wp->sign.top + 24 && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1653 |
x >= wp->sign.left && |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1654 |
x < wp->sign.left + wp->sign.width_2 * 4) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
1655 |
ShowRenameWaypointWindow(wp); |
0 | 1656 |
return true; |
1657 |
} |
|
1658 |
} |
|
1659 |
} |
|
1660 |
||
1661 |
return false; |
|
1662 |
} |
|
1663 |
||
1664 |
||
2116 | 1665 |
static void CheckClickOnLandscape(const ViewPort *vp, int x, int y) |
0 | 1666 |
{ |
2116 | 1667 |
Point pt = TranslateXYToTileCoord(vp, x, y); |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1964
diff
changeset
|
1668 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1669 |
if (pt.x != -1) ClickTile(TileVirtXY(pt.x, pt.y)); |
0 | 1670 |
} |
1671 |
||
2662
8b46824bd821
(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
|
1672 |
|
8b46824bd821
(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
|
1673 |
static void SafeShowTrainViewWindow(const Vehicle* v) |
8b46824bd821
(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
|
1674 |
{ |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1675 |
if (!IsFrontEngine(v)) v = GetFirstVehicleInChain(v); |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1676 |
ShowTrainViewWindow(v); |
2662
8b46824bd821
(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
|
1677 |
} |
8b46824bd821
(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
|
1678 |
|
4171 | 1679 |
static void Nop(const Vehicle *v) {} |
2662
8b46824bd821
(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
|
1680 |
|
4171 | 1681 |
typedef void OnVehicleClickProc(const Vehicle *v); |
2662
8b46824bd821
(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
|
1682 |
static OnVehicleClickProc* const _on_vehicle_click_proc[] = { |
8b46824bd821
(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
|
1683 |
SafeShowTrainViewWindow, |
8b46824bd821
(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
|
1684 |
ShowRoadVehViewWindow, |
8b46824bd821
(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
|
1685 |
ShowShipViewWindow, |
8b46824bd821
(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
|
1686 |
ShowAircraftViewWindow, |
8b46824bd821
(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
|
1687 |
Nop, // Special vehicles |
8b46824bd821
(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
|
1688 |
Nop // Disaster vehicles |
0 | 1689 |
}; |
1690 |
||
2116 | 1691 |
void HandleViewportClicked(const ViewPort *vp, int x, int y) |
0 | 1692 |
{ |
4171 | 1693 |
const Vehicle *v; |
0 | 1694 |
|
2116 | 1695 |
if (CheckClickOnTown(vp, x, y)) return; |
1696 |
if (CheckClickOnStation(vp, x, y)) return; |
|
1697 |
if (CheckClickOnSign(vp, x, y)) return; |
|
1698 |
if (CheckClickOnWaypoint(vp, x, y)) return; |
|
0 | 1699 |
CheckClickOnLandscape(vp, x, y); |
1700 |
||
2116 | 1701 |
v = CheckClickOnVehicle(vp, x, y); |
3809
d67cd0232924
(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
|
1702 |
if (v != NULL) { |
d67cd0232924
(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
|
1703 |
DEBUG(misc, 2) ("Vehicle %d at %p", v->index, v); |
d67cd0232924
(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
|
1704 |
_on_vehicle_click_proc[v->type - 0x10](v); |
d67cd0232924
(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
|
1705 |
} |
0 | 1706 |
} |
1707 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
1708 |
Vehicle *CheckMouseOverVehicle(void) |
0 | 1709 |
{ |
4171 | 1710 |
const Window *w; |
1711 |
const ViewPort *vp; |
|
0 | 1712 |
|
1713 |
int x = _cursor.pos.x; |
|
1714 |
int y = _cursor.pos.y; |
|
1715 |
||
1716 |
w = FindWindowFromPt(x, y); |
|
2116 | 1717 |
if (w == NULL) return NULL; |
0 | 1718 |
|
1719 |
vp = IsPtInWindowViewport(w, x, y); |
|
2116 | 1720 |
return (vp != NULL) ? CheckClickOnVehicle(vp, x, y) : NULL; |
0 | 1721 |
} |
1722 |
||
1723 |
||
1724 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
1725 |
void PlaceObject(void) |
0 | 1726 |
{ |
1727 |
Point pt; |
|
1728 |
Window *w; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1729 |
|
0 | 1730 |
pt = GetTileBelowCursor(); |
2116 | 1731 |
if (pt.x == -1) return; |
0 | 1732 |
|
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1733 |
if (_thd.place_mode == VHM_POINT) { |
0 | 1734 |
pt.x += 8; |
1735 |
pt.y += 8; |
|
1736 |
} |
|
1737 |
||
1738 |
_tile_fract_coords.x = pt.x & 0xF; |
|
1739 |
_tile_fract_coords.y = pt.y & 0xF; |
|
1740 |
||
2116 | 1741 |
w = GetCallbackWnd(); |
1742 |
if (w != NULL) { |
|
1743 |
WindowEvent e; |
|
1744 |
||
0 | 1745 |
e.event = WE_PLACE_OBJ; |
1746 |
e.place.pt = pt; |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1747 |
e.place.tile = TileVirtXY(pt.x, pt.y); |
0 | 1748 |
w->wndproc(w, &e); |
1749 |
} |
|
1750 |
} |
|
1751 |
||
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
|
1752 |
|
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
|
1753 |
/* scrolls the viewport in a window to a given location */ |
4171 | 1754 |
bool ScrollWindowTo(int x , int y, Window *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
|
1755 |
{ |
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
|
1756 |
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
|
1757 |
|
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
|
1758 |
pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y)); |
2116 | 1759 |
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
|
1760 |
|
2116 | 1761 |
if (WP(w, vp_d).scrollpos_x == pt.x && WP(w, vp_d).scrollpos_y == pt.y) |
1762 |
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
|
1763 |
|
2116 | 1764 |
WP(w, vp_d).scrollpos_x = pt.x; |
1765 |
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
|
1766 |
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
|
1767 |
} |
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
|
1768 |
|
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
|
1769 |
|
0 | 1770 |
bool ScrollMainWindowTo(int x, int y) |
1771 |
{ |
|
2116 | 1772 |
return ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0)); |
0 | 1773 |
} |
1774 |
||
1775 |
||
1776 |
bool ScrollMainWindowToTile(TileIndex tile) |
|
1777 |
{ |
|
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
1778 |
return ScrollMainWindowTo(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2); |
0 | 1779 |
} |
1780 |
||
1781 |
void SetRedErrorSquare(TileIndex tile) |
|
1782 |
{ |
|
1783 |
TileIndex old; |
|
1784 |
||
1785 |
old = _thd.redsq; |
|
1786 |
_thd.redsq = tile; |
|
1787 |
||
1788 |
if (tile != old) { |
|
3281
757d7da49445
(svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents:
3279
diff
changeset
|
1789 |
if (tile != 0) MarkTileDirtyByTile(tile); |
757d7da49445
(svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents:
3279
diff
changeset
|
1790 |
if (old != 0) MarkTileDirtyByTile(old); |
0 | 1791 |
} |
1792 |
} |
|
1793 |
||
1794 |
void SetTileSelectSize(int w, int h) |
|
1795 |
{ |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1796 |
_thd.new_size.x = w * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1797 |
_thd.new_size.y = h * TILE_SIZE; |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1798 |
_thd.new_outersize.x = 0; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1799 |
_thd.new_outersize.y = 0; |
0 | 1800 |
} |
1801 |
||
2116 | 1802 |
void SetTileSelectBigSize(int ox, int oy, int sx, int sy) |
1803 |
{ |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1804 |
_thd.offs.x = ox * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1805 |
_thd.offs.y = oy * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1806 |
_thd.new_outersize.x = sx * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1807 |
_thd.new_outersize.y = sy * TILE_SIZE; |
0 | 1808 |
} |
1809 |
||
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1810 |
/* returns the best autorail highlight type from map coordinates */ |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1811 |
static byte GetAutorailHT(int x, int y) |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1812 |
{ |
2710
44278abd3ef9
(svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents:
2676
diff
changeset
|
1813 |
return HT_RAIL | _AutorailPiece[x & 0xF][y & 0xF]; |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1814 |
} |
0 | 1815 |
|
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1816 |
// called regular to update tile highlighting in all cases |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
1817 |
void UpdateTileSelection(void) |
0 | 1818 |
{ |
2116 | 1819 |
int x1; |
1820 |
int y1; |
|
0 | 1821 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1822 |
_thd.new_drawstyle = 0; |
0 | 1823 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1824 |
if (_thd.place_mode == VHM_SPECIAL) { |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1825 |
x1 = _thd.selend.x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1826 |
y1 = _thd.selend.y; |
0 | 1827 |
if (x1 != -1) { |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1828 |
int x2 = _thd.selstart.x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1829 |
int y2 = _thd.selstart.y; |
0 | 1830 |
x1 &= ~0xF; |
1831 |
y1 &= ~0xF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1832 |
|
0 | 1833 |
if (x1 >= x2) intswap(x1,x2); |
1834 |
if (y1 >= y2) intswap(y1,y2); |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1835 |
_thd.new_pos.x = x1; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1836 |
_thd.new_pos.y = y1; |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1837 |
_thd.new_size.x = x2 - x1 + TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1838 |
_thd.new_size.y = y2 - y1 + TILE_SIZE; |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1839 |
_thd.new_drawstyle = _thd.next_drawstyle; |
0 | 1840 |
} |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1841 |
} else if (_thd.place_mode != VHM_NONE) { |
2116 | 1842 |
Point pt = GetTileBelowCursor(); |
0 | 1843 |
x1 = pt.x; |
1844 |
y1 = pt.y; |
|
1845 |
if (x1 != -1) { |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1846 |
switch (_thd.place_mode) { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1847 |
case VHM_RECT: |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1848 |
_thd.new_drawstyle = HT_RECT; |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1849 |
break; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1850 |
case VHM_POINT: |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1851 |
_thd.new_drawstyle = HT_POINT; |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1852 |
x1 += 8; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1853 |
y1 += 8; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1854 |
break; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1855 |
case VHM_RAIL: |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1856 |
_thd.new_drawstyle = GetAutorailHT(pt.x, pt.y); // draw one highlighted tile |
0 | 1857 |
} |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1858 |
_thd.new_pos.x = x1 & ~0xF; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1859 |
_thd.new_pos.y = y1 & ~0xF; |
0 | 1860 |
} |
1861 |
} |
|
1862 |
||
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1863 |
// redraw selection |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1864 |
if (_thd.drawstyle != _thd.new_drawstyle || |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1865 |
_thd.pos.x != _thd.new_pos.x || _thd.pos.y != _thd.new_pos.y || |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1866 |
_thd.size.x != _thd.new_size.x || _thd.size.y != _thd.new_size.y) { |
0 | 1867 |
// clear the old selection? |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1868 |
if (_thd.drawstyle) SetSelectionTilesDirty(); |
0 | 1869 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1870 |
_thd.drawstyle = _thd.new_drawstyle; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1871 |
_thd.pos = _thd.new_pos; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1872 |
_thd.size = _thd.new_size; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1873 |
_thd.outersize = _thd.new_outersize; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1874 |
_thd.dirty = 0xff; |
0 | 1875 |
|
1876 |
// draw the new selection? |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1877 |
if (_thd.new_drawstyle) SetSelectionTilesDirty(); |
0 | 1878 |
} |
1879 |
} |
|
1880 |
||
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1881 |
// highlighting tiles while only going over them with the mouse |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1964
diff
changeset
|
1882 |
void VpStartPlaceSizing(TileIndex tile, int user) |
0 | 1883 |
{ |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1884 |
_thd.userdata = user; |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1885 |
_thd.selend.x = TileX(tile) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1886 |
_thd.selstart.x = TileX(tile) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1887 |
_thd.selend.y = TileY(tile) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1888 |
_thd.selstart.y = TileY(tile) * TILE_SIZE; |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1889 |
if (_thd.place_mode == VHM_RECT) { |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1890 |
_thd.place_mode = VHM_SPECIAL; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1891 |
_thd.next_drawstyle = HT_RECT; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1892 |
} else if (_thd.place_mode == VHM_RAIL) { // autorail one piece |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1893 |
_thd.place_mode = VHM_SPECIAL; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1894 |
_thd.next_drawstyle = _thd.drawstyle; |
0 | 1895 |
} else { |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1896 |
_thd.place_mode = VHM_SPECIAL; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1897 |
_thd.next_drawstyle = HT_POINT; |
0 | 1898 |
} |
1899 |
_special_mouse_mode = WSM_SIZING; |
|
1900 |
} |
|
1901 |
||
1902 |
void VpSetPlaceSizingLimit(int limit) |
|
1903 |
{ |
|
1904 |
_thd.sizelimit = limit; |
|
1905 |
} |
|
1906 |
||
1907 |
void VpSetPresizeRange(uint from, uint to) |
|
1908 |
{ |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1909 |
_thd.selend.x = TileX(to) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1910 |
_thd.selend.y = TileY(to) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1911 |
_thd.selstart.x = TileX(from) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1912 |
_thd.selstart.y = TileY(from) * TILE_SIZE; |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1913 |
_thd.next_drawstyle = HT_RECT; |
0 | 1914 |
} |
1915 |
||
2817 | 1916 |
static void VpStartPreSizing(void) |
0 | 1917 |
{ |
1918 |
_thd.selend.x = -1; |
|
1919 |
_special_mouse_mode = WSM_PRESIZE; |
|
1920 |
} |
|
1921 |
||
1109
ecb98f43ba2c
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
1922 |
/* returns information about the 2x1 piece to be build. |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1923 |
* The lower bits (0-3) are the track type. */ |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1924 |
static byte Check2x1AutoRail(int mode) |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1925 |
{ |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1926 |
int fxpy = _tile_fract_coords.x + _tile_fract_coords.y; |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1927 |
int sxpy = (_thd.selend.x & 0xF) + (_thd.selend.y & 0xF); |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1928 |
int fxmy = _tile_fract_coords.x - _tile_fract_coords.y; |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1929 |
int sxmy = (_thd.selend.x & 0xF) - (_thd.selend.y & 0xF); |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1930 |
|
2952 | 1931 |
switch (mode) { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1932 |
case 0: // end piece is lower right |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1933 |
if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; } |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1934 |
if (fxmy < -3 && sxmy > 3) {/* DoRailroadTrack(0); */return 5; } |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1935 |
return 1; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1936 |
|
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1937 |
case 1: |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1938 |
if (fxmy > 3 && sxmy < -3) { /*SwapSelection(); DoRailroadTrack(0); */return 4; } |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1939 |
if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; } |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1940 |
return 1; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1941 |
|
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1942 |
case 2: |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1943 |
if (fxmy > 3 && sxmy < -3) { /*DoRailroadTrack(3);*/ return 4; } |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1944 |
if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; } |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1945 |
return 0; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1946 |
|
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1947 |
case 3: |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1948 |
if (fxmy < -3 && sxmy > 3) { /*SwapSelection(); DoRailroadTrack(3);*/ return 5; } |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1949 |
if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; } |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1950 |
return 0; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1951 |
} |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1952 |
|
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1953 |
return 0; // avoids compiler warnings |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1954 |
} |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1955 |
|
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1956 |
|
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1957 |
// while dragging |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1958 |
static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int method) |
0 | 1959 |
{ |
1960 |
int d; |
|
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1961 |
byte b=6; |
0 | 1962 |
uint w,h; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1963 |
|
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1964 |
int dx = thd->selstart.x - (thd->selend.x&~0xF); |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1965 |
int dy = thd->selstart.y - (thd->selend.y&~0xF); |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1966 |
w = myabs(dx) + 16; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1967 |
h = myabs(dy) + 16; |
0 | 1968 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1969 |
if (TileVirtXY(thd->selstart.x, thd->selstart.y) == TileVirtXY(x, y)) { // check if we're only within one tile |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1970 |
if (method == VPM_RAILDIRS) { |
2116 | 1971 |
b = GetAutorailHT(x, y); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1972 |
} else { // rect for autosignals on one tile |
2116 | 1973 |
b = HT_RECT; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1974 |
} |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1975 |
} else if (h == 16) { // Is this in X direction? |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1976 |
if (dx == 16) { // 2x1 special handling |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1977 |
b = (Check2x1AutoRail(3)) | HT_LINE; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1978 |
} else if (dx == -16) { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1979 |
b = (Check2x1AutoRail(2)) | HT_LINE; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1980 |
} else { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1981 |
b = HT_LINE | HT_DIR_X; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1982 |
} |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1983 |
y = thd->selstart.y; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1984 |
} else if (w == 16) { // Or Y direction? |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1985 |
if (dy == 16) { // 2x1 special handling |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1986 |
b = (Check2x1AutoRail(1)) | HT_LINE; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1987 |
} else if (dy == -16) { // 2x1 other direction |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1988 |
b = (Check2x1AutoRail(0)) | HT_LINE; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1989 |
} else { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1990 |
b = HT_LINE | HT_DIR_Y; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1991 |
} |
0 | 1992 |
x = thd->selstart.x; |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1993 |
} else if (w > h * 2) { // still count as x dir? |
2116 | 1994 |
b = HT_LINE | HT_DIR_X; |
0 | 1995 |
y = thd->selstart.y; |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1996 |
} else if (h > w * 2) { // still count as y dir? |
2116 | 1997 |
b = HT_LINE | HT_DIR_Y; |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1998 |
x = thd->selstart.x; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1999 |
} else { // complicated direction |
0 | 2000 |
d = w - h; |
2116 | 2001 |
thd->selend.x = thd->selend.x & ~0xF; |
2002 |
thd->selend.y = thd->selend.y & ~0xF; |
|
0 | 2003 |
|
2004 |
// four cases. |
|
2005 |
if (x > thd->selstart.x) { |
|
2006 |
if (y > thd->selstart.y) { |
|
2007 |
// south |
|
2116 | 2008 |
if (d == 0) { |
2009 |
b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR; |
|
2010 |
} else if (d >= 0) { |
|
2011 |
x = thd->selstart.x + h; |
|
2012 |
b = HT_LINE | HT_DIR_VL; |
|
2013 |
// return px == py || px == py + 16; |
|
2014 |
} else { |
|
2015 |
y = thd->selstart.y + w; |
|
2016 |
b = HT_LINE | HT_DIR_VR; |
|
2017 |
} // return px == py || px == py - 16; |
|
0 | 2018 |
} else { |
2019 |
// west |
|
2116 | 2020 |
if (d == 0) { |
2021 |
b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU; |
|
2022 |
} else if (d >= 0) { |
|
2023 |
x = thd->selstart.x + h; |
|
2024 |
b = HT_LINE | HT_DIR_HL; |
|
2025 |
} else { |
|
2026 |
y = thd->selstart.y - w; |
|
2027 |
b = HT_LINE | HT_DIR_HU; |
|
2028 |
} |
|
0 | 2029 |
} |
2030 |
} else { |
|
2031 |
if (y > thd->selstart.y) { |
|
2032 |
// east |
|
2116 | 2033 |
if (d == 0) { |
2034 |
b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU; |
|
2035 |
} else if (d >= 0) { |
|
2036 |
x = thd->selstart.x - h; |
|
2037 |
b = HT_LINE | HT_DIR_HU; |
|
2038 |
// return px == -py || px == -py - 16; |
|
2039 |
} else { |
|
2040 |
y = thd->selstart.y + w; |
|
2041 |
b = HT_LINE | HT_DIR_HL; |
|
2042 |
} // return px == -py || px == -py + 16; |
|
0 | 2043 |
} else { |
2044 |
// north |
|
2116 | 2045 |
if (d == 0) { |
2046 |
b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR; |
|
2047 |
} else if (d >= 0) { |
|
2048 |
x = thd->selstart.x - h; |
|
2049 |
b = HT_LINE | HT_DIR_VR; |
|
2050 |
// return px == py || px == py - 16; |
|
2051 |
} else { |
|
2052 |
y = thd->selstart.y - w; |
|
2053 |
b = HT_LINE | HT_DIR_VL; |
|
2054 |
} //return px == py || px == py + 16; |
|
0 | 2055 |
} |
2056 |
} |
|
2057 |
} |
|
2058 |
thd->selend.x = x; |
|
2059 |
thd->selend.y = y; |
|
2060 |
thd->next_drawstyle = b; |
|
2061 |
} |
|
2062 |
||
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2063 |
// while dragging |
0 | 2064 |
void VpSelectTilesWithMethod(int x, int y, int method) |
2065 |
{ |
|
2116 | 2066 |
int sx; |
2067 |
int sy; |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2068 |
|
0 | 2069 |
if (x == -1) { |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2070 |
_thd.selend.x = -1; |
0 | 2071 |
return; |
2072 |
} |
|
2073 |
||
2074 |
// allow drag in any rail 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
|
2075 |
if (method == VPM_RAILDIRS || method == VPM_SIGNALDIRS) { |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2076 |
_thd.selend.x = x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2077 |
_thd.selend.y = y; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2078 |
CalcRaildirsDrawstyle(&_thd, x, y, method); |
0 | 2079 |
return; |
2080 |
} |
|
2081 |
||
2116 | 2082 |
if (_thd.next_drawstyle == HT_POINT) { |
2083 |
x += 8; |
|
2084 |
y += 8; |
|
2085 |
} |
|
0 | 2086 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2087 |
sx = _thd.selstart.x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2088 |
sy = _thd.selstart.y; |
0 | 2089 |
|
2116 | 2090 |
switch (method) { |
2091 |
case VPM_FIX_X: |
|
2092 |
x = sx; |
|
2093 |
break; |
|
0 | 2094 |
|
2116 | 2095 |
case VPM_FIX_Y: |
2096 |
y = sy; |
|
2097 |
break; |
|
0 | 2098 |
|
2116 | 2099 |
case VPM_X_OR_Y: |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2100 |
if (myabs(sy - y) < myabs(sx - x)) { |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2101 |
y = sy; |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2102 |
} else { |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2103 |
x = sx; |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2104 |
} |
2116 | 2105 |
break; |
2106 |
||
2107 |
case VPM_X_AND_Y: |
|
2108 |
break; |
|
2109 |
||
2110 |
// limit the selected area to a 10x10 rect. |
|
2111 |
case VPM_X_AND_Y_LIMITED: { |
|
2112 |
int limit = (_thd.sizelimit - 1) * 16; |
|
2113 |
x = sx + clamp(x - sx, -limit, limit); |
|
2114 |
y = sy + clamp(y - sy, -limit, limit); |
|
2115 |
break; |
|
2116 |
} |
|
0 | 2117 |
} |
2118 |
||
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2119 |
_thd.selend.x = x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2120 |
_thd.selend.y = y; |
0 | 2121 |
} |
2122 |
||
1109
ecb98f43ba2c
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
2123 |
// while dragging |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
2124 |
bool VpHandlePlaceSizingDrag(void) |
0 | 2125 |
{ |
2126 |
Window *w; |
|
2127 |
WindowEvent e; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2128 |
|
2116 | 2129 |
if (_special_mouse_mode != WSM_SIZING) return true; |
0 | 2130 |
|
2131 |
e.place.userdata = _thd.userdata; |
|
2132 |
||
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2133 |
// stop drag mode if the window has been closed |
0 | 2134 |
w = FindWindowById(_thd.window_class,_thd.window_number); |
2135 |
if (w == NULL) { |
|
2136 |
ResetObjectToPlace(); |
|
2137 |
return false; |
|
2138 |
} |
|
2139 |
||
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2140 |
// while dragging execute the drag procedure of the corresponding window (mostly VpSelectTilesWithMethod() ) |
0 | 2141 |
if (_left_button_down) { |
2142 |
e.event = WE_PLACE_DRAG; |
|
2143 |
e.place.pt = GetTileBelowCursor(); |
|
2144 |
w->wndproc(w, &e); |
|
2145 |
return false; |
|
2146 |
} |
|
2147 |
||
2148 |
// mouse button released.. |
|
2149 |
// 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
|
2150 |
_special_mouse_mode = WSM_NONE; |
2116 | 2151 |
if (_thd.next_drawstyle == HT_RECT) { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2152 |
_thd.place_mode = VHM_RECT; |
2116 | 2153 |
} else if ((e.place.userdata & 0xF) == VPM_SIGNALDIRS) { // some might call this a hack... -- Dominik |
2154 |
_thd.place_mode = VHM_RECT; |
|
2155 |
} else if (_thd.next_drawstyle & HT_LINE) { |
|
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2156 |
_thd.place_mode = VHM_RAIL; |
2116 | 2157 |
} else if (_thd.next_drawstyle & HT_RAIL) { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2158 |
_thd.place_mode = VHM_RAIL; |
2116 | 2159 |
} else { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2160 |
_thd.place_mode = VHM_POINT; |
2116 | 2161 |
} |
0 | 2162 |
SetTileSelectSize(1, 1); |
2163 |
||
2164 |
// and call the mouseup event. |
|
2165 |
e.event = WE_PLACE_MOUSEUP; |
|
2166 |
e.place.pt = _thd.selend; |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
2167 |
e.place.tile = TileVirtXY(e.place.pt.x, e.place.pt.y); |
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
2168 |
e.place.starttile = TileVirtXY(_thd.selstart.x, _thd.selstart.y); |
0 | 2169 |
w->wndproc(w, &e); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2170 |
|
0 | 2171 |
return false; |
2172 |
} |
|
2173 |
||
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
2174 |
void SetObjectToPlaceWnd(CursorID icon, byte mode, Window *w) |
0 | 2175 |
{ |
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
2176 |
SetObjectToPlace(icon, mode, w->window_class, w->window_number); |
0 | 2177 |
} |
2178 |
||
2179 |
#include "table/animcursors.h" |
|
2180 |
||
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
2181 |
void SetObjectToPlace(CursorID icon, byte mode, WindowClass window_class, WindowNumber window_num) |
0 | 2182 |
{ |
2183 |
Window *w; |
|
2184 |
||
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2185 |
// undo clicking on button |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2186 |
if (_thd.place_mode != 0) { |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2187 |
_thd.place_mode = 0; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2188 |
w = FindWindowById(_thd.window_class, _thd.window_number); |
2116 | 2189 |
if (w != NULL) CallWindowEventNP(w, WE_ABORT_PLACE_OBJ); |
0 | 2190 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2191 |
|
0 | 2192 |
SetTileSelectSize(1, 1); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2193 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2194 |
_thd.make_square_red = false; |
0 | 2195 |
|
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2196 |
if (mode == VHM_DRAG) { // mode 4 is for dragdropping trains in the depot window |
0 | 2197 |
mode = 0; |
2198 |
_special_mouse_mode = WSM_DRAGDROP; |
|
2199 |
} else { |
|
2200 |
_special_mouse_mode = WSM_NONE; |
|
2201 |
} |
|
2202 |
||
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2203 |
_thd.place_mode = mode; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2204 |
_thd.window_class = window_class; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2205 |
_thd.window_number = window_num; |
0 | 2206 |
|
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2207 |
if (mode == VHM_SPECIAL) // special tools, like tunnels or docks start with presizing mode |
0 | 2208 |
VpStartPreSizing(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2209 |
|
0 | 2210 |
if ( (int)icon < 0) |
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2482
diff
changeset
|
2211 |
SetAnimatedMouseCursor(_animcursors[~icon]); |
0 | 2212 |
else |
2213 |
SetMouseCursor(icon); |
|
2214 |
} |
|
2215 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
2216 |
void ResetObjectToPlace(void) |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
2217 |
{ |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2218 |
SetObjectToPlace(SPR_CURSOR_MOUSE, VHM_NONE, 0, 0); |
0 | 2219 |
} |