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.

144 lines
3.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=============================================================================
  4. #ifndef DUAL_PANEL_LIST_H
  5. #define DUAL_PANEL_LIST_H
  6. #if defined( _WIN32 )
  7. #pragma once
  8. #endif
  9. #include <utllinkedlist.h>
  10. #include <utlvector.h>
  11. #include <vgui/VGUI.h>
  12. #include <vgui_controls/Panel.h>
  13. class KeyValues;
  14. //-----------------------------------------------------------------------------
  15. // Purpose: A list of variable height child panels
  16. // each list item consists of a label-panel pair. Height of the item is
  17. // determined from the lable.
  18. //-----------------------------------------------------------------------------
  19. class CDualPanelList : public vgui::Panel
  20. {
  21. DECLARE_CLASS_SIMPLE( CDualPanelList, vgui::Panel );
  22. public:
  23. CDualPanelList( vgui::Panel *parent, char const *panelName );
  24. ~CDualPanelList();
  25. // DATA & ROW HANDLING
  26. // The list now owns the panel
  27. virtual int AddItem( vgui::Panel *labelPanel, vgui::Panel *panel );
  28. int GetItemCount() const;
  29. int GetItemIDFromRow( int nRow ) const;
  30. // Iteration. Use these until they return InvalidItemID to iterate all the items.
  31. int FirstItem() const;
  32. int NextItem( int nItemID ) const;
  33. int InvalidItemID() const;
  34. virtual Panel *GetItemLabel( int itemID );
  35. virtual Panel *GetItemPanel( int itemID );
  36. virtual bool IsItemVisible( int nItemID ) const;
  37. virtual void SetItemVisible( int nItemID, bool bVisible );
  38. // vgui::ScrollBar *GetScrollbar() { return m_pScrollBar; }
  39. virtual void RemoveItem( int itemID ); // removes an item from the table (changing the indices of all following items)
  40. virtual void DeleteAllItems(); // clears and deletes all the memory used by the data items
  41. void RemoveAll();
  42. // painting
  43. virtual vgui::Panel *GetCellRenderer( int row );
  44. // layout
  45. void SetFirstColumnWidth( int width );
  46. int GetFirstColumnWidth();
  47. void SetNumColumns( int iNumColumns );
  48. int GetNumColumns( void );
  49. // void MoveScrollBarToTop();
  50. // selection
  51. void SetSelectedPanel( vgui::Panel *panel );
  52. Panel *GetSelectedPanel();
  53. /*
  54. On a panel being selected, a message gets sent to it
  55. "PanelSelected" int "state"
  56. where state is 1 on selection, 0 on deselection
  57. */
  58. void SetVerticalBufferPixels( int buffer );
  59. void ScrollToItem( int itemNumber );
  60. CUtlVector< int > *GetSortedVector( void )
  61. {
  62. return &m_SortedItems;
  63. }
  64. protected:
  65. // overrides
  66. virtual void OnSizeChanged(int wide, int tall);
  67. MESSAGE_FUNC_INT( OnSliderMoved, "ScrollBarSliderMoved", position );
  68. virtual void PerformLayout();
  69. virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
  70. virtual void OnMouseWheeled(int delta);
  71. private:
  72. int ComputeVPixelsNeeded();
  73. enum { DEFAULT_HEIGHT = 24, PANELBUFFER = 5 };
  74. class CDataItem
  75. {
  76. public:
  77. CDataItem()
  78. : m_bVisible( true )
  79. {
  80. }
  81. void SetVisible( int bVisible )
  82. {
  83. m_bVisible = bVisible;
  84. if ( panel )
  85. {
  86. panel->SetVisible( m_bVisible );
  87. }
  88. if ( labelPanel )
  89. {
  90. labelPanel->SetVisible( m_bVisible );
  91. }
  92. }
  93. bool IsVisible() const { return m_bVisible; }
  94. // Always store a panel pointer
  95. vgui::Panel *panel;
  96. vgui::Panel *labelPanel;
  97. bool m_bVisible;
  98. };
  99. // list of the column headers
  100. CUtlLinkedList< CDataItem, int> m_DataItems;
  101. CUtlVector<int> m_SortedItems;
  102. vgui::ScrollBar *m_pScrollBar;
  103. vgui::Panel *m_pPanelEmbedded;
  104. vgui::PHandle m_hSelectedItem;
  105. int m_iFirstColumnWidth;
  106. int m_nNumColumns;
  107. int m_iDefaultHeight;
  108. int m_iPanelBuffer;
  109. // CPanelAnimationVar( bool, m_bAutoHideScrollbar, "autohide_scrollbar", "0" );
  110. };
  111. #endif // DUAL_PANEL_LIST_H