guiSliderCtrl.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "console/console.h"
  23. #include "console/consoleTypes.h"
  24. #include "console/engineAPI.h"
  25. #include "gfx/gfxTextureManager.h"
  26. #include "gui/controls/guiSliderCtrl.h"
  27. #include "gui/core/guiDefaultControlRender.h"
  28. #include "gfx/primBuilder.h"
  29. #include "gfx/gfxDrawUtil.h"
  30. #include "sfx/sfxSystem.h"
  31. #include "sfx/sfxTrack.h"
  32. IMPLEMENT_CONOBJECT( GuiSliderCtrl );
  33. ConsoleDocClass( GuiSliderCtrl,
  34. "@brief A control that displays a value between its minimal and maximal bounds using a slider placed on a vertical "
  35. "or horizontal axis.\n\n"
  36. "A slider displays a value and allows that value to be changed by dragging a thumb control along the axis of the "
  37. "slider. In this way, the value is changed between its allowed minimum and maximum.\n\n"
  38. "To hook up script code to the value changes of a slider, use the #command and #altCommand properties. #command is "
  39. "executed once the thumb is released by the user whereas #altCommand is called any time the slider value changes. "
  40. "When changing the slider value from script, however, trigger of #altCommand is suppressed by default.\n\n"
  41. "The orientation of a slider is automatically determined from the ratio of its width to its height. If a slider is "
  42. "taller than it is wide, it will be rendered with a vertical orientation. If it is wider than it is tall, it will be "
  43. "rendered with a horizontal orientation.\n\n"
  44. "The rendering of a slider depends on the bitmap in the slider's profile. This bitmap must be a bitmap array comprised "
  45. "of at least five bitmap rectangles. The rectangles are used such that:\n\n"
  46. "- Rectangle #1: Left edge of slider\n"
  47. "- Rectangle #2: Center piece of slider; this is stretched between the left and right edge\n"
  48. "- Rectangle #3: Right edge of slider\n"
  49. "- Rectangle #4: Thumb button in normal state\n"
  50. "- Rectangle #5: Thumb button in highlighted (mouse-over) state\n\n"
  51. "@tsexample\n"
  52. "// Create a sound source and a slider that changes the volume of the source.\n"
  53. "\n"
  54. "%source = sfxPlayOnce( \"art/sound/testing\", AudioLoop2D );\n"
  55. "\n"
  56. "new GuiSlider()\n"
  57. "{\n"
  58. " // Update the sound source volume when the slider is being dragged and released.\n"
  59. " command = %source @ \".setVolume( $ThisControl.value );\";\n"
  60. "\n"
  61. " // Limit the range to 0..1 since that is the allowable range for sound volumes.\n"
  62. " range = \"0 1\";\n"
  63. "};\n"
  64. "@endtsexample\n\n"
  65. "@see GuiTextEditSliderCtrl\n"
  66. "@see GuiTextEditSliderBitmapCtrl\n\n"
  67. "@ingroup GuiValues"
  68. );
  69. IMPLEMENT_CALLBACK( GuiSliderCtrl, onMouseDragged, void, (), (),
  70. "Called when the left mouse button is dragged across the slider." );
  71. //----------------------------------------------------------------------------
  72. GuiSliderCtrl::GuiSliderCtrl()
  73. : mRange( 0., 1.f ),
  74. mTicks( 10 ),
  75. mRenderTicks(true),
  76. mSnap( false ),
  77. mValue( 0.5f ),
  78. mThumbSize( 8, 20 ),
  79. mShiftPoint( 5 ),
  80. mShiftExtent( 10 ),
  81. mIncAmount( 0.f ),
  82. mDisplayValue( false ),
  83. mMouseOver( false ),
  84. mDepressed( false ),
  85. mMouseDragged( false ),
  86. mHasTexture(false),
  87. mUseFillBar(false),
  88. mFillBarColor(ColorI(255,255,255)),
  89. mBitmapBounds(NULL)
  90. {
  91. }
  92. //----------------------------------------------------------------------------
  93. void GuiSliderCtrl::initPersistFields()
  94. {
  95. addGroup( "Slider" );
  96. addField( "range", TypePoint2F, Offset( mRange, GuiSliderCtrl ),
  97. "Min and max values corresponding to left and right slider position." );
  98. addField( "ticks", TypeS32, Offset( mTicks, GuiSliderCtrl ),
  99. "Spacing between tick marks in pixels. 0=off." );
  100. addField( "snap", TypeBool, Offset( mSnap, GuiSliderCtrl ),
  101. "Whether to snap the slider to tick marks." );
  102. addProtectedField( "value", TypeF32, Offset( mValue, GuiSliderCtrl ),
  103. _setValue, defaultProtectedGetFn,
  104. "The value corresponding to the current slider position." );
  105. addField("useFillBar", TypeBool, Offset(mUseFillBar, GuiSliderCtrl),
  106. "Whether to render the tick marks.");
  107. addField("fillBarColor", TypeColorI, Offset(mFillBarColor, GuiSliderCtrl),
  108. "Whether to render the tick marks.");
  109. addField("renderTicks", TypeBool, Offset(mRenderTicks, GuiSliderCtrl),
  110. "Whether to render the tick marks.");
  111. endGroup( "Slider" );
  112. Parent::initPersistFields();
  113. }
  114. //----------------------------------------------------------------------------
  115. void GuiSliderCtrl::setValue(F32 val, bool doCallback)
  116. {
  117. _updateThumb( val, mSnap, false, doCallback );
  118. }
  119. //----------------------------------------------------------------------------
  120. void GuiSliderCtrl::setActive( bool value )
  121. {
  122. if( !value && mDepressed )
  123. {
  124. // We're in the middle of a drag. Finish it here as once we've
  125. // been deactivated, we are not going to see a mouse-up event.
  126. mDepressed = false;
  127. mouseUnlock();
  128. execConsoleCallback();
  129. }
  130. Parent::setActive( value );
  131. }
  132. //----------------------------------------------------------------------------
  133. bool GuiSliderCtrl::onWake()
  134. {
  135. if( !Parent::onWake() )
  136. return false;
  137. mHasTexture = mProfile->constructBitmapArray() >= NumBitmaps;
  138. if( mHasTexture )
  139. {
  140. mBitmapBounds = mProfile->mBitmapArrayRects.address();
  141. mThumbSize = Point2I( mBitmapBounds[ SliderButtonNormal ].extent.x, mBitmapBounds[ SliderButtonNormal ].extent.y );
  142. }
  143. F32 value;
  144. if( mConsoleVariable[ 0 ] )
  145. value = getFloatVariable();
  146. else
  147. value = mValue;
  148. mValue = mClampF( value, mRange.x, mRange.y );
  149. // mouse scroll increment percentage is 5% of the range
  150. mIncAmount = ( ( mRange.y - mRange.x ) * 0.05 );
  151. if( ( mThumbSize.y + mProfile->mFont->getHeight() - 4 ) <= getExtent().y )
  152. mDisplayValue = true;
  153. else
  154. mDisplayValue = false;
  155. _updateThumb( mValue, mSnap, true );
  156. return true;
  157. }
  158. //----------------------------------------------------------------------------
  159. void GuiSliderCtrl::onMouseDown(const GuiEvent &event)
  160. {
  161. if ( !mActive || !mAwake || !mVisible )
  162. return;
  163. mouseLock();
  164. setFirstResponder();
  165. mDepressed = true;
  166. if (mProfile->isSoundButtonDownValid())
  167. SFX->playOnce(mProfile->getSoundButtonDownProfile());
  168. Point2I curMousePos = globalToLocalCoord( event.mousePoint );
  169. F32 value;
  170. if (getWidth() >= getHeight())
  171. value = F32(curMousePos.x-mShiftPoint) / F32(getWidth()-mShiftExtent)*(mRange.y-mRange.x) + mRange.x;
  172. else
  173. value = F32(curMousePos.y) / F32(getHeight())*(mRange.y-mRange.x) + mRange.x;
  174. _updateThumb( value, mSnap || ( event.modifier & SI_SHIFT ) );
  175. }
  176. //----------------------------------------------------------------------------
  177. void GuiSliderCtrl::onMouseDragged( const GuiEvent &event )
  178. {
  179. if ( !mActive || !mAwake || !mVisible )
  180. return;
  181. mMouseDragged = true;
  182. F32 value = _getThumbValue( event );
  183. _updateThumb( value, mSnap || ( event.modifier & SI_SHIFT ) );
  184. onMouseDragged_callback();
  185. }
  186. //----------------------------------------------------------------------------
  187. void GuiSliderCtrl::onMouseUp( const GuiEvent& event )
  188. {
  189. if ( !mActive || !mAwake || !mVisible )
  190. return;
  191. mouseUnlock();
  192. mDepressed = false;
  193. mMouseDragged = false;
  194. _updateThumb( _getThumbValue( event ), event.modifier & SI_SHIFT );
  195. execConsoleCallback();
  196. }
  197. //----------------------------------------------------------------------------
  198. void GuiSliderCtrl::onMouseEnter(const GuiEvent &event)
  199. {
  200. setUpdate();
  201. if( isMouseLocked() )
  202. {
  203. mDepressed = true;
  204. mMouseOver = true;
  205. }
  206. else
  207. {
  208. if( mActive && mProfile->mSoundButtonOver )
  209. {
  210. //F32 pan = (F32(event.mousePoint.x)/F32(getRoot()->getWidth())*2.0f-1.0f)*0.8f;
  211. if (mProfile->isSoundButtonOverValid())
  212. SFX->playOnce(mProfile->getSoundButtonOverProfile());
  213. }
  214. mMouseOver = true;
  215. }
  216. }
  217. //----------------------------------------------------------------------------
  218. void GuiSliderCtrl::onMouseLeave(const GuiEvent &)
  219. {
  220. setUpdate();
  221. if( isMouseLocked() )
  222. mDepressed = false;
  223. mMouseOver = false;
  224. }
  225. //----------------------------------------------------------------------------
  226. bool GuiSliderCtrl::onMouseWheelUp(const GuiEvent &event)
  227. {
  228. if ( !mActive || !mAwake || !mVisible )
  229. return Parent::onMouseWheelUp(event);
  230. _updateThumb( mValue + mIncAmount, ( event.modifier & SI_SHIFT ) );
  231. execConsoleCallback();
  232. return true;
  233. }
  234. //----------------------------------------------------------------------------
  235. bool GuiSliderCtrl::onMouseWheelDown(const GuiEvent &event)
  236. {
  237. if ( !mActive || !mAwake || !mVisible )
  238. return Parent::onMouseWheelUp(event);
  239. _updateThumb( mValue - mIncAmount, ( event.modifier & SI_SHIFT ) );
  240. execConsoleCallback();
  241. return true;
  242. }
  243. //----------------------------------------------------------------------------
  244. void GuiSliderCtrl::_updateThumb( F32 _value, bool snap, bool onWake, bool doCallback )
  245. {
  246. if( snap && mTicks > 0 )
  247. {
  248. // If the shift key is held, snap to the nearest tick, if any are being drawn
  249. F32 tickStep = (mRange.y - mRange.x) / F32(mTicks + 1);
  250. F32 tickSteps = (_value - mRange.x) / tickStep;
  251. S32 actualTick = S32(tickSteps + 0.5);
  252. _value = actualTick * tickStep + mRange.x;
  253. }
  254. // Clamp the thumb to legal values.
  255. if( _value < mRange.x )
  256. _value = mRange.x;
  257. if( _value > mRange.y )
  258. _value = mRange.y;
  259. // If value hasn't changed and this isn't the initial update on
  260. // waking, do nothing.
  261. if( mValue == _value && !onWake )
  262. return;
  263. mValue = _value;
  264. Point2I ext = getExtent();
  265. ext.x -= ( mShiftExtent + mThumbSize.x ) / 2;
  266. // update the bounding thumb rect
  267. if (getWidth() >= getHeight())
  268. { // HORZ thumb
  269. S32 mx = (S32)((F32(ext.x) * (mValue-mRange.x) / (mRange.y-mRange.x)));
  270. S32 my = ext.y/2;
  271. if(mDisplayValue)
  272. my = mThumbSize.y/2;
  273. mThumb.point.x = mx - (mThumbSize.x/2);
  274. mThumb.point.y = my - (mThumbSize.y/2);
  275. mThumb.extent = mThumbSize;
  276. }
  277. else
  278. { // VERT thumb
  279. S32 mx = ext.x/2;
  280. S32 my = (S32)((F32(ext.y) * (mValue-mRange.x) / (mRange.y-mRange.x)));
  281. mThumb.point.x = mx - (mThumbSize.y/2);
  282. mThumb.point.y = my - (mThumbSize.x/2);
  283. mThumb.extent.x = mThumbSize.y;
  284. mThumb.extent.y = mThumbSize.x;
  285. }
  286. setFloatVariable(mValue);
  287. setUpdate();
  288. // Use the alt console command if you want to continually update:
  289. if ( !onWake && doCallback )
  290. execAltConsoleCallback();
  291. }
  292. //----------------------------------------------------------------------------
  293. void GuiSliderCtrl::onRender(Point2I offset, const RectI &updateRect)
  294. {
  295. Point2I pos(offset.x+mShiftPoint, offset.y);
  296. Point2I ext(getWidth() - mShiftExtent, getHeight());
  297. RectI thumb = mThumb;
  298. GFXDrawUtil* drawUtil = GFX->getDrawUtil();
  299. if (mUseFillBar)
  300. {
  301. drawUtil->drawRectFill(RectI(offset.x, offset.y, getWidth() * mValue, getHeight()), mFillBarColor);
  302. renderChildControls(offset, updateRect);
  303. return;
  304. }
  305. if( mHasTexture )
  306. {
  307. if(mTicks > 0 && mRenderTicks)
  308. {
  309. // TODO: tick marks should be positioned based on the bitmap dimensions.
  310. Point2I mid(ext.x, ext.y/2);
  311. Point2I oldpos = pos;
  312. pos += Point2I(1, 0);
  313. PrimBuild::color4f( 0.f, 0.f, 0.f, 1.f );
  314. PrimBuild::begin( GFXLineList, ( mTicks + 2 ) * 2 );
  315. // tick marks
  316. for (U32 t = 0; t <= (mTicks+1); t++)
  317. {
  318. S32 x = (S32)(F32(mid.x+1)/F32(mTicks+1)*F32(t)) + pos.x;
  319. S32 y = pos.y + mid.y;
  320. PrimBuild::vertex2i(x, y + mShiftPoint);
  321. PrimBuild::vertex2i(x, y + mShiftPoint*2 + 2);
  322. }
  323. PrimBuild::end();
  324. // TODO: it would be nice, if the primitive builder were a little smarter,
  325. // so that we could change colors midstream.
  326. PrimBuild::color4f(0.9f, 0.9f, 0.9f, 1.0f);
  327. PrimBuild::begin( GFXLineList, ( mTicks + 2 ) * 2 );
  328. // tick marks
  329. for (U32 t = 0; t <= (mTicks+1); t++)
  330. {
  331. S32 x = (S32)(F32(mid.x+1)/F32(mTicks+1)*F32(t)) + pos.x + 1;
  332. S32 y = pos.y + mid.y + 1;
  333. PrimBuild::vertex2i(x, y + mShiftPoint );
  334. PrimBuild::vertex2i(x, y + mShiftPoint * 2 + 3);
  335. }
  336. PrimBuild::end();
  337. pos = oldpos;
  338. }
  339. S32 index = SliderButtonNormal;
  340. if(mMouseOver)
  341. index = SliderButtonHighlight;
  342. drawUtil->clearBitmapModulation();
  343. //left border
  344. drawUtil->drawBitmapSR(mProfile->getBitmapResource(), Point2I(offset.x,offset.y), mBitmapBounds[SliderLineLeft]);
  345. //right border
  346. drawUtil->drawBitmapSR(mProfile->getBitmapResource(), Point2I(offset.x + getWidth() - mBitmapBounds[SliderLineRight].extent.x, offset.y), mBitmapBounds[SliderLineRight]);
  347. //draw our center piece to our slider control's border and stretch it
  348. RectI destRect;
  349. destRect.point.x = offset.x + mBitmapBounds[SliderLineLeft].extent.x;
  350. destRect.extent.x = getWidth() - mBitmapBounds[SliderLineLeft].extent.x - mBitmapBounds[SliderLineRight].extent.x;
  351. destRect.point.y = offset.y;
  352. destRect.extent.y = mBitmapBounds[SliderLineCenter].extent.y;
  353. RectI stretchRect;
  354. stretchRect = mBitmapBounds[SliderLineCenter];
  355. stretchRect.inset(1,0);
  356. drawUtil->drawBitmapStretchSR(mProfile->getBitmapResource(), destRect, stretchRect);
  357. //draw our control slider button
  358. thumb.point += pos;
  359. drawUtil->drawBitmapSR(mProfile->getBitmapResource(),Point2I(thumb.point.x,offset.y ),mBitmapBounds[index]);
  360. }
  361. else if (getWidth() >= getHeight())
  362. {
  363. Point2I mid(ext.x, ext.y/2);
  364. if(mDisplayValue)
  365. mid.set(ext.x, mThumbSize.y/2);
  366. PrimBuild::color4f( 0.f, 0.f, 0.f, 1.f );
  367. PrimBuild::begin( GFXLineList, ( mTicks + 2 ) * 2 + 2);
  368. // horz rule
  369. PrimBuild::vertex2i( pos.x, pos.y + mid.y );
  370. PrimBuild::vertex2i( pos.x + mid.x, pos.y + mid.y );
  371. // tick marks
  372. if (mRenderTicks)
  373. {
  374. for (U32 t = 0; t <= (mTicks + 1); t++)
  375. {
  376. S32 x = (S32)(F32(mid.x - 1) / F32(mTicks + 1) * F32(t));
  377. PrimBuild::vertex2i(pos.x + x, pos.y + mid.y - mShiftPoint);
  378. PrimBuild::vertex2i(pos.x + x, pos.y + mid.y + mShiftPoint);
  379. }
  380. }
  381. PrimBuild::end();
  382. }
  383. else
  384. {
  385. Point2I mid(ext.x/2, ext.y);
  386. PrimBuild::color4f( 0.f, 0.f, 0.f, 1.f );
  387. PrimBuild::begin( GFXLineList, ( mTicks + 2 ) * 2 + 2);
  388. // horz rule
  389. PrimBuild::vertex2i( pos.x + mid.x, pos.y );
  390. PrimBuild::vertex2i( pos.x + mid.x, pos.y + mid.y );
  391. // tick marks
  392. if (mRenderTicks)
  393. {
  394. for (U32 t = 0; t <= (mTicks + 1); t++)
  395. {
  396. S32 y = (S32)(F32(mid.y - 1) / F32(mTicks + 1) * F32(t));
  397. PrimBuild::vertex2i(pos.x + mid.x - mShiftPoint, pos.y + y);
  398. PrimBuild::vertex2i(pos.x + mid.x + mShiftPoint, pos.y + y);
  399. }
  400. }
  401. PrimBuild::end();
  402. mDisplayValue = false;
  403. }
  404. // draw the thumb
  405. thumb.point += pos;
  406. renderRaisedBox(thumb, mProfile);
  407. if(mDisplayValue)
  408. {
  409. char buf[20];
  410. dSprintf(buf,sizeof(buf),"%0.3f",mValue);
  411. Point2I textStart = thumb.point;
  412. S32 txt_w = mProfile->mFont->getStrWidth((const UTF8 *)buf);
  413. textStart.x += (S32)((thumb.extent.x/2.0f));
  414. textStart.y += thumb.extent.y - 2; //19
  415. textStart.x -= (txt_w/2);
  416. if(textStart.x < offset.x)
  417. textStart.x = offset.x;
  418. else if(textStart.x + txt_w > offset.x+getWidth())
  419. textStart.x -=((textStart.x + txt_w) - (offset.x+getWidth()));
  420. drawUtil->setBitmapModulation(mProfile->mFontColor);
  421. drawUtil->drawText(mProfile->mFont, textStart, buf, mProfile->mFontColors);
  422. }
  423. renderChildControls(offset, updateRect);
  424. }
  425. //----------------------------------------------------------------------------
  426. bool GuiSliderCtrl::resize( const Point2I& newPosition, const Point2I& newSize )
  427. {
  428. if( !Parent::resize( newPosition, newSize ) )
  429. return false;
  430. _updateThumb( mValue, false, true, false );
  431. return true;
  432. }
  433. //----------------------------------------------------------------------------
  434. void GuiSliderCtrl::parentResized( const RectI& oldParentRect, const RectI& newParentRect )
  435. {
  436. Parent::parentResized( oldParentRect, newParentRect );
  437. _updateThumb( mValue, false, true, false );
  438. }
  439. //----------------------------------------------------------------------------
  440. F32 GuiSliderCtrl::_getThumbValue( const GuiEvent& event )
  441. {
  442. Point2I curMousePos = globalToLocalCoord( event.mousePoint );
  443. F32 value;
  444. if( getWidth() >= getHeight() )
  445. value = F32( curMousePos.x - mShiftPoint ) / F32( getWidth() - mShiftExtent ) * ( mRange.y - mRange.x ) + mRange.x;
  446. else
  447. value = F32( curMousePos.y ) / F32( getHeight() ) * ( mRange.y - mRange.x ) + mRange.x;
  448. if(value > mRange.y )
  449. value = mRange.y;
  450. else if( value < mRange.x )
  451. value = mRange.x;
  452. if( mSnap || ( event.modifier & SI_SHIFT && mTicks >= 1 ) )
  453. {
  454. // If the shift key is held, snap to the nearest tick, if any are being drawn
  455. F32 tickStep = ( mRange.y - mRange.x ) / F32( mTicks + 1 );
  456. F32 tickSteps = (value - mRange.x ) / tickStep;
  457. S32 actualTick = S32( tickSteps + 0.5 );
  458. value = actualTick * tickStep + mRange.x;
  459. AssertFatal( value <= mRange.y && value >= mRange.x, "Error, out of bounds value generated from shift-snap of slider" );
  460. }
  461. return value;
  462. }
  463. //=============================================================================
  464. // Console Methods.
  465. //=============================================================================
  466. //-----------------------------------------------------------------------------
  467. DefineEngineMethod( GuiSliderCtrl, getValue, F32, (),,
  468. "Get the current value of the slider based on the position of the thumb.\n"
  469. "@return Slider position (from range.x to range.y)." )
  470. {
  471. return object->getValue();
  472. }
  473. //----------------------------------------------------------------------------
  474. DefineEngineMethod( GuiSliderCtrl, setValue, void, ( F32 pos, bool doCallback ), ( false ),
  475. "Set position of the thumb on the slider.\n"
  476. "@param pos New slider position (from range.x to range.y)\n"
  477. "@param doCallback If true, the altCommand callback will be invoked\n" )
  478. {
  479. object->setValue( pos, doCallback );
  480. }
  481. //----------------------------------------------------------------------------
  482. DefineEngineMethod( GuiSliderCtrl, isThumbBeingDragged, bool, (),,
  483. "Returns true if the thumb is currently being dragged by the user. This method is mainly useful "
  484. "for scrubbing type sliders where the slider position is sync'd to a changing value. When the "
  485. "user is dragging the thumb, however, the sync'ing should pause and not get in the way of the user." )
  486. {
  487. return object->isThumbBeingDragged();
  488. }