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