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