summaryrefslogtreecommitdiff
path: root/utils/vgui_panel_zoo/RadioButtonDemo.cpp
blob: 65f72516a3d06eedee4da17baf613765eebfd29a (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//
#include "DemoPage.h"

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

#include <vgui_controls/RadioButton.h>


using namespace vgui;


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

		void OnRadioButtonHit();

	
	private:
		RadioButton *m_pRadioButton1;
		RadioButton *m_pRadioButton2;

		DECLARE_PANELMAP();
};

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
RadioButtonDemo::RadioButtonDemo(Panel *parent, const char *name) : DemoPage(parent, name)
{
	// Radio buttons are a little dot circle with a label attached.
	// You can have only one radio button selected at a time.
	// Other radio buttons will become deselected.

	// Create a radio button.
	m_pRadioButton1 = new RadioButton(this, "ARadioButton", "ClickMe");

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

	// A little label for our button
	m_pRadioButton1->SetText("Click the radio button!");

	// Size the label so the message fits nicely.
	m_pRadioButton1->SizeToContents();

	// Radio buttons are Buttons, and can send a command when clicked.
    // Install a command to be sent when the box is checked or unchecked
	m_pRadioButton1->SetCommand(new KeyValues("Radio1"));

	// Radio buttons are grouped together by tab position sub tab position
	// determines the order to move through the buttons when arrow keys are hit
	m_pRadioButton1->SetSubTabPosition(0);


	// Create another radio button.
	m_pRadioButton2 = new RadioButton(this, "AnotherRadioButton", "ClickMe");

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

	// A little label for our button
	m_pRadioButton2->SetText("Click the other radio button!");

	// Size the label so the message fits nicely.
	m_pRadioButton2->SizeToContents();

	// Start the button off checked. Its unchecked by default.
	m_pRadioButton2->SetSelected(true);

	m_pRadioButton1->SetSubTabPosition(1);

    // Don't install a command to be sent when the box is checked or unchecked,
	// Because all buttons respons when a new one is checked (they uncheck themselves if checked)
	// In this case when a button is selected a RadioButtonChecked message gets sent

}

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

//-----------------------------------------------------------------------------
// Purpose:	 Respond to a message based action signal
//-----------------------------------------------------------------------------
void RadioButtonDemo::OnRadioButtonHit()
{
   	if (m_pRadioButton1->IsSelected())
	{
		ivgui()->DPrintf("Radio button one is checked.\n"); 
	}
	else
	{
		ivgui()->DPrintf("Radio button one is unchecked.\n"); 
	}
	
	if (m_pRadioButton2->IsSelected())
	{
		ivgui()->DPrintf("Radio button two is checked.\n"); 
	}
	else
	{
		ivgui()->DPrintf("Radio button two is unchecked.\n"); 
	}
}



MessageMapItem_t RadioButtonDemo::m_MessageMap[] =
{
	MAP_MESSAGE( RadioButtonDemo, "RadioButtonChecked", OnRadioButtonHit ),
};

IMPLEMENT_PANELMAP(RadioButtonDemo, DemoPage);



Panel* RadioButtonDemo_Create(Panel *parent)
{
	return new RadioButtonDemo(parent, "RadioButtonDemo");
}