PageRenderTime 159ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/newview/llscrollingpanelparam.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 358 lines | 253 code | 54 blank | 51 comment | 29 complexity | 5f54da49d7ae913844837fa3d48f94c6 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 "llscrollingpanelparam.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. // Constants for LLPanelVisualParam
  40. const F32 LLScrollingPanelParam::PARAM_STEP_TIME_THRESHOLD = 0.25f;
  41. const S32 LLScrollingPanelParam::PARAM_HINT_WIDTH = 128;
  42. const S32 LLScrollingPanelParam::PARAM_HINT_HEIGHT = 128;
  43. // LLScrollingPanelParam
  44. //static
  45. S32 LLScrollingPanelParam::sUpdateDelayFrames = 0;
  46. LLScrollingPanelParam::LLScrollingPanelParam( const LLPanel::Params& panel_params,
  47. LLViewerJointMesh* mesh, LLViewerVisualParam* param, BOOL allow_modify, LLWearable* wearable, LLJoint* jointp, BOOL use_hints )
  48. : LLScrollingPanelParamBase( panel_params, mesh, param, allow_modify, wearable, jointp, use_hints)
  49. {
  50. // *HACK To avoid hard coding texture position, lets use border's position for texture.
  51. LLViewBorder* left_border = getChild<LLViewBorder>("left_border");
  52. static LLUICachedControl<S32> slider_ctrl_height ("UISliderctrlHeight", 0);
  53. S32 pos_x = left_border->getRect().mLeft + left_border->getBorderWidth();
  54. S32 pos_y = left_border->getRect().mBottom + left_border->getBorderWidth();
  55. F32 min_weight = param->getMinWeight();
  56. F32 max_weight = param->getMaxWeight();
  57. mHintMin = new LLVisualParamHint( pos_x, pos_y, PARAM_HINT_WIDTH, PARAM_HINT_HEIGHT, mesh, (LLViewerVisualParam*) wearable->getVisualParam(param->getID()), wearable, min_weight, jointp);
  58. pos_x = getChild<LLViewBorder>("right_border")->getRect().mLeft + left_border->getBorderWidth();
  59. mHintMax = new LLVisualParamHint( pos_x, pos_y, PARAM_HINT_WIDTH, PARAM_HINT_HEIGHT, mesh, (LLViewerVisualParam*) wearable->getVisualParam(param->getID()), wearable, max_weight, jointp );
  60. mHintMin->setAllowsUpdates( FALSE );
  61. mHintMax->setAllowsUpdates( FALSE );
  62. std::string min_name = LLTrans::getString(param->getMinDisplayName());
  63. std::string max_name = LLTrans::getString(param->getMaxDisplayName());
  64. getChild<LLUICtrl>("min param text")->setValue(min_name);
  65. getChild<LLUICtrl>("max param text")->setValue(max_name);
  66. LLButton* less = getChild<LLButton>("less");
  67. if (less)
  68. {
  69. less->setMouseDownCallback( LLScrollingPanelParam::onHintMinMouseDown, this );
  70. less->setMouseUpCallback( LLScrollingPanelParam::onHintMinMouseUp, this );
  71. less->setHeldDownCallback( LLScrollingPanelParam::onHintMinHeldDown, this );
  72. less->setHeldDownDelay( PARAM_STEP_TIME_THRESHOLD );
  73. }
  74. LLButton* more = getChild<LLButton>("more");
  75. if (more)
  76. {
  77. more->setMouseDownCallback( LLScrollingPanelParam::onHintMaxMouseDown, this );
  78. more->setMouseUpCallback( LLScrollingPanelParam::onHintMaxMouseUp, this );
  79. more->setHeldDownCallback( LLScrollingPanelParam::onHintMaxHeldDown, this );
  80. more->setHeldDownDelay( PARAM_STEP_TIME_THRESHOLD );
  81. }
  82. setVisible(FALSE);
  83. setBorderVisible( FALSE );
  84. }
  85. LLScrollingPanelParam::~LLScrollingPanelParam()
  86. {
  87. }
  88. void LLScrollingPanelParam::updatePanel(BOOL allow_modify)
  89. {
  90. if (!mWearable)
  91. {
  92. // not editing a wearable just now, no update necessary
  93. return;
  94. }
  95. LLScrollingPanelParamBase::updatePanel(allow_modify);
  96. mHintMin->requestUpdate( sUpdateDelayFrames++ );
  97. mHintMax->requestUpdate( sUpdateDelayFrames++ );
  98. getChildView("less")->setEnabled(mAllowModify);
  99. getChildView("more")->setEnabled(mAllowModify);
  100. }
  101. void LLScrollingPanelParam::setVisible( BOOL visible )
  102. {
  103. if( getVisible() != visible )
  104. {
  105. LLPanel::setVisible( visible );
  106. if (mHintMin)
  107. mHintMin->setAllowsUpdates( visible );
  108. if (mHintMax)
  109. mHintMax->setAllowsUpdates( visible );
  110. if( visible )
  111. {
  112. if (mHintMin)
  113. mHintMin->setUpdateDelayFrames( sUpdateDelayFrames++ );
  114. if (mHintMax)
  115. mHintMax->setUpdateDelayFrames( sUpdateDelayFrames++ );
  116. }
  117. }
  118. }
  119. void LLScrollingPanelParam::draw()
  120. {
  121. if( !mWearable )
  122. {
  123. return;
  124. }
  125. getChildView("less")->setVisible( mHintMin->getVisible());
  126. getChildView("more")->setVisible( mHintMax->getVisible());
  127. // hide borders if texture has been loaded
  128. getChildView("left_border")->setVisible( !mHintMin->getVisible());
  129. getChildView("right_border")->setVisible( !mHintMax->getVisible());
  130. // Draw all the children except for the labels
  131. getChildView("min param text")->setVisible( FALSE );
  132. getChildView("max param text")->setVisible( FALSE );
  133. LLPanel::draw();
  134. // If we're in a focused floater, don't apply the floater's alpha to visual param hint,
  135. // making its behavior similar to texture controls'.
  136. F32 alpha = getTransparencyType() == TT_ACTIVE ? 1.0f : getCurrentTransparency();
  137. // Draw the hints over the "less" and "more" buttons.
  138. gGL.pushUIMatrix();
  139. {
  140. const LLRect& r = mHintMin->getRect();
  141. gGL.translateUI((F32)r.mLeft, (F32)r.mBottom, 0.f);
  142. mHintMin->draw(alpha);
  143. }
  144. gGL.popUIMatrix();
  145. gGL.pushUIMatrix();
  146. {
  147. const LLRect& r = mHintMax->getRect();
  148. gGL.translateUI((F32)r.mLeft, (F32)r.mBottom, 0.f);
  149. mHintMax->draw(alpha);
  150. }
  151. gGL.popUIMatrix();
  152. // Draw labels on top of the buttons
  153. getChildView("min param text")->setVisible( TRUE );
  154. drawChild(getChild<LLView>("min param text"));
  155. getChildView("max param text")->setVisible( TRUE );
  156. drawChild(getChild<LLView>("max param text"));
  157. }
  158. // static
  159. void LLScrollingPanelParam::onSliderMouseDown(LLUICtrl* ctrl, void* userdata)
  160. {
  161. }
  162. // static
  163. void LLScrollingPanelParam::onSliderMouseUp(LLUICtrl* ctrl, void* userdata)
  164. {
  165. LLScrollingPanelParam* self = (LLScrollingPanelParam*) userdata;
  166. LLVisualParamHint::requestHintUpdates( self->mHintMin, self->mHintMax );
  167. }
  168. // static
  169. void LLScrollingPanelParam::onHintMinMouseDown( void* userdata )
  170. {
  171. LLScrollingPanelParam* self = (LLScrollingPanelParam*) userdata;
  172. self->onHintMouseDown( self->mHintMin );
  173. }
  174. // static
  175. void LLScrollingPanelParam::onHintMaxMouseDown( void* userdata )
  176. {
  177. LLScrollingPanelParam* self = (LLScrollingPanelParam*) userdata;
  178. self->onHintMouseDown( self->mHintMax );
  179. }
  180. void LLScrollingPanelParam::onHintMouseDown( LLVisualParamHint* hint )
  181. {
  182. // morph towards this result
  183. F32 current_weight = mWearable->getVisualParamWeight( hint->getVisualParam()->getID() );
  184. // if we have maxed out on this morph, we shouldn't be able to click it
  185. if( hint->getVisualParamWeight() != current_weight )
  186. {
  187. mMouseDownTimer.reset();
  188. mLastHeldTime = 0.f;
  189. }
  190. }
  191. // static
  192. void LLScrollingPanelParam::onHintMinHeldDown( void* userdata )
  193. {
  194. LLScrollingPanelParam* self = (LLScrollingPanelParam*) userdata;
  195. self->onHintHeldDown( self->mHintMin );
  196. }
  197. // static
  198. void LLScrollingPanelParam::onHintMaxHeldDown( void* userdata )
  199. {
  200. LLScrollingPanelParam* self = (LLScrollingPanelParam*) userdata;
  201. self->onHintHeldDown( self->mHintMax );
  202. }
  203. void LLScrollingPanelParam::onHintHeldDown( LLVisualParamHint* hint )
  204. {
  205. F32 current_weight = mWearable->getVisualParamWeight( hint->getVisualParam()->getID() );
  206. if (current_weight != hint->getVisualParamWeight() )
  207. {
  208. const F32 FULL_BLEND_TIME = 2.f;
  209. F32 elapsed_time = mMouseDownTimer.getElapsedTimeF32() - mLastHeldTime;
  210. mLastHeldTime += elapsed_time;
  211. F32 new_weight;
  212. if (current_weight > hint->getVisualParamWeight() )
  213. {
  214. new_weight = current_weight - (elapsed_time / FULL_BLEND_TIME);
  215. }
  216. else
  217. {
  218. new_weight = current_weight + (elapsed_time / FULL_BLEND_TIME);
  219. }
  220. // Make sure we're not taking the slider out of bounds
  221. // (this is where some simple UI limits are stored)
  222. F32 new_percent = weightToPercent(new_weight);
  223. LLSliderCtrl* slider = getChild<LLSliderCtrl>("param slider");
  224. if (slider)
  225. {
  226. if (slider->getMinValue() < new_percent
  227. && new_percent < slider->getMaxValue())
  228. {
  229. mWearable->setVisualParamWeight( hint->getVisualParam()->getID(), new_weight, FALSE);
  230. mWearable->writeToAvatar();
  231. gAgentAvatarp->updateVisualParams();
  232. slider->setValue( weightToPercent( new_weight ) );
  233. }
  234. }
  235. }
  236. }
  237. // static
  238. void LLScrollingPanelParam::onHintMinMouseUp( void* userdata )
  239. {
  240. LLScrollingPanelParam* self = (LLScrollingPanelParam*) userdata;
  241. F32 elapsed_time = self->mMouseDownTimer.getElapsedTimeF32();
  242. LLVisualParamHint* hint = self->mHintMin;
  243. if (elapsed_time < PARAM_STEP_TIME_THRESHOLD)
  244. {
  245. // step in direction
  246. F32 current_weight = self->mWearable->getVisualParamWeight( hint->getVisualParam()->getID() );
  247. F32 range = self->mHintMax->getVisualParamWeight() - self->mHintMin->getVisualParamWeight();
  248. // step a fraction in the negative directiona
  249. F32 new_weight = current_weight - (range / 10.f);
  250. F32 new_percent = self->weightToPercent(new_weight);
  251. LLSliderCtrl* slider = self->getChild<LLSliderCtrl>("param slider");
  252. if (slider)
  253. {
  254. if (slider->getMinValue() < new_percent
  255. && new_percent < slider->getMaxValue())
  256. {
  257. self->mWearable->setVisualParamWeight(hint->getVisualParam()->getID(), new_weight, FALSE);
  258. self->mWearable->writeToAvatar();
  259. slider->setValue( self->weightToPercent( new_weight ) );
  260. }
  261. }
  262. }
  263. LLVisualParamHint::requestHintUpdates( self->mHintMin, self->mHintMax );
  264. }
  265. void LLScrollingPanelParam::onHintMaxMouseUp( void* userdata )
  266. {
  267. LLScrollingPanelParam* self = (LLScrollingPanelParam*) userdata;
  268. F32 elapsed_time = self->mMouseDownTimer.getElapsedTimeF32();
  269. if (isAgentAvatarValid())
  270. {
  271. LLVisualParamHint* hint = self->mHintMax;
  272. if (elapsed_time < PARAM_STEP_TIME_THRESHOLD)
  273. {
  274. // step in direction
  275. F32 current_weight = self->mWearable->getVisualParamWeight( hint->getVisualParam()->getID() );
  276. F32 range = self->mHintMax->getVisualParamWeight() - self->mHintMin->getVisualParamWeight();
  277. // step a fraction in the negative direction
  278. F32 new_weight = current_weight + (range / 10.f);
  279. F32 new_percent = self->weightToPercent(new_weight);
  280. LLSliderCtrl* slider = self->getChild<LLSliderCtrl>("param slider");
  281. if (slider)
  282. {
  283. if (slider->getMinValue() < new_percent
  284. && new_percent < slider->getMaxValue())
  285. {
  286. self->mWearable->setVisualParamWeight(hint->getVisualParam()->getID(), new_weight, FALSE);
  287. self->mWearable->writeToAvatar();
  288. slider->setValue( self->weightToPercent( new_weight ) );
  289. }
  290. }
  291. }
  292. }
  293. LLVisualParamHint::requestHintUpdates( self->mHintMin, self->mHintMax );
  294. }
  295. F32 LLScrollingPanelParam::weightToPercent( F32 weight )
  296. {
  297. LLViewerVisualParam* param = mParam;
  298. return (weight - param->getMinWeight()) / (param->getMaxWeight() - param->getMinWeight()) * 100.f;
  299. }
  300. F32 LLScrollingPanelParam::percentToWeight( F32 percent )
  301. {
  302. LLViewerVisualParam* param = mParam;
  303. return percent / 100.f * (param->getMaxWeight() - param->getMinWeight()) + param->getMinWeight();
  304. }