OpenTTD Source: src/transparency.h Source File

OpenTTD Source 15.0-RC2

transparency.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 TRANSPARENCY_H
11#define TRANSPARENCY_H
12
13#include "gfx_func.h"
14#include "openttd.h"
15#include "core/bitmath_func.hpp"
16#include "station_type.h"
17
23 enum TransparencyOption : uint8_t {
24 TO_SIGNS = 0,
25 TO_TREES,
26 TO_HOUSES,
27 TO_INDUSTRIES,
28 TO_BUILDINGS,
29 TO_BRIDGES,
30 TO_STRUCTURES,
31 TO_CATENARY,
32 TO_TEXT,
33 TO_END,
34 TO_INVALID,
35};
36
37 typedef uint TransparencyOptionBits;
38extern TransparencyOptionBits _transparency_opt;
39extern TransparencyOptionBits _transparency_lock;
40extern TransparencyOptionBits _invisibility_opt;
41extern uint8_t _display_opt;
42extern StationFacilities _facility_display_opt;
43
50 inline bool IsTransparencySet(TransparencyOption to)
51{
52 return (HasBit(_transparency_opt, to) && _game_mode != GM_MENU);
53}
54
61 inline bool IsInvisibilitySet(TransparencyOption to)
62{
63 return (HasBit(_transparency_opt & _invisibility_opt, to) && _game_mode != GM_MENU);
64}
65
71 inline void ToggleTransparency(TransparencyOption to)
72{
73 ToggleBit(_transparency_opt, to);
74}
75
81 inline void ToggleInvisibility(TransparencyOption to)
82{
83 ToggleBit(_invisibility_opt, to);
84}
85
93 inline void ToggleInvisibilityWithTransparency(TransparencyOption to)
94{
95 if (IsInvisibilitySet(to)) {
96 ClrBit(_invisibility_opt, to);
97 ClrBit(_transparency_opt, to);
98 } else {
99 SetBit(_invisibility_opt, to);
100 SetBit(_transparency_opt, to);
101 }
102}
103
109 inline void ToggleTransparencyLock(TransparencyOption to)
110{
111 ToggleBit(_transparency_lock, to);
112}
113
115 inline void ResetRestoreAllTransparency()
116{
117 /* if none of the non-locked options are set */
118 if ((_transparency_opt & ~_transparency_lock) == 0) {
119 /* set all non-locked options */
120 _transparency_opt |= GB(~_transparency_lock, 0, TO_END);
121 } else {
122 /* clear all non-locked options */
123 _transparency_opt &= _transparency_lock;
124 }
125
126 MarkWholeScreenDirty();
127}
128
129#endif /* TRANSPARENCY_H */
bitmath_func.hpp
Functions related to bit mathematics.
GB
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition bitmath_func.hpp:32
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition bitmath_func.hpp:121
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
ToggleBit
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
Definition bitmath_func.hpp:157
ClrBit
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Definition bitmath_func.hpp:139
EnumBitSet< StationFacility, uint8_t >
gfx_func.h
Functions related to the gfx engine.
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1546
openttd.h
Some generic types.
station_type.h
Types related to stations.
ResetRestoreAllTransparency
void ResetRestoreAllTransparency()
Set or clear all non-locked transparency options.
Definition transparency.h:115
_transparency_opt
TransparencyOptionBits _transparency_opt
The bits that should be transparent.
Definition transparency_gui.cpp:23
_facility_display_opt
StationFacilities _facility_display_opt
What station facilities to draw.
Definition transparency_gui.cpp:27
ToggleTransparency
void ToggleTransparency(TransparencyOption to)
Toggle the transparency option bit.
Definition transparency.h:71
IsTransparencySet
bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
Definition transparency.h:50
ToggleInvisibility
void ToggleInvisibility(TransparencyOption to)
Toggle the invisibility option bit.
Definition transparency.h:81
_transparency_lock
TransparencyOptionBits _transparency_lock
Prevent these bits from flipping with X.
Definition transparency_gui.cpp:24
ToggleInvisibilityWithTransparency
void ToggleInvisibilityWithTransparency(TransparencyOption to)
Toggles between invisible and solid state.
Definition transparency.h:93
_invisibility_opt
TransparencyOptionBits _invisibility_opt
The bits that should be invisible.
Definition transparency_gui.cpp:25
_display_opt
uint8_t _display_opt
What do we want to draw/do?
Definition transparency_gui.cpp:26
TransparencyOptionBits
uint TransparencyOptionBits
transparency option bits
Definition transparency.h:37
IsInvisibilitySet
bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren't in the game menu (there's never transpar...
Definition transparency.h:61
TransparencyOption
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
Definition transparency.h:23
TO_INVALID
@ TO_INVALID
Invalid transparency option.
Definition transparency.h:34
TO_BRIDGES
@ TO_BRIDGES
bridges
Definition transparency.h:29
TO_BUILDINGS
@ TO_BUILDINGS
company buildings - depots, stations, HQ, ...
Definition transparency.h:28
TO_TEXT
@ TO_TEXT
loading and cost/income text
Definition transparency.h:32
TO_CATENARY
@ TO_CATENARY
catenary
Definition transparency.h:31
TO_TREES
@ TO_TREES
trees
Definition transparency.h:25
TO_HOUSES
@ TO_HOUSES
town buildings
Definition transparency.h:26
TO_SIGNS
@ TO_SIGNS
signs
Definition transparency.h:24
TO_STRUCTURES
@ TO_STRUCTURES
other objects such as transmitters and lighthouses
Definition transparency.h:30
TO_INDUSTRIES
@ TO_INDUSTRIES
industries
Definition transparency.h:27
ToggleTransparencyLock
void ToggleTransparencyLock(TransparencyOption to)
Toggle the transparency lock bit.
Definition transparency.h:109