Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "DemoPage.h"
  8. #include <VGUI/IVGui.h>
  9. #include <vgui_controls/Controls.h>
  10. #include <Keyvalues.h>
  11. #include <vgui_controls/Button.h>
  12. using namespace vgui;
  13. class ButtonDemo: public DemoPage
  14. {
  15. public:
  16. ButtonDemo(Panel *parent, const char *name);
  17. ~ButtonDemo();
  18. void OnButtonClicked();
  19. private:
  20. Button *m_pButton;
  21. DECLARE_PANELMAP();
  22. };
  23. //-----------------------------------------------------------------------------
  24. // Purpose: Constructor
  25. //-----------------------------------------------------------------------------
  26. ButtonDemo::ButtonDemo(Panel *parent, const char *name) : DemoPage(parent, name)
  27. {
  28. // Create a button.
  29. m_pButton = new Button(this, "AButton", "ClickMe");
  30. // Set its position.
  31. m_pButton->SetPos(100, 100);
  32. // Install a command that will be executed when the button is pressed
  33. // Here we use a KeyValues command, this is mapped using the Message map
  34. // below to a function.
  35. m_pButton->SetCommand(new KeyValues ("ButtonClicked"));
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Purpose: Destructor
  39. //-----------------------------------------------------------------------------
  40. ButtonDemo::~ButtonDemo()
  41. {
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose: Respond to a message based action signal
  45. //-----------------------------------------------------------------------------
  46. void ButtonDemo::OnButtonClicked()
  47. {
  48. ivgui()->DPrintf("Button was clicked.\n");
  49. }
  50. MessageMapItem_t ButtonDemo::m_MessageMap[] =
  51. {
  52. MAP_MESSAGE( ButtonDemo, "ButtonClicked", OnButtonClicked ),
  53. };
  54. IMPLEMENT_PANELMAP(ButtonDemo, DemoPage);
  55. Panel* ButtonDemo_Create(Panel *parent)
  56. {
  57. return new ButtonDemo(parent, "ButtonDemo");
  58. }