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