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