author | celestar |
Fri, 29 Dec 2006 12:03:28 +0000 | |
branch | custombridgeheads |
changeset 5594 | 04068f82afaa |
parent 5568 | 75f13d7bfaed |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1864
diff
changeset
|
4 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1172
diff
changeset
|
5 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
6 |
#include "functions.h" |
2662
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
7 |
#include "gui.h" |
1349
07514c2cc6d1
(svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents:
1309
diff
changeset
|
8 |
#include "spritecache.h" |
1309
dab90d4cbf2d
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1299
diff
changeset
|
9 |
#include "strings.h" |
1363
01d3de5d8039
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1349
diff
changeset
|
10 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
500
diff
changeset
|
11 |
#include "table/strings.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
657
diff
changeset
|
12 |
#include "map.h" |
0 | 13 |
#include "viewport.h" |
14 |
#include "window.h" |
|
15 |
#include "vehicle.h" |
|
16 |
#include "station.h" |
|
17 |
#include "gfx.h" |
|
18 |
#include "town.h" |
|
988
2482369a61ff
(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
981
diff
changeset
|
19 |
#include "signs.h" |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
20 |
#include "waypoint.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2125
diff
changeset
|
21 |
#include "variables.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2662
diff
changeset
|
22 |
#include "train.h" |
0 | 23 |
|
133
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
24 |
#define VIEWPORT_DRAW_MEM (65536 * 2) |
0 | 25 |
|
5122
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
26 |
/* viewport.c */ |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
27 |
// XXX - maximum viewports is maximum windows - 2 (main toolbar + status bar) |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
28 |
static ViewPort _viewports[25 - 2]; |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
29 |
static uint32 _active_viewports; ///< bitmasked variable where each bit signifies if a viewport is in use or not |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
30 |
assert_compile(lengthof(_viewports) < sizeof(_active_viewports) * 8); |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
31 |
|
0 | 32 |
static bool _added_tile_sprite; |
33 |
static bool _offset_ground_sprites; |
|
34 |
||
4186
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
35 |
/* The in-game coordiante system looks like this * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
36 |
* * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
37 |
* ^ Z * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
38 |
* | * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
39 |
* | * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
40 |
* | * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
41 |
* | * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
42 |
* / \ * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
43 |
* / \ * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
44 |
* / \ * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
45 |
* / \ * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
46 |
* X < > Y * |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
47 |
*/ |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
48 |
|
0 | 49 |
typedef struct StringSpriteToDraw { |
50 |
uint16 string; |
|
51 |
uint16 color; |
|
52 |
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
|
53 |
int32 x; |
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
54 |
int32 y; |
5026
c8b7148798ac
(svn r7067) Remove the unused parameter params_3 from AddStringToDraw()
tron
parents:
5025
diff
changeset
|
55 |
uint32 params[2]; |
0 | 56 |
uint16 width; |
57 |
} StringSpriteToDraw; |
|
58 |
||
59 |
typedef struct TileSpriteToDraw { |
|
60 |
uint32 image; |
|
61 |
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
|
62 |
int32 x; |
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
63 |
int32 y; |
0 | 64 |
byte z; |
65 |
} TileSpriteToDraw; |
|
66 |
||
67 |
typedef struct ChildScreenSpriteToDraw { |
|
68 |
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
|
69 |
int32 x; |
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
70 |
int32 y; |
0 | 71 |
struct ChildScreenSpriteToDraw *next; |
72 |
} ChildScreenSpriteToDraw; |
|
73 |
||
74 |
typedef struct ParentSpriteToDraw { |
|
75 |
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
|
76 |
int32 left; |
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
77 |
int32 top; |
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
78 |
int32 right; |
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
79 |
int32 bottom; |
4186
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
80 |
int32 xmin; |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
81 |
int32 ymin; |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
82 |
int32 xmax; |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
83 |
int32 ymax; |
0 | 84 |
ChildScreenSpriteToDraw *child; |
85 |
byte unk16; |
|
4186
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
86 |
byte zmin; |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
87 |
byte zmax; |
0 | 88 |
} ParentSpriteToDraw; |
89 |
||
2109
c3202f3988df
(svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents:
2085
diff
changeset
|
90 |
// Quick hack to know how much memory to reserve when allocating from the spritelist |
c3202f3988df
(svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents:
2085
diff
changeset
|
91 |
// to prevent a buffer overflow. |
c3202f3988df
(svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents:
2085
diff
changeset
|
92 |
#define LARGEST_SPRITELIST_STRUCT ParentSpriteToDraw |
c3202f3988df
(svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents:
2085
diff
changeset
|
93 |
|
0 | 94 |
typedef struct ViewportDrawer { |
95 |
DrawPixelInfo dpi; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
96 |
|
2116 | 97 |
byte *spritelist_mem; |
98 |
const byte *eof_spritelist_mem; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
99 |
|
0 | 100 |
StringSpriteToDraw **last_string, *first_string; |
101 |
TileSpriteToDraw **last_tile, *first_tile; |
|
102 |
||
103 |
ChildScreenSpriteToDraw **last_child; |
|
104 |
||
105 |
ParentSpriteToDraw **parent_list; |
|
2116 | 106 |
ParentSpriteToDraw * const *eof_parent_list; |
0 | 107 |
|
108 |
byte combine_sprites; |
|
109 |
||
110 |
int offs_x, offs_y; // used when drawing ground sprites relative |
|
111 |
} ViewportDrawer; |
|
112 |
||
113 |
static ViewportDrawer *_cur_vd; |
|
114 |
||
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
115 |
TileHighlightData _thd; |
0 | 116 |
static TileInfo *_cur_ti; |
117 |
||
4340
1b2bf292033b
(svn r6041) -Fix r6040: forgot to declare a function in viewport.c
truelight
parents:
4339
diff
changeset
|
118 |
extern void SmallMapCenterOnCurrentPos(Window *w); |
0 | 119 |
|
2116 | 120 |
static Point MapXYZToViewport(const ViewPort *vp, uint x, uint y, uint z) |
0 | 121 |
{ |
122 |
Point p = RemapCoords(x, y, z); |
|
2116 | 123 |
p.x -= vp->virtual_width / 2; |
124 |
p.y -= vp->virtual_height / 2; |
|
0 | 125 |
return p; |
126 |
} |
|
127 |
||
5122
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
128 |
void InitViewports(void) { |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
129 |
memset(_viewports, 0, sizeof(_viewports)); |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
130 |
_active_viewports = 0; |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
131 |
} |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
132 |
|
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
133 |
void DeleteWindowViewport(Window *w) |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
134 |
{ |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
135 |
CLRBIT(_active_viewports, w->viewport - _viewports); |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
136 |
w->viewport->width = 0; |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
137 |
w->viewport = NULL; |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
138 |
} |
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
139 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
140 |
void AssignWindowViewport(Window *w, int x, int y, |
0 | 141 |
int width, int height, uint32 follow_flags, byte zoom) |
142 |
{ |
|
143 |
ViewPort *vp; |
|
144 |
Point pt; |
|
145 |
uint32 bit; |
|
146 |
||
5122
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
147 |
for (vp = _viewports, bit = 0; ; vp++, bit++) { |
2116 | 148 |
assert(vp != endof(_viewports)); |
149 |
if (vp->width == 0) break; |
|
0 | 150 |
} |
5122
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
151 |
SETBIT(_active_viewports, bit); |
0 | 152 |
|
153 |
vp->left = x + w->left; |
|
154 |
vp->top = y + w->top; |
|
155 |
vp->width = width; |
|
156 |
vp->height = height; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
157 |
|
0 | 158 |
vp->zoom = zoom; |
159 |
||
160 |
vp->virtual_width = width << zoom; |
|
161 |
vp->virtual_height = height << zoom; |
|
162 |
||
163 |
if (follow_flags & 0x80000000) { |
|
2116 | 164 |
const Vehicle *veh; |
165 |
||
166 |
WP(w, vp_d).follow_vehicle = (VehicleID)(follow_flags & 0xFFFF); |
|
167 |
veh = GetVehicle(WP(w, vp_d).follow_vehicle); |
|
0 | 168 |
pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos); |
169 |
} else { |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
170 |
uint x = TileX(follow_flags) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
171 |
uint y = TileY(follow_flags) * TILE_SIZE; |
2116 | 172 |
|
173 |
WP(w, vp_d).follow_vehicle = INVALID_VEHICLE; |
|
174 |
pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y)); |
|
0 | 175 |
} |
176 |
||
2116 | 177 |
WP(w, vp_d).scrollpos_x = pt.x; |
178 |
WP(w, vp_d).scrollpos_y = pt.y; |
|
0 | 179 |
w->viewport = vp; |
180 |
vp->virtual_left = 0;//pt.x; |
|
181 |
vp->virtual_top = 0;//pt.y; |
|
182 |
} |
|
183 |
||
184 |
static Point _vp_move_offs; |
|
185 |
||
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5124
diff
changeset
|
186 |
static void DoSetViewportPosition(Window* const *wz, int left, int top, int width, int height) |
0 | 187 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
188 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
189 |
for (; wz != _last_z_window; wz++) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
190 |
const Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
191 |
|
0 | 192 |
if (left + width > w->left && |
2116 | 193 |
w->left + w->width > left && |
0 | 194 |
top + height > w->top && |
2116 | 195 |
w->top + w->height > top) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
196 |
|
0 | 197 |
if (left < w->left) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
198 |
DoSetViewportPosition(wz, left, top, w->left - left, height); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
199 |
DoSetViewportPosition(wz, left + (w->left - left), top, width - (w->left - left), height); |
0 | 200 |
return; |
201 |
} |
|
202 |
||
203 |
if (left + width > w->left + w->width) { |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
204 |
DoSetViewportPosition(wz, left, top, (w->left + w->width - left), height); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
205 |
DoSetViewportPosition(wz, left + (w->left + w->width - left), top, width - (w->left + w->width - left) , height); |
0 | 206 |
return; |
207 |
} |
|
208 |
||
209 |
if (top < w->top) { |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
210 |
DoSetViewportPosition(wz, left, top, width, (w->top - top)); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
211 |
DoSetViewportPosition(wz, left, top + (w->top - top), width, height - (w->top - top)); |
0 | 212 |
return; |
213 |
} |
|
214 |
||
215 |
if (top + height > w->top + w->height) { |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
216 |
DoSetViewportPosition(wz, left, top, width, (w->top + w->height - top)); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
217 |
DoSetViewportPosition(wz, left, top + (w->top + w->height - top), width , height - (w->top + w->height - top)); |
0 | 218 |
return; |
219 |
} |
|
220 |
||
221 |
return; |
|
222 |
} |
|
223 |
} |
|
224 |
||
225 |
{ |
|
226 |
int xo = _vp_move_offs.x; |
|
227 |
int yo = _vp_move_offs.y; |
|
228 |
||
229 |
if (abs(xo) >= width || abs(yo) >= height) { |
|
230 |
/* fully_outside */ |
|
2116 | 231 |
RedrawScreenRect(left, top, left + width, top + height); |
0 | 232 |
return; |
233 |
} |
|
234 |
||
235 |
GfxScroll(left, top, width, height, xo, yo); |
|
236 |
||
237 |
if (xo > 0) { |
|
238 |
RedrawScreenRect(left, top, xo + left, top + height); |
|
239 |
left += xo; |
|
240 |
width -= xo; |
|
241 |
} else if (xo < 0) { |
|
242 |
RedrawScreenRect(left+width+xo, top, left+width, top + height); |
|
243 |
width += xo; |
|
244 |
} |
|
245 |
||
246 |
if (yo > 0) { |
|
247 |
RedrawScreenRect(left, top, width+left, top + yo); |
|
248 |
} else if (yo < 0) { |
|
249 |
RedrawScreenRect(left, top + height + yo, width+left, top + height); |
|
250 |
} |
|
251 |
} |
|
252 |
} |
|
253 |
||
4171 | 254 |
static void SetViewportPosition(Window *w, int x, int y) |
0 | 255 |
{ |
256 |
ViewPort *vp = w->viewport; |
|
257 |
int old_left = vp->virtual_left; |
|
258 |
int old_top = vp->virtual_top; |
|
259 |
int i; |
|
260 |
int left, top, width, height; |
|
261 |
||
262 |
vp->virtual_left = x; |
|
263 |
vp->virtual_top = y; |
|
264 |
||
265 |
old_left >>= vp->zoom; |
|
266 |
old_top >>= vp->zoom; |
|
267 |
x >>= vp->zoom; |
|
268 |
y >>= vp->zoom; |
|
269 |
||
270 |
old_left -= x; |
|
271 |
old_top -= y; |
|
272 |
||
2116 | 273 |
if (old_top == 0 && old_left == 0) return; |
0 | 274 |
|
275 |
_vp_move_offs.x = old_left; |
|
276 |
_vp_move_offs.y = old_top; |
|
277 |
||
278 |
left = vp->left; |
|
279 |
top = vp->top; |
|
280 |
width = vp->width; |
|
281 |
height = vp->height; |
|
282 |
||
283 |
if (left < 0) { |
|
284 |
width += left; |
|
285 |
left = 0; |
|
286 |
} |
|
287 |
||
2116 | 288 |
i = left + width - _screen.width; |
289 |
if (i >= 0) width -= i; |
|
0 | 290 |
|
291 |
if (width > 0) { |
|
292 |
if (top < 0) { |
|
293 |
height += top; |
|
294 |
top = 0; |
|
295 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
296 |
|
2116 | 297 |
i = top + height - _screen.height; |
298 |
if (i >= 0) height -= i; |
|
0 | 299 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
300 |
if (height > 0) DoSetViewportPosition(FindWindowZPosition(w) + 1, left, top, width, height); |
0 | 301 |
} |
302 |
} |
|
303 |
||
304 |
||
2116 | 305 |
ViewPort *IsPtInWindowViewport(const Window *w, int x, int y) |
0 | 306 |
{ |
307 |
ViewPort *vp = w->viewport; |
|
2116 | 308 |
|
0 | 309 |
if (vp != NULL && |
310 |
IS_INT_INSIDE(x, vp->left, vp->left + vp->width) && |
|
311 |
IS_INT_INSIDE(y, vp->top, vp->top + vp->height)) |
|
312 |
return vp; |
|
313 |
||
314 |
return NULL; |
|
315 |
} |
|
316 |
||
2116 | 317 |
static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y) |
1095 | 318 |
{ |
0 | 319 |
Point pt; |
320 |
int a,b; |
|
5014
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
321 |
uint z; |
0 | 322 |
|
323 |
if ( (uint)(x -= vp->left) >= (uint)vp->width || |
|
324 |
(uint)(y -= vp->top) >= (uint)vp->height) { |
|
325 |
Point pt = {-1, -1}; |
|
326 |
return pt; |
|
327 |
} |
|
328 |
||
329 |
x = ((x << vp->zoom) + vp->virtual_left) >> 2; |
|
330 |
y = ((y << vp->zoom) + vp->virtual_top) >> 1; |
|
331 |
||
332 |
#if !defined(NEW_ROTATION) |
|
333 |
a = y-x; |
|
334 |
b = y+x; |
|
335 |
#else |
|
336 |
a = x+y; |
|
337 |
b = x-y; |
|
338 |
#endif |
|
339 |
||
5014
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
340 |
/* we need to move variables in to the valid range, as the |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
341 |
* GetTileZoomCenterWindow() function can call here with invalid x and/or y, |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
342 |
* when the user tries to zoom out along the sides of the map */ |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
343 |
a = clamp(a, 0, (int)(MapMaxX() * TILE_SIZE) - 1); |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
344 |
b = clamp(b, 0, (int)(MapMaxY() * TILE_SIZE) - 1); |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
345 |
|
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
346 |
z = GetSlopeZ(a, b ) / 2; |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
347 |
z = GetSlopeZ(a + z, b + z) / 2; |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
348 |
z = GetSlopeZ(a + z, b + z) / 2; |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
349 |
z = GetSlopeZ(a + z, b + z) / 2; |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
350 |
z = GetSlopeZ(a + z, b + z) / 2; |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
351 |
|
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
352 |
pt.x = a + z; |
aaa61af89635
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
353 |
pt.y = b + z; |
0 | 354 |
|
355 |
return pt; |
|
356 |
} |
|
357 |
||
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
|
358 |
/* 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
|
359 |
* 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
|
360 |
* 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
|
361 |
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
|
362 |
{ |
0 | 363 |
Window *w; |
364 |
ViewPort *vp; |
|
365 |
Point pt; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
366 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
367 |
if ( (w = FindWindowFromPt(x, y)) != NULL && |
0 | 368 |
(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
|
369 |
return TranslateXYToTileCoord(vp, zoom_x, zoom_y); |
0 | 370 |
|
371 |
pt.y = pt.x = -1; |
|
372 |
return pt; |
|
373 |
} |
|
374 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
375 |
Point GetTileBelowCursor(void) |
0 | 376 |
{ |
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
|
377 |
return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, _cursor.pos.x, _cursor.pos.y); |
0 | 378 |
} |
379 |
||
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
|
380 |
|
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
|
381 |
Point GetTileZoomCenterWindow(bool in, Window * w) |
0 | 382 |
{ |
383 |
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
|
384 |
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
|
385 |
|
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
|
386 |
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
|
387 |
|
2026 | 388 |
if (in) { |
2116 | 389 |
x = ((_cursor.pos.x - vp->left) >> 1) + (vp->width >> 2); |
390 |
y = ((_cursor.pos.y - vp->top) >> 1) + (vp->height >> 2); |
|
391 |
} 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
|
392 |
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
|
393 |
y = vp->height - (_cursor.pos.y - vp->top); |
0 | 394 |
} |
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
|
395 |
/* 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
|
396 |
return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, x + vp->left, y + vp->top); |
0 | 397 |
} |
398 |
||
5045
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
399 |
/** Update the status of the zoom-buttons according to the zoom-level |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
400 |
* of the viewport. This will update their status and invalidate accordingly |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
401 |
* @param window pointer to the window that has the zoom buttons |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
402 |
* @param vp pointer to the viewport whose zoom-level the buttons represent |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
403 |
* @param widget_zoom_in widget index for window with zoom-in button |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
404 |
* @param widget_zoom_out widget index for window with zoom-out button */ |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
405 |
void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out) |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
406 |
{ |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
407 |
SetWindowWidgetDisabledState(w, widget_zoom_in, vp->zoom == 0); |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
408 |
InvalidateWidget(w, widget_zoom_in); |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
409 |
|
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
410 |
SetWindowWidgetDisabledState(w, widget_zoom_out, vp->zoom == 2); |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
411 |
InvalidateWidget(w, widget_zoom_out); |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
412 |
} |
3e734e178dae
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
413 |
|
849
c6223dbdb202
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
414 |
void DrawGroundSpriteAt(uint32 image, int32 x, int32 y, byte z) |
0 | 415 |
{ |
416 |
ViewportDrawer *vd = _cur_vd; |
|
417 |
TileSpriteToDraw *ts; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
418 |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
419 |
assert((image & SPRITE_MASK) < MAX_SPRITES); |
0 | 420 |
|
2116 | 421 |
if (vd->spritelist_mem >= vd->eof_spritelist_mem) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5137
diff
changeset
|
422 |
DEBUG(sprite, 0, "Out of sprite memory"); |
0 | 423 |
return; |
424 |
} |
|
2116 | 425 |
ts = (TileSpriteToDraw*)vd->spritelist_mem; |
0 | 426 |
|
427 |
vd->spritelist_mem += sizeof(TileSpriteToDraw); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
428 |
|
0 | 429 |
ts->image = image; |
430 |
ts->next = NULL; |
|
431 |
ts->x = x; |
|
432 |
ts->y = y; |
|
433 |
ts->z = z; |
|
434 |
*vd->last_tile = ts; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
435 |
vd->last_tile = &ts->next; |
0 | 436 |
} |
437 |
||
438 |
void DrawGroundSprite(uint32 image) |
|
439 |
{ |
|
440 |
if (_offset_ground_sprites) { |
|
441 |
// offset ground sprite because of foundation? |
|
442 |
AddChildSpriteScreen(image, _cur_vd->offs_x, _cur_vd->offs_y); |
|
443 |
} else { |
|
1083
2e9d525af38d
(svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents:
1070
diff
changeset
|
444 |
_added_tile_sprite = true; |
0 | 445 |
DrawGroundSpriteAt(image, _cur_ti->x, _cur_ti->y, _cur_ti->z); |
446 |
} |
|
447 |
} |
|
448 |
||
449 |
||
450 |
void OffsetGroundSprite(int x, int y) |
|
451 |
{ |
|
452 |
_cur_vd->offs_x = x; |
|
453 |
_cur_vd->offs_y = y; |
|
454 |
_offset_ground_sprites = true; |
|
455 |
} |
|
456 |
||
457 |
static void AddCombinedSprite(uint32 image, int x, int y, byte z) |
|
458 |
{ |
|
2116 | 459 |
const ViewportDrawer *vd = _cur_vd; |
0 | 460 |
Point pt = RemapCoords(x, y, z); |
2319
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
461 |
const Sprite* spr = GetSprite(image & SPRITE_MASK); |
0 | 462 |
|
2319
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
463 |
if (pt.x + spr->x_offs >= vd->dpi.left + vd->dpi.width || |
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
464 |
pt.x + spr->x_offs + spr->width <= vd->dpi.left || |
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
465 |
pt.y + spr->y_offs >= vd->dpi.top + vd->dpi.height || |
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
466 |
pt.y + spr->y_offs + spr->height <= vd->dpi.top) |
0 | 467 |
return; |
468 |
||
2116 | 469 |
AddChildSpriteScreen(image, pt.x - vd->parent_list[-1]->left, pt.y - vd->parent_list[-1]->top); |
0 | 470 |
} |
471 |
||
472 |
||
473 |
void AddSortableSpriteToDraw(uint32 image, int x, int y, int w, int h, byte dz, byte z) |
|
474 |
{ |
|
475 |
ViewportDrawer *vd = _cur_vd; |
|
476 |
ParentSpriteToDraw *ps; |
|
4171 | 477 |
const Sprite *spr; |
0 | 478 |
Point pt; |
479 |
||
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
480 |
assert((image & SPRITE_MASK) < MAX_SPRITES); |
0 | 481 |
|
482 |
if (vd->combine_sprites == 2) { |
|
483 |
AddCombinedSprite(image, x, y, z); |
|
484 |
return; |
|
485 |
} |
|
486 |
||
487 |
vd->last_child = NULL; |
|
488 |
||
2116 | 489 |
if (vd->spritelist_mem >= vd->eof_spritelist_mem) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5137
diff
changeset
|
490 |
DEBUG(sprite, 0, "Out of sprite memory"); |
0 | 491 |
return; |
492 |
} |
|
2116 | 493 |
ps = (ParentSpriteToDraw*)vd->spritelist_mem; |
494 |
||
133
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
495 |
if (vd->parent_list >= vd->eof_parent_list) { |
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
496 |
// 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
|
497 |
// 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
|
498 |
// sort-list, this function). To solve it, increase |
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
499 |
// parent_list somewhere below to a higher number. |
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
500 |
// 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
|
501 |
// spots on the screen ;) |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5137
diff
changeset
|
502 |
DEBUG(sprite, 0, "Out of sprite memory (parent_list)"); |
133
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
503 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
504 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
505 |
|
4189
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
506 |
pt = RemapCoords(x, y, z); |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
507 |
spr = GetSprite(image & SPRITE_MASK); |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
508 |
if ((ps->left = (pt.x += spr->x_offs)) >= vd->dpi.left + vd->dpi.width || |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
509 |
(ps->right = (pt.x + spr->width )) <= vd->dpi.left || |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
510 |
(ps->top = (pt.y += spr->y_offs)) >= vd->dpi.top + vd->dpi.height || |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
511 |
(ps->bottom = (pt.y + spr->height)) <= vd->dpi.top) { |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
512 |
return; |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
513 |
} |
258f98b17f57
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
514 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
515 |
vd->spritelist_mem += sizeof(ParentSpriteToDraw); |
0 | 516 |
|
517 |
ps->image = image; |
|
4186
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
518 |
ps->xmin = x; |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
519 |
ps->xmax = x + w - 1; |
0 | 520 |
|
4186
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
521 |
ps->ymin = y; |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
522 |
ps->ymax = y + h - 1; |
0 | 523 |
|
4186
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
524 |
ps->zmin = z; |
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
525 |
ps->zmax = z + dz - 1; |
0 | 526 |
|
527 |
ps->unk16 = 0; |
|
528 |
ps->child = NULL; |
|
529 |
vd->last_child = &ps->child; |
|
530 |
||
531 |
*vd->parent_list++ = ps; |
|
532 |
||
2116 | 533 |
if (vd->combine_sprites == 1) vd->combine_sprites = 2; |
0 | 534 |
} |
535 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
536 |
void StartSpriteCombine(void) |
0 | 537 |
{ |
538 |
_cur_vd->combine_sprites = 1; |
|
539 |
} |
|
540 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
541 |
void EndSpriteCombine(void) |
0 | 542 |
{ |
543 |
_cur_vd->combine_sprites = 0; |
|
544 |
} |
|
545 |
||
546 |
void AddChildSpriteScreen(uint32 image, int x, int y) |
|
547 |
{ |
|
548 |
ViewportDrawer *vd = _cur_vd; |
|
549 |
ChildScreenSpriteToDraw *cs; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
550 |
|
2187
2a51f8925eeb
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
551 |
assert((image & SPRITE_MASK) < MAX_SPRITES); |
0 | 552 |
|
2116 | 553 |
if (vd->spritelist_mem >= vd->eof_spritelist_mem) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5137
diff
changeset
|
554 |
DEBUG(sprite, 0, "Out of sprite memory"); |
0 | 555 |
return; |
556 |
} |
|
2116 | 557 |
cs = (ChildScreenSpriteToDraw*)vd->spritelist_mem; |
0 | 558 |
|
2116 | 559 |
if (vd->last_child == NULL) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
560 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
561 |
vd->spritelist_mem += sizeof(ChildScreenSpriteToDraw); |
0 | 562 |
|
563 |
*vd->last_child = cs; |
|
564 |
vd->last_child = &cs->next; |
|
565 |
||
566 |
cs->image = image; |
|
567 |
cs->x = x; |
|
568 |
cs->y = y; |
|
569 |
cs->next = NULL; |
|
570 |
} |
|
571 |
||
572 |
/* Returns a StringSpriteToDraw */ |
|
5026
c8b7148798ac
(svn r7067) Remove the unused parameter params_3 from AddStringToDraw()
tron
parents:
5025
diff
changeset
|
573 |
void *AddStringToDraw(int x, int y, StringID string, uint32 params_1, uint32 params_2) |
0 | 574 |
{ |
575 |
ViewportDrawer *vd = _cur_vd; |
|
576 |
StringSpriteToDraw *ss; |
|
577 |
||
2116 | 578 |
if (vd->spritelist_mem >= vd->eof_spritelist_mem) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5137
diff
changeset
|
579 |
DEBUG(sprite, 0, "Out of sprite memory"); |
0 | 580 |
return NULL; |
581 |
} |
|
2116 | 582 |
ss = (StringSpriteToDraw*)vd->spritelist_mem; |
0 | 583 |
|
584 |
vd->spritelist_mem += sizeof(StringSpriteToDraw); |
|
585 |
||
586 |
ss->string = string; |
|
587 |
ss->next = NULL; |
|
588 |
ss->x = x; |
|
589 |
ss->y = y; |
|
590 |
ss->params[0] = params_1; |
|
591 |
ss->params[1] = params_2; |
|
592 |
ss->width = 0; |
|
593 |
||
594 |
*vd->last_string = ss; |
|
595 |
vd->last_string = &ss->next; |
|
596 |
||
597 |
return ss; |
|
598 |
} |
|
599 |
||
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3809
diff
changeset
|
600 |
|
0 | 601 |
static void DrawSelectionSprite(uint32 image, const TileInfo *ti) |
602 |
{ |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
603 |
if (_added_tile_sprite && !(_thd.drawstyle & HT_LINE)) { // draw on real ground |
1083
2e9d525af38d
(svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents:
1070
diff
changeset
|
604 |
DrawGroundSpriteAt(image, ti->x, ti->y, ti->z + 7); |
2e9d525af38d
(svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents:
1070
diff
changeset
|
605 |
} else { // draw on top of foundation |
2e9d525af38d
(svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents:
1070
diff
changeset
|
606 |
AddSortableSpriteToDraw(image, ti->x, ti->y, 0x10, 0x10, 1, ti->z + 7); |
2e9d525af38d
(svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents:
1070
diff
changeset
|
607 |
} |
0 | 608 |
} |
609 |
||
610 |
static bool IsPartOfAutoLine(int px, int py) |
|
611 |
{ |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
612 |
px -= _thd.selstart.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
613 |
py -= _thd.selstart.y; |
0 | 614 |
|
2952 | 615 |
switch (_thd.drawstyle) { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
616 |
case HT_LINE | HT_DIR_X: return py == 0; // x direction |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
617 |
case HT_LINE | HT_DIR_Y: return px == 0; // y direction |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
618 |
case HT_LINE | HT_DIR_HU: return px == -py || px == -py - 16; // horizontal upper |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
619 |
case HT_LINE | HT_DIR_HL: return px == -py || px == -py + 16; // horizontal lower |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
620 |
case HT_LINE | HT_DIR_VL: return px == py || px == py + 16; // vertival left |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
621 |
case HT_LINE | HT_DIR_VR: return px == py || px == py - 16; // vertical right |
0 | 622 |
default: |
623 |
NOT_REACHED(); |
|
624 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
625 |
|
0 | 626 |
/* useless, but avoids compiler warning this way */ |
627 |
return 0; |
|
628 |
} |
|
629 |
||
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
630 |
// [direction][side] |
2710
e144188c1fdb
(svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents:
2676
diff
changeset
|
631 |
static const int _AutorailType[6][2] = { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
632 |
{ HT_DIR_X, HT_DIR_X }, |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
633 |
{ HT_DIR_Y, HT_DIR_Y }, |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
634 |
{ HT_DIR_HU, HT_DIR_HL }, |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
635 |
{ HT_DIR_HL, HT_DIR_HU }, |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
636 |
{ HT_DIR_VL, HT_DIR_VR }, |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
637 |
{ HT_DIR_VR, HT_DIR_VL } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
638 |
}; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
639 |
|
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
640 |
#include "table/autorail.h" |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
641 |
|
0 | 642 |
static void DrawTileSelection(const TileInfo *ti) |
643 |
{ |
|
644 |
uint32 image; |
|
645 |
||
646 |
// Draw a red error square? |
|
3281
0f3d836e35b1
(svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents:
3279
diff
changeset
|
647 |
if (_thd.redsq != 0 && _thd.redsq == ti->tile) { |
1864
83c91b158180
(svn r2370) Replace some magic numbers with symbolic names
tron
parents:
1863
diff
changeset
|
648 |
DrawSelectionSprite(PALETTE_TILE_RED_PULSATING | (SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh]), ti); |
0 | 649 |
return; |
650 |
} |
|
651 |
||
652 |
// no selection active? |
|
2116 | 653 |
if (_thd.drawstyle == 0) return; |
0 | 654 |
|
655 |
// Inside the inner area? |
|
2116 | 656 |
if (IS_INSIDE_1D(ti->x, _thd.pos.x, _thd.size.x) && |
657 |
IS_INSIDE_1D(ti->y, _thd.pos.y, _thd.size.y)) { |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
658 |
if (_thd.drawstyle & HT_RECT) { |
1864
83c91b158180
(svn r2370) Replace some magic numbers with symbolic names
tron
parents:
1863
diff
changeset
|
659 |
image = SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh]; |
83c91b158180
(svn r2370) Replace some magic numbers with symbolic names
tron
parents:
1863
diff
changeset
|
660 |
if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED; |
0 | 661 |
DrawSelectionSprite(image, ti); |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
662 |
} else if (_thd.drawstyle & HT_POINT) { |
0 | 663 |
// Figure out the Z coordinate for the single dot. |
664 |
byte z = ti->z; |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3609
diff
changeset
|
665 |
if (ti->tileh & SLOPE_N) { |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
666 |
z += TILE_HEIGHT; |
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
667 |
if (ti->tileh == SLOPE_STEEP_N) z += TILE_HEIGHT; |
0 | 668 |
} |
1864
83c91b158180
(svn r2370) Replace some magic numbers with symbolic names
tron
parents:
1863
diff
changeset
|
669 |
DrawGroundSpriteAt(_cur_dpi->zoom != 2 ? SPR_DOT : SPR_DOT_SMALL, ti->x, ti->y, z); |
2116 | 670 |
} else if (_thd.drawstyle & HT_RAIL /*&& _thd.place_mode == VHM_RAIL*/) { |
671 |
// autorail highlight piece under cursor |
|
672 |
uint type = _thd.drawstyle & 0xF; |
|
673 |
assert(type <= 5); |
|
2710
e144188c1fdb
(svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents:
2676
diff
changeset
|
674 |
image = SPR_AUTORAIL_BASE + _AutorailTilehSprite[ti->tileh][_AutorailType[type][0]]; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
675 |
|
1864
83c91b158180
(svn r2370) Replace some magic numbers with symbolic names
tron
parents:
1863
diff
changeset
|
676 |
if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
677 |
DrawSelectionSprite(image, ti); |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
678 |
|
2116 | 679 |
} else if (IsPartOfAutoLine(ti->x, ti->y)) { |
680 |
// autorail highlighting long line |
|
681 |
int dir = _thd.drawstyle & ~0xF0; |
|
682 |
uint side; |
|
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
683 |
|
2116 | 684 |
if (dir < 2) { |
685 |
side = 0; |
|
686 |
} else { |
|
687 |
TileIndex start = TileVirtXY(_thd.selstart.x, _thd.selstart.y); |
|
688 |
int diffx = myabs(TileX(start) - TileX(ti->tile)); |
|
689 |
int diffy = myabs(TileY(start) - TileY(ti->tile)); |
|
690 |
side = myabs(diffx - diffy); |
|
691 |
} |
|
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
692 |
|
2710
e144188c1fdb
(svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents:
2676
diff
changeset
|
693 |
image = SPR_AUTORAIL_BASE + _AutorailTilehSprite[ti->tileh][_AutorailType[dir][side]]; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
694 |
|
2116 | 695 |
if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED; |
696 |
DrawSelectionSprite(image, ti); |
|
697 |
} |
|
0 | 698 |
return; |
699 |
} |
|
700 |
||
701 |
// Check if it's inside the outer area? |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
702 |
if (_thd.outersize.x && |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
703 |
_thd.size.x < _thd.size.x + _thd.outersize.x && |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
704 |
IS_INSIDE_1D(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) && |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
705 |
IS_INSIDE_1D(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) { |
0 | 706 |
// Draw a blue rect. |
1864
83c91b158180
(svn r2370) Replace some magic numbers with symbolic names
tron
parents:
1863
diff
changeset
|
707 |
DrawSelectionSprite(PALETTE_SEL_TILE_BLUE | (SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh]), ti); |
0 | 708 |
return; |
709 |
} |
|
710 |
} |
|
711 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
712 |
static void ViewportAddLandscape(void) |
0 | 713 |
{ |
714 |
ViewportDrawer *vd = _cur_vd; |
|
715 |
int x, y, width, height; |
|
716 |
TileInfo ti; |
|
717 |
bool direction; |
|
718 |
||
719 |
_cur_ti = &ti; |
|
720 |
||
721 |
// Transform into tile coordinates and round to closest full tile |
|
722 |
#if !defined(NEW_ROTATION) |
|
723 |
x = ((vd->dpi.top >> 1) - (vd->dpi.left >> 2)) & ~0xF; |
|
724 |
y = ((vd->dpi.top >> 1) + (vd->dpi.left >> 2) - 0x10) & ~0xF; |
|
725 |
#else |
|
726 |
x = ((vd->dpi.top >> 1) + (vd->dpi.left >> 2) - 0x10) & ~0xF; |
|
727 |
y = ((vd->dpi.left >> 2) - (vd->dpi.top >> 1)) & ~0xF; |
|
728 |
#endif |
|
729 |
// determine size of area |
|
730 |
{ |
|
731 |
Point pt = RemapCoords(x, y, 241); |
|
732 |
width = (vd->dpi.left + vd->dpi.width - pt.x + 95) >> 6; |
|
733 |
height = (vd->dpi.top + vd->dpi.height - pt.y) >> 5 << 1; |
|
734 |
} |
|
735 |
||
736 |
assert(width > 0); |
|
737 |
assert(height > 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
738 |
|
0 | 739 |
direction = false; |
740 |
||
741 |
do { |
|
742 |
int width_cur = width; |
|
743 |
int x_cur = x; |
|
744 |
int y_cur = y; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
745 |
|
0 | 746 |
do { |
4238
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
747 |
TileType tt; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
748 |
|
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
749 |
ti.x = x_cur; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
750 |
ti.y = y_cur; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
751 |
if (0 <= x_cur && x_cur < (int)MapMaxX() * TILE_SIZE && |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
752 |
0 <= y_cur && y_cur < (int)MapMaxY() * TILE_SIZE) { |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
753 |
TileIndex tile = TileVirtXY(x_cur, y_cur); |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
754 |
|
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
755 |
ti.tile = tile; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
756 |
ti.tileh = GetTileSlope(tile, &ti.z); |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
757 |
tt = GetTileType(tile); |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
758 |
} else { |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
759 |
ti.tileh = SLOPE_FLAT; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
760 |
ti.tile = 0; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
761 |
ti.z = 0; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
762 |
tt = MP_VOID; |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
763 |
} |
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
764 |
|
0 | 765 |
#if !defined(NEW_ROTATION) |
766 |
y_cur += 0x10; |
|
767 |
x_cur -= 0x10; |
|
768 |
#else |
|
769 |
y_cur += 0x10; |
|
770 |
x_cur += 0x10; |
|
771 |
#endif |
|
772 |
_added_tile_sprite = false; |
|
773 |
_offset_ground_sprites = false; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
774 |
|
4238
e017178ca040
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
775 |
_tile_type_procs[tt]->draw_tile_proc(&ti); |
0 | 776 |
DrawTileSelection(&ti); |
777 |
} while (--width_cur); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
778 |
|
0 | 779 |
#if !defined(NEW_ROTATION) |
780 |
if ( (direction^=1) != 0) |
|
781 |
y += 0x10; |
|
782 |
else |
|
783 |
x += 0x10; |
|
784 |
#else |
|
785 |
if ( (direction^=1) != 0) |
|
786 |
x += 0x10; |
|
787 |
else |
|
788 |
y -= 0x10; |
|
789 |
#endif |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
790 |
} while (--height); |
0 | 791 |
} |
792 |
||
793 |
||
410 | 794 |
static void ViewportAddTownNames(DrawPixelInfo *dpi) |
0 | 795 |
{ |
796 |
Town *t; |
|
797 |
int left, top, right, bottom; |
|
798 |
||
799 |
if (!(_display_opt & DO_SHOW_TOWN_NAMES) || _game_mode == GM_MENU) |
|
800 |
return; |
|
801 |
||
802 |
left = dpi->left; |
|
803 |
top = dpi->top; |
|
804 |
right = left + dpi->width; |
|
805 |
bottom = top + dpi->height; |
|
806 |
||
5027 | 807 |
switch (dpi->zoom) { |
808 |
case 0: |
|
809 |
FOR_ALL_TOWNS(t) { |
|
810 |
if (bottom > t->sign.top && |
|
811 |
top < t->sign.top + 12 && |
|
812 |
right > t->sign.left && |
|
813 |
left < t->sign.left + t->sign.width_1) { |
|
814 |
AddStringToDraw(t->sign.left + 1, t->sign.top + 1, |
|
815 |
_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL, |
|
816 |
t->index, t->population); |
|
817 |
} |
|
0 | 818 |
} |
5027 | 819 |
break; |
820 |
||
821 |
case 1: |
|
822 |
right += 2; |
|
823 |
bottom += 2; |
|
824 |
||
825 |
FOR_ALL_TOWNS(t) { |
|
826 |
if (bottom > t->sign.top && |
|
827 |
top < t->sign.top + 24 && |
|
828 |
right > t->sign.left && |
|
829 |
left < t->sign.left + t->sign.width_1*2) { |
|
830 |
AddStringToDraw(t->sign.left + 1, t->sign.top + 1, |
|
831 |
_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL, |
|
832 |
t->index, t->population); |
|
833 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
834 |
} |
5027 | 835 |
break; |
836 |
||
837 |
default: NOT_REACHED(); |
|
838 |
case 2: |
|
839 |
right += 4; |
|
840 |
bottom += 5; |
|
841 |
||
842 |
FOR_ALL_TOWNS(t) { |
|
843 |
if (bottom > t->sign.top && |
|
844 |
top < t->sign.top + 24 && |
|
845 |
right > t->sign.left && |
|
846 |
left < t->sign.left + t->sign.width_2*4) { |
|
847 |
AddStringToDraw(t->sign.left + 5, t->sign.top + 1, STR_TOWN_LABEL_TINY_BLACK, t->index, 0); |
|
848 |
AddStringToDraw(t->sign.left + 1, t->sign.top - 3, STR_TOWN_LABEL_TINY_WHITE, t->index, 0); |
|
849 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
850 |
} |
5027 | 851 |
break; |
0 | 852 |
} |
853 |
} |
|
854 |
||
5025 | 855 |
|
856 |
static void AddStation(const Station *st, StringID str, uint16 width) |
|
857 |
{ |
|
858 |
StringSpriteToDraw *sstd; |
|
859 |
||
5026
c8b7148798ac
(svn r7067) Remove the unused parameter params_3 from AddStringToDraw()
tron
parents:
5025
diff
changeset
|
860 |
sstd = AddStringToDraw(st->sign.left + 1, st->sign.top + 1, str, st->index, st->facilities); |
5025 | 861 |
if (sstd != NULL) { |
862 |
sstd->color = (st->owner == OWNER_NONE || st->facilities == 0) ? 0xE : _player_colors[st->owner]; |
|
863 |
sstd->width = width; |
|
864 |
} |
|
865 |
} |
|
866 |
||
867 |
||
410 | 868 |
static void ViewportAddStationNames(DrawPixelInfo *dpi) |
0 | 869 |
{ |
870 |
int left, top, right, bottom; |
|
5025 | 871 |
const Station *st; |
0 | 872 |
|
873 |
if (!(_display_opt & DO_SHOW_STATION_NAMES) || _game_mode == GM_MENU) |
|
874 |
return; |
|
875 |
||
876 |
left = dpi->left; |
|
877 |
top = dpi->top; |
|
878 |
right = left + dpi->width; |
|
879 |
bottom = top + dpi->height; |
|
880 |
||
5027 | 881 |
switch (dpi->zoom) { |
882 |
case 0: |
|
883 |
FOR_ALL_STATIONS(st) { |
|
884 |
if (bottom > st->sign.top && |
|
885 |
top < st->sign.top + 12 && |
|
886 |
right > st->sign.left && |
|
887 |
left < st->sign.left + st->sign.width_1) { |
|
888 |
AddStation(st, STR_305C_0, st->sign.width_1); |
|
889 |
} |
|
0 | 890 |
} |
5027 | 891 |
break; |
892 |
||
893 |
case 1: |
|
894 |
right += 2; |
|
895 |
bottom += 2; |
|
896 |
FOR_ALL_STATIONS(st) { |
|
897 |
if (bottom > st->sign.top && |
|
898 |
top < st->sign.top + 24 && |
|
899 |
right > st->sign.left && |
|
900 |
left < st->sign.left + st->sign.width_1*2) { |
|
901 |
AddStation(st, STR_305C_0, st->sign.width_1); |
|
902 |
} |
|
0 | 903 |
} |
5027 | 904 |
break; |
905 |
||
906 |
default: NOT_REACHED(); |
|
907 |
case 2: |
|
908 |
right += 4; |
|
909 |
bottom += 5; |
|
910 |
FOR_ALL_STATIONS(st) { |
|
911 |
if (bottom > st->sign.top && |
|
912 |
top < st->sign.top + 24 && |
|
913 |
right > st->sign.left && |
|
914 |
left < st->sign.left + st->sign.width_2*4) { |
|
915 |
AddStation(st, STR_STATION_SIGN_TINY, st->sign.width_2 | 0x8000); |
|
916 |
} |
|
0 | 917 |
} |
5027 | 918 |
break; |
0 | 919 |
} |
920 |
} |
|
921 |
||
5025 | 922 |
|
923 |
static void AddSign(const Sign *si, StringID str, uint16 width) |
|
924 |
{ |
|
925 |
StringSpriteToDraw *sstd; |
|
926 |
||
5026
c8b7148798ac
(svn r7067) Remove the unused parameter params_3 from AddStringToDraw()
tron
parents:
5025
diff
changeset
|
927 |
sstd = AddStringToDraw(si->sign.left + 1, si->sign.top + 1, str, si->str, 0); |
5025 | 928 |
if (sstd != NULL) { |
929 |
sstd->color = (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner]; |
|
930 |
sstd->width = width; |
|
931 |
} |
|
932 |
} |
|
933 |
||
934 |
||
410 | 935 |
static void ViewportAddSigns(DrawPixelInfo *dpi) |
0 | 936 |
{ |
5025 | 937 |
const Sign *si; |
0 | 938 |
int left, top, right, bottom; |
939 |
||
940 |
if (!(_display_opt & DO_SHOW_SIGNS)) |
|
941 |
return; |
|
942 |
||
943 |
left = dpi->left; |
|
944 |
top = dpi->top; |
|
945 |
right = left + dpi->width; |
|
946 |
bottom = top + dpi->height; |
|
947 |
||
5027 | 948 |
switch (dpi->zoom) { |
949 |
case 0: |
|
950 |
FOR_ALL_SIGNS(si) { |
|
951 |
if (bottom > si->sign.top && |
|
952 |
top < si->sign.top + 12 && |
|
953 |
right > si->sign.left && |
|
954 |
left < si->sign.left + si->sign.width_1) { |
|
955 |
AddSign(si, STR_2806, si->sign.width_1); |
|
956 |
} |
|
0 | 957 |
} |
5027 | 958 |
break; |
959 |
||
960 |
case 1: |
|
961 |
right += 2; |
|
962 |
bottom += 2; |
|
963 |
FOR_ALL_SIGNS(si) { |
|
964 |
if (bottom > si->sign.top && |
|
965 |
top < si->sign.top + 24 && |
|
966 |
right > si->sign.left && |
|
967 |
left < si->sign.left + si->sign.width_1 * 2) { |
|
968 |
AddSign(si, STR_2806, si->sign.width_1); |
|
969 |
} |
|
0 | 970 |
} |
5027 | 971 |
break; |
972 |
||
973 |
default: NOT_REACHED(); |
|
974 |
case 2: |
|
975 |
right += 4; |
|
976 |
bottom += 5; |
|
977 |
FOR_ALL_SIGNS(si) { |
|
978 |
if (bottom > si->sign.top && |
|
979 |
top < si->sign.top + 24 && |
|
980 |
right > si->sign.left && |
|
981 |
left < si->sign.left + si->sign.width_2 * 4) { |
|
982 |
AddSign(si, STR_2002, si->sign.width_2 | 0x8000); |
|
983 |
} |
|
0 | 984 |
} |
5027 | 985 |
break; |
0 | 986 |
} |
987 |
} |
|
988 |
||
5025 | 989 |
|
990 |
static void AddWaypoint(const Waypoint *wp, StringID str, uint16 width) |
|
991 |
{ |
|
992 |
StringSpriteToDraw *sstd; |
|
993 |
||
5026
c8b7148798ac
(svn r7067) Remove the unused parameter params_3 from AddStringToDraw()
tron
parents:
5025
diff
changeset
|
994 |
sstd = AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, str, wp->index, 0); |
5025 | 995 |
if (sstd != NULL) { |
996 |
sstd->color = (wp->deleted ? 0xE : 11); |
|
997 |
sstd->width = width; |
|
998 |
} |
|
999 |
} |
|
1000 |
||
1001 |
||
410 | 1002 |
static void ViewportAddWaypoints(DrawPixelInfo *dpi) |
0 | 1003 |
{ |
5025 | 1004 |
const Waypoint *wp; |
0 | 1005 |
int left, top, right, bottom; |
1006 |
||
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
|
1007 |
if (!(_display_opt & DO_WAYPOINTS)) |
0 | 1008 |
return; |
1009 |
||
1010 |
left = dpi->left; |
|
1011 |
top = dpi->top; |
|
1012 |
right = left + dpi->width; |
|
1013 |
bottom = top + dpi->height; |
|
1014 |
||
5027 | 1015 |
switch (dpi->zoom) { |
1016 |
case 0: |
|
1017 |
FOR_ALL_WAYPOINTS(wp) { |
|
1018 |
if (bottom > wp->sign.top && |
|
1019 |
top < wp->sign.top + 12 && |
|
1020 |
right > wp->sign.left && |
|
1021 |
left < wp->sign.left + wp->sign.width_1) { |
|
1022 |
AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1); |
|
1023 |
} |
|
0 | 1024 |
} |
5027 | 1025 |
break; |
1026 |
||
1027 |
case 1: |
|
1028 |
right += 2; |
|
1029 |
bottom += 2; |
|
1030 |
FOR_ALL_WAYPOINTS(wp) { |
|
1031 |
if (bottom > wp->sign.top && |
|
1032 |
top < wp->sign.top + 24 && |
|
1033 |
right > wp->sign.left && |
|
1034 |
left < wp->sign.left + wp->sign.width_1*2) { |
|
1035 |
AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1); |
|
1036 |
} |
|
0 | 1037 |
} |
5027 | 1038 |
break; |
1039 |
||
1040 |
default: NOT_REACHED(); |
|
1041 |
case 2: |
|
1042 |
right += 4; |
|
1043 |
bottom += 5; |
|
1044 |
FOR_ALL_WAYPOINTS(wp) { |
|
1045 |
if (bottom > wp->sign.top && |
|
1046 |
top < wp->sign.top + 24 && |
|
1047 |
right > wp->sign.left && |
|
1048 |
left < wp->sign.left + wp->sign.width_2*4) { |
|
1049 |
AddWaypoint(wp, STR_WAYPOINT_VIEWPORT_TINY, wp->sign.width_2 | 0x8000); |
|
1050 |
} |
|
0 | 1051 |
} |
5027 | 1052 |
break; |
0 | 1053 |
} |
1054 |
} |
|
1055 |
||
1056 |
void UpdateViewportSignPos(ViewportSign *sign, int left, int top, StringID str) |
|
1057 |
{ |
|
1058 |
char buffer[128]; |
|
2116 | 1059 |
uint w; |
0 | 1060 |
|
1061 |
sign->top = top; |
|
1062 |
||
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4885
diff
changeset
|
1063 |
GetString(buffer, str, lastof(buffer)); |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4539
diff
changeset
|
1064 |
w = GetStringBoundingBox(buffer).width + 3; |
0 | 1065 |
sign->width_1 = w; |
2116 | 1066 |
sign->left = left - w / 2; |
0 | 1067 |
|
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4539
diff
changeset
|
1068 |
/* zoomed out version */ |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3645
diff
changeset
|
1069 |
_cur_fontsize = FS_SMALL; |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4539
diff
changeset
|
1070 |
w = GetStringBoundingBox(buffer).width + 3; |
3798
37a2090eac94
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3645
diff
changeset
|
1071 |
_cur_fontsize = FS_NORMAL; |
1390
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1363
diff
changeset
|
1072 |
sign->width_2 = w; |
0 | 1073 |
} |
1074 |
||
1075 |
||
410 | 1076 |
static void ViewportDrawTileSprites(TileSpriteToDraw *ts) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1077 |
{ |
0 | 1078 |
do { |
1079 |
Point pt = RemapCoords(ts->x, ts->y, ts->z); |
|
1080 |
DrawSprite(ts->image, pt.x, pt.y); |
|
2116 | 1081 |
ts = ts->next; |
1082 |
} while (ts != NULL); |
|
0 | 1083 |
} |
1084 |
||
4171 | 1085 |
static void ViewportSortParentSprites(ParentSpriteToDraw *psd[]) |
0 | 1086 |
{ |
2116 | 1087 |
while (*psd != NULL) { |
1088 |
ParentSpriteToDraw* ps = *psd; |
|
0 | 1089 |
|
1090 |
if (!(ps->unk16 & 1)) { |
|
2116 | 1091 |
ParentSpriteToDraw** psd2 = psd; |
1092 |
||
0 | 1093 |
ps->unk16 |= 1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1094 |
|
2116 | 1095 |
while (*++psd2 != NULL) { |
1096 |
ParentSpriteToDraw* ps2 = *psd2; |
|
4188 | 1097 |
ParentSpriteToDraw** psd3; |
1934
b3d568113d4d
(svn r2440) - Fix: [newgrf] Fix the spritesorter to handle overlapping sprites properly, this fixes display problems with really short wagons. (algorithm by patchman, ported by therax)
hackykid
parents:
1932
diff
changeset
|
1098 |
|
2116 | 1099 |
if (ps2->unk16 & 1) continue; |
0 | 1100 |
|
4187
50b94420d9a2
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1101 |
/* Decide which comparator to use, based on whether the bounding |
50b94420d9a2
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1102 |
* boxes overlap |
50b94420d9a2
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1103 |
*/ |
50b94420d9a2
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1104 |
if (ps->xmax > ps2->xmin && ps->xmin < ps2->xmax && // overlap in X? |
50b94420d9a2
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1105 |
ps->ymax > ps2->ymin && ps->ymin < ps2->ymax && // overlap in Y? |
50b94420d9a2
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1106 |
ps->zmax > ps2->zmin && ps->zmin < ps2->zmax) { // overlap in Z? |
4188 | 1107 |
/* Use X+Y+Z as the sorting order, so sprites closer to the bottom of |
1108 |
* the screen and with higher Z elevation, are drawn in front. |
|
1109 |
* Here X,Y,Z are the coordinates of the "center of mass" of the sprite, |
|
1110 |
* i.e. X=(left+right)/2, etc. |
|
1111 |
* However, since we only care about order, don't actually divide / 2 |
|
1112 |
*/ |
|
1113 |
if (ps->xmin + ps->xmax + ps->ymin + ps->ymax + ps->zmin + ps->zmax <= |
|
1114 |
ps2->xmin + ps2->xmax + ps2->ymin + ps2->ymax + ps2->zmin + ps2->zmax) { |
|
1115 |
continue; |
|
1116 |
} |
|
1934
b3d568113d4d
(svn r2440) - Fix: [newgrf] Fix the spritesorter to handle overlapping sprites properly, this fixes display problems with really short wagons. (algorithm by patchman, ported by therax)
hackykid
parents:
1932
diff
changeset
|
1117 |
} else { |
4188 | 1118 |
if (ps->xmax < ps2->xmin || |
1119 |
ps->ymax < ps2->ymin || |
|
1120 |
ps->zmax < ps2->zmin || ( |
|
1121 |
ps->xmin < ps2->xmax && |
|
1122 |
ps->ymin < ps2->ymax && |
|
1123 |
ps->zmin < ps2->zmax |
|
1124 |
)) { |
|
1125 |
continue; |
|
1126 |
} |
|
1934
b3d568113d4d
(svn r2440) - Fix: [newgrf] Fix the spritesorter to handle overlapping sprites properly, this fixes display problems with really short wagons. (algorithm by patchman, ported by therax)
hackykid
parents:
1932
diff
changeset
|
1127 |
} |
2116 | 1128 |
|
4188 | 1129 |
// Swap the two sprites ps and ps2 using bubble-sort algorithm. |
1130 |
psd3 = psd; |
|
1131 |
do { |
|
1132 |
ParentSpriteToDraw* temp = *psd3; |
|
1133 |
*psd3 = ps2; |
|
1134 |
ps2 = temp; |
|
0 | 1135 |
|
4188 | 1136 |
psd3++; |
1137 |
} while (psd3 <= psd2); |
|
0 | 1138 |
} |
1139 |
} else { |
|
1140 |
psd++; |
|
1141 |
} |
|
1142 |
} |
|
1143 |
} |
|
1144 |
||
2116 | 1145 |
static void ViewportDrawParentSprites(ParentSpriteToDraw *psd[]) |
0 | 1146 |
{ |
2116 | 1147 |
for (; *psd != NULL; psd++) { |
1148 |
const ParentSpriteToDraw* ps = *psd; |
|
4186
853361bea03b
(svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents:
4171
diff
changeset
|
1149 |
Point pt = RemapCoords(ps->xmin, ps->ymin, ps->zmin); |
2116 | 1150 |
const ChildScreenSpriteToDraw* cs; |
0 | 1151 |
|
1152 |
DrawSprite(ps->image, pt.x, pt.y); |
|
1153 |
||
2116 | 1154 |
for (cs = ps->child; cs != NULL; cs = cs->next) { |
0 | 1155 |
DrawSprite(cs->image, ps->left + cs->x, ps->top + cs->y); |
1156 |
} |
|
1157 |
} |
|
1158 |
} |
|
1159 |
||
2116 | 1160 |
static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDraw *ss) |
0 | 1161 |
{ |
1162 |
DrawPixelInfo dp; |
|
1163 |
byte zoom; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1164 |
|
0 | 1165 |
_cur_dpi = &dp; |
1166 |
dp = *dpi; |
|
1167 |
||
2116 | 1168 |
zoom = dp.zoom; |
0 | 1169 |
dp.zoom = 0; |
1170 |
||
1171 |
dp.left >>= zoom; |
|
1172 |
dp.top >>= zoom; |
|
1173 |
dp.width >>= zoom; |
|
1174 |
dp.height >>= zoom; |
|
1175 |
||
1176 |
do { |
|
5025 | 1177 |
uint16 colour; |
1178 |
||
0 | 1179 |
if (ss->width != 0) { |
2116 | 1180 |
int x = (ss->x >> zoom) - 1; |
1181 |
int y = (ss->y >> zoom) - 1; |
|
1182 |
int bottom = y + 11; |
|
1183 |
int w = ss->width; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1184 |
|
0 | 1185 |
if (w & 0x8000) { |
1186 |
w &= ~0x8000; |
|
1187 |
y--; |
|
1188 |
bottom -= 6; |
|
1189 |
w -= 3; |
|
1190 |
} |
|
1191 |
||
2116 | 1192 |
/* Draw the rectangle if 'tranparent station signs' is off, |
1193 |
* or if we are drawing a general text sign (STR_2806) */ |
|
1194 |
if (!(_display_opt & DO_TRANS_SIGNS) || ss->string == STR_2806) |
|
1195 |
DrawFrameRect( |
|
1196 |
x, y, x + w, bottom, ss->color, |
|
4439 | 1197 |
(_display_opt & DO_TRANS_BUILDINGS) ? FR_TRANSPARENT : 0 |
2116 | 1198 |
); |
0 | 1199 |
} |
1200 |
||
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1201 |
SetDParam(0, ss->params[0]); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1202 |
SetDParam(1, ss->params[1]); |
2116 | 1203 |
/* if we didn't draw a rectangle, or if transparant building is on, |
1204 |
* draw the text in the color the rectangle would have */ |
|
1205 |
if (( |
|
1206 |
(_display_opt & DO_TRANS_BUILDINGS) || |
|
1207 |
(_display_opt & DO_TRANS_SIGNS && ss->string != STR_2806) |
|
1208 |
) && ss->width != 0) { |
|
1209 |
/* Real colors need the IS_PALETTE_COLOR flag |
|
1210 |
* otherwise colors from _string_colormap are assumed. */ |
|
5025 | 1211 |
colour = _colour_gradient[ss->color][6] | IS_PALETTE_COLOR; |
0 | 1212 |
} else { |
5025 | 1213 |
colour = 16; |
0 | 1214 |
} |
5025 | 1215 |
DrawString( |
1216 |
ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0), |
|
1217 |
ss->string, colour |
|
1218 |
); |
|
2116 | 1219 |
|
1220 |
ss = ss->next; |
|
1221 |
} while (ss != NULL); |
|
0 | 1222 |
} |
1223 |
||
430 | 1224 |
void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom) |
0 | 1225 |
{ |
1226 |
ViewportDrawer vd; |
|
1227 |
int mask; |
|
2116 | 1228 |
int x; |
1229 |
int y; |
|
0 | 1230 |
DrawPixelInfo *old_dpi; |
1231 |
||
1232 |
byte mem[VIEWPORT_DRAW_MEM]; |
|
137
73f897e1bf4a
(svn r138) -Add: 64x64 stations are now nicely painted (increased size of
truelight
parents:
133
diff
changeset
|
1233 |
ParentSpriteToDraw *parent_list[6144]; |
0 | 1234 |
|
1235 |
_cur_vd = &vd; |
|
1236 |
||
1237 |
old_dpi = _cur_dpi; |
|
1238 |
_cur_dpi = &vd.dpi; |
|
1239 |
||
1240 |
vd.dpi.zoom = vp->zoom; |
|
1241 |
mask = (-1) << vp->zoom; |
|
1242 |
||
1243 |
vd.combine_sprites = 0; |
|
1244 |
||
1245 |
vd.dpi.width = (right - left) & mask; |
|
1246 |
vd.dpi.height = (bottom - top) & mask; |
|
1247 |
vd.dpi.left = left & mask; |
|
1248 |
vd.dpi.top = top & mask; |
|
1249 |
vd.dpi.pitch = old_dpi->pitch; |
|
1250 |
||
1251 |
x = ((vd.dpi.left - (vp->virtual_left&mask)) >> vp->zoom) + vp->left; |
|
1252 |
y = ((vd.dpi.top - (vp->virtual_top&mask)) >> vp->zoom) + vp->top; |
|
1253 |
||
1254 |
vd.dpi.dst_ptr = old_dpi->dst_ptr + x - old_dpi->left + (y - old_dpi->top) * old_dpi->pitch; |
|
1255 |
||
1256 |
vd.parent_list = parent_list; |
|
2116 | 1257 |
vd.eof_parent_list = endof(parent_list); |
0 | 1258 |
vd.spritelist_mem = mem; |
2116 | 1259 |
vd.eof_spritelist_mem = endof(mem) - sizeof(LARGEST_SPRITELIST_STRUCT); |
0 | 1260 |
vd.last_string = &vd.first_string; |
1261 |
vd.first_string = NULL; |
|
1262 |
vd.last_tile = &vd.first_tile; |
|
1263 |
vd.first_tile = NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1264 |
|
0 | 1265 |
ViewportAddLandscape(); |
1266 |
#if !defined(NEW_ROTATION) |
|
1267 |
ViewportAddVehicles(&vd.dpi); |
|
1268 |
DrawTextEffects(&vd.dpi); |
|
1269 |
||
1270 |
ViewportAddTownNames(&vd.dpi); |
|
1271 |
ViewportAddStationNames(&vd.dpi); |
|
1272 |
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
|
1273 |
ViewportAddWaypoints(&vd.dpi); |
0 | 1274 |
#endif |
1275 |
||
133
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
1276 |
// 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
|
1277 |
// is checked) |
979
f12f96116cdd
(svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
1278 |
assert(vd.parent_list <= endof(parent_list)); |
133
321532e90bc8
(svn r134) -Fix: [976583] parent_list was too small
truelight
parents:
58
diff
changeset
|
1279 |
|
2116 | 1280 |
if (vd.first_tile != NULL) ViewportDrawTileSprites(vd.first_tile); |
0 | 1281 |
|
1282 |
/* null terminate parent sprite list */ |
|
1283 |
*vd.parent_list = NULL; |
|
1284 |
||
1285 |
ViewportSortParentSprites(parent_list); |
|
1286 |
ViewportDrawParentSprites(parent_list); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1287 |
|
2116 | 1288 |
if (vd.first_string != NULL) ViewportDrawStrings(&vd.dpi, vd.first_string); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1289 |
|
0 | 1290 |
_cur_dpi = old_dpi; |
1291 |
} |
|
1292 |
||
1293 |
// Make sure we don't draw a too big area at a time. |
|
1294 |
// If we do, the sprite memory will overflow. |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5045
diff
changeset
|
1295 |
static void ViewportDrawChk(const ViewPort *vp, int left, int top, int right, int bottom) |
0 | 1296 |
{ |
1297 |
if (((bottom - top) * (right - left) << vp->zoom) > 180000) { |
|
1298 |
if ((bottom - top) > (right - left)) { |
|
1299 |
int t = (top + bottom) >> 1; |
|
1300 |
ViewportDrawChk(vp, left, top, right, t); |
|
1301 |
ViewportDrawChk(vp, left, t, right, bottom); |
|
1302 |
} else { |
|
1303 |
int t = (left + right) >> 1; |
|
1304 |
ViewportDrawChk(vp, left, top, t, bottom); |
|
1305 |
ViewportDrawChk(vp, t, top, right, bottom); |
|
1306 |
} |
|
1307 |
} else { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1308 |
ViewportDoDraw(vp, |
0 | 1309 |
((left - vp->left) << vp->zoom) + vp->virtual_left, |
1310 |
((top - vp->top) << vp->zoom) + vp->virtual_top, |
|
1311 |
((right - vp->left) << vp->zoom) + vp->virtual_left, |
|
1312 |
((bottom - vp->top) << vp->zoom) + vp->virtual_top |
|
1313 |
); |
|
1314 |
} |
|
1315 |
} |
|
1316 |
||
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5045
diff
changeset
|
1317 |
static inline void ViewportDraw(const ViewPort *vp, int left, int top, int right, int bottom) |
0 | 1318 |
{ |
2116 | 1319 |
if (right <= vp->left || bottom <= vp->top) return; |
0 | 1320 |
|
2116 | 1321 |
if (left >= vp->left + vp->width) return; |
0 | 1322 |
|
1323 |
if (left < vp->left) left = vp->left; |
|
2116 | 1324 |
if (right > vp->left + vp->width) right = vp->left + vp->width; |
0 | 1325 |
|
2116 | 1326 |
if (top >= vp->top + vp->height) return; |
0 | 1327 |
|
1328 |
if (top < vp->top) top = vp->top; |
|
2116 | 1329 |
if (bottom > vp->top + vp->height) bottom = vp->top + vp->height; |
0 | 1330 |
|
1331 |
ViewportDrawChk(vp, left, top, right, bottom); |
|
1332 |
} |
|
1333 |
||
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5045
diff
changeset
|
1334 |
void DrawWindowViewport(const Window *w) |
2116 | 1335 |
{ |
0 | 1336 |
DrawPixelInfo *dpi = _cur_dpi; |
1337 |
||
1338 |
dpi->left += w->left; |
|
1339 |
dpi->top += w->top; |
|
1340 |
||
1341 |
ViewportDraw(w->viewport, dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height); |
|
1342 |
||
1343 |
dpi->left -= w->left; |
|
1344 |
dpi->top -= w->top; |
|
1345 |
} |
|
1346 |
||
1347 |
void UpdateViewportPosition(Window *w) |
|
1348 |
{ |
|
2116 | 1349 |
const ViewPort *vp = w->viewport; |
0 | 1350 |
|
2116 | 1351 |
if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE) { |
1352 |
const Vehicle* veh = GetVehicle(WP(w,vp_d).follow_vehicle); |
|
1353 |
Point pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos); |
|
0 | 1354 |
|
1355 |
SetViewportPosition(w, pt.x, pt.y); |
|
1356 |
} 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
|
1357 |
#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
|
1358 |
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
|
1359 |
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
|
1360 |
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
|
1361 |
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
|
1362 |
|
0e71f12b846b
(svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents:
534
diff
changeset
|
1363 |
// 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
|
1364 |
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
|
1365 |
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
|
1366 |
// 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
|
1367 |
// 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
|
1368 |
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
|
1369 |
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
|
1370 |
// clamp to size of map |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1371 |
vx = clamp(vx, 0 * 4, MapMaxX() * TILE_SIZE * 4); |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1372 |
vy = clamp(vy, 0 * 4, MapMaxY() * TILE_SIZE * 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
|
1373 |
// 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
|
1374 |
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
|
1375 |
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
|
1376 |
// Set position |
2116 | 1377 |
WP(w, vp_d).scrollpos_x = x - vp->virtual_width / 2; |
1378 |
WP(w, vp_d).scrollpos_y = y - vp->virtual_height / 2; |
|
632
0e71f12b846b
(svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents:
534
diff
changeset
|
1379 |
#else |
0 | 1380 |
int x,y,t; |
1381 |
int err; |
|
1382 |
||
1383 |
x = WP(w,vp_d).scrollpos_x >> 2; |
|
1384 |
y = WP(w,vp_d).scrollpos_y >> 1; |
|
1385 |
||
1386 |
t = x; |
|
1387 |
x = x + y; |
|
1388 |
y = x - y; |
|
1389 |
err= 0; |
|
1390 |
||
1391 |
if (err != 0) { |
|
1392 |
/* coordinate remap */ |
|
1393 |
Point pt = RemapCoords(x, y, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1394 |
t = (-1) << vp->zoom; |
0 | 1395 |
WP(w,vp_d).scrollpos_x = pt.x & t; |
1396 |
WP(w,vp_d).scrollpos_y = pt.y & t; |
|
1397 |
} |
|
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
|
1398 |
#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
|
1399 |
|
2116 | 1400 |
SetViewportPosition(w, WP(w, vp_d).scrollpos_x, WP(w, vp_d).scrollpos_y); |
0 | 1401 |
} |
1402 |
} |
|
1403 |
||
2116 | 1404 |
static void MarkViewportDirty(const ViewPort *vp, int left, int top, int right, int bottom) |
0 | 1405 |
{ |
2116 | 1406 |
right -= vp->virtual_left; |
1407 |
if (right <= 0) return; |
|
0 | 1408 |
|
2116 | 1409 |
bottom -= vp->virtual_top; |
1410 |
if (bottom <= 0) return; |
|
0 | 1411 |
|
2116 | 1412 |
left = max(0, left - vp->virtual_left); |
0 | 1413 |
|
2116 | 1414 |
if (left >= vp->virtual_width) return; |
0 | 1415 |
|
2116 | 1416 |
top = max(0, top - vp->virtual_top); |
1417 |
||
1418 |
if (top >= vp->virtual_height) return; |
|
0 | 1419 |
|
1420 |
SetDirtyBlocks( |
|
1421 |
(left >> vp->zoom) + vp->left, |
|
1422 |
(top >> vp->zoom) + vp->top, |
|
1423 |
(right >> vp->zoom) + vp->left, |
|
1424 |
(bottom >> vp->zoom) + vp->top |
|
1425 |
); |
|
1426 |
} |
|
1427 |
||
1428 |
void MarkAllViewportsDirty(int left, int top, int right, int bottom) |
|
1429 |
{ |
|
2116 | 1430 |
const ViewPort *vp = _viewports; |
0 | 1431 |
uint32 act = _active_viewports; |
1432 |
do { |
|
1433 |
if (act & 1) { |
|
1434 |
assert(vp->width != 0); |
|
1435 |
MarkViewportDirty(vp, left, top, right, bottom); |
|
1436 |
} |
|
1437 |
} while (vp++,act>>=1); |
|
1438 |
} |
|
1439 |
||
2116 | 1440 |
void MarkTileDirtyByTile(TileIndex tile) |
1441 |
{ |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1442 |
Point pt = RemapCoords(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, GetTileZ(tile)); |
0 | 1443 |
MarkAllViewportsDirty( |
1444 |
pt.x - 31, |
|
1445 |
pt.y - 122, |
|
1446 |
pt.x - 31 + 67, |
|
1447 |
pt.y - 122 + 154 |
|
1448 |
); |
|
1449 |
} |
|
1450 |
||
1451 |
void MarkTileDirty(int x, int y) |
|
1452 |
{ |
|
2116 | 1453 |
uint z = 0; |
0 | 1454 |
Point pt; |
2116 | 1455 |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1456 |
if (IS_INT_INSIDE(x, 0, MapSizeX() * TILE_SIZE) && |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1457 |
IS_INT_INSIDE(y, 0, MapSizeY() * TILE_SIZE)) |
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1458 |
z = GetTileZ(TileVirtXY(x, y)); |
0 | 1459 |
pt = RemapCoords(x, y, z); |
1460 |
||
1461 |
MarkAllViewportsDirty( |
|
1462 |
pt.x - 31, |
|
1463 |
pt.y - 122, |
|
1464 |
pt.x - 31 + 67, |
|
1465 |
pt.y - 122 + 154 |
|
1466 |
); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1467 |
} |
0 | 1468 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
1469 |
static void SetSelectionTilesDirty(void) |
0 | 1470 |
{ |
1471 |
int y_size, x_size; |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1472 |
int x = _thd.pos.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1473 |
int y = _thd.pos.y; |
0 | 1474 |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1475 |
x_size = _thd.size.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1476 |
y_size = _thd.size.y; |
0 | 1477 |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1478 |
if (_thd.outersize.x) { |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1479 |
x_size += _thd.outersize.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1480 |
x += _thd.offs.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1481 |
y_size += _thd.outersize.y; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1482 |
y += _thd.offs.y; |
0 | 1483 |
} |
1484 |
||
1485 |
assert(x_size > 0); |
|
1486 |
assert(y_size > 0); |
|
1487 |
||
1488 |
x_size += x; |
|
1489 |
y_size += y; |
|
1490 |
||
1491 |
do { |
|
1492 |
int y_bk = y; |
|
1493 |
do { |
|
1494 |
MarkTileDirty(x, y); |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1495 |
} while ( (y += TILE_SIZE) != y_size); |
0 | 1496 |
y = y_bk; |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1497 |
} while ( (x += TILE_SIZE) != x_size); |
0 | 1498 |
} |
1499 |
||
1500 |
||
1990
90eb49e87b90
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1501 |
void SetSelectionRed(bool b) |
90eb49e87b90
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1502 |
{ |
90eb49e87b90
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1503 |
_thd.make_square_red = b; |
90eb49e87b90
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1504 |
SetSelectionTilesDirty(); |
90eb49e87b90
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1505 |
} |
90eb49e87b90
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1506 |
|
90eb49e87b90
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1507 |
|
2116 | 1508 |
static bool CheckClickOnTown(const ViewPort *vp, int x, int y) |
0 | 1509 |
{ |
2116 | 1510 |
const Town *t; |
0 | 1511 |
|
2116 | 1512 |
if (!(_display_opt & DO_SHOW_TOWN_NAMES)) return false; |
0 | 1513 |
|
4471 | 1514 |
switch (vp->zoom) { |
1515 |
case 0: |
|
1516 |
x = x - vp->left + vp->virtual_left; |
|
1517 |
y = y - vp->top + vp->virtual_top; |
|
1518 |
FOR_ALL_TOWNS(t) { |
|
1519 |
if (y >= t->sign.top && |
|
1520 |
y < t->sign.top + 12 && |
|
1521 |
x >= t->sign.left && |
|
1522 |
x < t->sign.left + t->sign.width_1) { |
|
1523 |
ShowTownViewWindow(t->index); |
|
1524 |
return true; |
|
1525 |
} |
|
0 | 1526 |
} |
4471 | 1527 |
break; |
1528 |
||
1529 |
case 1: |
|
1530 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
|
1531 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
|
1532 |
FOR_ALL_TOWNS(t) { |
|
1533 |
if (y >= t->sign.top && |
|
1534 |
y < t->sign.top + 24 && |
|
1535 |
x >= t->sign.left && |
|
1536 |
x < t->sign.left + t->sign.width_1 * 2) { |
|
1537 |
ShowTownViewWindow(t->index); |
|
1538 |
return true; |
|
1539 |
} |
|
0 | 1540 |
} |
4471 | 1541 |
break; |
1542 |
||
1543 |
default: |
|
1544 |
x = (x - vp->left + 3) * 4 + vp->virtual_left; |
|
1545 |
y = (y - vp->top + 3) * 4 + vp->virtual_top; |
|
1546 |
FOR_ALL_TOWNS(t) { |
|
1547 |
if (y >= t->sign.top && |
|
1548 |
y < t->sign.top + 24 && |
|
1549 |
x >= t->sign.left && |
|
1550 |
x < t->sign.left + t->sign.width_2 * 4) { |
|
1551 |
ShowTownViewWindow(t->index); |
|
1552 |
return true; |
|
1553 |
} |
|
0 | 1554 |
} |
4471 | 1555 |
break; |
0 | 1556 |
} |
1557 |
||
1558 |
return false; |
|
1559 |
} |
|
1560 |
||
4471 | 1561 |
|
2116 | 1562 |
static bool CheckClickOnStation(const ViewPort *vp, int x, int y) |
0 | 1563 |
{ |
2116 | 1564 |
const Station *st; |
0 | 1565 |
|
2116 | 1566 |
if (!(_display_opt & DO_SHOW_STATION_NAMES)) return false; |
0 | 1567 |
|
4471 | 1568 |
switch (vp->zoom) { |
1569 |
case 0: |
|
1570 |
x = x - vp->left + vp->virtual_left; |
|
1571 |
y = y - vp->top + vp->virtual_top; |
|
1572 |
FOR_ALL_STATIONS(st) { |
|
1573 |
if (y >= st->sign.top && |
|
1574 |
y < st->sign.top + 12 && |
|
1575 |
x >= st->sign.left && |
|
1576 |
x < st->sign.left + st->sign.width_1) { |
|
1577 |
ShowStationViewWindow(st->index); |
|
1578 |
return true; |
|
1579 |
} |
|
0 | 1580 |
} |
4471 | 1581 |
break; |
1582 |
||
1583 |
case 1: |
|
1584 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
|
1585 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
|
1586 |
FOR_ALL_STATIONS(st) { |
|
1587 |
if (y >= st->sign.top && |
|
1588 |
y < st->sign.top + 24 && |
|
1589 |
x >= st->sign.left && |
|
1590 |
x < st->sign.left + st->sign.width_1 * 2) { |
|
1591 |
ShowStationViewWindow(st->index); |
|
1592 |
return true; |
|
1593 |
} |
|
0 | 1594 |
} |
4471 | 1595 |
break; |
1596 |
||
1597 |
default: |
|
1598 |
x = (x - vp->left + 3) * 4 + vp->virtual_left; |
|
1599 |
y = (y - vp->top + 3) * 4 + vp->virtual_top; |
|
1600 |
FOR_ALL_STATIONS(st) { |
|
1601 |
if (y >= st->sign.top && |
|
1602 |
y < st->sign.top + 24 && |
|
1603 |
x >= st->sign.left && |
|
1604 |
x < st->sign.left + st->sign.width_2 * 4) { |
|
1605 |
ShowStationViewWindow(st->index); |
|
1606 |
return true; |
|
1607 |
} |
|
0 | 1608 |
} |
4471 | 1609 |
break; |
0 | 1610 |
} |
1611 |
||
1612 |
return false; |
|
1613 |
} |
|
1614 |
||
4471 | 1615 |
|
2116 | 1616 |
static bool CheckClickOnSign(const ViewPort *vp, int x, int y) |
0 | 1617 |
{ |
4349
2fc39ff2626e
(svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents:
4346
diff
changeset
|
1618 |
const Sign *si; |
0 | 1619 |
|
2116 | 1620 |
if (!(_display_opt & DO_SHOW_SIGNS)) return false; |
0 | 1621 |
|
4471 | 1622 |
switch (vp->zoom) { |
1623 |
case 0: |
|
1624 |
x = x - vp->left + vp->virtual_left; |
|
1625 |
y = y - vp->top + vp->virtual_top; |
|
1626 |
FOR_ALL_SIGNS(si) { |
|
1627 |
if (y >= si->sign.top && |
|
1628 |
y < si->sign.top + 12 && |
|
1629 |
x >= si->sign.left && |
|
1630 |
x < si->sign.left + si->sign.width_1) { |
|
1631 |
ShowRenameSignWindow(si); |
|
1632 |
return true; |
|
1633 |
} |
|
0 | 1634 |
} |
4471 | 1635 |
break; |
1636 |
||
1637 |
case 1: |
|
1638 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
|
1639 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
|
1640 |
FOR_ALL_SIGNS(si) { |
|
1641 |
if (y >= si->sign.top && |
|
1642 |
y < si->sign.top + 24 && |
|
1643 |
x >= si->sign.left && |
|
1644 |
x < si->sign.left + si->sign.width_1 * 2) { |
|
1645 |
ShowRenameSignWindow(si); |
|
1646 |
return true; |
|
1647 |
} |
|
0 | 1648 |
} |
4471 | 1649 |
break; |
1650 |
||
1651 |
default: |
|
1652 |
x = (x - vp->left + 3) * 4 + vp->virtual_left; |
|
1653 |
y = (y - vp->top + 3) * 4 + vp->virtual_top; |
|
1654 |
FOR_ALL_SIGNS(si) { |
|
1655 |
if (y >= si->sign.top && |
|
1656 |
y < si->sign.top + 24 && |
|
1657 |
x >= si->sign.left && |
|
1658 |
x < si->sign.left + si->sign.width_2 * 4) { |
|
1659 |
ShowRenameSignWindow(si); |
|
1660 |
return true; |
|
1661 |
} |
|
0 | 1662 |
} |
4471 | 1663 |
break; |
0 | 1664 |
} |
1665 |
||
1666 |
return false; |
|
1667 |
} |
|
1668 |
||
4471 | 1669 |
|
2116 | 1670 |
static bool CheckClickOnWaypoint(const ViewPort *vp, int x, int y) |
0 | 1671 |
{ |
2116 | 1672 |
const Waypoint *wp; |
0 | 1673 |
|
2116 | 1674 |
if (!(_display_opt & DO_WAYPOINTS)) return false; |
0 | 1675 |
|
4471 | 1676 |
switch (vp->zoom) { |
1677 |
case 0: |
|
1678 |
x = x - vp->left + vp->virtual_left; |
|
1679 |
y = y - vp->top + vp->virtual_top; |
|
1680 |
FOR_ALL_WAYPOINTS(wp) { |
|
1681 |
if (y >= wp->sign.top && |
|
1682 |
y < wp->sign.top + 12 && |
|
1683 |
x >= wp->sign.left && |
|
1684 |
x < wp->sign.left + wp->sign.width_1) { |
|
1685 |
ShowRenameWaypointWindow(wp); |
|
1686 |
return true; |
|
1687 |
} |
|
0 | 1688 |
} |
4471 | 1689 |
break; |
1690 |
||
1691 |
case 1: |
|
1692 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
|
1693 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
|
1694 |
FOR_ALL_WAYPOINTS(wp) { |
|
1695 |
if (y >= wp->sign.top && |
|
1696 |
y < wp->sign.top + 24 && |
|
1697 |
x >= wp->sign.left && |
|
1698 |
x < wp->sign.left + wp->sign.width_1 * 2) { |
|
1699 |
ShowRenameWaypointWindow(wp); |
|
1700 |
return true; |
|
1701 |
} |
|
0 | 1702 |
} |
4471 | 1703 |
break; |
1704 |
||
1705 |
default: |
|
1706 |
x = (x - vp->left + 3) * 4 + vp->virtual_left; |
|
1707 |
y = (y - vp->top + 3) * 4 + vp->virtual_top; |
|
1708 |
FOR_ALL_WAYPOINTS(wp) { |
|
1709 |
if (y >= wp->sign.top && |
|
1710 |
y < wp->sign.top + 24 && |
|
1711 |
x >= wp->sign.left && |
|
1712 |
x < wp->sign.left + wp->sign.width_2 * 4) { |
|
1713 |
ShowRenameWaypointWindow(wp); |
|
1714 |
return true; |
|
1715 |
} |
|
0 | 1716 |
} |
4471 | 1717 |
break; |
0 | 1718 |
} |
1719 |
||
1720 |
return false; |
|
1721 |
} |
|
1722 |
||
1723 |
||
2116 | 1724 |
static void CheckClickOnLandscape(const ViewPort *vp, int x, int y) |
0 | 1725 |
{ |
2116 | 1726 |
Point pt = TranslateXYToTileCoord(vp, x, y); |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1964
diff
changeset
|
1727 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1728 |
if (pt.x != -1) ClickTile(TileVirtXY(pt.x, pt.y)); |
0 | 1729 |
} |
1730 |
||
2662
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1731 |
|
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1732 |
static void SafeShowTrainViewWindow(const Vehicle* v) |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1733 |
{ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1734 |
if (!IsFrontEngine(v)) v = GetFirstVehicleInChain(v); |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1735 |
ShowTrainViewWindow(v); |
2662
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1736 |
} |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1737 |
|
4171 | 1738 |
static void Nop(const Vehicle *v) {} |
2662
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1739 |
|
4171 | 1740 |
typedef void OnVehicleClickProc(const Vehicle *v); |
2662
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1741 |
static OnVehicleClickProc* const _on_vehicle_click_proc[] = { |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1742 |
SafeShowTrainViewWindow, |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1743 |
ShowRoadVehViewWindow, |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1744 |
ShowShipViewWindow, |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1745 |
ShowAircraftViewWindow, |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1746 |
Nop, // Special vehicles |
42c11a1a0a4b
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1747 |
Nop // Disaster vehicles |
0 | 1748 |
}; |
1749 |
||
2116 | 1750 |
void HandleViewportClicked(const ViewPort *vp, int x, int y) |
0 | 1751 |
{ |
4171 | 1752 |
const Vehicle *v; |
0 | 1753 |
|
2116 | 1754 |
if (CheckClickOnTown(vp, x, y)) return; |
1755 |
if (CheckClickOnStation(vp, x, y)) return; |
|
1756 |
if (CheckClickOnSign(vp, x, y)) return; |
|
1757 |
if (CheckClickOnWaypoint(vp, x, y)) return; |
|
0 | 1758 |
CheckClickOnLandscape(vp, x, y); |
1759 |
||
2116 | 1760 |
v = CheckClickOnVehicle(vp, x, y); |
3809
cff6d5e916f7
(svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents:
3798
diff
changeset
|
1761 |
if (v != NULL) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5137
diff
changeset
|
1762 |
DEBUG(misc, 2, "Vehicle %d (index %d) at %p", v->unitnumber, v->index, v); |
3809
cff6d5e916f7
(svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents:
3798
diff
changeset
|
1763 |
_on_vehicle_click_proc[v->type - 0x10](v); |
cff6d5e916f7
(svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents:
3798
diff
changeset
|
1764 |
} |
0 | 1765 |
} |
1766 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
1767 |
Vehicle *CheckMouseOverVehicle(void) |
0 | 1768 |
{ |
4171 | 1769 |
const Window *w; |
1770 |
const ViewPort *vp; |
|
0 | 1771 |
|
1772 |
int x = _cursor.pos.x; |
|
1773 |
int y = _cursor.pos.y; |
|
1774 |
||
1775 |
w = FindWindowFromPt(x, y); |
|
2116 | 1776 |
if (w == NULL) return NULL; |
0 | 1777 |
|
1778 |
vp = IsPtInWindowViewport(w, x, y); |
|
2116 | 1779 |
return (vp != NULL) ? CheckClickOnVehicle(vp, x, y) : NULL; |
0 | 1780 |
} |
1781 |
||
1782 |
||
1783 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
1784 |
void PlaceObject(void) |
0 | 1785 |
{ |
1786 |
Point pt; |
|
1787 |
Window *w; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1788 |
|
0 | 1789 |
pt = GetTileBelowCursor(); |
2116 | 1790 |
if (pt.x == -1) return; |
0 | 1791 |
|
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1792 |
if (_thd.place_mode == VHM_POINT) { |
0 | 1793 |
pt.x += 8; |
1794 |
pt.y += 8; |
|
1795 |
} |
|
1796 |
||
1797 |
_tile_fract_coords.x = pt.x & 0xF; |
|
1798 |
_tile_fract_coords.y = pt.y & 0xF; |
|
1799 |
||
2116 | 1800 |
w = GetCallbackWnd(); |
1801 |
if (w != NULL) { |
|
1802 |
WindowEvent e; |
|
1803 |
||
0 | 1804 |
e.event = WE_PLACE_OBJ; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
1805 |
e.we.place.pt = pt; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
1806 |
e.we.place.tile = TileVirtXY(pt.x, pt.y); |
0 | 1807 |
w->wndproc(w, &e); |
1808 |
} |
|
1809 |
} |
|
1810 |
||
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
|
1811 |
|
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1812 |
/* scrolls the viewport in a window to a given location */ |
4171 | 1813 |
bool ScrollWindowTo(int x , int y, Window *w) |
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1814 |
{ |
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1815 |
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
|
1816 |
|
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1817 |
pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y)); |
2116 | 1818 |
WP(w, vp_d).follow_vehicle = INVALID_VEHICLE; |
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1819 |
|
2116 | 1820 |
if (WP(w, vp_d).scrollpos_x == pt.x && WP(w, vp_d).scrollpos_y == pt.y) |
1821 |
return false; |
|
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1822 |
|
2116 | 1823 |
WP(w, vp_d).scrollpos_x = pt.x; |
1824 |
WP(w, vp_d).scrollpos_y = pt.y; |
|
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1825 |
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
|
1826 |
} |
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
137
diff
changeset
|
1827 |
|
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
|
1828 |
|
0 | 1829 |
bool ScrollMainWindowTo(int x, int y) |
1830 |
{ |
|
4339
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1831 |
Window *w; |
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1832 |
bool res = ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0)); |
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1833 |
|
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1834 |
/* If a user scrolls to a tile (via what way what so ever) and already is on |
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1835 |
* that tile (e.g.: pressed twice), move the smallmap to that location, |
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1836 |
* so you directly see where you are on the smallmap. */ |
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1837 |
|
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1838 |
if (res) return res; |
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1839 |
|
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1840 |
w = FindWindowById(WC_SMALLMAP, 0); |
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1841 |
if (w == NULL) return res; |
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1842 |
|
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1843 |
SmallMapCenterOnCurrentPos(w); |
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1844 |
|
f5e99218131a
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents:
4334
diff
changeset
|
1845 |
return res; |
0 | 1846 |
} |
1847 |
||
1848 |
||
1849 |
bool ScrollMainWindowToTile(TileIndex tile) |
|
1850 |
{ |
|
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
1851 |
return ScrollMainWindowTo(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2); |
0 | 1852 |
} |
1853 |
||
1854 |
void SetRedErrorSquare(TileIndex tile) |
|
1855 |
{ |
|
1856 |
TileIndex old; |
|
1857 |
||
1858 |
old = _thd.redsq; |
|
1859 |
_thd.redsq = tile; |
|
1860 |
||
1861 |
if (tile != old) { |
|
3281
0f3d836e35b1
(svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents:
3279
diff
changeset
|
1862 |
if (tile != 0) MarkTileDirtyByTile(tile); |
0f3d836e35b1
(svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents:
3279
diff
changeset
|
1863 |
if (old != 0) MarkTileDirtyByTile(old); |
0 | 1864 |
} |
1865 |
} |
|
1866 |
||
1867 |
void SetTileSelectSize(int w, int h) |
|
1868 |
{ |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1869 |
_thd.new_size.x = w * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1870 |
_thd.new_size.y = h * TILE_SIZE; |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1871 |
_thd.new_outersize.x = 0; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1872 |
_thd.new_outersize.y = 0; |
0 | 1873 |
} |
1874 |
||
2116 | 1875 |
void SetTileSelectBigSize(int ox, int oy, int sx, int sy) |
1876 |
{ |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1877 |
_thd.offs.x = ox * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1878 |
_thd.offs.y = oy * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1879 |
_thd.new_outersize.x = sx * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1880 |
_thd.new_outersize.y = sy * TILE_SIZE; |
0 | 1881 |
} |
1882 |
||
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1883 |
/* returns the best autorail highlight type from map coordinates */ |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1884 |
static byte GetAutorailHT(int x, int y) |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1885 |
{ |
2710
e144188c1fdb
(svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents:
2676
diff
changeset
|
1886 |
return HT_RAIL | _AutorailPiece[x & 0xF][y & 0xF]; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1887 |
} |
0 | 1888 |
|
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1889 |
// called regular to update tile highlighting in all cases |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
1890 |
void UpdateTileSelection(void) |
0 | 1891 |
{ |
2116 | 1892 |
int x1; |
1893 |
int y1; |
|
0 | 1894 |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1895 |
_thd.new_drawstyle = 0; |
0 | 1896 |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1897 |
if (_thd.place_mode == VHM_SPECIAL) { |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1898 |
x1 = _thd.selend.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1899 |
y1 = _thd.selend.y; |
0 | 1900 |
if (x1 != -1) { |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1901 |
int x2 = _thd.selstart.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1902 |
int y2 = _thd.selstart.y; |
0 | 1903 |
x1 &= ~0xF; |
1904 |
y1 &= ~0xF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1905 |
|
0 | 1906 |
if (x1 >= x2) intswap(x1,x2); |
1907 |
if (y1 >= y2) intswap(y1,y2); |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1908 |
_thd.new_pos.x = x1; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1909 |
_thd.new_pos.y = y1; |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1910 |
_thd.new_size.x = x2 - x1 + TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1911 |
_thd.new_size.y = y2 - y1 + TILE_SIZE; |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1912 |
_thd.new_drawstyle = _thd.next_drawstyle; |
0 | 1913 |
} |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1914 |
} else if (_thd.place_mode != VHM_NONE) { |
2116 | 1915 |
Point pt = GetTileBelowCursor(); |
0 | 1916 |
x1 = pt.x; |
1917 |
y1 = pt.y; |
|
1918 |
if (x1 != -1) { |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1919 |
switch (_thd.place_mode) { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1920 |
case VHM_RECT: |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1921 |
_thd.new_drawstyle = HT_RECT; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1922 |
break; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1923 |
case VHM_POINT: |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1924 |
_thd.new_drawstyle = HT_POINT; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1925 |
x1 += 8; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1926 |
y1 += 8; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1927 |
break; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1928 |
case VHM_RAIL: |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1929 |
_thd.new_drawstyle = GetAutorailHT(pt.x, pt.y); // draw one highlighted tile |
0 | 1930 |
} |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1931 |
_thd.new_pos.x = x1 & ~0xF; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1932 |
_thd.new_pos.y = y1 & ~0xF; |
0 | 1933 |
} |
1934 |
} |
|
1935 |
||
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1936 |
// redraw selection |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1937 |
if (_thd.drawstyle != _thd.new_drawstyle || |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1938 |
_thd.pos.x != _thd.new_pos.x || _thd.pos.y != _thd.new_pos.y || |
4539
0b13858554fb
(svn r6368) -Fix [FS#136]: Station catchment area persists after switching tools. The
Darkvater
parents:
4523
diff
changeset
|
1939 |
_thd.size.x != _thd.new_size.x || _thd.size.y != _thd.new_size.y || |
0b13858554fb
(svn r6368) -Fix [FS#136]: Station catchment area persists after switching tools. The
Darkvater
parents:
4523
diff
changeset
|
1940 |
_thd.outersize.x != _thd.new_outersize.x || |
0b13858554fb
(svn r6368) -Fix [FS#136]: Station catchment area persists after switching tools. The
Darkvater
parents:
4523
diff
changeset
|
1941 |
_thd.outersize.y != _thd.new_outersize.y) { |
0 | 1942 |
// clear the old selection? |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1943 |
if (_thd.drawstyle) SetSelectionTilesDirty(); |
0 | 1944 |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1945 |
_thd.drawstyle = _thd.new_drawstyle; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1946 |
_thd.pos = _thd.new_pos; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1947 |
_thd.size = _thd.new_size; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1948 |
_thd.outersize = _thd.new_outersize; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1949 |
_thd.dirty = 0xff; |
0 | 1950 |
|
1951 |
// draw the new selection? |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1952 |
if (_thd.new_drawstyle) SetSelectionTilesDirty(); |
0 | 1953 |
} |
1954 |
} |
|
1955 |
||
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
1956 |
// highlighting tiles while only going over them with the mouse |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1964
diff
changeset
|
1957 |
void VpStartPlaceSizing(TileIndex tile, int user) |
0 | 1958 |
{ |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1959 |
_thd.userdata = user; |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1960 |
_thd.selend.x = TileX(tile) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1961 |
_thd.selstart.x = TileX(tile) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1962 |
_thd.selend.y = TileY(tile) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1963 |
_thd.selstart.y = TileY(tile) * TILE_SIZE; |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1964 |
if (_thd.place_mode == VHM_RECT) { |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1965 |
_thd.place_mode = VHM_SPECIAL; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1966 |
_thd.next_drawstyle = HT_RECT; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1967 |
} else if (_thd.place_mode == VHM_RAIL) { // autorail one piece |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1968 |
_thd.place_mode = VHM_SPECIAL; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1969 |
_thd.next_drawstyle = _thd.drawstyle; |
0 | 1970 |
} else { |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1971 |
_thd.place_mode = VHM_SPECIAL; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1972 |
_thd.next_drawstyle = HT_POINT; |
0 | 1973 |
} |
1974 |
_special_mouse_mode = WSM_SIZING; |
|
1975 |
} |
|
1976 |
||
1977 |
void VpSetPlaceSizingLimit(int limit) |
|
1978 |
{ |
|
1979 |
_thd.sizelimit = limit; |
|
1980 |
} |
|
1981 |
||
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1982 |
/** |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1983 |
* Highlights all tiles between a set of two tiles. Used in dock and tunnel placement |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1984 |
* @param from TileIndex of the first tile to highlight |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1985 |
* @param to TileIndex of the last tile to highlight */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1986 |
void VpSetPresizeRange(TileIndex from, TileIndex to) |
0 | 1987 |
{ |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1988 |
uint distance = DistanceManhattan(from, to) + 1; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1989 |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1990 |
_thd.selend.x = TileX(to) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1991 |
_thd.selend.y = TileY(to) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1992 |
_thd.selstart.x = TileX(from) * TILE_SIZE; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1993 |
_thd.selstart.y = TileY(from) * TILE_SIZE; |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1994 |
_thd.next_drawstyle = HT_RECT; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1995 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1996 |
/* show measurement only if there is any length to speak of */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
1997 |
if (distance > 1) GuiShowTooltipsWithArgs(STR_MEASURE_LENGTH, 1, &distance); |
0 | 1998 |
} |
1999 |
||
2817 | 2000 |
static void VpStartPreSizing(void) |
0 | 2001 |
{ |
2002 |
_thd.selend.x = -1; |
|
2003 |
_special_mouse_mode = WSM_PRESIZE; |
|
2004 |
} |
|
2005 |
||
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
2006 |
/* returns information about the 2x1 piece to be build. |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2007 |
* The lower bits (0-3) are the track type. */ |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2008 |
static byte Check2x1AutoRail(int mode) |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2009 |
{ |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2010 |
int fxpy = _tile_fract_coords.x + _tile_fract_coords.y; |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2011 |
int sxpy = (_thd.selend.x & 0xF) + (_thd.selend.y & 0xF); |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2012 |
int fxmy = _tile_fract_coords.x - _tile_fract_coords.y; |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2013 |
int sxmy = (_thd.selend.x & 0xF) - (_thd.selend.y & 0xF); |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2014 |
|
2952 | 2015 |
switch (mode) { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2016 |
case 0: // end piece is lower right |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2017 |
if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2018 |
if (fxmy < -3 && sxmy > 3) {/* DoRailroadTrack(0); */return 5; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2019 |
return 1; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2020 |
|
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2021 |
case 1: |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2022 |
if (fxmy > 3 && sxmy < -3) { /*SwapSelection(); DoRailroadTrack(0); */return 4; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2023 |
if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2024 |
return 1; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2025 |
|
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2026 |
case 2: |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2027 |
if (fxmy > 3 && sxmy < -3) { /*DoRailroadTrack(3);*/ return 4; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2028 |
if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2029 |
return 0; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2030 |
|
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2031 |
case 3: |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2032 |
if (fxmy < -3 && sxmy > 3) { /*SwapSelection(); DoRailroadTrack(3);*/ return 5; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2033 |
if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; } |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2034 |
return 0; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2035 |
} |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2036 |
|
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2037 |
return 0; // avoids compiler warnings |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2038 |
} |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2039 |
|
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2040 |
/** Check if the direction of start and end tile should be swapped based on |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2041 |
* the dragging-style. Default directions are: |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2042 |
* in the case of a line (HT_RAIL, HT_LINE): DIR_NE, DIR_NW, DIR_N, DIR_E |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2043 |
* in the case of a rect (HT_RECT, HT_POINT): DIR_S, DIR_E |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2044 |
* For example dragging a rectangle area from south to north should be swapped to |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2045 |
* north-south (DIR_S) to obtain the same results with less code. This is what |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2046 |
* the return value signifies. |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2047 |
* @param style HighLightStyle dragging style |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2048 |
* @param start_tile, end_tile start and end tile of drag |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2049 |
* @param boolean value which when true means start/end should be swapped */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2050 |
static bool SwapDirection(HighLightStyle style, TileIndex start_tile, TileIndex end_tile) |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2051 |
{ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2052 |
uint start_x = TileX(start_tile); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2053 |
uint start_y = TileY(start_tile); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2054 |
uint end_x = TileX(end_tile); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2055 |
uint end_y = TileY(end_tile); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2056 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2057 |
switch (style & HT_DRAG_MASK) { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2058 |
case HT_RAIL: |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2059 |
case HT_LINE: return (end_x > start_x || (end_x == start_x && end_y > start_y)); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2060 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2061 |
case HT_RECT: |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2062 |
case HT_POINT: return (end_x != start_x && end_y < start_y); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2063 |
default: NOT_REACHED(); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2064 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2065 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2066 |
return false; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2067 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2068 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2069 |
/** Calculates height difference between one tile and another |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2070 |
* Multiplies the result to suit the standard given by minimap - 50 meters high |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2071 |
* To correctly get the height difference we need the direction we are dragging |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2072 |
* in, as well as with what kind of tool we are dragging. For example a horizontal |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2073 |
* autorail tool that starts in bottom and ends at the top of a tile will need the |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2074 |
* maximum of SW,S and SE,N corners respectively. This is handled by the lookup table below |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2075 |
* See _tileoffs_by_dir in map.c for the direction enums if you can't figure out |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2076 |
* the values yourself. |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2077 |
* @param style HightlightStyle of drag. This includes direction and style (autorail, rect, etc.) |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2078 |
* @param distance amount of tiles dragged, important for horizontal/vertical drags |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2079 |
* ignored for others |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2080 |
* @param start_tile, end_tile start and end tile of drag operation |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2081 |
* @return height difference between two tiles. Tile measurement tool utilizes |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2082 |
* this value in its tooltips */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2083 |
static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_tile, TileIndex end_tile) |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2084 |
{ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2085 |
bool swap = SwapDirection(style, start_tile, end_tile); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2086 |
byte style_t; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2087 |
uint h0, h1, ht; // start heigth, end height, and temp variable |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2088 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2089 |
if (start_tile == end_tile) return 0; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2090 |
if (swap) swap_tile(&start_tile, &end_tile); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2091 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2092 |
switch (style & HT_DRAG_MASK) { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2093 |
case HT_RECT: { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2094 |
static const TileIndexDiffC heightdiff_area_by_dir[] = { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2095 |
/* Start */ {1, 0}, /* Dragging east */ {0, 0}, /* Dragging south */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2096 |
/* End */ {0, 1}, /* Dragging east */ {1, 1} /* Dragging south */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2097 |
}; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2098 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2099 |
/* In the case of an area we can determine whether we were dragging south or |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2100 |
* east by checking the X-coordinates of the tiles */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2101 |
style_t = (byte)(TileX(end_tile) > TileX(start_tile)); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2102 |
start_tile = TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_area_by_dir[style_t])); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2103 |
end_tile = TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_area_by_dir[2 + style_t])); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2104 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2105 |
/* Fallthrough */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2106 |
case HT_POINT: |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2107 |
h0 = TileHeight(start_tile); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2108 |
h1 = TileHeight(end_tile); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2109 |
break; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2110 |
default: { /* All other types, this is mostly only line/autorail */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2111 |
static const HighLightStyle flip_style_direction[] = { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2112 |
HT_DIR_X, HT_DIR_Y, HT_DIR_HL, HT_DIR_HU, HT_DIR_VR, HT_DIR_VL |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2113 |
}; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2114 |
static const TileIndexDiffC heightdiff_line_by_dir[] = { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2115 |
/* Start */ {1, 0}, {1, 1}, /* HT_DIR_X */ {0, 1}, {1, 1}, /* HT_DIR_Y */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2116 |
/* Start */ {1, 0}, {0, 0}, /* HT_DIR_HU */ {1, 0}, {1, 1}, /* HT_DIR_HL */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2117 |
/* Start */ {1, 0}, {1, 1}, /* HT_DIR_VL */ {0, 1}, {1, 1}, /* HT_DIR_VR */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2118 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2119 |
/* Start */ {0, 1}, {0, 0}, /* HT_DIR_X */ {1, 0}, {0, 0}, /* HT_DIR_Y */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2120 |
/* End */ {0, 1}, {0, 0}, /* HT_DIR_HU */ {1, 1}, {0, 1}, /* HT_DIR_HL */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2121 |
/* End */ {1, 0}, {0, 0}, /* HT_DIR_VL */ {0, 0}, {0, 1}, /* HT_DIR_VR */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2122 |
}; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2123 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2124 |
distance %= 2; // we're only interested if the distance is even or uneven |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2125 |
style &= HT_DIR_MASK; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2126 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2127 |
/* To handle autorail, we do some magic to be able to use a lookup table. |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2128 |
* Firstly if we drag the other way around, we switch start&end, and if needed |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2129 |
* also flip the drag-position. Eg if it was on the left, and the distance is even |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2130 |
* that means the end, which is now the start is on the right */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2131 |
if (swap && distance == 0) style = flip_style_direction[style]; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2132 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2133 |
/* Use lookup table for start-tile based on HighLightStyle direction */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2134 |
style_t = style * 2; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2135 |
assert(style_t < lengthof(heightdiff_line_by_dir) - 13); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2136 |
h0 = TileHeight(TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_line_by_dir[style_t]))); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2137 |
ht = TileHeight(TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_line_by_dir[style_t + 1]))); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2138 |
h0 = maxu(h0, ht); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2139 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2140 |
/* Use lookup table for end-tile based on HighLightStyle direction |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2141 |
* flip around side (lower/upper, left/right) based on distance */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2142 |
if (distance == 0) style_t = flip_style_direction[style] * 2; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2143 |
assert(style_t < lengthof(heightdiff_line_by_dir) - 13); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2144 |
h1 = TileHeight(TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_line_by_dir[12 + style_t]))); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2145 |
ht = TileHeight(TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_line_by_dir[12 + style_t + 1]))); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2146 |
h1 = maxu(h1, ht); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2147 |
} break; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2148 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2149 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2150 |
if (swap) swap_uint32(&h0, &h1); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2151 |
/* Minimap shows height in intervals of 50 meters, let's do the same */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2152 |
return (int)(h1 - h0) * 50; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2153 |
} |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2154 |
|
4885
c9fe8c52fd50
(svn r6822) -Fix r6821: add type for measure_strings_length[]
glx
parents:
4884
diff
changeset
|
2155 |
static const StringID measure_strings_length[] = {STR_NULL, STR_MEASURE_LENGTH, STR_MEASURE_LENGTH_HEIGHTDIFF}; |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2156 |
|
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2157 |
// while dragging |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2158 |
static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int method) |
0 | 2159 |
{ |
4799
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2160 |
HighLightStyle b; |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2161 |
uint w, h; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2162 |
|
4799
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2163 |
int dx = thd->selstart.x - (thd->selend.x & ~0xF); |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2164 |
int dy = thd->selstart.y - (thd->selend.y & ~0xF); |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2165 |
w = myabs(dx) + 16; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2166 |
h = myabs(dy) + 16; |
0 | 2167 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
2168 |
if (TileVirtXY(thd->selstart.x, thd->selstart.y) == TileVirtXY(x, y)) { // check if we're only within one tile |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2169 |
if (method == VPM_RAILDIRS) { |
2116 | 2170 |
b = GetAutorailHT(x, y); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2171 |
} else { // rect for autosignals on one tile |
2116 | 2172 |
b = HT_RECT; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2173 |
} |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2174 |
} else if (h == 16) { // Is this in X direction? |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2175 |
if (dx == 16) { // 2x1 special handling |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2176 |
b = (Check2x1AutoRail(3)) | HT_LINE; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2177 |
} else if (dx == -16) { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2178 |
b = (Check2x1AutoRail(2)) | HT_LINE; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2179 |
} else { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2180 |
b = HT_LINE | HT_DIR_X; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2181 |
} |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2182 |
y = thd->selstart.y; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2183 |
} else if (w == 16) { // Or Y direction? |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2184 |
if (dy == 16) { // 2x1 special handling |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2185 |
b = (Check2x1AutoRail(1)) | HT_LINE; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2186 |
} else if (dy == -16) { // 2x1 other direction |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2187 |
b = (Check2x1AutoRail(0)) | HT_LINE; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2188 |
} else { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2189 |
b = HT_LINE | HT_DIR_Y; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2190 |
} |
0 | 2191 |
x = thd->selstart.x; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2192 |
} else if (w > h * 2) { // still count as x dir? |
2116 | 2193 |
b = HT_LINE | HT_DIR_X; |
0 | 2194 |
y = thd->selstart.y; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2195 |
} else if (h > w * 2) { // still count as y dir? |
2116 | 2196 |
b = HT_LINE | HT_DIR_Y; |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2197 |
x = thd->selstart.x; |
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2198 |
} else { // complicated direction |
4799
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2199 |
int d = w - h; |
2116 | 2200 |
thd->selend.x = thd->selend.x & ~0xF; |
2201 |
thd->selend.y = thd->selend.y & ~0xF; |
|
0 | 2202 |
|
2203 |
// four cases. |
|
2204 |
if (x > thd->selstart.x) { |
|
2205 |
if (y > thd->selstart.y) { |
|
2206 |
// south |
|
2116 | 2207 |
if (d == 0) { |
2208 |
b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR; |
|
2209 |
} else if (d >= 0) { |
|
2210 |
x = thd->selstart.x + h; |
|
2211 |
b = HT_LINE | HT_DIR_VL; |
|
2212 |
// return px == py || px == py + 16; |
|
2213 |
} else { |
|
2214 |
y = thd->selstart.y + w; |
|
2215 |
b = HT_LINE | HT_DIR_VR; |
|
2216 |
} // return px == py || px == py - 16; |
|
0 | 2217 |
} else { |
2218 |
// west |
|
2116 | 2219 |
if (d == 0) { |
2220 |
b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU; |
|
2221 |
} else if (d >= 0) { |
|
2222 |
x = thd->selstart.x + h; |
|
2223 |
b = HT_LINE | HT_DIR_HL; |
|
2224 |
} else { |
|
2225 |
y = thd->selstart.y - w; |
|
2226 |
b = HT_LINE | HT_DIR_HU; |
|
2227 |
} |
|
0 | 2228 |
} |
2229 |
} else { |
|
2230 |
if (y > thd->selstart.y) { |
|
2231 |
// east |
|
2116 | 2232 |
if (d == 0) { |
2233 |
b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU; |
|
2234 |
} else if (d >= 0) { |
|
2235 |
x = thd->selstart.x - h; |
|
2236 |
b = HT_LINE | HT_DIR_HU; |
|
2237 |
// return px == -py || px == -py - 16; |
|
2238 |
} else { |
|
2239 |
y = thd->selstart.y + w; |
|
2240 |
b = HT_LINE | HT_DIR_HL; |
|
2241 |
} // return px == -py || px == -py + 16; |
|
0 | 2242 |
} else { |
2243 |
// north |
|
2116 | 2244 |
if (d == 0) { |
2245 |
b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR; |
|
2246 |
} else if (d >= 0) { |
|
2247 |
x = thd->selstart.x - h; |
|
2248 |
b = HT_LINE | HT_DIR_VR; |
|
2249 |
// return px == py || px == py - 16; |
|
2250 |
} else { |
|
2251 |
y = thd->selstart.y - w; |
|
2252 |
b = HT_LINE | HT_DIR_VL; |
|
2253 |
} //return px == py || px == py + 16; |
|
0 | 2254 |
} |
2255 |
} |
|
2256 |
} |
|
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2257 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2258 |
if (_patches.measure_tooltip) { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2259 |
TileIndex t0 = TileVirtXY(thd->selstart.x, thd->selstart.y); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2260 |
TileIndex t1 = TileVirtXY(x, y); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2261 |
uint distance = DistanceManhattan(t0, t1) + 1; |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2262 |
byte index = 0; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2263 |
uint params[2]; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2264 |
|
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2265 |
if (distance != 1) { |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2266 |
int heightdiff = CalcHeightdiff(b, distance, t0, t1); |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2267 |
/* If we are showing a tooltip for horizontal or vertical drags, |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2268 |
* 2 tiles have a length of 1. To bias towards the ceiling we add |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2269 |
* one before division. It feels more natural to count 3 lengths as 2 */ |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2270 |
if ((b & HT_DIR_MASK) != HT_DIR_X && (b & HT_DIR_MASK) != HT_DIR_Y) { |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2271 |
distance = (distance + 1) / 2; |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2272 |
} |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2273 |
|
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2274 |
params[index++] = distance; |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2275 |
if (heightdiff != 0) params[index++] = heightdiff; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2276 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2277 |
|
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2278 |
GuiShowTooltipsWithArgs(measure_strings_length[index], index, params); |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2279 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2280 |
|
0 | 2281 |
thd->selend.x = x; |
2282 |
thd->selend.y = y; |
|
2283 |
thd->next_drawstyle = b; |
|
2284 |
} |
|
2285 |
||
4799
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2286 |
/** |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2287 |
* Selects tiles while dragging |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2288 |
* @param x X coordinate of end of selection |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2289 |
* @param y Y coordinate of end of selection |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2290 |
* @param method modifies the way tiles are selected. Possible |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2291 |
* methods are VPM_* in viewport.h */ |
0 | 2292 |
void VpSelectTilesWithMethod(int x, int y, int method) |
2293 |
{ |
|
4799
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2294 |
int sx, sy; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2295 |
HighLightStyle style; |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2296 |
|
0 | 2297 |
if (x == -1) { |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2298 |
_thd.selend.x = -1; |
0 | 2299 |
return; |
2300 |
} |
|
2301 |
||
4799
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2302 |
/* Special handling of drag in any (8-way) 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
|
2303 |
if (method == VPM_RAILDIRS || method == VPM_SIGNALDIRS) { |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2304 |
_thd.selend.x = x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2305 |
_thd.selend.y = y; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2306 |
CalcRaildirsDrawstyle(&_thd, x, y, method); |
0 | 2307 |
return; |
2308 |
} |
|
2309 |
||
2116 | 2310 |
if (_thd.next_drawstyle == HT_POINT) { |
4799
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2311 |
x += TILE_SIZE / 2; |
a32af5dd7b6c
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2312 |
y += TILE_SIZE / 2; |
2116 | 2313 |
} |
0 | 2314 |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2315 |
sx = _thd.selstart.x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2316 |
sy = _thd.selstart.y; |
0 | 2317 |
|
2116 | 2318 |
switch (method) { |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2319 |
case VPM_X_OR_Y: /* drag in X or Y direction */ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2320 |
if (myabs(sy - y) < myabs(sx - x)) { |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2321 |
y = sy; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2322 |
style = HT_DIR_X; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2323 |
} else { |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2324 |
x = sx; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2325 |
style = HT_DIR_Y; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2326 |
} |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2327 |
goto calc_heightdiff_single_direction; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2328 |
case VPM_FIX_X: /* drag in Y direction */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2329 |
x = sx; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2330 |
style = HT_DIR_Y; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2331 |
goto calc_heightdiff_single_direction; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2332 |
case VPM_FIX_Y: /* drag in X direction */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2333 |
y = sy; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2334 |
style = HT_DIR_X; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2335 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2336 |
calc_heightdiff_single_direction:; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2337 |
if (_patches.measure_tooltip) { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2338 |
TileIndex t0 = TileVirtXY(sx, sy); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2339 |
TileIndex t1 = TileVirtXY(x, y); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2340 |
uint distance = DistanceManhattan(t0, t1) + 1; |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2341 |
byte index = 0; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2342 |
uint params[2]; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2343 |
|
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2344 |
if (distance != 1) { |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2345 |
/* With current code passing a HT_LINE style to calculate the height |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2346 |
* difference is enough. However if/when a point-tool is created |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2347 |
* with this method, function should be called with new_style (below) |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2348 |
* instead of HT_LINE | style case HT_POINT is handled specially |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2349 |
* new_style := (_thd.next_drawstyle & HT_RECT) ? HT_LINE | style : _thd.next_drawstyle; */ |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2350 |
int heightdiff = CalcHeightdiff(HT_LINE | style, 0, t0, t1); |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2351 |
|
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2352 |
params[index++] = distance; |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2353 |
if (heightdiff != 0) params[index++] = heightdiff; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2354 |
} |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2355 |
|
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2356 |
GuiShowTooltipsWithArgs(measure_strings_length[index], index, params); |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2357 |
} break; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2358 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2359 |
case VPM_X_AND_Y_LIMITED: { /* drag an X by Y constrained rect area */ |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2360 |
int limit = (_thd.sizelimit - 1) * TILE_SIZE; |
2116 | 2361 |
x = sx + clamp(x - sx, -limit, limit); |
2362 |
y = sy + clamp(y - sy, -limit, limit); |
|
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2363 |
/* Fallthrough */ |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2364 |
case VPM_X_AND_Y: /* drag an X by Y area */ |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2365 |
if (_patches.measure_tooltip) { |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2366 |
static const StringID measure_strings_area[] = { |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2367 |
STR_NULL, STR_NULL, STR_MEASURE_AREA, STR_MEASURE_AREA_HEIGHTDIFF |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2368 |
}; |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2369 |
|
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2370 |
TileIndex t0 = TileVirtXY(sx, sy); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2371 |
TileIndex t1 = TileVirtXY(x, y); |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2372 |
uint dx = abs(TileX(t0) - TileX(t1)) + 1; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2373 |
uint dy = abs(TileY(t0) - TileY(t1)) + 1; |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2374 |
byte index = 0; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2375 |
uint params[3]; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2376 |
|
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2377 |
/* If dragging an area (eg dynamite tool) and it is actually a single |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2378 |
* row/column, change the type to 'line' to get proper calculation for height */ |
4838
d7570b95d5f8
(svn r6764) -Fix (r6758): Wrong height difference calculated because invalid drag-type
Darkvater
parents:
4834
diff
changeset
|
2379 |
style = _thd.next_drawstyle; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2380 |
if (style & HT_RECT) { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2381 |
if (dx == 1) { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2382 |
style = HT_LINE | HT_DIR_Y; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2383 |
} else if (dy == 1) { |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2384 |
style = HT_LINE | HT_DIR_X; |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2385 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2386 |
} |
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2387 |
|
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2388 |
if (dx != 1 || dy != 1) { |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2389 |
int heightdiff = CalcHeightdiff(style, 0, t0, t1); |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2390 |
|
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2391 |
params[index++] = dx; |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2392 |
params[index++] = dy; |
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2393 |
if (heightdiff != 0) params[index++] = heightdiff; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2394 |
} |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2395 |
|
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2396 |
GuiShowTooltipsWithArgs(measure_strings_area[index], index, params); |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2397 |
} |
4884
895f06b87934
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2398 |
break; |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2399 |
|
2116 | 2400 |
} |
4834
ddcf440d0ffd
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2401 |
default: NOT_REACHED(); |
0 | 2402 |
} |
2403 |
||
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2404 |
_thd.selend.x = x; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2405 |
_thd.selend.y = y; |
0 | 2406 |
} |
2407 |
||
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
2408 |
// while dragging |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
2409 |
bool VpHandlePlaceSizingDrag(void) |
0 | 2410 |
{ |
2411 |
Window *w; |
|
2412 |
WindowEvent e; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2413 |
|
2116 | 2414 |
if (_special_mouse_mode != WSM_SIZING) return true; |
0 | 2415 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
2416 |
e.we.place.userdata = _thd.userdata; |
0 | 2417 |
|
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2418 |
// stop drag mode if the window has been closed |
0 | 2419 |
w = FindWindowById(_thd.window_class,_thd.window_number); |
2420 |
if (w == NULL) { |
|
2421 |
ResetObjectToPlace(); |
|
2422 |
return false; |
|
2423 |
} |
|
2424 |
||
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2425 |
// while dragging execute the drag procedure of the corresponding window (mostly VpSelectTilesWithMethod() ) |
0 | 2426 |
if (_left_button_down) { |
2427 |
e.event = WE_PLACE_DRAG; |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
2428 |
e.we.place.pt = GetTileBelowCursor(); |
0 | 2429 |
w->wndproc(w, &e); |
2430 |
return false; |
|
2431 |
} |
|
2432 |
||
2433 |
// mouse button released.. |
|
2434 |
// 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
|
2435 |
_special_mouse_mode = WSM_NONE; |
2116 | 2436 |
if (_thd.next_drawstyle == HT_RECT) { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2437 |
_thd.place_mode = VHM_RECT; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
2438 |
} else if ((e.we.place.userdata & 0xF) == VPM_SIGNALDIRS) { // some might call this a hack... -- Dominik |
2116 | 2439 |
_thd.place_mode = VHM_RECT; |
2440 |
} else if (_thd.next_drawstyle & HT_LINE) { |
|
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2441 |
_thd.place_mode = VHM_RAIL; |
2116 | 2442 |
} else if (_thd.next_drawstyle & HT_RAIL) { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2443 |
_thd.place_mode = VHM_RAIL; |
2116 | 2444 |
} else { |
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2445 |
_thd.place_mode = VHM_POINT; |
2116 | 2446 |
} |
0 | 2447 |
SetTileSelectSize(1, 1); |
2448 |
||
2449 |
// and call the mouseup event. |
|
2450 |
e.event = WE_PLACE_MOUSEUP; |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
2451 |
e.we.place.pt = _thd.selend; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
2452 |
e.we.place.tile = TileVirtXY(e.we.place.pt.x, e.we.place.pt.y); |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
2453 |
e.we.place.starttile = TileVirtXY(_thd.selstart.x, _thd.selstart.y); |
0 | 2454 |
w->wndproc(w, &e); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2455 |
|
0 | 2456 |
return false; |
2457 |
} |
|
2458 |
||
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
2459 |
void SetObjectToPlaceWnd(CursorID icon, byte mode, Window *w) |
0 | 2460 |
{ |
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
2461 |
SetObjectToPlace(icon, mode, w->window_class, w->window_number); |
0 | 2462 |
} |
2463 |
||
2464 |
#include "table/animcursors.h" |
|
2465 |
||
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
2466 |
void SetObjectToPlace(CursorID icon, byte mode, WindowClass window_class, WindowNumber window_num) |
0 | 2467 |
{ |
2468 |
Window *w; |
|
2469 |
||
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2470 |
// undo clicking on button |
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2471 |
if (_thd.place_mode != 0) { |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2472 |
_thd.place_mode = 0; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2473 |
w = FindWindowById(_thd.window_class, _thd.window_number); |
2116 | 2474 |
if (w != NULL) CallWindowEventNP(w, WE_ABORT_PLACE_OBJ); |
0 | 2475 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2476 |
|
0 | 2477 |
SetTileSelectSize(1, 1); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2478 |
|
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2479 |
_thd.make_square_red = false; |
0 | 2480 |
|
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2481 |
if (mode == VHM_DRAG) { // mode 4 is for dragdropping trains in the depot window |
0 | 2482 |
mode = 0; |
2483 |
_special_mouse_mode = WSM_DRAGDROP; |
|
2484 |
} else { |
|
2485 |
_special_mouse_mode = WSM_NONE; |
|
2486 |
} |
|
2487 |
||
1863
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2488 |
_thd.place_mode = mode; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2489 |
_thd.window_class = window_class; |
610acc8bc189
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2490 |
_thd.window_number = window_num; |
0 | 2491 |
|
1070
bef634a62323
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2492 |
if (mode == VHM_SPECIAL) // special tools, like tunnels or docks start with presizing mode |
0 | 2493 |
VpStartPreSizing(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2494 |
|
0 | 2495 |
if ( (int)icon < 0) |
4334
75322a204d0c
(svn r6035) -Revert r5900 which supposedly fixed an invalid warning caused by buggy MS software
Darkvater
parents:
4272
diff
changeset
|
2496 |
SetAnimatedMouseCursor(_animcursors[~icon]); |
0 | 2497 |
else |
2498 |
SetMouseCursor(icon); |
|
2499 |
} |
|
2500 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
2501 |
void ResetObjectToPlace(void) |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
2502 |
{ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2503 |
SetObjectToPlace(SPR_CURSOR_MOUSE, VHM_NONE, 0, 0); |
0 | 2504 |
} |