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.5 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 "MapAxisHandle.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 "ToolAxisHandle.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. CToolAxisHandle::CToolAxisHandle(void)
  26. {
  27. m_pAxis = NULL;
  28. m_nPointIndex = 0;
  29. }
  30. //-----------------------------------------------------------------------------
  31. // Purpose: Attaches the point to the tool for manipulation.
  32. //-----------------------------------------------------------------------------
  33. void CToolAxisHandle::Attach(CMapAxisHandle *pAxis, int nPointIndex)
  34. {
  35. if ((pAxis != NULL) && (nPointIndex < 2))
  36. {
  37. m_pAxis = pAxis;
  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 CToolAxisHandle::OnLMouseDown2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint)
  47. {
  48. //
  49. // Activate this tool and start dragging the axis endpoint.
  50. //
  51. ToolManager()->PushTool(TOOL_AXIS_HANDLE);
  52. pView->SetCapture();
  53. CMapDoc *pDoc = pView->GetMapDoc();
  54. GetHistory()->MarkUndoPosition(pDoc->GetSelection()->GetList(), "Modify Axis");
  55. GetHistory()->Keep(m_pAxis);
  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 CToolAxisHandle::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 CToolAxisHandle::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 axis even on odd-width objects.
  86. //
  87. Vector vecWorld;
  88. pView->ClientToWorld(vecWorld, vPoint);
  89. CMapDoc *pDoc = pView->GetMapDoc();
  90. pDoc->Snap(vecWorld, constrainHalfSnap);
  91. //
  92. // Move to the snapped position.
  93. //
  94. Vector vecPos[2];
  95. m_pAxis->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_pAxis->UpdateEndPoint(vecPos[m_nPointIndex], m_nPointIndex);
  99. int nOtherIndex = (m_nPointIndex == 0);
  100. m_pAxis->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 CToolAxisHandle::RenderTool2D(CRender2D *pRender)
  115. {
  116. SelectionState_t eState = m_pAxis->SetSelectionState(SELECT_MODIFY, m_nPointIndex);
  117. m_pAxis->Render2D(pRender);
  118. m_pAxis->SetSelectionState(eState);
  119. }