Add templated versions of CeilDiv and Ceil maths functions
[openttd-joker.git] / src / transparency.h
blob7f6087f16a4277cc43730a9cf77d88dd614e429d
1 /* $Id: transparency.h 22506 2011-05-28 09:46:37Z frosch $ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file transparency.h Functions related to transparency. */
12 #ifndef TRANSPARENCY_H
13 #define TRANSPARENCY_H
15 #include "gfx_func.h"
16 #include "openttd.h"
17 #include "core/bitmath_func.hpp"
19 /**
20 * Transparency option bits: which position in _transparency_opt stands for which transparency.
21 * If you change the order, change the order of the ShowTransparencyToolbar() stuff in transparency_gui.cpp too.
22 * If you add or remove an option don't forget to change the transparency 'hot keys' in main_gui.cpp.
24 enum TransparencyOption {
25 TO_SIGNS = 0, ///< signs
26 TO_TREES, ///< trees
27 TO_HOUSES, ///< town buildings
28 TO_INDUSTRIES, ///< industries
29 TO_BUILDINGS, ///< company buildings - depots, stations, HQ, ...
30 TO_BRIDGES, ///< bridges
31 TO_STRUCTURES, ///< other objects such as transmitters and lighthouses
32 TO_CATENARY, ///< catenary
33 TO_LOADING, ///< loading indicators
34 TO_TUNNELS, ///< vehicles in tunnels
35 TO_END,
36 TO_INVALID, ///< Invalid transparency option
39 typedef uint TransparencyOptionBits; ///< transparency option bits
40 extern TransparencyOptionBits _transparency_opt;
41 extern TransparencyOptionBits _transparency_lock;
42 extern TransparencyOptionBits _invisibility_opt;
43 extern byte _display_opt;
45 /**
46 * Check if the transparency option bit is set
47 * and if we aren't in the game menu (there's never transparency)
49 * @param to the structure which transparency option is ask for
51 static inline bool IsTransparencySet(TransparencyOption to)
53 return (HasBit(_transparency_opt, to) && _game_mode != GM_MENU);
56 /**
57 * Check if the invisibility option bit is set
58 * and if we aren't in the game menu (there's never transparency)
60 * @param to the structure which invisibility option is ask for
62 static inline bool IsInvisibilitySet(TransparencyOption to)
64 return (HasBit(_transparency_opt & _invisibility_opt, to) && _game_mode != GM_MENU);
67 /**
68 * Toggle the transparency option bit
70 * @param to the transparency option to be toggled
72 static inline void ToggleTransparency(TransparencyOption to)
74 ToggleBit(_transparency_opt, to);
77 /**
78 * Toggle the invisibility option bit
80 * @param to the structure which invisibility option is toggle
82 static inline void ToggleInvisibility(TransparencyOption to)
84 ToggleBit(_invisibility_opt, to);
87 /**
88 * Toggles between invisible and solid state.
89 * If object is transparent, then it is made invisible.
90 * Used by the keyboard shortcuts.
92 * @param to the object type which invisibility option to toggle
94 static inline void ToggleInvisibilityWithTransparency(TransparencyOption to)
96 if (IsInvisibilitySet(to)) {
97 ClrBit(_invisibility_opt, to);
98 ClrBit(_transparency_opt, to);
99 } else {
100 SetBit(_invisibility_opt, to);
101 SetBit(_transparency_opt, to);
106 * Toggle the transparency lock bit
108 * @param to the transparency option to be locked or unlocked
110 static inline void ToggleTransparencyLock(TransparencyOption to)
112 ToggleBit(_transparency_lock, to);
115 /** Set or clear all non-locked transparency options */
116 static inline void ResetRestoreAllTransparency()
118 /* if none of the non-locked options are set */
119 if ((_transparency_opt & ~_transparency_lock) == 0) {
120 /* set all non-locked options */
121 _transparency_opt |= GB(~_transparency_lock, 0, TO_END);
122 } else {
123 /* clear all non-locked options */
124 _transparency_opt &= _transparency_lock;
127 MarkWholeScreenDirty();
130 #endif /* TRANSPARENCY_H */