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