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.

135 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 <Keyvalues.h>
  10. #include <vgui_controls/Controls.h>
  11. #include <vgui_controls/RadioButton.h>
  12. using namespace vgui;
  13. class RadioButtonDemo: public DemoPage
  14. {
  15. public:
  16. RadioButtonDemo(Panel *parent, const char *name);
  17. ~RadioButtonDemo();
  18. void OnRadioButtonHit();
  19. private:
  20. RadioButton *m_pRadioButton1;
  21. RadioButton *m_pRadioButton2;
  22. DECLARE_PANELMAP();
  23. };
  24. //-----------------------------------------------------------------------------
  25. // Purpose: Constructor
  26. //-----------------------------------------------------------------------------
  27. RadioButtonDemo::RadioButtonDemo(Panel *parent, const char *name) : DemoPage(parent, name)
  28. {
  29. // Radio buttons are a little dot circle with a label attached.
  30. // You can have only one radio button selected at a time.
  31. // Other radio buttons will become deselected.
  32. // Create a radio button.
  33. m_pRadioButton1 = new RadioButton(this, "ARadioButton", "ClickMe");
  34. // Set its position.
  35. m_pRadioButton1->SetPos(100, 100);
  36. // A little label for our button
  37. m_pRadioButton1->SetText("Click the radio button!");
  38. // Size the label so the message fits nicely.
  39. m_pRadioButton1->SizeToContents();
  40. // Radio buttons are Buttons, and can send a command when clicked.
  41. // Install a command to be sent when the box is checked or unchecked
  42. m_pRadioButton1->SetCommand(new KeyValues("Radio1"));
  43. // Radio buttons are grouped together by tab position sub tab position
  44. // determines the order to move through the buttons when arrow keys are hit
  45. m_pRadioButton1->SetSubTabPosition(0);
  46. // Create another radio button.
  47. m_pRadioButton2 = new RadioButton(this, "AnotherRadioButton", "ClickMe");
  48. // Set its position.
  49. m_pRadioButton2->SetPos(100, 120);
  50. // A little label for our button
  51. m_pRadioButton2->SetText("Click the other radio button!");
  52. // Size the label so the message fits nicely.
  53. m_pRadioButton2->SizeToContents();
  54. // Start the button off checked. Its unchecked by default.
  55. m_pRadioButton2->SetSelected(true);
  56. m_pRadioButton1->SetSubTabPosition(1);
  57. // Don't install a command to be sent when the box is checked or unchecked,
  58. // Because all buttons respons when a new one is checked (they uncheck themselves if checked)
  59. // In this case when a button is selected a RadioButtonChecked message gets sent
  60. }
  61. //-----------------------------------------------------------------------------
  62. // Purpose: Destructor
  63. //-----------------------------------------------------------------------------
  64. RadioButtonDemo::~RadioButtonDemo()
  65. {
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose: Respond to a message based action signal
  69. //-----------------------------------------------------------------------------
  70. void RadioButtonDemo::OnRadioButtonHit()
  71. {
  72. if (m_pRadioButton1->IsSelected())
  73. {
  74. ivgui()->DPrintf("Radio button one is checked.\n");
  75. }
  76. else
  77. {
  78. ivgui()->DPrintf("Radio button one is unchecked.\n");
  79. }
  80. if (m_pRadioButton2->IsSelected())
  81. {
  82. ivgui()->DPrintf("Radio button two is checked.\n");
  83. }
  84. else
  85. {
  86. ivgui()->DPrintf("Radio button two is unchecked.\n");
  87. }
  88. }
  89. MessageMapItem_t RadioButtonDemo::m_MessageMap[] =
  90. {
  91. MAP_MESSAGE( RadioButtonDemo, "RadioButtonChecked", OnRadioButtonHit ),
  92. };
  93. IMPLEMENT_PANELMAP(RadioButtonDemo, DemoPage);
  94. Panel* RadioButtonDemo_Create(Panel *parent)
  95. {
  96. return new RadioButtonDemo(parent, "RadioButtonDemo");
  97. }