OpenTTD Source: src/viewport_type.h Source File

OpenTTD Source 15.3

viewport_type.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef VIEWPORT_TYPE_H
11#define VIEWPORT_TYPE_H
12
13#include "core/enum_type.hpp"
14#include "zoom_type.h"
15
16class LinkGraphOverlay;
17
19 enum class ViewportStringFlag : uint8_t {
20 Small,
21 Shadow,
22 ColourRect,
23 TransparentRect,
24 TextColour,
25};
26using ViewportStringFlags = EnumBitSet<ViewportStringFlag, uint8_t>;
27
31 struct Viewport {
32 int left;
33 int top;
34 int width;
35 int height;
36
37 int virtual_left;
38 int virtual_top;
39 int virtual_width;
40 int virtual_height;
41
42 ZoomLevel zoom;
43 std::shared_ptr<LinkGraphOverlay> overlay;
44};
45
47 struct ViewportSign {
48 int32_t center = 0;
49 int32_t top = 0;
50 uint16_t width_normal = 0;
51 uint16_t width_small = 0;
52
53 auto operator<=>(const ViewportSign &) const = default;
54
55 void UpdatePosition(int center, int top, std::string_view str, std::string_view str_small = {});
56 void MarkDirty(ZoomLevel maxzoom = ZoomLevel::Max) const;
57};
58
60 struct TrackedViewportSign : ViewportSign {
61 bool kdtree_valid = false;
62
63 auto operator<=>(const TrackedViewportSign &) const = default;
64
69 void UpdatePosition(int center, int top, std::string_view str, std::string_view str_small = {})
70 {
71 this->kdtree_valid = true;
72 this->ViewportSign::UpdatePosition(center, top, str, str_small);
73 }
74};
75
80 enum ZoomStateChange : uint8_t {
81 ZOOM_IN = 0,
82 ZOOM_OUT = 1,
83 ZOOM_NONE = 2,
84};
85
92 static constexpr int BB_HEIGHT_UNDER_BRIDGE = 6;
93 static constexpr int BB_Z_SEPARATOR = 7;
94
96 enum ViewportPlaceMethod : uint8_t {
97 VPM_X_OR_Y = 0,
98 VPM_FIX_X = 1,
99 VPM_FIX_Y = 2,
100 VPM_X_AND_Y = 3,
101 VPM_X_AND_Y_LIMITED = 4,
102 VPM_FIX_HORIZONTAL = 5,
103 VPM_FIX_VERTICAL = 6,
104 VPM_X_LIMITED = 7,
105 VPM_Y_LIMITED = 8,
106 VPM_RAILDIRS = 0x40,
107 VPM_SIGNALDIRS = 0x80,
108};
109 DECLARE_ENUM_AS_BIT_SET(ViewportPlaceMethod)
110
111
115enum ViewportDragDropSelectionProcess : uint8_t {
116 DDSP_DEMOLISH_AREA,
117 DDSP_RAISE_AND_LEVEL_AREA,
118 DDSP_LOWER_AND_LEVEL_AREA,
119 DDSP_LEVEL_AREA,
120 DDSP_CREATE_DESERT,
121 DDSP_CREATE_ROCKS,
122 DDSP_CREATE_WATER,
123 DDSP_CREATE_RIVER,
124 DDSP_PLANT_TREES,
125 DDSP_BUILD_BRIDGE,
126 DDSP_BUILD_OBJECT,
127
128 /* Rail specific actions */
129 DDSP_PLACE_RAIL,
130 DDSP_BUILD_SIGNALS,
131 DDSP_BUILD_STATION,
132 DDSP_REMOVE_STATION,
133 DDSP_CONVERT_RAIL,
134
135 /* Road specific actions */
136 DDSP_PLACE_ROAD_X_DIR,
137 DDSP_PLACE_ROAD_Y_DIR,
138 DDSP_PLACE_AUTOROAD,
139 DDSP_BUILD_ROAD_WAYPOINT,
140 DDSP_BUILD_BUSSTOP,
141 DDSP_BUILD_TRUCKSTOP,
142 DDSP_REMOVE_ROAD_WAYPOINT,
143 DDSP_REMOVE_BUSSTOP,
144 DDSP_REMOVE_TRUCKSTOP,
145 DDSP_CONVERT_ROAD,
146};
147
148
152 enum ViewportScrollTarget : uint8_t {
153 VST_EVERYONE,
154 VST_COMPANY,
155 VST_CLIENT,
156};
157
158#endif /* VIEWPORT_TYPE_H */
EnumBitSet< ViewportStringFlag, uint8_t >
LinkGraphOverlay
Handles drawing of links into some window.
Definition linkgraph_gui.h:41
enum_type.hpp
Type (helpers) for enums.
DECLARE_ENUM_AS_BIT_SET
#define DECLARE_ENUM_AS_BIT_SET(enum_type)
Operators to allow to work with enum as with type safe bit set in C++.
Definition enum_type.hpp:119
ViewportSign::MarkDirty
void MarkDirty(ZoomLevel maxzoom=ZoomLevel::Max) const
Mark the sign dirty in all viewports.
Definition viewport.cpp:1555
TrackedViewportSign
Specialised ViewportSign that tracks whether it is valid for entering into a Kdtree.
Definition viewport_type.h:60
TrackedViewportSign::UpdatePosition
void UpdatePosition(int center, int top, std::string_view str, std::string_view str_small={})
Update the position of the viewport sign.
Definition viewport_type.h:69
TrackedViewportSign::kdtree_valid
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
Definition viewport_type.h:61
ViewportSign
Location information about a sign as seen on the viewport.
Definition viewport_type.h:47
ViewportSign::center
int32_t center
The center position of the sign.
Definition viewport_type.h:48
ViewportSign::width_small
uint16_t width_small
The width when zoomed out (small font)
Definition viewport_type.h:51
ViewportSign::width_normal
uint16_t width_normal
The width when not zoomed out (normal font)
Definition viewport_type.h:50
ViewportSign::UpdatePosition
void UpdatePosition(int center, int top, std::string_view str, std::string_view str_small={})
Update the position of the viewport sign.
Definition viewport.cpp:1533
ViewportSign::top
int32_t top
The top of the sign.
Definition viewport_type.h:49
Viewport
Data structure for viewport, display of a part of the world.
Definition viewport_type.h:31
Viewport::top
int top
Screen coordinate top edge of the viewport.
Definition viewport_type.h:33
Viewport::width
int width
Screen width of the viewport.
Definition viewport_type.h:34
Viewport::zoom
ZoomLevel zoom
The zoom level of the viewport.
Definition viewport_type.h:42
Viewport::virtual_top
int virtual_top
Virtual top coordinate.
Definition viewport_type.h:38
Viewport::virtual_left
int virtual_left
Virtual left coordinate.
Definition viewport_type.h:37
Viewport::virtual_width
int virtual_width
width << zoom
Definition viewport_type.h:39
Viewport::left
int left
Screen coordinate left edge of the viewport.
Definition viewport_type.h:32
Viewport::height
int height
Screen height of the viewport.
Definition viewport_type.h:35
Viewport::virtual_height
int virtual_height
height << zoom
Definition viewport_type.h:40
ViewportScrollTarget
ViewportScrollTarget
Target of the viewport scrolling GS method.
Definition viewport_type.h:152
VST_EVERYONE
@ VST_EVERYONE
All players.
Definition viewport_type.h:153
VST_COMPANY
@ VST_COMPANY
All players in specific company.
Definition viewport_type.h:154
VST_CLIENT
@ VST_CLIENT
Single player.
Definition viewport_type.h:155
ViewportPlaceMethod
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
Definition viewport_type.h:96
VPM_FIX_Y
@ VPM_FIX_Y
drag only in Y axis
Definition viewport_type.h:99
VPM_Y_LIMITED
@ VPM_Y_LIMITED
Drag only in Y axis with limited size.
Definition viewport_type.h:105
VPM_X_AND_Y_LIMITED
@ VPM_X_AND_Y_LIMITED
area of land of limited size
Definition viewport_type.h:101
VPM_FIX_VERTICAL
@ VPM_FIX_VERTICAL
drag only in vertical direction
Definition viewport_type.h:103
VPM_X_LIMITED
@ VPM_X_LIMITED
Drag only in X axis with limited size.
Definition viewport_type.h:104
VPM_X_AND_Y
@ VPM_X_AND_Y
area of land in X and Y directions
Definition viewport_type.h:100
VPM_FIX_HORIZONTAL
@ VPM_FIX_HORIZONTAL
drag only in horizontal direction
Definition viewport_type.h:102
VPM_FIX_X
@ VPM_FIX_X
drag only in X axis
Definition viewport_type.h:98
VPM_SIGNALDIRS
@ VPM_SIGNALDIRS
similar to VMP_RAILDIRS, but with different cursor
Definition viewport_type.h:107
VPM_X_OR_Y
@ VPM_X_OR_Y
drag in X or Y direction
Definition viewport_type.h:97
VPM_RAILDIRS
@ VPM_RAILDIRS
all rail directions
Definition viewport_type.h:106
ZoomStateChange
ZoomStateChange
Directions of zooming.
Definition viewport_type.h:80
ZOOM_IN
@ ZOOM_IN
Zoom in (get more detailed view).
Definition viewport_type.h:81
ZOOM_NONE
@ ZOOM_NONE
Hack, used to update the button status.
Definition viewport_type.h:83
ZOOM_OUT
@ ZOOM_OUT
Zoom out (get helicopter view).
Definition viewport_type.h:82
ViewportDragDropSelectionProcess
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
Definition viewport_type.h:115
DDSP_PLACE_ROAD_Y_DIR
@ DDSP_PLACE_ROAD_Y_DIR
Road placement (Y axis)
Definition viewport_type.h:137
DDSP_CREATE_DESERT
@ DDSP_CREATE_DESERT
Fill area with desert.
Definition viewport_type.h:120
DDSP_BUILD_BUSSTOP
@ DDSP_BUILD_BUSSTOP
Road stop placement (buses)
Definition viewport_type.h:140
DDSP_REMOVE_BUSSTOP
@ DDSP_REMOVE_BUSSTOP
Road stop removal (buses)
Definition viewport_type.h:143
DDSP_REMOVE_ROAD_WAYPOINT
@ DDSP_REMOVE_ROAD_WAYPOINT
Road stop removal (waypoint)
Definition viewport_type.h:142
DDSP_LOWER_AND_LEVEL_AREA
@ DDSP_LOWER_AND_LEVEL_AREA
Lower / level area.
Definition viewport_type.h:118
DDSP_CONVERT_RAIL
@ DDSP_CONVERT_RAIL
Rail conversion.
Definition viewport_type.h:133
DDSP_DEMOLISH_AREA
@ DDSP_DEMOLISH_AREA
Clear area.
Definition viewport_type.h:116
DDSP_BUILD_SIGNALS
@ DDSP_BUILD_SIGNALS
Signal placement.
Definition viewport_type.h:130
DDSP_BUILD_TRUCKSTOP
@ DDSP_BUILD_TRUCKSTOP
Road stop placement (trucks)
Definition viewport_type.h:141
DDSP_REMOVE_STATION
@ DDSP_REMOVE_STATION
Station removal.
Definition viewport_type.h:132
DDSP_CREATE_ROCKS
@ DDSP_CREATE_ROCKS
Fill area with rocks.
Definition viewport_type.h:121
DDSP_REMOVE_TRUCKSTOP
@ DDSP_REMOVE_TRUCKSTOP
Road stop removal (trucks)
Definition viewport_type.h:144
DDSP_RAISE_AND_LEVEL_AREA
@ DDSP_RAISE_AND_LEVEL_AREA
Raise / level area.
Definition viewport_type.h:117
DDSP_LEVEL_AREA
@ DDSP_LEVEL_AREA
Level area.
Definition viewport_type.h:119
DDSP_BUILD_STATION
@ DDSP_BUILD_STATION
Station placement.
Definition viewport_type.h:131
DDSP_CREATE_WATER
@ DDSP_CREATE_WATER
Create a canal.
Definition viewport_type.h:122
DDSP_PLANT_TREES
@ DDSP_PLANT_TREES
Plant trees.
Definition viewport_type.h:124
DDSP_PLACE_AUTOROAD
@ DDSP_PLACE_AUTOROAD
Road placement (auto)
Definition viewport_type.h:138
DDSP_BUILD_ROAD_WAYPOINT
@ DDSP_BUILD_ROAD_WAYPOINT
Road stop placement (waypoint)
Definition viewport_type.h:139
DDSP_CREATE_RIVER
@ DDSP_CREATE_RIVER
Create rivers.
Definition viewport_type.h:123
DDSP_BUILD_OBJECT
@ DDSP_BUILD_OBJECT
Build an object.
Definition viewport_type.h:126
DDSP_PLACE_ROAD_X_DIR
@ DDSP_PLACE_ROAD_X_DIR
Road placement (X axis)
Definition viewport_type.h:136
DDSP_BUILD_BRIDGE
@ DDSP_BUILD_BRIDGE
Bridge placement.
Definition viewport_type.h:125
DDSP_PLACE_RAIL
@ DDSP_PLACE_RAIL
Rail placement.
Definition viewport_type.h:129
DDSP_CONVERT_ROAD
@ DDSP_CONVERT_ROAD
Road conversion.
Definition viewport_type.h:145
ViewportStringFlag
ViewportStringFlag
Flags to control how Viewport Strings are rendered.
Definition viewport_type.h:19
ViewportStringFlag::ColourRect
@ ColourRect
Draw a colour rect around the sign.
ViewportStringFlag::Small
@ Small
Draw using the small font.
ViewportStringFlag::Shadow
@ Shadow
Draw an extra text shadow. Should only be used with ViewportStringFlag::Small, as normal font already...
ViewportStringFlag::TransparentRect
@ TransparentRect
Draw a transparent rect around the sign.
ViewportStringFlag::TextColour
@ TextColour
Draw text in colour.
BB_HEIGHT_UNDER_BRIDGE
static constexpr int BB_HEIGHT_UNDER_BRIDGE
Some values for constructing bounding boxes (BB).
Definition viewport_type.h:92
BB_Z_SEPARATOR
static constexpr int BB_Z_SEPARATOR
Separates the bridge/tunnel from the things under/above it.
Definition viewport_type.h:93
zoom_type.h
Types related to zooming in and out.
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition zoom_type.h:20
ZoomLevel::Max
@ Max
Maximum zoom level.