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.

80 lines
2.0 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 ButtonDemo2: public DemoPage
  14. {
  15. public:
  16. ButtonDemo2(Panel *parent, const char *name);
  17. ~ButtonDemo2();
  18. void OnCommand(const char *command);
  19. private:
  20. Button *m_pButton;
  21. };
  22. //-----------------------------------------------------------------------------
  23. // Purpose: Constructor
  24. //-----------------------------------------------------------------------------
  25. ButtonDemo2::ButtonDemo2(Panel *parent, const char *name) : DemoPage(parent, name)
  26. {
  27. SetPos(0,80);
  28. int wide, tall;
  29. GetParent()->GetSize(wide, tall);
  30. SetSize (wide, tall - 80);
  31. // Create a button.
  32. m_pButton = new Button(this, "AButton", "ClickMe");
  33. // Set its position.
  34. m_pButton->SetPos(100, 100);
  35. // Install a command that will be executed when the button is pressed
  36. // Here we use a string command. Panels recieve string commands through
  37. // a command message map, already implemented in the Panel class.
  38. // the onCommand function parses the command string
  39. // and takes the appropriate action.
  40. m_pButton->SetCommand("ButtonClicked");
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose: Destructor
  44. //-----------------------------------------------------------------------------
  45. ButtonDemo2::~ButtonDemo2()
  46. {
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Purpose: Respond to a message based action signal
  50. //-----------------------------------------------------------------------------
  51. void ButtonDemo2::OnCommand(const char *command)
  52. {
  53. if (!strcmp(command, "ButtonClicked") )
  54. {
  55. ivgui()->DPrintf("Button was clicked.\n");
  56. }
  57. }
  58. Panel* ButtonDemo2_Create(Panel *parent)
  59. {
  60. return new ButtonDemo2(parent, "ButtonDemo2");
  61. }