PageRenderTime 50ms CodeModel.GetById 45ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llpanelvolumepulldown.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 148 lines | 83 code | 23 blank | 42 comment | 7 complexity | 215b3a7b28f44cb52a38803b160e4417 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpanelvolumepulldown.cpp
  3. * @author Tofu Linden
  4. * @brief A floater showing the master volume pull-down
  5. *
  6. * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "llviewerprecompiledheaders.h"
  28. #include "llpanelvolumepulldown.h"
  29. // Viewer libs
  30. #include "llviewercontrol.h"
  31. #include "llstatusbar.h"
  32. // Linden libs
  33. #include "llbutton.h"
  34. #include "lltabcontainer.h"
  35. #include "llfloaterreg.h"
  36. #include "llfloaterpreference.h"
  37. #include "llsliderctrl.h"
  38. /* static */ const F32 LLPanelVolumePulldown::sAutoCloseFadeStartTimeSec = 4.0f;
  39. /* static */ const F32 LLPanelVolumePulldown::sAutoCloseTotalTimeSec = 5.0f;
  40. ///----------------------------------------------------------------------------
  41. /// Class LLPanelVolumePulldown
  42. ///----------------------------------------------------------------------------
  43. // Default constructor
  44. LLPanelVolumePulldown::LLPanelVolumePulldown()
  45. {
  46. mHoverTimer.stop();
  47. mCommitCallbackRegistrar.add("Vol.setControlFalse", boost::bind(&LLPanelVolumePulldown::setControlFalse, this, _2));
  48. mCommitCallbackRegistrar.add("Vol.GoAudioPrefs", boost::bind(&LLPanelVolumePulldown::onAdvancedButtonClick, this, _2));
  49. buildFromFile( "panel_volume_pulldown.xml");
  50. }
  51. BOOL LLPanelVolumePulldown::postBuild()
  52. {
  53. // set the initial volume-slider's position to reflect reality
  54. LLSliderCtrl* volslider = getChild<LLSliderCtrl>( "mastervolume" );
  55. volslider->setValue(gSavedSettings.getF32("AudioLevelMaster"));
  56. return LLPanel::postBuild();
  57. }
  58. /*virtual*/
  59. void LLPanelVolumePulldown::onMouseEnter(S32 x, S32 y, MASK mask)
  60. {
  61. mHoverTimer.stop();
  62. LLPanel::onMouseEnter(x,y,mask);
  63. }
  64. /*virtual*/
  65. void LLPanelVolumePulldown::onTopLost()
  66. {
  67. setVisible(FALSE);
  68. }
  69. /*virtual*/
  70. void LLPanelVolumePulldown::onMouseLeave(S32 x, S32 y, MASK mask)
  71. {
  72. mHoverTimer.start();
  73. LLPanel::onMouseLeave(x,y,mask);
  74. }
  75. /*virtual*/
  76. void LLPanelVolumePulldown::handleVisibilityChange ( BOOL new_visibility )
  77. {
  78. if (new_visibility)
  79. {
  80. mHoverTimer.start(); // timer will be stopped when mouse hovers over panel
  81. }
  82. else
  83. {
  84. mHoverTimer.stop();
  85. }
  86. }
  87. void LLPanelVolumePulldown::onAdvancedButtonClick(const LLSD& user_data)
  88. {
  89. // close the global volume minicontrol, we're bringing up the big one
  90. setVisible(FALSE);
  91. // bring up the prefs floater
  92. LLFloaterPreference* prefsfloater = dynamic_cast<LLFloaterPreference*>
  93. (LLFloaterReg::showInstance("preferences"));
  94. if (prefsfloater)
  95. {
  96. // grab the 'audio' panel from the preferences floater and
  97. // bring it the front!
  98. LLTabContainer* tabcontainer = prefsfloater->getChild<LLTabContainer>("pref core");
  99. LLPanel* audiopanel = prefsfloater->getChild<LLPanel>("audio");
  100. if (tabcontainer && audiopanel)
  101. {
  102. tabcontainer->selectTabPanel(audiopanel);
  103. }
  104. }
  105. }
  106. void LLPanelVolumePulldown::setControlFalse(const LLSD& user_data)
  107. {
  108. std::string control_name = user_data.asString();
  109. LLControlVariable* control = findControl(control_name);
  110. if (control)
  111. control->set(LLSD(FALSE));
  112. }
  113. //virtual
  114. void LLPanelVolumePulldown::draw()
  115. {
  116. F32 alpha = mHoverTimer.getStarted()
  117. ? clamp_rescale(mHoverTimer.getElapsedTimeF32(), sAutoCloseFadeStartTimeSec, sAutoCloseTotalTimeSec, 1.f, 0.f)
  118. : 1.0f;
  119. LLViewDrawContext context(alpha);
  120. LLPanel::draw();
  121. if (alpha == 0.f)
  122. {
  123. setVisible(FALSE);
  124. }
  125. }