llscrollingpanelparam.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:13k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llscrollingpanelparam.cpp
  3.  * @brief UI panel for a list of visual param panels
  4.  *
  5.  * $LicenseInfo:firstyear=2009&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2009-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llscrollingpanelparam.h"
  34. #include "llviewerjointmesh.h"
  35. #include "llviewervisualparam.h"
  36. #include "llwearable.h"
  37. #include "llviewervisualparam.h"
  38. #include "lltoolmorph.h"
  39. #include "lltrans.h"
  40. #include "llbutton.h"
  41. #include "llsliderctrl.h"
  42. #include "llagent.h"
  43. #include "llvoavatarself.h"
  44. // Constants for LLPanelVisualParam
  45. const F32 LLScrollingPanelParam::PARAM_STEP_TIME_THRESHOLD = 0.25f;
  46. const S32 LLScrollingPanelParam::BTN_BORDER = 2;
  47. const S32 LLScrollingPanelParam::PARAM_HINT_WIDTH = 128;
  48. const S32 LLScrollingPanelParam::PARAM_HINT_HEIGHT = 128;
  49. const S32 LLScrollingPanelParam::PARAM_HINT_LABEL_HEIGHT = 16;
  50. const S32 LLScrollingPanelParam::PARAM_PANEL_WIDTH = 2 * (3* BTN_BORDER + PARAM_HINT_WIDTH +  LLPANEL_BORDER_WIDTH);
  51. const S32 LLScrollingPanelParam::PARAM_PANEL_HEIGHT = 2 * BTN_BORDER + PARAM_HINT_HEIGHT + PARAM_HINT_LABEL_HEIGHT + 4 * LLPANEL_BORDER_WIDTH; 
  52. // LLScrollingPanelParam
  53. //static
  54. S32 LLScrollingPanelParam::sUpdateDelayFrames = 0;
  55. LLScrollingPanelParam::LLScrollingPanelParam( const LLPanel::Params& panel_params,
  56.   LLViewerJointMesh* mesh, LLViewerVisualParam* param, BOOL allow_modify, LLWearable* wearable )
  57. : LLScrollingPanel( panel_params ),
  58.   mParam(param),
  59.   mAllowModify(allow_modify),
  60.   mWearable(wearable)
  61. {
  62. LLUICtrlFactory::getInstance()->buildPanel(this, "panel_scrolling_param.xml");
  63. static LLUICachedControl<S32> slider_ctrl_height ("UISliderctrlHeight", 0);
  64. S32 pos_x = 2 * LLPANEL_BORDER_WIDTH;
  65. S32 pos_y = 3 * LLPANEL_BORDER_WIDTH + slider_ctrl_height;
  66. F32 min_weight = param->getMinWeight();
  67. F32 max_weight = param->getMaxWeight();
  68. mHintMin = new LLVisualParamHint( pos_x, pos_y, PARAM_HINT_WIDTH, PARAM_HINT_HEIGHT, mesh, (LLViewerVisualParam*) wearable->getVisualParam(param->getID()),  min_weight);
  69. pos_x += PARAM_HINT_WIDTH + 3 * BTN_BORDER;
  70. mHintMax = new LLVisualParamHint( pos_x, pos_y, PARAM_HINT_WIDTH, PARAM_HINT_HEIGHT, mesh, (LLViewerVisualParam*) wearable->getVisualParam(param->getID()), max_weight );
  71. mHintMin->setAllowsUpdates( FALSE );
  72. mHintMax->setAllowsUpdates( FALSE );
  73. childSetValue("param slider", weightToPercent(param->getWeight()));
  74. std::string display_name = LLTrans::getString(param->getDisplayName());
  75. childSetLabelArg("param slider", "[DESC]", display_name);
  76. childSetEnabled("param slider", mAllowModify);
  77. childSetCommitCallback("param slider", LLScrollingPanelParam::onSliderMoved, this);
  78. std::string min_name = LLTrans::getString(param->getMinDisplayName());
  79. std::string max_name = LLTrans::getString(param->getMaxDisplayName());
  80. childSetValue("min param text", min_name);
  81. childSetValue("max param text", max_name);
  82. LLButton* less = getChild<LLButton>("less");
  83. if (less)
  84. {
  85. less->setMouseDownCallback( LLScrollingPanelParam::onHintMinMouseDown, this );
  86. less->setMouseUpCallback( LLScrollingPanelParam::onHintMinMouseUp, this );
  87. less->setHeldDownCallback( LLScrollingPanelParam::onHintMinHeldDown, this );
  88. less->setHeldDownDelay( PARAM_STEP_TIME_THRESHOLD );
  89. }
  90. LLButton* more = getChild<LLButton>("more");
  91. if (more)
  92. {
  93. more->setMouseDownCallback( LLScrollingPanelParam::onHintMaxMouseDown, this );
  94. more->setMouseUpCallback( LLScrollingPanelParam::onHintMaxMouseUp, this );
  95. more->setHeldDownCallback( LLScrollingPanelParam::onHintMaxHeldDown, this );
  96. more->setHeldDownDelay( PARAM_STEP_TIME_THRESHOLD );
  97. }
  98. setVisible(FALSE);
  99. setBorderVisible( FALSE );
  100. }
  101. LLScrollingPanelParam::~LLScrollingPanelParam()
  102. {
  103. }
  104. void LLScrollingPanelParam::updatePanel(BOOL allow_modify)
  105. {
  106. LLViewerVisualParam* param = mHintMin->getVisualParam();
  107. if (!mWearable)
  108. {
  109. // not editing a wearable just now, no update necessary
  110. return;
  111. }
  112. F32 current_weight = mWearable->getVisualParamWeight( param->getID() );
  113. childSetValue("param slider", weightToPercent( current_weight ) );
  114. mHintMin->requestUpdate( sUpdateDelayFrames++ );
  115. mHintMax->requestUpdate( sUpdateDelayFrames++ );
  116. mAllowModify = allow_modify;
  117. childSetEnabled("param slider", mAllowModify);
  118. childSetEnabled("less", mAllowModify);
  119. childSetEnabled("more", mAllowModify);
  120. }
  121. void LLScrollingPanelParam::setVisible( BOOL visible )
  122. {
  123. if( getVisible() != visible )
  124. {
  125. LLPanel::setVisible( visible );
  126. mHintMin->setAllowsUpdates( visible );
  127. mHintMax->setAllowsUpdates( visible );
  128. if( visible )
  129. {
  130. mHintMin->setUpdateDelayFrames( sUpdateDelayFrames++ );
  131. mHintMax->setUpdateDelayFrames( sUpdateDelayFrames++ );
  132. }
  133. }
  134. }
  135. void LLScrollingPanelParam::draw()
  136. {
  137. if( !mWearable )
  138. {
  139. return;
  140. }
  141. childSetVisible("less", mHintMin->getVisible());
  142. childSetVisible("more", mHintMax->getVisible());
  143. // Draw all the children except for the labels
  144. childSetVisible( "min param text", FALSE );
  145. childSetVisible( "max param text", FALSE );
  146. LLPanel::draw();
  147. // Draw the hints over the "less" and "more" buttons.
  148. glPushMatrix();
  149. {
  150. const LLRect& r = mHintMin->getRect();
  151. F32 left = (F32)(r.mLeft + BTN_BORDER);
  152. F32 bot  = (F32)(r.mBottom + BTN_BORDER);
  153. glTranslatef(left, bot, 0.f);
  154. mHintMin->draw();
  155. }
  156. glPopMatrix();
  157. glPushMatrix();
  158. {
  159. const LLRect& r = mHintMax->getRect();
  160. F32 left = (F32)(r.mLeft + BTN_BORDER);
  161. F32 bot  = (F32)(r.mBottom + BTN_BORDER);
  162. glTranslatef(left, bot, 0.f);
  163. mHintMax->draw();
  164. }
  165. glPopMatrix();
  166. // Draw labels on top of the buttons
  167. childSetVisible( "min param text", TRUE );
  168. drawChild(getChild<LLView>("min param text"), BTN_BORDER, BTN_BORDER);
  169. childSetVisible( "max param text", TRUE );
  170. drawChild(getChild<LLView>("max param text"), BTN_BORDER, BTN_BORDER);
  171. }
  172. // static
  173. void LLScrollingPanelParam::onSliderMoved(LLUICtrl* ctrl, void* userdata)
  174. {
  175. LLSliderCtrl* slider = (LLSliderCtrl*) ctrl;
  176. LLScrollingPanelParam* self = (LLScrollingPanelParam*) userdata;
  177. LLViewerVisualParam* param = self->mParam;
  178. F32 current_weight = self->mWearable->getVisualParamWeight( param->getID() );
  179. F32 new_weight = self->percentToWeight( (F32)slider->getValue().asReal() );
  180. if (current_weight != new_weight )
  181. {
  182. self->mWearable->setVisualParamWeight( param->getID(), new_weight, FALSE );
  183. gAgent.getAvatarObject()->updateVisualParams();
  184. }
  185. }
  186. // static
  187. void LLScrollingPanelParam::onSliderMouseDown(LLUICtrl* ctrl, void* userdata)
  188. {
  189. }
  190. // static
  191. void LLScrollingPanelParam::onSliderMouseUp(LLUICtrl* ctrl, void* userdata)
  192. {
  193. LLScrollingPanelParam* self = (LLScrollingPanelParam*) userdata;
  194. LLVisualParamHint::requestHintUpdates( self->mHintMin, self->mHintMax );
  195. }
  196. // static
  197. void LLScrollingPanelParam::onHintMinMouseDown( void* userdata )
  198. {
  199. LLScrollingPanelParam* self = (LLScrollingPanelParam*) userdata;
  200. self->onHintMouseDown( self->mHintMin );
  201. }
  202. // static
  203. void LLScrollingPanelParam::onHintMaxMouseDown( void* userdata )
  204. {
  205. LLScrollingPanelParam* self = (LLScrollingPanelParam*) userdata;
  206. self->onHintMouseDown( self->mHintMax );
  207. }
  208. void LLScrollingPanelParam::onHintMouseDown( LLVisualParamHint* hint )
  209. {
  210. // morph towards this result
  211. F32 current_weight = mWearable->getVisualParamWeight( hint->getVisualParam()->getID() );
  212. // if we have maxed out on this morph, we shouldn't be able to click it
  213. if( hint->getVisualParamWeight() != current_weight )
  214. {
  215. mMouseDownTimer.reset();
  216. mLastHeldTime = 0.f;
  217. }
  218. }
  219. // static
  220. void LLScrollingPanelParam::onHintMinHeldDown( void* userdata )
  221. {
  222. LLScrollingPanelParam* self = (LLScrollingPanelParam*) userdata;
  223. self->onHintHeldDown( self->mHintMin );
  224. }
  225. // static
  226. void LLScrollingPanelParam::onHintMaxHeldDown( void* userdata )
  227. {
  228. LLScrollingPanelParam* self = (LLScrollingPanelParam*) userdata;
  229. self->onHintHeldDown( self->mHintMax );
  230. }
  231. void LLScrollingPanelParam::onHintHeldDown( LLVisualParamHint* hint )
  232. {
  233. F32 current_weight = mWearable->getVisualParamWeight( hint->getVisualParam()->getID() );
  234. if (current_weight != hint->getVisualParamWeight() )
  235. {
  236. const F32 FULL_BLEND_TIME = 2.f;
  237. F32 elapsed_time = mMouseDownTimer.getElapsedTimeF32() - mLastHeldTime;
  238. mLastHeldTime += elapsed_time;
  239. F32 new_weight;
  240. if (current_weight > hint->getVisualParamWeight() )
  241. {
  242. new_weight = current_weight - (elapsed_time / FULL_BLEND_TIME);
  243. }
  244. else
  245. {
  246. new_weight = current_weight + (elapsed_time / FULL_BLEND_TIME);
  247. }
  248. // Make sure we're not taking the slider out of bounds
  249. // (this is where some simple UI limits are stored)
  250. F32 new_percent = weightToPercent(new_weight);
  251. LLSliderCtrl* slider = getChild<LLSliderCtrl>("param slider");
  252. if (slider)
  253. {
  254. if (slider->getMinValue() < new_percent
  255. && new_percent < slider->getMaxValue())
  256. {
  257. mWearable->setVisualParamWeight( hint->getVisualParam()->getID(), new_weight, FALSE);
  258. gAgent.getAvatarObject()->updateVisualParams();
  259. slider->setValue( weightToPercent( new_weight ) );
  260. }
  261. }
  262. }
  263. }
  264. // static
  265. void LLScrollingPanelParam::onHintMinMouseUp( void* userdata )
  266. {
  267. LLScrollingPanelParam* self = (LLScrollingPanelParam*) userdata;
  268. F32 elapsed_time = self->mMouseDownTimer.getElapsedTimeF32();
  269. LLVisualParamHint* hint = self->mHintMin;
  270. if (elapsed_time < PARAM_STEP_TIME_THRESHOLD)
  271. {
  272. // step in direction
  273. F32 current_weight = self->mWearable->getVisualParamWeight( hint->getVisualParam()->getID() );
  274. F32 range = self->mHintMax->getVisualParamWeight() - self->mHintMin->getVisualParamWeight();
  275. // step a fraction in the negative directiona
  276. F32 new_weight = current_weight - (range / 10.f);
  277. F32 new_percent = self->weightToPercent(new_weight);
  278. LLSliderCtrl* slider = self->getChild<LLSliderCtrl>("param slider");
  279. if (slider)
  280. {
  281. if (slider->getMinValue() < new_percent
  282. && new_percent < slider->getMaxValue())
  283. {
  284. self->mWearable->setVisualParamWeight(hint->getVisualParam()->getID(), new_weight, FALSE);
  285. slider->setValue( self->weightToPercent( new_weight ) );
  286. }
  287. }
  288. }
  289. LLVisualParamHint::requestHintUpdates( self->mHintMin, self->mHintMax );
  290. }
  291. void LLScrollingPanelParam::onHintMaxMouseUp( void* userdata )
  292. {
  293. LLScrollingPanelParam* self = (LLScrollingPanelParam*) userdata;
  294. F32 elapsed_time = self->mMouseDownTimer.getElapsedTimeF32();
  295. LLVOAvatarSelf* avatar = gAgent.getAvatarObject();
  296. if (avatar)
  297. {
  298. LLVisualParamHint* hint = self->mHintMax;
  299. if (elapsed_time < PARAM_STEP_TIME_THRESHOLD)
  300. {
  301. // step in direction
  302. F32 current_weight = self->mWearable->getVisualParamWeight( hint->getVisualParam()->getID() );
  303. F32 range = self->mHintMax->getVisualParamWeight() - self->mHintMin->getVisualParamWeight();
  304. // step a fraction in the negative direction
  305. F32 new_weight = current_weight + (range / 10.f);
  306. F32 new_percent = self->weightToPercent(new_weight);
  307. LLSliderCtrl* slider = self->getChild<LLSliderCtrl>("param slider");
  308. if (slider)
  309. {
  310. if (slider->getMinValue() < new_percent
  311. && new_percent < slider->getMaxValue())
  312. {
  313. self->mWearable->setVisualParamWeight(hint->getVisualParam()->getID(), new_weight, FALSE);
  314. slider->setValue( self->weightToPercent( new_weight ) );
  315. }
  316. }
  317. }
  318. }
  319. LLVisualParamHint::requestHintUpdates( self->mHintMin, self->mHintMax );
  320. }
  321. F32 LLScrollingPanelParam::weightToPercent( F32 weight )
  322. {
  323. LLViewerVisualParam* param = mParam;
  324. return (weight - param->getMinWeight()) /  (param->getMaxWeight() - param->getMinWeight()) * 100.f;
  325. }
  326. F32 LLScrollingPanelParam::percentToWeight( F32 percent )
  327. {
  328. LLViewerVisualParam* param = mParam;
  329. return percent / 100.f * (param->getMaxWeight() - param->getMinWeight()) + param->getMinWeight();
  330. }