aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llwindlightremotectrl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/llwindlightremotectrl.cpp')
-rw-r--r--linden/indra/newview/llwindlightremotectrl.cpp312
1 files changed, 312 insertions, 0 deletions
diff --git a/linden/indra/newview/llwindlightremotectrl.cpp b/linden/indra/newview/llwindlightremotectrl.cpp
new file mode 100644
index 0000000..f805763
--- /dev/null
+++ b/linden/indra/newview/llwindlightremotectrl.cpp
@@ -0,0 +1,312 @@
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 "llfloaterwater.h"
39#include "llfloaterwindlight.h"
40#include "lloverlaybar.h"
41#include "lluictrlfactory.h"
42#include "llwlparammanager.h"
43#include "llviewercontrol.h"
44
45// [RLVa:KB] - Alternate: Imprudence-1.2.0
46#include "rlvhandler.h"
47// [/RLVa:KB]
48
49class LLWindlightRemoteObserver : public LLWLPresetsObserver
50{
51public:
52 LLWindlightRemoteObserver(LLWindlightRemoteCtrl* wind_rem) : mWindlightRemote(wind_rem){}
53 virtual ~LLWindlightRemoteObserver() {}
54 virtual void changed() { mWindlightRemote->refreshPresets(); }
55private:
56 LLWindlightRemoteCtrl* mWindlightRemote;
57};
58
59
60LLWindlightRemoteCtrl::LLWindlightRemoteCtrl()
61{
62 mPresetsCombo = NULL;
63 mObserver = NULL;
64 setIsChrome(TRUE);
65
66 build();
67
68 setFocusRoot(TRUE);
69}
70
71LLWindlightRemoteCtrl::~LLWindlightRemoteCtrl()
72{
73 delete mObserver;
74 mObserver = NULL;
75}
76
77void LLWindlightRemoteCtrl::draw()
78{
79 LLButton* expand_button = getChild<LLButton>("Popup");
80 if (expand_button)
81 {
82 if (expand_button->getToggleState())
83 {
84 expand_button->setImageOverlay("arrow_down.tga");
85 }
86 else
87 {
88 expand_button->setImageOverlay("arrow_up.tga");
89 }
90 }
91
92// [RLVa:KB] - Alternate: Imprudence-1.2.0
93 if (rlv_handler_t::isEnabled())
94 {
95 childSetEnabled("Environment", !gRlvHandler.hasBehaviour(RLV_BHVR_SETENV));
96 mPresetsCombo->setEnabled(!gRlvHandler.hasBehaviour(RLV_BHVR_SETENV));
97 }
98// [/RLVA:KB]
99
100 LLPanel::draw();
101}
102
103void LLWindlightRemoteCtrl::build()
104{
105 if (gSavedSettings.getBOOL("ShowWindlightSettingsPopup"))
106 {
107 LLUICtrlFactory::getInstance()->buildPanel(this, "panel_windlight_remote_expanded.xml");
108 }
109 else
110 {
111 LLUICtrlFactory::getInstance()->buildPanel(this, "panel_windlight_remote.xml");
112 }
113}
114
115BOOL LLWindlightRemoteCtrl::postBuild()
116{
117
118 childSetAction("Environment", onClickToggleEnvironment, this);
119 childSetAction("Popup", onClickPopupBtn, this);
120
121 mPresetsCombo = getChild<LLComboBox>("Presets");
122 if (mPresetsCombo)
123 {
124 mPresetsCombo->setCommitCallback(onCommitPreset);
125 mPresetsCombo->setCallbackUserData(this);
126
127 // set up observer to follow changes
128 mObserver = new LLWindlightRemoteObserver(this);
129 LLWLParamManager::addObserver(mObserver);
130
131 // refresh list from current presets
132 refreshPresets();
133 }
134
135 return TRUE;
136}
137
138void LLWindlightRemoteCtrl::refreshPresets()
139{
140 if (mPresetsCombo)
141 {
142 // snag current preset
143 LLWLParamManager * param_mgr = LLWLParamManager::instance();
144 LLWLParamSet& currentParams = param_mgr->mCurParams;
145
146 // clear in case presets names have changed
147 mPresetsCombo->clearRows();
148
149 std::map<std::string, LLWLParamSet>::iterator mIt =
150 param_mgr->mParamList.begin();
151 for(; mIt != param_mgr->mParamList.end(); mIt++)
152 {
153 mPresetsCombo->add(mIt->first);
154 }
155
156 // insert separator and add World menu options
157 mPresetsCombo->addSeparator(ADD_BOTTOM);
158 mPresetsCombo->addSimpleElement(getString("atmosphere"), ADD_BOTTOM);
159 mPresetsCombo->addSimpleElement(getString("lighting"), ADD_BOTTOM);
160 mPresetsCombo->addSimpleElement(getString("clouds"), ADD_BOTTOM);
161 mPresetsCombo->addSimpleElement(getString("advanced_water"), ADD_BOTTOM);
162 mPresetsCombo->addSeparator(ADD_BOTTOM);
163 mPresetsCombo->addSimpleElement(getString("sunrise"), ADD_BOTTOM);
164 mPresetsCombo->addSimpleElement(getString("noon"), ADD_BOTTOM);
165 mPresetsCombo->addSimpleElement(getString("sunset"), ADD_BOTTOM);
166 mPresetsCombo->addSimpleElement(getString("midnight"), ADD_BOTTOM);
167 mPresetsCombo->addSimpleElement(getString("revert_region"), ADD_BOTTOM);
168
169 if (mPresetsCombo->getSelectedItemLabel() != currentParams.mName &&
170 !currentParams.mName.empty())
171 {
172 mPresetsCombo->selectByValue(LLSD(currentParams.mName));
173 }
174 else
175 {
176 mPresetsCombo->selectByValue(LLSD("Default"));
177 }
178 }
179}
180
181// static
182void LLWindlightRemoteCtrl::onCommitPreset(LLUICtrl* ctrl, void* data)
183{
184 LLWindlightRemoteCtrl* self = (LLWindlightRemoteCtrl*)data;
185
186 LLCtrlListInterface* presets = self->mPresetsCombo ? self->mPresetsCombo->getListInterface() : NULL;
187 if (presets)
188 {
189 S32 index = presets->getFirstSelectedIndex();
190 if (index < 0)
191 {
192 // Open Advanced Sky
193 LLFloaterWindLight::show();
194 return;
195 }
196
197 // check for World menu options; if none, apply preset
198 std::string selected = self->mPresetsCombo->getSelectedValue().asString();
199
200 if (selected == self->getString("atmosphere"))
201 {
202 if (!LLFloaterWindLight::instance()->getVisible())
203 {
204 LLFloaterWindLight::show();
205 }
206 LLFloaterWindLight::instance()->selectTab("Atmosphere");
207 }
208 else if (selected == self->getString("lighting"))
209 {
210 if (!LLFloaterWindLight::instance()->getVisible())
211 {
212 LLFloaterWindLight::show();
213 }
214 LLFloaterWindLight::instance()->selectTab("Lighting");
215 }
216 else if (selected == self->getString("clouds"))
217 {
218 if (!LLFloaterWindLight::instance()->getVisible())
219 {
220 LLFloaterWindLight::show();
221 }
222 LLFloaterWindLight::instance()->selectTab("Clouds");
223 }
224 else if (selected == self->getString("advanced_water"))
225 {
226 LLFloaterWater::show();
227 }
228 else if (selected == self->getString("sunrise"))
229 {
230 // set the value, turn off animation
231 LLWLParamManager::instance()->mAnimator.setDayTime(0.25);
232 LLWLParamManager::instance()->mAnimator.mIsRunning = false;
233 LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;
234
235 // then call update once
236 LLWLParamManager::instance()->mAnimator.update(
237 LLWLParamManager::instance()->mCurParams);
238 }
239 else if (selected == self->getString("noon"))
240 {
241 // set the value, turn off animation
242 LLWLParamManager::instance()->mAnimator.setDayTime(0.567);
243 LLWLParamManager::instance()->mAnimator.mIsRunning = false;
244 LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;
245
246 // then call update once
247 LLWLParamManager::instance()->mAnimator.update(
248 LLWLParamManager::instance()->mCurParams);
249 }
250 else if (selected == self->getString("sunset"))
251 {
252 // set the value, turn off animation
253 LLWLParamManager::instance()->mAnimator.setDayTime(0.75);
254 LLWLParamManager::instance()->mAnimator.mIsRunning = false;
255 LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;
256
257 // then call update once
258 LLWLParamManager::instance()->mAnimator.update(
259 LLWLParamManager::instance()->mCurParams);
260 }
261 else if (selected == self->getString("midnight"))
262 {
263 // set the value, turn off animation
264 LLWLParamManager::instance()->mAnimator.setDayTime(0.0);
265 LLWLParamManager::instance()->mAnimator.mIsRunning = false;
266 LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;
267
268 // then call update once
269 LLWLParamManager::instance()->mAnimator.update(
270 LLWLParamManager::instance()->mCurParams);
271 }
272 else if (selected == self->getString("revert_region"))
273 {
274 LLWLParamManager::instance()->mAnimator.mIsRunning = true;
275 LLWLParamManager::instance()->mAnimator.mUseLindenTime = true;
276 }
277 else
278 {
279 // Apply preset
280 LLWLParamManager::instance()->mAnimator.mIsRunning = false;
281 LLWLParamManager::instance()->mAnimator.mUseLindenTime = false;
282 LLWLParamManager::instance()->loadPreset(selected, true);
283 }
284 }
285}
286
287// static
288void LLWindlightRemoteCtrl::onClickToggleEnvironment(void* data)
289{
290 // if evn settings not there or is hidden, show it
291 if( !LLFloaterEnvSettings::isOpen() ||
292 !LLFloaterEnvSettings::instance()->getVisible())
293 {
294 LLFloaterEnvSettings::show();
295
296 // otherwise, close it button acts like a toggle
297 }
298 else
299 {
300 LLFloaterEnvSettings::instance()->close();
301 }
302}
303
304//static
305void LLWindlightRemoteCtrl::onClickPopupBtn(void* data)
306{
307 LLWindlightRemoteCtrl* remotep = (LLWindlightRemoteCtrl*)data;
308
309 remotep->deleteAllChildren();
310 remotep->build();
311 gOverlayBar->layoutButtons();
312}