summaryrefslogtreecommitdiff
path: root/utils/vgui_panel_zoo/ButtonDemo.cpp
blob: e0baa40a95dd0a391fce3cceda66c74725ef00a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//
#include "DemoPage.h"

#include <VGUI/IVGui.h>
#include <vgui_controls/Controls.h>
#include <Keyvalues.h>
#include <vgui_controls/Button.h>


using namespace vgui;


class ButtonDemo: public DemoPage
{
	public:
		ButtonDemo(Panel *parent, const char *name);
		~ButtonDemo();

		void OnButtonClicked();
	
	private:
		Button *m_pButton;
		
		DECLARE_PANELMAP();
};

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
ButtonDemo::ButtonDemo(Panel *parent, const char *name) : DemoPage(parent, name)
{
	// Create a button.
	m_pButton = new Button(this, "AButton", "ClickMe");

	// Set its position.
	m_pButton->SetPos(100, 100);

	// Install a command that will be executed when the button is pressed
	// Here we use a KeyValues command, this is mapped using the Message map
	// below to a function.
	m_pButton->SetCommand(new KeyValues ("ButtonClicked"));
	
}

//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
ButtonDemo::~ButtonDemo()
{
}

//-----------------------------------------------------------------------------
// Purpose:	 Respond to a message based action signal
//-----------------------------------------------------------------------------
void ButtonDemo::OnButtonClicked()
{
	ivgui()->DPrintf("Button was clicked.\n");
}



MessageMapItem_t ButtonDemo::m_MessageMap[] =
{
	MAP_MESSAGE( ButtonDemo, "ButtonClicked", OnButtonClicked ),   
};

IMPLEMENT_PANELMAP(ButtonDemo, DemoPage);



Panel* ButtonDemo_Create(Panel *parent)
{
	return new ButtonDemo(parent, "ButtonDemo");
}