author | peter1138 |
Sun, 03 Aug 2008 17:35:08 +0000 | |
changeset 9834 | 7474149531c1 |
parent 9781 | 31e0e461d7bf |
child 9847 | d1f9d05f76dd |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
9082
diff
changeset
|
3 |
/** @file viewport.cpp Handling of all viewports. |
8957
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
4 |
* |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
5 |
* \verbatim |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
6 |
* The in-game coordinate system looks like this * |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
7 |
* * |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
8 |
* ^ Z * |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
9 |
* | * |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
10 |
* | * |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
11 |
* | * |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
12 |
* | * |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
13 |
* / \ * |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
14 |
* / \ * |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
15 |
* / \ * |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
16 |
* / \ * |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
17 |
* X < > Y * |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
18 |
* \endverbatim |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
19 |
*/ |
6117
6507b2a7e71d
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6106
diff
changeset
|
20 |
|
0 | 21 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1864
diff
changeset
|
22 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1172
diff
changeset
|
23 |
#include "debug.h" |
8119
52b48108425a
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents:
8114
diff
changeset
|
24 |
#include "tile_cmd.h" |
2662
8b46824bd821
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
25 |
#include "gui.h" |
1349
15979a2e9001
(svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents:
1309
diff
changeset
|
26 |
#include "spritecache.h" |
6453
226bcddeba32
(svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents:
6448
diff
changeset
|
27 |
#include "landscape.h" |
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
28 |
#include "viewport_func.h" |
8785
871586967963
(svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents:
8743
diff
changeset
|
29 |
#include "station_base.h" |
0 | 30 |
#include "town.h" |
8790 | 31 |
#include "signs_base.h" |
32 |
#include "signs_func.h" |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1390
diff
changeset
|
33 |
#include "waypoint.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2125
diff
changeset
|
34 |
#include "variables.h" |
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2662
diff
changeset
|
35 |
#include "train.h" |
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6853
diff
changeset
|
36 |
#include "roadveh.h" |
7486
bf6a94009823
(svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents:
7333
diff
changeset
|
37 |
#include "vehicle_gui.h" |
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6878
diff
changeset
|
38 |
#include "blitter/factory.hpp" |
7849
0a1c0af2c96c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
7824
diff
changeset
|
39 |
#include "transparency.h" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8106
diff
changeset
|
40 |
#include "strings_func.h" |
8123
ce31d2843a95
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8121
diff
changeset
|
41 |
#include "zoom_func.h" |
8144
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8139
diff
changeset
|
42 |
#include "vehicle_func.h" |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8237
diff
changeset
|
43 |
#include "player_func.h" |
8270
e7c342f6b14c
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8264
diff
changeset
|
44 |
#include "settings_type.h" |
8785
871586967963
(svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents:
8743
diff
changeset
|
45 |
#include "station_func.h" |
8925
e0d37ce1eba8
(svn r12695) -Codechange: only allocate window structs when needed. Based on a patch by Alberth.
rubidium
parents:
8806
diff
changeset
|
46 |
#include "core/alloc_type.hpp" |
9555
68e7c84b2d19
(svn r13575) -Codechange: Move small vector to core since it fits better in there
skidd13
parents:
9553
diff
changeset
|
47 |
#include "core/smallvec_type.hpp" |
9117
87f472043e9e
(svn r12977) -Codechange: remove quite some redundant (duplicate) function declarations.
rubidium
parents:
9111
diff
changeset
|
48 |
#include "window_func.h" |
9127
14f21c5954ee
(svn r12987) -Codechange: split viewport and tile selection.
rubidium
parents:
9117
diff
changeset
|
49 |
#include "tilehighlight_func.h" |
9274
42b67e65f1c2
(svn r13140) -Codechange: move the gui-list-sorting out of window_gui.h so window_gui.h only needs to be included in *_gui.cpp.
rubidium
parents:
9273
diff
changeset
|
50 |
#include "window_gui.h" |
8946
a800978c3c8f
(svn r12734) -Codechange: use a vector instead of allocating memory in a big byte array for StringSpriteToDraw.
rubidium
parents:
8925
diff
changeset
|
51 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
52 |
#include "table/sprites.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
53 |
#include "table/strings.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
54 |
|
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
55 |
PlaceProc *_place_proc; |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
56 |
Point _tile_fract_coords; |
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
57 |
ZoomLevel _saved_scrollpos_zoom; |
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
58 |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
59 |
struct StringSpriteToDraw { |
0 | 60 |
uint16 string; |
61 |
uint16 color; |
|
849
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
62 |
int32 x; |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
63 |
int32 y; |
7006
bfa3974da32b
(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:
6937
diff
changeset
|
64 |
uint64 params[2]; |
0 | 65 |
uint16 width; |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
66 |
}; |
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
67 |
|
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
68 |
struct TileSpriteToDraw { |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5602
diff
changeset
|
69 |
SpriteID image; |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5602
diff
changeset
|
70 |
SpriteID pal; |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
71 |
const SubSprite *sub; ///< only draw a rectangular part of the sprite |
849
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
72 |
int32 x; |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
73 |
int32 y; |
0 | 74 |
byte z; |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
75 |
}; |
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
76 |
|
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
77 |
struct ChildScreenSpriteToDraw { |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5602
diff
changeset
|
78 |
SpriteID image; |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5602
diff
changeset
|
79 |
SpriteID pal; |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
80 |
const SubSprite *sub; ///< only draw a rectangular part of the sprite |
849
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
81 |
int32 x; |
c3407041774f
(svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents:
835
diff
changeset
|
82 |
int32 y; |
9534
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
83 |
int next; ///< next child to draw (-1 at the end) |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
84 |
}; |
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
85 |
|
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
86 |
struct ParentSpriteToDraw { |
7569
86ad3f6e7a1a
(svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents:
7545
diff
changeset
|
87 |
SpriteID image; ///< sprite to draw |
86ad3f6e7a1a
(svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents:
7545
diff
changeset
|
88 |
SpriteID pal; ///< palette to use |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
89 |
const SubSprite *sub; ///< only draw a rectangular part of the sprite |
7569
86ad3f6e7a1a
(svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents:
7545
diff
changeset
|
90 |
|
7580
fc9a8300f34e
(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:
7579
diff
changeset
|
91 |
int32 x; ///< screen X coordinate of sprite |
fc9a8300f34e
(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:
7579
diff
changeset
|
92 |
int32 y; ///< screen Y coordinate of sprite |
fc9a8300f34e
(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:
7579
diff
changeset
|
93 |
|
7569
86ad3f6e7a1a
(svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents:
7545
diff
changeset
|
94 |
int32 left; ///< minimal screen X coordinate of sprite (= x + sprite->x_offs), reference point for child sprites |
86ad3f6e7a1a
(svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents:
7545
diff
changeset
|
95 |
int32 top; ///< minimal screen Y coordinate of sprite (= y + sprite->y_offs), reference point for child sprites |
86ad3f6e7a1a
(svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents:
7545
diff
changeset
|
96 |
|
86ad3f6e7a1a
(svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents:
7545
diff
changeset
|
97 |
int32 xmin; ///< minimal world X coordinate of bounding box |
86ad3f6e7a1a
(svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents:
7545
diff
changeset
|
98 |
int32 xmax; ///< maximal world X coordinate of bounding box |
86ad3f6e7a1a
(svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents:
7545
diff
changeset
|
99 |
int32 ymin; ///< minimal world Y coordinate of bounding box |
86ad3f6e7a1a
(svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents:
7545
diff
changeset
|
100 |
int32 ymax; ///< maximal world Y coordinate of bounding box |
7580
fc9a8300f34e
(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:
7579
diff
changeset
|
101 |
int zmin; ///< minimal world Z coordinate of bounding box |
fc9a8300f34e
(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:
7579
diff
changeset
|
102 |
int zmax; ///< maximal world Z coordinate of bounding box |
7569
86ad3f6e7a1a
(svn r11094) -Documentation: Add comments on viewport structures and change an obscure variable name to something a little more meaningfull.
belugas
parents:
7545
diff
changeset
|
103 |
|
8952
be6bfd75e554
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
8951
diff
changeset
|
104 |
int first_child; ///< the first child to draw. |
7580
fc9a8300f34e
(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:
7579
diff
changeset
|
105 |
bool comparison_done; ///< Used during sprite sorting: true if sprite has been compared with all other sprites |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
106 |
}; |
0 | 107 |
|
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
108 |
/* Enumeration of multi-part foundations */ |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
109 |
enum FoundationPart { |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
110 |
FOUNDATION_PART_NONE = 0xFF, ///< Neither foundation nor groundsprite drawn yet. |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
111 |
FOUNDATION_PART_NORMAL = 0, ///< First part (normal foundation or no foundation) |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
112 |
FOUNDATION_PART_HALFTILE = 1, ///< Second part (halftile foundation) |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
113 |
FOUNDATION_PART_END |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
114 |
}; |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
115 |
|
8949
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
116 |
typedef SmallVector<TileSpriteToDraw, 64> TileSpriteToDrawVector; |
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
117 |
typedef SmallVector<StringSpriteToDraw, 4> StringSpriteToDrawVector; |
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
118 |
typedef SmallVector<ParentSpriteToDraw, 64> ParentSpriteToDrawVector; |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
119 |
typedef SmallVector<ParentSpriteToDraw*, 64> ParentSpriteToSortVector; |
8952
be6bfd75e554
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
8951
diff
changeset
|
120 |
typedef SmallVector<ChildScreenSpriteToDraw, 16> ChildScreenSpriteToDrawVector; |
8946
a800978c3c8f
(svn r12734) -Codechange: use a vector instead of allocating memory in a big byte array for StringSpriteToDraw.
rubidium
parents:
8925
diff
changeset
|
121 |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
122 |
struct ViewportDrawer { |
0 | 123 |
DrawPixelInfo dpi; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
124 |
|
8946
a800978c3c8f
(svn r12734) -Codechange: use a vector instead of allocating memory in a big byte array for StringSpriteToDraw.
rubidium
parents:
8925
diff
changeset
|
125 |
StringSpriteToDrawVector string_sprites_to_draw; |
8947
89220c41178d
(svn r12735) -Codechange: use a vector instead of allocating memory in a byte array for TileSpriteToDraw.
rubidium
parents:
8946
diff
changeset
|
126 |
TileSpriteToDrawVector tile_sprites_to_draw; |
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
127 |
ParentSpriteToDrawVector parent_sprites_to_draw; |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
128 |
ParentSpriteToSortVector parent_sprites_to_sort; |
8952
be6bfd75e554
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
8951
diff
changeset
|
129 |
ChildScreenSpriteToDrawVector child_screen_sprites_to_draw; |
be6bfd75e554
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
8951
diff
changeset
|
130 |
|
be6bfd75e554
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
8951
diff
changeset
|
131 |
int *last_child; |
0 | 132 |
|
133 |
byte combine_sprites; |
|
134 |
||
8952
be6bfd75e554
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
8951
diff
changeset
|
135 |
int foundation[FOUNDATION_PART_END]; ///< Foundation sprites (index into parent_sprites_to_draw). |
be6bfd75e554
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
8951
diff
changeset
|
136 |
FoundationPart foundation_part; ///< Currently active foundation for ground sprite drawing. |
be6bfd75e554
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
8951
diff
changeset
|
137 |
int *last_foundation_child[FOUNDATION_PART_END]; ///< Tail of ChildSprite list of the foundations. (index into child_screen_sprites_to_draw) |
be6bfd75e554
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
8951
diff
changeset
|
138 |
Point foundation_offset[FOUNDATION_PART_END]; ///< Pixeloffset for ground sprites on the foundations. |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
139 |
}; |
0 | 140 |
|
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
141 |
static ViewportDrawer _vd; |
0 | 142 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
143 |
TileHighlightData _thd; |
0 | 144 |
static TileInfo *_cur_ti; |
8979
d7ba4e5eac9c
(svn r12771) -Codechange: remove more from variables.h.
rubidium
parents:
8969
diff
changeset
|
145 |
bool _draw_bounding_boxes = false; |
0 | 146 |
|
2116 | 147 |
static Point MapXYZToViewport(const ViewPort *vp, uint x, uint y, uint z) |
0 | 148 |
{ |
149 |
Point p = RemapCoords(x, y, z); |
|
2116 | 150 |
p.x -= vp->virtual_width / 2; |
151 |
p.y -= vp->virtual_height / 2; |
|
0 | 152 |
return p; |
153 |
} |
|
154 |
||
5122
3aa375cb5e8e
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
155 |
void DeleteWindowViewport(Window *w) |
3aa375cb5e8e
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
156 |
{ |
9184 | 157 |
free(w->viewport); |
5122
3aa375cb5e8e
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
158 |
w->viewport = NULL; |
3aa375cb5e8e
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
159 |
} |
3aa375cb5e8e
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5120
diff
changeset
|
160 |
|
8992
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
161 |
/** |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
162 |
* Initialize viewport of the window for use. |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
163 |
* @param w Window to use/display the viewport in |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
164 |
* @param x Offset of left edge of viewport with respect to left edge window \a w |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
165 |
* @param y Offset of top edge of viewport with respect to top edge window \a w |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
166 |
* @param width Width of the viewport |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
167 |
* @param height Height of the viewport |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
168 |
* @param follow_flags Flags controlling the viewport. |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
169 |
* - If bit 31 is set, the lower 16 bits are the vehicle that the viewport should follow. |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
170 |
* - If bit 31 is clear, it is a tile position. |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
171 |
* @param zoom Zoomlevel to display |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
172 |
*/ |
8994
fb5e761cf141
(svn r12789) -Codechange: rename AssignWindowViewport to InitializeWindowViewport because the viewport is now part of the window struct. Patch by Alberth.
rubidium
parents:
8992
diff
changeset
|
173 |
void InitializeWindowViewport(Window *w, int x, int y, |
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
174 |
int width, int height, uint32 follow_flags, ZoomLevel zoom) |
0 | 175 |
{ |
8957
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
176 |
assert(w->viewport == NULL); |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
177 |
|
9184 | 178 |
ViewportData *vp = CallocT<ViewportData>(1); |
0 | 179 |
|
180 |
vp->left = x + w->left; |
|
181 |
vp->top = y + w->top; |
|
182 |
vp->width = width; |
|
183 |
vp->height = height; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
184 |
|
0 | 185 |
vp->zoom = zoom; |
186 |
||
6654
31d17823506f
(svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents:
6653
diff
changeset
|
187 |
vp->virtual_width = ScaleByZoom(width, zoom); |
31d17823506f
(svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents:
6653
diff
changeset
|
188 |
vp->virtual_height = ScaleByZoom(height, zoom); |
0 | 189 |
|
8957
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
190 |
Point pt; |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
191 |
|
0 | 192 |
if (follow_flags & 0x80000000) { |
2116 | 193 |
const Vehicle *veh; |
194 |
||
9184 | 195 |
vp->follow_vehicle = (VehicleID)(follow_flags & 0xFFFF); |
196 |
veh = GetVehicle(vp->follow_vehicle); |
|
0 | 197 |
pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos); |
198 |
} else { |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
199 |
uint x = TileX(follow_flags) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
200 |
uint y = TileY(follow_flags) * TILE_SIZE; |
2116 | 201 |
|
9184 | 202 |
vp->follow_vehicle = INVALID_VEHICLE; |
2116 | 203 |
pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y)); |
0 | 204 |
} |
205 |
||
9184 | 206 |
vp->scrollpos_x = pt.x; |
207 |
vp->scrollpos_y = pt.y; |
|
208 |
vp->dest_scrollpos_x = pt.x; |
|
209 |
vp->dest_scrollpos_y = pt.y; |
|
6730
9311a208f8f7
(svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents:
6669
diff
changeset
|
210 |
|
0 | 211 |
w->viewport = vp; |
212 |
vp->virtual_left = 0;//pt.x; |
|
213 |
vp->virtual_top = 0;//pt.y; |
|
214 |
} |
|
215 |
||
216 |
static Point _vp_move_offs; |
|
217 |
||
5137
54425dc8b5b3
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5124
diff
changeset
|
218 |
static void DoSetViewportPosition(Window* const *wz, int left, int top, int width, int height) |
0 | 219 |
{ |
5124
2ca62776430e
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
220 |
|
2ca62776430e
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
221 |
for (; wz != _last_z_window; wz++) { |
2ca62776430e
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
222 |
const Window *w = *wz; |
2ca62776430e
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
223 |
|
0 | 224 |
if (left + width > w->left && |
2116 | 225 |
w->left + w->width > left && |
0 | 226 |
top + height > w->top && |
2116 | 227 |
w->top + w->height > top) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
228 |
|
0 | 229 |
if (left < w->left) { |
5124
2ca62776430e
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
230 |
DoSetViewportPosition(wz, left, top, w->left - left, height); |
2ca62776430e
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
231 |
DoSetViewportPosition(wz, left + (w->left - left), top, width - (w->left - left), height); |
0 | 232 |
return; |
233 |
} |
|
234 |
||
235 |
if (left + width > w->left + w->width) { |
|
5124
2ca62776430e
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
236 |
DoSetViewportPosition(wz, left, top, (w->left + w->width - left), height); |
2ca62776430e
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
237 |
DoSetViewportPosition(wz, left + (w->left + w->width - left), top, width - (w->left + w->width - left) , height); |
0 | 238 |
return; |
239 |
} |
|
240 |
||
241 |
if (top < w->top) { |
|
5124
2ca62776430e
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
242 |
DoSetViewportPosition(wz, left, top, width, (w->top - top)); |
2ca62776430e
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
243 |
DoSetViewportPosition(wz, left, top + (w->top - top), width, height - (w->top - top)); |
0 | 244 |
return; |
245 |
} |
|
246 |
||
247 |
if (top + height > w->top + w->height) { |
|
5124
2ca62776430e
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
248 |
DoSetViewportPosition(wz, left, top, width, (w->top + w->height - top)); |
2ca62776430e
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
249 |
DoSetViewportPosition(wz, left, top + (w->top + w->height - top), width , height - (w->top + w->height - top)); |
0 | 250 |
return; |
251 |
} |
|
252 |
||
253 |
return; |
|
254 |
} |
|
255 |
} |
|
256 |
||
257 |
{ |
|
258 |
int xo = _vp_move_offs.x; |
|
259 |
int yo = _vp_move_offs.y; |
|
260 |
||
261 |
if (abs(xo) >= width || abs(yo) >= height) { |
|
262 |
/* fully_outside */ |
|
2116 | 263 |
RedrawScreenRect(left, top, left + width, top + height); |
0 | 264 |
return; |
265 |
} |
|
266 |
||
267 |
GfxScroll(left, top, width, height, xo, yo); |
|
268 |
||
269 |
if (xo > 0) { |
|
270 |
RedrawScreenRect(left, top, xo + left, top + height); |
|
271 |
left += xo; |
|
272 |
width -= xo; |
|
273 |
} else if (xo < 0) { |
|
274 |
RedrawScreenRect(left+width+xo, top, left+width, top + height); |
|
275 |
width += xo; |
|
276 |
} |
|
277 |
||
278 |
if (yo > 0) { |
|
279 |
RedrawScreenRect(left, top, width+left, top + yo); |
|
280 |
} else if (yo < 0) { |
|
281 |
RedrawScreenRect(left, top + height + yo, width+left, top + height); |
|
282 |
} |
|
283 |
} |
|
284 |
} |
|
285 |
||
4171 | 286 |
static void SetViewportPosition(Window *w, int x, int y) |
0 | 287 |
{ |
288 |
ViewPort *vp = w->viewport; |
|
289 |
int old_left = vp->virtual_left; |
|
290 |
int old_top = vp->virtual_top; |
|
291 |
int i; |
|
292 |
int left, top, width, height; |
|
293 |
||
294 |
vp->virtual_left = x; |
|
295 |
vp->virtual_top = y; |
|
296 |
||
7905
d78686954e4b
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7889
diff
changeset
|
297 |
/* viewport is bound to its left top corner, so it must be rounded down (UnScaleByZoomLower) |
d78686954e4b
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7889
diff
changeset
|
298 |
* else glitch described in FS#1412 will happen (offset by 1 pixel with zoom level > NORMAL) |
d78686954e4b
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7889
diff
changeset
|
299 |
*/ |
d78686954e4b
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7889
diff
changeset
|
300 |
old_left = UnScaleByZoomLower(old_left, vp->zoom); |
d78686954e4b
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7889
diff
changeset
|
301 |
old_top = UnScaleByZoomLower(old_top, vp->zoom); |
d78686954e4b
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7889
diff
changeset
|
302 |
x = UnScaleByZoomLower(x, vp->zoom); |
d78686954e4b
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7889
diff
changeset
|
303 |
y = UnScaleByZoomLower(y, vp->zoom); |
0 | 304 |
|
305 |
old_left -= x; |
|
306 |
old_top -= y; |
|
307 |
||
2116 | 308 |
if (old_top == 0 && old_left == 0) return; |
0 | 309 |
|
310 |
_vp_move_offs.x = old_left; |
|
311 |
_vp_move_offs.y = old_top; |
|
312 |
||
313 |
left = vp->left; |
|
314 |
top = vp->top; |
|
315 |
width = vp->width; |
|
316 |
height = vp->height; |
|
317 |
||
318 |
if (left < 0) { |
|
319 |
width += left; |
|
320 |
left = 0; |
|
321 |
} |
|
322 |
||
2116 | 323 |
i = left + width - _screen.width; |
324 |
if (i >= 0) width -= i; |
|
0 | 325 |
|
326 |
if (width > 0) { |
|
327 |
if (top < 0) { |
|
328 |
height += top; |
|
329 |
top = 0; |
|
330 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
331 |
|
2116 | 332 |
i = top + height - _screen.height; |
333 |
if (i >= 0) height -= i; |
|
0 | 334 |
|
5124
2ca62776430e
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
335 |
if (height > 0) DoSetViewportPosition(FindWindowZPosition(w) + 1, left, top, width, height); |
0 | 336 |
} |
337 |
} |
|
338 |
||
8992
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
339 |
/** |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
340 |
* Is a xy position inside the viewport of the window? |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
341 |
* @param w Window to examine its viewport |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
342 |
* @param x X coordinate of the xy position |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
343 |
* @param y Y coordinate of the xy position |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
344 |
* @return Pointer to the viewport if the xy position is in the viewport of the window, |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
345 |
* otherwise \c NULL is returned. |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
346 |
*/ |
2116 | 347 |
ViewPort *IsPtInWindowViewport(const Window *w, int x, int y) |
0 | 348 |
{ |
349 |
ViewPort *vp = w->viewport; |
|
2116 | 350 |
|
0 | 351 |
if (vp != NULL && |
8562
7419166c16bd
(svn r12140) -Codechange: A bit of code style fixes(Geektoo).
belugas
parents:
8473
diff
changeset
|
352 |
IsInsideMM(x, vp->left, vp->left + vp->width) && |
7954
57b51c69c072
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
7951
diff
changeset
|
353 |
IsInsideMM(y, vp->top, vp->top + vp->height)) |
0 | 354 |
return vp; |
355 |
||
356 |
return NULL; |
|
357 |
} |
|
358 |
||
2116 | 359 |
static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y) |
1095 | 360 |
{ |
0 | 361 |
Point pt; |
362 |
int a,b; |
|
5014
27054c09dc66
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
363 |
uint z; |
0 | 364 |
|
365 |
if ( (uint)(x -= vp->left) >= (uint)vp->width || |
|
366 |
(uint)(y -= vp->top) >= (uint)vp->height) { |
|
367 |
Point pt = {-1, -1}; |
|
368 |
return pt; |
|
369 |
} |
|
370 |
||
6626
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
371 |
x = (ScaleByZoom(x, vp->zoom) + vp->virtual_left) >> 2; |
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
372 |
y = (ScaleByZoom(y, vp->zoom) + vp->virtual_top) >> 1; |
0 | 373 |
|
374 |
a = y-x; |
|
375 |
b = y+x; |
|
376 |
||
5014
27054c09dc66
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
377 |
/* we need to move variables in to the valid range, as the |
27054c09dc66
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
378 |
* GetTileZoomCenterWindow() function can call here with invalid x and/or y, |
27054c09dc66
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
379 |
* when the user tries to zoom out along the sides of the map */ |
7922
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7918
diff
changeset
|
380 |
a = Clamp(a, 0, (int)(MapMaxX() * TILE_SIZE) - 1); |
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7918
diff
changeset
|
381 |
b = Clamp(b, 0, (int)(MapMaxY() * TILE_SIZE) - 1); |
5014
27054c09dc66
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
382 |
|
7764
e594296e90f6
(svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents:
7726
diff
changeset
|
383 |
/* (a, b) is the X/Y-world coordinate that belongs to (x,y) if the landscape would be completely flat on height 0. |
e594296e90f6
(svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents:
7726
diff
changeset
|
384 |
* Now find the Z-world coordinate by fix point iteration. |
e594296e90f6
(svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents:
7726
diff
changeset
|
385 |
* This is a bit tricky because the tile height is non-continuous at foundations. |
e594296e90f6
(svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents:
7726
diff
changeset
|
386 |
* The clicked point should be approached from the back, otherwise there are regions that are not clickable. |
e594296e90f6
(svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents:
7726
diff
changeset
|
387 |
* (FOUNDATION_HALFTILE_LOWER on SLOPE_STEEP_S hides north halftile completely) |
e594296e90f6
(svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents:
7726
diff
changeset
|
388 |
* So give it a z-malus of 4 in the first iterations. |
e594296e90f6
(svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents:
7726
diff
changeset
|
389 |
*/ |
e594296e90f6
(svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents:
7726
diff
changeset
|
390 |
z = 0; |
e594296e90f6
(svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents:
7726
diff
changeset
|
391 |
for (int i = 0; i < 5; i++) z = GetSlopeZ(a + max(z, 4u) - 4, b + max(z, 4u) - 4) / 2; |
e594296e90f6
(svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents:
7726
diff
changeset
|
392 |
for (uint malus = 3; malus > 0; malus--) z = GetSlopeZ(a + max(z, malus) - malus, b + max(z, malus) - malus) / 2; |
e594296e90f6
(svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents:
7726
diff
changeset
|
393 |
for (int i = 0; i < 5; i++) z = GetSlopeZ(a + z, b + z) / 2; |
5014
27054c09dc66
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
394 |
|
27054c09dc66
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
395 |
pt.x = a + z; |
27054c09dc66
(svn r7047) -Fix [FS#317]: Zooming out near map-borders would previously fail because the new centre
Darkvater
parents:
4912
diff
changeset
|
396 |
pt.y = b + z; |
0 | 397 |
|
398 |
return pt; |
|
399 |
} |
|
400 |
||
981
f74abee65b7b
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
401 |
/* When used for zooming, check area below current coordinates (x,y) |
f74abee65b7b
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
402 |
* and return the tile of the zoomed out/in position (zoom_x, zoom_y) |
f74abee65b7b
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
403 |
* when you just want the tile, make x = zoom_x and y = zoom_y */ |
f74abee65b7b
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
404 |
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
|
405 |
{ |
0 | 406 |
Window *w; |
407 |
ViewPort *vp; |
|
408 |
Point pt; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
409 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
410 |
if ( (w = FindWindowFromPt(x, y)) != NULL && |
0 | 411 |
(vp = IsPtInWindowViewport(w, x, y)) != NULL) |
981
f74abee65b7b
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
412 |
return TranslateXYToTileCoord(vp, zoom_x, zoom_y); |
0 | 413 |
|
414 |
pt.y = pt.x = -1; |
|
415 |
return pt; |
|
416 |
} |
|
417 |
||
6247 | 418 |
Point GetTileBelowCursor() |
0 | 419 |
{ |
981
f74abee65b7b
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
420 |
return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, _cursor.pos.x, _cursor.pos.y); |
0 | 421 |
} |
422 |
||
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
|
423 |
|
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
|
424 |
Point GetTileZoomCenterWindow(bool in, Window * w) |
0 | 425 |
{ |
426 |
int x, y; |
|
9184 | 427 |
ViewPort *vp = w->viewport; |
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
|
428 |
|
2026 | 429 |
if (in) { |
2116 | 430 |
x = ((_cursor.pos.x - vp->left) >> 1) + (vp->width >> 2); |
431 |
y = ((_cursor.pos.y - vp->top) >> 1) + (vp->height >> 2); |
|
432 |
} 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
|
433 |
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
|
434 |
y = vp->height - (_cursor.pos.y - vp->top); |
0 | 435 |
} |
981
f74abee65b7b
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
436 |
/* Get the tile below the cursor and center on the zoomed-out center */ |
f74abee65b7b
(svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents:
979
diff
changeset
|
437 |
return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, x + vp->left, y + vp->top); |
0 | 438 |
} |
439 |
||
5045
846098142ffe
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
440 |
/** Update the status of the zoom-buttons according to the zoom-level |
846098142ffe
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
441 |
* of the viewport. This will update their status and invalidate accordingly |
6443
63fbe9f76801
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6427
diff
changeset
|
442 |
* @param w Window pointer to the window that has the zoom buttons |
5045
846098142ffe
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
443 |
* @param vp pointer to the viewport whose zoom-level the buttons represent |
846098142ffe
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
444 |
* @param widget_zoom_in widget index for window with zoom-in button |
846098142ffe
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
445 |
* @param widget_zoom_out widget index for window with zoom-out button */ |
846098142ffe
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
446 |
void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out) |
846098142ffe
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
447 |
{ |
7997
df87ccd00a96
(svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents:
7970
diff
changeset
|
448 |
w->SetWidgetDisabledState(widget_zoom_in, vp->zoom == ZOOM_LVL_MIN); |
8028
e578ea22f371
(svn r11588) -Codechange: use the new member introduced in r11551
glx
parents:
7997
diff
changeset
|
449 |
w->InvalidateWidget(widget_zoom_in); |
5045
846098142ffe
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
450 |
|
7997
df87ccd00a96
(svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents:
7970
diff
changeset
|
451 |
w->SetWidgetDisabledState(widget_zoom_out, vp->zoom == ZOOM_LVL_MAX); |
8028
e578ea22f371
(svn r11588) -Codechange: use the new member introduced in r11551
glx
parents:
7997
diff
changeset
|
452 |
w->InvalidateWidget(widget_zoom_out); |
5045
846098142ffe
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
453 |
} |
846098142ffe
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
5027
diff
changeset
|
454 |
|
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
455 |
/** |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
456 |
* Draws a ground sprite at a specific world-coordinate. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
457 |
* |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
458 |
* @param image the image to draw. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
459 |
* @param pal the provided palette. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
460 |
* @param x position x of the sprite. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
461 |
* @param y position y of the sprite. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
462 |
* @param z position z of the sprite. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
463 |
* @param sub Only draw a part of the sprite. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
464 |
* |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
465 |
*/ |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
466 |
void DrawGroundSpriteAt(SpriteID image, SpriteID pal, int32 x, int32 y, byte z, const SubSprite *sub) |
0 | 467 |
{ |
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
468 |
assert((image & SPRITE_MASK) < MAX_SPRITES); |
0 | 469 |
|
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
470 |
TileSpriteToDraw *ts = _vd.tile_sprites_to_draw.Append(); |
8949
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
471 |
ts->image = image; |
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
472 |
ts->pal = pal; |
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
473 |
ts->sub = sub; |
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
474 |
ts->x = x; |
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
475 |
ts->y = y; |
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
476 |
ts->z = z; |
0 | 477 |
} |
478 |
||
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
479 |
/** |
7726
a9c8beebf2c1
(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:
7681
diff
changeset
|
480 |
* Adds a child sprite to the active foundation. |
a9c8beebf2c1
(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:
7681
diff
changeset
|
481 |
* |
a9c8beebf2c1
(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:
7681
diff
changeset
|
482 |
* The pixel offset of the sprite relative to the ParentSprite is the sum of the offset passed to OffsetGroundSprite() and extra_offs_?. |
a9c8beebf2c1
(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:
7681
diff
changeset
|
483 |
* |
a9c8beebf2c1
(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:
7681
diff
changeset
|
484 |
* @param image the image to draw. |
a9c8beebf2c1
(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:
7681
diff
changeset
|
485 |
* @param pal the provided palette. |
a9c8beebf2c1
(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:
7681
diff
changeset
|
486 |
* @param sub Only draw a part of the sprite. |
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
487 |
* @param foundation_part Foundation part. |
7726
a9c8beebf2c1
(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:
7681
diff
changeset
|
488 |
* @param extra_offs_x Pixel X offset for the sprite position. |
a9c8beebf2c1
(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:
7681
diff
changeset
|
489 |
* @param extra_offs_y Pixel Y offset for the sprite position. |
a9c8beebf2c1
(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:
7681
diff
changeset
|
490 |
*/ |
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
491 |
static void AddChildSpriteToFoundation(SpriteID image, SpriteID pal, const SubSprite *sub, FoundationPart foundation_part, int extra_offs_x, int extra_offs_y) |
7726
a9c8beebf2c1
(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:
7681
diff
changeset
|
492 |
{ |
7954
57b51c69c072
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
7951
diff
changeset
|
493 |
assert(IsInsideMM(foundation_part, 0, FOUNDATION_PART_END)); |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
494 |
assert(_vd.foundation[foundation_part] != -1); |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
495 |
Point offs = _vd.foundation_offset[foundation_part]; |
7726
a9c8beebf2c1
(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:
7681
diff
changeset
|
496 |
|
a9c8beebf2c1
(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:
7681
diff
changeset
|
497 |
/* Change the active ChildSprite list to the one of the foundation */ |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
498 |
int *old_child = _vd.last_child; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
499 |
_vd.last_child = _vd.last_foundation_child[foundation_part]; |
7726
a9c8beebf2c1
(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:
7681
diff
changeset
|
500 |
|
a9c8beebf2c1
(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:
7681
diff
changeset
|
501 |
AddChildSpriteScreen(image, pal, offs.x + extra_offs_x, offs.y + extra_offs_y, false, sub); |
a9c8beebf2c1
(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:
7681
diff
changeset
|
502 |
|
a9c8beebf2c1
(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:
7681
diff
changeset
|
503 |
/* Switch back to last ChildSprite list */ |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
504 |
_vd.last_child = old_child; |
7726
a9c8beebf2c1
(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:
7681
diff
changeset
|
505 |
} |
a9c8beebf2c1
(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:
7681
diff
changeset
|
506 |
|
a9c8beebf2c1
(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:
7681
diff
changeset
|
507 |
/** |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
508 |
* Draws a ground sprite for the current tile. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
509 |
* If the current tile is drawn on top of a foundation the sprite is added as child sprite to the "foundation"-ParentSprite. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
510 |
* |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
511 |
* @param image the image to draw. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
512 |
* @param pal the provided palette. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
513 |
* @param sub Only draw a part of the sprite. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
514 |
*/ |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
515 |
void DrawGroundSprite(SpriteID image, SpriteID pal, const SubSprite *sub) |
0 | 516 |
{ |
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
517 |
/* Switch to first foundation part, if no foundation was drawn */ |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
518 |
if (_vd.foundation_part == FOUNDATION_PART_NONE) _vd.foundation_part = FOUNDATION_PART_NORMAL; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
519 |
|
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
520 |
if (_vd.foundation[_vd.foundation_part] != -1) { |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
521 |
AddChildSpriteToFoundation(image, pal, sub, _vd.foundation_part, 0, 0); |
0 | 522 |
} else { |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
523 |
DrawGroundSpriteAt(image, pal, _cur_ti->x, _cur_ti->y, _cur_ti->z, sub); |
0 | 524 |
} |
525 |
} |
|
526 |
||
527 |
||
7726
a9c8beebf2c1
(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:
7681
diff
changeset
|
528 |
/** |
a9c8beebf2c1
(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:
7681
diff
changeset
|
529 |
* Called when a foundation has been drawn for the current tile. |
a9c8beebf2c1
(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:
7681
diff
changeset
|
530 |
* Successive ground sprites for the current tile will be drawn as child sprites of the "foundation"-ParentSprite, not as TileSprites. |
a9c8beebf2c1
(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:
7681
diff
changeset
|
531 |
* |
a9c8beebf2c1
(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:
7681
diff
changeset
|
532 |
* @param x sprite x-offset (screen coordinates) of ground sprites relative to the "foundation"-ParentSprite. |
a9c8beebf2c1
(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:
7681
diff
changeset
|
533 |
* @param y sprite y-offset (screen coordinates) of ground sprites relative to the "foundation"-ParentSprite. |
a9c8beebf2c1
(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:
7681
diff
changeset
|
534 |
*/ |
0 | 535 |
void OffsetGroundSprite(int x, int y) |
536 |
{ |
|
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
537 |
/* Switch to next foundation part */ |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
538 |
switch (_vd.foundation_part) { |
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
539 |
case FOUNDATION_PART_NONE: |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
540 |
_vd.foundation_part = FOUNDATION_PART_NORMAL; |
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
541 |
break; |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
542 |
case FOUNDATION_PART_NORMAL: |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
543 |
_vd.foundation_part = FOUNDATION_PART_HALFTILE; |
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
544 |
break; |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
545 |
default: NOT_REACHED(); |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
546 |
} |
7726
a9c8beebf2c1
(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:
7681
diff
changeset
|
547 |
|
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
548 |
/* _vd.last_child == NULL if foundation sprite was clipped by the viewport bounds */ |
9553
93848ae90336
(svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13
parents:
9534
diff
changeset
|
549 |
if (_vd.last_child != NULL) _vd.foundation[_vd.foundation_part] = _vd.parent_sprites_to_draw.Length() - 1; |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
550 |
|
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
551 |
_vd.foundation_offset[_vd.foundation_part].x = x; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
552 |
_vd.foundation_offset[_vd.foundation_part].y = y; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
553 |
_vd.last_foundation_child[_vd.foundation_part] = _vd.last_child; |
0 | 554 |
} |
555 |
||
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
556 |
/** |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
557 |
* Adds a child sprite to a parent sprite. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
558 |
* In contrast to "AddChildSpriteScreen()" the sprite position is in world coordinates |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
559 |
* |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
560 |
* @param image the image to draw. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
561 |
* @param pal the provided palette. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
562 |
* @param x position x of the sprite. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
563 |
* @param y position y of the sprite. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
564 |
* @param z position z of the sprite. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
565 |
* @param sub Only draw a part of the sprite. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
566 |
*/ |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
567 |
static void AddCombinedSprite(SpriteID image, SpriteID pal, int x, int y, byte z, const SubSprite *sub) |
0 | 568 |
{ |
569 |
Point pt = RemapCoords(x, y, z); |
|
2319
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2187
diff
changeset
|
570 |
const Sprite* spr = GetSprite(image & SPRITE_MASK); |
0 | 571 |
|
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
572 |
if (pt.x + spr->x_offs >= _vd.dpi.left + _vd.dpi.width || |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
573 |
pt.x + spr->x_offs + spr->width <= _vd.dpi.left || |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
574 |
pt.y + spr->y_offs >= _vd.dpi.top + _vd.dpi.height || |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
575 |
pt.y + spr->y_offs + spr->height <= _vd.dpi.top) |
0 | 576 |
return; |
577 |
||
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
578 |
const ParentSpriteToDraw *pstd = _vd.parent_sprites_to_draw.End() - 1; |
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
579 |
AddChildSpriteScreen(image, pal, pt.x - pstd->left, pt.y - pstd->top, false, sub); |
0 | 580 |
} |
581 |
||
7580
fc9a8300f34e
(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:
7579
diff
changeset
|
582 |
/** Draw a (transparent) sprite at given coordinates with a given bounding box. |
fc9a8300f34e
(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:
7579
diff
changeset
|
583 |
* 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. |
7617
804e665b79fa
(svn r11147) -Fix [FS#1247] (r11105): reallow bounding boxes with x/y/z-extent 0. Some NewGRFs need them. Patch by frosch.
rubidium
parents:
7601
diff
changeset
|
584 |
* Bounding boxes with bb_offset_x == w or bb_offset_y == h or bb_offset_z == dz are allowed and produce thin slices. |
7580
fc9a8300f34e
(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:
7579
diff
changeset
|
585 |
* |
fc9a8300f34e
(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:
7579
diff
changeset
|
586 |
* @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 |
fc9a8300f34e
(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:
7579
diff
changeset
|
587 |
* defined by the sprite offset in the grf file. |
fc9a8300f34e
(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:
7579
diff
changeset
|
588 |
* However if modifying the sprite offsets is not suitable (e.g. when using existing graphics), the bounding box can be tuned by bb_offset. |
fc9a8300f34e
(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:
7579
diff
changeset
|
589 |
* |
7617
804e665b79fa
(svn r11147) -Fix [FS#1247] (r11105): reallow bounding boxes with x/y/z-extent 0. Some NewGRFs need them. Patch by frosch.
rubidium
parents:
7601
diff
changeset
|
590 |
* @pre w >= bb_offset_x, h >= bb_offset_y, dz >= bb_offset_z. Else w, h or dz are ignored. |
7580
fc9a8300f34e
(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:
7579
diff
changeset
|
591 |
* |
7333
e48228e44be8
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents:
7321
diff
changeset
|
592 |
* @param image the image to combine and draw, |
e48228e44be8
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents:
7321
diff
changeset
|
593 |
* @param pal the provided palette, |
7580
fc9a8300f34e
(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:
7579
diff
changeset
|
594 |
* @param x position X (world) of the sprite, |
fc9a8300f34e
(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:
7579
diff
changeset
|
595 |
* @param y position Y (world) of the sprite, |
fc9a8300f34e
(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:
7579
diff
changeset
|
596 |
* @param w bounding box extent towards positive X (world), |
fc9a8300f34e
(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:
7579
diff
changeset
|
597 |
* @param h bounding box extent towards positive Y (world), |
fc9a8300f34e
(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:
7579
diff
changeset
|
598 |
* @param dz bounding box extent towards positive Z (world), |
fc9a8300f34e
(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:
7579
diff
changeset
|
599 |
* @param z position Z (world) of the sprite, |
fc9a8300f34e
(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:
7579
diff
changeset
|
600 |
* @param transparent if true, switch the palette between the provided palette and the transparent palette, |
fc9a8300f34e
(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:
7579
diff
changeset
|
601 |
* @param bb_offset_x bounding box extent towards negative X (world), |
fc9a8300f34e
(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:
7579
diff
changeset
|
602 |
* @param bb_offset_y bounding box extent towards negative Y (world), |
fc9a8300f34e
(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:
7579
diff
changeset
|
603 |
* @param bb_offset_z bounding box extent towards negative Z (world) |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
604 |
* @param sub Only draw a part of the sprite. |
7333
e48228e44be8
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents:
7321
diff
changeset
|
605 |
*/ |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
606 |
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 | 607 |
{ |
7643
af32b07bc027
(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:
7617
diff
changeset
|
608 |
int32 left, right, top, bottom; |
0 | 609 |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
610 |
assert((image & SPRITE_MASK) < MAX_SPRITES); |
0 | 611 |
|
7333
e48228e44be8
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents:
7321
diff
changeset
|
612 |
/* make the sprites transparent with the right palette */ |
e48228e44be8
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents:
7321
diff
changeset
|
613 |
if (transparent) { |
7931
b0a46cd92225
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7929
diff
changeset
|
614 |
SetBit(image, PALETTE_MODIFIER_TRANSPARENT); |
7333
e48228e44be8
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents:
7321
diff
changeset
|
615 |
pal = PALETTE_TO_TRANSPARENT; |
e48228e44be8
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents:
7321
diff
changeset
|
616 |
} |
e48228e44be8
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents:
7321
diff
changeset
|
617 |
|
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
618 |
if (_vd.combine_sprites == 2) { |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
619 |
AddCombinedSprite(image, pal, x, y, z, sub); |
0 | 620 |
return; |
621 |
} |
|
622 |
||
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
623 |
_vd.last_child = NULL; |
0 | 624 |
|
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
625 |
Point pt = RemapCoords(x, y, z); |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
626 |
int tmp_left, tmp_top, tmp_x = pt.x, tmp_y = pt.y; |
7643
af32b07bc027
(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:
7617
diff
changeset
|
627 |
|
af32b07bc027
(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:
7617
diff
changeset
|
628 |
/* Compute screen extents of sprite */ |
7601
988040ee27f4
(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:
7580
diff
changeset
|
629 |
if (image == SPR_EMPTY_BOUNDING_BOX) { |
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
630 |
left = tmp_left = RemapCoords(x + w , y + bb_offset_y, z + bb_offset_z).x; |
7643
af32b07bc027
(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:
7617
diff
changeset
|
631 |
right = RemapCoords(x + bb_offset_x, y + h , z + bb_offset_z).x + 1; |
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
632 |
top = tmp_top = RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz ).y; |
7643
af32b07bc027
(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:
7617
diff
changeset
|
633 |
bottom = RemapCoords(x + w , y + h , z + bb_offset_z).y + 1; |
7601
988040ee27f4
(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:
7580
diff
changeset
|
634 |
} else { |
988040ee27f4
(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:
7580
diff
changeset
|
635 |
const Sprite *spr = GetSprite(image & SPRITE_MASK); |
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
636 |
left = tmp_left = (pt.x += spr->x_offs); |
7643
af32b07bc027
(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:
7617
diff
changeset
|
637 |
right = (pt.x + spr->width ); |
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
638 |
top = tmp_top = (pt.y += spr->y_offs); |
7643
af32b07bc027
(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:
7617
diff
changeset
|
639 |
bottom = (pt.y + spr->height); |
7601
988040ee27f4
(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:
7580
diff
changeset
|
640 |
} |
8562
7419166c16bd
(svn r12140) -Codechange: A bit of code style fixes(Geektoo).
belugas
parents:
8473
diff
changeset
|
641 |
|
7643
af32b07bc027
(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:
7617
diff
changeset
|
642 |
if (_draw_bounding_boxes && (image != SPR_EMPTY_BOUNDING_BOX)) { |
af32b07bc027
(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:
7617
diff
changeset
|
643 |
/* Compute maximal extents of sprite and it's bounding box */ |
af32b07bc027
(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:
7617
diff
changeset
|
644 |
left = min(left , RemapCoords(x + w , y + bb_offset_y, z + bb_offset_z).x); |
af32b07bc027
(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:
7617
diff
changeset
|
645 |
right = max(right , RemapCoords(x + bb_offset_x, y + h , z + bb_offset_z).x + 1); |
af32b07bc027
(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:
7617
diff
changeset
|
646 |
top = min(top , RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz ).y); |
af32b07bc027
(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:
7617
diff
changeset
|
647 |
bottom = max(bottom, RemapCoords(x + w , y + h , z + bb_offset_z).y + 1); |
af32b07bc027
(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:
7617
diff
changeset
|
648 |
} |
8562
7419166c16bd
(svn r12140) -Codechange: A bit of code style fixes(Geektoo).
belugas
parents:
8473
diff
changeset
|
649 |
|
7643
af32b07bc027
(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:
7617
diff
changeset
|
650 |
/* Do not add the sprite to the viewport, if it is outside */ |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
651 |
if (left >= _vd.dpi.left + _vd.dpi.width || |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
652 |
right <= _vd.dpi.left || |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
653 |
top >= _vd.dpi.top + _vd.dpi.height || |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
654 |
bottom <= _vd.dpi.top) { |
4189
fcc29d7b6722
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
655 |
return; |
fcc29d7b6722
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
656 |
} |
fcc29d7b6722
(svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents:
4188
diff
changeset
|
657 |
|
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
658 |
ParentSpriteToDraw *ps = _vd.parent_sprites_to_draw.Append(); |
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
659 |
ps->x = tmp_x; |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
660 |
ps->y = tmp_y; |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
661 |
|
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
662 |
ps->left = tmp_left; |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
663 |
ps->top = tmp_top; |
0 | 664 |
|
665 |
ps->image = image; |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5602
diff
changeset
|
666 |
ps->pal = pal; |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
667 |
ps->sub = sub; |
7580
fc9a8300f34e
(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:
7579
diff
changeset
|
668 |
ps->xmin = x + bb_offset_x; |
7617
804e665b79fa
(svn r11147) -Fix [FS#1247] (r11105): reallow bounding boxes with x/y/z-extent 0. Some NewGRFs need them. Patch by frosch.
rubidium
parents:
7601
diff
changeset
|
669 |
ps->xmax = x + max(bb_offset_x, w) - 1; |
7580
fc9a8300f34e
(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:
7579
diff
changeset
|
670 |
|
fc9a8300f34e
(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:
7579
diff
changeset
|
671 |
ps->ymin = y + bb_offset_y; |
7617
804e665b79fa
(svn r11147) -Fix [FS#1247] (r11105): reallow bounding boxes with x/y/z-extent 0. Some NewGRFs need them. Patch by frosch.
rubidium
parents:
7601
diff
changeset
|
672 |
ps->ymax = y + max(bb_offset_y, h) - 1; |
7580
fc9a8300f34e
(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:
7579
diff
changeset
|
673 |
|
fc9a8300f34e
(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:
7579
diff
changeset
|
674 |
ps->zmin = z + bb_offset_z; |
7617
804e665b79fa
(svn r11147) -Fix [FS#1247] (r11105): reallow bounding boxes with x/y/z-extent 0. Some NewGRFs need them. Patch by frosch.
rubidium
parents:
7601
diff
changeset
|
675 |
ps->zmax = z + max(bb_offset_z, dz) - 1; |
7580
fc9a8300f34e
(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:
7579
diff
changeset
|
676 |
|
fc9a8300f34e
(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:
7579
diff
changeset
|
677 |
ps->comparison_done = false; |
9534
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
678 |
ps->first_child = -1; |
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
679 |
|
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
680 |
_vd.last_child = &ps->first_child; |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
681 |
|
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
682 |
if (_vd.combine_sprites == 1) _vd.combine_sprites = 2; |
0 | 683 |
} |
684 |
||
6247 | 685 |
void StartSpriteCombine() |
0 | 686 |
{ |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
687 |
_vd.combine_sprites = 1; |
0 | 688 |
} |
689 |
||
6247 | 690 |
void EndSpriteCombine() |
0 | 691 |
{ |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
692 |
_vd.combine_sprites = 0; |
0 | 693 |
} |
694 |
||
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
695 |
/** |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
696 |
* Add a child sprite to a parent sprite. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
697 |
* |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
698 |
* @param image the image to draw. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
699 |
* @param pal the provided palette. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
700 |
* @param x sprite x-offset (screen coordinates) relative to parent sprite. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
701 |
* @param y sprite y-offset (screen coordinates) relative to parent sprite. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
702 |
* @param transparent if true, switch the palette between the provided palette and the transparent palette, |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
703 |
* @param sub Only draw a part of the sprite. |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
704 |
*/ |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
705 |
void AddChildSpriteScreen(SpriteID image, SpriteID pal, int x, int y, bool transparent, const SubSprite *sub) |
0 | 706 |
{ |
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
707 |
assert((image & SPRITE_MASK) < MAX_SPRITES); |
0 | 708 |
|
8952
be6bfd75e554
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
8951
diff
changeset
|
709 |
/* If the ParentSprite was clipped by the viewport bounds, do not draw the ChildSprites either */ |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
710 |
if (_vd.last_child == NULL) return; |
8952
be6bfd75e554
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
8951
diff
changeset
|
711 |
|
7659
c86da4c6292f
(svn r11190) -Fix: make snowy roofs of (newgrf) houses also transparent.
rubidium
parents:
7643
diff
changeset
|
712 |
/* make the sprites transparent with the right palette */ |
c86da4c6292f
(svn r11190) -Fix: make snowy roofs of (newgrf) houses also transparent.
rubidium
parents:
7643
diff
changeset
|
713 |
if (transparent) { |
7931
b0a46cd92225
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7929
diff
changeset
|
714 |
SetBit(image, PALETTE_MODIFIER_TRANSPARENT); |
7659
c86da4c6292f
(svn r11190) -Fix: make snowy roofs of (newgrf) houses also transparent.
rubidium
parents:
7643
diff
changeset
|
715 |
pal = PALETTE_TO_TRANSPARENT; |
c86da4c6292f
(svn r11190) -Fix: make snowy roofs of (newgrf) houses also transparent.
rubidium
parents:
7643
diff
changeset
|
716 |
} |
c86da4c6292f
(svn r11190) -Fix: make snowy roofs of (newgrf) houses also transparent.
rubidium
parents:
7643
diff
changeset
|
717 |
|
9553
93848ae90336
(svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13
parents:
9534
diff
changeset
|
718 |
*_vd.last_child = _vd.child_screen_sprites_to_draw.Length(); |
9534
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
719 |
|
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
720 |
ChildScreenSpriteToDraw *cs = _vd.child_screen_sprites_to_draw.Append(); |
0 | 721 |
cs->image = image; |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5602
diff
changeset
|
722 |
cs->pal = pal; |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
723 |
cs->sub = sub; |
0 | 724 |
cs->x = x; |
725 |
cs->y = y; |
|
9534
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
726 |
cs->next = -1; |
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
727 |
|
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
728 |
/* Append the sprite to the active ChildSprite list. |
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
729 |
* If the active ParentSprite is a foundation, update last_foundation_child as well. |
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
730 |
* Note: ChildSprites of foundations are NOT sequential in the vector, as selection sprites are added at last. */ |
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
731 |
if (_vd.last_foundation_child[0] == _vd.last_child) _vd.last_foundation_child[0] = &cs->next; |
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
732 |
if (_vd.last_foundation_child[1] == _vd.last_child) _vd.last_foundation_child[1] = &cs->next; |
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
733 |
_vd.last_child = &cs->next; |
0 | 734 |
} |
735 |
||
736 |
/* Returns a StringSpriteToDraw */ |
|
8946
a800978c3c8f
(svn r12734) -Codechange: use a vector instead of allocating memory in a big byte array for StringSpriteToDraw.
rubidium
parents:
8925
diff
changeset
|
737 |
void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2, uint16 color, uint16 width) |
0 | 738 |
{ |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
739 |
StringSpriteToDraw *ss = _vd.string_sprites_to_draw.Append(); |
8949
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
740 |
ss->string = string; |
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
741 |
ss->x = x; |
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
742 |
ss->y = y; |
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
743 |
ss->params[0] = params_1; |
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
744 |
ss->params[1] = params_2; |
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
745 |
ss->width = width; |
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
746 |
ss->color = color; |
0 | 747 |
} |
748 |
||
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3809
diff
changeset
|
749 |
|
7726
a9c8beebf2c1
(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:
7681
diff
changeset
|
750 |
/** |
a9c8beebf2c1
(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:
7681
diff
changeset
|
751 |
* Draws sprites between ground sprite and everything above. |
a9c8beebf2c1
(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:
7681
diff
changeset
|
752 |
* |
a9c8beebf2c1
(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:
7681
diff
changeset
|
753 |
* The sprite is either drawn as TileSprite or as ChildSprite of the active foundation. |
a9c8beebf2c1
(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:
7681
diff
changeset
|
754 |
* |
a9c8beebf2c1
(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:
7681
diff
changeset
|
755 |
* @param image the image to draw. |
a9c8beebf2c1
(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:
7681
diff
changeset
|
756 |
* @param pal the provided palette. |
a9c8beebf2c1
(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:
7681
diff
changeset
|
757 |
* @param ti TileInfo Tile that is being drawn |
a9c8beebf2c1
(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:
7681
diff
changeset
|
758 |
* @param z_offset Z offset relative to the groundsprite. Only used for the sprite position, not for sprite sorting. |
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
759 |
* @param foundation_part Foundation part the sprite belongs to. |
7726
a9c8beebf2c1
(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:
7681
diff
changeset
|
760 |
*/ |
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
761 |
static void DrawSelectionSprite(SpriteID image, SpriteID pal, const TileInfo *ti, int z_offset, FoundationPart foundation_part) |
0 | 762 |
{ |
7726
a9c8beebf2c1
(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:
7681
diff
changeset
|
763 |
/* FIXME: This is not totally valid for some autorail highlights, that extent over the edges of the tile. */ |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
764 |
if (_vd.foundation[foundation_part] == -1) { |
7726
a9c8beebf2c1
(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:
7681
diff
changeset
|
765 |
/* draw on real ground */ |
a9c8beebf2c1
(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:
7681
diff
changeset
|
766 |
DrawGroundSpriteAt(image, pal, ti->x, ti->y, ti->z + z_offset); |
a9c8beebf2c1
(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:
7681
diff
changeset
|
767 |
} else { |
a9c8beebf2c1
(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:
7681
diff
changeset
|
768 |
/* draw on top of foundation */ |
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
769 |
AddChildSpriteToFoundation(image, pal, NULL, foundation_part, 0, -z_offset); |
1083
8e64dc3ed29f
(svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents:
1070
diff
changeset
|
770 |
} |
0 | 771 |
} |
772 |
||
7679
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
773 |
/** |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
774 |
* Draws a selection rectangle on a tile. |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
775 |
* |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
776 |
* @param ti TileInfo Tile that is being drawn |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
777 |
* @param pal Palette to apply. |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
778 |
*/ |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
779 |
static void DrawTileSelectionRect(const TileInfo *ti, SpriteID pal) |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
780 |
{ |
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
781 |
SpriteID sel; |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
782 |
if (IsHalftileSlope(ti->tileh)) { |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
783 |
Corner halftile_corner = GetHalftileSlopeCorner(ti->tileh); |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
784 |
SpriteID sel2 = SPR_HALFTILE_SELECTION_FLAT + halftile_corner; |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
785 |
DrawSelectionSprite(sel2, pal, ti, 7 + TILE_HEIGHT, FOUNDATION_PART_HALFTILE); |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
786 |
|
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
787 |
Corner opposite_corner = OppositeCorner(halftile_corner); |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
788 |
if (IsSteepSlope(ti->tileh)) { |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
789 |
sel = SPR_HALFTILE_SELECTION_DOWN; |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
790 |
} else { |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
791 |
sel = ((ti->tileh & SlopeWithOneCornerRaised(opposite_corner)) != 0 ? SPR_HALFTILE_SELECTION_UP : SPR_HALFTILE_SELECTION_FLAT); |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
792 |
} |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
793 |
sel += opposite_corner; |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
794 |
} else { |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
795 |
sel = SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh]; |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
796 |
} |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
797 |
DrawSelectionSprite(sel, pal, ti, 7, FOUNDATION_PART_NORMAL); |
7679
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
798 |
} |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
799 |
|
0 | 800 |
static bool IsPartOfAutoLine(int px, int py) |
801 |
{ |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
802 |
px -= _thd.selstart.x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
803 |
py -= _thd.selstart.y; |
0 | 804 |
|
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
805 |
if ((_thd.drawstyle & ~HT_DIR_MASK) != HT_LINE) return false; |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
806 |
|
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
807 |
switch (_thd.drawstyle & HT_DIR_MASK) { |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
808 |
case HT_DIR_X: return py == 0; // x direction |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
809 |
case HT_DIR_Y: return px == 0; // y direction |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
810 |
case HT_DIR_HU: return px == -py || px == -py - 16; // horizontal upper |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
811 |
case HT_DIR_HL: return px == -py || px == -py + 16; // horizontal lower |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
812 |
case HT_DIR_VL: return px == py || px == py + 16; // vertival left |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
813 |
case HT_DIR_VR: return px == py || px == py - 16; // vertical right |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
814 |
default: |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
815 |
NOT_REACHED(); |
0 | 816 |
} |
817 |
} |
|
818 |
||
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
819 |
// [direction][side] |
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
820 |
static const HighLightStyle _autorail_type[6][2] = { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
821 |
{ HT_DIR_X, HT_DIR_X }, |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
822 |
{ HT_DIR_Y, HT_DIR_Y }, |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
823 |
{ HT_DIR_HU, HT_DIR_HL }, |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
824 |
{ HT_DIR_HL, HT_DIR_HU }, |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
825 |
{ HT_DIR_VL, HT_DIR_VR }, |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
826 |
{ HT_DIR_VR, HT_DIR_VL } |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
827 |
}; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
828 |
|
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
829 |
#include "table/autorail.h" |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
830 |
|
7078
521bc677ce92
(svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents:
7069
diff
changeset
|
831 |
/** |
7679
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
832 |
* Draws autorail highlights. |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
833 |
* |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
834 |
* @param *ti TileInfo Tile that is being drawn |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
835 |
* @param autorail_type Offset into _AutorailTilehSprite[][] |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
836 |
*/ |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
837 |
static void DrawAutorailSelection(const TileInfo *ti, uint autorail_type) |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
838 |
{ |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
839 |
SpriteID image; |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
840 |
SpriteID pal; |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
841 |
int offset; |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
842 |
|
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
843 |
FoundationPart foundation_part = FOUNDATION_PART_NORMAL; |
8413
c7f3384330a3
(svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents:
8270
diff
changeset
|
844 |
Slope autorail_tileh = RemoveHalftileSlope(ti->tileh); |
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
845 |
if (IsHalftileSlope(ti->tileh)) { |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
846 |
static const uint _lower_rail[4] = { 5U, 2U, 4U, 3U }; |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
847 |
Corner halftile_corner = GetHalftileSlopeCorner(ti->tileh); |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
848 |
if (autorail_type != _lower_rail[halftile_corner]) { |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
849 |
foundation_part = FOUNDATION_PART_HALFTILE; |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
850 |
/* Here we draw the highlights of the "three-corners-raised"-slope. That looks ok to me. */ |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
851 |
autorail_tileh = SlopeWithThreeCornersRaised(OppositeCorner(halftile_corner)); |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
852 |
} |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
853 |
} |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
854 |
|
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
855 |
offset = _AutorailTilehSprite[autorail_tileh][autorail_type]; |
7679
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
856 |
if (offset >= 0) { |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
857 |
image = SPR_AUTORAIL_BASE + offset; |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
858 |
pal = PAL_NONE; |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
859 |
} else { |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
860 |
image = SPR_AUTORAIL_BASE - offset; |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
861 |
pal = PALETTE_SEL_TILE_RED; |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
862 |
} |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
863 |
|
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
864 |
DrawSelectionSprite(image, _thd.make_square_red ? PALETTE_SEL_TILE_RED : pal, ti, 7, foundation_part); |
7679
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
865 |
} |
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
866 |
|
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
867 |
/** |
7078
521bc677ce92
(svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents:
7069
diff
changeset
|
868 |
* Checks if the specified tile is selected and if so draws selection using correct selectionstyle. |
521bc677ce92
(svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents:
7069
diff
changeset
|
869 |
* @param *ti TileInfo Tile that is being drawn |
521bc677ce92
(svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents:
7069
diff
changeset
|
870 |
*/ |
0 | 871 |
static void DrawTileSelection(const TileInfo *ti) |
872 |
{ |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
873 |
/* Draw a red error square? */ |
8743
83eeb388f213
(svn r12439) -Fix [FS#1871]: do not 'disable' the drawing of autorail overlays when the tile is 'error'-marked (red pulsating selection). Patch by Icosikai.
rubidium
parents:
8585
diff
changeset
|
874 |
bool is_redsq = _thd.redsq != 0 && _thd.redsq == ti->tile; |
83eeb388f213
(svn r12439) -Fix [FS#1871]: do not 'disable' the drawing of autorail overlays when the tile is 'error'-marked (red pulsating selection). Patch by Icosikai.
rubidium
parents:
8585
diff
changeset
|
875 |
if (is_redsq) DrawTileSelectionRect(ti, PALETTE_TILE_RED_PULSATING); |
0 | 876 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
877 |
/* no selection active? */ |
2116 | 878 |
if (_thd.drawstyle == 0) return; |
0 | 879 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
880 |
/* Inside the inner area? */ |
7954
57b51c69c072
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
7951
diff
changeset
|
881 |
if (IsInsideBS(ti->x, _thd.pos.x, _thd.size.x) && |
57b51c69c072
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
7951
diff
changeset
|
882 |
IsInsideBS(ti->y, _thd.pos.y, _thd.size.y)) { |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
883 |
if (_thd.drawstyle & HT_RECT) { |
8743
83eeb388f213
(svn r12439) -Fix [FS#1871]: do not 'disable' the drawing of autorail overlays when the tile is 'error'-marked (red pulsating selection). Patch by Icosikai.
rubidium
parents:
8585
diff
changeset
|
884 |
if (!is_redsq) DrawTileSelectionRect(ti, _thd.make_square_red ? PALETTE_SEL_TILE_RED : PAL_NONE); |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
885 |
} else if (_thd.drawstyle & HT_POINT) { |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
886 |
/* Figure out the Z coordinate for the single dot. */ |
7726
a9c8beebf2c1
(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:
7681
diff
changeset
|
887 |
byte z = 0; |
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
888 |
FoundationPart foundation_part = FOUNDATION_PART_NORMAL; |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3609
diff
changeset
|
889 |
if (ti->tileh & SLOPE_N) { |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
890 |
z += TILE_HEIGHT; |
8413
c7f3384330a3
(svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents:
8270
diff
changeset
|
891 |
if (RemoveHalftileSlope(ti->tileh) == SLOPE_STEEP_N) z += TILE_HEIGHT; |
0 | 892 |
} |
7769
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
893 |
if (IsHalftileSlope(ti->tileh)) { |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
894 |
Corner halftile_corner = GetHalftileSlopeCorner(ti->tileh); |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
895 |
if ((halftile_corner == CORNER_W) || (halftile_corner == CORNER_E)) z += TILE_HEIGHT; |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
896 |
if (halftile_corner != CORNER_S) { |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
897 |
foundation_part = FOUNDATION_PART_HALFTILE; |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
898 |
if (IsSteepSlope(ti->tileh)) z -= TILE_HEIGHT; |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
899 |
} |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
900 |
} |
f072d6bb8b99
(svn r11318) -Codechange: add the actual support for drawing selections on halftiles, r11316 just added the things needed to load the sprites. Patch by frosch.
rubidium
parents:
7764
diff
changeset
|
901 |
DrawSelectionSprite(_cur_dpi->zoom <= ZOOM_LVL_DETAIL ? SPR_DOT : SPR_DOT_SMALL, PAL_NONE, ti, z, foundation_part); |
2116 | 902 |
} else if (_thd.drawstyle & HT_RAIL /*&& _thd.place_mode == VHM_RAIL*/) { |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
903 |
/* autorail highlight piece under cursor */ |
2116 | 904 |
uint type = _thd.drawstyle & 0xF; |
905 |
assert(type <= 5); |
|
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
906 |
DrawAutorailSelection(ti, _autorail_type[type][0]); |
2116 | 907 |
} else if (IsPartOfAutoLine(ti->x, ti->y)) { |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
908 |
/* autorail highlighting long line */ |
2116 | 909 |
int dir = _thd.drawstyle & ~0xF0; |
910 |
uint side; |
|
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
911 |
|
2116 | 912 |
if (dir < 2) { |
913 |
side = 0; |
|
914 |
} else { |
|
915 |
TileIndex start = TileVirtXY(_thd.selstart.x, _thd.selstart.y); |
|
7970
7d6b9ab57081
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents:
7954
diff
changeset
|
916 |
side = Delta(Delta(TileX(start), TileX(ti->tile)), Delta(TileY(start), TileY(ti->tile))); |
2116 | 917 |
} |
1109
ecb98f43ba2c
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
918 |
|
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
919 |
DrawAutorailSelection(ti, _autorail_type[dir][side]); |
2116 | 920 |
} |
0 | 921 |
return; |
922 |
} |
|
923 |
||
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
924 |
/* Check if it's inside the outer area? */ |
8743
83eeb388f213
(svn r12439) -Fix [FS#1871]: do not 'disable' the drawing of autorail overlays when the tile is 'error'-marked (red pulsating selection). Patch by Icosikai.
rubidium
parents:
8585
diff
changeset
|
925 |
if (!is_redsq && _thd.outersize.x && |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
926 |
_thd.size.x < _thd.size.x + _thd.outersize.x && |
7954
57b51c69c072
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
7951
diff
changeset
|
927 |
IsInsideBS(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) && |
57b51c69c072
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
7951
diff
changeset
|
928 |
IsInsideBS(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) { |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
929 |
/* Draw a blue rect. */ |
7679
8a6dd197ccf1
(svn r11210) -Codechange: unify the way that selection sprites are drawn. Patch by frosch.
rubidium
parents:
7659
diff
changeset
|
930 |
DrawTileSelectionRect(ti, PALETTE_SEL_TILE_BLUE); |
0 | 931 |
return; |
932 |
} |
|
933 |
} |
|
934 |
||
6247 | 935 |
static void ViewportAddLandscape() |
0 | 936 |
{ |
937 |
int x, y, width, height; |
|
938 |
TileInfo ti; |
|
939 |
bool direction; |
|
940 |
||
941 |
_cur_ti = &ti; |
|
942 |
||
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
943 |
/* Transform into tile coordinates and round to closest full tile */ |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
944 |
x = ((_vd.dpi.top >> 1) - (_vd.dpi.left >> 2)) & ~0xF; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
945 |
y = ((_vd.dpi.top >> 1) + (_vd.dpi.left >> 2) - 0x10) & ~0xF; |
5501
b4e81fd72b3a
(svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents:
5475
diff
changeset
|
946 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
947 |
/* determine size of area */ |
0 | 948 |
{ |
949 |
Point pt = RemapCoords(x, y, 241); |
|
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
950 |
width = (_vd.dpi.left + _vd.dpi.width - pt.x + 95) >> 6; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
951 |
height = (_vd.dpi.top + _vd.dpi.height - pt.y) >> 5 << 1; |
0 | 952 |
} |
953 |
||
954 |
assert(width > 0); |
|
955 |
assert(height > 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
956 |
|
0 | 957 |
direction = false; |
958 |
||
959 |
do { |
|
960 |
int width_cur = width; |
|
961 |
int x_cur = x; |
|
962 |
int y_cur = y; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
963 |
|
0 | 964 |
do { |
4238
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
965 |
TileType tt; |
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
966 |
|
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
967 |
ti.x = x_cur; |
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
968 |
ti.y = y_cur; |
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
969 |
if (0 <= x_cur && x_cur < (int)MapMaxX() * TILE_SIZE && |
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
970 |
0 <= y_cur && y_cur < (int)MapMaxY() * TILE_SIZE) { |
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
971 |
TileIndex tile = TileVirtXY(x_cur, y_cur); |
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
972 |
|
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
973 |
ti.tile = tile; |
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
974 |
ti.tileh = GetTileSlope(tile, &ti.z); |
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
975 |
tt = GetTileType(tile); |
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
976 |
} else { |
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
977 |
ti.tileh = SLOPE_FLAT; |
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
978 |
ti.tile = 0; |
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
979 |
ti.z = 0; |
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
980 |
tt = MP_VOID; |
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
981 |
} |
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
982 |
|
0 | 983 |
y_cur += 0x10; |
984 |
x_cur -= 0x10; |
|
5501
b4e81fd72b3a
(svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents:
5475
diff
changeset
|
985 |
|
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
986 |
_vd.foundation_part = FOUNDATION_PART_NONE; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
987 |
_vd.foundation[0] = -1; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
988 |
_vd.foundation[1] = -1; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
989 |
_vd.last_foundation_child[0] = NULL; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
990 |
_vd.last_foundation_child[1] = NULL; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
991 |
|
4238
4b58d6ea4e5b
(svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents:
4231
diff
changeset
|
992 |
_tile_type_procs[tt]->draw_tile_proc(&ti); |
0 | 993 |
DrawTileSelection(&ti); |
994 |
} while (--width_cur); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
995 |
|
5501
b4e81fd72b3a
(svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents:
5475
diff
changeset
|
996 |
if ((direction ^= 1) != 0) { |
0 | 997 |
y += 0x10; |
5501
b4e81fd72b3a
(svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents:
5475
diff
changeset
|
998 |
} else { |
0 | 999 |
x += 0x10; |
5501
b4e81fd72b3a
(svn r7794) -Cleanup: Remove obsolete, never-used landscape rotation code. And spell obsolete correctly.
peter1138
parents:
5475
diff
changeset
|
1000 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1001 |
} while (--height); |
0 | 1002 |
} |
1003 |
||
1004 |
||
410 | 1005 |
static void ViewportAddTownNames(DrawPixelInfo *dpi) |
0 | 1006 |
{ |
1007 |
Town *t; |
|
1008 |
int left, top, right, bottom; |
|
1009 |
||
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
1010 |
if (!HasBit(_display_opt, DO_SHOW_TOWN_NAMES) || _game_mode == GM_MENU) |
0 | 1011 |
return; |
1012 |
||
1013 |
left = dpi->left; |
|
1014 |
top = dpi->top; |
|
1015 |
right = left + dpi->width; |
|
1016 |
bottom = top + dpi->height; |
|
1017 |
||
5027 | 1018 |
switch (dpi->zoom) { |
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1019 |
case ZOOM_LVL_NORMAL: |
5027 | 1020 |
FOR_ALL_TOWNS(t) { |
1021 |
if (bottom > t->sign.top && |
|
1022 |
top < t->sign.top + 12 && |
|
1023 |
right > t->sign.left && |
|
1024 |
left < t->sign.left + t->sign.width_1) { |
|
1025 |
AddStringToDraw(t->sign.left + 1, t->sign.top + 1, |
|
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9410
diff
changeset
|
1026 |
_settings_client.gui.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL, |
5027 | 1027 |
t->index, t->population); |
1028 |
} |
|
0 | 1029 |
} |
5027 | 1030 |
break; |
1031 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1032 |
case ZOOM_LVL_OUT_2X: |
5027 | 1033 |
right += 2; |
1034 |
bottom += 2; |
|
1035 |
||
1036 |
FOR_ALL_TOWNS(t) { |
|
1037 |
if (bottom > t->sign.top && |
|
1038 |
top < t->sign.top + 24 && |
|
1039 |
right > t->sign.left && |
|
8969
6d1c74e0e2cd
(svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents:
8957
diff
changeset
|
1040 |
left < t->sign.left + t->sign.width_1 * 2) { |
5027 | 1041 |
AddStringToDraw(t->sign.left + 1, t->sign.top + 1, |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9410
diff
changeset
|
1042 |
_settings_client.gui.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL, |
5027 | 1043 |
t->index, t->population); |
1044 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1045 |
} |
5027 | 1046 |
break; |
1047 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1048 |
case ZOOM_LVL_OUT_4X: |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1049 |
case ZOOM_LVL_OUT_8X: |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1050 |
right += ScaleByZoom(1, dpi->zoom); |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1051 |
bottom += ScaleByZoom(1, dpi->zoom) + 1; |
5027 | 1052 |
|
1053 |
FOR_ALL_TOWNS(t) { |
|
1054 |
if (bottom > t->sign.top && |
|
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1055 |
top < t->sign.top + ScaleByZoom(12, dpi->zoom) && |
5027 | 1056 |
right > t->sign.left && |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1057 |
left < t->sign.left + ScaleByZoom(t->sign.width_2, dpi->zoom)) { |
5027 | 1058 |
AddStringToDraw(t->sign.left + 5, t->sign.top + 1, STR_TOWN_LABEL_TINY_BLACK, t->index, 0); |
1059 |
AddStringToDraw(t->sign.left + 1, t->sign.top - 3, STR_TOWN_LABEL_TINY_WHITE, t->index, 0); |
|
1060 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1061 |
} |
5027 | 1062 |
break; |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1063 |
|
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1064 |
default: NOT_REACHED(); |
0 | 1065 |
} |
1066 |
} |
|
1067 |
||
5025 | 1068 |
|
1069 |
static void AddStation(const Station *st, StringID str, uint16 width) |
|
1070 |
{ |
|
8946
a800978c3c8f
(svn r12734) -Codechange: use a vector instead of allocating memory in a big byte array for StringSpriteToDraw.
rubidium
parents:
8925
diff
changeset
|
1071 |
AddStringToDraw(st->sign.left + 1, st->sign.top + 1, str, st->index, st->facilities, (st->owner == OWNER_NONE || st->facilities == 0) ? 0xE : _player_colors[st->owner], width); |
5025 | 1072 |
} |
1073 |
||
1074 |
||
410 | 1075 |
static void ViewportAddStationNames(DrawPixelInfo *dpi) |
0 | 1076 |
{ |
1077 |
int left, top, right, bottom; |
|
5025 | 1078 |
const Station *st; |
0 | 1079 |
|
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
1080 |
if (!HasBit(_display_opt, DO_SHOW_STATION_NAMES) || _game_mode == GM_MENU) |
0 | 1081 |
return; |
1082 |
||
1083 |
left = dpi->left; |
|
1084 |
top = dpi->top; |
|
1085 |
right = left + dpi->width; |
|
1086 |
bottom = top + dpi->height; |
|
1087 |
||
5027 | 1088 |
switch (dpi->zoom) { |
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1089 |
case ZOOM_LVL_NORMAL: |
5027 | 1090 |
FOR_ALL_STATIONS(st) { |
1091 |
if (bottom > st->sign.top && |
|
1092 |
top < st->sign.top + 12 && |
|
1093 |
right > st->sign.left && |
|
1094 |
left < st->sign.left + st->sign.width_1) { |
|
1095 |
AddStation(st, STR_305C_0, st->sign.width_1); |
|
1096 |
} |
|
0 | 1097 |
} |
5027 | 1098 |
break; |
1099 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1100 |
case ZOOM_LVL_OUT_2X: |
5027 | 1101 |
right += 2; |
1102 |
bottom += 2; |
|
1103 |
FOR_ALL_STATIONS(st) { |
|
1104 |
if (bottom > st->sign.top && |
|
1105 |
top < st->sign.top + 24 && |
|
1106 |
right > st->sign.left && |
|
8969
6d1c74e0e2cd
(svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents:
8957
diff
changeset
|
1107 |
left < st->sign.left + st->sign.width_1 * 2) { |
5027 | 1108 |
AddStation(st, STR_305C_0, st->sign.width_1); |
1109 |
} |
|
0 | 1110 |
} |
5027 | 1111 |
break; |
1112 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1113 |
case ZOOM_LVL_OUT_4X: |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1114 |
case ZOOM_LVL_OUT_8X: |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1115 |
right += ScaleByZoom(1, dpi->zoom); |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1116 |
bottom += ScaleByZoom(1, dpi->zoom) + 1; |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1117 |
|
5027 | 1118 |
FOR_ALL_STATIONS(st) { |
1119 |
if (bottom > st->sign.top && |
|
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1120 |
top < st->sign.top + ScaleByZoom(12, dpi->zoom) && |
5027 | 1121 |
right > st->sign.left && |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1122 |
left < st->sign.left + ScaleByZoom(st->sign.width_2, dpi->zoom)) { |
5027 | 1123 |
AddStation(st, STR_STATION_SIGN_TINY, st->sign.width_2 | 0x8000); |
1124 |
} |
|
0 | 1125 |
} |
5027 | 1126 |
break; |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1127 |
|
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1128 |
default: NOT_REACHED(); |
0 | 1129 |
} |
1130 |
} |
|
1131 |
||
5025 | 1132 |
|
1133 |
static void AddSign(const Sign *si, StringID str, uint16 width) |
|
1134 |
{ |
|
8946
a800978c3c8f
(svn r12734) -Codechange: use a vector instead of allocating memory in a big byte array for StringSpriteToDraw.
rubidium
parents:
8925
diff
changeset
|
1135 |
AddStringToDraw(si->sign.left + 1, si->sign.top + 1, str, si->index, 0, (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner], width); |
5025 | 1136 |
} |
1137 |
||
1138 |
||
410 | 1139 |
static void ViewportAddSigns(DrawPixelInfo *dpi) |
0 | 1140 |
{ |
5025 | 1141 |
const Sign *si; |
0 | 1142 |
int left, top, right, bottom; |
1143 |
||
8806
4fe163e0b52a
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents:
8798
diff
changeset
|
1144 |
/* Signs are turned off or are invisible */ |
4fe163e0b52a
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents:
8798
diff
changeset
|
1145 |
if (!HasBit(_display_opt, DO_SHOW_SIGNS) || IsInvisibilitySet(TO_SIGNS)) return; |
0 | 1146 |
|
1147 |
left = dpi->left; |
|
1148 |
top = dpi->top; |
|
1149 |
right = left + dpi->width; |
|
1150 |
bottom = top + dpi->height; |
|
1151 |
||
5027 | 1152 |
switch (dpi->zoom) { |
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1153 |
case ZOOM_LVL_NORMAL: |
5027 | 1154 |
FOR_ALL_SIGNS(si) { |
1155 |
if (bottom > si->sign.top && |
|
1156 |
top < si->sign.top + 12 && |
|
1157 |
right > si->sign.left && |
|
1158 |
left < si->sign.left + si->sign.width_1) { |
|
1159 |
AddSign(si, STR_2806, si->sign.width_1); |
|
1160 |
} |
|
0 | 1161 |
} |
5027 | 1162 |
break; |
1163 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1164 |
case ZOOM_LVL_OUT_2X: |
5027 | 1165 |
right += 2; |
1166 |
bottom += 2; |
|
1167 |
FOR_ALL_SIGNS(si) { |
|
1168 |
if (bottom > si->sign.top && |
|
1169 |
top < si->sign.top + 24 && |
|
1170 |
right > si->sign.left && |
|
1171 |
left < si->sign.left + si->sign.width_1 * 2) { |
|
1172 |
AddSign(si, STR_2806, si->sign.width_1); |
|
1173 |
} |
|
0 | 1174 |
} |
5027 | 1175 |
break; |
1176 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1177 |
case ZOOM_LVL_OUT_4X: |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1178 |
case ZOOM_LVL_OUT_8X: |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1179 |
right += ScaleByZoom(1, dpi->zoom); |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1180 |
bottom += ScaleByZoom(1, dpi->zoom) + 1; |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1181 |
|
5027 | 1182 |
FOR_ALL_SIGNS(si) { |
1183 |
if (bottom > si->sign.top && |
|
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1184 |
top < si->sign.top + ScaleByZoom(12, dpi->zoom) && |
5027 | 1185 |
right > si->sign.left && |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1186 |
left < si->sign.left + ScaleByZoom(si->sign.width_2, dpi->zoom)) { |
7951
9df5b61377c7
(svn r11507) -Fix [FS#1463]: signs totally illegible when transparant signs is turned on and zoomed out more than one level.
rubidium
parents:
7931
diff
changeset
|
1187 |
AddSign(si, IsTransparencySet(TO_SIGNS) ? STR_2002_WHITE : STR_2002, si->sign.width_2 | 0x8000); |
5027 | 1188 |
} |
0 | 1189 |
} |
5027 | 1190 |
break; |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1191 |
|
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1192 |
default: NOT_REACHED(); |
0 | 1193 |
} |
1194 |
} |
|
1195 |
||
5025 | 1196 |
|
1197 |
static void AddWaypoint(const Waypoint *wp, StringID str, uint16 width) |
|
1198 |
{ |
|
8946
a800978c3c8f
(svn r12734) -Codechange: use a vector instead of allocating memory in a big byte array for StringSpriteToDraw.
rubidium
parents:
8925
diff
changeset
|
1199 |
AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, str, wp->index, 0, (wp->deleted ? 0xE : 11), width); |
5025 | 1200 |
} |
1201 |
||
1202 |
||
410 | 1203 |
static void ViewportAddWaypoints(DrawPixelInfo *dpi) |
0 | 1204 |
{ |
5025 | 1205 |
const Waypoint *wp; |
0 | 1206 |
int left, top, right, bottom; |
1207 |
||
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
1208 |
if (!HasBit(_display_opt, DO_WAYPOINTS)) |
0 | 1209 |
return; |
1210 |
||
1211 |
left = dpi->left; |
|
1212 |
top = dpi->top; |
|
1213 |
right = left + dpi->width; |
|
1214 |
bottom = top + dpi->height; |
|
1215 |
||
5027 | 1216 |
switch (dpi->zoom) { |
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1217 |
case ZOOM_LVL_NORMAL: |
5027 | 1218 |
FOR_ALL_WAYPOINTS(wp) { |
1219 |
if (bottom > wp->sign.top && |
|
1220 |
top < wp->sign.top + 12 && |
|
1221 |
right > wp->sign.left && |
|
1222 |
left < wp->sign.left + wp->sign.width_1) { |
|
1223 |
AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1); |
|
1224 |
} |
|
0 | 1225 |
} |
5027 | 1226 |
break; |
1227 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1228 |
case ZOOM_LVL_OUT_2X: |
5027 | 1229 |
right += 2; |
1230 |
bottom += 2; |
|
1231 |
FOR_ALL_WAYPOINTS(wp) { |
|
1232 |
if (bottom > wp->sign.top && |
|
1233 |
top < wp->sign.top + 24 && |
|
1234 |
right > wp->sign.left && |
|
8969
6d1c74e0e2cd
(svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents:
8957
diff
changeset
|
1235 |
left < wp->sign.left + wp->sign.width_1 * 2) { |
5027 | 1236 |
AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1); |
1237 |
} |
|
0 | 1238 |
} |
5027 | 1239 |
break; |
1240 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1241 |
case ZOOM_LVL_OUT_4X: |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1242 |
case ZOOM_LVL_OUT_8X: |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1243 |
right += ScaleByZoom(1, dpi->zoom); |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1244 |
bottom += ScaleByZoom(1, dpi->zoom) + 1; |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1245 |
|
5027 | 1246 |
FOR_ALL_WAYPOINTS(wp) { |
1247 |
if (bottom > wp->sign.top && |
|
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1248 |
top < wp->sign.top + ScaleByZoom(12, dpi->zoom) && |
5027 | 1249 |
right > wp->sign.left && |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1250 |
left < wp->sign.left + ScaleByZoom(wp->sign.width_2, dpi->zoom)) { |
5027 | 1251 |
AddWaypoint(wp, STR_WAYPOINT_VIEWPORT_TINY, wp->sign.width_2 | 0x8000); |
1252 |
} |
|
0 | 1253 |
} |
5027 | 1254 |
break; |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1255 |
|
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1256 |
default: NOT_REACHED(); |
0 | 1257 |
} |
1258 |
} |
|
1259 |
||
1260 |
void UpdateViewportSignPos(ViewportSign *sign, int left, int top, StringID str) |
|
1261 |
{ |
|
1262 |
char buffer[128]; |
|
2116 | 1263 |
uint w; |
0 | 1264 |
|
1265 |
sign->top = top; |
|
1266 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4885
diff
changeset
|
1267 |
GetString(buffer, str, lastof(buffer)); |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4539
diff
changeset
|
1268 |
w = GetStringBoundingBox(buffer).width + 3; |
0 | 1269 |
sign->width_1 = w; |
2116 | 1270 |
sign->left = left - w / 2; |
0 | 1271 |
|
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4539
diff
changeset
|
1272 |
/* zoomed out version */ |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3645
diff
changeset
|
1273 |
_cur_fontsize = FS_SMALL; |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4539
diff
changeset
|
1274 |
w = GetStringBoundingBox(buffer).width + 3; |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3645
diff
changeset
|
1275 |
_cur_fontsize = FS_NORMAL; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1363
diff
changeset
|
1276 |
sign->width_2 = w; |
0 | 1277 |
} |
1278 |
||
1279 |
||
8947
89220c41178d
(svn r12735) -Codechange: use a vector instead of allocating memory in a byte array for TileSpriteToDraw.
rubidium
parents:
8946
diff
changeset
|
1280 |
static void ViewportDrawTileSprites(const TileSpriteToDrawVector *tstdv) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1281 |
{ |
8949
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
1282 |
const TileSpriteToDraw *tsend = tstdv->End(); |
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
1283 |
for (const TileSpriteToDraw *ts = tstdv->Begin(); ts != tsend; ++ts) { |
0 | 1284 |
Point pt = RemapCoords(ts->x, ts->y, ts->z); |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
1285 |
DrawSprite(ts->image, ts->pal, pt.x, pt.y, ts->sub); |
8947
89220c41178d
(svn r12735) -Codechange: use a vector instead of allocating memory in a byte array for TileSpriteToDraw.
rubidium
parents:
8946
diff
changeset
|
1286 |
} |
0 | 1287 |
} |
1288 |
||
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
1289 |
static void ViewportSortParentSprites(ParentSpriteToSortVector *psdv) |
0 | 1290 |
{ |
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
1291 |
ParentSpriteToDraw **psdvend = psdv->End(); |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
1292 |
ParentSpriteToDraw **psd = psdv->Begin(); |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
1293 |
while (psd != psdvend) { |
8948
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1294 |
ParentSpriteToDraw *ps = *psd; |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1295 |
|
8950
1b63e0102dbb
(svn r12738) -Fix (r12736): some sprites could be left unsorted
smatz
parents:
8949
diff
changeset
|
1296 |
if (ps->comparison_done) { |
1b63e0102dbb
(svn r12738) -Fix (r12736): some sprites could be left unsorted
smatz
parents:
8949
diff
changeset
|
1297 |
psd++; |
1b63e0102dbb
(svn r12738) -Fix (r12736): some sprites could be left unsorted
smatz
parents:
8949
diff
changeset
|
1298 |
continue; |
1b63e0102dbb
(svn r12738) -Fix (r12736): some sprites could be left unsorted
smatz
parents:
8949
diff
changeset
|
1299 |
} |
8948
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1300 |
|
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1301 |
ps->comparison_done = true; |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1302 |
|
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
1303 |
for (ParentSpriteToDraw **psd2 = psd + 1; psd2 != psdvend; psd2++) { |
8948
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1304 |
ParentSpriteToDraw *ps2 = *psd2; |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1305 |
|
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1306 |
if (ps2->comparison_done) continue; |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1307 |
|
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1308 |
/* Decide which comparator to use, based on whether the bounding |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1309 |
* boxes overlap |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1310 |
*/ |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1311 |
if (ps->xmax >= ps2->xmin && ps->xmin <= ps2->xmax && // overlap in X? |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1312 |
ps->ymax >= ps2->ymin && ps->ymin <= ps2->ymax && // overlap in Y? |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1313 |
ps->zmax >= ps2->zmin && ps->zmin <= ps2->zmax) { // overlap in Z? |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1314 |
/* Use X+Y+Z as the sorting order, so sprites closer to the bottom of |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1315 |
* the screen and with higher Z elevation, are drawn in front. |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1316 |
* Here X,Y,Z are the coordinates of the "center of mass" of the sprite, |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1317 |
* i.e. X=(left+right)/2, etc. |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1318 |
* However, since we only care about order, don't actually divide / 2 |
4187
4eaf57b951c8
(svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents:
4186
diff
changeset
|
1319 |
*/ |
8948
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1320 |
if (ps->xmin + ps->xmax + ps->ymin + ps->ymax + ps->zmin + ps->zmax <= |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1321 |
ps2->xmin + ps2->xmax + ps2->ymin + ps2->ymax + ps2->zmin + ps2->zmax) { |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1322 |
continue; |
1934
b27bc12822cd
(svn r2440) - Fix: [newgrf] Fix the spritesorter to handle overlapping sprites properly, this fixes display problems with really short wagons. (algorithm by patchman, ported by therax)
hackykid
parents:
1932
diff
changeset
|
1323 |
} |
8948
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1324 |
} else { |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1325 |
/* We only change the order, if it is definite. |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1326 |
* I.e. every single order of X, Y, Z says ps2 is behind ps or they overlap. |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1327 |
* That is: If one partial order says ps behind ps2, do not change the order. |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1328 |
*/ |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1329 |
if (ps->xmax < ps2->xmin || |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1330 |
ps->ymax < ps2->ymin || |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1331 |
ps->zmax < ps2->zmin) { |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1332 |
continue; |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1333 |
} |
0 | 1334 |
} |
8948
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1335 |
|
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1336 |
/* Swap the two sprites ps and ps2 using bubble-sort algorithm. */ |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1337 |
ParentSpriteToDraw **psd3 = psd; |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1338 |
do { |
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
1339 |
ParentSpriteToDraw *temp = *psd3; |
8948
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1340 |
*psd3 = ps2; |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1341 |
ps2 = temp; |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1342 |
|
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1343 |
psd3++; |
1c59e18c90ec
(svn r12736) -Codechange: a (small) touch of coding style in viewport.cpp.
rubidium
parents:
8947
diff
changeset
|
1344 |
} while (psd3 <= psd2); |
0 | 1345 |
} |
1346 |
} |
|
1347 |
} |
|
1348 |
||
8952
be6bfd75e554
(svn r12740) -Codechange: use a vector instead of allocating memory in a byte array for ChildScreenSpriteToDraw.
rubidium
parents:
8951
diff
changeset
|
1349 |
static void ViewportDrawParentSprites(const ParentSpriteToSortVector *psd, const ChildScreenSpriteToDrawVector *csstdv) |
0 | 1350 |
{ |
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
1351 |
const ParentSpriteToDraw * const *psd_end = psd->End(); |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
1352 |
for (const ParentSpriteToDraw * const *it = psd->Begin(); it != psd_end; it++) { |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
1353 |
const ParentSpriteToDraw *ps = *it; |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
1354 |
if (ps->image != SPR_EMPTY_BOUNDING_BOX) DrawSprite(ps->image, ps->pal, ps->x, ps->y, ps->sub); |
0 | 1355 |
|
9534
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
1356 |
int child_idx = ps->first_child; |
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
1357 |
while (child_idx >= 0) { |
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
1358 |
const ChildScreenSpriteToDraw *cs = csstdv->Get(child_idx); |
088ad1af3261
(svn r13538) -Fix (r12740)[FS#2087]: ChildSprites of foundations are not necessarily consecutive.
frosch
parents:
9510
diff
changeset
|
1359 |
child_idx = cs->next; |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7679
diff
changeset
|
1360 |
DrawSprite(cs->image, cs->pal, ps->left + cs->x, ps->top + cs->y, cs->sub); |
0 | 1361 |
} |
1362 |
} |
|
1363 |
} |
|
1364 |
||
7643
af32b07bc027
(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:
7617
diff
changeset
|
1365 |
/** |
af32b07bc027
(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:
7617
diff
changeset
|
1366 |
* Draws the bounding boxes of all ParentSprites |
af32b07bc027
(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:
7617
diff
changeset
|
1367 |
* @param psd Array of ParentSprites |
af32b07bc027
(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:
7617
diff
changeset
|
1368 |
*/ |
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
1369 |
static void ViewportDrawBoundingBoxes(const ParentSpriteToSortVector *psd) |
7643
af32b07bc027
(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:
7617
diff
changeset
|
1370 |
{ |
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
1371 |
const ParentSpriteToDraw * const *psd_end = psd->End(); |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
1372 |
for (const ParentSpriteToDraw * const *it = psd->Begin(); it != psd_end; it++) { |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
1373 |
const ParentSpriteToDraw *ps = *it; |
7643
af32b07bc027
(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:
7617
diff
changeset
|
1374 |
Point pt1 = RemapCoords(ps->xmax + 1, ps->ymax + 1, ps->zmax + 1); // top front corner |
af32b07bc027
(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:
7617
diff
changeset
|
1375 |
Point pt2 = RemapCoords(ps->xmin , ps->ymax + 1, ps->zmax + 1); // top left corner |
af32b07bc027
(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:
7617
diff
changeset
|
1376 |
Point pt3 = RemapCoords(ps->xmax + 1, ps->ymin , ps->zmax + 1); // top right corner |
af32b07bc027
(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:
7617
diff
changeset
|
1377 |
Point pt4 = RemapCoords(ps->xmax + 1, ps->ymax + 1, ps->zmin ); // bottom front corner |
af32b07bc027
(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:
7617
diff
changeset
|
1378 |
|
af32b07bc027
(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:
7617
diff
changeset
|
1379 |
DrawBox( pt1.x, pt1.y, |
af32b07bc027
(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:
7617
diff
changeset
|
1380 |
pt2.x - pt1.x, pt2.y - pt1.y, |
af32b07bc027
(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:
7617
diff
changeset
|
1381 |
pt3.x - pt1.x, pt3.y - pt1.y, |
af32b07bc027
(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:
7617
diff
changeset
|
1382 |
pt4.x - pt1.x, pt4.y - pt1.y); |
af32b07bc027
(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:
7617
diff
changeset
|
1383 |
} |
af32b07bc027
(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:
7617
diff
changeset
|
1384 |
} |
af32b07bc027
(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:
7617
diff
changeset
|
1385 |
|
8946
a800978c3c8f
(svn r12734) -Codechange: use a vector instead of allocating memory in a big byte array for StringSpriteToDraw.
rubidium
parents:
8925
diff
changeset
|
1386 |
static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDrawVector *sstdv) |
0 | 1387 |
{ |
1388 |
DrawPixelInfo dp; |
|
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1389 |
ZoomLevel zoom; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1390 |
|
0 | 1391 |
_cur_dpi = &dp; |
1392 |
dp = *dpi; |
|
1393 |
||
2116 | 1394 |
zoom = dp.zoom; |
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1395 |
dp.zoom = ZOOM_LVL_NORMAL; |
0 | 1396 |
|
6654
31d17823506f
(svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents:
6653
diff
changeset
|
1397 |
dp.left = UnScaleByZoom(dp.left, zoom); |
31d17823506f
(svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents:
6653
diff
changeset
|
1398 |
dp.top = UnScaleByZoom(dp.top, zoom); |
31d17823506f
(svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents:
6653
diff
changeset
|
1399 |
dp.width = UnScaleByZoom(dp.width, zoom); |
31d17823506f
(svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents:
6653
diff
changeset
|
1400 |
dp.height = UnScaleByZoom(dp.height, zoom); |
0 | 1401 |
|
8949
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
1402 |
const StringSpriteToDraw *ssend = sstdv->End(); |
4c9fbf5ec359
(svn r12737) -Codechange: Replace vector with a cut down class to allocate space as necessary. This avoids copying data around for vector's push_back() function.
peter1138
parents:
8948
diff
changeset
|
1403 |
for (const StringSpriteToDraw *ss = sstdv->Begin(); ss != ssend; ++ss) { |
5025 | 1404 |
uint16 colour; |
1405 |
||
0 | 1406 |
if (ss->width != 0) { |
8806
4fe163e0b52a
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents:
8798
diff
changeset
|
1407 |
/* Do not draw signs nor station names if they are set invisible */ |
8946
a800978c3c8f
(svn r12734) -Codechange: use a vector instead of allocating memory in a big byte array for StringSpriteToDraw.
rubidium
parents:
8925
diff
changeset
|
1408 |
if (IsInvisibilitySet(TO_SIGNS) && ss->string != STR_2806) continue; |
8806
4fe163e0b52a
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents:
8798
diff
changeset
|
1409 |
|
6654
31d17823506f
(svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents:
6653
diff
changeset
|
1410 |
int x = UnScaleByZoom(ss->x, zoom) - 1; |
31d17823506f
(svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents:
6653
diff
changeset
|
1411 |
int y = UnScaleByZoom(ss->y, zoom) - 1; |
2116 | 1412 |
int bottom = y + 11; |
1413 |
int w = ss->width; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1414 |
|
0 | 1415 |
if (w & 0x8000) { |
1416 |
w &= ~0x8000; |
|
1417 |
y--; |
|
1418 |
bottom -= 6; |
|
1419 |
w -= 3; |
|
1420 |
} |
|
1421 |
||
2116 | 1422 |
/* Draw the rectangle if 'tranparent station signs' is off, |
1423 |
* or if we are drawing a general text sign (STR_2806) */ |
|
7849
0a1c0af2c96c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
7824
diff
changeset
|
1424 |
if (!IsTransparencySet(TO_SIGNS) || ss->string == STR_2806) { |
2116 | 1425 |
DrawFrameRect( |
1426 |
x, y, x + w, bottom, ss->color, |
|
7849
0a1c0af2c96c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
7824
diff
changeset
|
1427 |
IsTransparencySet(TO_SIGNS) ? FR_TRANSPARENT : FR_NONE |
2116 | 1428 |
); |
6427
7dc1012757d8
(svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
6423
diff
changeset
|
1429 |
} |
0 | 1430 |
} |
1431 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1432 |
SetDParam(0, ss->params[0]); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1433 |
SetDParam(1, ss->params[1]); |
2116 | 1434 |
/* if we didn't draw a rectangle, or if transparant building is on, |
1435 |
* draw the text in the color the rectangle would have */ |
|
7849
0a1c0af2c96c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
7824
diff
changeset
|
1436 |
if (IsTransparencySet(TO_SIGNS) && ss->string != STR_2806 && ss->width != 0) { |
2116 | 1437 |
/* Real colors need the IS_PALETTE_COLOR flag |
1438 |
* otherwise colors from _string_colormap are assumed. */ |
|
5025 | 1439 |
colour = _colour_gradient[ss->color][6] | IS_PALETTE_COLOR; |
0 | 1440 |
} else { |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7769
diff
changeset
|
1441 |
colour = TC_BLACK; |
0 | 1442 |
} |
5025 | 1443 |
DrawString( |
6654
31d17823506f
(svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents:
6653
diff
changeset
|
1444 |
UnScaleByZoom(ss->x, zoom), UnScaleByZoom(ss->y, zoom) - (ss->width & 0x8000 ? 2 : 0), |
5025 | 1445 |
ss->string, colour |
1446 |
); |
|
8947
89220c41178d
(svn r12735) -Codechange: use a vector instead of allocating memory in a byte array for TileSpriteToDraw.
rubidium
parents:
8946
diff
changeset
|
1447 |
} |
0 | 1448 |
} |
1449 |
||
430 | 1450 |
void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom) |
0 | 1451 |
{ |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1452 |
DrawPixelInfo *old_dpi = _cur_dpi; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1453 |
_cur_dpi = &_vd.dpi; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1454 |
|
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1455 |
_vd.dpi.zoom = vp->zoom; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1456 |
int mask = ScaleByZoom(-1, vp->zoom); |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1457 |
|
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1458 |
_vd.combine_sprites = 0; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1459 |
|
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1460 |
_vd.dpi.width = (right - left) & mask; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1461 |
_vd.dpi.height = (bottom - top) & mask; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1462 |
_vd.dpi.left = left & mask; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1463 |
_vd.dpi.top = top & mask; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1464 |
_vd.dpi.pitch = old_dpi->pitch; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1465 |
_vd.last_child = NULL; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1466 |
|
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1467 |
int x = UnScaleByZoom(_vd.dpi.left - (vp->virtual_left & mask), vp->zoom) + vp->left; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1468 |
int y = UnScaleByZoom(_vd.dpi.top - (vp->virtual_top & mask), vp->zoom) + vp->top; |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1469 |
|
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1470 |
_vd.dpi.dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(old_dpi->dst_ptr, x - old_dpi->left, y - old_dpi->top); |
0 | 1471 |
|
1472 |
ViewportAddLandscape(); |
|
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1473 |
ViewportAddVehicles(&_vd.dpi); |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1474 |
DrawTextEffects(&_vd.dpi); |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1475 |
|
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1476 |
ViewportAddTownNames(&_vd.dpi); |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1477 |
ViewportAddStationNames(&_vd.dpi); |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1478 |
ViewportAddSigns(&_vd.dpi); |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1479 |
ViewportAddWaypoints(&_vd.dpi); |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1480 |
|
9553
93848ae90336
(svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13
parents:
9534
diff
changeset
|
1481 |
if (_vd.tile_sprites_to_draw.Length() != 0) ViewportDrawTileSprites(&_vd.tile_sprites_to_draw); |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1482 |
|
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1483 |
ParentSpriteToDraw *psd_end = _vd.parent_sprites_to_draw.End(); |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1484 |
for (ParentSpriteToDraw *it = _vd.parent_sprites_to_draw.Begin(); it != psd_end; it++) { |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1485 |
*_vd.parent_sprites_to_sort.Append() = it; |
8951
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
1486 |
} |
618a0b1a5061
(svn r12739) -Codechange: use a vector instead of allocating memory in a byte array for ParentSpriteToDraw.
rubidium
parents:
8950
diff
changeset
|
1487 |
|
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1488 |
ViewportSortParentSprites(&_vd.parent_sprites_to_sort); |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1489 |
ViewportDrawParentSprites(&_vd.parent_sprites_to_sort, &_vd.child_screen_sprites_to_draw); |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1490 |
|
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1491 |
if (_draw_bounding_boxes) ViewportDrawBoundingBoxes(&_vd.parent_sprites_to_sort); |
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1492 |
|
9553
93848ae90336
(svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13
parents:
9534
diff
changeset
|
1493 |
if (_vd.string_sprites_to_draw.Length() != 0) ViewportDrawStrings(&_vd.dpi, &_vd.string_sprites_to_draw); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1494 |
|
0 | 1495 |
_cur_dpi = old_dpi; |
8953
fea4aa214d9c
(svn r12741) -Codechange: do not allocate the viewport drawer each time on the stack, but only once and reuse this.
rubidium
parents:
8952
diff
changeset
|
1496 |
|
9553
93848ae90336
(svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13
parents:
9534
diff
changeset
|
1497 |
_vd.string_sprites_to_draw.Clear(); |
93848ae90336
(svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13
parents:
9534
diff
changeset
|
1498 |
_vd.tile_sprites_to_draw.Clear(); |
93848ae90336
(svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13
parents:
9534
diff
changeset
|
1499 |
_vd.parent_sprites_to_draw.Clear(); |
93848ae90336
(svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13
parents:
9534
diff
changeset
|
1500 |
_vd.parent_sprites_to_sort.Clear(); |
93848ae90336
(svn r13573) -Codechange: Use smallvec class functions instead of class members
skidd13
parents:
9534
diff
changeset
|
1501 |
_vd.child_screen_sprites_to_draw.Clear(); |
0 | 1502 |
} |
1503 |
||
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
1504 |
/** Make sure we don't draw a too big area at a time. |
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
1505 |
* If we do, the sprite memory will overflow. */ |
5120
1ff65e874ce3
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5045
diff
changeset
|
1506 |
static void ViewportDrawChk(const ViewPort *vp, int left, int top, int right, int bottom) |
0 | 1507 |
{ |
6626
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
1508 |
if (ScaleByZoom(bottom - top, vp->zoom) * ScaleByZoom(right - left, vp->zoom) > 180000) { |
0 | 1509 |
if ((bottom - top) > (right - left)) { |
1510 |
int t = (top + bottom) >> 1; |
|
1511 |
ViewportDrawChk(vp, left, top, right, t); |
|
1512 |
ViewportDrawChk(vp, left, t, right, bottom); |
|
1513 |
} else { |
|
1514 |
int t = (left + right) >> 1; |
|
1515 |
ViewportDrawChk(vp, left, top, t, bottom); |
|
1516 |
ViewportDrawChk(vp, t, top, right, bottom); |
|
1517 |
} |
|
1518 |
} else { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1519 |
ViewportDoDraw(vp, |
6626
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
1520 |
ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left, |
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
1521 |
ScaleByZoom(top - vp->top, vp->zoom) + vp->virtual_top, |
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
1522 |
ScaleByZoom(right - vp->left, vp->zoom) + vp->virtual_left, |
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
1523 |
ScaleByZoom(bottom - vp->top, vp->zoom) + vp->virtual_top |
0 | 1524 |
); |
1525 |
} |
|
1526 |
} |
|
1527 |
||
5120
1ff65e874ce3
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5045
diff
changeset
|
1528 |
static inline void ViewportDraw(const ViewPort *vp, int left, int top, int right, int bottom) |
0 | 1529 |
{ |
2116 | 1530 |
if (right <= vp->left || bottom <= vp->top) return; |
0 | 1531 |
|
2116 | 1532 |
if (left >= vp->left + vp->width) return; |
0 | 1533 |
|
1534 |
if (left < vp->left) left = vp->left; |
|
2116 | 1535 |
if (right > vp->left + vp->width) right = vp->left + vp->width; |
0 | 1536 |
|
2116 | 1537 |
if (top >= vp->top + vp->height) return; |
0 | 1538 |
|
1539 |
if (top < vp->top) top = vp->top; |
|
2116 | 1540 |
if (bottom > vp->top + vp->height) bottom = vp->top + vp->height; |
0 | 1541 |
|
1542 |
ViewportDrawChk(vp, left, top, right, bottom); |
|
1543 |
} |
|
1544 |
||
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9244
diff
changeset
|
1545 |
void Window::DrawViewport() const |
2116 | 1546 |
{ |
0 | 1547 |
DrawPixelInfo *dpi = _cur_dpi; |
1548 |
||
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9244
diff
changeset
|
1549 |
dpi->left += this->left; |
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9244
diff
changeset
|
1550 |
dpi->top += this->top; |
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9244
diff
changeset
|
1551 |
|
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9244
diff
changeset
|
1552 |
ViewportDraw(this->viewport, dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height); |
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9244
diff
changeset
|
1553 |
|
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9244
diff
changeset
|
1554 |
dpi->left -= this->left; |
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9244
diff
changeset
|
1555 |
dpi->top -= this->top; |
0 | 1556 |
} |
1557 |
||
7069
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1558 |
static inline void ClampViewportToMap(const ViewPort *vp, int &x, int &y) |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1559 |
{ |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1560 |
/* Centre of the viewport is hot spot */ |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1561 |
x += vp->virtual_width / 2; |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1562 |
y += vp->virtual_height / 2; |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1563 |
|
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1564 |
/* Convert viewport coordinates to map coordinates |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1565 |
* Calculation is scaled by 4 to avoid rounding errors */ |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1566 |
int vx = -x + y * 2; |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1567 |
int vy = x + y * 2; |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1568 |
|
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1569 |
/* clamp to size of map */ |
7922
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7918
diff
changeset
|
1570 |
vx = Clamp(vx, 0, MapMaxX() * TILE_SIZE * 4); |
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7918
diff
changeset
|
1571 |
vy = Clamp(vy, 0, MapMaxY() * TILE_SIZE * 4); |
7069
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1572 |
|
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1573 |
/* Convert map coordinates to viewport coordinates */ |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1574 |
x = (-vx + vy) / 2; |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1575 |
y = ( vx + vy) / 4; |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1576 |
|
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1577 |
/* Remove centreing */ |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1578 |
x -= vp->virtual_width / 2; |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1579 |
y -= vp->virtual_height / 2; |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1580 |
} |
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1581 |
|
0 | 1582 |
void UpdateViewportPosition(Window *w) |
1583 |
{ |
|
2116 | 1584 |
const ViewPort *vp = w->viewport; |
0 | 1585 |
|
9184 | 1586 |
if (w->viewport->follow_vehicle != INVALID_VEHICLE) { |
1587 |
const Vehicle* veh = GetVehicle(w->viewport->follow_vehicle); |
|
2116 | 1588 |
Point pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos); |
0 | 1589 |
|
1590 |
SetViewportPosition(w, pt.x, pt.y); |
|
1591 |
} else { |
|
7069
c5e067d3e3cc
(svn r10334) -Fix [FS#937]: with smooth scrolling enabled, the viewport destination was not clamped to the map
peter1138
parents:
7056
diff
changeset
|
1592 |
/* Ensure the destination location is within the map */ |
9184 | 1593 |
ClampViewportToMap(vp, w->viewport->dest_scrollpos_x, w->viewport->dest_scrollpos_y); |
1594 |
||
1595 |
int delta_x = w->viewport->dest_scrollpos_x - w->viewport->scrollpos_x; |
|
1596 |
int delta_y = w->viewport->dest_scrollpos_y - w->viewport->scrollpos_y; |
|
6730
9311a208f8f7
(svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents:
6669
diff
changeset
|
1597 |
|
9311a208f8f7
(svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents:
6669
diff
changeset
|
1598 |
if (delta_x != 0 || delta_y != 0) { |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9410
diff
changeset
|
1599 |
if (_settings_client.gui.smooth_scroll) { |
6731
d018207588bb
(svn r9963) -Fix (r9962): 'smooth_scroll' patch setting was ignored (always on) in some places.
peter1138
parents:
6730
diff
changeset
|
1600 |
int max_scroll = ScaleByMapSize1D(512); |
d018207588bb
(svn r9963) -Fix (r9962): 'smooth_scroll' patch setting was ignored (always on) in some places.
peter1138
parents:
6730
diff
changeset
|
1601 |
/* Not at our desired positon yet... */ |
9184 | 1602 |
w->viewport->scrollpos_x += Clamp(delta_x / 4, -max_scroll, max_scroll); |
1603 |
w->viewport->scrollpos_y += Clamp(delta_y / 4, -max_scroll, max_scroll); |
|
6731
d018207588bb
(svn r9963) -Fix (r9962): 'smooth_scroll' patch setting was ignored (always on) in some places.
peter1138
parents:
6730
diff
changeset
|
1604 |
} else { |
9184 | 1605 |
w->viewport->scrollpos_x = w->viewport->dest_scrollpos_x; |
1606 |
w->viewport->scrollpos_y = w->viewport->dest_scrollpos_y; |
|
6731
d018207588bb
(svn r9963) -Fix (r9962): 'smooth_scroll' patch setting was ignored (always on) in some places.
peter1138
parents:
6730
diff
changeset
|
1607 |
} |
6730
9311a208f8f7
(svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents:
6669
diff
changeset
|
1608 |
} |
9311a208f8f7
(svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents:
6669
diff
changeset
|
1609 |
|
9184 | 1610 |
ClampViewportToMap(vp, w->viewport->scrollpos_x, w->viewport->scrollpos_y); |
1611 |
||
1612 |
SetViewportPosition(w, w->viewport->scrollpos_x, w->viewport->scrollpos_y); |
|
0 | 1613 |
} |
1614 |
} |
|
1615 |
||
7545
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7497
diff
changeset
|
1616 |
/** |
8992
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
1617 |
* Marks a viewport as dirty for repaint if it displays (a part of) the area the needs to be repainted. |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
1618 |
* @param vp The viewport to mark as dirty |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
1619 |
* @param left Left edge of area to repaint |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
1620 |
* @param top Top edge of area to repaint |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
1621 |
* @param right Right edge of area to repaint |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
1622 |
* @param bottom Bottom edge of area to repaint |
7545
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7497
diff
changeset
|
1623 |
* @ingroup dirty |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7497
diff
changeset
|
1624 |
*/ |
2116 | 1625 |
static void MarkViewportDirty(const ViewPort *vp, int left, int top, int right, int bottom) |
0 | 1626 |
{ |
2116 | 1627 |
right -= vp->virtual_left; |
1628 |
if (right <= 0) return; |
|
0 | 1629 |
|
2116 | 1630 |
bottom -= vp->virtual_top; |
1631 |
if (bottom <= 0) return; |
|
0 | 1632 |
|
2116 | 1633 |
left = max(0, left - vp->virtual_left); |
0 | 1634 |
|
2116 | 1635 |
if (left >= vp->virtual_width) return; |
0 | 1636 |
|
2116 | 1637 |
top = max(0, top - vp->virtual_top); |
1638 |
||
1639 |
if (top >= vp->virtual_height) return; |
|
0 | 1640 |
|
1641 |
SetDirtyBlocks( |
|
6626
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
1642 |
UnScaleByZoom(left, vp->zoom) + vp->left, |
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
1643 |
UnScaleByZoom(top, vp->zoom) + vp->top, |
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
1644 |
UnScaleByZoom(right, vp->zoom) + vp->left, |
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
1645 |
UnScaleByZoom(bottom, vp->zoom) + vp->top |
0 | 1646 |
); |
1647 |
} |
|
1648 |
||
8992
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
1649 |
/** |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
1650 |
* Mark all viewports that display an area as dirty (in need of repaint). |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
1651 |
* @param left Left edge of area to repaint |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
1652 |
* @param top Top edge of area to repaint |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
1653 |
* @param right Right edge of area to repaint |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
1654 |
* @param bottom Bottom edge of area to repaint |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
1655 |
* @ingroup dirty |
0b2fb43cc875
(svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents:
8979
diff
changeset
|
1656 |
*/ |
0 | 1657 |
void MarkAllViewportsDirty(int left, int top, int right, int bottom) |
1658 |
{ |
|
8957
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
1659 |
Window **wz; |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
1660 |
|
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
1661 |
FOR_ALL_WINDOWS(wz) { |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
1662 |
ViewPort *vp = (*wz)->viewport; |
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
1663 |
if (vp != NULL) { |
0 | 1664 |
assert(vp->width != 0); |
1665 |
MarkViewportDirty(vp, left, top, right, bottom); |
|
1666 |
} |
|
8957
ef3f499ff423
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
rubidium
parents:
8953
diff
changeset
|
1667 |
} |
0 | 1668 |
} |
1669 |
||
2116 | 1670 |
void MarkTileDirtyByTile(TileIndex tile) |
1671 |
{ |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1672 |
Point pt = RemapCoords(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, GetTileZ(tile)); |
0 | 1673 |
MarkAllViewportsDirty( |
1674 |
pt.x - 31, |
|
1675 |
pt.y - 122, |
|
1676 |
pt.x - 31 + 67, |
|
1677 |
pt.y - 122 + 154 |
|
1678 |
); |
|
1679 |
} |
|
1680 |
||
1681 |
void MarkTileDirty(int x, int y) |
|
1682 |
{ |
|
2116 | 1683 |
uint z = 0; |
0 | 1684 |
Point pt; |
2116 | 1685 |
|
7954
57b51c69c072
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
7951
diff
changeset
|
1686 |
if (IsInsideMM(x, 0, MapSizeX() * TILE_SIZE) && |
57b51c69c072
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
7951
diff
changeset
|
1687 |
IsInsideMM(y, 0, MapSizeY() * TILE_SIZE)) |
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1688 |
z = GetTileZ(TileVirtXY(x, y)); |
0 | 1689 |
pt = RemapCoords(x, y, z); |
1690 |
||
1691 |
MarkAllViewportsDirty( |
|
1692 |
pt.x - 31, |
|
1693 |
pt.y - 122, |
|
1694 |
pt.x - 31 + 67, |
|
1695 |
pt.y - 122 + 154 |
|
1696 |
); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
1697 |
} |
0 | 1698 |
|
7545
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7497
diff
changeset
|
1699 |
/** |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7497
diff
changeset
|
1700 |
* Marks the selected tiles as dirty. |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7497
diff
changeset
|
1701 |
* |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7497
diff
changeset
|
1702 |
* This function marks the selected tiles as dirty for repaint |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7497
diff
changeset
|
1703 |
* |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7497
diff
changeset
|
1704 |
* @note Documentation may be wrong (Progman) |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7497
diff
changeset
|
1705 |
* @ingroup dirty |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7497
diff
changeset
|
1706 |
*/ |
6247 | 1707 |
static void SetSelectionTilesDirty() |
0 | 1708 |
{ |
1709 |
int y_size, x_size; |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1710 |
int x = _thd.pos.x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1711 |
int y = _thd.pos.y; |
0 | 1712 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1713 |
x_size = _thd.size.x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1714 |
y_size = _thd.size.y; |
0 | 1715 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1716 |
if (_thd.outersize.x) { |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1717 |
x_size += _thd.outersize.x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1718 |
x += _thd.offs.x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1719 |
y_size += _thd.outersize.y; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
1720 |
y += _thd.offs.y; |
0 | 1721 |
} |
1722 |
||
1723 |
assert(x_size > 0); |
|
1724 |
assert(y_size > 0); |
|
1725 |
||
1726 |
x_size += x; |
|
1727 |
y_size += y; |
|
1728 |
||
1729 |
do { |
|
1730 |
int y_bk = y; |
|
1731 |
do { |
|
1732 |
MarkTileDirty(x, y); |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1733 |
} while ( (y += TILE_SIZE) != y_size); |
0 | 1734 |
y = y_bk; |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
1735 |
} while ( (x += TILE_SIZE) != x_size); |
0 | 1736 |
} |
1737 |
||
1738 |
||
1990
efb67f977138
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1739 |
void SetSelectionRed(bool b) |
efb67f977138
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1740 |
{ |
efb67f977138
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1741 |
_thd.make_square_red = b; |
efb67f977138
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1742 |
SetSelectionTilesDirty(); |
efb67f977138
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1743 |
} |
efb67f977138
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1744 |
|
efb67f977138
(svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents:
1980
diff
changeset
|
1745 |
|
2116 | 1746 |
static bool CheckClickOnTown(const ViewPort *vp, int x, int y) |
0 | 1747 |
{ |
2116 | 1748 |
const Town *t; |
0 | 1749 |
|
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
1750 |
if (!HasBit(_display_opt, DO_SHOW_TOWN_NAMES)) return false; |
0 | 1751 |
|
4471 | 1752 |
switch (vp->zoom) { |
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1753 |
case ZOOM_LVL_NORMAL: |
4471 | 1754 |
x = x - vp->left + vp->virtual_left; |
1755 |
y = y - vp->top + vp->virtual_top; |
|
1756 |
FOR_ALL_TOWNS(t) { |
|
1757 |
if (y >= t->sign.top && |
|
1758 |
y < t->sign.top + 12 && |
|
1759 |
x >= t->sign.left && |
|
1760 |
x < t->sign.left + t->sign.width_1) { |
|
1761 |
ShowTownViewWindow(t->index); |
|
1762 |
return true; |
|
1763 |
} |
|
0 | 1764 |
} |
4471 | 1765 |
break; |
1766 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1767 |
case ZOOM_LVL_OUT_2X: |
4471 | 1768 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
1769 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
|
1770 |
FOR_ALL_TOWNS(t) { |
|
1771 |
if (y >= t->sign.top && |
|
1772 |
y < t->sign.top + 24 && |
|
1773 |
x >= t->sign.left && |
|
1774 |
x < t->sign.left + t->sign.width_1 * 2) { |
|
1775 |
ShowTownViewWindow(t->index); |
|
1776 |
return true; |
|
1777 |
} |
|
0 | 1778 |
} |
4471 | 1779 |
break; |
1780 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1781 |
case ZOOM_LVL_OUT_4X: |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1782 |
case ZOOM_LVL_OUT_8X: |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1783 |
x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left; |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1784 |
y = ScaleByZoom(y - vp->top + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top; |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1785 |
|
4471 | 1786 |
FOR_ALL_TOWNS(t) { |
1787 |
if (y >= t->sign.top && |
|
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1788 |
y < t->sign.top + ScaleByZoom(12, vp->zoom) && |
4471 | 1789 |
x >= t->sign.left && |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1790 |
x < t->sign.left + ScaleByZoom(t->sign.width_2, vp->zoom)) { |
4471 | 1791 |
ShowTownViewWindow(t->index); |
1792 |
return true; |
|
1793 |
} |
|
0 | 1794 |
} |
4471 | 1795 |
break; |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1796 |
|
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1797 |
default: NOT_REACHED(); |
0 | 1798 |
} |
1799 |
||
1800 |
return false; |
|
1801 |
} |
|
1802 |
||
4471 | 1803 |
|
2116 | 1804 |
static bool CheckClickOnStation(const ViewPort *vp, int x, int y) |
0 | 1805 |
{ |
2116 | 1806 |
const Station *st; |
0 | 1807 |
|
9755
da0c1b33c727
(svn r13891) -Fix (r12547): one could click on waypoint and station signs even when they were invisible
smatz
parents:
9555
diff
changeset
|
1808 |
if (!HasBit(_display_opt, DO_SHOW_STATION_NAMES) || IsInvisibilitySet(TO_SIGNS)) return false; |
0 | 1809 |
|
4471 | 1810 |
switch (vp->zoom) { |
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1811 |
case ZOOM_LVL_NORMAL: |
4471 | 1812 |
x = x - vp->left + vp->virtual_left; |
1813 |
y = y - vp->top + vp->virtual_top; |
|
1814 |
FOR_ALL_STATIONS(st) { |
|
1815 |
if (y >= st->sign.top && |
|
1816 |
y < st->sign.top + 12 && |
|
1817 |
x >= st->sign.left && |
|
1818 |
x < st->sign.left + st->sign.width_1) { |
|
1819 |
ShowStationViewWindow(st->index); |
|
1820 |
return true; |
|
1821 |
} |
|
0 | 1822 |
} |
4471 | 1823 |
break; |
1824 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1825 |
case ZOOM_LVL_OUT_2X: |
4471 | 1826 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
1827 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
|
1828 |
FOR_ALL_STATIONS(st) { |
|
1829 |
if (y >= st->sign.top && |
|
1830 |
y < st->sign.top + 24 && |
|
1831 |
x >= st->sign.left && |
|
1832 |
x < st->sign.left + st->sign.width_1 * 2) { |
|
1833 |
ShowStationViewWindow(st->index); |
|
1834 |
return true; |
|
1835 |
} |
|
0 | 1836 |
} |
4471 | 1837 |
break; |
1838 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1839 |
case ZOOM_LVL_OUT_4X: |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1840 |
case ZOOM_LVL_OUT_8X: |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1841 |
x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left; |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1842 |
y = ScaleByZoom(y - vp->top + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top; |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1843 |
|
4471 | 1844 |
FOR_ALL_STATIONS(st) { |
1845 |
if (y >= st->sign.top && |
|
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1846 |
y < st->sign.top + ScaleByZoom(12, vp->zoom) && |
4471 | 1847 |
x >= st->sign.left && |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1848 |
x < st->sign.left + ScaleByZoom(st->sign.width_2, vp->zoom)) { |
4471 | 1849 |
ShowStationViewWindow(st->index); |
1850 |
return true; |
|
1851 |
} |
|
0 | 1852 |
} |
4471 | 1853 |
break; |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1854 |
|
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1855 |
default: NOT_REACHED(); |
0 | 1856 |
} |
1857 |
||
1858 |
return false; |
|
1859 |
} |
|
1860 |
||
4471 | 1861 |
|
2116 | 1862 |
static bool CheckClickOnSign(const ViewPort *vp, int x, int y) |
0 | 1863 |
{ |
4349
1016170ae0cb
(svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents:
4346
diff
changeset
|
1864 |
const Sign *si; |
0 | 1865 |
|
8806
4fe163e0b52a
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents:
8798
diff
changeset
|
1866 |
/* Signs are turned off, or they are transparent and invisibility is ON, or player is a spectator */ |
4fe163e0b52a
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents:
8798
diff
changeset
|
1867 |
if (!HasBit(_display_opt, DO_SHOW_SIGNS) || IsInvisibilitySet(TO_SIGNS) || _current_player == PLAYER_SPECTATOR) return false; |
0 | 1868 |
|
4471 | 1869 |
switch (vp->zoom) { |
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1870 |
case ZOOM_LVL_NORMAL: |
4471 | 1871 |
x = x - vp->left + vp->virtual_left; |
1872 |
y = y - vp->top + vp->virtual_top; |
|
1873 |
FOR_ALL_SIGNS(si) { |
|
1874 |
if (y >= si->sign.top && |
|
1875 |
y < si->sign.top + 12 && |
|
1876 |
x >= si->sign.left && |
|
1877 |
x < si->sign.left + si->sign.width_1) { |
|
9510
5ca327a7ce93
(svn r13501) -Feature(tte): ctrl+click on sign you own to remove it (Osai, planetmaker)
smatz
parents:
9413
diff
changeset
|
1878 |
HandleClickOnSign(si); |
4471 | 1879 |
return true; |
1880 |
} |
|
0 | 1881 |
} |
4471 | 1882 |
break; |
1883 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1884 |
case ZOOM_LVL_OUT_2X: |
4471 | 1885 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
1886 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
|
1887 |
FOR_ALL_SIGNS(si) { |
|
1888 |
if (y >= si->sign.top && |
|
1889 |
y < si->sign.top + 24 && |
|
1890 |
x >= si->sign.left && |
|
1891 |
x < si->sign.left + si->sign.width_1 * 2) { |
|
9510
5ca327a7ce93
(svn r13501) -Feature(tte): ctrl+click on sign you own to remove it (Osai, planetmaker)
smatz
parents:
9413
diff
changeset
|
1892 |
HandleClickOnSign(si); |
4471 | 1893 |
return true; |
1894 |
} |
|
0 | 1895 |
} |
4471 | 1896 |
break; |
1897 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1898 |
case ZOOM_LVL_OUT_4X: |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1899 |
case ZOOM_LVL_OUT_8X: |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1900 |
x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left; |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1901 |
y = ScaleByZoom(y - vp->top + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top; |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1902 |
|
4471 | 1903 |
FOR_ALL_SIGNS(si) { |
1904 |
if (y >= si->sign.top && |
|
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1905 |
y < si->sign.top + ScaleByZoom(12, vp->zoom) && |
4471 | 1906 |
x >= si->sign.left && |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1907 |
x < si->sign.left + ScaleByZoom(si->sign.width_2, vp->zoom)) { |
9510
5ca327a7ce93
(svn r13501) -Feature(tte): ctrl+click on sign you own to remove it (Osai, planetmaker)
smatz
parents:
9413
diff
changeset
|
1908 |
HandleClickOnSign(si); |
4471 | 1909 |
return true; |
1910 |
} |
|
0 | 1911 |
} |
4471 | 1912 |
break; |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1913 |
|
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1914 |
default: NOT_REACHED(); |
0 | 1915 |
} |
1916 |
||
1917 |
return false; |
|
1918 |
} |
|
1919 |
||
4471 | 1920 |
|
2116 | 1921 |
static bool CheckClickOnWaypoint(const ViewPort *vp, int x, int y) |
0 | 1922 |
{ |
2116 | 1923 |
const Waypoint *wp; |
0 | 1924 |
|
9755
da0c1b33c727
(svn r13891) -Fix (r12547): one could click on waypoint and station signs even when they were invisible
smatz
parents:
9555
diff
changeset
|
1925 |
if (!HasBit(_display_opt, DO_WAYPOINTS) || IsInvisibilitySet(TO_SIGNS)) return false; |
0 | 1926 |
|
4471 | 1927 |
switch (vp->zoom) { |
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1928 |
case ZOOM_LVL_NORMAL: |
4471 | 1929 |
x = x - vp->left + vp->virtual_left; |
1930 |
y = y - vp->top + vp->virtual_top; |
|
1931 |
FOR_ALL_WAYPOINTS(wp) { |
|
1932 |
if (y >= wp->sign.top && |
|
1933 |
y < wp->sign.top + 12 && |
|
1934 |
x >= wp->sign.left && |
|
1935 |
x < wp->sign.left + wp->sign.width_1) { |
|
1936 |
ShowRenameWaypointWindow(wp); |
|
1937 |
return true; |
|
1938 |
} |
|
0 | 1939 |
} |
4471 | 1940 |
break; |
1941 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1942 |
case ZOOM_LVL_OUT_2X: |
4471 | 1943 |
x = (x - vp->left + 1) * 2 + vp->virtual_left; |
1944 |
y = (y - vp->top + 1) * 2 + vp->virtual_top; |
|
1945 |
FOR_ALL_WAYPOINTS(wp) { |
|
1946 |
if (y >= wp->sign.top && |
|
1947 |
y < wp->sign.top + 24 && |
|
1948 |
x >= wp->sign.left && |
|
1949 |
x < wp->sign.left + wp->sign.width_1 * 2) { |
|
1950 |
ShowRenameWaypointWindow(wp); |
|
1951 |
return true; |
|
1952 |
} |
|
0 | 1953 |
} |
4471 | 1954 |
break; |
1955 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6591
diff
changeset
|
1956 |
case ZOOM_LVL_OUT_4X: |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1957 |
case ZOOM_LVL_OUT_8X: |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1958 |
x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left; |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1959 |
y = ScaleByZoom(y - vp->top + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top; |
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1960 |
|
4471 | 1961 |
FOR_ALL_WAYPOINTS(wp) { |
1962 |
if (y >= wp->sign.top && |
|
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1963 |
y < wp->sign.top + ScaleByZoom(12, vp->zoom) && |
4471 | 1964 |
x >= wp->sign.left && |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1965 |
x < wp->sign.left + ScaleByZoom(wp->sign.width_2, vp->zoom)) { |
4471 | 1966 |
ShowRenameWaypointWindow(wp); |
1967 |
return true; |
|
1968 |
} |
|
0 | 1969 |
} |
4471 | 1970 |
break; |
6653
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1971 |
|
b20fcfed0847
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
6626
diff
changeset
|
1972 |
default: NOT_REACHED(); |
0 | 1973 |
} |
1974 |
||
1975 |
return false; |
|
1976 |
} |
|
1977 |
||
1978 |
||
2116 | 1979 |
static void CheckClickOnLandscape(const ViewPort *vp, int x, int y) |
0 | 1980 |
{ |
2116 | 1981 |
Point pt = TranslateXYToTileCoord(vp, x, y); |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1964
diff
changeset
|
1982 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1983 |
if (pt.x != -1) ClickTile(TileVirtXY(pt.x, pt.y)); |
0 | 1984 |
} |
1985 |
||
2662
8b46824bd821
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1986 |
|
8b46824bd821
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1987 |
static void SafeShowTrainViewWindow(const Vehicle* v) |
8b46824bd821
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1988 |
{ |
7497
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7486
diff
changeset
|
1989 |
if (!IsFrontEngine(v)) v = v->First(); |
7486
bf6a94009823
(svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents:
7333
diff
changeset
|
1990 |
ShowVehicleViewWindow(v); |
2662
8b46824bd821
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1991 |
} |
8b46824bd821
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
1992 |
|
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6853
diff
changeset
|
1993 |
static void SafeShowRoadVehViewWindow(const Vehicle *v) |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6853
diff
changeset
|
1994 |
{ |
7497
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7486
diff
changeset
|
1995 |
if (!IsRoadVehFront(v)) v = v->First(); |
7486
bf6a94009823
(svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents:
7333
diff
changeset
|
1996 |
ShowVehicleViewWindow(v); |
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6853
diff
changeset
|
1997 |
} |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6853
diff
changeset
|
1998 |
|
4171 | 1999 |
static void Nop(const Vehicle *v) {} |
2662
8b46824bd821
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
2000 |
|
4171 | 2001 |
typedef void OnVehicleClickProc(const Vehicle *v); |
2662
8b46824bd821
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
2002 |
static OnVehicleClickProc* const _on_vehicle_click_proc[] = { |
8b46824bd821
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
2003 |
SafeShowTrainViewWindow, |
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6853
diff
changeset
|
2004 |
SafeShowRoadVehViewWindow, |
7486
bf6a94009823
(svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents:
7333
diff
changeset
|
2005 |
ShowVehicleViewWindow, |
bf6a94009823
(svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents:
7333
diff
changeset
|
2006 |
ShowVehicleViewWindow, |
2662
8b46824bd821
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
2007 |
Nop, // Special vehicles |
8b46824bd821
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents:
2484
diff
changeset
|
2008 |
Nop // Disaster vehicles |
0 | 2009 |
}; |
2010 |
||
2116 | 2011 |
void HandleViewportClicked(const ViewPort *vp, int x, int y) |
0 | 2012 |
{ |
4171 | 2013 |
const Vehicle *v; |
0 | 2014 |
|
2116 | 2015 |
if (CheckClickOnTown(vp, x, y)) return; |
2016 |
if (CheckClickOnStation(vp, x, y)) return; |
|
2017 |
if (CheckClickOnSign(vp, x, y)) return; |
|
2018 |
if (CheckClickOnWaypoint(vp, x, y)) return; |
|
0 | 2019 |
CheckClickOnLandscape(vp, x, y); |
2020 |
||
2116 | 2021 |
v = CheckClickOnVehicle(vp, x, y); |
3809
d67cd0232924
(svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents:
3798
diff
changeset
|
2022 |
if (v != NULL) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5137
diff
changeset
|
2023 |
DEBUG(misc, 2, "Vehicle %d (index %d) at %p", v->unitnumber, v->index, v); |
5955
fe61588d5188
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
5893
diff
changeset
|
2024 |
_on_vehicle_click_proc[v->type](v); |
3809
d67cd0232924
(svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents:
3798
diff
changeset
|
2025 |
} |
0 | 2026 |
} |
2027 |
||
6247 | 2028 |
Vehicle *CheckMouseOverVehicle() |
0 | 2029 |
{ |
4171 | 2030 |
const Window *w; |
2031 |
const ViewPort *vp; |
|
0 | 2032 |
|
2033 |
int x = _cursor.pos.x; |
|
2034 |
int y = _cursor.pos.y; |
|
2035 |
||
2036 |
w = FindWindowFromPt(x, y); |
|
2116 | 2037 |
if (w == NULL) return NULL; |
0 | 2038 |
|
2039 |
vp = IsPtInWindowViewport(w, x, y); |
|
2116 | 2040 |
return (vp != NULL) ? CheckClickOnVehicle(vp, x, y) : NULL; |
0 | 2041 |
} |
2042 |
||
2043 |
||
2044 |
||
6247 | 2045 |
void PlaceObject() |
0 | 2046 |
{ |
2047 |
Point pt; |
|
2048 |
Window *w; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2049 |
|
0 | 2050 |
pt = GetTileBelowCursor(); |
2116 | 2051 |
if (pt.x == -1) return; |
0 | 2052 |
|
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2053 |
if (_thd.place_mode == VHM_POINT) { |
0 | 2054 |
pt.x += 8; |
2055 |
pt.y += 8; |
|
2056 |
} |
|
2057 |
||
2058 |
_tile_fract_coords.x = pt.x & 0xF; |
|
2059 |
_tile_fract_coords.y = pt.y & 0xF; |
|
2060 |
||
2116 | 2061 |
w = GetCallbackWnd(); |
9166
dce886fc5eeb
(svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents:
9147
diff
changeset
|
2062 |
if (w != NULL) w->OnPlaceObject(pt, TileVirtXY(pt.x, pt.y)); |
0 | 2063 |
} |
2064 |
||
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
|
2065 |
|
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
|
2066 |
/* scrolls the viewport in a window to a given location */ |
6730
9311a208f8f7
(svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents:
6669
diff
changeset
|
2067 |
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
|
2068 |
{ |
8473
c8613732cd3b
(svn r12044) -Fix [FS#1741]: crash when centering on a vehicle (aircraft) that is outside of the map.
rubidium
parents:
8413
diff
changeset
|
2069 |
/* The slope cannot be acquired outside of the map, so make sure we are always within the map. */ |
c8613732cd3b
(svn r12044) -Fix [FS#1741]: crash when centering on a vehicle (aircraft) that is outside of the map.
rubidium
parents:
8413
diff
changeset
|
2070 |
Point pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(Clamp(x, 0, MapSizeX()), Clamp(y, 0, MapSizeY()))); |
9184 | 2071 |
w->viewport->follow_vehicle = INVALID_VEHICLE; |
2072 |
||
2073 |
if (w->viewport->dest_scrollpos_x == pt.x && w->viewport->dest_scrollpos_y == pt.y) |
|
2116 | 2074 |
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
|
2075 |
|
6731
d018207588bb
(svn r9963) -Fix (r9962): 'smooth_scroll' patch setting was ignored (always on) in some places.
peter1138
parents:
6730
diff
changeset
|
2076 |
if (instant) { |
9184 | 2077 |
w->viewport->scrollpos_x = pt.x; |
2078 |
w->viewport->scrollpos_y = pt.y; |
|
6730
9311a208f8f7
(svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents:
6669
diff
changeset
|
2079 |
} |
9311a208f8f7
(svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents:
6669
diff
changeset
|
2080 |
|
9184 | 2081 |
w->viewport->dest_scrollpos_x = pt.x; |
2082 |
w->viewport->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
|
2083 |
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
|
2084 |
} |
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
|
2085 |
|
6730
9311a208f8f7
(svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents:
6669
diff
changeset
|
2086 |
bool ScrollMainWindowToTile(TileIndex tile, bool instant) |
0 | 2087 |
{ |
6730
9311a208f8f7
(svn r9962) -Feature: Add smooth viewport scrolling. This must be enabled with patch setting 'smooth_scroll'
peter1138
parents:
6669
diff
changeset
|
2088 |
return ScrollMainWindowTo(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, instant); |
0 | 2089 |
} |
2090 |
||
2091 |
void SetRedErrorSquare(TileIndex tile) |
|
2092 |
{ |
|
2093 |
TileIndex old; |
|
2094 |
||
2095 |
old = _thd.redsq; |
|
2096 |
_thd.redsq = tile; |
|
2097 |
||
2098 |
if (tile != old) { |
|
3281
757d7da49445
(svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents:
3279
diff
changeset
|
2099 |
if (tile != 0) MarkTileDirtyByTile(tile); |
757d7da49445
(svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents:
3279
diff
changeset
|
2100 |
if (old != 0) MarkTileDirtyByTile(old); |
0 | 2101 |
} |
2102 |
} |
|
2103 |
||
2104 |
void SetTileSelectSize(int w, int h) |
|
2105 |
{ |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2106 |
_thd.new_size.x = w * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2107 |
_thd.new_size.y = h * TILE_SIZE; |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2108 |
_thd.new_outersize.x = 0; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2109 |
_thd.new_outersize.y = 0; |
0 | 2110 |
} |
2111 |
||
2116 | 2112 |
void SetTileSelectBigSize(int ox, int oy, int sx, int sy) |
2113 |
{ |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2114 |
_thd.offs.x = ox * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2115 |
_thd.offs.y = oy * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2116 |
_thd.new_outersize.x = sx * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2117 |
_thd.new_outersize.y = sy * TILE_SIZE; |
0 | 2118 |
} |
2119 |
||
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
2120 |
/** returns the best autorail highlight type from map coordinates */ |
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2121 |
static HighLightStyle GetAutorailHT(int x, int y) |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2122 |
{ |
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2123 |
return HT_RAIL | _autorail_piece[x & 0xF][y & 0xF]; |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2124 |
} |
0 | 2125 |
|
7078
521bc677ce92
(svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents:
7069
diff
changeset
|
2126 |
/** |
521bc677ce92
(svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents:
7069
diff
changeset
|
2127 |
* Updates tile highlighting for all cases. |
521bc677ce92
(svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents:
7069
diff
changeset
|
2128 |
* Uses _thd.selstart and _thd.selend and _thd.place_mode (set elsewhere) to determine _thd.pos and _thd.size |
521bc677ce92
(svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents:
7069
diff
changeset
|
2129 |
* Also drawstyle is determined. Uses _thd.new.* as a buffer and calls SetSelectionTilesDirty() twice, |
521bc677ce92
(svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents:
7069
diff
changeset
|
2130 |
* Once for the old and once for the new selection. |
521bc677ce92
(svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents:
7069
diff
changeset
|
2131 |
* _thd is TileHighlightData, found in viewport.h |
521bc677ce92
(svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents:
7069
diff
changeset
|
2132 |
* Called by MouseLoop() in windows.cpp |
521bc677ce92
(svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents:
7069
diff
changeset
|
2133 |
*/ |
6247 | 2134 |
void UpdateTileSelection() |
0 | 2135 |
{ |
2116 | 2136 |
int x1; |
2137 |
int y1; |
|
0 | 2138 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2139 |
_thd.new_drawstyle = 0; |
0 | 2140 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2141 |
if (_thd.place_mode == VHM_SPECIAL) { |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2142 |
x1 = _thd.selend.x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2143 |
y1 = _thd.selend.y; |
0 | 2144 |
if (x1 != -1) { |
7912
49d1b8b4557c
(svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz
parents:
7905
diff
changeset
|
2145 |
int x2 = _thd.selstart.x & ~0xF; |
49d1b8b4557c
(svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz
parents:
7905
diff
changeset
|
2146 |
int y2 = _thd.selstart.y & ~0xF; |
0 | 2147 |
x1 &= ~0xF; |
2148 |
y1 &= ~0xF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2149 |
|
6106 | 2150 |
if (x1 >= x2) Swap(x1, x2); |
2151 |
if (y1 >= y2) Swap(y1, y2); |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2152 |
_thd.new_pos.x = x1; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2153 |
_thd.new_pos.y = y1; |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2154 |
_thd.new_size.x = x2 - x1 + TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2155 |
_thd.new_size.y = y2 - y1 + TILE_SIZE; |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2156 |
_thd.new_drawstyle = _thd.next_drawstyle; |
0 | 2157 |
} |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2158 |
} else if (_thd.place_mode != VHM_NONE) { |
2116 | 2159 |
Point pt = GetTileBelowCursor(); |
0 | 2160 |
x1 = pt.x; |
2161 |
y1 = pt.y; |
|
2162 |
if (x1 != -1) { |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2163 |
switch (_thd.place_mode) { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2164 |
case VHM_RECT: |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2165 |
_thd.new_drawstyle = HT_RECT; |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2166 |
break; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2167 |
case VHM_POINT: |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2168 |
_thd.new_drawstyle = HT_POINT; |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2169 |
x1 += 8; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2170 |
y1 += 8; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2171 |
break; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2172 |
case VHM_RAIL: |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2173 |
_thd.new_drawstyle = GetAutorailHT(pt.x, pt.y); // draw one highlighted tile |
7918
970e7c5005e5
(svn r11471) -Codechange: one more variable retyped to enum ViewportHighlightMode
smatz
parents:
7912
diff
changeset
|
2174 |
break; |
970e7c5005e5
(svn r11471) -Codechange: one more variable retyped to enum ViewportHighlightMode
smatz
parents:
7912
diff
changeset
|
2175 |
default: |
970e7c5005e5
(svn r11471) -Codechange: one more variable retyped to enum ViewportHighlightMode
smatz
parents:
7912
diff
changeset
|
2176 |
NOT_REACHED(); |
970e7c5005e5
(svn r11471) -Codechange: one more variable retyped to enum ViewportHighlightMode
smatz
parents:
7912
diff
changeset
|
2177 |
break; |
0 | 2178 |
} |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2179 |
_thd.new_pos.x = x1 & ~0xF; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2180 |
_thd.new_pos.y = y1 & ~0xF; |
0 | 2181 |
} |
2182 |
} |
|
2183 |
||
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
2184 |
/* redraw selection */ |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2185 |
if (_thd.drawstyle != _thd.new_drawstyle || |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2186 |
_thd.pos.x != _thd.new_pos.x || _thd.pos.y != _thd.new_pos.y || |
4539
0004dc6c3777
(svn r6368) -Fix [FS#136]: Station catchment area persists after switching tools. The
Darkvater
parents:
4523
diff
changeset
|
2187 |
_thd.size.x != _thd.new_size.x || _thd.size.y != _thd.new_size.y || |
7078
521bc677ce92
(svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents:
7069
diff
changeset
|
2188 |
_thd.outersize.x != _thd.new_outersize.x || |
521bc677ce92
(svn r10343) -Cleanup: Add documentation of functions and code-style fix.
belugas
parents:
7069
diff
changeset
|
2189 |
_thd.outersize.y != _thd.new_outersize.y) { |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
2190 |
/* clear the old selection? */ |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2191 |
if (_thd.drawstyle) SetSelectionTilesDirty(); |
0 | 2192 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2193 |
_thd.drawstyle = _thd.new_drawstyle; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2194 |
_thd.pos = _thd.new_pos; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2195 |
_thd.size = _thd.new_size; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2196 |
_thd.outersize = _thd.new_outersize; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2197 |
_thd.dirty = 0xff; |
0 | 2198 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
2199 |
/* draw the new selection? */ |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2200 |
if (_thd.new_drawstyle) SetSelectionTilesDirty(); |
0 | 2201 |
} |
2202 |
} |
|
2203 |
||
9781
31e0e461d7bf
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch
parents:
9755
diff
changeset
|
2204 |
/** Displays the measurement tooltips when selecting multiple tiles |
31e0e461d7bf
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch
parents:
9755
diff
changeset
|
2205 |
* @param str String to be displayed |
31e0e461d7bf
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch
parents:
9755
diff
changeset
|
2206 |
* @param paramcount number of params to deal with |
31e0e461d7bf
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch
parents:
9755
diff
changeset
|
2207 |
* @param params (optional) up to 5 pieces of additional information that may be added to a tooltip |
31e0e461d7bf
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch
parents:
9755
diff
changeset
|
2208 |
*/ |
31e0e461d7bf
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch
parents:
9755
diff
changeset
|
2209 |
static inline void ShowMeasurementTooltips(StringID str, uint paramcount, const uint64 params[]) |
31e0e461d7bf
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch
parents:
9755
diff
changeset
|
2210 |
{ |
31e0e461d7bf
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch
parents:
9755
diff
changeset
|
2211 |
if (!_settings_client.gui.measure_tooltip) return; |
31e0e461d7bf
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch
parents:
9755
diff
changeset
|
2212 |
GuiShowTooltips(str, paramcount, params, true); |
31e0e461d7bf
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch
parents:
9755
diff
changeset
|
2213 |
} |
31e0e461d7bf
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch
parents:
9755
diff
changeset
|
2214 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
2215 |
/** highlighting tiles while only going over them with the mouse */ |
9147
d9ec5ed630ff
(svn r13009) -Codechange: move more tile highlighting related functions/types to tilehighlight_*.h.
rubidium
parents:
9127
diff
changeset
|
2216 |
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process) |
0 | 2217 |
{ |
6669
bb48a810a509
(svn r9900) -Codechange: Separate the variables for how to highlight a land area and what to do with it afterwards.
maedhros
parents:
6654
diff
changeset
|
2218 |
_thd.select_method = method; |
bb48a810a509
(svn r9900) -Codechange: Separate the variables for how to highlight a land area and what to do with it afterwards.
maedhros
parents:
6654
diff
changeset
|
2219 |
_thd.select_proc = process; |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2220 |
_thd.selend.x = TileX(tile) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2221 |
_thd.selstart.x = TileX(tile) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2222 |
_thd.selend.y = TileY(tile) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2223 |
_thd.selstart.y = TileY(tile) * TILE_SIZE; |
7912
49d1b8b4557c
(svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz
parents:
7905
diff
changeset
|
2224 |
|
49d1b8b4557c
(svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz
parents:
7905
diff
changeset
|
2225 |
/* Needed so several things (road, autoroad, bridges, ...) are placed correctly. |
49d1b8b4557c
(svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz
parents:
7905
diff
changeset
|
2226 |
* In effect, placement starts from the centre of a tile |
49d1b8b4557c
(svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz
parents:
7905
diff
changeset
|
2227 |
*/ |
49d1b8b4557c
(svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz
parents:
7905
diff
changeset
|
2228 |
if (method == VPM_X_OR_Y || method == VPM_FIX_X || method == VPM_FIX_Y) { |
49d1b8b4557c
(svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz
parents:
7905
diff
changeset
|
2229 |
_thd.selend.x += TILE_SIZE / 2; |
49d1b8b4557c
(svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz
parents:
7905
diff
changeset
|
2230 |
_thd.selend.y += TILE_SIZE / 2; |
49d1b8b4557c
(svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz
parents:
7905
diff
changeset
|
2231 |
_thd.selstart.x += TILE_SIZE / 2; |
49d1b8b4557c
(svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz
parents:
7905
diff
changeset
|
2232 |
_thd.selstart.y += TILE_SIZE / 2; |
49d1b8b4557c
(svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz
parents:
7905
diff
changeset
|
2233 |
} |
49d1b8b4557c
(svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz
parents:
7905
diff
changeset
|
2234 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2235 |
if (_thd.place_mode == VHM_RECT) { |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2236 |
_thd.place_mode = VHM_SPECIAL; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2237 |
_thd.next_drawstyle = HT_RECT; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2238 |
} else if (_thd.place_mode == VHM_RAIL) { // autorail one piece |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2239 |
_thd.place_mode = VHM_SPECIAL; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2240 |
_thd.next_drawstyle = _thd.drawstyle; |
0 | 2241 |
} else { |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2242 |
_thd.place_mode = VHM_SPECIAL; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2243 |
_thd.next_drawstyle = HT_POINT; |
0 | 2244 |
} |
2245 |
_special_mouse_mode = WSM_SIZING; |
|
2246 |
} |
|
2247 |
||
2248 |
void VpSetPlaceSizingLimit(int limit) |
|
2249 |
{ |
|
2250 |
_thd.sizelimit = limit; |
|
2251 |
} |
|
2252 |
||
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2253 |
/** |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2254 |
* Highlights all tiles between a set of two tiles. Used in dock and tunnel placement |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2255 |
* @param from TileIndex of the first tile to highlight |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2256 |
* @param to TileIndex of the last tile to highlight */ |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2257 |
void VpSetPresizeRange(TileIndex from, TileIndex to) |
0 | 2258 |
{ |
7006
bfa3974da32b
(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:
6937
diff
changeset
|
2259 |
uint64 distance = DistanceManhattan(from, to) + 1; |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2260 |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2261 |
_thd.selend.x = TileX(to) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2262 |
_thd.selend.y = TileY(to) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2263 |
_thd.selstart.x = TileX(from) * TILE_SIZE; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3281
diff
changeset
|
2264 |
_thd.selstart.y = TileY(from) * TILE_SIZE; |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2265 |
_thd.next_drawstyle = HT_RECT; |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2266 |
|
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2267 |
/* show measurement only if there is any length to speak of */ |
9781
31e0e461d7bf
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch
parents:
9755
diff
changeset
|
2268 |
if (distance > 1) ShowMeasurementTooltips(STR_MEASURE_LENGTH, 1, &distance); |
0 | 2269 |
} |
2270 |
||
6247 | 2271 |
static void VpStartPreSizing() |
0 | 2272 |
{ |
2273 |
_thd.selend.x = -1; |
|
2274 |
_special_mouse_mode = WSM_PRESIZE; |
|
2275 |
} |
|
2276 |
||
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
2277 |
/** returns information about the 2x1 piece to be build. |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2278 |
* The lower bits (0-3) are the track type. */ |
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2279 |
static HighLightStyle Check2x1AutoRail(int mode) |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2280 |
{ |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2281 |
int fxpy = _tile_fract_coords.x + _tile_fract_coords.y; |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2282 |
int sxpy = (_thd.selend.x & 0xF) + (_thd.selend.y & 0xF); |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2283 |
int fxmy = _tile_fract_coords.x - _tile_fract_coords.y; |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2284 |
int sxmy = (_thd.selend.x & 0xF) - (_thd.selend.y & 0xF); |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2285 |
|
2952 | 2286 |
switch (mode) { |
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2287 |
default: NOT_REACHED(); |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2288 |
case 0: // end piece is lower right |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2289 |
if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return HT_DIR_HL; } |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2290 |
if (fxmy < -3 && sxmy > 3) {/* DoRailroadTrack(0); */return HT_DIR_VR; } |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2291 |
return HT_DIR_Y; |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2292 |
|
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2293 |
case 1: |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2294 |
if (fxmy > 3 && sxmy < -3) { /*SwapSelection(); DoRailroadTrack(0); */return HT_DIR_VL; } |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2295 |
if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return HT_DIR_HU; } |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2296 |
return HT_DIR_Y; |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2297 |
|
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2298 |
case 2: |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2299 |
if (fxmy > 3 && sxmy < -3) { /*DoRailroadTrack(3);*/ return HT_DIR_VL; } |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2300 |
if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return HT_DIR_HL; } |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2301 |
return HT_DIR_X; |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2302 |
|
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2303 |
case 3: |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2304 |
if (fxmy < -3 && sxmy > 3) { /*SwapSelection(); DoRailroadTrack(3);*/ return HT_DIR_VR; } |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2305 |
if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return HT_DIR_HU; } |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2306 |
return HT_DIR_X; |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2307 |
} |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2308 |
} |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2309 |
|
4834
3c6e8a547174
(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 |
3c6e8a547174
(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: |
3c6e8a547174
(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 |
3c6e8a547174
(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 |
3c6e8a547174
(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 |
3c6e8a547174
(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 |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2316 |
* the return value signifies. |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2317 |
* @param style HighLightStyle dragging style |
6484
79156627e1ba
(svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents:
6453
diff
changeset
|
2318 |
* @param start_tile start tile of drag |
79156627e1ba
(svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents:
6453
diff
changeset
|
2319 |
* @param end_tile end tile of drag |
79156627e1ba
(svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents:
6453
diff
changeset
|
2320 |
* @return boolean value which when true means start/end should be swapped */ |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2321 |
static bool SwapDirection(HighLightStyle style, TileIndex start_tile, TileIndex end_tile) |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2322 |
{ |
3c6e8a547174
(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); |
3c6e8a547174
(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); |
3c6e8a547174
(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); |
3c6e8a547174
(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); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2327 |
|
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2328 |
switch (style & HT_DRAG_MASK) { |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2329 |
case HT_RAIL: |
3c6e8a547174
(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)); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2331 |
|
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2332 |
case HT_RECT: |
3c6e8a547174
(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); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2334 |
default: NOT_REACHED(); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2335 |
} |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2336 |
|
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2337 |
return false; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2338 |
} |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2339 |
|
3c6e8a547174
(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 |
3c6e8a547174
(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 |
3c6e8a547174
(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 |
3c6e8a547174
(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 |
3c6e8a547174
(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 |
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6484
diff
changeset
|
2345 |
* maximum of SW, S and SE, N corners respectively. This is handled by the lookup table below |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2346 |
* See _tileoffs_by_dir in map.c for the direction enums if you can't figure out |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2347 |
* the values yourself. |
3c6e8a547174
(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.) |
3c6e8a547174
(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 |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2350 |
* ignored for others |
3c6e8a547174
(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 |
3c6e8a547174
(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 |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2353 |
* this value in its tooltips */ |
3c6e8a547174
(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) |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2355 |
{ |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2356 |
bool swap = SwapDirection(style, start_tile, end_tile); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2357 |
byte style_t; |
3c6e8a547174
(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 |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2359 |
|
3c6e8a547174
(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; |
5733 | 2361 |
if (swap) Swap(start_tile, end_tile); |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2362 |
|
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2363 |
switch (style & HT_DRAG_MASK) { |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2364 |
case HT_RECT: { |
3c6e8a547174
(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[] = { |
3c6e8a547174
(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 */ |
3c6e8a547174
(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 */ |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2368 |
}; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2369 |
|
3c6e8a547174
(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 |
3c6e8a547174
(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 */ |
3c6e8a547174
(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)); |
3c6e8a547174
(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])); |
3c6e8a547174
(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])); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2375 |
} |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2376 |
/* Fallthrough */ |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2377 |
case HT_POINT: |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2378 |
h0 = TileHeight(start_tile); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2379 |
h1 = TileHeight(end_tile); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2380 |
break; |
3c6e8a547174
(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 */ |
3c6e8a547174
(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[] = { |
3c6e8a547174
(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 |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2384 |
}; |
3c6e8a547174
(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[] = { |
3c6e8a547174
(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 */ |
3c6e8a547174
(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 */ |
3c6e8a547174
(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 */ |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2389 |
|
3c6e8a547174
(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 */ |
3c6e8a547174
(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 */ |
3c6e8a547174
(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 */ |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2393 |
}; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2394 |
|
3c6e8a547174
(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 |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2396 |
style &= HT_DIR_MASK; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2397 |
|
3c6e8a547174
(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. |
3c6e8a547174
(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 |
3c6e8a547174
(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 |
3c6e8a547174
(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 */ |
3c6e8a547174
(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]; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2403 |
|
3c6e8a547174
(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 */ |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2405 |
style_t = style * 2; |
3c6e8a547174
(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); |
3c6e8a547174
(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]))); |
3c6e8a547174
(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]))); |
5601
d58f82901b2f
(svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents:
5587
diff
changeset
|
2409 |
h0 = max(h0, ht); |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2410 |
|
3c6e8a547174
(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 |
3c6e8a547174
(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 */ |
3c6e8a547174
(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; |
3c6e8a547174
(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); |
3c6e8a547174
(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]))); |
3c6e8a547174
(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]))); |
5601
d58f82901b2f
(svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents:
5587
diff
changeset
|
2417 |
h1 = max(h1, ht); |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2418 |
} break; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2419 |
} |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2420 |
|
5733 | 2421 |
if (swap) Swap(h0, h1); |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2422 |
/* Minimap shows height in intervals of 50 meters, let's do the same */ |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2423 |
return (int)(h1 - h0) * 50; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2424 |
} |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2425 |
|
4885
19e116dc240f
(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
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2427 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
2428 |
/** while dragging */ |
1070
bd31ed783fd3
(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
20311e38bedf
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2431 |
HighLightStyle b; |
20311e38bedf
(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
20311e38bedf
(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); |
20311e38bedf
(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); |
7923
91982bd3c549
(svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
skidd13
parents:
7922
diff
changeset
|
2436 |
w = abs(dx) + 16; |
91982bd3c549
(svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
skidd13
parents:
7922
diff
changeset
|
2437 |
h = abs(dy) + 16; |
0 | 2438 |
|
1980
6c5917cfcb78
(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
d4d440dd8925
(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
d4d440dd8925
(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
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2444 |
} |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2445 |
} else if (h == 16) { // Is this in X direction? |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2446 |
if (dx == 16) { // 2x1 special handling |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2447 |
b = (Check2x1AutoRail(3)) | HT_LINE; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2448 |
} else if (dx == -16) { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2449 |
b = (Check2x1AutoRail(2)) | HT_LINE; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2450 |
} else { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2451 |
b = HT_LINE | HT_DIR_X; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2452 |
} |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2453 |
y = thd->selstart.y; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2454 |
} else if (w == 16) { // Or Y direction? |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2455 |
if (dy == 16) { // 2x1 special handling |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2456 |
b = (Check2x1AutoRail(1)) | HT_LINE; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2457 |
} else if (dy == -16) { // 2x1 other direction |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2458 |
b = (Check2x1AutoRail(0)) | HT_LINE; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2459 |
} else { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2460 |
b = HT_LINE | HT_DIR_Y; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2461 |
} |
0 | 2462 |
x = thd->selstart.x; |
1070
bd31ed783fd3
(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
bd31ed783fd3
(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
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2468 |
x = thd->selstart.x; |
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2469 |
} else { // complicated direction |
4799
20311e38bedf
(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
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2528 |
|
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9410
diff
changeset
|
2529 |
if (_settings_client.gui.measure_tooltip) { |
4834
3c6e8a547174
(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); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2531 |
TileIndex t1 = TileVirtXY(x, y); |
3c6e8a547174
(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
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2533 |
byte index = 0; |
7006
bfa3974da32b
(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:
6937
diff
changeset
|
2534 |
uint64 params[2]; |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2535 |
|
4884
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2536 |
if (distance != 1) { |
94dd5df0d584
(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); |
94dd5df0d584
(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, |
94dd5df0d584
(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 |
94dd5df0d584
(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 */ |
94dd5df0d584
(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) { |
94dd5df0d584
(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; |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2543 |
} |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2544 |
|
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2545 |
params[index++] = distance; |
94dd5df0d584
(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
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2547 |
} |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2548 |
|
9781
31e0e461d7bf
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch
parents:
9755
diff
changeset
|
2549 |
ShowMeasurementTooltips(measure_strings_length[index], index, params); |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2550 |
} |
3c6e8a547174
(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
20311e38bedf
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2557 |
/** |
20311e38bedf
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2558 |
* Selects tiles while dragging |
20311e38bedf
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2559 |
* @param x X coordinate of end of selection |
20311e38bedf
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2560 |
* @param y Y coordinate of end of selection |
20311e38bedf
(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 |
20311e38bedf
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2562 |
* methods are VPM_* in viewport.h */ |
7888
a28f4cfff934
(svn r11439) -Codechange: replace some magic numbers by a ViewportPlaceMethod enumified constant. Patch by SmatZ.
rubidium
parents:
7849
diff
changeset
|
2563 |
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method) |
0 | 2564 |
{ |
4799
20311e38bedf
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2565 |
int sx, sy; |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2566 |
HighLightStyle style; |
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2567 |
|
0 | 2568 |
if (x == -1) { |
1863
74a8379bb868
(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
20311e38bedf
(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
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2575 |
_thd.selend.x = x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2576 |
_thd.selend.y = y; |
74a8379bb868
(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 |
||
7912
49d1b8b4557c
(svn r11465) -Fix: more user-friedly placement in X and Y directions (most noticeable with autoroad)
smatz
parents:
7905
diff
changeset
|
2581 |
/* Needed so level-land is placed correctly */ |
2116 | 2582 |
if (_thd.next_drawstyle == HT_POINT) { |
4799
20311e38bedf
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2583 |
x += TILE_SIZE / 2; |
20311e38bedf
(svn r6721) -Codechange: some comments, aligning, types and variable localization.
Darkvater
parents:
4634
diff
changeset
|
2584 |
y += TILE_SIZE / 2; |
2116 | 2585 |
} |
0 | 2586 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2587 |
sx = _thd.selstart.x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2588 |
sy = _thd.selstart.y; |
0 | 2589 |
|
2116 | 2590 |
switch (method) { |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2591 |
case VPM_X_OR_Y: /* drag in X or Y direction */ |
7923
91982bd3c549
(svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
skidd13
parents:
7922
diff
changeset
|
2592 |
if (abs(sy - y) < abs(sx - x)) { |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2593 |
y = sy; |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2594 |
style = HT_DIR_X; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2595 |
} else { |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2596 |
x = sx; |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2597 |
style = HT_DIR_Y; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2598 |
} |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2599 |
goto calc_heightdiff_single_direction; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2600 |
case VPM_FIX_X: /* drag in Y direction */ |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2601 |
x = sx; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2602 |
style = HT_DIR_Y; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2603 |
goto calc_heightdiff_single_direction; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2604 |
case VPM_FIX_Y: /* drag in X direction */ |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2605 |
y = sy; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2606 |
style = HT_DIR_X; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2607 |
|
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2608 |
calc_heightdiff_single_direction:; |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9410
diff
changeset
|
2609 |
if (_settings_client.gui.measure_tooltip) { |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2610 |
TileIndex t0 = TileVirtXY(sx, sy); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2611 |
TileIndex t1 = TileVirtXY(x, y); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2612 |
uint distance = DistanceManhattan(t0, t1) + 1; |
4884
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2613 |
byte index = 0; |
7006
bfa3974da32b
(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:
6937
diff
changeset
|
2614 |
uint64 params[2]; |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2615 |
|
4884
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2616 |
if (distance != 1) { |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2617 |
/* With current code passing a HT_LINE style to calculate the height |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2618 |
* difference is enough. However if/when a point-tool is created |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2619 |
* with this method, function should be called with new_style (below) |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2620 |
* instead of HT_LINE | style case HT_POINT is handled specially |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2621 |
* new_style := (_thd.next_drawstyle & HT_RECT) ? HT_LINE | style : _thd.next_drawstyle; */ |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2622 |
int heightdiff = CalcHeightdiff(HT_LINE | style, 0, t0, t1); |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2623 |
|
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2624 |
params[index++] = distance; |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2625 |
if (heightdiff != 0) params[index++] = heightdiff; |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2626 |
} |
4884
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2627 |
|
9781
31e0e461d7bf
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch
parents:
9755
diff
changeset
|
2628 |
ShowMeasurementTooltips(measure_strings_length[index], index, params); |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2629 |
} break; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2630 |
|
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2631 |
case VPM_X_AND_Y_LIMITED: { /* drag an X by Y constrained rect area */ |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2632 |
int limit = (_thd.sizelimit - 1) * TILE_SIZE; |
7922
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7918
diff
changeset
|
2633 |
x = sx + Clamp(x - sx, -limit, limit); |
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7918
diff
changeset
|
2634 |
y = sy + Clamp(y - sy, -limit, limit); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
2635 |
} /* Fallthrough */ |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
2636 |
case VPM_X_AND_Y: { /* drag an X by Y area */ |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9410
diff
changeset
|
2637 |
if (_settings_client.gui.measure_tooltip) { |
4884
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2638 |
static const StringID measure_strings_area[] = { |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2639 |
STR_NULL, STR_NULL, STR_MEASURE_AREA, STR_MEASURE_AREA_HEIGHTDIFF |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2640 |
}; |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2641 |
|
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2642 |
TileIndex t0 = TileVirtXY(sx, sy); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2643 |
TileIndex t1 = TileVirtXY(x, y); |
7970
7d6b9ab57081
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents:
7954
diff
changeset
|
2644 |
uint dx = Delta(TileX(t0), TileX(t1)) + 1; |
7d6b9ab57081
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents:
7954
diff
changeset
|
2645 |
uint dy = Delta(TileY(t0), TileY(t1)) + 1; |
4884
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2646 |
byte index = 0; |
7006
bfa3974da32b
(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:
6937
diff
changeset
|
2647 |
uint64 params[3]; |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2648 |
|
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2649 |
/* If dragging an area (eg dynamite tool) and it is actually a single |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2650 |
* row/column, change the type to 'line' to get proper calculation for height */ |
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8144
diff
changeset
|
2651 |
style = (HighLightStyle)_thd.next_drawstyle; |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2652 |
if (style & HT_RECT) { |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2653 |
if (dx == 1) { |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2654 |
style = HT_LINE | HT_DIR_Y; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2655 |
} else if (dy == 1) { |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2656 |
style = HT_LINE | HT_DIR_X; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2657 |
} |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2658 |
} |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2659 |
|
4884
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2660 |
if (dx != 1 || dy != 1) { |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2661 |
int heightdiff = CalcHeightdiff(style, 0, t0, t1); |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2662 |
|
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2663 |
params[index++] = dx; |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2664 |
params[index++] = dy; |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2665 |
if (heightdiff != 0) params[index++] = heightdiff; |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2666 |
} |
4884
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2667 |
|
9781
31e0e461d7bf
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
frosch
parents:
9755
diff
changeset
|
2668 |
ShowMeasurementTooltips(measure_strings_area[index], index, params); |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2669 |
} |
4884
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4838
diff
changeset
|
2670 |
break; |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2671 |
|
2116 | 2672 |
} |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4799
diff
changeset
|
2673 |
default: NOT_REACHED(); |
0 | 2674 |
} |
2675 |
||
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2676 |
_thd.selend.x = x; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2677 |
_thd.selend.y = y; |
0 | 2678 |
} |
2679 |
||
9314
9ba6a9620a69
(svn r13182) -Doc: add documentation to mostly rail_gui related functions. Patch by Alberth.
rubidium
parents:
9274
diff
changeset
|
2680 |
/** |
9ba6a9620a69
(svn r13182) -Doc: add documentation to mostly rail_gui related functions. Patch by Alberth.
rubidium
parents:
9274
diff
changeset
|
2681 |
* Handle the mouse while dragging for placement/resizing. |
9ba6a9620a69
(svn r13182) -Doc: add documentation to mostly rail_gui related functions. Patch by Alberth.
rubidium
parents:
9274
diff
changeset
|
2682 |
* @return Boolean whether search for a handler should continue |
9ba6a9620a69
(svn r13182) -Doc: add documentation to mostly rail_gui related functions. Patch by Alberth.
rubidium
parents:
9274
diff
changeset
|
2683 |
*/ |
6247 | 2684 |
bool VpHandlePlaceSizingDrag() |
0 | 2685 |
{ |
2116 | 2686 |
if (_special_mouse_mode != WSM_SIZING) return true; |
0 | 2687 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
2688 |
/* stop drag mode if the window has been closed */ |
9166
dce886fc5eeb
(svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents:
9147
diff
changeset
|
2689 |
Window *w = FindWindowById(_thd.window_class, _thd.window_number); |
0 | 2690 |
if (w == NULL) { |
2691 |
ResetObjectToPlace(); |
|
2692 |
return false; |
|
2693 |
} |
|
2694 |
||
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
2695 |
/* while dragging execute the drag procedure of the corresponding window (mostly VpSelectTilesWithMethod() ) */ |
0 | 2696 |
if (_left_button_down) { |
9166
dce886fc5eeb
(svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents:
9147
diff
changeset
|
2697 |
w->OnPlaceDrag(_thd.select_method, _thd.select_proc, GetTileBelowCursor()); |
0 | 2698 |
return false; |
2699 |
} |
|
2700 |
||
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
2701 |
/* mouse button released.. |
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6248
diff
changeset
|
2702 |
* 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
|
2703 |
_special_mouse_mode = WSM_NONE; |
2116 | 2704 |
if (_thd.next_drawstyle == HT_RECT) { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2705 |
_thd.place_mode = VHM_RECT; |
9166
dce886fc5eeb
(svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents:
9147
diff
changeset
|
2706 |
} else if (_thd.select_method == VPM_SIGNALDIRS) { // some might call this a hack... -- Dominik |
2116 | 2707 |
_thd.place_mode = VHM_RECT; |
2708 |
} else if (_thd.next_drawstyle & HT_LINE) { |
|
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2709 |
_thd.place_mode = VHM_RAIL; |
2116 | 2710 |
} else if (_thd.next_drawstyle & HT_RAIL) { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2711 |
_thd.place_mode = VHM_RAIL; |
2116 | 2712 |
} else { |
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2713 |
_thd.place_mode = VHM_POINT; |
2116 | 2714 |
} |
0 | 2715 |
SetTileSelectSize(1, 1); |
2716 |
||
9166
dce886fc5eeb
(svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents:
9147
diff
changeset
|
2717 |
w->OnPlaceMouseUp(_thd.select_method, _thd.select_proc, _thd.selend, TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2718 |
|
0 | 2719 |
return false; |
2720 |
} |
|
2721 |
||
7889
e74ce8853ba7
(svn r11440) -Codechange: replace magic numbers with enumified WindowHighlightMode constants. Patch by SmatZ.
rubidium
parents:
7888
diff
changeset
|
2722 |
void SetObjectToPlaceWnd(CursorID icon, SpriteID pal, ViewportHighlightMode mode, Window *w) |
0 | 2723 |
{ |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5602
diff
changeset
|
2724 |
SetObjectToPlace(icon, pal, mode, w->window_class, w->window_number); |
0 | 2725 |
} |
2726 |
||
2727 |
#include "table/animcursors.h" |
|
2728 |
||
7889
e74ce8853ba7
(svn r11440) -Codechange: replace magic numbers with enumified WindowHighlightMode constants. Patch by SmatZ.
rubidium
parents:
7888
diff
changeset
|
2729 |
void SetObjectToPlace(CursorID icon, SpriteID pal, ViewportHighlightMode mode, WindowClass window_class, WindowNumber window_num) |
0 | 2730 |
{ |
8585
61ac905ff5f7
(svn r12166) -Fix [FS#337]: when drag&drop mode was cancelled by keyboard input, depot/group window wasn't updated (original patch by GrimRC)
smatz
parents:
8562
diff
changeset
|
2731 |
/* undo clicking on button and drag & drop */ |
61ac905ff5f7
(svn r12166) -Fix [FS#337]: when drag&drop mode was cancelled by keyboard input, depot/group window wasn't updated (original patch by GrimRC)
smatz
parents:
8562
diff
changeset
|
2732 |
if (_thd.place_mode != VHM_NONE || _special_mouse_mode == WSM_DRAGDROP) { |
9244
bd42e32e71f3
(svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium
parents:
9238
diff
changeset
|
2733 |
Window *w = FindWindowById(_thd.window_class, _thd.window_number); |
bd42e32e71f3
(svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium
parents:
9238
diff
changeset
|
2734 |
if (w != NULL) { |
bd42e32e71f3
(svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium
parents:
9238
diff
changeset
|
2735 |
/* Call the abort function, but set the window class to something |
bd42e32e71f3
(svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium
parents:
9238
diff
changeset
|
2736 |
* that will never be used to avoid infinite loops. Setting it to |
bd42e32e71f3
(svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium
parents:
9238
diff
changeset
|
2737 |
* the 'next' window class must not be done because recursion into |
bd42e32e71f3
(svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium
parents:
9238
diff
changeset
|
2738 |
* this function might in some cases reset the newly set object to |
bd42e32e71f3
(svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium
parents:
9238
diff
changeset
|
2739 |
* place or not properly reset the original selection. */ |
bd42e32e71f3
(svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium
parents:
9238
diff
changeset
|
2740 |
_thd.window_class = WC_INVALID; |
bd42e32e71f3
(svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium
parents:
9238
diff
changeset
|
2741 |
w->OnPlaceObjectAbort(); |
bd42e32e71f3
(svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
rubidium
parents:
9238
diff
changeset
|
2742 |
} |
0 | 2743 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2744 |
|
0 | 2745 |
SetTileSelectSize(1, 1); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2746 |
|
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2747 |
_thd.make_square_red = false; |
0 | 2748 |
|
7889
e74ce8853ba7
(svn r11440) -Codechange: replace magic numbers with enumified WindowHighlightMode constants. Patch by SmatZ.
rubidium
parents:
7888
diff
changeset
|
2749 |
if (mode == VHM_DRAG) { // VHM_DRAG is for dragdropping trains in the depot window |
e74ce8853ba7
(svn r11440) -Codechange: replace magic numbers with enumified WindowHighlightMode constants. Patch by SmatZ.
rubidium
parents:
7888
diff
changeset
|
2750 |
mode = VHM_NONE; |
0 | 2751 |
_special_mouse_mode = WSM_DRAGDROP; |
2752 |
} else { |
|
2753 |
_special_mouse_mode = WSM_NONE; |
|
2754 |
} |
|
2755 |
||
1863
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2756 |
_thd.place_mode = mode; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2757 |
_thd.window_class = window_class; |
74a8379bb868
(svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents:
1542
diff
changeset
|
2758 |
_thd.window_number = window_num; |
0 | 2759 |
|
1070
bd31ed783fd3
(svn r1571) Feature: Visually enhanced autorail placing
dominik
parents:
988
diff
changeset
|
2760 |
if (mode == VHM_SPECIAL) // special tools, like tunnels or docks start with presizing mode |
0 | 2761 |
VpStartPreSizing(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
152
diff
changeset
|
2762 |
|
9238
e2f586d12318
(svn r13104) -Codechange: make ResetObjectToPlace safe to be called recursively via the OnPlaceObjectAbort callback and use this knowledge to simplify closing some windows.
rubidium
parents:
9192
diff
changeset
|
2763 |
if ((int)icon < 0) { |
4334
99abd73de061
(svn r6035) -Revert r5900 which supposedly fixed an invalid warning caused by buggy MS software
Darkvater
parents:
4272
diff
changeset
|
2764 |
SetAnimatedMouseCursor(_animcursors[~icon]); |
9238
e2f586d12318
(svn r13104) -Codechange: make ResetObjectToPlace safe to be called recursively via the OnPlaceObjectAbort callback and use this knowledge to simplify closing some windows.
rubidium
parents:
9192
diff
changeset
|
2765 |
} else { |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5602
diff
changeset
|
2766 |
SetMouseCursor(icon, pal); |
9238
e2f586d12318
(svn r13104) -Codechange: make ResetObjectToPlace safe to be called recursively via the OnPlaceObjectAbort callback and use this knowledge to simplify closing some windows.
rubidium
parents:
9192
diff
changeset
|
2767 |
} |
e2f586d12318
(svn r13104) -Codechange: make ResetObjectToPlace safe to be called recursively via the OnPlaceObjectAbort callback and use this knowledge to simplify closing some windows.
rubidium
parents:
9192
diff
changeset
|
2768 |
|
0 | 2769 |
} |
2770 |
||
6247 | 2771 |
void ResetObjectToPlace() |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1083
diff
changeset
|
2772 |
{ |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5733
diff
changeset
|
2773 |
SetObjectToPlace(SPR_CURSOR_MOUSE, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0); |
0 | 2774 |
} |
9410
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2775 |
|
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2776 |
|
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2777 |
void SaveViewportBeforeSaveGame() |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2778 |
{ |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2779 |
const Window *w = FindWindowById(WC_MAIN_WINDOW, 0); |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2780 |
|
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2781 |
if (w != NULL) { |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2782 |
_saved_scrollpos_x = w->viewport->scrollpos_x; |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2783 |
_saved_scrollpos_y = w->viewport->scrollpos_y; |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2784 |
_saved_scrollpos_zoom = w->viewport->zoom; |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2785 |
} |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2786 |
} |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2787 |
|
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2788 |
void ResetViewportAfterLoadGame() |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2789 |
{ |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2790 |
Window *w = FindWindowById(WC_MAIN_WINDOW, 0); |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2791 |
|
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2792 |
w->viewport->scrollpos_x = _saved_scrollpos_x; |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2793 |
w->viewport->scrollpos_y = _saved_scrollpos_y; |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2794 |
w->viewport->dest_scrollpos_x = _saved_scrollpos_x; |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2795 |
w->viewport->dest_scrollpos_y = _saved_scrollpos_y; |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2796 |
|
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2797 |
ViewPort *vp = w->viewport; |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2798 |
vp->zoom = min(_saved_scrollpos_zoom, ZOOM_LVL_MAX); |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2799 |
vp->virtual_width = ScaleByZoom(vp->width, vp->zoom); |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2800 |
vp->virtual_height = ScaleByZoom(vp->height, vp->zoom); |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2801 |
|
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2802 |
DoZoomInOutWindow(ZOOM_NONE, w); // update button status |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2803 |
MarkWholeScreenDirty(); |
b8cbfacc9057
(svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents:
9354
diff
changeset
|
2804 |
} |