summaryrefslogtreecommitdiff
path: root/hammer/ToolAxisHandle.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /hammer/ToolAxisHandle.cpp
downloadarchived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz
archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip
Diffstat (limited to 'hammer/ToolAxisHandle.cpp')
-rw-r--r--hammer/ToolAxisHandle.cpp149
1 files changed, 149 insertions, 0 deletions
diff --git a/hammer/ToolAxisHandle.cpp b/hammer/ToolAxisHandle.cpp
new file mode 100644
index 0000000..e9f33d0
--- /dev/null
+++ b/hammer/ToolAxisHandle.cpp
@@ -0,0 +1,149 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#include "stdafx.h"
+#include "History.h"
+#include "MainFrm.h" // For ObjectProperties
+#include "MapDoc.h"
+#include "MapAxisHandle.h"
+#include "MapPointHandle.h"
+#include "MapView2D.h"
+#include "Render2D.h"
+#include "StatusBarIDs.h" // For SetStatusText
+#include "ToolManager.h"
+#include "ToolAxisHandle.h"
+#include "ToolPointHandle.h"
+#include "Selection.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include <tier0/memdbgon.h>
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Constructor.
+//-----------------------------------------------------------------------------
+CToolAxisHandle::CToolAxisHandle(void)
+{
+ m_pAxis = NULL;
+ m_nPointIndex = 0;
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Attaches the point to the tool for manipulation.
+//-----------------------------------------------------------------------------
+void CToolAxisHandle::Attach(CMapAxisHandle *pAxis, int nPointIndex)
+{
+ if ((pAxis != NULL) && (nPointIndex < 2))
+ {
+ m_pAxis = pAxis;
+ m_nPointIndex = nPointIndex;
+ }
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Handles left button down events in the 2D view.
+// Input : Per CWnd::OnLButtonDown.
+// Output : Returns true if the message was handled, false if not.
+//-----------------------------------------------------------------------------
+bool CToolAxisHandle::OnLMouseDown2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint)
+{
+ //
+ // Activate this tool and start dragging the axis endpoint.
+ //
+ ToolManager()->PushTool(TOOL_AXIS_HANDLE);
+ pView->SetCapture();
+
+ CMapDoc *pDoc = pView->GetMapDoc();
+ GetHistory()->MarkUndoPosition(pDoc->GetSelection()->GetList(), "Modify Axis");
+ GetHistory()->Keep(m_pAxis);
+
+ return true;
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Handles left button up events in the 2D view.
+// Input : Per CWnd::OnLButtonUp.
+// Output : Returns true if the message was handled, false if not.
+//-----------------------------------------------------------------------------
+bool CToolAxisHandle::OnLMouseUp2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint)
+{
+ // dvsFIXME: do we need to update the point here?
+
+ ToolManager()->PopTool();
+ ReleaseCapture();
+
+ CMapDoc *pDoc = pView->GetMapDoc();
+ pDoc->UpdateAllViews( MAPVIEW_UPDATE_TOOL );
+
+ return true;
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Handles mouse move events in the 2D view.
+// Input : Per CWnd::OnMouseMove.
+// Output : Returns true if the message was handled, false if not.
+//-----------------------------------------------------------------------------
+bool CToolAxisHandle::OnMouseMove2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint)
+{
+ //
+ // Make sure the point is visible.
+ //
+ pView->ToolScrollToPoint( vPoint);
+
+ //
+ // Snap the point to half the grid size. Do this so that we can always center
+ // the axis even on odd-width objects.
+ //
+ Vector vecWorld;
+ pView->ClientToWorld(vecWorld, vPoint);
+
+ CMapDoc *pDoc = pView->GetMapDoc();
+ pDoc->Snap(vecWorld, constrainHalfSnap);
+
+ //
+ // Move to the snapped position.
+ //
+ Vector vecPos[2];
+ m_pAxis->GetEndPoint(vecPos[m_nPointIndex], m_nPointIndex);
+
+ vecPos[m_nPointIndex][pView->axHorz] = vecWorld[pView->axHorz];
+ vecPos[m_nPointIndex][pView->axVert] = vecWorld[pView->axVert];
+
+ m_pAxis->UpdateEndPoint(vecPos[m_nPointIndex], m_nPointIndex);
+
+ int nOtherIndex = (m_nPointIndex == 0);
+ m_pAxis->GetEndPoint(vecPos[nOtherIndex], nOtherIndex);
+
+ //
+ // Update the status bar and the views.
+ //
+ char szBuf[128];
+ sprintf(szBuf, " (%.0f %.0f %0.f) ", vecPos[m_nPointIndex][0], vecPos[m_nPointIndex][1], vecPos[m_nPointIndex][2]);
+ SetStatusText(SBI_COORDS, szBuf);
+
+ pDoc->UpdateAllViews( MAPVIEW_UPDATE_TOOL );
+
+ return true;
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Renders the tool in the 2D view.
+// Input : pRender - The interface to use for rendering.
+//-----------------------------------------------------------------------------
+void CToolAxisHandle::RenderTool2D(CRender2D *pRender)
+{
+ SelectionState_t eState = m_pAxis->SetSelectionState(SELECT_MODIFY, m_nPointIndex);
+ m_pAxis->Render2D(pRender);
+ m_pAxis->SetSelectionState(eState);
+}
+
+