guiTextEditSliderCtrl.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 _GUITEXTEDITSLIDERCTRL_H_
  23. #define _GUITEXTEDITSLIDERCTRL_H_
  24. #ifndef _GUITYPES_H_
  25. #include "gui/core/guiTypes.h"
  26. #endif
  27. #ifndef _GUITEXTEDITCTRL_H_
  28. #include "gui/controls/guiTextEditCtrl.h"
  29. #endif
  30. class GuiTextEditSliderCtrl : public GuiTextEditCtrl
  31. {
  32. typedef GuiTextEditCtrl Parent;
  33. public:
  34. enum CtrlArea
  35. {
  36. None,
  37. Slider,
  38. ArrowUp,
  39. ArrowDown
  40. };
  41. GuiTextEditSliderCtrl();
  42. ~GuiTextEditSliderCtrl();
  43. DECLARE_CONOBJECT(GuiTextEditSliderCtrl);
  44. DECLARE_CATEGORY( "Gui Values" );
  45. DECLARE_DESCRIPTION( "A text that shows a numeric value and up/down arrows to\n"
  46. "increase/decrease the value." );
  47. static void initPersistFields();
  48. virtual void getText(char *dest); // dest must be of size
  49. // StructDes::MAX_STRING_LEN + 1
  50. virtual void setText(const char *txt);
  51. void setValue();
  52. void checkRange();
  53. void checkIncValue();
  54. void timeInc(U32 elapseTime);
  55. virtual bool onKeyDown(const GuiEvent &event);
  56. virtual void onMouseDown(const GuiEvent &event);
  57. virtual void onMouseDragged(const GuiEvent &event);
  58. virtual void onMouseUp(const GuiEvent &event);
  59. virtual bool onMouseWheelUp(const GuiEvent &event);
  60. virtual bool onMouseWheelDown(const GuiEvent &event);
  61. virtual void onPreRender();
  62. virtual void onRender(Point2I offset, const RectI &updateRect);
  63. protected:
  64. Point2F mRange;
  65. F32 mIncAmount;
  66. F32 mValue;
  67. F32 mIncCounter;
  68. F32 mMulInc;
  69. StringTableEntry mFormat;
  70. U32 mMouseDownTime;
  71. bool mFocusOnMouseWheel;
  72. CtrlArea mTextAreaHit;
  73. };
  74. #endif //_GUITEXTEDITSLIDERCTRL_H_