From 6a5e203884e73e2f2cb61dab7321062277708c73 Mon Sep 17 00:00:00 2001 From: Shyotl Date: Sat, 17 Dec 2011 00:20:54 -0600 Subject: [PATCH] Remove hardcoded var passing between LLPostProcess and its floater. Now driven through the xml file. --- indra/newview/llfloaterpostprocess.cpp | 145 +++++++----------- indra/newview/llfloaterpostprocess.h | 7 +- .../xui/en-us/floater_post_process.xml | 68 ++++---- 3 files changed, 92 insertions(+), 128 deletions(-) diff --git a/indra/newview/llfloaterpostprocess.cpp b/indra/newview/llfloaterpostprocess.cpp index 095e23050..bc72bf9ba 100644 --- a/indra/newview/llfloaterpostprocess.cpp +++ b/indra/newview/llfloaterpostprocess.cpp @@ -43,7 +43,11 @@ #include "llcombobox.h" #include "lllineeditor.h" #include "llviewerwindow.h" - +#if LL_MSVC +// disable boost::lexical_cast warning +#pragma warning (disable:4702) +#endif +#include LLFloaterPostProcess* LLFloaterPostProcess::sPostProcess = NULL; @@ -52,27 +56,31 @@ LLFloaterPostProcess::LLFloaterPostProcess() : LLFloater(std::string("Post-Proce { LLUICtrlFactory::getInstance()->buildFloater(this, "floater_post_process.xml"); - /// Color Filter Callbacks - childSetCommitCallback("ColorFilterToggle", &LLFloaterPostProcess::onBoolToggle, (char*)"enable_color_filter"); - childSetCommitCallback("ColorFilterGamma", &LLFloaterPostProcess::onFloatControlMoved, (char*)"gamma"); - childSetCommitCallback("ColorFilterBrightness", &LLFloaterPostProcess::onFloatControlMoved, (char*)"brightness"); - childSetCommitCallback("ColorFilterSaturation", &LLFloaterPostProcess::onFloatControlMoved, (char*)"saturation"); - childSetCommitCallback("ColorFilterContrast", &LLFloaterPostProcess::onFloatControlMoved, (char*)"contrast"); + LLTabContainer *panel_list = getChild("Post-Process Tabs",false,false); //Contains a tab for each shader + if(panel_list) + { + //Iterate down tabs to access each panel + for(S32 i = 0; igetTabCount(); ++i) + { + //Get the panel via index + LLPanel *shader_panel = panel_list->getPanelByIndex(i); - childSetCommitCallback("ColorFilterBaseR", &LLFloaterPostProcess::onColorControlRMoved, (char*)"contrast_base"); - childSetCommitCallback("ColorFilterBaseG", &LLFloaterPostProcess::onColorControlGMoved, (char*)"contrast_base"); - childSetCommitCallback("ColorFilterBaseB", &LLFloaterPostProcess::onColorControlBMoved, (char*)"contrast_base"); - childSetCommitCallback("ColorFilterBaseI", &LLFloaterPostProcess::onColorControlIMoved, (char*)"contrast_base"); + //'Extra' panel controls loading/saving. No uniforms should be altered in this panel. + if(shader_panel->getName() == "Extras") + continue; - /// Night Vision Callbacks - childSetCommitCallback("NightVisionToggle", &LLFloaterPostProcess::onBoolToggle, (char*)"enable_night_vision"); - childSetCommitCallback("NightVisionBrightMult", &LLFloaterPostProcess::onFloatControlMoved, (char*)"brightness_multiplier"); - childSetCommitCallback("NightVisionNoiseSize", &LLFloaterPostProcess::onFloatControlMoved, (char*)"noise_size"); - childSetCommitCallback("NightVisionNoiseStrength", &LLFloaterPostProcess::onFloatControlMoved, (char*)"noise_strength"); - - // Gauss Blur Callbacks - childSetCommitCallback("GaussBlurToggle", &LLFloaterPostProcess::onBoolToggle, (char*)"enable_gauss_blur"); - childSetCommitCallback("GaussBlurPasses", &LLFloaterPostProcess::onFloatControlMoved, (char*)"gauss_blur_passes"); + //Iterate down children elements of each panel. + for ( child_list_const_iter_t child_it = shader_panel->getChildList()->begin(); child_it != shader_panel->getChildList()->end(); ++child_it) + { + //Hacky, but for now checkboxes and sliders are assumed to link to shader uniforms. + if(dynamic_cast(*child_it) || dynamic_cast(*child_it)) + { + LLUICtrl *ctrl = dynamic_cast(*child_it); + ctrl->setCommitCallback(boost::bind(&LLFloaterPostProcess::onControlChanged, _1, (void*)ctrl->getName().c_str())); + } + } + } + } // Effect loading and saving. LLComboBox* comboBox = getChild("PPEffectsCombo"); @@ -104,54 +112,20 @@ LLFloaterPostProcess* LLFloaterPostProcess::instance() return sPostProcess; } -// Bool Toggle -void LLFloaterPostProcess::onBoolToggle(LLUICtrl* ctrl, void* userData) -{ - char const * boolVariableName = (char const *)userData; - - // check the bool - LLCheckBoxCtrl* cbCtrl = static_cast(ctrl); - LLPostProcess::getInstance()->tweaks[boolVariableName] = cbCtrl->getValue(); -} -// Float Moved -void LLFloaterPostProcess::onFloatControlMoved(LLUICtrl* ctrl, void* userData) +void LLFloaterPostProcess::onControlChanged(LLUICtrl* ctrl, void* userData) { - char const * floatVariableName = (char const *)userData; - LLSliderCtrl* sldrCtrl = static_cast(ctrl); - LLPostProcess::getInstance()->tweaks[floatVariableName] = sldrCtrl->getValue(); -} - -// Color Moved -void LLFloaterPostProcess::onColorControlRMoved(LLUICtrl* ctrl, void* userData) -{ - char const * floatVariableName = (char const *)userData; - LLSliderCtrl* sldrCtrl = static_cast(ctrl); - LLPostProcess::getInstance()->tweaks[floatVariableName][0] = sldrCtrl->getValue(); -} - -// Color Moved -void LLFloaterPostProcess::onColorControlGMoved(LLUICtrl* ctrl, void* userData) -{ - char const * floatVariableName = (char const *)userData; - LLSliderCtrl* sldrCtrl = static_cast(ctrl); - LLPostProcess::getInstance()->tweaks[floatVariableName][1] = sldrCtrl->getValue(); -} - -// Color Moved -void LLFloaterPostProcess::onColorControlBMoved(LLUICtrl* ctrl, void* userData) -{ - char const * floatVariableName = (char const *)userData; - LLSliderCtrl* sldrCtrl = static_cast(ctrl); - LLPostProcess::getInstance()->tweaks[floatVariableName][2] = sldrCtrl->getValue(); -} - -// Color Moved -void LLFloaterPostProcess::onColorControlIMoved(LLUICtrl* ctrl, void* userData) -{ - char const * floatVariableName = (char const *)userData; - LLSliderCtrl* sldrCtrl = static_cast(ctrl); - LLPostProcess::getInstance()->tweaks[floatVariableName][3] = sldrCtrl->getValue(); + char const *VariableName = (char const *)userData; + char buf[256]; + S32 elem=0; + if(sscanf(VariableName,"%255[^[][%d]", buf, &elem) == 2) + { + LLPostProcess::getInstance()->tweaks[buf][elem] = ctrl->getValue(); + } + else + { + LLPostProcess::getInstance()->tweaks[VariableName] = ctrl->getValue(); + } } void LLFloaterPostProcess::onLoadEffect(void* userData) @@ -245,24 +219,23 @@ void LLFloaterPostProcess::syncMenu() // set the current effect as selected. comboBox->selectByValue(LLPostProcess::getInstance()->getSelectedEffect()); - /// Sync Color Filter Menu - childSetValue("ColorFilterToggle", LLPostProcess::getInstance()->tweaks.useColorFilter()); - childSetValue("ColorFilterGamma", LLPostProcess::getInstance()->tweaks.getGamma()); - childSetValue("ColorFilterBrightness", LLPostProcess::getInstance()->tweaks.brightness()); - childSetValue("ColorFilterSaturation", LLPostProcess::getInstance()->tweaks.saturation()); - childSetValue("ColorFilterContrast", LLPostProcess::getInstance()->tweaks.contrast()); - childSetValue("ColorFilterBaseR", LLPostProcess::getInstance()->tweaks.contrastBaseR()); - childSetValue("ColorFilterBaseG", LLPostProcess::getInstance()->tweaks.contrastBaseG()); - childSetValue("ColorFilterBaseB", LLPostProcess::getInstance()->tweaks.contrastBaseB()); - childSetValue("ColorFilterBaseI", LLPostProcess::getInstance()->tweaks.contrastBaseIntensity()); - - /// Sync Night Vision Menu - childSetValue("NightVisionToggle", LLPostProcess::getInstance()->tweaks.useNightVisionShader()); - childSetValue("NightVisionBrightMult", LLPostProcess::getInstance()->tweaks.brightMult()); - childSetValue("NightVisionNoiseSize", LLPostProcess::getInstance()->tweaks.noiseSize()); - childSetValue("NightVisionNoiseStrength", LLPostProcess::getInstance()->tweaks.noiseStrength()); - - /// Sync Gaussian Blur Menu - childSetValue("GaussBlurToggle", LLPostProcess::getInstance()->tweaks.useGaussBlurFilter()); - childSetValue("GaussBlurPasses", LLPostProcess::getInstance()->tweaks.getGaussBlurPasses()); + LLSD &tweaks = LLPostProcess::getInstance()->tweaks; + //Iterate down all uniforms handled by post-process shaders. Update any linked ui elements. + for (LLSD::map_const_iterator it = tweaks.beginMap(); it != tweaks.endMap(); ++it) + { + if(it->second.isArray()) + { + //llsd["uniform"][0]=>"uniform[0]" + //llsd["uniform"][1]=>"uniform[1]" + for(S32 i=0;isecond.size();++i) + { + childSetValue(it->first+"["+boost::lexical_cast(i)+"]",it->second[i]); + } + } + else + { + //llsd["uniform"]=>"uniform" + childSetValue(it->first,it->second); + } + } } diff --git a/indra/newview/llfloaterpostprocess.h b/indra/newview/llfloaterpostprocess.h index 08a3618c2..4f0ef7a63 100644 --- a/indra/newview/llfloaterpostprocess.h +++ b/indra/newview/llfloaterpostprocess.h @@ -58,12 +58,7 @@ public: static LLFloaterPostProcess* instance(); /// post process callbacks - static void onBoolToggle(LLUICtrl* ctrl, void* userData); - static void onFloatControlMoved(LLUICtrl* ctrl, void* userData); - static void onColorControlRMoved(LLUICtrl* ctrl, void* userData); - static void onColorControlGMoved(LLUICtrl* ctrl, void* userData); - static void onColorControlBMoved(LLUICtrl* ctrl, void* userData); - static void onColorControlIMoved(LLUICtrl* ctrl, void* userData); + static void onControlChanged(LLUICtrl* ctrl, void* userData); static void onLoadEffect(void* userData); static void onSaveEffect(void* userData); static void onChangeEffectName(LLUICtrl* ctrl, void * userData); diff --git a/indra/newview/skins/default/xui/en-us/floater_post_process.xml b/indra/newview/skins/default/xui/en-us/floater_post_process.xml index 58d538205..179a40e2e 100644 --- a/indra/newview/skins/default/xui/en-us/floater_post_process.xml +++ b/indra/newview/skins/default/xui/en-us/floater_post_process.xml @@ -9,9 +9,9 @@ - + left="14" mouse_opaque="true" name="enable_color_filter" width="200" /> Gamma - Brightness - Saturation - + name="saturation" show_text="true" value="1.0" width="200" /> Contrast - - Contrast Base Color + Contrast Base Colora - - - - - + left="14" mouse_opaque="true" name="enable_gauss_blur" width="200" /> + name="gauss_blur_passes" show_text="true" value="0.7" width="200" /> - + left="14" mouse_opaque="true" name="enable_night_vision" width="200" /> + name="brightness_multiplier" show_text="true" value="0.7" width="200" /> Noise Size - Noise Strength - + name="noise_strength" show_text="true" value="1.0" width="200" />