-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_frame.cpp
More file actions
89 lines (67 loc) · 2.29 KB
/
Copy pathexample_frame.cpp
File metadata and controls
89 lines (67 loc) · 2.29 KB
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
#include "example_frame.h"
#include "convar.h"
#include "tier1/strtools.h"
#include <vgui/ISurface.h>
#include <vgui/IScheme.h>
#include <vgui_controls/Button.h>
#include <vgui_controls/Label.h>
/* Must be last include file in .cpp file */
#include "tier0/memdbgon.h"
CExampleFrame *g_pExampleFrame = NULL;
CExampleFrame::CExampleFrame(vgui::VPANEL parent)
: BaseClass(NULL, "ExampleFrame") {
SetParent(parent);
SetProportional(false);
SetTitle("Example VGUI Plugin", true);
SetSizeable(true);
SetMoveable(true);
SetCloseButtonVisible(true);
SetScheme(vgui::scheme()->LoadSchemeFromFile("resource/SourceScheme.res",
"SourceScheme"));
m_pLabel = new vgui::Label(this, "HelloLabel", "Hello from a client plugin!");
m_pButton = new vgui::Button(this, "PrintButton", "Print to console");
m_pButton->SetCommand("print_hello");
int sw = 0, sh = 0;
vgui::surface()->GetScreenSize(sw, sh);
const int w = 320, h = 140;
SetBounds((sw - w) / 2, (sh - h) / 2, w, h);
SetVisible(false);
InvalidateLayout(true, true);
}
void CExampleFrame::PerformLayout() {
BaseClass::PerformLayout();
int x, y, w, h;
GetClientArea(x, y, w, h);
m_pLabel->SetBounds(x + 12, y + 8, w - 24, 24);
m_pButton->SetBounds(x + 12, y + 40, 160, 24);
}
void CExampleFrame::Install(vgui::VPANEL parent) {
if (g_pExampleFrame)
return;
g_pExampleFrame = new CExampleFrame(parent);
Assert(g_pExampleFrame);
}
void CExampleFrame::OnCommand(const char *command) {
if (command && !V_stricmp(command, "print_hello")) {
Msg("button clicked!\n");
return;
}
BaseClass::OnCommand(command);
}
// ---------------------------------------------------------------------------
// Console command to toggle the window
// ---------------------------------------------------------------------------
static void ToggleExampleFrame() {
if (!g_pExampleFrame)
return;
bool show = !g_pExampleFrame->IsVisible();
g_pExampleFrame->SetVisible(show);
if (show) {
g_pExampleFrame->MoveToFront();
g_pExampleFrame->RequestFocus();
g_pExampleFrame->Activate();
}
}
static ConCommand example_vgui("example_vgui", ToggleExampleFrame,
"Show/hide the example VGUI window.",
FCVAR_DONTRECORD);