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.

133 lines
3.6 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. #include <vgui_controls/MenuButton.h>
  13. using namespace vgui;
  14. class SampleButtons: public DemoPage
  15. {
  16. public:
  17. SampleButtons(Panel *parent, const char *name);
  18. ~SampleButtons();
  19. void onButtonClicked();
  20. private:
  21. Button *m_pEnabledButton;
  22. Button *m_pDepressedButton;
  23. Button *m_pDefaultButton;
  24. Button *m_pDisabledButton;
  25. Button *m_pDisActiveButton;
  26. Button *m_pMoreInfoButton;
  27. Button *m_pExpandButton;
  28. MenuButton *m_pMenuButton;
  29. DECLARE_PANELMAP();
  30. };
  31. //-----------------------------------------------------------------------------
  32. // Purpose: Constructor
  33. //-----------------------------------------------------------------------------
  34. SampleButtons::SampleButtons(Panel *parent, const char *name) : DemoPage(parent, name)
  35. {
  36. // Create a button.
  37. m_pEnabledButton = new Button(this, "EnabledButton", "Enabled");
  38. // Set its position.
  39. m_pEnabledButton->SetPos(90, 15);
  40. // Set its size
  41. m_pEnabledButton->SetSize(90, 25);
  42. // Install a command that will be executed when the button is pressed
  43. // Here we use a KeyValues command, this is mapped using the Message map
  44. // below to a function.
  45. m_pEnabledButton->SetCommand(new KeyValues ("ButtonClicked"));
  46. m_pEnabledButton->SetEnabled(true);
  47. m_pDepressedButton = new Button(this, "ActiveButton", "Active");
  48. m_pDepressedButton->SetPos(192, 15);
  49. m_pDepressedButton->SetSize(90, 25);
  50. // Set it pressed down
  51. m_pDepressedButton->ForceDepressed(true);
  52. m_pDefaultButton = new Button(this, "DefaultButton", "Default");
  53. // Set this button to be the default
  54. m_pDefaultButton->SetAsDefaultButton(true);
  55. m_pDefaultButton->SetPos(292, 15);
  56. m_pDefaultButton->SetSize(90, 25);
  57. m_pDisabledButton = new Button(this, "DisabledButton", "Disabled");
  58. m_pDisabledButton->SetPos(90, 55);
  59. m_pDisabledButton->SetSize(90, 25);
  60. // Set it disabled
  61. m_pDisabledButton->SetEnabled(false);
  62. m_pDisActiveButton = new Button(this, "DisActiveButton", "Active");
  63. m_pDisActiveButton->SetPos(192, 55);
  64. m_pDisActiveButton->SetSize(90, 25);
  65. // Set it pressed down
  66. m_pDisActiveButton->ForceDepressed(true);
  67. // Set it disabled
  68. m_pDisActiveButton->SetEnabled(false);
  69. m_pMoreInfoButton = new Button(this, "MoreInfoButton", "More info required...");
  70. m_pMoreInfoButton->SetPos(90, 105);
  71. m_pMoreInfoButton->SetSize(160, 25);
  72. m_pExpandButton = new Button(this, "ExpandButton", "Expand this window >>");
  73. m_pExpandButton->SetPos(90, 155);
  74. m_pExpandButton->SetSize(160, 25);
  75. m_pMenuButton = new MenuButton(this, "MenuButton", "Open a menu");
  76. m_pMenuButton->SetPos(90, 205);
  77. m_pMenuButton->SetSize(125, 25);
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Purpose: Destructor
  81. //-----------------------------------------------------------------------------
  82. SampleButtons::~SampleButtons()
  83. {
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Purpose: Respond to a message based action signal
  87. //-----------------------------------------------------------------------------
  88. void SampleButtons::onButtonClicked()
  89. {
  90. ivgui()->DPrintf("Button was clicked.\n");
  91. }
  92. MessageMapItem_t SampleButtons::m_MessageMap[] =
  93. {
  94. MAP_MESSAGE( SampleButtons, "ButtonClicked", onButtonClicked ),
  95. };
  96. IMPLEMENT_PANELMAP(SampleButtons, DemoPage);
  97. Panel* SampleButtons_Create(Panel *parent)
  98. {
  99. return new SampleButtons(parent, "Buttons");
  100. }