summaryrefslogtreecommitdiff
path: root/utils/vgui_panel_zoo/QueryBoxDemo.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/QueryBoxDemo.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'utils/vgui_panel_zoo/QueryBoxDemo.cpp')
-rw-r--r--utils/vgui_panel_zoo/QueryBoxDemo.cpp147
1 files changed, 147 insertions, 0 deletions
diff --git a/utils/vgui_panel_zoo/QueryBoxDemo.cpp b/utils/vgui_panel_zoo/QueryBoxDemo.cpp
new file mode 100644
index 0000000..612b9a7
--- /dev/null
+++ b/utils/vgui_panel_zoo/QueryBoxDemo.cpp
@@ -0,0 +1,147 @@
+//========= 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/QueryBox.h>
+
+
+using namespace vgui;
+
+// Query boxes are windows that pop up in response to events.
+// They are useful for asking questions (like... "Are you sure you want to do this?").
+// In this example we will trigger the opening of a query box when
+// a button is pressed.
+// Query boxes are Message boxes that have an OK and a Cancel button,
+// each button may be linked to an additional command in order to trigger an
+// appropriate response.
+
+class QueryBoxDemo: public DemoPage
+{
+ public:
+ QueryBoxDemo(Panel *parent, const char *name);
+ ~QueryBoxDemo();
+
+ void OnButtonClicked();
+ void ShowQueryBox();
+ void OnOK();
+ void OnCancel();
+
+ private:
+ Button *m_pButton;
+
+ DECLARE_PANELMAP();
+};
+
+//-----------------------------------------------------------------------------
+// Purpose: Constructor
+//-----------------------------------------------------------------------------
+QueryBoxDemo::QueryBoxDemo(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 Question");
+
+ // Size the button to its text.
+ m_pButton->SizeToContents();
+
+ // 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
+//-----------------------------------------------------------------------------
+QueryBoxDemo::~QueryBoxDemo()
+{
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Respond to a message based action signal
+// Popup the query box.
+//-----------------------------------------------------------------------------
+void QueryBoxDemo::OnButtonClicked()
+{
+ ivgui()->DPrintf("Button was clicked.\n");
+
+ // When the button is clicked we open the message box in response.
+ ShowQueryBox();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Display a query box
+//-----------------------------------------------------------------------------
+void QueryBoxDemo::ShowQueryBox()
+{
+ // 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.
+
+ QueryBox *pQuery = new QueryBox ("Message Window", "Will you pick OK or Cancel?");
+
+ // Make ourselves the target of the button messages
+ pQuery->AddActionSignalTarget(this);
+
+ // Install the message to be sent when the ok button is clicked.
+ pQuery->SetOKCommand(new KeyValues("OKClicked"));
+
+ // Install the message to be sent when the cancel button is clicked.
+ pQuery->SetCancelCommand(new KeyValues("Cancel"));
+
+ // This command will pop up the message box and hold it there until we click
+ // a button. When a button is clicked the query box object is destroyed.
+ pQuery->DoModal();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Respond to a message based action signal
+// Respond to the OK button in the query box.
+//-----------------------------------------------------------------------------
+void QueryBoxDemo::OnOK()
+{
+ ivgui()->DPrintf("Query received the OK.\n");
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Respond to a message based action signal
+// Respond to the Cancel button in the query box
+//-----------------------------------------------------------------------------
+void QueryBoxDemo::OnCancel()
+{
+ ivgui()->DPrintf("Query was canceled.\n");
+}
+
+
+
+MessageMapItem_t QueryBoxDemo::m_MessageMap[] =
+{
+ MAP_MESSAGE( QueryBoxDemo, "ButtonClicked", OnButtonClicked ),
+ MAP_MESSAGE( QueryBoxDemo, "OKClicked", OnOK ),
+ MAP_MESSAGE( QueryBoxDemo, "Cancel", OnCancel ),
+
+};
+
+IMPLEMENT_PANELMAP(QueryBoxDemo, DemoPage);
+
+
+
+Panel* QueryBoxDemo_Create(Panel *parent)
+{
+ return new QueryBoxDemo(parent, "QueryBoxDemo");
+}
+
+