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.

99 lines
2.5 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 <Keyvalues.h>
  10. #include <vgui_controls/Controls.h>
  11. #include <vgui_controls/ToggleButton.h>
  12. using namespace vgui;
  13. // Toggle buttons are a buttons that stay down when you click them.
  14. // Clicking again toggles the button back up.
  15. class ToggleButtonDemo: public DemoPage
  16. {
  17. public:
  18. ToggleButtonDemo(Panel *parent, const char *name);
  19. ~ToggleButtonDemo();
  20. void OnToggleButtonToggled();
  21. private:
  22. ToggleButton *m_pToggleButton;
  23. DECLARE_PANELMAP();
  24. };
  25. //-----------------------------------------------------------------------------
  26. // Purpose: Constructor
  27. //-----------------------------------------------------------------------------
  28. ToggleButtonDemo::ToggleButtonDemo(Panel *parent, const char *name) : DemoPage(parent, name)
  29. {
  30. // Toggle buttons are a buttons that stay down when you click them.
  31. // Create a Toggle button.
  32. m_pToggleButton = new ToggleButton(this, "AToggleButton", "Toggle me!");
  33. // Set its position.
  34. m_pToggleButton->SetPos(100, 100);
  35. // Size the button so the message fits nicely.
  36. int wide, tall;
  37. m_pToggleButton->GetContentSize(wide, tall);
  38. m_pToggleButton->SetSize(wide + Label::Content, tall + Label::Content);
  39. // Toggle buttons are Buttons, and can send a command when clicked.
  40. // Install a command to be sent when the button is toggled.
  41. m_pToggleButton->SetCommand(new KeyValues("Toggle"));
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose: Destructor
  45. //-----------------------------------------------------------------------------
  46. ToggleButtonDemo::~ToggleButtonDemo()
  47. {
  48. }
  49. //-----------------------------------------------------------------------------
  50. // Purpose: Respond to a message based action signal
  51. //-----------------------------------------------------------------------------
  52. void ToggleButtonDemo::OnToggleButtonToggled()
  53. {
  54. if (m_pToggleButton->IsDepressed())
  55. {
  56. ivgui()->DPrintf("Toggle button is down.\n");
  57. }
  58. else
  59. {
  60. ivgui()->DPrintf("Toggle button is up.\n");
  61. }
  62. }
  63. MessageMapItem_t ToggleButtonDemo::m_MessageMap[] =
  64. {
  65. MAP_MESSAGE( ToggleButtonDemo, "Toggle", OnToggleButtonToggled ),
  66. };
  67. IMPLEMENT_PANELMAP(ToggleButtonDemo, DemoPage);
  68. Panel* ToggleButtonDemo_Create(Panel *parent)
  69. {
  70. return new ToggleButtonDemo(parent, "ToggleButtonDemo");
  71. }