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.

145 lines
4.4 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 "tier1/KeyValues.h"
  11. #include <vgui_controls/EditablePanel.h>
  12. #include <vgui_controls/Label.h>
  13. #include <vgui_controls/ComboBox.h>
  14. using namespace vgui;
  15. // EditablePanels are panels that can create certain vgui controls
  16. // by using the function createControlByName()
  17. class EditablePanelDemo: public DemoPage
  18. {
  19. public:
  20. EditablePanelDemo(Panel *parent, const char *name);
  21. ~EditablePanelDemo();
  22. private:
  23. EditablePanel *m_pEditablePanel;
  24. Label *m_pSpeedLabel;
  25. ComboBox *m_pInternetSpeed;
  26. };
  27. //-----------------------------------------------------------------------------
  28. // Purpose: Constructor
  29. //-----------------------------------------------------------------------------
  30. EditablePanelDemo::EditablePanelDemo(Panel *parent, const char *name) : DemoPage(parent, name)
  31. {
  32. // Create an EditablePanel.
  33. m_pEditablePanel = new EditablePanel(this, "AnEditablePanel");
  34. // Set its position and size
  35. m_pEditablePanel->SetSize(400, 200);
  36. m_pEditablePanel->SetPos(0, 0);
  37. // Add a child Label panel to the EditablePanel
  38. m_pSpeedLabel = (Label *)(m_pEditablePanel->CreateControlByName("Label"));
  39. // Set its parent to our editable panel.
  40. m_pSpeedLabel->SetParent(m_pEditablePanel);
  41. // Set its Position
  42. m_pSpeedLabel->SetPos(20, 30);
  43. // Set its size
  44. m_pSpeedLabel->SetSize(96,20);
  45. // Set it not to resize with the window.
  46. m_pSpeedLabel->SetAutoResize(PIN_TOPLEFT, AUTORESIZE_NO, 0, 0, 0, 0 );
  47. // Set it visible
  48. m_pSpeedLabel->SetVisible(true);
  49. // Set it enabled
  50. m_pSpeedLabel->SetEnabled(true);
  51. // Set its tab position
  52. m_pSpeedLabel->SetTabPosition(0);
  53. // Set the text in the label
  54. m_pSpeedLabel->SetText("Internet &Speed");
  55. // Set its text alignment
  56. m_pSpeedLabel->SetContentAlignment(Label::a_east);
  57. // Add another child panel to the EditablePanel, this time a ComboBox.
  58. // This will be the menu items of our combo box menu.
  59. // List of all the different internet speeds
  60. char *g_Speeds[] =
  61. {
  62. { "Modem - 14.4k"},
  63. { "Modem - 28.8k"},
  64. { "Modem - 33.6k"},
  65. { "Modem - 56k"},
  66. { "ISDN - 112k"},
  67. { "DSL > 256k"},
  68. { "LAN/T1 > 1M"},
  69. };
  70. // Create the combo box using the create function
  71. m_pInternetSpeed = (ComboBox *)(m_pEditablePanel->CreateControlByName("ComboBox"));
  72. // Set its parent to our editable panel.
  73. m_pInternetSpeed->SetParent(m_pEditablePanel);
  74. // Set its position next to the label.
  75. m_pInternetSpeed->SetPos(124, 30);
  76. // Set its size
  77. m_pInternetSpeed->SetSize(200, 20);
  78. // Set it not to resize with the window.
  79. m_pInternetSpeed->SetAutoResize(PIN_TOPLEFT, AUTORESIZE_NO, 0, 0, 0, 0 );
  80. // Set it visible
  81. m_pInternetSpeed->SetVisible(true);
  82. // Set it enabled
  83. m_pInternetSpeed->SetEnabled(true);
  84. // Set its tab position
  85. m_pInternetSpeed->SetTabPosition(0);
  86. // Set its text hidden attribute
  87. m_pInternetSpeed->SetTextHidden(false);
  88. // Set it not editable
  89. m_pInternetSpeed->SetEditable(false);
  90. // Set its maxchars to -1 since it is not editable
  91. //m_pInternetSpeed->SetMaximumCharCount(-1);
  92. // Set the number of items in the combo box menu
  93. m_pInternetSpeed->SetNumberOfEditLines(ARRAYSIZE(g_Speeds));
  94. // Set the drop down arrow button visible
  95. m_pInternetSpeed->SetDropdownButtonVisible(true);
  96. // Add menu items to this combo box.
  97. for (int i = 0; i < ARRAYSIZE(g_Speeds); i++)
  98. {
  99. m_pInternetSpeed->AddItem(g_Speeds[i], NULL );
  100. }
  101. // Associate our label with our combo box
  102. m_pSpeedLabel->SetAssociatedControl(m_pInternetSpeed);
  103. // Now you're saying... why bother using an EditablePanel class for this?
  104. // I could have just created a panel and just created each child panel on my own
  105. // using code like this: memberLabel = new Label(NULL, NULL, "Label");
  106. // I could have even saved many lines of code by choosing nice constructor args.
  107. // Well the real power of editable panels lies in the use of Resource Files
  108. // as seen in the next example.
  109. }
  110. //-----------------------------------------------------------------------------
  111. // Purpose: Destructor
  112. //-----------------------------------------------------------------------------
  113. EditablePanelDemo::~EditablePanelDemo()
  114. {
  115. }
  116. Panel* EditablePanelDemo_Create(Panel *parent)
  117. {
  118. return new EditablePanelDemo(parent, "EditablePanelDemo");
  119. }