OpenTTD Source  20241108-master-g80f628063a
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 
23  TO_SIGNS = 0,
32  TO_END,
34 };
35 
36 typedef uint TransparencyOptionBits;
40 extern uint8_t _display_opt;
41 
49 {
50  return (HasBit(_transparency_opt, to) && _game_mode != GM_MENU);
51 }
52 
60 {
61  return (HasBit(_transparency_opt & _invisibility_opt, to) && _game_mode != GM_MENU);
62 }
63 
70 {
72 }
73 
80 {
82 }
83 
92 {
93  if (IsInvisibilitySet(to)) {
96  } else {
99  }
100 }
101 
108 {
110 }
111 
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 */
122  }
123 
125 }
126 
127 #endif /* TRANSPARENCY_H */
Functions related to bit mathematics.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Functions related to the gfx engine.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1529
Some generic types.
void ResetRestoreAllTransparency()
Set or clear all non-locked transparency options.
Definition: transparency.h:113
TransparencyOptionBits _transparency_opt
The bits that should be transparent.
void ToggleTransparency(TransparencyOption to)
Toggle the transparency option bit.
Definition: transparency.h:69
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
Definition: transparency.h:22
@ TO_INVALID
Invalid transparency option.
Definition: transparency.h:33
@ TO_BRIDGES
bridges
Definition: transparency.h:28
@ TO_BUILDINGS
company buildings - depots, stations, HQ, ...
Definition: transparency.h:27
@ TO_TEXT
loading and cost/income text
Definition: transparency.h:31
@ TO_CATENARY
catenary
Definition: transparency.h:30
@ TO_TREES
trees
Definition: transparency.h:24
@ TO_HOUSES
town buildings
Definition: transparency.h:25
@ TO_SIGNS
signs
Definition: transparency.h:23
@ TO_STRUCTURES
other objects such as transmitters and lighthouses
Definition: transparency.h:29
@ TO_INDUSTRIES
industries
Definition: transparency.h:26
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
void ToggleInvisibility(TransparencyOption to)
Toggle the invisibility option bit.
Definition: transparency.h:79
TransparencyOptionBits _transparency_lock
Prevent these bits from flipping with X.
void ToggleInvisibilityWithTransparency(TransparencyOption to)
Toggles between invisible and solid state.
Definition: transparency.h:91
TransparencyOptionBits _invisibility_opt
The bits that should be invisible.
uint8_t _display_opt
What do we want to draw/do?
uint TransparencyOptionBits
transparency option bits
Definition: transparency.h:36
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
void ToggleTransparencyLock(TransparencyOption to)
Toggle the transparency lock bit.
Definition: transparency.h:107