summaryrefslogtreecommitdiff
path: root/utils/vgui_panel_zoo/EditablePanel2Demo.cpp
blob: 111d338daa61125e54b9a06af20518bce68662c0 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//
#include "DemoPage.h"

#include "tier1/KeyValues.h"
#include <vgui_controls/ComboBox.h>

using namespace vgui;


class EditablePanel2Demo: public DemoPage
{
	public:
		EditablePanel2Demo(Panel *parent, const char *name);
		~EditablePanel2Demo();
	
	private:
		ComboBox *m_pInternetSpeed;	
};

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
EditablePanel2Demo::EditablePanel2Demo(Panel *parent, const char *name) : DemoPage(parent, name)
{
	// Editable panels are able to have their layout described by external
	// resource files. All Frames belong to the Editable Panel class.
	// The class EditablePanel2Demo is a PropertyPage class, and PropertyPage
	// is an EditablePanel, so we can load in a resource file for this class.


	// Load the vgui controls from a resource file.
	// The resource file looks like this:
	/* EDITABLE PANEL DEMO RESOURCE FILE LAYOUT
	"EditablePanelDemo"
	{
		"SpeedLabel"
		{
			"ControlName"		"Label"
				"fieldName"		"SpeedLabel"
				"xpos"		"20"
				"ypos"		"30"
				"wide"		"96"
				"tall"		"20"
				"autoResize"		"0"
				"pinCorner"		"0"
				"visible"		"1"
				"enabled"		"1"
				"tabPosition"		"0"
				"labelText"		"Internet &Speed"
				"textAlignment"		"east"
				"associate"		"InternetSpeed"
		}
		"InternetSpeed"
		{
			"ControlName"		"ComboBox"
				"fieldName"		"InternetSpeed"
				"xpos"		"124"
				"ypos"		"30"
				"wide"		"200"
				"tall"		"20"
				"autoResize"		"0"
				"pinCorner"		"0"
				"visible"		"1"
				"enabled"		"1"
				"tabPosition"		"0"
				"textHidden"		"0"
				"editable"		"0"
				"maxchars"		"-1"
		}
	}
	*/

	// VGUI control panel resource values are grouped by a panel name, here 
	// we have 2 panels, one called "SpeedLabel" and one called
	// "Internet Speed".
	// Each control has a set of keyValues that describe attributes of
	// the panel. SpeedLabel's control name is Label, this is a vgui Label class.
	// Its 'xpos' and 'ypos' tell is position in the parent window. 
	// Its 'wide' and 'tall' tell its size.
	// 'AutoResize' is false meaning this panel will not grow or shrink in size
	// response to panel resizing.
	// More panel attributes follow, until we come to 'labelText'.
	// This is the text that will appear in the label. The text is
	// "Internet Speed" and the ampersand (&) in front of the 'S' indicates
	// that S is a hotkey in the label name.
	// 'Associate' associates this label with another vgui control that will
	// gain focus when the hotkey is hit. The associated control is called
	// "InternetSpeed" and this panel name happens to be the very next panel in the list.
	// Its 'ControlName' tells us it is a ComboBox. Hitting the 'S' hotkey will trigger
	// the combo box to gain focus. Note that the combo box does not currently 
	// have any items within it.


	// This will be the menu items of our combo box menu.	
	// List of all the different internet speeds
	char *g_Speeds[] =
	{
		{ "Modem - 14.4k"},
		{ "Modem - 28.8k"},
		{ "Modem - 33.6k"},
		{ "Modem - 56k"},
		{ "ISDN - 112k"},
		{ "DSL > 256k"},
		{ "LAN/T1 > 1M"},		
	};

	// Create a combo box with the name "InternetSpeed"
	// The parameters of the resource file will be applied to this
	// combo box.
	m_pInternetSpeed = new ComboBox(this, "InternetSpeed", ARRAYSIZE(g_Speeds), false);

	// Add menu items to this combo box.
	for (int i = 0; i < ARRAYSIZE(g_Speeds); i++)
	{
		m_pInternetSpeed->AddItem(g_Speeds[i], NULL );
	}

	// Load the resource file settings into our panel.
	LoadControlSettings("Demo/EditablePanelDemo.res");

	// When the settings are applied (in applySettings()) our panels gain the 
	// additional layout specified by the resource keyValues.

	// There, we are done, we have created one control from "thin air" (the Label)
	// and only had to specify the menu items of the other control (the ComboBox).
	// All the rest of the layout was done using the EditablePanel's smarts and
	// a resource file.

}

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



Panel* EditablePanel2Demo_Create(Panel *parent)
{
	return new EditablePanel2Demo(parent, "EditablePanel2Demo");
}