guiSliderCtrl.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #ifndef _GUISLIDERCTRL_H_
  23. #define _GUISLIDERCTRL_H_
  24. #ifndef _GUICONTROL_H_
  25. #include "gui/core/guiControl.h"
  26. #endif
  27. /// A slider control that selects out of a floating-point value range.
  28. class GuiSliderCtrl : public GuiControl
  29. {
  30. public:
  31. typedef GuiControl Parent;
  32. protected:
  33. Point2F mRange;
  34. U32 mTicks;
  35. bool mSnap;
  36. F32 mValue;
  37. RectI mThumb;
  38. Point2I mThumbSize;
  39. S32 mShiftPoint;
  40. S32 mShiftExtent;
  41. F32 mIncAmount;
  42. bool mDisplayValue;
  43. bool mDepressed;
  44. bool mMouseOver;
  45. bool mMouseDragged;
  46. bool mHasTexture;
  47. enum
  48. {
  49. SliderLineLeft = 0,
  50. SliderLineCenter,
  51. SliderLineRight,
  52. SliderButtonNormal,
  53. SliderButtonHighlight,
  54. NumBitmaps
  55. };
  56. RectI *mBitmapBounds;
  57. F32 _getThumbValue( const GuiEvent& event );
  58. void _updateThumb( F32 value, bool snap = true, bool onWake = false, bool doCallback = true );
  59. /// @name Callbacks
  60. /// @{
  61. DECLARE_CALLBACK( void, onMouseDragged, () );
  62. /// @}
  63. static bool _setValue( void* object, const char* index, const char* data ) { static_cast< GuiSliderCtrl* >( object )->setValue( dAtof( data ) ); return false; }
  64. public:
  65. GuiSliderCtrl();
  66. bool isThumbBeingDragged() const { return mDepressed; }
  67. const Point2F& getRange() const { return mRange; }
  68. // GuiControl.
  69. bool onWake();
  70. void onMouseDown(const GuiEvent &event);
  71. void onMouseDragged(const GuiEvent &event);
  72. void onMouseUp(const GuiEvent &);
  73. void onMouseLeave(const GuiEvent &);
  74. void onMouseEnter(const GuiEvent &);
  75. bool onMouseWheelUp(const GuiEvent &event);
  76. bool onMouseWheelDown(const GuiEvent &event);
  77. void setActive( bool value );
  78. F32 getValue() const { return mValue; }
  79. void setScriptValue(const char *val) { setValue(dAtof(val)); }
  80. void setValue(F32 val, bool doCallback=false);
  81. void onRender(Point2I offset, const RectI &updateRect);
  82. virtual bool resize( const Point2I& newSize, const Point2I& newExtent );
  83. virtual void parentResized( const RectI& oldParentRect, const RectI& newParentRect );
  84. static void initPersistFields();
  85. DECLARE_CONOBJECT(GuiSliderCtrl);
  86. DECLARE_CATEGORY( "Gui Values" );
  87. DECLARE_DESCRIPTION( "A control that implements a horizontal or vertical slider to\n"
  88. "select/represent values in a certain range." )
  89. };
  90. #endif