diff options
Diffstat (limited to 'linden/indra/newview/llwindlightremotectrl.cpp')
-rw-r--r-- | linden/indra/newview/llwindlightremotectrl.cpp | 267 |
1 files changed, 267 insertions, 0 deletions
diff --git a/linden/indra/newview/llwindlightremotectrl.cpp b/linden/indra/newview/llwindlightremotectrl.cpp new file mode 100644 index 0000000..591b413 --- /dev/null +++ b/linden/indra/newview/llwindlightremotectrl.cpp | |||
@@ -0,0 +1,267 @@ | |||
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"); | ||
96 | } | ||
97 | else | ||
98 | { | ||
99 | LLUICtrlFactory::getInstance()->buildPanel(this, "panel_windlight_remote.xml"); | ||
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 | // snag current preset | ||
131 | LLWLParamManager * param_mgr = LLWLParamManager::instance(); | ||
132 | LLWLParamSet& currentParams = param_mgr->mCurParams; | ||
133 | |||
134 | // clear in case presets names have changed | ||
135 | mPresetsCombo->clearRows(); | ||
136 | |||
137 | std::map<std::string, LLWLParamSet>::iterator mIt = | ||
138 | param_mgr->mParamList.begin(); | ||
139 | for(; mIt != param_mgr->mParamList.end(); mIt++) | ||
140 | { | ||
141 | mPresetsCombo->add(mIt->first); | ||
142 | } | ||
143 | |||
144 | // insert separator and add World menu options | ||
145 | mPresetsCombo->addSeparator(ADD_BOTTOM); | ||
146 | mPresetsCombo->addSimpleElement(getString("sunrise"), ADD_BOTTOM); | ||
147 | mPresetsCombo->addSimpleElement(getString("noon"), ADD_BOTTOM); | ||
148 | mPresetsCombo->addSimpleElement(getString("sunset"), ADD_BOTTOM); | ||
149 | mPresetsCombo->addSimpleElement(getString("midnight"), ADD_BOTTOM); | ||
150 | mPresetsCombo->addSimpleElement(getString("revert_region"), ADD_BOTTOM); | ||
151 | |||
152 | if (mPresetsCombo->getSelectedItemLabel() != currentParams.mName && | ||
153 | !currentParams.mName.empty()) | ||
154 | { | ||
155 | mPresetsCombo->selectByValue(LLSD(currentParams.mName)); | ||
156 | } | ||
157 | else | ||
158 | { | ||
159 | mPresetsCombo->selectByValue(LLSD("Default")); | ||
160 | } | ||
161 | } | ||
162 | } | ||
163 | |||
164 | // static | ||
165 | void LLWindlightRemoteCtrl::onCommitPreset(LLUICtrl* ctrl, void* data) | ||
166 | { | ||
167 | LLWindlightRemoteCtrl* self = (LLWindlightRemoteCtrl*)data; | ||
168 | |||
169 | LLCtrlListInterface* presets = self->mPresetsCombo ? self->mPresetsCombo->getListInterface() : NULL; | ||
170 | if (presets) | ||
171 | { | ||
172 | S32 index = presets->getFirstSelectedIndex(); | ||
173 | if (index <= 0) | ||
174 | { | ||
175 | // Open Advanced Sky | ||
176 | LLFloaterWindLight::show(); | ||
177 | return; | ||
178 | } | ||
179 | |||
180 | // check for World menu options; if none, apply preset | ||
181 | std::string selected = self->mPresetsCombo->getSelectedValue().asString(); | ||
182 | |||
183 | if (selected == self->getString("sunrise")) | ||
184 | { | ||
185 | // set the value, turn off animation | ||
186 | LLWLParamManager::instance()->mAnimator.setDayTime(0.25); | ||
187 | LLWLParamManager::instance()->mAnimator.mIsRunning = false; | ||
188 | LLWLParamManager::instance()->mAnimator.mUseLindenTime = false; | ||
189 | |||
190 | // then call update once | ||
191 | LLWLParamManager::instance()->mAnimator.update( | ||
192 | LLWLParamManager::instance()->mCurParams); | ||
193 | } | ||
194 | else if (selected == self->getString("noon")) | ||
195 | { | ||
196 | // set the value, turn off animation | ||
197 | LLWLParamManager::instance()->mAnimator.setDayTime(0.567); | ||
198 | LLWLParamManager::instance()->mAnimator.mIsRunning = false; | ||
199 | LLWLParamManager::instance()->mAnimator.mUseLindenTime = false; | ||
200 | |||
201 | // then call update once | ||
202 | LLWLParamManager::instance()->mAnimator.update( | ||
203 | LLWLParamManager::instance()->mCurParams); | ||
204 | } | ||
205 | else if (selected == self->getString("sunset")) | ||
206 | { | ||
207 | // set the value, turn off animation | ||
208 | LLWLParamManager::instance()->mAnimator.setDayTime(0.75); | ||
209 | LLWLParamManager::instance()->mAnimator.mIsRunning = false; | ||
210 | LLWLParamManager::instance()->mAnimator.mUseLindenTime = false; | ||
211 | |||
212 | // then call update once | ||
213 | LLWLParamManager::instance()->mAnimator.update( | ||
214 | LLWLParamManager::instance()->mCurParams); | ||
215 | } | ||
216 | else if (selected == self->getString("midnight")) | ||
217 | { | ||
218 | // set the value, turn off animation | ||
219 | LLWLParamManager::instance()->mAnimator.setDayTime(0.0); | ||
220 | LLWLParamManager::instance()->mAnimator.mIsRunning = false; | ||
221 | LLWLParamManager::instance()->mAnimator.mUseLindenTime = false; | ||
222 | |||
223 | // then call update once | ||
224 | LLWLParamManager::instance()->mAnimator.update( | ||
225 | LLWLParamManager::instance()->mCurParams); | ||
226 | } | ||
227 | else if (selected == self->getString("revert_region")) | ||
228 | { | ||
229 | LLWLParamManager::instance()->mAnimator.mIsRunning = true; | ||
230 | LLWLParamManager::instance()->mAnimator.mUseLindenTime = true; | ||
231 | } | ||
232 | else | ||
233 | { | ||
234 | // Apply preset | ||
235 | LLWLParamManager::instance()->mAnimator.mIsRunning = false; | ||
236 | LLWLParamManager::instance()->mAnimator.mUseLindenTime = false; | ||
237 | LLWLParamManager::instance()->loadPreset(selected, true); | ||
238 | } | ||
239 | } | ||
240 | } | ||
241 | |||
242 | // static | ||
243 | void LLWindlightRemoteCtrl::onClickToggleEnvironment(void* data) | ||
244 | { | ||
245 | // if evn settings not there or is hidden, show it | ||
246 | if( !LLFloaterEnvSettings::isOpen() || | ||
247 | !LLFloaterEnvSettings::instance()->getVisible()) | ||
248 | { | ||
249 | LLFloaterEnvSettings::show(); | ||
250 | |||
251 | // otherwise, close it button acts like a toggle | ||
252 | } | ||
253 | else | ||
254 | { | ||
255 | LLFloaterEnvSettings::instance()->close(); | ||
256 | } | ||
257 | } | ||
258 | |||
259 | //static | ||
260 | void LLWindlightRemoteCtrl::onClickPopupBtn(void* data) | ||
261 | { | ||
262 | LLWindlightRemoteCtrl* remotep = (LLWindlightRemoteCtrl*)data; | ||
263 | |||
264 | remotep->deleteAllChildren(); | ||
265 | remotep->build(); | ||
266 | gOverlayBar->layoutButtons(); | ||
267 | } | ||