(svn r27707) -Fix: Make the result of NewGRF's CARGO_NAME string code reliably print...
[openttd.git] / src / transparency.h
blobab6f9a6f338a149ac9aa59f9247033026a68ed17
1 /* $Id$ */
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_END,
35 TO_INVALID, ///< Invalid transparency option
38 typedef uint TransparencyOptionBits; ///< transparency option bits
39 extern TransparencyOptionBits _transparency_opt;
40 extern TransparencyOptionBits _transparency_lock;
41 extern TransparencyOptionBits _invisibility_opt;
42 extern byte _display_opt;
44 /**
45 * Check if the transparency option bit is set
46 * and if we aren't in the game menu (there's never transparency)
48 * @param to the structure which transparency option is ask for
50 static inline bool IsTransparencySet(TransparencyOption to)
52 return (HasBit(_transparency_opt, to) && _game_mode != GM_MENU);
55 /**
56 * Check if the invisibility option bit is set
57 * and if we aren't in the game menu (there's never transparency)
59 * @param to the structure which invisibility option is ask for
61 static inline bool IsInvisibilitySet(TransparencyOption to)
63 return (HasBit(_transparency_opt & _invisibility_opt, to) && _game_mode != GM_MENU);
66 /**
67 * Toggle the transparency option bit
69 * @param to the transparency option to be toggled
71 static inline void ToggleTransparency(TransparencyOption to)
73 ToggleBit(_transparency_opt, to);
76 /**
77 * Toggle the invisibility option bit
79 * @param to the structure which invisibility option is toggle
81 static inline void ToggleInvisibility(TransparencyOption to)
83 ToggleBit(_invisibility_opt, to);
86 /**
87 * Toggles between invisible and solid state.
88 * If object is transparent, then it is made invisible.
89 * Used by the keyboard shortcuts.
91 * @param to the object type which invisibility option to toggle
93 static inline void ToggleInvisibilityWithTransparency(TransparencyOption to)
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);
105 * Toggle the transparency lock bit
107 * @param to the transparency option to be locked or unlocked
109 static inline void ToggleTransparencyLock(TransparencyOption to)
111 ToggleBit(_transparency_lock, to);
114 /** Set or clear all non-locked transparency options */
115 static inline void ResetRestoreAllTransparency()
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;
126 MarkWholeScreenDirty();
129 #endif /* TRANSPARENCY_H */