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.

187 lines
6.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "CControlCatalog.h"
  9. #include "stdio.h"
  10. #include <vgui/ISurface.h>
  11. #include "vgui_controls/Controls.h"
  12. #include "tier1/KeyValues.h"
  13. #include <vgui_controls/Label.h>
  14. #include <vgui_controls/ComboBox.h>
  15. #include "vgui/IVGui.h" // for dprinf statements
  16. #include "filesystem.h"
  17. using namespace vgui;
  18. //-----------------------------------------------------------------------------
  19. // Purpose:
  20. //-----------------------------------------------------------------------------
  21. CControlCatalog::CControlCatalog(): Frame(NULL, "PanelZoo")
  22. {
  23. SetTitle("VGUI SDK Sample Application", true);
  24. // calculate defaults
  25. int x, y, wide, tall;
  26. vgui::surface()->GetScreenSize(wide, tall);
  27. int dwide, dtall;
  28. dwide = 535;
  29. dtall = 405;
  30. x = (int)((wide - dwide) * 0.5);
  31. y = (int)((tall - dtall) * 0.5);
  32. SetBounds (x, y, dwide, dtall);
  33. // Add all demos to the panel list
  34. // These are SDK control display demos
  35. m_PanelList.AddToTail(SampleButtons_Create(this));
  36. m_PanelList.AddToTail(SampleMenus_Create(this));
  37. m_PanelList.AddToTail(SampleDropDowns_Create(this));
  38. m_PanelList.AddToTail(SampleListPanelColumns_Create(this));
  39. m_PanelList.AddToTail(SampleListPanelCats_Create(this));
  40. m_PanelList.AddToTail(SampleListPanelBoth_Create(this));
  41. m_PanelList.AddToTail(SampleRadioButtons_Create(this));
  42. m_PanelList.AddToTail(SampleCheckButtons_Create(this));
  43. m_PanelList.AddToTail(SampleTabs_Create(this));
  44. m_PanelList.AddToTail(SampleEditFields_Create(this));
  45. m_PanelList.AddToTail(SampleSliders_Create(this));
  46. m_PanelList.AddToTail(DefaultColors_Create(this));
  47. // These are panel zoo demos
  48. // These have commented source files with a step by step
  49. // of how to make and use each control
  50. // They will have resource file attributes eventually.
  51. m_PanelList.AddToTail(ImageDemo_Create(this));
  52. m_PanelList.AddToTail(ImagePanelDemo_Create(this));
  53. m_PanelList.AddToTail(TextImageDemo_Create(this));
  54. m_PanelList.AddToTail(LabelDemo_Create(this));
  55. m_PanelList.AddToTail(Label2Demo_Create(this));
  56. m_PanelList.AddToTail(TextEntryDemo_Create(this));
  57. m_PanelList.AddToTail(TextEntryDemo2_Create(this));
  58. m_PanelList.AddToTail(TextEntryDemo3_Create(this));
  59. m_PanelList.AddToTail(TextEntryDemo4_Create(this));
  60. m_PanelList.AddToTail(TextEntryDemo5_Create(this));
  61. m_PanelList.AddToTail(ButtonDemo_Create(this));
  62. m_PanelList.AddToTail(ButtonDemo2_Create(this));
  63. m_PanelList.AddToTail(CheckButtonDemo_Create(this));
  64. m_PanelList.AddToTail(ToggleButtonDemo_Create(this));
  65. m_PanelList.AddToTail(RadioButtonDemo_Create(this));
  66. m_PanelList.AddToTail(MenuDemo_Create(this));
  67. m_PanelList.AddToTail(MenuDemo2_Create(this));
  68. m_PanelList.AddToTail(CascadingMenuDemo_Create(this));
  69. m_PanelList.AddToTail(MessageBoxDemo_Create(this));
  70. m_PanelList.AddToTail(QueryBoxDemo_Create(this));
  71. m_PanelList.AddToTail(ComboBoxDemo_Create(this));
  72. m_PanelList.AddToTail(ComboBox2Demo_Create(this));
  73. m_PanelList.AddToTail(FrameDemo_Create(this));
  74. m_PanelList.AddToTail(ProgressBarDemo_Create(this));
  75. m_PanelList.AddToTail(ScrollBarDemo_Create(this));
  76. m_PanelList.AddToTail(ScrollBar2Demo_Create(this));
  77. m_PanelList.AddToTail(EditablePanelDemo_Create(this));
  78. m_PanelList.AddToTail(EditablePanel2Demo_Create(this));
  79. m_PanelList.AddToTail(ListPanelDemo_Create(this));
  80. m_PanelList.AddToTail(TooltipsDemo_Create(this));
  81. m_PanelList.AddToTail(AnimatingImagePanelDemo_Create(this));
  82. m_PanelList.AddToTail(WizardPanelDemo_Create(this));
  83. m_PanelList.AddToTail(FileOpenDemo_Create(this));
  84. m_PanelList.AddToTail(HTMLDemo_Create(this));
  85. m_PanelList.AddToTail(HTMLDemo2_Create(this));
  86. m_PanelList.AddToTail(MenuBarDemo_Create(this));
  87. m_pSelectControl = new ComboBox(this, "ControlSelect", 10, false);
  88. // Position the box.
  89. m_pSelectControl->SetPos(90, 50);
  90. // Set the width of the Combo box so any element selected will display nicely.
  91. m_pSelectControl->SetWide(180);
  92. CUtlRBTree< char const *, int > sorted( 0, 0, CaselessStringLessThan );
  93. int i;
  94. for ( i = 0; i < m_PanelList.Size(); i++)
  95. {
  96. sorted.Insert( m_PanelList[i]->GetName() );
  97. }
  98. // Add text selections to the menu list
  99. // These are the names of the panels in the panel list
  100. for ( i = sorted.FirstInorder() ; i != sorted.InvalidIndex(); i = sorted.NextInorder( i ) )
  101. {
  102. m_pSelectControl->AddItem( sorted[ i ], NULL);
  103. }
  104. m_pSelectControl->ActivateItem(0);
  105. m_pPrevPanel = m_PanelList[0];
  106. m_pCategoryLabel = new Label (this, "CategoryLabel", "Category");
  107. m_pCategoryLabel->GetContentSize(wide, tall);
  108. m_pCategoryLabel->SetSize(wide + Label::Content/2, tall + Label::Content/2);
  109. m_pCategoryLabel->SetPos(27, 50);
  110. }
  111. //-----------------------------------------------------------------------------
  112. // Purpose: Destructor
  113. //-----------------------------------------------------------------------------
  114. CControlCatalog::~CControlCatalog()
  115. {
  116. }
  117. //-----------------------------------------------------------------------------
  118. // Purpose: Handles closing of the dialog - shuts down the whole app
  119. //-----------------------------------------------------------------------------
  120. void CControlCatalog::OnClose()
  121. {
  122. Frame::OnClose();
  123. // stop vgui running
  124. vgui::ivgui()->Stop();
  125. }
  126. //-----------------------------------------------------------------------------
  127. // Purpose: Checks to see if any text in the combobox has changed
  128. //-----------------------------------------------------------------------------
  129. void CControlCatalog::OnTextChanged()
  130. {
  131. char buf[40];
  132. m_pSelectControl->GetText(buf, sizeof( buf ));
  133. m_pPrevPanel->SetVisible(false);
  134. for (int i = 0; i < m_PanelList.Size(); i++)
  135. {
  136. if (!strcmp(buf, m_PanelList[i]->GetName()))
  137. {
  138. m_PanelList[i]->SetVisible(true);
  139. m_pPrevPanel = m_PanelList[i];
  140. break;
  141. }
  142. }
  143. }
  144. //-----------------------------------------------------------------------------
  145. // Purpose: Message map
  146. //-----------------------------------------------------------------------------
  147. MessageMapItem_t CControlCatalog::m_MessageMap[] =
  148. {
  149. MAP_MESSAGE( CControlCatalog, "TextChanged", OnTextChanged ), // message from the text entry
  150. };
  151. IMPLEMENT_PANELMAP(CControlCatalog, Frame);