diff options
author | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
commit | cd17687f01420952712a500107e0f93e7ab8d5f8 (patch) | |
tree | ce48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/newview/llfloaterenvsettings.cpp | |
parent | Second Life viewer sources 1.19.0.5 (diff) | |
download | meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2 meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz |
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/newview/llfloaterenvsettings.cpp')
-rw-r--r-- | linden/indra/newview/llfloaterenvsettings.cpp | 384 |
1 files changed, 384 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloaterenvsettings.cpp b/linden/indra/newview/llfloaterenvsettings.cpp new file mode 100644 index 0000000..6a0400c --- /dev/null +++ b/linden/indra/newview/llfloaterenvsettings.cpp | |||
@@ -0,0 +1,384 @@ | |||
1 | /** | ||
2 | * @file llfloaterenvsettings.cpp | ||
3 | * @brief LLFloaterEnvSettings class definition | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2007&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2007-2008, 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 http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | * $/LicenseInfo$ | ||
30 | */ | ||
31 | |||
32 | #include "llviewerprecompiledheaders.h" | ||
33 | |||
34 | #include "llfloaterenvsettings.h" | ||
35 | |||
36 | #include "llfloaterwindlight.h" | ||
37 | #include "llfloaterwater.h" | ||
38 | #include "llvieweruictrlfactory.h" | ||
39 | #include "llsliderctrl.h" | ||
40 | #include "llcombobox.h" | ||
41 | #include "llcolorswatch.h" | ||
42 | #include "llwlanimator.h" | ||
43 | |||
44 | #include "llwlparamset.h" | ||
45 | #include "llwlparammanager.h" | ||
46 | #include "llwaterparammanager.h" | ||
47 | #include "llmath.h" | ||
48 | #include "llviewerwindow.h" | ||
49 | |||
50 | #include "pipeline.h" | ||
51 | |||
52 | #include <sstream> | ||
53 | |||
54 | LLFloaterEnvSettings* LLFloaterEnvSettings::sEnvSettings = NULL; | ||
55 | |||
56 | LLFloaterEnvSettings::LLFloaterEnvSettings() : LLFloater("Environment Settings Floater") | ||
57 | { | ||
58 | gUICtrlFactory->buildFloater(this, "floater_env_settings.xml"); | ||
59 | |||
60 | // load it up | ||
61 | initCallbacks(); | ||
62 | } | ||
63 | |||
64 | LLFloaterEnvSettings::~LLFloaterEnvSettings() | ||
65 | { | ||
66 | } | ||
67 | |||
68 | void LLFloaterEnvSettings::onClickHelp(void* data) | ||
69 | { | ||
70 | LLFloaterEnvSettings* self = static_cast<LLFloaterEnvSettings*>(data); | ||
71 | |||
72 | const char* xml_alert = "EnvSettingsHelpButton"; | ||
73 | LLAlertDialog* dialogp = gViewerWindow->alertXml(xml_alert); | ||
74 | if (dialogp) | ||
75 | { | ||
76 | LLFloater* root_floater = gFloaterView->getParentFloater(self); | ||
77 | if (root_floater) | ||
78 | { | ||
79 | root_floater->addDependentFloater(dialogp); | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | |||
84 | void LLFloaterEnvSettings::initCallbacks(void) | ||
85 | { | ||
86 | // our three sliders | ||
87 | childSetCommitCallback("EnvTimeSlider", onChangeDayTime, NULL); | ||
88 | childSetCommitCallback("EnvCloudSlider", onChangeCloudCoverage, NULL); | ||
89 | childSetCommitCallback("EnvWaterFogSlider", onChangeWaterFogDensity, | ||
90 | &LLWaterParamManager::instance()->mFogDensity); | ||
91 | |||
92 | // color picker | ||
93 | childSetCommitCallback("EnvWaterColor", onChangeWaterColor, | ||
94 | &LLWaterParamManager::instance()->mFogColor); | ||
95 | |||
96 | // WL Top | ||
97 | childSetAction("EnvAdvancedSkyButton", onOpenAdvancedSky, NULL); | ||
98 | childSetAction("EnvAdvancedWaterButton", onOpenAdvancedWater, NULL); | ||
99 | childSetAction("EnvUseEstateTimeButton", onUseEstateTime, NULL); | ||
100 | childSetAction("EnvSettingsHelpButton", onClickHelp, this); | ||
101 | } | ||
102 | |||
103 | |||
104 | // menu maintenance functions | ||
105 | |||
106 | void LLFloaterEnvSettings::syncMenu() | ||
107 | { | ||
108 | LLSliderCtrl* sldr; | ||
109 | sldr = LLUICtrlFactory::getSliderByName(sEnvSettings, | ||
110 | "EnvTimeSlider"); | ||
111 | if(NULL == sldr) | ||
112 | { | ||
113 | return; | ||
114 | } | ||
115 | |||
116 | // sync the clock | ||
117 | F32 val = (F32)LLWLParamManager::instance()->mAnimator.getDayTime(); | ||
118 | LLString timeStr = timeToString(val); | ||
119 | |||
120 | LLTextBox* textBox; | ||
121 | textBox = LLUICtrlFactory::getTextBoxByName(sEnvSettings, | ||
122 | "EnvTimeText"); | ||
123 | if(NULL == textBox) | ||
124 | { | ||
125 | return; | ||
126 | } | ||
127 | |||
128 | textBox->setValue(timeStr); | ||
129 | |||
130 | // sync time slider which starts at 6 AM | ||
131 | val -= 0.25; | ||
132 | if(val < 0) | ||
133 | { | ||
134 | val++; | ||
135 | } | ||
136 | sldr->setValue(val); | ||
137 | |||
138 | // sync cloud coverage | ||
139 | bool err; | ||
140 | childSetValue("EnvCloudSlider", LLWLParamManager::instance()->mCurParams.getFloat("cloud_shadow", err)); | ||
141 | |||
142 | LLWaterParamManager * param_mgr = LLWaterParamManager::instance(); | ||
143 | // sync water params | ||
144 | LLColor4 col = param_mgr->getFogColor(); | ||
145 | LLColorSwatchCtrl* colCtrl = sEnvSettings->getChild<LLColorSwatchCtrl>("EnvWaterColor"); | ||
146 | col.mV[3] = 1.0f; | ||
147 | colCtrl->set(col); | ||
148 | |||
149 | childSetValue("EnvWaterFogSlider", param_mgr->mFogDensity.mExp); | ||
150 | param_mgr->setDensitySliderValue(param_mgr->mFogDensity.mExp); | ||
151 | |||
152 | // turn off Use Estate Time button if it's already being used | ||
153 | if(LLWLParamManager::instance()->mAnimator.mUseLindenTime) | ||
154 | { | ||
155 | childDisable("EnvUseEstateTimeButton"); | ||
156 | } else { | ||
157 | childEnable("EnvUseEstateTimeButton"); | ||
158 | } | ||
159 | |||
160 | if(!gPipeline.canUseVertexShaders()) | ||
161 | { | ||
162 | childDisable("EnvWaterColor"); | ||
163 | childDisable("EnvWaterColorText"); | ||
164 | //childDisable("EnvAdvancedWaterButton"); | ||
165 | } | ||
166 | else | ||
167 | { | ||
168 | childEnable("EnvWaterColor"); | ||
169 | childEnable("EnvWaterColorText"); | ||
170 | //childEnable("EnvAdvancedWaterButton"); | ||
171 | } | ||
172 | |||
173 | // only allow access to these if they are using windlight | ||
174 | if(!gPipeline.canUseWindLightShaders()) | ||
175 | { | ||
176 | |||
177 | childDisable("EnvCloudSlider"); | ||
178 | childDisable("EnvCloudText"); | ||
179 | //childDisable("EnvAdvancedSkyButton"); | ||
180 | } | ||
181 | else | ||
182 | { | ||
183 | childEnable("EnvCloudSlider"); | ||
184 | childEnable("EnvCloudText"); | ||
185 | //childEnable("EnvAdvancedSkyButton"); | ||
186 | } | ||
187 | } | ||
188 | |||
189 | |||
190 | // static instance of it | ||
191 | LLFloaterEnvSettings* LLFloaterEnvSettings::instance() | ||
192 | { | ||
193 | if (!sEnvSettings) | ||
194 | { | ||
195 | sEnvSettings = new LLFloaterEnvSettings(); | ||
196 | sEnvSettings->open(); | ||
197 | sEnvSettings->setFocus(TRUE); | ||
198 | } | ||
199 | return sEnvSettings; | ||
200 | } | ||
201 | void LLFloaterEnvSettings::show() | ||
202 | { | ||
203 | LLFloaterEnvSettings* envSettings = instance(); | ||
204 | envSettings->syncMenu(); | ||
205 | |||
206 | // comment in if you want the menu to rebuild each time | ||
207 | //gUICtrlFactory->buildFloater(envSettings, "floater_env_settings.xml"); | ||
208 | //envSettings->initCallbacks(); | ||
209 | |||
210 | envSettings->open(); | ||
211 | } | ||
212 | |||
213 | bool LLFloaterEnvSettings::isOpen() | ||
214 | { | ||
215 | if (sEnvSettings != NULL) | ||
216 | { | ||
217 | return true; | ||
218 | } | ||
219 | return false; | ||
220 | } | ||
221 | |||
222 | // virtual | ||
223 | void LLFloaterEnvSettings::onClose(bool app_quitting) | ||
224 | { | ||
225 | if (sEnvSettings) | ||
226 | { | ||
227 | sEnvSettings->setVisible(FALSE); | ||
228 | } | ||
229 | } | ||
230 | |||
231 | |||
232 | void LLFloaterEnvSettings::onChangeDayTime(LLUICtrl* ctrl, void* userData) | ||
233 | { | ||
234 | LLSliderCtrl* sldr; | ||
235 | sldr = LLUICtrlFactory::getSliderByName(sEnvSettings, | ||
236 | "EnvTimeSlider"); | ||
237 | |||
238 | // deactivate animator | ||
239 | LLWLParamManager::instance()->mAnimator.mIsRunning = false; | ||
240 | LLWLParamManager::instance()->mAnimator.mUseLindenTime = false; | ||
241 | |||
242 | F32 val = sldr->getValueF32() + 0.25f; | ||
243 | if(val > 1.0) | ||
244 | { | ||
245 | val--; | ||
246 | } | ||
247 | |||
248 | LLWLParamManager::instance()->mAnimator.setDayTime((F64)val); | ||
249 | LLWLParamManager::instance()->mAnimator.update( | ||
250 | LLWLParamManager::instance()->mCurParams); | ||
251 | } | ||
252 | |||
253 | void LLFloaterEnvSettings::onChangeCloudCoverage(LLUICtrl* ctrl, void* userData) | ||
254 | { | ||
255 | LLSliderCtrl* sldr; | ||
256 | sldr = LLUICtrlFactory::getSliderByName(sEnvSettings, | ||
257 | "EnvCloudSlider"); | ||
258 | |||
259 | // deactivate animator | ||
260 | //LLWLParamManager::instance()->mAnimator.mIsRunning = false; | ||
261 | //LLWLParamManager::instance()->mAnimator.mUseLindenTime = false; | ||
262 | |||
263 | F32 val = sldr->getValueF32(); | ||
264 | LLWLParamManager::instance()->mCurParams.set("cloud_shadow", val); | ||
265 | } | ||
266 | |||
267 | void LLFloaterEnvSettings::onChangeWaterFogDensity(LLUICtrl* ctrl, void* userData) | ||
268 | { | ||
269 | LLSliderCtrl* sldr; | ||
270 | sldr = LLUICtrlFactory::getSliderByName(sEnvSettings, | ||
271 | "EnvWaterFogSlider"); | ||
272 | |||
273 | if(NULL == sldr || NULL == userData) | ||
274 | { | ||
275 | return; | ||
276 | } | ||
277 | |||
278 | WaterExpFloatControl * expFloatControl = static_cast<WaterExpFloatControl *>(userData); | ||
279 | |||
280 | F32 val = sldr->getValueF32(); | ||
281 | expFloatControl->mExp = val; | ||
282 | LLWaterParamManager::instance()->setDensitySliderValue(val); | ||
283 | |||
284 | expFloatControl->update(LLWaterParamManager::instance()->mCurParams); | ||
285 | LLWaterParamManager::instance()->propagateParameters(); | ||
286 | } | ||
287 | |||
288 | void LLFloaterEnvSettings::onChangeWaterColor(LLUICtrl* ctrl, void* userData) | ||
289 | { | ||
290 | LLColorSwatchCtrl* swatch = static_cast<LLColorSwatchCtrl*>(ctrl); | ||
291 | WaterColorControl * colorControl = static_cast<WaterColorControl *>(userData); | ||
292 | *colorControl = swatch->get(); | ||
293 | |||
294 | colorControl->update(LLWaterParamManager::instance()->mCurParams); | ||
295 | LLWaterParamManager::instance()->propagateParameters(); | ||
296 | } | ||
297 | |||
298 | |||
299 | void LLFloaterEnvSettings::onOpenAdvancedSky(void* userData) | ||
300 | { | ||
301 | LLFloaterWindLight::show(); | ||
302 | } | ||
303 | |||
304 | void LLFloaterEnvSettings::onOpenAdvancedWater(void* userData) | ||
305 | { | ||
306 | LLFloaterWater::show(); | ||
307 | } | ||
308 | |||
309 | |||
310 | void LLFloaterEnvSettings::onUseEstateTime(void* userData) | ||
311 | { | ||
312 | if(LLFloaterWindLight::isOpen()) | ||
313 | { | ||
314 | // select the blank value in | ||
315 | LLFloaterWindLight* wl = LLFloaterWindLight::instance(); | ||
316 | LLComboBox* box = LLUICtrlFactory::getComboBoxByName(wl, "WLPresetsCombo"); | ||
317 | box->selectByValue(""); | ||
318 | } | ||
319 | |||
320 | LLWLParamManager::instance()->mAnimator.mIsRunning = true; | ||
321 | LLWLParamManager::instance()->mAnimator.mUseLindenTime = true; | ||
322 | } | ||
323 | |||
324 | LLString LLFloaterEnvSettings::timeToString(F32 curTime) | ||
325 | { | ||
326 | S32 hours; | ||
327 | S32 min; | ||
328 | bool isPM = false; | ||
329 | |||
330 | // get hours and minutes | ||
331 | hours = (S32) (24.0 * curTime); | ||
332 | curTime -= ((F32) hours / 24.0f); | ||
333 | min = llround(24.0f * 60.0f * curTime); | ||
334 | |||
335 | // handle case where it's 60 | ||
336 | if(min == 60) | ||
337 | { | ||
338 | hours++; | ||
339 | min = 0; | ||
340 | } | ||
341 | |||
342 | // set for PM | ||
343 | if(hours >= 12 && hours < 24) | ||
344 | { | ||
345 | isPM = true; | ||
346 | } | ||
347 | |||
348 | // convert to non-military notation | ||
349 | if(hours >= 24) | ||
350 | { | ||
351 | hours = 12; | ||
352 | } | ||
353 | else if(hours > 12) | ||
354 | { | ||
355 | hours -= 12; | ||
356 | } | ||
357 | else if(hours == 0) | ||
358 | { | ||
359 | hours = 12; | ||
360 | } | ||
361 | |||
362 | // make the string | ||
363 | std::stringstream newTime; | ||
364 | newTime << hours << ":"; | ||
365 | |||
366 | // double 0 | ||
367 | if(min < 10) | ||
368 | { | ||
369 | newTime << 0; | ||
370 | } | ||
371 | |||
372 | // finish it | ||
373 | newTime << min << " "; | ||
374 | if(isPM) | ||
375 | { | ||
376 | newTime << "PM"; | ||
377 | } | ||
378 | else | ||
379 | { | ||
380 | newTime << "AM"; | ||
381 | } | ||
382 | |||
383 | return newTime.str(); | ||
384 | } | ||