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.

119 lines
3.4 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" // FIXME: For ObjectProperties
  10. #include "MapDoc.h"
  11. #include "MapView2D.h"
  12. #include "MapSphere.h"
  13. #include "StatusBarIDs.h" // For updating status bar text
  14. #include "ToolManager.h"
  15. #include "ToolSphere.h"
  16. #include "Selection.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include <tier0/memdbgon.h>
  19. //-----------------------------------------------------------------------------
  20. // Purpose:
  21. //-----------------------------------------------------------------------------
  22. CToolSphere::CToolSphere()
  23. {
  24. m_pSphere = NULL;
  25. }
  26. //-----------------------------------------------------------------------------
  27. // Purpose:
  28. // Input : pSphere -
  29. //-----------------------------------------------------------------------------
  30. void CToolSphere::Attach(CMapSphere *pSphere)
  31. {
  32. m_pSphere = pSphere;
  33. }
  34. //-----------------------------------------------------------------------------
  35. // Purpose:
  36. // Input : pView -
  37. // nFlags -
  38. // point -
  39. // Output : Returns true if the message was handled, false otherwise.
  40. //-----------------------------------------------------------------------------
  41. bool CToolSphere::OnLMouseDown2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint)
  42. {
  43. //
  44. // Activate this tool and start resizing the sphere.
  45. //
  46. ToolManager()->PushTool(TOOL_SPHERE);
  47. pView->SetCapture();
  48. GetHistory()->MarkUndoPosition(m_pDocument->GetSelection()->GetList(), "Modify Radius");
  49. GetHistory()->Keep(m_pSphere);
  50. return true;
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose:
  54. // Input : pView -
  55. // nFlags -
  56. // point -
  57. // Output : Returns true if the message was handled, false otherwise.
  58. //-----------------------------------------------------------------------------
  59. bool CToolSphere::OnLMouseUp2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint)
  60. {
  61. ToolManager()->PopTool();
  62. ReleaseCapture();
  63. m_pDocument->SetModifiedFlag();
  64. return true;
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose:
  68. // Input : pView -
  69. // nFlags -
  70. // point -
  71. // Output : Returns true if the message was handled, false otherwise.
  72. //-----------------------------------------------------------------------------
  73. bool CToolSphere::OnMouseMove2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint)
  74. {
  75. // Make sure the point is visible.
  76. pView->ToolScrollToPoint( vPoint );
  77. Vector vecWorld;
  78. pView->ClientToWorld( vecWorld, vPoint );
  79. m_pDocument->Snap( vecWorld, constrainSnap );
  80. //
  81. // Use whichever axis they dragged the most along as the drag axis.
  82. // Calculate the drag distance in client coordinates.
  83. //
  84. float flHorzRadius = fabs((float)vecWorld[pView->axHorz] - m_pSphere->m_Origin[pView->axHorz]);
  85. float flVertRadius = fabs((float)vecWorld[pView->axVert] - m_pSphere->m_Origin[pView->axVert]);
  86. float flRadius = max(flHorzRadius, flVertRadius);
  87. m_pSphere->SetRadius(flRadius);
  88. //
  89. // Update the status bar text with the new value of the radius.
  90. //
  91. char szBuf[128];
  92. sprintf(szBuf, " %s = %g ", m_pSphere->m_szKeyName, (double)m_pSphere->m_flRadius);
  93. SetStatusText(SBI_COORDS, szBuf);
  94. m_pDocument->UpdateAllViews( MAPVIEW_UPDATE_TOOL );
  95. return true;
  96. }