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