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.

86 lines
2.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef ANCHORMGR_H
  7. #define ANCHORMGR_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier1/utlvector.h"
  12. enum ESimpleAnchor
  13. {
  14. k_eSimpleAnchorAllSides,
  15. k_eSimpleAnchorBottomRight, // The whole control follows the bottom right.
  16. k_eSimpleAnchorStretchRight, // Only grow in width.
  17. k_eSimpleAnchorRightSide,
  18. k_eSimpleAnchorBottomSide
  19. };
  20. enum EAnchorHorz
  21. {
  22. k_eAnchorLeft, // Anchor this side of the control to the left of its parent window.
  23. k_eAnchorRight // Anchor this side of the control to the right of its parent window.
  24. };
  25. enum EAnchorVert
  26. {
  27. k_eAnchorTop, // Anchor this side of the control to the top of its parent window.
  28. k_eAnchorBottom // Anchor this side of the control to the bottom of its parent window.
  29. };
  30. class CAnchorDef
  31. {
  32. public:
  33. friend class CAnchorMgr;
  34. // You can use the first constructor for simple cases.
  35. CAnchorDef() {}
  36. CAnchorDef( int dlgItemID, ESimpleAnchor eSimpleAnchor );
  37. CAnchorDef( HWND hWnd, ESimpleAnchor eSimpleAnchor );
  38. CAnchorDef( int dlgItemID, EAnchorHorz eLeftSide=k_eAnchorLeft, EAnchorVert eTopSide=k_eAnchorTop, EAnchorHorz eRightSide=k_eAnchorRight, EAnchorVert eBottomSide=k_eAnchorBottom );
  39. CAnchorDef( HWND hWnd, EAnchorHorz eLeftSide=k_eAnchorLeft, EAnchorVert eTopSide=k_eAnchorTop, EAnchorHorz eRightSide=k_eAnchorRight, EAnchorVert eBottomSide=k_eAnchorBottom );
  40. // Only one of hWnd or dlgItemID should be set.
  41. void Init( HWND hWnd, int dlgItemID, ESimpleAnchor eSimpleAnchor );
  42. void Init( HWND hWnd, int dlgItemID, EAnchorHorz eLeftSide, EAnchorVert eTopSide, EAnchorHorz eRightSide, EAnchorVert eBottomSide );
  43. public:
  44. int m_DlgItemID;
  45. HWND m_hInputWnd; // Either this or m_DlgItemID is set.
  46. EAnchorHorz m_AnchorLeft, m_AnchorRight;
  47. EAnchorVert m_AnchorTop, m_AnchorBottom;
  48. private:
  49. int m_OriginalPos[4]; // left, top, right, bottom
  50. HWND m_hWnd;
  51. };
  52. //-----------------------------------------------------------------------------
  53. // Purpose: This class helps a resizable window resize and move its controls
  54. // whenever the window is resized. First, you call Init() to tell it how
  55. // you want all the child windows anchored, then just call OnSize() whenever
  56. // the parent window is sized.
  57. //-----------------------------------------------------------------------------
  58. class CAnchorMgr
  59. {
  60. public:
  61. CAnchorMgr();
  62. void Init( HWND hParentWnd, CAnchorMgr::CAnchorDef *pAnchors, int nAnchors );
  63. // Call this when the parent window's size changes and it'll resize all the subcontrols.
  64. void OnSize();
  65. private:
  66. CUtlVector<CAnchorMgr::CAnchorDef> m_Anchors;
  67. HWND m_hParentWnd;
  68. int m_OriginalParentSize[2]; // wide, tall
  69. };
  70. #endif // ANCHORMGR_H