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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "DemoPage.h"
#include <VGUI/IVGui.h>
#include <vgui_controls/Controls.h>
#include <vgui_controls/Menu.h>
#include <vgui_controls/MenuItem.h>
#include <vgui_controls/MenuButton.h>
#include <Keyvalues.h>
#include <vgui_controls/Label.h>
using namespace vgui;
class SampleMenus: public DemoPage
{
public:
SampleMenus(Panel *parent, const char *name);
~SampleMenus();
void InitMenus();
void OnCommand( const char *command );
private:
// Menu that opens when button is pressed
Menu *m_pMenu;
Menu *m_pOuterMenu;
Menu *m_pInnerMenu;
Menu *m_pInnerMenu2;
Menu *m_pScrollMenu;
// Button to trigger the menu
MenuButton *m_pMenuButton;
MenuButton *m_pOuterMenuButton;
MenuButton *m_pScrollMenuButton;
// These are the same menus as above with checkable menu items in them
MenuButton *m_pMenuButton2;
MenuButton *m_pOuterMenuButton2;
MenuButton *m_pScrollMenuButton2;
Menu *m_pMenu2;
Menu *m_pOuterMenu2;
Menu *m_pInnerMenu_2;
Menu *m_pInnerMenu22;
Menu *m_pScrollMenu2;
MenuButton *m_pMenuButton3;
Menu *m_pMenu3;
MenuButton *m_pMenuButton4;
Menu *m_pMenu4;
MenuButton *m_pMenuButton5;
Menu *m_pMenu5;
};
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
SampleMenus::SampleMenus(Panel *parent, const char *name) : DemoPage(parent, name)
{
// A fixed width menu
m_pMenuButton = new MenuButton(this, "AMenuButton", "Fixed width");
int wide, tall;
m_pMenuButton->GetContentSize(wide, tall);
m_pMenuButton->SetSize(wide + Label::Content, tall + Label::Content);
// Position the menu button in the window.
m_pMenuButton->SetPos(95, 15);
m_pMenu = new Menu(m_pMenuButton, "AMenu");
m_pMenu->AddMenuItem("Menu Item", "junk", this);
m_pMenu->AddMenuItem("Another Choice", "junk", this);
m_pMenu->AddMenuItem("Menu Item", "junk", this);
m_pMenu->SetVisible(false);
m_pMenuButton->SetMenu(m_pMenu);
m_pMenuButton->GetSize(wide, tall);
m_pMenu->SetFixedWidth(wide);
// Cascading menu
InitMenus();
// Scrolling menu
m_pScrollMenuButton = new MenuButton(this, "AMenuButton", "Scrolling");
m_pScrollMenuButton->GetContentSize(wide, tall);
m_pScrollMenuButton->SetSize(wide + Label::Content, tall + Label::Content);
// Position the menu button in the window.
m_pScrollMenuButton->SetPos(360, 15);
m_pScrollMenu = new Menu(m_pScrollMenuButton, "AScrollingMenu");
m_pScrollMenu->AddMenuItem("Freezes", "junk", this);
m_pScrollMenu->AddMenuItem("Kipup", "junk", this);
m_pScrollMenu->AddMenuItem("Donkey", "junk", this);
m_pScrollMenu->AddMenuItem("Sidewinder", "junk", this);
m_pScrollMenu->AddMenuItem("Handspin", "junk", this);
m_pScrollMenu->AddMenuItem("Coffee Grinder", "junk", this);
m_pScrollMenu->AddMenuItem("Headspin", "junk", this);
m_pScrollMenu->AddMenuItem("The Worm", "junk", this);
m_pScrollMenu->SetNumberOfVisibleItems(5);
m_pScrollMenu->SetVisible(false);
m_pScrollMenuButton->SetMenu(m_pScrollMenu);
// A fixed width menu with checkable menu items and items with names longer than the menu width
m_pMenuButton2 = new MenuButton(this, "AMenuButton", "A Check menu");
m_pMenuButton2->GetContentSize(wide, tall);
m_pMenuButton2->SetSize(wide + Label::Content, tall + Label::Content);
// Position the menu button in the window.
m_pMenuButton2->SetPos(95, 85);
m_pMenu2 = new Menu(m_pMenuButton2, "AMenu");
m_pMenu2->AddCheckableMenuItem("Menu Item Long Long Name", "junk", this );
m_pMenu2->AddCheckableMenuItem("Another Choice", "junk", this );
// last item not checkable for testing
m_pMenu2->AddMenuItem("Menu Item", "junk", this);
m_pMenu2->SetVisible(false);
m_pMenuButton2->SetMenu(m_pMenu2);
m_pMenuButton2->GetSize(wide, tall);
m_pMenu2->SetFixedWidth(wide);
// Cascading menu with checkable menu items and items with names longer than the menu width
InitMenus();
// Scrolling menu with checkable menu items and items with names longer than the menu width
m_pScrollMenuButton2 = new MenuButton(this, "AMenuButton", "Scrolling");
m_pScrollMenuButton2->GetContentSize(wide, tall);
m_pScrollMenuButton2->SetSize(wide + Label::Content, tall + Label::Content);
// Position the menu button in the window.
m_pScrollMenuButton2->SetPos(360, 85);
m_pScrollMenu2 = new Menu(m_pScrollMenuButton2, "AScrollingMenu");
m_pScrollMenu2->AddCheckableMenuItem("Freezes", "junk", this);
m_pScrollMenu2->AddCheckableMenuItem("Kipup", "junk", this);
m_pScrollMenu2->AddCheckableMenuItem("Donkey", "junk", this);
m_pScrollMenu2->AddCheckableMenuItem("Sidewinder", "junk", this);
m_pScrollMenu2->AddCheckableMenuItem("Handspin", "junk", this);
m_pScrollMenu2->AddCheckableMenuItem("Coffee Grinder", "junk", this);
m_pScrollMenu2->AddCheckableMenuItem("Headspin", "junk", this);
// last item not checkable for testing
m_pScrollMenu2->AddMenuItem("The Worm", "junk", this);
m_pScrollMenu2->SetNumberOfVisibleItems(5);
m_pScrollMenu2->SetVisible(false);
m_pScrollMenuButton2->SetMenu(m_pScrollMenu2);
// Lets check off some stuff
m_pMenu2->SetMenuItemChecked( 1, true );
m_pScrollMenu2->SetMenuItemChecked( 0, true );
m_pScrollMenu2->SetMenuItemChecked( 2, true );
m_pScrollMenu2->SetMenuItemChecked( 3, true );
Label *buttonLabel = new Label (this, "buttonLabel", "These are the same menus as above with checkable/elipsis menuitems");
buttonLabel->SetPos(95, 60);
buttonLabel->SizeToContents();
// A button to toggle a check setting in a menu
Button *toggleMenuCheckButton = new Button (this, "Toggle Menu Check", "Toggle Simple Menu Check");
toggleMenuCheckButton->SetCommand("Check");
toggleMenuCheckButton->AddActionSignalTarget(this);
toggleMenuCheckButton->GetContentSize(wide, tall);
toggleMenuCheckButton->SetSize(wide + Label::Content, tall + Label::Content);
toggleMenuCheckButton->SetPos( 95, 220);
// A non fixed width menu with checkable menu items
m_pMenuButton3 = new MenuButton(this, "AMenuButton", "A menu");
m_pMenuButton3->GetContentSize(wide, tall);
m_pMenuButton3->SetSize(wide + Label::Content, tall + Label::Content);
// Position the menu button in the window.
m_pMenuButton3->SetPos(285, 220);
m_pMenu3 = new Menu(m_pMenuButton3, "AMenu");
m_pMenu3->AddCheckableMenuItem("Menu Item", "junk", this);
m_pMenu3->AddCheckableMenuItem("Another Choice", "junk", this);
m_pMenu3->AddCheckableMenuItem("Menu Item", "junk", this);
m_pMenu3->SetVisible(false);
m_pMenuButton3->SetMenu(m_pMenu3);
// A non fixed width menu
m_pMenuButton4 = new MenuButton(this, "AMenuButton", "A menu");
m_pMenuButton4->GetContentSize(wide, tall);
m_pMenuButton4->SetSize(wide + Label::Content, tall + Label::Content);
// Position the menu button in the window.
m_pMenuButton4->SetPos(355, 220);
m_pMenu4 = new Menu(m_pMenuButton4, "AMenu");
m_pMenu4->AddMenuItem("Menu Item", "junk", this);
m_pMenu4->AddMenuItem("Another Choice", "junk", this);
m_pMenu4->AddMenuItem("Menu Item", "junk", this);
m_pMenu4->SetVisible(false);
m_pMenuButton4->SetMenu(m_pMenu4);
// A non fixed width menu with a minimum width
m_pMenuButton5 = new MenuButton(this, "AMenuButton", "A Minimum Width Menu");
m_pMenuButton5->GetContentSize(wide, tall);
m_pMenuButton5->SetSize(wide + Label::Content, tall + Label::Content);
m_pMenuButton5->GetContentSize(wide, tall);
m_pMenuButton5->SetSize(wide + Label::Content, tall + Label::Content);
// Position the menu button in the window.
m_pMenuButton5->SetPos(355, 270);
m_pMenu5 = new Menu(m_pMenuButton5, "AMenu");
m_pMenu5->AddMenuItem("Menu Item", "junk", this);
m_pMenu5->AddMenuItem("Another Choice", "junk", this);
m_pMenu5->AddMenuItem("Menu Item", "junk", this);
m_pMenu5->SetVisible(false);
m_pMenuButton5->GetSize(wide, tall);
m_pMenu5->SetMinimumWidth(wide);
m_pMenuButton5->SetMenu(m_pMenu5);
}
//-----------------------------------------------------------------------------
// Purpose: Create cascading menus.
// We will create a Menu with 2 Menus inside it, and yet another Menu inside one of those!
//-----------------------------------------------------------------------------
void SampleMenus::InitMenus()
{
// A drop down menu button for the top most menu
m_pOuterMenuButton = new MenuButton(this, "OuterMenu", "Cascading");
// Size the Button so we can read its label.
int wide, tall;
m_pOuterMenuButton->GetContentSize(wide, tall);
m_pOuterMenuButton->SetSize(wide + Label::Content, tall + Label::Content);
// Create the Menu to go with it.
m_pOuterMenu = new Menu(m_pOuterMenuButton, "OuterMenu");
// Add the menu items to this menu
m_pOuterMenu->SetVisible(false);
m_pOuterMenu->SetNumberOfVisibleItems(5);
// Attach this menu to the menu button
m_pOuterMenuButton->SetMenu(m_pOuterMenu);
// Position the menu button on screen.
m_pOuterMenuButton->SetPos(220, 15);
// Create cascading menu #1
m_pInnerMenu = new Menu(m_pOuterMenu, "InnerMenu");
// Add menu items to this menu.
m_pInnerMenu->AddMenuItem("Marcia", "junk", this);
m_pInnerMenu->AddMenuItem("Greg", "junk", this);
m_pInnerMenu->AddMenuItem("Peter", "junk", this);
m_pInnerMenu->SetVisible(false);
// Now add the cascading menu to the top menu as a menu item!
m_pOuterMenu->AddCascadingMenuItem("Cascades", this, m_pInnerMenu);
// Create cascading menu #2
m_pInnerMenu2 = new Menu(m_pOuterMenu, "InnerMenu2");
m_pInnerMenu2->AddMenuItem("One Fish", "junk", this);
m_pInnerMenu2->AddMenuItem("Two Fish", "junk", this);
m_pInnerMenu2->AddMenuItem("Red Fish", "junk", this);
m_pInnerMenu2->AddMenuItem("Blue Fish", "junk", this);
m_pInnerMenu2->SetVisible(false);
// Add this cascading menu to the top menu as a manu item.
m_pOuterMenu->AddCascadingMenuItem("Cascading Choice", this, m_pInnerMenu2);
// Make one of the items in the menu disabled.
m_pOuterMenu->AddMenuItem("Normal Menuitem", "junk", this);
m_pOuterMenu->AddMenuItem("Disabled Menuitem", "Disabled", this);
Panel *menuItem = m_pOuterMenu->FindChildByName("Disabled Menuitem");
assert(menuItem);
menuItem->SetEnabled(false);
m_pOuterMenu->AddMenuItem("Normal Menuitem", "junk", this);
// A drop down menu button for the top most menu
m_pOuterMenuButton2 = new MenuButton(this, "OuterMenu", "Cascading");
// Size the Button so we can read its label.
m_pOuterMenuButton2->GetContentSize(wide, tall);
m_pOuterMenuButton2->SetSize(wide + Label::Content, tall + Label::Content);
// Create the Menu to go with it.
m_pOuterMenu2 = new Menu(m_pOuterMenuButton2, "OuterMenu");
// Add the menu items to this menu
m_pOuterMenu2->SetVisible(false);
m_pOuterMenu2->SetNumberOfVisibleItems(7);
// Attach this menu to the menu button
m_pOuterMenuButton2->SetMenu(m_pOuterMenu2);
// Position the menu button on screen.
m_pOuterMenuButton2->SetPos(220, 85);
// Create cascading menu #1
m_pInnerMenu_2 = new Menu(m_pOuterMenu2, "InnerMenu");
// Add menu items to this menu.
m_pInnerMenu_2->AddCheckableMenuItem("Marcia", "junk", this);
m_pInnerMenu_2->AddCheckableMenuItem("Greg", "junk", this);
m_pInnerMenu_2->AddMenuItem("Peter", "junk", this);
m_pInnerMenu_2->SetVisible(false);
// Now add the cascading menu to the top menu as a menu item!
m_pOuterMenu2->AddCascadingMenuItem("Cascades", this, m_pInnerMenu_2);
// Create cascading menu #2
m_pInnerMenu22 = new Menu(m_pOuterMenu2, "InnerMenu2");
m_pInnerMenu22->AddCheckableMenuItem("One Fish", "junk", this);
m_pInnerMenu22->AddCheckableMenuItem("Two Fish", "junk", this);
m_pInnerMenu22->AddCheckableMenuItem("Red Fish", "junk", this);
m_pInnerMenu22->AddCheckableMenuItem("Blue Fish", "junk", this);
m_pInnerMenu22->SetVisible(false);
// Add this cascading menu to the top menu as a manu item.
m_pOuterMenu2->AddCascadingMenuItem("Cascading Choice", this, m_pInnerMenu22);
// Make one of the items in the menu disabled.
m_pOuterMenu2->AddMenuItem("Normal Menuitem", "junk", this);
// checkable so we can see what disabled checkable items look like
m_pOuterMenu2->AddCheckableMenuItem("Disabled Menuitem", "Disabled", this);
menuItem = m_pOuterMenu2->FindChildByName("Disabled Menuitem");
assert(menuItem);
menuItem->SetEnabled(false);
m_pOuterMenu2->AddMenuItem("Normal Menuitem", "junk", this);
m_pOuterMenu2->AddCheckableMenuItem("Normal Checkable", "junk", this);
// Lets check off some stuff for starters
m_pOuterMenu2->SetMenuItemChecked( 3, true );
m_pOuterMenu2->SetMenuItemChecked( 5, true );
//m_pInnerMenu_2->SetMenuItemChecked( 0, true );
m_pInnerMenu22->SetMenuItemChecked( 0, true );
m_pInnerMenu22->SetMenuItemChecked( 1, true );
m_pInnerMenu22->SetMenuItemChecked( 2, true );
// another way of checking a menu item
m_pInnerMenu22->GetMenuItem(3)->SetChecked( true );
}
void SampleMenus::OnCommand( const char *command )
{
// Hitting the button will toggle the checking and unchecking
// of the first item of menu3
if (!stricmp(command, "Check"))
{
if (!m_pMenu3->GetMenuItem(0)->IsChecked())
// check the first menu item in the first menu
m_pMenu3->SetMenuItemChecked( 0, true );
else
// another way of setting the checked state.
m_pMenu3->GetMenuItem(0)->SetChecked(false);
}
Panel::OnCommand(command);
}
//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
SampleMenus::~SampleMenus()
{
}
Panel* SampleMenus_Create(Panel *parent)
{
return new SampleMenus(parent, "Menus");
}
|