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