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