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.

149 lines
4.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "stdafx.h"
  8. #include "History.h"
  9. #include "MainFrm.h" // For ObjectProperties
  10. #include "MapDoc.h"
  11. #include "MapSweptPlayerHull.h"
  12. #include "MapPointHandle.h"
  13. #include "MapView2D.h"
  14. #include "Render2D.h"
  15. #include "StatusBarIDs.h" // For SetStatusText
  16. #include "ToolManager.h"
  17. #include "ToolSweptHull.h"
  18. #include "ToolPointHandle.h"
  19. #include "Selection.h"
  20. // memdbgon must be the last include file in a .cpp file!!!
  21. #include <tier0/memdbgon.h>
  22. //-----------------------------------------------------------------------------
  23. // Purpose: Constructor.
  24. //-----------------------------------------------------------------------------
  25. CToolSweptPlayerHull::CToolSweptPlayerHull(void)
  26. {
  27. m_pSweptHull = NULL;
  28. m_nPointIndex = 0;
  29. }
  30. //-----------------------------------------------------------------------------
  31. // Purpose: Attaches the point to the tool for manipulation.
  32. //-----------------------------------------------------------------------------
  33. void CToolSweptPlayerHull::Attach(CMapSweptPlayerHull *pSweptHull, int nPointIndex)
  34. {
  35. if ((pSweptHull != NULL) && (nPointIndex < 2))
  36. {
  37. m_pSweptHull = pSweptHull;
  38. m_nPointIndex = nPointIndex;
  39. }
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Purpose: Handles left button down events in the 2D view.
  43. // Input : Per CWnd::OnLButtonDown.
  44. // Output : Returns true if the message was handled, false if not.
  45. //-----------------------------------------------------------------------------
  46. bool CToolSweptPlayerHull::OnLMouseDown2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint)
  47. {
  48. //
  49. // Activate this tool and start dragging the swept hull endpoint.
  50. //
  51. ToolManager()->PushTool(TOOL_SWEPT_HULL);
  52. pView->SetCapture();
  53. CMapDoc *pDoc = pView->GetMapDoc();
  54. GetHistory()->MarkUndoPosition(pDoc->GetSelection()->GetList(), "Modify Swept Hull");
  55. GetHistory()->Keep(m_pSweptHull);
  56. return true;
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Purpose: Handles left button up events in the 2D view.
  60. // Input : Per CWnd::OnLButtonUp.
  61. // Output : Returns true if the message was handled, false if not.
  62. //-----------------------------------------------------------------------------
  63. bool CToolSweptPlayerHull::OnLMouseUp2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint)
  64. {
  65. // dvsFIXME: do we need to update the point here?
  66. ToolManager()->PopTool();
  67. ReleaseCapture();
  68. CMapDoc *pDoc = pView->GetMapDoc();
  69. pDoc->UpdateAllViews( MAPVIEW_UPDATE_TOOL );
  70. return true;
  71. }
  72. //-----------------------------------------------------------------------------
  73. // Purpose: Handles mouse move events in the 2D view.
  74. // Input : Per CWnd::OnMouseMove.
  75. // Output : Returns true if the message was handled, false if not.
  76. //-----------------------------------------------------------------------------
  77. bool CToolSweptPlayerHull::OnMouseMove2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint)
  78. {
  79. //
  80. // Make sure the point is visible.
  81. //
  82. pView->ToolScrollToPoint(vPoint);
  83. //
  84. // Snap the point to half the grid size. Do this so that we can always center
  85. // the hull even on odd-width objects.
  86. //
  87. Vector vecWorld;
  88. pView->ClientToWorld(vecWorld, vPoint);
  89. CMapDoc *pDoc = pView->GetMapDoc();
  90. pDoc->Snap(vecWorld, 0);
  91. //
  92. // Move to the snapped position.
  93. //
  94. Vector vecPos[2];
  95. m_pSweptHull->GetEndPoint(vecPos[m_nPointIndex], m_nPointIndex);
  96. vecPos[m_nPointIndex][pView->axHorz] = vecWorld[pView->axHorz];
  97. vecPos[m_nPointIndex][pView->axVert] = vecWorld[pView->axVert];
  98. m_pSweptHull->UpdateEndPoint(vecPos[m_nPointIndex], m_nPointIndex);
  99. int nOtherIndex = (m_nPointIndex == 0);
  100. m_pSweptHull->GetEndPoint(vecPos[nOtherIndex], nOtherIndex);
  101. //
  102. // Update the status bar and the views.
  103. //
  104. char szBuf[128];
  105. sprintf(szBuf, " (%.0f %.0f %0.f) ", vecPos[m_nPointIndex][0], vecPos[m_nPointIndex][1], vecPos[m_nPointIndex][2]);
  106. SetStatusText(SBI_COORDS, szBuf);
  107. pDoc->UpdateAllViews( MAPVIEW_UPDATE_TOOL );
  108. return true;
  109. }
  110. //-----------------------------------------------------------------------------
  111. // Purpose: Renders the tool in the 2D view.
  112. // Input : pRender - The interface to use for rendering.
  113. //-----------------------------------------------------------------------------
  114. void CToolSweptPlayerHull::RenderTool2D(CRender2D *pRender)
  115. {
  116. SelectionState_t eState = m_pSweptHull->SetSelectionState(SELECT_MODIFY, m_nPointIndex);
  117. m_pSweptHull->Render2D(pRender);
  118. m_pSweptHull->SetSelectionState(eState);
  119. }