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.

79 lines
2.0 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/ComboBox.h>
  12. using namespace vgui;
  13. // Combo boxes are boxes that display text and have a menu attached.
  14. // Selecting an item from the menu changes the displayed text in the box.
  15. class ComboBoxDemo: public DemoPage
  16. {
  17. public:
  18. ComboBoxDemo(Panel *parent, const char *name);
  19. ~ComboBoxDemo();
  20. private:
  21. ComboBox *m_pComboBox;
  22. };
  23. //-----------------------------------------------------------------------------
  24. // Purpose: Constructor
  25. //-----------------------------------------------------------------------------
  26. ComboBoxDemo::ComboBoxDemo(Panel *parent, const char *name) : DemoPage(parent, name)
  27. {
  28. // Create a new combo box.
  29. // The first arg is the parent, the second the name
  30. // The third arg is the number of items that will be in the list
  31. // The fourth arg is if the box is editable or not.
  32. m_pComboBox = new ComboBox(this, "Directions", 6, false);
  33. // Position the box.
  34. m_pComboBox->SetPos(100, 100);
  35. // Set the width of the Combo box so any element selected will display nicely.
  36. m_pComboBox->SetWide(80);
  37. // Add text selections to the menu list
  38. m_pComboBox->AddItem("Right", NULL );
  39. m_pComboBox->AddItem("Left", NULL );
  40. m_pComboBox->AddItem("Up", NULL );
  41. m_pComboBox->AddItem("Down", NULL );
  42. m_pComboBox->AddItem("Forward", NULL );
  43. m_pComboBox->AddItem("Backward", NULL );
  44. // Activate the first item in the list, so our box will start out
  45. // with a default selection. ("Right")
  46. m_pComboBox->ActivateItem(0);
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Purpose: Destructor
  50. //-----------------------------------------------------------------------------
  51. ComboBoxDemo::~ComboBoxDemo()
  52. {
  53. }
  54. Panel* ComboBoxDemo_Create(Panel *parent)
  55. {
  56. return new ComboBoxDemo(parent, "ComboBoxDemo");
  57. }