diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/newview/llwindlightremotectrl.cpp | 262 |
1 files changed, 262 insertions, 0 deletions
diff --git a/linden/indra/newview/llwindlightremotectrl.cpp b/linden/indra/newview/llwindlightremotectrl.cpp new file mode 100644 index 0000000..e47eef7 --- /dev/null +++ b/linden/indra/newview/llwindlightremotectrl.cpp | |||
@@ -0,0 +1,262 @@ | |||
1 | /** | ||
2 | * @file llwindlightremotectrl.cpp | ||
3 | * @brief toolbar remote for windlight options and presets | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2009&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2009, McCabe Maxsted | ||
8 | * | ||
9 | * Imprudence Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided to you | ||
11 | * under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"). Terms of the GPL can be found in doc/GPL-license.txt in | ||
13 | * this distribution, or online at | ||
14 | * http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL SOURCE CODE IS PROVIDED "AS IS." THE AUTHOR MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | * $/LicenseInfo$ | ||
29 | */ | ||
30 | |||
31 | #include "llviewerprecompiledheaders.h" | ||
32 | |||
33 | #include "llwindlightremotectrl.h" | ||
34 | |||
35 | #include "llbutton.h" | ||
36 | #include "llcombobox.h" | ||
37 | #include "llfloaterenvsettings.h" | ||
38 | #include "llfloaterwindlight.h" | ||
39 | #include "lloverlaybar.h" | ||
40 | #include "lluictrlfactory.h" | ||
41 | #include "llwlparammanager.h" | ||
42 | #include "llviewercontrol.h" | ||
43 | |||
44 | |||
45 | class LLWindlightRemoteObserver : public LLWLPresetsObserver | ||
46 | { | ||
47 | public: | ||
48 | LLWindlightRemoteObserver(LLWindlightRemoteCtrl* wind_rem) : mWindlightRemote(wind_rem){} | ||
49 | virtual ~LLWindlightRemoteObserver() {} | ||
50 | virtual void changed() { mWindlightRemote->refreshPresets(); } | ||
51 | private: | ||
52 | LLWindlightRemoteCtrl* mWindlightRemote; | ||
53 | }; | ||
54 | |||
55 | |||
56 | LLWindlightRemoteCtrl::LLWindlightRemoteCtrl() | ||
57 | { | ||
58 | mPresetsCombo = NULL; | ||
59 | mObserver = NULL; | ||
60 | setIsChrome(TRUE); | ||
61 | |||
62 | build(); | ||
63 | |||
64 | setFocusRoot(TRUE); | ||
65 | } | ||
66 | |||
67 | LLWindlightRemoteCtrl::~LLWindlightRemoteCtrl() | ||
68 | { | ||
69 | delete mObserver; | ||
70 | mObserver = NULL; | ||
71 | } | ||
72 | |||
73 | void LLWindlightRemoteCtrl::draw() | ||
74 | { | ||
75 | LLButton* expand_button = getChild<LLButton>("Popup"); | ||
76 | if (expand_button) | ||
77 | { | ||
78 | if (expand_button->getToggleState()) | ||
79 | { | ||
80 | expand_button->setImageOverlay("arrow_down.tga"); | ||
81 | } | ||
82 | else | ||
83 | { | ||
84 | expand_button->setImageOverlay("arrow_up.tga"); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | LLPanel::draw(); | ||
89 | } | ||
90 | |||
91 | void LLWindlightRemoteCtrl::build() | ||
92 | { | ||
93 | if (gSavedSettings.getBOOL("ShowWindlightSettingsPopup")) | ||
94 | { | ||
95 | LLUICtrlFactory::getInstance()->buildPanel(this, "panel_windlight_remote_expanded.xml"/*, &getFactoryMap()*/); | ||
96 | } | ||
97 | else | ||
98 | { | ||
99 | LLUICtrlFactory::getInstance()->buildPanel(this, "panel_windlight_remote.xml"/*, &getFactoryMap()*/); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | BOOL LLWindlightRemoteCtrl::postBuild() | ||
104 | { | ||
105 | |||
106 | childSetAction("Environment", onClickToggleEnvironment, this); | ||
107 | childSetAction("Popup", onClickPopupBtn, this); | ||
108 | |||
109 | mPresetsCombo = getChild<LLComboBox>("Presets"); | ||
110 | if (mPresetsCombo) | ||
111 | { | ||
112 | mPresetsCombo->setCommitCallback(onCommitPreset); | ||
113 | mPresetsCombo->setCallbackUserData(this); | ||
114 | |||
115 | // set up observer to follow changes | ||
116 | mObserver = new LLWindlightRemoteObserver(this); | ||
117 | LLWLParamManager::addObserver(mObserver); | ||
118 | |||
119 | // refresh list from current presets | ||
120 | refreshPresets(); | ||
121 | } | ||
122 | |||
123 | return TRUE; | ||
124 | } | ||
125 | |||
126 | void LLWindlightRemoteCtrl::refreshPresets() | ||
127 | { | ||
128 | if (mPresetsCombo) | ||
129 | { | ||
130 | //store current preset | ||
131 | std::string cur_preset = mPresetsCombo->getValue().asString(); | ||
132 | |||
133 | mPresetsCombo->clearRows(); | ||
134 | |||
135 | std::map<std::string, LLWLParamSet>::iterator mIt = | ||
136 | LLWLParamManager::instance()->mParamList.begin(); | ||
137 | for(; mIt != LLWLParamManager::instance()->mParamList.end(); mIt++) | ||
138 | { | ||
139 | mPresetsCombo->add(mIt->first); | ||
140 | } | ||
141 | |||
142 | // Insert label after sorting, at top, with separator below it | ||
143 | mPresetsCombo->addSeparator(ADD_BOTTOM); | ||
144 | mPresetsCombo->addSimpleElement(getString("sunrise"), ADD_BOTTOM); | ||
145 | mPresetsCombo->addSimpleElement(getString("noon"), ADD_BOTTOM); | ||
146 | mPresetsCombo->addSimpleElement(getString("sunset"), ADD_BOTTOM); | ||
147 | mPresetsCombo->addSimpleElement(getString("midnight"), ADD_BOTTOM); | ||
148 | mPresetsCombo->addSimpleElement(getString("revert_region"), ADD_BOTTOM); | ||
149 | |||
150 | if (!cur_preset.empty()) | ||
151 | { | ||
152 | mPresetsCombo->selectByValue(LLSD(cur_preset)); | ||
153 | } | ||
154 | else | ||
155 | { | ||
156 | mPresetsCombo->selectByValue(LLSD("Default")); | ||
157 | } | ||
158 | } | ||
159 | } | ||
160 | |||
161 | // static | ||
162 | void LLWindlightRemoteCtrl::onCommitPreset(LLUICtrl* ctrl, void* data) | ||
163 | { | ||
164 | LLWindlightRemoteCtrl* self = (LLWindlightRemoteCtrl*)data; | ||
165 | |||
166 | LLCtrlListInterface* presets = self->mPresetsCombo ? self->mPresetsCombo->getListInterface() : NULL; | ||
167 | if (presets) | ||
168 | { | ||
169 | S32 index = presets->getFirstSelectedIndex(); | ||
170 | if (index <= 0) | ||
171 | { | ||
172 | // Open Advanced Sky | ||
173 | LLFloaterWindLight::show(); | ||
174 | return; | ||
175 | } | ||
176 | |||
177 | // check for World menu options; if none, apply preset | ||
178 | std::string selected = self->mPresetsCombo->getSelectedValue().asString(); | ||
179 | |||
180 | if (selected == self->getString("sunrise")) | ||
181 | { | ||
182 | // set the value, turn off animation | ||
183 | LLWLParamManager::instance()->mAnimator.setDayTime(0.25); | ||
184 | LLWLParamManager::instance()->mAnimator.mIsRunning = false; | ||
185 | LLWLParamManager::instance()->mAnimator.mUseLindenTime = false; | ||
186 | |||
187 | // then call update once | ||
188 | LLWLParamManager::instance()->mAnimator.update( | ||
189 | LLWLParamManager::instance()->mCurParams); | ||
190 | } | ||
191 | else if (selected == self->getString("noon")) | ||
192 | { | ||
193 | // set the value, turn off animation | ||
194 | LLWLParamManager::instance()->mAnimator.setDayTime(0.567); | ||
195 | LLWLParamManager::instance()->mAnimator.mIsRunning = false; | ||
196 | LLWLParamManager::instance()->mAnimator.mUseLindenTime = false; | ||
197 | |||
198 | // then call update once | ||
199 | LLWLParamManager::instance()->mAnimator.update( | ||
200 | LLWLParamManager::instance()->mCurParams); | ||
201 | } | ||
202 | else if (selected == self->getString("sunset")) | ||
203 | { | ||
204 | // set the value, turn off animation | ||
205 | LLWLParamManager::instance()->mAnimator.setDayTime(0.75); | ||
206 | LLWLParamManager::instance()->mAnimator.mIsRunning = false; | ||
207 | LLWLParamManager::instance()->mAnimator.mUseLindenTime = false; | ||
208 | |||
209 | // then call update once | ||
210 | LLWLParamManager::instance()->mAnimator.update( | ||
211 | LLWLParamManager::instance()->mCurParams); | ||
212 | } | ||
213 | else if (selected == self->getString("midnight")) | ||
214 | { | ||
215 | // set the value, turn off animation | ||
216 | LLWLParamManager::instance()->mAnimator.setDayTime(0.0); | ||
217 | LLWLParamManager::instance()->mAnimator.mIsRunning = false; | ||
218 | LLWLParamManager::instance()->mAnimator.mUseLindenTime = false; | ||
219 | |||
220 | // then call update once | ||
221 | LLWLParamManager::instance()->mAnimator.update( | ||
222 | LLWLParamManager::instance()->mCurParams); | ||
223 | } | ||
224 | else if (selected == self->getString("revert_region")) | ||
225 | { | ||
226 | LLWLParamManager::instance()->mAnimator.mIsRunning = true; | ||
227 | LLWLParamManager::instance()->mAnimator.mUseLindenTime = true; | ||
228 | } | ||
229 | else | ||
230 | { | ||
231 | // Apply preset | ||
232 | LLWLParamManager::instance()->loadPreset(selected); | ||
233 | } | ||
234 | } | ||
235 | } | ||
236 | |||
237 | // static | ||
238 | void LLWindlightRemoteCtrl::onClickToggleEnvironment(void* data) | ||
239 | { | ||
240 | // if evn settings not there or is hidden, show it | ||
241 | if( !LLFloaterEnvSettings::isOpen() || | ||
242 | !LLFloaterEnvSettings::instance()->getVisible()) | ||
243 | { | ||
244 | LLFloaterEnvSettings::show(); | ||
245 | |||
246 | // otherwise, close it button acts like a toggle | ||
247 | } | ||
248 | else | ||
249 | { | ||
250 | LLFloaterEnvSettings::instance()->close(); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | //static | ||
255 | void LLWindlightRemoteCtrl::onClickPopupBtn(void* data) | ||
256 | { | ||
257 | LLWindlightRemoteCtrl* remotep = (LLWindlightRemoteCtrl*)data; | ||
258 | |||
259 | remotep->deleteAllChildren(); | ||
260 | remotep->build(); | ||
261 | gOverlayBar->layoutButtons(); | ||
262 | } | ||