Button.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. GWEN
  3. Copyright (c) 2010 Facepunch Studios
  4. See license in Gwen.h
  5. */
  6. #pragma once
  7. #ifndef GWEN_CONTROLS_BUTTON_H
  8. #define GWEN_CONTROLS_BUTTON_H
  9. #include "Gwen/TextObject.h"
  10. #include "Gwen/Controls/Base.h"
  11. #include "Gwen/Controls/Label.h"
  12. namespace Gwen
  13. {
  14. namespace Controls
  15. {
  16. class ImagePanel;
  17. class GWEN_EXPORT Button : public Label
  18. {
  19. public:
  20. GWEN_CONTROL( Button, Label );
  21. virtual void Render( Skin::Base* skin );
  22. virtual void OnMouseClickLeft( int x, int y, bool bDown );
  23. virtual void OnMouseDoubleClickLeft( int x, int y );
  24. virtual bool OnKeySpace( bool bDown );
  25. virtual void OnPress();
  26. virtual void AcceleratePressed();
  27. virtual bool IsDepressed() const { return m_bDepressed; }
  28. //
  29. // Buttons can be toggle type, which means that it is
  30. // toggled on and off. Its toggle status is in IsDepressed.
  31. //
  32. virtual void SetIsToggle( bool b ){ m_bToggle = b; }
  33. virtual bool IsToggle() const { return m_bToggle; }
  34. virtual bool GetToggleState() const { return m_bToggleStatus; }
  35. virtual void SetToggleState( bool b );
  36. virtual void Toggle(){ SetToggleState( !GetToggleState() ); }
  37. virtual void SetImage( const TextObject& strName, bool bCenter = false );
  38. // You can use this to trigger OnPress directly from other controls using GWEN_CALL_EX
  39. virtual void ReceiveEventPress( Base* /*pControl*/ )
  40. {
  41. OnPress();
  42. }
  43. virtual void SizeToContents();
  44. virtual void Layout( Skin::Base* pSkin );
  45. virtual bool OnKeyReturn(bool bDown)
  46. {
  47. onKeyboardReturn.Call(this);
  48. return true;
  49. }
  50. public:
  51. Gwen::Event::Caller onPress;
  52. Gwen::Event::Caller onDown;
  53. Gwen::Event::Caller onUp;
  54. Gwen::Event::Caller onDoubleClick;
  55. Gwen::Event::Caller onKeyboardReturn;
  56. Gwen::Event::Caller onToggle;
  57. Gwen::Event::Caller onToggleOn;
  58. Gwen::Event::Caller onToggleOff;
  59. protected:
  60. ImagePanel* m_Image;
  61. bool m_bDepressed;
  62. bool m_bToggle;
  63. bool m_bToggleStatus;
  64. bool m_bCenterImage;
  65. };
  66. }
  67. }
  68. #endif