PageRenderTime 33ms CodeModel.GetById 18ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  27. #include "llscrollingpanelparambase.h"
  28. #include "llviewerjointmesh.h"
  29. #include "llviewervisualparam.h"
  30. #include "llwearable.h"
  31. #include "llviewervisualparam.h"
  32. #include "lltoolmorph.h"
  33. #include "lltrans.h"
  34. #include "llbutton.h"
  35. #include "llsliderctrl.h"
  36. #include "llagent.h"
  37. #include "llviewborder.h"
  38. #include "llvoavatarself.h"
  39. LLScrollingPanelParamBase::LLScrollingPanelParamBase( const LLPanel::Params& panel_params,
  40. LLViewerJointMesh* mesh, LLViewerVisualParam* param, BOOL allow_modify, LLWearable* wearable, LLJoint* jointp, BOOL use_hints)
  41. : LLScrollingPanel( panel_params ),
  42. mParam(param),
  43. mAllowModify(allow_modify),
  44. mWearable(wearable)
  45. {
  46. if (use_hints)
  47. buildFromFile( "panel_scrolling_param.xml");
  48. else
  49. buildFromFile( "panel_scrolling_param_base.xml");
  50. getChild<LLUICtrl>("param slider")->setValue(weightToPercent(param->getWeight()));
  51. std::string display_name = LLTrans::getString(param->getDisplayName());
  52. getChild<LLUICtrl>("param slider")->setLabelArg("[DESC]", display_name);
  53. getChildView("param slider")->setEnabled(mAllowModify);
  54. childSetCommitCallback("param slider", LLScrollingPanelParamBase::onSliderMoved, this);
  55. setVisible(FALSE);
  56. setBorderVisible( FALSE );
  57. }
  58. LLScrollingPanelParamBase::~LLScrollingPanelParamBase()
  59. {
  60. }
  61. void LLScrollingPanelParamBase::updatePanel(BOOL allow_modify)
  62. {
  63. LLViewerVisualParam* param = mParam;
  64. if (!mWearable)
  65. {
  66. // not editing a wearable just now, no update necessary
  67. return;
  68. }
  69. F32 current_weight = mWearable->getVisualParamWeight( param->getID() );
  70. getChild<LLUICtrl>("param slider")->setValue(weightToPercent( current_weight ) );
  71. mAllowModify = allow_modify;
  72. getChildView("param slider")->setEnabled(mAllowModify);
  73. }
  74. // static
  75. void LLScrollingPanelParamBase::onSliderMoved(LLUICtrl* ctrl, void* userdata)
  76. {
  77. LLSliderCtrl* slider = (LLSliderCtrl*) ctrl;
  78. LLScrollingPanelParamBase* self = (LLScrollingPanelParamBase*) userdata;
  79. LLViewerVisualParam* param = self->mParam;
  80. F32 current_weight = self->mWearable->getVisualParamWeight( param->getID() );
  81. F32 new_weight = self->percentToWeight( (F32)slider->getValue().asReal() );
  82. if (current_weight != new_weight )
  83. {
  84. self->mWearable->setVisualParamWeight( param->getID(), new_weight, FALSE );
  85. self->mWearable->writeToAvatar();
  86. gAgentAvatarp->updateVisualParams();
  87. }
  88. }
  89. F32 LLScrollingPanelParamBase::weightToPercent( F32 weight )
  90. {
  91. LLViewerVisualParam* param = mParam;
  92. return (weight - param->getMinWeight()) / (param->getMaxWeight() - param->getMinWeight()) * 100.f;
  93. }
  94. F32 LLScrollingPanelParamBase::percentToWeight( F32 percent )
  95. {
  96. LLViewerVisualParam* param = mParam;
  97. return percent / 100.f * (param->getMaxWeight() - param->getMinWeight()) + param->getMinWeight();
  98. }