# transparency.h

Go to the documentation of this file.

    00001 /* $Id: transparency.h 22506 2011-05-28 09:46:37Z frosch $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef TRANSPARENCY_H
    00013 #define TRANSPARENCY_H
    00014
    00015 #include "gfx_func.h"
    00016 #include "openttd.h"
    00017 #include "core/bitmath_func.hpp"
    00018
    00024 enum TransparencyOption {
    00025   TO_SIGNS = 0,
    00026   TO_TREES,
    00027   TO_HOUSES,
    00028   TO_INDUSTRIES,
    00029   TO_BUILDINGS,
    00030   TO_BRIDGES,
    00031   TO_STRUCTURES,
    00032   TO_CATENARY,
    00033   TO_LOADING,
    00034   TO_END,
    00035   TO_INVALID,
    00036 };
    00037
    00038 typedef uint TransparencyOptionBits;
    00039 extern TransparencyOptionBits _transparency_opt;
    00040 extern TransparencyOptionBits _transparency_lock;
    00041 extern TransparencyOptionBits _invisibility_opt;
    00042 extern byte _display_opt;
    00043
    00050 static inline bool IsTransparencySet(TransparencyOption to)
    00051 {
    00052   return (HasBit(_transparency_opt, to) && _game_mode != GM_MENU);
    00053 }
    00054
    00061 static inline bool IsInvisibilitySet(TransparencyOption to)
    00062 {
    00063   return (HasBit(_transparency_opt & _invisibility_opt, to) && _game_mode != GM_MENU);
    00064 }
    00065
    00071 static inline void ToggleTransparency(TransparencyOption to)
    00072 {
    00073   ToggleBit(_transparency_opt, to);
    00074 }
    00075
    00081 static inline void ToggleInvisibility(TransparencyOption to)
    00082 {
    00083   ToggleBit(_invisibility_opt, to);
    00084 }
    00085
    00093 static inline void ToggleInvisibilityWithTransparency(TransparencyOption to)
    00094 {
    00095   if (IsInvisibilitySet(to)) {
    00096     ClrBit(_invisibility_opt, to);
    00097     ClrBit(_transparency_opt, to);
    00098   } else {
    00099     SetBit(_invisibility_opt, to);
    00100     SetBit(_transparency_opt, to);
    00101   }
    00102 }
    00103
    00109 static inline void ToggleTransparencyLock(TransparencyOption to)
    00110 {
    00111   ToggleBit(_transparency_lock, to);
    00112 }
    00113
    00115 static inline void ResetRestoreAllTransparency()
    00116 {
    00117   /* if none of the non-locked options are set */
    00118   if ((_transparency_opt & ~_transparency_lock) == 0) {
    00119     /* set all non-locked options */
    00120     _transparency_opt |= GB(~_transparency_lock, 0, TO_END);
    00121   } else {
    00122     /* clear all non-locked options */
    00123     _transparency_opt &= _transparency_lock;
    00124   }
    00125
    00126   MarkWholeScreenDirty();
    00127 }
    00128
    00129 #endif /* TRANSPARENCY_H */