guiButtonBaseCtrl.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 _GUIBUTTONBASECTRL_H_
  23. #define _GUIBUTTONBASECTRL_H_
  24. #ifndef _GUICONTROL_H_
  25. #include "gui/core/guiControl.h"
  26. #endif
  27. /// Base class for all button controls. Subclasses are mostly for specific
  28. /// rendering types.
  29. ///
  30. class GuiButtonBaseCtrl : public GuiControl
  31. {
  32. public:
  33. typedef GuiControl Parent;
  34. enum ButtonType
  35. {
  36. ButtonTypePush,
  37. ButtonTypeCheck,
  38. ButtonTypeRadio,
  39. };
  40. protected:
  41. StringTableEntry mButtonText;
  42. StringTableEntry mButtonTextID;
  43. bool mDepressed;
  44. bool mHighlighted;
  45. bool mStateOn;
  46. S32 mButtonType;
  47. S32 mRadioGroup;
  48. bool mUseMouseEvents;
  49. /// Point where left mouse button was pressed down. Used to find when to start
  50. /// a mouse drag.
  51. Point2I mMouseDownPoint;
  52. ///
  53. bool mMouseDragged;
  54. /// @name Callbacks
  55. /// @{
  56. DECLARE_CALLBACK(void, onMouseDown, ());
  57. DECLARE_CALLBACK(void, onMouseUp, ());
  58. DECLARE_CALLBACK(void, onClick, ());
  59. DECLARE_CALLBACK(void, onRightClick, ());
  60. DECLARE_CALLBACK(void, onDoubleClick, ());
  61. DECLARE_CALLBACK(void, onMouseEnter, ());
  62. DECLARE_CALLBACK(void, onMouseLeave, ());
  63. DECLARE_CALLBACK(void, onMouseDragged, ());
  64. DECLARE_CALLBACK(void, onHighlighted, (bool));
  65. /// @}
  66. public:
  67. GuiButtonBaseCtrl();
  68. bool onWake() override;
  69. DECLARE_CONOBJECT(GuiButtonBaseCtrl);
  70. DECLARE_CATEGORY("Gui Buttons");
  71. DECLARE_DESCRIPTION("A basic button control.");
  72. static void initPersistFields();
  73. void setText(const char* text);
  74. void setTextID(S32 id);
  75. void setTextID(const char* id);
  76. const char* getText();
  77. void setStateOn(bool bStateOn);
  78. bool getStateOn() const { return mStateOn; }
  79. void setDepressed(bool depressed) { mDepressed = depressed; }
  80. void resetState() { mDepressed = false; mHighlighted = false; }
  81. void setHighlighted(bool highlighted);
  82. bool isHighlighted() { return mHighlighted; }
  83. void acceleratorKeyPress(U32 index) override;
  84. void acceleratorKeyRelease(U32 index) override;
  85. void onMouseDown(const GuiEvent&) override;
  86. void onMouseUp(const GuiEvent&) override;
  87. void onMouseDragged(const GuiEvent& event) override;
  88. void onRightMouseUp(const GuiEvent&) override;
  89. void onMouseEnter(const GuiEvent&) override;
  90. void onMouseLeave(const GuiEvent&) override;
  91. bool onKeyDown(const GuiEvent& event) override;
  92. bool onKeyUp(const GuiEvent& event) override;
  93. void setScriptValue(const char* value) override;
  94. const char* getScriptValue() override;
  95. void onMessage(GuiControl*, S32 msg) override;
  96. void onAction() override;
  97. bool usesMouseEvents() const { return mUseMouseEvents; }
  98. void setUseMouseEvents(bool val) { mUseMouseEvents = val; }
  99. };
  100. typedef GuiButtonBaseCtrl::ButtonType GuiButtonType;
  101. DefineEnumType(GuiButtonType);
  102. #endif