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.

189 lines
5.7 KiB

  1. //=========== Copyright Valve Corporation, All rights reserved. ===============//
  2. //
  3. // Purpose:
  4. //=============================================================================//
  5. #ifndef GRID_H
  6. #define GRID_H
  7. #ifdef _WIN32
  8. #pragma once
  9. #endif
  10. #include "panel2d.h"
  11. #include "panorama/controls/label.h"
  12. #include "panorama/controls/mousescroll.h"
  13. namespace panorama
  14. {
  15. DECLARE_PANEL_EVENT0( ReadyPanelForDisplay )
  16. DECLARE_PANEL_EVENT0( PanelDoneWithDisplay )
  17. DECLARE_PANEL_EVENT0( GridMotionTimeout );
  18. DECLARE_PANEL_EVENT0( GridInFastMotion );
  19. DECLARE_PANEL_EVENT0( GridStoppingFastMotion );
  20. DECLARE_PANEL_EVENT0( GridPageLeft );
  21. DECLARE_PANEL_EVENT0( GridPageRight );
  22. DECLARE_PANEL_EVENT0( GridDirectionalMove );
  23. DECLARE_PANEL_EVENT1( ChildIndexSelected, int );
  24. //-----------------------------------------------------------------------------
  25. // Purpose: Button
  26. //-----------------------------------------------------------------------------
  27. class CGrid : public CPanel2D
  28. {
  29. DECLARE_PANEL2D( CGrid, CPanel2D );
  30. public:
  31. CGrid( CPanel2D *parent, const char * pchPanelID );
  32. virtual ~CGrid();
  33. CPanel2D * AccessSelectedPanel() { return m_pFocusedChild.Get(); }
  34. virtual void SetupJavascriptObjectTemplate() OVERRIDE;
  35. // Scroll the grid so the focused panel is in the top left corner
  36. void MoveFocusToTopLeft();
  37. // Scroll the grid all the way to the left regardless of what's
  38. // focused.
  39. void ScrollPanelToLeftEdge();
  40. // Trigger fast motion style temporarily, do this if you are directly setting focus ahead a bunch
  41. void TriggerFastMotion();
  42. void BumpFastMotionTimeout();
  43. void SetHorizontalCount( int nCount ) { SetHorizontalAndVerticalCount( nCount, m_nVerticalCount ); }
  44. void SetVerticalCount( int nCount ) { SetHorizontalAndVerticalCount( m_nHorizontalCount, nCount ); }
  45. int GetHorizontalCount() const { return m_nHorizontalCount; }
  46. int GetVerticalCount() const { return m_nVerticalCount; }
  47. void SetHorizontalFocusLimit( int nCount ) { m_nHorizontalFocusLimit = nCount; InvalidateSizeAndPosition(); }
  48. int GetHorizontalFocusLimit() const { return m_nHorizontalFocusLimit; }
  49. float GetScrollProgress() const { return m_flScrollProgress; }
  50. virtual bool OnMoveUp( int nRepeats );
  51. virtual bool OnMoveDown( int nRepeats );
  52. virtual bool OnMoveRight( int nRepeats );
  53. virtual bool OnMoveLeft( int nRepeats );
  54. virtual bool OnTabForward( int nRepeats );
  55. virtual bool OnTabBackward( int nRepeats );
  56. virtual bool OnMouseWheel( const panorama::MouseData_t &code );
  57. virtual bool OnGamePadDown( const panorama::GamePadData_t &code );
  58. virtual bool OnKeyDown( const KeyData_t &code );
  59. virtual bool BRequiresContentClipLayer() OVERRIDE { return true; }
  60. virtual void Paint();
  61. virtual bool OnSetFocusToNextPanel( int nRepeats, EFocusMoveDirection moveType, bool bAllowWrap, float flTabIndexCurrent, float flXPosCurrent, float flYPosCurrent, float flXStart, float fYStart ) OVERRIDE
  62. {
  63. switch( moveType )
  64. {
  65. case k_ENextInTabOrder:
  66. if ( OnTabForward( nRepeats ) )
  67. return true;
  68. break;
  69. case k_ENextByXPosition:
  70. if ( OnMoveRight( nRepeats ) )
  71. return true;
  72. break;
  73. case k_EPrevInTabOrder:
  74. if ( OnTabBackward( nRepeats ) )
  75. return true;
  76. break;
  77. case k_EPrevByXPosition:
  78. if ( OnMoveLeft( nRepeats ) )
  79. return true;
  80. break;
  81. case k_ENextByYPosition:
  82. if ( OnMoveDown( nRepeats ) )
  83. return true;
  84. break;
  85. case k_EPrevByYPosition:
  86. if ( OnMoveUp( nRepeats ) )
  87. return true;
  88. break;
  89. default:
  90. break;
  91. }
  92. return false;
  93. }
  94. void SetHorizontalAndVerticalCount( int nHorizontalCount, int nVerticalCount );
  95. void SetIgnoreFastMotion( bool bValue ) { m_bIgnoreFastMotion = bValue; }
  96. #ifdef DBGFLAG_VALIDATE
  97. virtual void ValidateClientPanel( CValidator &validator, const tchar *pchName ) OVERRIDE;
  98. #endif
  99. protected:
  100. virtual bool BSetProperty( CPanoramaSymbol symName, const char *pchValue ) OVERRIDE;
  101. virtual void OnLayoutTraverse( float flFinalWidth, float flFinalHeight );
  102. virtual void OnBeforeChildrenChanged() { m_bForceRelayout = true; }
  103. virtual void OnChildStylesChanged() OVERRIDE { m_bVecVisibleDirty = true; }
  104. virtual void OnAfterChildrenChanged() OVERRIDE { m_bVecVisibleDirty = true; }
  105. private:
  106. void UpdateVecVisible();
  107. int GetVisibleChildCount();
  108. CPanel2D *GetVisibleChild( int iVisibleIndex );
  109. // event handlers
  110. bool EventInputFocusSet( const CPanelPtr< IUIPanel > &ptrPanel );
  111. bool EventInputFocusLost( const CPanelPtr< IUIPanel > &ptrPanel );
  112. bool MotionTimeout( const CPanelPtr< IUIPanel > &ptrPanel );
  113. bool OnMouseScroll( const CPanelPtr< IUIPanel > &ptrPanel, int cRepeat );
  114. void LayoutMouseScrollRegions( float flFinalWidth, float flFinalHeight );
  115. bool EventWindowCursorShown( IUIWindow *pWindow );
  116. bool EventWindowCursorHidden( IUIWindow *pWindow );
  117. void RegisterForCursorChanges();
  118. void UnregisterForCursorChanges();
  119. int GetFocusedChildVisibleIndex();
  120. void UpdateChildPositions( bool bForceTopLeft = false );
  121. bool m_bHadFocus;
  122. CPanelPtr< CPanel2D > m_pFocusedChild;
  123. CUtlVector< CPanelPtr<CPanel2D> > m_vecPanelsReadyForDisplay;
  124. int m_nScrollOffset;
  125. float m_flChildWidth;
  126. float m_flChildHeight;
  127. float m_flScaleOffset;
  128. float m_flScrollProgress;
  129. int m_nHorizontalCount;
  130. int m_nVerticalCount;
  131. // Override how far right you can move before all items must shift, should be smaller than m_nHorizontalCount
  132. int m_nHorizontalFocusLimit;
  133. double m_flLastMouseWheel;
  134. bool m_bForceRelayout;
  135. bool m_bIgnoreFastMotion;
  136. double m_flStartedMotion;
  137. double m_flLastMotion;
  138. uint64 m_ulMotionSinceStart;
  139. bool m_bFastMotionStarted;
  140. bool m_bVecVisibleDirty;
  141. CUtlVector< CPanel2D * > m_vecVisibleChildren;
  142. panorama::CMouseScrollRegion *m_pLeftMouseScrollRegion;
  143. panorama::CMouseScrollRegion *m_pRightMouseScrollRegion;
  144. };
  145. } // namespace panorama
  146. #endif // GRID_H