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