/indra/newview/llfloaterpostprocess.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 229 lines · 145 code · 38 blank · 46 comment · 5 complexity · d0ee4044f15353f85d46e2599a97393e MD5 · raw file

  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. #include "llviewerprecompiledheaders.h"
  27. #include "llfloaterpostprocess.h"
  28. #include "llsliderctrl.h"
  29. #include "llcheckboxctrl.h"
  30. #include "llnotificationsutil.h"
  31. #include "lluictrlfactory.h"
  32. #include "llviewerdisplay.h"
  33. #include "llpostprocess.h"
  34. #include "llcombobox.h"
  35. #include "lllineeditor.h"
  36. #include "llviewerwindow.h"
  37. LLFloaterPostProcess::LLFloaterPostProcess(const LLSD& key)
  38. : LLFloater(key)
  39. {
  40. }
  41. LLFloaterPostProcess::~LLFloaterPostProcess()
  42. {
  43. }
  44. BOOL LLFloaterPostProcess::postBuild()
  45. {
  46. /// Color Filter Callbacks
  47. childSetCommitCallback("ColorFilterToggle", &LLFloaterPostProcess::onBoolToggle, (char*)"enable_color_filter");
  48. //childSetCommitCallback("ColorFilterGamma", &LLFloaterPostProcess::onFloatControlMoved, &(gPostProcess->tweaks.gamma()));
  49. childSetCommitCallback("ColorFilterBrightness", &LLFloaterPostProcess::onFloatControlMoved, (char*)"brightness");
  50. childSetCommitCallback("ColorFilterSaturation", &LLFloaterPostProcess::onFloatControlMoved, (char*)"saturation");
  51. childSetCommitCallback("ColorFilterContrast", &LLFloaterPostProcess::onFloatControlMoved, (char*)"contrast");
  52. childSetCommitCallback("ColorFilterBaseR", &LLFloaterPostProcess::onColorControlRMoved, (char*)"contrast_base");
  53. childSetCommitCallback("ColorFilterBaseG", &LLFloaterPostProcess::onColorControlGMoved, (char*)"contrast_base");
  54. childSetCommitCallback("ColorFilterBaseB", &LLFloaterPostProcess::onColorControlBMoved, (char*)"contrast_base");
  55. childSetCommitCallback("ColorFilterBaseI", &LLFloaterPostProcess::onColorControlIMoved, (char*)"contrast_base");
  56. /// Night Vision Callbacks
  57. childSetCommitCallback("NightVisionToggle", &LLFloaterPostProcess::onBoolToggle, (char*)"enable_night_vision");
  58. childSetCommitCallback("NightVisionBrightMult", &LLFloaterPostProcess::onFloatControlMoved, (char*)"brightness_multiplier");
  59. childSetCommitCallback("NightVisionNoiseSize", &LLFloaterPostProcess::onFloatControlMoved, (char*)"noise_size");
  60. childSetCommitCallback("NightVisionNoiseStrength", &LLFloaterPostProcess::onFloatControlMoved, (char*)"noise_strength");
  61. /// Bloom Callbacks
  62. childSetCommitCallback("BloomToggle", &LLFloaterPostProcess::onBoolToggle, (char*)"enable_bloom");
  63. childSetCommitCallback("BloomExtract", &LLFloaterPostProcess::onFloatControlMoved, (char*)"extract_low");
  64. childSetCommitCallback("BloomSize", &LLFloaterPostProcess::onFloatControlMoved, (char*)"bloom_width");
  65. childSetCommitCallback("BloomStrength", &LLFloaterPostProcess::onFloatControlMoved, (char*)"bloom_strength");
  66. // Effect loading and saving.
  67. LLComboBox* comboBox = getChild<LLComboBox>("PPEffectsCombo");
  68. getChild<LLComboBox>("PPLoadEffect")->setCommitCallback(boost::bind(&LLFloaterPostProcess::onLoadEffect, this, comboBox));
  69. comboBox->setCommitCallback(boost::bind(&LLFloaterPostProcess::onChangeEffectName, this, _1));
  70. LLLineEditor* editBox = getChild<LLLineEditor>("PPEffectNameEditor");
  71. getChild<LLComboBox>("PPSaveEffect")->setCommitCallback(boost::bind(&LLFloaterPostProcess::onSaveEffect, this, editBox));
  72. syncMenu();
  73. return TRUE;
  74. }
  75. // Bool Toggle
  76. void LLFloaterPostProcess::onBoolToggle(LLUICtrl* ctrl, void* userData)
  77. {
  78. char const * boolVariableName = (char const *)userData;
  79. // check the bool
  80. LLCheckBoxCtrl* cbCtrl = static_cast<LLCheckBoxCtrl*>(ctrl);
  81. gPostProcess->tweaks[boolVariableName] = cbCtrl->getValue();
  82. }
  83. // Float Moved
  84. void LLFloaterPostProcess::onFloatControlMoved(LLUICtrl* ctrl, void* userData)
  85. {
  86. char const * floatVariableName = (char const *)userData;
  87. LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
  88. gPostProcess->tweaks[floatVariableName] = sldrCtrl->getValue();
  89. }
  90. // Color Moved
  91. void LLFloaterPostProcess::onColorControlRMoved(LLUICtrl* ctrl, void* userData)
  92. {
  93. char const * floatVariableName = (char const *)userData;
  94. LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
  95. gPostProcess->tweaks[floatVariableName][0] = sldrCtrl->getValue();
  96. }
  97. // Color Moved
  98. void LLFloaterPostProcess::onColorControlGMoved(LLUICtrl* ctrl, void* userData)
  99. {
  100. char const * floatVariableName = (char const *)userData;
  101. LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
  102. gPostProcess->tweaks[floatVariableName][1] = sldrCtrl->getValue();
  103. }
  104. // Color Moved
  105. void LLFloaterPostProcess::onColorControlBMoved(LLUICtrl* ctrl, void* userData)
  106. {
  107. char const * floatVariableName = (char const *)userData;
  108. LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
  109. gPostProcess->tweaks[floatVariableName][2] = sldrCtrl->getValue();
  110. }
  111. // Color Moved
  112. void LLFloaterPostProcess::onColorControlIMoved(LLUICtrl* ctrl, void* userData)
  113. {
  114. char const * floatVariableName = (char const *)userData;
  115. LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
  116. gPostProcess->tweaks[floatVariableName][3] = sldrCtrl->getValue();
  117. }
  118. void LLFloaterPostProcess::onLoadEffect(LLComboBox* comboBox)
  119. {
  120. LLSD::String effectName(comboBox->getSelectedValue().asString());
  121. gPostProcess->setSelectedEffect(effectName);
  122. syncMenu();
  123. }
  124. void LLFloaterPostProcess::onSaveEffect(LLLineEditor* editBox)
  125. {
  126. std::string effectName(editBox->getValue().asString());
  127. if (gPostProcess->mAllEffects.has(effectName))
  128. {
  129. LLSD payload;
  130. payload["effect_name"] = effectName;
  131. LLNotificationsUtil::add("PPSaveEffectAlert", LLSD(), payload, boost::bind(&LLFloaterPostProcess::saveAlertCallback, this, _1, _2));
  132. }
  133. else
  134. {
  135. gPostProcess->saveEffect(effectName);
  136. syncMenu();
  137. }
  138. }
  139. void LLFloaterPostProcess::onChangeEffectName(LLUICtrl* ctrl)
  140. {
  141. // get the combo box and name
  142. LLLineEditor* editBox = getChild<LLLineEditor>("PPEffectNameEditor");
  143. // set the parameter's new name
  144. editBox->setValue(ctrl->getValue());
  145. }
  146. bool LLFloaterPostProcess::saveAlertCallback(const LLSD& notification, const LLSD& response)
  147. {
  148. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  149. // if they choose save, do it. Otherwise, don't do anything
  150. if (option == 0)
  151. {
  152. gPostProcess->saveEffect(notification["payload"]["effect_name"].asString());
  153. syncMenu();
  154. }
  155. return false;
  156. }
  157. void LLFloaterPostProcess::syncMenu()
  158. {
  159. // add the combo boxe contents
  160. LLComboBox* comboBox = getChild<LLComboBox>("PPEffectsCombo");
  161. comboBox->removeall();
  162. LLSD::map_const_iterator currEffect;
  163. for(currEffect = gPostProcess->mAllEffects.beginMap();
  164. currEffect != gPostProcess->mAllEffects.endMap();
  165. ++currEffect)
  166. {
  167. comboBox->add(currEffect->first);
  168. }
  169. // set the current effect as selected.
  170. comboBox->selectByValue(gPostProcess->getSelectedEffect());
  171. /// Sync Color Filter Menu
  172. getChild<LLUICtrl>("ColorFilterToggle")->setValue(gPostProcess->tweaks.useColorFilter());
  173. //getChild<LLUICtrl>("ColorFilterGamma")->setValue(gPostProcess->tweaks.gamma());
  174. getChild<LLUICtrl>("ColorFilterBrightness")->setValue(gPostProcess->tweaks.brightness());
  175. getChild<LLUICtrl>("ColorFilterSaturation")->setValue(gPostProcess->tweaks.saturation());
  176. getChild<LLUICtrl>("ColorFilterContrast")->setValue(gPostProcess->tweaks.contrast());
  177. getChild<LLUICtrl>("ColorFilterBaseR")->setValue(gPostProcess->tweaks.contrastBaseR());
  178. getChild<LLUICtrl>("ColorFilterBaseG")->setValue(gPostProcess->tweaks.contrastBaseG());
  179. getChild<LLUICtrl>("ColorFilterBaseB")->setValue(gPostProcess->tweaks.contrastBaseB());
  180. getChild<LLUICtrl>("ColorFilterBaseI")->setValue(gPostProcess->tweaks.contrastBaseIntensity());
  181. /// Sync Night Vision Menu
  182. getChild<LLUICtrl>("NightVisionToggle")->setValue(gPostProcess->tweaks.useNightVisionShader());
  183. getChild<LLUICtrl>("NightVisionBrightMult")->setValue(gPostProcess->tweaks.brightMult());
  184. getChild<LLUICtrl>("NightVisionNoiseSize")->setValue(gPostProcess->tweaks.noiseSize());
  185. getChild<LLUICtrl>("NightVisionNoiseStrength")->setValue(gPostProcess->tweaks.noiseStrength());
  186. /// Sync Bloom Menu
  187. getChild<LLUICtrl>("BloomToggle")->setValue(LLSD(gPostProcess->tweaks.useBloomShader()));
  188. getChild<LLUICtrl>("BloomExtract")->setValue(gPostProcess->tweaks.extractLow());
  189. getChild<LLUICtrl>("BloomSize")->setValue(gPostProcess->tweaks.bloomWidth());
  190. getChild<LLUICtrl>("BloomStrength")->setValue(gPostProcess->tweaks.bloomStrength());
  191. }