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.

218 lines
6.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef MAPVIEW2DBASE_H
  8. #define MAPVIEW2DBASE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "Axes2.h"
  13. #include "MapView.h"
  14. #include "MapClass.h" // For CMapObjectList
  15. #include "utlvector.h"
  16. #include "VGuiWnd.h"
  17. #include "color.h"
  18. class CTitleWnd;
  19. class CMapDoc;
  20. class Tool3D;
  21. class CMapView2DBase : public CView, public CMapView, public Axes2, public CVGuiWnd
  22. {
  23. // Operations
  24. public:
  25. LRESULT WindowProc( UINT message, WPARAM wParam, LPARAM lParam );
  26. void SetViewOrigin( float flHorz, float flVert, bool bRelative = false );
  27. void SetZoom(float flNewZoom);
  28. float GetZoom( void );
  29. void CenterView(Vector *pt3 = NULL);
  30. void UpdateClientView();
  31. void ToolScrollToPoint(const Vector2D &ptClient);
  32. void UpdateStatusBar();
  33. int ObjectsAt( const Vector2D &vPoint, HitInfo_t *pObjects, int nMaxObjects, unsigned int nFlags = 0 );
  34. int ObjectsAt( CMapWorld *pWorld, const Vector2D &vPoint, HitInfo_t *pObjects, int nMaxObjects, unsigned int nFlags = 0 );
  35. void GetCenterPoint(Vector& pt);
  36. void OnContextMenu(UINT nFlags, const Vector2D &vPoint);
  37. void EnsureVisible(Vector &vecPos, float flMargin);
  38. void UpdateTitleWindowPos();
  39. virtual void Render() {}
  40. void ZoomIn(BOOL bAllViews = FALSE);
  41. void ZoomOut(BOOL bAllViews = FALSE);
  42. //
  43. // Coordinate transformation functions.
  44. //
  45. void ProcessInput() {}
  46. void RenderView();
  47. void ActivateView(bool bActivate);
  48. void UpdateView(int nFlags);
  49. CView *GetViewWnd() { return (CView*)this; }
  50. CMapDoc *GetMapDoc() { return (CMapDoc*)m_pDocument; }
  51. void WorldToClient(Vector2D &vecClient, const Vector &vecWorld);
  52. void ClientToWorld(Vector &vecWorld, const Vector2D &ptClient);
  53. void BuildRay( const Vector2D &ptClient, Vector& vStart, Vector& vEnd );
  54. void GetBestTransformPlane( Vector &horzAxis, Vector &vertAxis, Vector &thirdAxis);
  55. const Vector &GetViewAxis();
  56. bool IsInClientView( const Vector &vecMin, const Vector &vecMax );
  57. bool IsInClientView( const Vector2D &vecMin, const Vector2D &vecMax );
  58. bool CheckDistance(const Vector2D &vecCheck, const Vector2D &vecRef, int nDist);
  59. bool IsBoxFullyVisible(const Vector &vecMins, const Vector &vecMaxs);
  60. bool CanBoxFitInView(const Vector &minsWorld, const Vector &maxsWorld);
  61. bool PointInClientRect( const Vector2D &point );
  62. bool HitTest( const Vector2D &vPoint, const Vector& mins, const Vector& maxs );
  63. // Implementation
  64. protected:
  65. CMapView2DBase(); // protected constructor used by dynamic creation
  66. virtual ~CMapView2DBase();
  67. DECLARE_DYNCREATE(CMapView2DBase)
  68. // Derived classes must implement these
  69. virtual bool IsLogical() { return false; }
  70. virtual void OnRenderListDirty() {}
  71. // Overrides
  72. // ClassWizard generated virtual function overrides
  73. //{{AFX_VIRTUAL(CMapView2DBase)
  74. protected:
  75. virtual void OnInitialUpdate(); // first time after construct
  76. virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  77. virtual BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint point);
  78. virtual void OnDraw(CDC *) {};
  79. //}}AFX_VIRTUAL
  80. #ifdef _DEBUG
  81. virtual void AssertValid() const;
  82. virtual void Dump(CDumpContext& dc) const;
  83. #endif
  84. void DrawGridLogical( CRender2D *pRender );
  85. void DrawGrid( CRender2D *pRender, int xAxis, int yAxis, float depth, bool bNoSmallGrid = false );
  86. CRender2D *GetRender();
  87. CTitleWnd *GetTitleWnd();
  88. bool HasTitleWnd() const;
  89. // Create a title window.
  90. void CreateTitleWindow(void);
  91. protected:
  92. // timer IDs:
  93. enum
  94. {
  95. TIMER_SCROLLVIEW = 1,
  96. };
  97. void DrawPointFile( CRender2D *pRender );
  98. bool HighlightGridLine( CRender2D *pRender, int nGridLine );
  99. POINT m_ptLDownClient; // client pos at which lbutton was pressed, for dragging the view
  100. // TODO zoom & forward are all camera properties, remove here
  101. CRender2D *m_pRender; // Performs the 3D rendering in our window.
  102. float m_flMinZoom; // Minimum legal zoom factor (should be sufficient to display entire map in the view)
  103. // these vars are used often, so keep values. they just mirror Camera values
  104. Vector m_vViewOrigin;
  105. float m_fZoom; // zoom factor (* map units)
  106. float m_fClientWidthHalf;
  107. float m_fClientHeightHalf;
  108. Vector m_vViewAxis; // view axis, normal
  109. Vector m_ViewMin; // client view in world coordinates, same as 3D view frustum
  110. Vector m_ViewMax;
  111. int m_ClientWidth;
  112. int m_ClientHeight;
  113. int m_xScroll, m_yScroll; // amount to scroll on timer
  114. bool m_bToolShown; // is tool currently visible?
  115. CTitleWnd *m_pwndTitle; // title window
  116. Color m_clrGrid; // standard grid color
  117. Color m_clrGrid1024; // 1024 unit line color
  118. Color m_clrGridCustom; // custom unit color
  119. Color m_clrGridDot; // grid dot color
  120. Color m_clrAxis; // grid axis color
  121. //
  122. // Color scheme functions.
  123. //
  124. void AdjustColorIntensity(Color &color, int nIntensity);
  125. void SetColorMode(bool bBlackOnWhite);
  126. // mouse drag (space + leftbutton):
  127. bool m_bMouseDrag; // status indicator
  128. // Generated message map functions
  129. //{{AFX_MSG(CMapView2DBase)
  130. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  131. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  132. afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
  133. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  134. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  135. afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  136. afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  137. afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
  138. afx_msg void OnTimer(UINT nIDEvent);
  139. afx_msg void OnSize(UINT nType, int cx, int cy);
  140. afx_msg void OnEditProperties();
  141. afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
  142. afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  143. afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
  144. afx_msg void OnUpdateEditFunction(CCmdUI *pCmdUI);
  145. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  146. //}}AFX_MSG
  147. DECLARE_MESSAGE_MAP()
  148. };
  149. //-----------------------------------------------------------------------------
  150. // Inline methods
  151. //-----------------------------------------------------------------------------
  152. inline bool CMapView2DBase::PointInClientRect( const Vector2D &point )
  153. {
  154. return ( point.x >= 0 && point.y >= 0 && point.x < m_ClientWidth && point.y < m_ClientHeight );
  155. }
  156. inline float CMapView2DBase::GetZoom()
  157. {
  158. return m_fZoom;
  159. }
  160. inline CRender2D *CMapView2DBase::GetRender()
  161. {
  162. return m_pRender;
  163. }
  164. inline CTitleWnd* CMapView2DBase::GetTitleWnd()
  165. {
  166. return m_pwndTitle;
  167. }
  168. inline bool CMapView2DBase::HasTitleWnd() const
  169. {
  170. return m_pwndTitle != NULL;
  171. }
  172. #endif // MAPVIEW2DBASE_H