guiButtonBaseCtrl.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. /// @}
  65. public:
  66. GuiButtonBaseCtrl();
  67. bool onWake();
  68. DECLARE_CONOBJECT( GuiButtonBaseCtrl );
  69. DECLARE_CATEGORY( "Gui Buttons" );
  70. DECLARE_DESCRIPTION( "A basic button control." );
  71. static void initPersistFields();
  72. void setText(const char *text);
  73. void setTextID(S32 id);
  74. void setTextID(const char *id);
  75. const char *getText();
  76. void setStateOn( bool bStateOn );
  77. bool getStateOn() const { return mStateOn; }
  78. void setDepressed( bool depressed ) { mDepressed = depressed; }
  79. void resetState() {mDepressed = false; mHighlighted = false;}
  80. void setHighlighted(bool highlighted) { mHighlighted = highlighted; }
  81. bool isHighlighted() { return mHighlighted; }
  82. void acceleratorKeyPress(U32 index);
  83. void acceleratorKeyRelease(U32 index);
  84. void onMouseDown(const GuiEvent &);
  85. void onMouseUp(const GuiEvent &);
  86. void onMouseDragged( const GuiEvent& event );
  87. void onRightMouseUp(const GuiEvent &);
  88. void onMouseEnter(const GuiEvent &);
  89. void onMouseLeave(const GuiEvent &);
  90. bool onKeyDown(const GuiEvent &event);
  91. bool onKeyUp(const GuiEvent &event);
  92. void setScriptValue(const char *value);
  93. const char *getScriptValue();
  94. void onMessage(GuiControl *,S32 msg);
  95. void onAction();
  96. bool usesMouseEvents() const { return mUseMouseEvents; }
  97. void setUseMouseEvents( bool val ) { mUseMouseEvents = val; }
  98. };
  99. typedef GuiButtonBaseCtrl::ButtonType GuiButtonType;
  100. DefineEnumType( GuiButtonType );
  101. #endif