PageRenderTime 28ms CodeModel.GetById 1ms app.highlight 21ms RepoModel.GetById 1ms 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
  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
 28#include "llviewerprecompiledheaders.h"
 29
 30#include "llpanelvolumepulldown.h"
 31
 32// Viewer libs
 33#include "llviewercontrol.h"
 34#include "llstatusbar.h"
 35
 36// Linden libs
 37#include "llbutton.h"
 38#include "lltabcontainer.h"
 39#include "llfloaterreg.h"
 40#include "llfloaterpreference.h"
 41#include "llsliderctrl.h"
 42
 43/* static */ const F32 LLPanelVolumePulldown::sAutoCloseFadeStartTimeSec = 4.0f;
 44/* static */ const F32 LLPanelVolumePulldown::sAutoCloseTotalTimeSec = 5.0f;
 45
 46///----------------------------------------------------------------------------
 47/// Class LLPanelVolumePulldown
 48///----------------------------------------------------------------------------
 49
 50// Default constructor
 51LLPanelVolumePulldown::LLPanelVolumePulldown()
 52{
 53	mHoverTimer.stop();
 54
 55    mCommitCallbackRegistrar.add("Vol.setControlFalse", boost::bind(&LLPanelVolumePulldown::setControlFalse, this, _2));
 56	mCommitCallbackRegistrar.add("Vol.GoAudioPrefs", boost::bind(&LLPanelVolumePulldown::onAdvancedButtonClick, this, _2));
 57	buildFromFile( "panel_volume_pulldown.xml");
 58}
 59
 60BOOL LLPanelVolumePulldown::postBuild()
 61{
 62	// set the initial volume-slider's position to reflect reality
 63	LLSliderCtrl* volslider =  getChild<LLSliderCtrl>( "mastervolume" );
 64	volslider->setValue(gSavedSettings.getF32("AudioLevelMaster"));
 65
 66	return LLPanel::postBuild();
 67}
 68
 69/*virtual*/
 70void LLPanelVolumePulldown::onMouseEnter(S32 x, S32 y, MASK mask)
 71{
 72	mHoverTimer.stop();
 73	LLPanel::onMouseEnter(x,y,mask);
 74}
 75
 76/*virtual*/
 77void LLPanelVolumePulldown::onTopLost()
 78{
 79	setVisible(FALSE);
 80}
 81
 82/*virtual*/
 83void LLPanelVolumePulldown::onMouseLeave(S32 x, S32 y, MASK mask)
 84{
 85	mHoverTimer.start();
 86	LLPanel::onMouseLeave(x,y,mask);
 87}
 88
 89/*virtual*/ 
 90void LLPanelVolumePulldown::handleVisibilityChange ( BOOL new_visibility )
 91{
 92	if (new_visibility)	
 93	{
 94		mHoverTimer.start(); // timer will be stopped when mouse hovers over panel
 95	}
 96	else
 97	{
 98		mHoverTimer.stop();
 99
100	}
101}
102
103void LLPanelVolumePulldown::onAdvancedButtonClick(const LLSD& user_data)
104{
105	// close the global volume minicontrol, we're bringing up the big one
106	setVisible(FALSE);
107
108	// bring up the prefs floater
109	LLFloaterPreference* prefsfloater = dynamic_cast<LLFloaterPreference*>
110		(LLFloaterReg::showInstance("preferences"));
111	if (prefsfloater)
112	{
113		// grab the 'audio' panel from the preferences floater and
114		// bring it the front!
115		LLTabContainer* tabcontainer = prefsfloater->getChild<LLTabContainer>("pref core");
116		LLPanel* audiopanel = prefsfloater->getChild<LLPanel>("audio");
117		if (tabcontainer && audiopanel)
118		{
119			tabcontainer->selectTabPanel(audiopanel);
120		}
121	}
122}
123
124void LLPanelVolumePulldown::setControlFalse(const LLSD& user_data)
125{
126	std::string control_name = user_data.asString();
127	LLControlVariable* control = findControl(control_name);
128	
129	if (control)
130		control->set(LLSD(FALSE));
131}
132
133//virtual
134void LLPanelVolumePulldown::draw()
135{
136	F32 alpha = mHoverTimer.getStarted() 
137		? clamp_rescale(mHoverTimer.getElapsedTimeF32(), sAutoCloseFadeStartTimeSec, sAutoCloseTotalTimeSec, 1.f, 0.f)
138		: 1.0f;
139	LLViewDrawContext context(alpha);
140
141	LLPanel::draw();
142
143	if (alpha == 0.f)
144	{
145		setVisible(FALSE);
146	}
147}
148