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