guiSliderCtrl.h 3.8 KB

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