Annotation of /trunk/indra/newview/llviewercontrol.h
Parent Directory
|
Revision Log
Revision 135 - (view) (download)
| 1 : | mjm | 135 | /** |
| 2 : | * @file llviewercontrol.h | ||
| 3 : | * @brief references to viewer-specific control files | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2001&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | * Copyright (c) 2001-2009, Linden Research, Inc. | ||
| 8 : | * | ||
| 9 : | * Second Life Viewer Source Code | ||
| 10 : | * The source code in this file ("Source Code") is provided by Linden Lab | ||
| 11 : | * to you under the terms of the GNU General Public License, version 2.0 | ||
| 12 : | * ("GPL"), unless you have obtained a separate licensing agreement | ||
| 13 : | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
| 14 : | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
| 15 : | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
| 16 : | * | ||
| 17 : | * There are special exceptions to the terms and conditions of the GPL as | ||
| 18 : | * it is applied to this Source Code. View the full text of the exception | ||
| 19 : | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
| 20 : | * online at | ||
| 21 : | * http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 22 : | * | ||
| 23 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 24 : | * that you have read and understood your obligations described above, | ||
| 25 : | * and agree to abide by those obligations. | ||
| 26 : | * | ||
| 27 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 28 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 29 : | * COMPLETENESS OR PERFORMANCE. | ||
| 30 : | * $/LicenseInfo$ | ||
| 31 : | */ | ||
| 32 : | |||
| 33 : | #ifndef LL_LLVIEWERCONTROL_H | ||
| 34 : | #define LL_LLVIEWERCONTROL_H | ||
| 35 : | |||
| 36 : | #include <map> | ||
| 37 : | #include "llcontrol.h" | ||
| 38 : | |||
| 39 : | // Enabled this definition to compile a 'hacked' viewer that | ||
| 40 : | // allows a hacked godmode to be toggled on and off. | ||
| 41 : | #define TOGGLE_HACKED_GODLIKE_VIEWER | ||
| 42 : | #ifdef TOGGLE_HACKED_GODLIKE_VIEWER | ||
| 43 : | extern BOOL gHackGodmode; | ||
| 44 : | #endif | ||
| 45 : | |||
| 46 : | // These functions found in llcontroldef.cpp *TODO: clean this up! | ||
| 47 : | //setting variables are declared in this function | ||
| 48 : | void settings_setup_listeners(); | ||
| 49 : | |||
| 50 : | extern std::map<std::string, LLControlGroup*> gSettings; | ||
| 51 : | |||
| 52 : | // for the graphics settings | ||
| 53 : | void create_graphics_group(LLControlGroup& group); | ||
| 54 : | |||
| 55 : | // saved at end of session | ||
| 56 : | extern LLControlGroup gSavedSettings; | ||
| 57 : | extern LLControlGroup gSavedPerAccountSettings; | ||
| 58 : | |||
| 59 : | // Read-only | ||
| 60 : | extern LLControlGroup gColors; | ||
| 61 : | |||
| 62 : | // Saved at end of session | ||
| 63 : | extern LLControlGroup gCrashSettings; | ||
| 64 : | |||
| 65 : | // Set after settings loaded | ||
| 66 : | extern std::string gLastRunVersion; | ||
| 67 : | extern std::string gCurrentVersion; | ||
| 68 : | |||
| 69 : | //! Helper function for LLCachedControl | ||
| 70 : | template <class T> | ||
| 71 : | eControlType get_control_type(const T& in, LLSD& out) | ||
| 72 : | { | ||
| 73 : | llerrs << "Usupported control type: " << typeid(T).name() << "." << llendl; | ||
| 74 : | return TYPE_COUNT; | ||
| 75 : | } | ||
| 76 : | |||
| 77 : | //! Publish/Subscribe object to interact with LLControlGroups. | ||
| 78 : | |||
| 79 : | //! An LLCachedControl instance to connect to a LLControlVariable | ||
| 80 : | //! without have to manually create and bind a listener to a local | ||
| 81 : | //! object. | ||
| 82 : | template <class T> | ||
| 83 : | class LLCachedControl | ||
| 84 : | { | ||
| 85 : | T mCachedValue; | ||
| 86 : | LLPointer<LLControlVariable> mControl; | ||
| 87 : | boost::signals::connection mConnection; | ||
| 88 : | |||
| 89 : | public: | ||
| 90 : | LLCachedControl(const std::string& name, | ||
| 91 : | const T& default_value, | ||
| 92 : | const std::string& comment = "Declared In Code") | ||
| 93 : | { | ||
| 94 : | mControl = gSavedSettings.getControl(name); | ||
| 95 : | if(mControl.isNull()) | ||
| 96 : | { | ||
| 97 : | declareTypedControl(gSavedSettings, name, default_value, comment); | ||
| 98 : | mControl = gSavedSettings.getControl(name); | ||
| 99 : | if(mControl.isNull()) | ||
| 100 : | { | ||
| 101 : | llerrs << "The control could not be created!!!" << llendl; | ||
| 102 : | } | ||
| 103 : | |||
| 104 : | mCachedValue = default_value; | ||
| 105 : | } | ||
| 106 : | else | ||
| 107 : | { | ||
| 108 : | mCachedValue = (const T&)mControl->getValue(); | ||
| 109 : | } | ||
| 110 : | |||
| 111 : | // Add a listener to the controls signal... | ||
| 112 : | mControl->getSignal()->connect( | ||
| 113 : | boost::bind(&LLCachedControl<T>::handleValueChange, this, _1) | ||
| 114 : | ); | ||
| 115 : | } | ||
| 116 : | |||
| 117 : | ~LLCachedControl() | ||
| 118 : | { | ||
| 119 : | if(mConnection.connected()) | ||
| 120 : | { | ||
| 121 : | mConnection.disconnect(); | ||
| 122 : | } | ||
| 123 : | } | ||
| 124 : | |||
| 125 : | LLCachedControl& operator =(const T& newvalue) | ||
| 126 : | { | ||
| 127 : | setTypeValue(*mControl, newvalue); | ||
| 128 : | } | ||
| 129 : | |||
| 130 : | operator const T&() { return mCachedValue; } | ||
| 131 : | |||
| 132 : | private: | ||
| 133 : | void declareTypedControl(LLControlGroup& group, | ||
| 134 : | const std::string& name, | ||
| 135 : | const T& default_value, | ||
| 136 : | const std::string& comment) | ||
| 137 : | { | ||
| 138 : | LLSD init_value; | ||
| 139 : | eControlType type = get_control_type<T>(default_value, init_value); | ||
| 140 : | if(type < TYPE_COUNT) | ||
| 141 : | { | ||
| 142 : | group.declareControl(name, type, init_value, comment, FALSE); | ||
| 143 : | } | ||
| 144 : | } | ||
| 145 : | |||
| 146 : | bool handleValueChange(const LLSD& newvalue) | ||
| 147 : | { | ||
| 148 : | mCachedValue = (const T &)newvalue; | ||
| 149 : | return true; | ||
| 150 : | } | ||
| 151 : | |||
| 152 : | void setTypeValue(LLControlVariable& c, const T& v) | ||
| 153 : | { | ||
| 154 : | // Implicit conversion from T to LLSD... | ||
| 155 : | c.set(v); | ||
| 156 : | } | ||
| 157 : | }; | ||
| 158 : | |||
| 159 : | template <> eControlType get_control_type<U32>(const U32& in, LLSD& out); | ||
| 160 : | template <> eControlType get_control_type<S32>(const S32& in, LLSD& out); | ||
| 161 : | template <> eControlType get_control_type<F32>(const F32& in, LLSD& out); | ||
| 162 : | template <> eControlType get_control_type<bool> (const bool& in, LLSD& out); | ||
| 163 : | // Yay BOOL, its really an S32. | ||
| 164 : | //template <> eControlType get_control_type<BOOL> (const BOOL& in, LLSD& out) | ||
| 165 : | template <> eControlType get_control_type<std::string>(const std::string& in, LLSD& out); | ||
| 166 : | template <> eControlType get_control_type<LLVector3>(const LLVector3& in, LLSD& out); | ||
| 167 : | template <> eControlType get_control_type<LLVector3d>(const LLVector3d& in, LLSD& out); | ||
| 168 : | template <> eControlType get_control_type<LLRect>(const LLRect& in, LLSD& out); | ||
| 169 : | template <> eControlType get_control_type<LLColor4>(const LLColor4& in, LLSD& out); | ||
| 170 : | template <> eControlType get_control_type<LLColor3>(const LLColor3& in, LLSD& out); | ||
| 171 : | template <> eControlType get_control_type<LLColor4U>(const LLColor4U& in, LLSD& out); | ||
| 172 : | template <> eControlType get_control_type<LLSD>(const LLSD& in, LLSD& out); | ||
| 173 : | |||
| 174 : | //#define TEST_CACHED_CONTROL 1 | ||
| 175 : | #ifdef TEST_CACHED_CONTROL | ||
| 176 : | void test_cached_control(); | ||
| 177 : | #endif // TEST_CACHED_CONTROL | ||
| 178 : | |||
| 179 : | #endif // LL_LLVIEWERCONTROL_H |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

