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/>.
8 /** @file transparency.h Functions related to transparency. */
10 #ifndef TRANSPARENCY_H
11 #define TRANSPARENCY_H
15 #include "core/bitmath_func.hpp"
18 * Transparency option bits: which position in _transparency_opt stands for which transparency.
19 * If you change the order, change the order of the ShowTransparencyToolbar() stuff in transparency_gui.cpp too.
20 * If you add or remove an option don't forget to change the transparency 'hot keys' in main_gui.cpp.
22 enum TransparencyOption
{
23 TO_SIGNS
= 0, ///< signs
25 TO_HOUSES
, ///< town buildings
26 TO_INDUSTRIES
, ///< industries
27 TO_BUILDINGS
, ///< company buildings - depots, stations, HQ, ...
28 TO_BRIDGES
, ///< bridges
29 TO_STRUCTURES
, ///< other objects such as transmitters and lighthouses
30 TO_CATENARY
, ///< catenary
31 TO_TEXT
, ///< loading and cost/income text
33 TO_INVALID
, ///< Invalid transparency option
36 typedef uint TransparencyOptionBits
; ///< transparency option bits
37 extern TransparencyOptionBits _transparency_opt
;
38 extern TransparencyOptionBits _transparency_lock
;
39 extern TransparencyOptionBits _invisibility_opt
;
40 extern byte _display_opt
;
43 * Check if the transparency option bit is set
44 * and if we aren't in the game menu (there's never transparency)
46 * @param to the structure which transparency option is ask for
48 inline bool IsTransparencySet(TransparencyOption to
)
50 return (HasBit(_transparency_opt
, to
) && _game_mode
!= GM_MENU
);
54 * Check if the invisibility option bit is set
55 * and if we aren't in the game menu (there's never transparency)
57 * @param to the structure which invisibility option is ask for
59 inline bool IsInvisibilitySet(TransparencyOption to
)
61 return (HasBit(_transparency_opt
& _invisibility_opt
, to
) && _game_mode
!= GM_MENU
);
65 * Toggle the transparency option bit
67 * @param to the transparency option to be toggled
69 inline void ToggleTransparency(TransparencyOption to
)
71 ToggleBit(_transparency_opt
, to
);
75 * Toggle the invisibility option bit
77 * @param to the structure which invisibility option is toggle
79 inline void ToggleInvisibility(TransparencyOption to
)
81 ToggleBit(_invisibility_opt
, to
);
85 * Toggles between invisible and solid state.
86 * If object is transparent, then it is made invisible.
87 * Used by the keyboard shortcuts.
89 * @param to the object type which invisibility option to toggle
91 inline void ToggleInvisibilityWithTransparency(TransparencyOption to
)
93 if (IsInvisibilitySet(to
)) {
94 ClrBit(_invisibility_opt
, to
);
95 ClrBit(_transparency_opt
, to
);
97 SetBit(_invisibility_opt
, to
);
98 SetBit(_transparency_opt
, to
);
103 * Toggle the transparency lock bit
105 * @param to the transparency option to be locked or unlocked
107 inline void ToggleTransparencyLock(TransparencyOption to
)
109 ToggleBit(_transparency_lock
, to
);
112 /** Set or clear all non-locked transparency options */
113 inline void ResetRestoreAllTransparency()
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
);
120 /* clear all non-locked options */
121 _transparency_opt
&= _transparency_lock
;
124 MarkWholeScreenDirty();
127 #endif /* TRANSPARENCY_H */