guiButtonBaseCtrl.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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();
  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()
  81. {
  82. mDepressed = false;
  83. mHighlighted = false;
  84. onHighlighted_callback(false);
  85. }
  86. void setHighlighted(bool highlighted)
  87. {
  88. mHighlighted = highlighted;
  89. onHighlighted_callback(highlighted);
  90. }
  91. bool isHighlighted() { return mHighlighted; }
  92. void acceleratorKeyPress(U32 index);
  93. void acceleratorKeyRelease(U32 index);
  94. void onMouseDown(const GuiEvent &);
  95. void onMouseUp(const GuiEvent &);
  96. void onMouseDragged( const GuiEvent& event );
  97. void onRightMouseUp(const GuiEvent &);
  98. void onMouseEnter(const GuiEvent &);
  99. void onMouseLeave(const GuiEvent &);
  100. bool onKeyDown(const GuiEvent &event);
  101. bool onKeyUp(const GuiEvent &event);
  102. void setScriptValue(const char *value);
  103. const char *getScriptValue();
  104. void onMessage(GuiControl *,S32 msg);
  105. void onAction();
  106. bool usesMouseEvents() const { return mUseMouseEvents; }
  107. void setUseMouseEvents( bool val ) { mUseMouseEvents = val; }
  108. };
  109. typedef GuiButtonBaseCtrl::ButtonType GuiButtonType;
  110. DefineEnumType( GuiButtonType );
  111. #endif