forked from nillerusr/source-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolAxisHandle.cpp
More file actions
149 lines (119 loc) · 4.48 KB
/
ToolAxisHandle.cpp
File metadata and controls
149 lines (119 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//========= 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);
}