/indra/newview/llfloaterpostprocess.cpp
C++ | 229 lines | 145 code | 38 blank | 46 comment | 5 complexity | d0ee4044f15353f85d46e2599a97393e MD5 | raw file
Possible License(s): LGPL-2.1
1/**
2 * @file llfloaterpostprocess.cpp
3 * @brief LLFloaterPostProcess class definition
4 *
5 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
6 * Second Life Viewer Source Code
7 * Copyright (C) 2010, Linden Research, Inc.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 *
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
24 * $/LicenseInfo$
25 */
26
27#include "llviewerprecompiledheaders.h"
28
29#include "llfloaterpostprocess.h"
30
31#include "llsliderctrl.h"
32#include "llcheckboxctrl.h"
33#include "llnotificationsutil.h"
34#include "lluictrlfactory.h"
35#include "llviewerdisplay.h"
36#include "llpostprocess.h"
37#include "llcombobox.h"
38#include "lllineeditor.h"
39#include "llviewerwindow.h"
40
41
42LLFloaterPostProcess::LLFloaterPostProcess(const LLSD& key)
43 : LLFloater(key)
44{
45}
46
47LLFloaterPostProcess::~LLFloaterPostProcess()
48{
49
50
51}
52BOOL LLFloaterPostProcess::postBuild()
53{
54 /// Color Filter Callbacks
55 childSetCommitCallback("ColorFilterToggle", &LLFloaterPostProcess::onBoolToggle, (char*)"enable_color_filter");
56 //childSetCommitCallback("ColorFilterGamma", &LLFloaterPostProcess::onFloatControlMoved, &(gPostProcess->tweaks.gamma()));
57 childSetCommitCallback("ColorFilterBrightness", &LLFloaterPostProcess::onFloatControlMoved, (char*)"brightness");
58 childSetCommitCallback("ColorFilterSaturation", &LLFloaterPostProcess::onFloatControlMoved, (char*)"saturation");
59 childSetCommitCallback("ColorFilterContrast", &LLFloaterPostProcess::onFloatControlMoved, (char*)"contrast");
60
61 childSetCommitCallback("ColorFilterBaseR", &LLFloaterPostProcess::onColorControlRMoved, (char*)"contrast_base");
62 childSetCommitCallback("ColorFilterBaseG", &LLFloaterPostProcess::onColorControlGMoved, (char*)"contrast_base");
63 childSetCommitCallback("ColorFilterBaseB", &LLFloaterPostProcess::onColorControlBMoved, (char*)"contrast_base");
64 childSetCommitCallback("ColorFilterBaseI", &LLFloaterPostProcess::onColorControlIMoved, (char*)"contrast_base");
65
66 /// Night Vision Callbacks
67 childSetCommitCallback("NightVisionToggle", &LLFloaterPostProcess::onBoolToggle, (char*)"enable_night_vision");
68 childSetCommitCallback("NightVisionBrightMult", &LLFloaterPostProcess::onFloatControlMoved, (char*)"brightness_multiplier");
69 childSetCommitCallback("NightVisionNoiseSize", &LLFloaterPostProcess::onFloatControlMoved, (char*)"noise_size");
70 childSetCommitCallback("NightVisionNoiseStrength", &LLFloaterPostProcess::onFloatControlMoved, (char*)"noise_strength");
71
72 /// Bloom Callbacks
73 childSetCommitCallback("BloomToggle", &LLFloaterPostProcess::onBoolToggle, (char*)"enable_bloom");
74 childSetCommitCallback("BloomExtract", &LLFloaterPostProcess::onFloatControlMoved, (char*)"extract_low");
75 childSetCommitCallback("BloomSize", &LLFloaterPostProcess::onFloatControlMoved, (char*)"bloom_width");
76 childSetCommitCallback("BloomStrength", &LLFloaterPostProcess::onFloatControlMoved, (char*)"bloom_strength");
77
78 // Effect loading and saving.
79 LLComboBox* comboBox = getChild<LLComboBox>("PPEffectsCombo");
80 getChild<LLComboBox>("PPLoadEffect")->setCommitCallback(boost::bind(&LLFloaterPostProcess::onLoadEffect, this, comboBox));
81 comboBox->setCommitCallback(boost::bind(&LLFloaterPostProcess::onChangeEffectName, this, _1));
82
83 LLLineEditor* editBox = getChild<LLLineEditor>("PPEffectNameEditor");
84 getChild<LLComboBox>("PPSaveEffect")->setCommitCallback(boost::bind(&LLFloaterPostProcess::onSaveEffect, this, editBox));
85
86 syncMenu();
87 return TRUE;
88}
89
90// Bool Toggle
91void LLFloaterPostProcess::onBoolToggle(LLUICtrl* ctrl, void* userData)
92{
93 char const * boolVariableName = (char const *)userData;
94
95 // check the bool
96 LLCheckBoxCtrl* cbCtrl = static_cast<LLCheckBoxCtrl*>(ctrl);
97 gPostProcess->tweaks[boolVariableName] = cbCtrl->getValue();
98}
99
100// Float Moved
101void LLFloaterPostProcess::onFloatControlMoved(LLUICtrl* ctrl, void* userData)
102{
103 char const * floatVariableName = (char const *)userData;
104 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
105 gPostProcess->tweaks[floatVariableName] = sldrCtrl->getValue();
106}
107
108// Color Moved
109void LLFloaterPostProcess::onColorControlRMoved(LLUICtrl* ctrl, void* userData)
110{
111 char const * floatVariableName = (char const *)userData;
112 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
113 gPostProcess->tweaks[floatVariableName][0] = sldrCtrl->getValue();
114}
115
116// Color Moved
117void LLFloaterPostProcess::onColorControlGMoved(LLUICtrl* ctrl, void* userData)
118{
119 char const * floatVariableName = (char const *)userData;
120 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
121 gPostProcess->tweaks[floatVariableName][1] = sldrCtrl->getValue();
122}
123
124// Color Moved
125void LLFloaterPostProcess::onColorControlBMoved(LLUICtrl* ctrl, void* userData)
126{
127 char const * floatVariableName = (char const *)userData;
128 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
129 gPostProcess->tweaks[floatVariableName][2] = sldrCtrl->getValue();
130}
131
132// Color Moved
133void LLFloaterPostProcess::onColorControlIMoved(LLUICtrl* ctrl, void* userData)
134{
135 char const * floatVariableName = (char const *)userData;
136 LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
137 gPostProcess->tweaks[floatVariableName][3] = sldrCtrl->getValue();
138}
139
140void LLFloaterPostProcess::onLoadEffect(LLComboBox* comboBox)
141{
142 LLSD::String effectName(comboBox->getSelectedValue().asString());
143
144 gPostProcess->setSelectedEffect(effectName);
145
146 syncMenu();
147}
148
149void LLFloaterPostProcess::onSaveEffect(LLLineEditor* editBox)
150{
151 std::string effectName(editBox->getValue().asString());
152
153 if (gPostProcess->mAllEffects.has(effectName))
154 {
155 LLSD payload;
156 payload["effect_name"] = effectName;
157 LLNotificationsUtil::add("PPSaveEffectAlert", LLSD(), payload, boost::bind(&LLFloaterPostProcess::saveAlertCallback, this, _1, _2));
158 }
159 else
160 {
161 gPostProcess->saveEffect(effectName);
162 syncMenu();
163 }
164}
165
166void LLFloaterPostProcess::onChangeEffectName(LLUICtrl* ctrl)
167{
168 // get the combo box and name
169 LLLineEditor* editBox = getChild<LLLineEditor>("PPEffectNameEditor");
170
171 // set the parameter's new name
172 editBox->setValue(ctrl->getValue());
173}
174
175bool LLFloaterPostProcess::saveAlertCallback(const LLSD& notification, const LLSD& response)
176{
177 S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
178
179 // if they choose save, do it. Otherwise, don't do anything
180 if (option == 0)
181 {
182 gPostProcess->saveEffect(notification["payload"]["effect_name"].asString());
183
184 syncMenu();
185 }
186 return false;
187}
188
189void LLFloaterPostProcess::syncMenu()
190{
191 // add the combo boxe contents
192 LLComboBox* comboBox = getChild<LLComboBox>("PPEffectsCombo");
193
194 comboBox->removeall();
195
196 LLSD::map_const_iterator currEffect;
197 for(currEffect = gPostProcess->mAllEffects.beginMap();
198 currEffect != gPostProcess->mAllEffects.endMap();
199 ++currEffect)
200 {
201 comboBox->add(currEffect->first);
202 }
203
204 // set the current effect as selected.
205 comboBox->selectByValue(gPostProcess->getSelectedEffect());
206
207 /// Sync Color Filter Menu
208 getChild<LLUICtrl>("ColorFilterToggle")->setValue(gPostProcess->tweaks.useColorFilter());
209 //getChild<LLUICtrl>("ColorFilterGamma")->setValue(gPostProcess->tweaks.gamma());
210 getChild<LLUICtrl>("ColorFilterBrightness")->setValue(gPostProcess->tweaks.brightness());
211 getChild<LLUICtrl>("ColorFilterSaturation")->setValue(gPostProcess->tweaks.saturation());
212 getChild<LLUICtrl>("ColorFilterContrast")->setValue(gPostProcess->tweaks.contrast());
213 getChild<LLUICtrl>("ColorFilterBaseR")->setValue(gPostProcess->tweaks.contrastBaseR());
214 getChild<LLUICtrl>("ColorFilterBaseG")->setValue(gPostProcess->tweaks.contrastBaseG());
215 getChild<LLUICtrl>("ColorFilterBaseB")->setValue(gPostProcess->tweaks.contrastBaseB());
216 getChild<LLUICtrl>("ColorFilterBaseI")->setValue(gPostProcess->tweaks.contrastBaseIntensity());
217
218 /// Sync Night Vision Menu
219 getChild<LLUICtrl>("NightVisionToggle")->setValue(gPostProcess->tweaks.useNightVisionShader());
220 getChild<LLUICtrl>("NightVisionBrightMult")->setValue(gPostProcess->tweaks.brightMult());
221 getChild<LLUICtrl>("NightVisionNoiseSize")->setValue(gPostProcess->tweaks.noiseSize());
222 getChild<LLUICtrl>("NightVisionNoiseStrength")->setValue(gPostProcess->tweaks.noiseStrength());
223
224 /// Sync Bloom Menu
225 getChild<LLUICtrl>("BloomToggle")->setValue(LLSD(gPostProcess->tweaks.useBloomShader()));
226 getChild<LLUICtrl>("BloomExtract")->setValue(gPostProcess->tweaks.extractLow());
227 getChild<LLUICtrl>("BloomSize")->setValue(gPostProcess->tweaks.bloomWidth());
228 getChild<LLUICtrl>("BloomStrength")->setValue(gPostProcess->tweaks.bloomStrength());
229}