PageRenderTime 33ms CodeModel.GetById 24ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llscrollingpanelparambase.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 112 lines | 71 code | 14 blank | 27 comment | 4 complexity | b1ff21540db48add1e2fd8c81096b9db MD5 | raw file
  1/** 
  2 * @file llscrollingpanelparam.cpp
  3 * @brief UI panel for a list of visual param panels
  4 *
  5 * $LicenseInfo:firstyear=2009&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 "llscrollingpanelparambase.h"
 30#include "llviewerjointmesh.h"
 31#include "llviewervisualparam.h"
 32#include "llwearable.h"
 33#include "llviewervisualparam.h"
 34#include "lltoolmorph.h"
 35#include "lltrans.h"
 36#include "llbutton.h"
 37#include "llsliderctrl.h"
 38#include "llagent.h"
 39#include "llviewborder.h"
 40#include "llvoavatarself.h"
 41
 42LLScrollingPanelParamBase::LLScrollingPanelParamBase( const LLPanel::Params& panel_params,
 43						      LLViewerJointMesh* mesh, LLViewerVisualParam* param, BOOL allow_modify, LLWearable* wearable, LLJoint* jointp, BOOL use_hints)
 44	: LLScrollingPanel( panel_params ),
 45	  mParam(param),
 46	  mAllowModify(allow_modify),
 47	  mWearable(wearable)
 48{
 49	if (use_hints)
 50		buildFromFile( "panel_scrolling_param.xml");
 51	else
 52		buildFromFile( "panel_scrolling_param_base.xml");
 53	
 54	getChild<LLUICtrl>("param slider")->setValue(weightToPercent(param->getWeight()));
 55
 56	std::string display_name = LLTrans::getString(param->getDisplayName());
 57	getChild<LLUICtrl>("param slider")->setLabelArg("[DESC]", display_name);
 58	getChildView("param slider")->setEnabled(mAllowModify);
 59	childSetCommitCallback("param slider", LLScrollingPanelParamBase::onSliderMoved, this);
 60
 61	setVisible(FALSE);
 62	setBorderVisible( FALSE );
 63}
 64
 65LLScrollingPanelParamBase::~LLScrollingPanelParamBase()
 66{
 67}
 68
 69void LLScrollingPanelParamBase::updatePanel(BOOL allow_modify)
 70{
 71	LLViewerVisualParam* param = mParam;
 72
 73	if (!mWearable)
 74	{
 75		// not editing a wearable just now, no update necessary
 76		return;
 77	}
 78
 79	F32 current_weight = mWearable->getVisualParamWeight( param->getID() );
 80	getChild<LLUICtrl>("param slider")->setValue(weightToPercent( current_weight ) );
 81	mAllowModify = allow_modify;
 82	getChildView("param slider")->setEnabled(mAllowModify);
 83}
 84
 85// static
 86void LLScrollingPanelParamBase::onSliderMoved(LLUICtrl* ctrl, void* userdata)
 87{
 88	LLSliderCtrl* slider = (LLSliderCtrl*) ctrl;
 89	LLScrollingPanelParamBase* self = (LLScrollingPanelParamBase*) userdata;
 90	LLViewerVisualParam* param = self->mParam;
 91	
 92	F32 current_weight = self->mWearable->getVisualParamWeight( param->getID() );
 93	F32 new_weight = self->percentToWeight( (F32)slider->getValue().asReal() );
 94	if (current_weight != new_weight )
 95	{
 96		self->mWearable->setVisualParamWeight( param->getID(), new_weight, FALSE );
 97		self->mWearable->writeToAvatar();
 98		gAgentAvatarp->updateVisualParams();
 99	}
100}
101
102F32 LLScrollingPanelParamBase::weightToPercent( F32 weight )
103{
104	LLViewerVisualParam* param = mParam;
105	return (weight - param->getMinWeight()) /  (param->getMaxWeight() - param->getMinWeight()) * 100.f;
106}
107
108F32 LLScrollingPanelParamBase::percentToWeight( F32 percent )
109{
110	LLViewerVisualParam* param = mParam;
111	return percent / 100.f * (param->getMaxWeight() - param->getMinWeight()) + param->getMinWeight();
112}