summaryrefslogtreecommitdiff
path: root/utils/vgui_panel_zoo/MessageBoxDemo.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/vgui_panel_zoo/MessageBoxDemo.cpp
downloadarchived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz
archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip
Diffstat (limited to 'utils/vgui_panel_zoo/MessageBoxDemo.cpp')
-rw-r--r--utils/vgui_panel_zoo/MessageBoxDemo.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/utils/vgui_panel_zoo/MessageBoxDemo.cpp b/utils/vgui_panel_zoo/MessageBoxDemo.cpp
new file mode 100644
index 0000000..1b0877b
--- /dev/null
+++ b/utils/vgui_panel_zoo/MessageBoxDemo.cpp
@@ -0,0 +1,118 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+#include "DemoPage.h"
+
+#include <VGUI/IVGui.h>
+#include <vgui_controls/Controls.h>
+
+#include <Keyvalues.h>
+#include <vgui_controls/Button.h>
+#include <vgui_controls/MessageBox.h>
+
+
+using namespace vgui;
+
+// Message boxes are windows that pop up in response to events.
+// They are particularly useful for error messages.
+// In this example we will trigger the opening of a message box when
+// a button is pressed.
+
+class MessageBoxDemo: public DemoPage
+{
+ public:
+ MessageBoxDemo(Panel *parent, const char *name);
+ ~MessageBoxDemo();
+
+ void OnButtonClicked();
+ void ShowMessageBox();
+ private:
+ Button *m_pButton;
+
+ DECLARE_PANELMAP();
+};
+
+//-----------------------------------------------------------------------------
+// Purpose: Constructor
+//-----------------------------------------------------------------------------
+MessageBoxDemo::MessageBoxDemo(Panel *parent, const char *name) : DemoPage(parent, name)
+{
+ // Create a button to trigger the message box.
+ m_pButton = new Button(this, "AButton", "Click Me For A Message");
+
+ // Size the button to its text.
+ int wide, tall;
+ m_pButton->GetContentSize(wide, tall);
+ m_pButton->SetSize(wide + Label::Content, tall + Label::Content);
+
+ // Set its position.
+ m_pButton->SetPos(100, 100);
+
+ // Install a command that will be executed when the button is pressed
+ // Here we use a KeyValues command, this is mapped using the Message map
+ // below to a function.
+ m_pButton->SetCommand(new KeyValues ("ButtonClicked"));
+
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Destructor
+//-----------------------------------------------------------------------------
+MessageBoxDemo::~MessageBoxDemo()
+{
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Respond to a message based action signal
+//
+//-----------------------------------------------------------------------------
+void MessageBoxDemo::OnButtonClicked()
+{
+ ivgui()->DPrintf("Button was clicked.\n");
+
+ // When the button is clicked we open the message box in response.
+ ShowMessageBox();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Display a message box
+//-----------------------------------------------------------------------------
+
+void MessageBoxDemo::ShowMessageBox()
+{
+ // create a new message box.
+ // The first arg is the name of the window and will be across the top.
+ // The second arg is the text that will appear in the message box.
+ // The third arg is if the box starts minimized (yes since we want the button to open it)
+ // The fourth arg is a parent window arg.
+ MessageBox *pMessage = new MessageBox ("Message Window", "Here is some message box text\n You must click OK to continue.", NULL);
+
+
+ // This command will pop up the message box and hold it there until we click
+ // the OK button. When the OK button is clicked the message box object is destroyed.
+ pMessage->DoModal();
+}
+
+
+
+
+
+MessageMapItem_t MessageBoxDemo::m_MessageMap[] =
+{
+ MAP_MESSAGE( MessageBoxDemo, "ButtonClicked", OnButtonClicked ),
+};
+
+IMPLEMENT_PANELMAP(MessageBoxDemo, DemoPage);
+
+
+
+Panel* MessageBoxDemo_Create(Panel *parent)
+{
+ return new MessageBoxDemo(parent, "MessageBoxDemo");
+}
+
+