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