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.

141 lines
3.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/CheckButton.h>
  12. using namespace vgui;
  13. class CheckButtonDemo: public DemoPage
  14. {
  15. public:
  16. CheckButtonDemo(Panel *parent, const char *name);
  17. ~CheckButtonDemo();
  18. void OnCheckButton1Checked();
  19. void OnCheckButton2Checked();
  20. private:
  21. CheckButton *m_pCheckButton1;
  22. CheckButton *m_pCheckButton2;
  23. DECLARE_PANELMAP();
  24. };
  25. //-----------------------------------------------------------------------------
  26. // Purpose: Constructor
  27. //-----------------------------------------------------------------------------
  28. CheckButtonDemo::CheckButtonDemo(Panel *parent, const char *name) : DemoPage(parent, name)
  29. {
  30. SetBorder(NULL);
  31. // Check buttons are a little checkable box with a label attached.
  32. // You can have as many check buttons checked at one time as you want.
  33. // Create a check button.
  34. m_pCheckButton1 = new CheckButton(this, "ACheckButton", "ClickMe");
  35. // Set its position.
  36. m_pCheckButton1->SetPos(100, 100);
  37. // A little label for our button
  38. m_pCheckButton1->SetText("Click the check button!");
  39. // Size the label so the message fits nicely.
  40. m_pCheckButton1->SizeToContents();
  41. // Start the button off checked. Its unchecked by default.
  42. m_pCheckButton1->SetSelected(true);
  43. // Check buttons are Buttons, and can send a command when clicked.
  44. // Install a command to be sent when the box is checked or unchecked
  45. m_pCheckButton1->SetCommand(new KeyValues("Check1"));
  46. // Create another check button.
  47. m_pCheckButton2 = new CheckButton(this, "AnotherCheckButton", "ClickMe");
  48. // Set its position.
  49. m_pCheckButton2->SetPos(100, 120);
  50. // A little label for our button
  51. m_pCheckButton2->SetText("Click the other check button!");
  52. // Size the label so the message fits nicely.
  53. m_pCheckButton2->SizeToContents();
  54. // Install a command to be sent when the box is checked or unchecked
  55. m_pCheckButton2->SetCommand(new KeyValues("Check2"));
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose: Destructor
  59. //-----------------------------------------------------------------------------
  60. CheckButtonDemo::~CheckButtonDemo()
  61. {
  62. }
  63. //-----------------------------------------------------------------------------
  64. // Purpose: Respond to a message based action signal
  65. //-----------------------------------------------------------------------------
  66. void CheckButtonDemo::OnCheckButton1Checked()
  67. {
  68. if (m_pCheckButton1->IsSelected())
  69. {
  70. ivgui()->DPrintf("Check box one is checked.\n");
  71. }
  72. else
  73. {
  74. ivgui()->DPrintf("Check box one is unchecked.\n");
  75. }
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose: Respond to a message based action signal
  79. //-----------------------------------------------------------------------------
  80. void CheckButtonDemo::OnCheckButton2Checked()
  81. {
  82. if (m_pCheckButton2->IsSelected())
  83. {
  84. ivgui()->DPrintf("Check box two is checked.\n");
  85. }
  86. else
  87. {
  88. ivgui()->DPrintf("Check box two is unchecked.\n");
  89. }
  90. }
  91. MessageMapItem_t CheckButtonDemo::m_MessageMap[] =
  92. {
  93. MAP_MESSAGE( CheckButtonDemo, "Check1", OnCheckButton1Checked ),
  94. MAP_MESSAGE( CheckButtonDemo, "Check2", OnCheckButton2Checked ),
  95. };
  96. IMPLEMENT_PANELMAP(CheckButtonDemo, DemoPage);
  97. Panel* CheckButtonDemo_Create(Panel *parent)
  98. {
  99. return new CheckButtonDemo(parent, "CheckButtonDemo");
  100. }