OpenTTD Source: src/transparency.h Source File

OpenTTD Source 12.2

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 <http://www.gnu.org/licenses/>.
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
22 enum TransparencyOption {
23 TO_SIGNS = 0,
24 TO_TREES,
25 TO_HOUSES,
26 TO_INDUSTRIES,
27 TO_BUILDINGS,
28 TO_BRIDGES,
29 TO_STRUCTURES,
30 TO_CATENARY,
31 TO_LOADING,
32 TO_END,
33 TO_INVALID,
34 };
35
36 typedef uint TransparencyOptionBits;
37 extern TransparencyOptionBits _transparency_opt;
38 extern TransparencyOptionBits _transparency_lock;
39 extern TransparencyOptionBits _invisibility_opt;
40 extern byte _display_opt;
41
48 static inline bool IsTransparencySet(TransparencyOption to)
49 {
50 return (HasBit(_transparency_opt, to) && _game_mode != GM_MENU);
51 }
52
59 static inline bool IsInvisibilitySet(TransparencyOption to)
60 {
61 return (HasBit(_transparency_opt & _invisibility_opt, to) && _game_mode != GM_MENU);
62 }
63
69 static inline void ToggleTransparency(TransparencyOption to)
70 {
71 ToggleBit(_transparency_opt, to);
72 }
73
79 static inline void ToggleInvisibility(TransparencyOption to)
80 {
81 ToggleBit(_invisibility_opt, to);
82 }
83
91 static inline void ToggleInvisibilityWithTransparency(TransparencyOption to)
92 {
93 if (IsInvisibilitySet(to)) {
94 ClrBit(_invisibility_opt, to);
95 ClrBit(_transparency_opt, to);
96 } else {
97 SetBit(_invisibility_opt, to);
98 SetBit(_transparency_opt, to);
99 }
100 }
101
107 static inline void ToggleTransparencyLock(TransparencyOption to)
108 {
109 ToggleBit(_transparency_lock, to);
110 }
111
113 static inline void ResetRestoreAllTransparency()
114 {
115 /* if none of the non-locked options are set */
116 if ((_transparency_opt & ~_transparency_lock) == 0) {
117 /* set all non-locked options */
118 _transparency_opt |= GB(~_transparency_lock, 0, TO_END);
119 } else {
120 /* clear all non-locked options */
121 _transparency_opt &= _transparency_lock;
122 }
123
124 MarkWholeScreenDirty();
125 }
126
127 #endif /* TRANSPARENCY_H */
TO_CATENARY
@ TO_CATENARY
catenary
Definition: transparency.h:30
ResetRestoreAllTransparency
static void ResetRestoreAllTransparency()
Set or clear all non-locked transparency options.
Definition: transparency.h:113
TO_HOUSES
@ TO_HOUSES
town buildings
Definition: transparency.h:25
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
TO_BUILDINGS
@ TO_BUILDINGS
company buildings - depots, stations, HQ, ...
Definition: transparency.h:27
_transparency_opt
TransparencyOptionBits _transparency_opt
The bits that should be transparent.
Definition: transparency_gui.cpp:23
IsTransparencySet
static 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:48
TO_LOADING
@ TO_LOADING
loading indicators
Definition: transparency.h:31
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
ClrBit
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
ToggleInvisibilityWithTransparency
static void ToggleInvisibilityWithTransparency(TransparencyOption to)
Toggles between invisible and solid state.
Definition: transparency.h:91
_display_opt
byte _display_opt
What do we want to draw/do?
Definition: transparency_gui.cpp:26
gfx_func.h
TO_TREES
@ TO_TREES
trees
Definition: transparency.h:24
TO_BRIDGES
@ TO_BRIDGES
bridges
Definition: transparency.h:28
bitmath_func.hpp
TO_INVALID
@ TO_INVALID
Invalid transparency option.
Definition: transparency.h:33
IsInvisibilitySet
static 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:59
TransparencyOptionBits
uint TransparencyOptionBits
transparency option bits
Definition: transparency.h:36
_transparency_lock
TransparencyOptionBits _transparency_lock
Prevent these bits from flipping with X.
Definition: transparency_gui.cpp:24
ToggleInvisibility
static void ToggleInvisibility(TransparencyOption to)
Toggle the invisibility option bit.
Definition: transparency.h:79
TO_INDUSTRIES
@ TO_INDUSTRIES
industries
Definition: transparency.h:26
TransparencyOption
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
Definition: transparency.h:22
TO_STRUCTURES
@ TO_STRUCTURES
other objects such as transmitters and lighthouses
Definition: transparency.h:29
openttd.h
TO_SIGNS
@ TO_SIGNS
signs
Definition: transparency.h:23
ToggleBit
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
Definition: bitmath_func.hpp:181
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1751
ToggleTransparency
static void ToggleTransparency(TransparencyOption to)
Toggle the transparency option bit.
Definition: transparency.h:69
ToggleTransparencyLock
static void ToggleTransparencyLock(TransparencyOption to)
Toggle the transparency lock bit.
Definition: transparency.h:107
_invisibility_opt
TransparencyOptionBits _invisibility_opt
The bits that should be invisible.
Definition: transparency_gui.cpp:25