summaryrefslogtreecommitdiff
path: root/utils/vgui_panel_zoo/CControlCatalog.cpp
blob: 831ba603dcdb7f8206f7f1219d16270f707d8c34 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//
//=============================================================================//


#include "CControlCatalog.h"
#include "stdio.h"

#include <vgui/ISurface.h>
#include "vgui_controls/Controls.h"
#include "tier1/KeyValues.h"

#include <vgui_controls/Label.h>
#include <vgui_controls/ComboBox.h>

#include "vgui/IVGui.h" // for dprinf statements

#include "filesystem.h"


using namespace vgui;

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
CControlCatalog::CControlCatalog(): Frame(NULL, "PanelZoo")
{
	SetTitle("VGUI SDK Sample Application", true);
	// calculate defaults
	int x, y, wide, tall;
	vgui::surface()->GetScreenSize(wide, tall);
	
	int dwide, dtall;
	dwide = 535;
	dtall = 405;
	x = (int)((wide - dwide) * 0.5);
	y = (int)((tall - dtall) * 0.5);
	SetBounds (x, y, dwide, dtall);

	// Add all demos to the panel list

	// These are SDK control display demos
	m_PanelList.AddToTail(SampleButtons_Create(this));
	m_PanelList.AddToTail(SampleMenus_Create(this));
	m_PanelList.AddToTail(SampleDropDowns_Create(this));
	m_PanelList.AddToTail(SampleListPanelColumns_Create(this));
	m_PanelList.AddToTail(SampleListPanelCats_Create(this));
	m_PanelList.AddToTail(SampleListPanelBoth_Create(this));
	m_PanelList.AddToTail(SampleRadioButtons_Create(this));
	m_PanelList.AddToTail(SampleCheckButtons_Create(this));
	m_PanelList.AddToTail(SampleTabs_Create(this));
	m_PanelList.AddToTail(SampleEditFields_Create(this));
	m_PanelList.AddToTail(SampleSliders_Create(this));
	m_PanelList.AddToTail(DefaultColors_Create(this));

	// These are panel zoo demos
	// These have commented source files with a step by step
	// of how to make and use each control
	// They will have resource file attributes eventually.
	m_PanelList.AddToTail(ImageDemo_Create(this));
	m_PanelList.AddToTail(ImagePanelDemo_Create(this));
	m_PanelList.AddToTail(TextImageDemo_Create(this));
	m_PanelList.AddToTail(LabelDemo_Create(this));
	m_PanelList.AddToTail(Label2Demo_Create(this));
	m_PanelList.AddToTail(TextEntryDemo_Create(this));
	m_PanelList.AddToTail(TextEntryDemo2_Create(this));
	m_PanelList.AddToTail(TextEntryDemo3_Create(this));
	m_PanelList.AddToTail(TextEntryDemo4_Create(this));
	m_PanelList.AddToTail(TextEntryDemo5_Create(this));
	m_PanelList.AddToTail(ButtonDemo_Create(this));
	m_PanelList.AddToTail(ButtonDemo2_Create(this));
	m_PanelList.AddToTail(CheckButtonDemo_Create(this));
	m_PanelList.AddToTail(ToggleButtonDemo_Create(this));
	m_PanelList.AddToTail(RadioButtonDemo_Create(this));
	m_PanelList.AddToTail(MenuDemo_Create(this));
	m_PanelList.AddToTail(MenuDemo2_Create(this));
	m_PanelList.AddToTail(CascadingMenuDemo_Create(this));
	m_PanelList.AddToTail(MessageBoxDemo_Create(this));
	m_PanelList.AddToTail(QueryBoxDemo_Create(this));
	m_PanelList.AddToTail(ComboBoxDemo_Create(this));
	m_PanelList.AddToTail(ComboBox2Demo_Create(this));
	m_PanelList.AddToTail(FrameDemo_Create(this));
	m_PanelList.AddToTail(ProgressBarDemo_Create(this));
	m_PanelList.AddToTail(ScrollBarDemo_Create(this));
	m_PanelList.AddToTail(ScrollBar2Demo_Create(this));
	m_PanelList.AddToTail(EditablePanelDemo_Create(this));
	m_PanelList.AddToTail(EditablePanel2Demo_Create(this));
	m_PanelList.AddToTail(ListPanelDemo_Create(this));
	m_PanelList.AddToTail(TooltipsDemo_Create(this));
	m_PanelList.AddToTail(AnimatingImagePanelDemo_Create(this));
	m_PanelList.AddToTail(WizardPanelDemo_Create(this));
	m_PanelList.AddToTail(FileOpenDemo_Create(this));
	m_PanelList.AddToTail(HTMLDemo_Create(this));
	m_PanelList.AddToTail(HTMLDemo2_Create(this));
	m_PanelList.AddToTail(MenuBarDemo_Create(this));


	m_pSelectControl = new ComboBox(this, "ControlSelect", 10, false);

	// Position the box.
	m_pSelectControl->SetPos(90, 50);

	// Set the width of the Combo box so any element selected will display nicely.
	m_pSelectControl->SetWide(180);

	CUtlRBTree< char const *, int > sorted( 0, 0, CaselessStringLessThan );

	int i;
	for ( i = 0; i < m_PanelList.Size(); i++)
	{
		sorted.Insert( m_PanelList[i]->GetName() );
	}

	// Add text selections to the menu list
	// These are the names of the panels in the panel list
	for ( i = sorted.FirstInorder() ; i != sorted.InvalidIndex(); i = sorted.NextInorder( i ) )
	{
		m_pSelectControl->AddItem( sorted[ i ], NULL);
	}

	m_pSelectControl->ActivateItem(0);
	m_pPrevPanel = m_PanelList[0];

	m_pCategoryLabel = new Label (this, "CategoryLabel", "Category");
	m_pCategoryLabel->GetContentSize(wide, tall);
	m_pCategoryLabel->SetSize(wide + Label::Content/2, tall + Label::Content/2);
	m_pCategoryLabel->SetPos(27, 50);
}


//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
CControlCatalog::~CControlCatalog()
{ 
}
 
//-----------------------------------------------------------------------------
// Purpose: Handles closing of the dialog - shuts down the whole app
//-----------------------------------------------------------------------------
void CControlCatalog::OnClose()
{
	Frame::OnClose();

	// stop vgui running
	vgui::ivgui()->Stop();
}


//-----------------------------------------------------------------------------
// Purpose: Checks to see if any text in the combobox has changed
//-----------------------------------------------------------------------------
void CControlCatalog::OnTextChanged()
{
	char buf[40];
	m_pSelectControl->GetText(buf, sizeof( buf ));

	m_pPrevPanel->SetVisible(false);

	for (int i = 0; i < m_PanelList.Size(); i++)
	{
		if (!strcmp(buf, m_PanelList[i]->GetName()))
		{
			m_PanelList[i]->SetVisible(true);
			m_pPrevPanel = m_PanelList[i];
			break;
		}
	}
}

//-----------------------------------------------------------------------------
// Purpose: Message map
//-----------------------------------------------------------------------------
MessageMapItem_t CControlCatalog::m_MessageMap[] =
{
	MAP_MESSAGE( CControlCatalog, "TextChanged", OnTextChanged ),	// message from the text entry
};

IMPLEMENT_PANELMAP(CControlCatalog, Frame);