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