Counter Strike : Global Offensive Source Code
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.

133 lines
3.6 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: An arbitrary picker
  4. //
  5. //=============================================================================
  6. #ifndef PICKER_H
  7. #define PICKER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "vgui_controls/EditablePanel.h"
  12. #include "vgui_controls/Frame.h"
  13. #include "tier1/utlstring.h"
  14. //-----------------------------------------------------------------------------
  15. // Forward declarations
  16. //-----------------------------------------------------------------------------
  17. namespace vgui
  18. {
  19. class Panel;
  20. }
  21. //-----------------------------------------------------------------------------
  22. // List of strings to appear in the picker
  23. //-----------------------------------------------------------------------------
  24. enum PickerChoiceType_t
  25. {
  26. PICKER_CHOICE_STRING = 0,
  27. PICKER_CHOICE_PTR,
  28. };
  29. struct PickerInfo_t
  30. {
  31. const char *m_pChoiceString; // This is what displays in the dialog
  32. union
  33. {
  34. const char *m_pChoiceValue;
  35. void *m_pChoiceValuePtr;
  36. };
  37. };
  38. struct PickerList_t
  39. {
  40. PickerList_t() : m_Type( PICKER_CHOICE_STRING ) {}
  41. PickerList_t( int nGrowSize, int nInitSize ) : m_Choices( nGrowSize, nInitSize ), m_Type( PICKER_CHOICE_STRING ) {}
  42. int Count() const { return m_Choices.Count(); }
  43. PickerInfo_t& operator[]( int i ) { return m_Choices[i]; }
  44. const PickerInfo_t& operator[]( int i ) const { return m_Choices[i]; }
  45. int AddToTail() { return m_Choices.AddToTail(); }
  46. void RemoveAll() { return m_Choices.RemoveAll(); }
  47. PickerChoiceType_t m_Type;
  48. CUtlVector< PickerInfo_t > m_Choices;
  49. };
  50. //-----------------------------------------------------------------------------
  51. // Purpose: Base class for choosing raw assets
  52. //-----------------------------------------------------------------------------
  53. class CPicker : public vgui::EditablePanel
  54. {
  55. DECLARE_CLASS_SIMPLE( CPicker, vgui::EditablePanel );
  56. public:
  57. CPicker( vgui::Panel *pParent, const char *pColumnHeader, const char *pTextType );
  58. ~CPicker();
  59. // Sets the list of strings to display
  60. void SetStringList( const PickerList_t &list );
  61. // Purpose:
  62. virtual void OnKeyCodeTyped( vgui::KeyCode code );
  63. // Returns the selected string
  64. PickerChoiceType_t GetSelectionType() const;
  65. const char *GetSelectedString( ) const;
  66. void *GetSelectedPtr( ) const;
  67. // Returns the index of the selected string
  68. int GetSelectedIndex();
  69. private:
  70. void RefreshChoiceList( );
  71. MESSAGE_FUNC( OnTextChanged, "TextChanged" );
  72. vgui::TextEntry *m_pFilterList;
  73. vgui::ListPanel *m_pPickerBrowser;
  74. CUtlString m_Filter;
  75. const char *m_pPickerType;
  76. const char *m_pPickerTextType;
  77. const char *m_pPickerExt;
  78. const char *m_pPickerSubDir;
  79. PickerChoiceType_t m_Type;
  80. friend class CPickerFrame;
  81. };
  82. //-----------------------------------------------------------------------------
  83. // Purpose: Modal dialog for picker
  84. //-----------------------------------------------------------------------------
  85. class CPickerFrame : public vgui::Frame
  86. {
  87. DECLARE_CLASS_SIMPLE( CPickerFrame, vgui::Frame );
  88. public:
  89. CPickerFrame( vgui::Panel *pParent, const char *pTitle, const char *pColumnHeader, const char *pTextType );
  90. ~CPickerFrame();
  91. // Inherited from Frame
  92. virtual void OnCommand( const char *pCommand );
  93. // Purpose: Activate the dialog
  94. // The message "Picked" will be sent if something is picked.
  95. // You can pass in keyvalues to get added to the message also.
  96. void DoModal( const PickerList_t &list, KeyValues *pContextKeyValues = NULL );
  97. private:
  98. void CleanUpMessage();
  99. CPicker *m_pPicker;
  100. vgui::Button *m_pOpenButton;
  101. vgui::Button *m_pCancelButton;
  102. KeyValues *m_pContextKeyValues;
  103. };
  104. #endif // PICKER_H