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.

150 lines
4.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "DemoPage.h"
  8. #include "tier1/KeyValues.h"
  9. #include <vgui_controls/ComboBox.h>
  10. using namespace vgui;
  11. class EditablePanel2Demo: public DemoPage
  12. {
  13. public:
  14. EditablePanel2Demo(Panel *parent, const char *name);
  15. ~EditablePanel2Demo();
  16. private:
  17. ComboBox *m_pInternetSpeed;
  18. };
  19. //-----------------------------------------------------------------------------
  20. // Purpose: Constructor
  21. //-----------------------------------------------------------------------------
  22. EditablePanel2Demo::EditablePanel2Demo(Panel *parent, const char *name) : DemoPage(parent, name)
  23. {
  24. // Editable panels are able to have their layout described by external
  25. // resource files. All Frames belong to the Editable Panel class.
  26. // The class EditablePanel2Demo is a PropertyPage class, and PropertyPage
  27. // is an EditablePanel, so we can load in a resource file for this class.
  28. // Load the vgui controls from a resource file.
  29. // The resource file looks like this:
  30. /* EDITABLE PANEL DEMO RESOURCE FILE LAYOUT
  31. "EditablePanelDemo"
  32. {
  33. "SpeedLabel"
  34. {
  35. "ControlName" "Label"
  36. "fieldName" "SpeedLabel"
  37. "xpos" "20"
  38. "ypos" "30"
  39. "wide" "96"
  40. "tall" "20"
  41. "autoResize" "0"
  42. "pinCorner" "0"
  43. "visible" "1"
  44. "enabled" "1"
  45. "tabPosition" "0"
  46. "labelText" "Internet &Speed"
  47. "textAlignment" "east"
  48. "associate" "InternetSpeed"
  49. }
  50. "InternetSpeed"
  51. {
  52. "ControlName" "ComboBox"
  53. "fieldName" "InternetSpeed"
  54. "xpos" "124"
  55. "ypos" "30"
  56. "wide" "200"
  57. "tall" "20"
  58. "autoResize" "0"
  59. "pinCorner" "0"
  60. "visible" "1"
  61. "enabled" "1"
  62. "tabPosition" "0"
  63. "textHidden" "0"
  64. "editable" "0"
  65. "maxchars" "-1"
  66. }
  67. }
  68. */
  69. // VGUI control panel resource values are grouped by a panel name, here
  70. // we have 2 panels, one called "SpeedLabel" and one called
  71. // "Internet Speed".
  72. // Each control has a set of keyValues that describe attributes of
  73. // the panel. SpeedLabel's control name is Label, this is a vgui Label class.
  74. // Its 'xpos' and 'ypos' tell is position in the parent window.
  75. // Its 'wide' and 'tall' tell its size.
  76. // 'AutoResize' is false meaning this panel will not grow or shrink in size
  77. // response to panel resizing.
  78. // More panel attributes follow, until we come to 'labelText'.
  79. // This is the text that will appear in the label. The text is
  80. // "Internet Speed" and the ampersand (&) in front of the 'S' indicates
  81. // that S is a hotkey in the label name.
  82. // 'Associate' associates this label with another vgui control that will
  83. // gain focus when the hotkey is hit. The associated control is called
  84. // "InternetSpeed" and this panel name happens to be the very next panel in the list.
  85. // Its 'ControlName' tells us it is a ComboBox. Hitting the 'S' hotkey will trigger
  86. // the combo box to gain focus. Note that the combo box does not currently
  87. // have any items within it.
  88. // This will be the menu items of our combo box menu.
  89. // List of all the different internet speeds
  90. char *g_Speeds[] =
  91. {
  92. { "Modem - 14.4k"},
  93. { "Modem - 28.8k"},
  94. { "Modem - 33.6k"},
  95. { "Modem - 56k"},
  96. { "ISDN - 112k"},
  97. { "DSL > 256k"},
  98. { "LAN/T1 > 1M"},
  99. };
  100. // Create a combo box with the name "InternetSpeed"
  101. // The parameters of the resource file will be applied to this
  102. // combo box.
  103. m_pInternetSpeed = new ComboBox(this, "InternetSpeed", ARRAYSIZE(g_Speeds), false);
  104. // Add menu items to this combo box.
  105. for (int i = 0; i < ARRAYSIZE(g_Speeds); i++)
  106. {
  107. m_pInternetSpeed->AddItem(g_Speeds[i], NULL );
  108. }
  109. // Load the resource file settings into our panel.
  110. LoadControlSettings("Demo/EditablePanelDemo.res");
  111. // When the settings are applied (in applySettings()) our panels gain the
  112. // additional layout specified by the resource keyValues.
  113. // There, we are done, we have created one control from "thin air" (the Label)
  114. // and only had to specify the menu items of the other control (the ComboBox).
  115. // All the rest of the layout was done using the EditablePanel's smarts and
  116. // a resource file.
  117. }
  118. //-----------------------------------------------------------------------------
  119. // Purpose: Destructor
  120. //-----------------------------------------------------------------------------
  121. EditablePanel2Demo::~EditablePanel2Demo()
  122. {
  123. }
  124. Panel* EditablePanel2Demo_Create(Panel *parent)
  125. {
  126. return new EditablePanel2Demo(parent, "EditablePanel2Demo");
  127. }