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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "stdafx.h"
#include "GlobalFunctions.h"
#include "History.h"
#include "MapDoc.h"
#include "MapDecal.h"
#include "MapSolid.h"
#include "MapView3D.h"
#include "resource.h"
#include "ToolManager.h"
#include "ToolDecal.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
//-----------------------------------------------------------------------------
// Purpose: Handles key down events in the 2D view.
// Input : Per CWnd::OnKeyDown.
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CToolDecal::OnKeyDown2D(CMapView2D *pView, UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch (nChar)
{
case VK_ESCAPE:
{
ToolManager()->SetTool(TOOL_POINTER);
return true;
}
}
return false;
}
//-----------------------------------------------------------------------------
// 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 CToolDecal::OnMouseMove2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint)
{
SetDecalCursor();
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Handles key down events in the 3D view.
// Input : Per CWnd::OnKeyDown.
// Output : Returns true if the message was handled, false if not.
//-----------------------------------------------------------------------------
bool CToolDecal::OnKeyDown3D(CMapView3D *pView, UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch (nChar)
{
case VK_ESCAPE:
{
ToolManager()->SetTool(TOOL_POINTER);
}
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: Handles left button down events in the 3D view.
// Input : Per CWnd::OnLButtonDown.
// Output : Returns true if the message was handled, false if not.
//-----------------------------------------------------------------------------
bool CToolDecal::OnLMouseDown3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
{
//
// See if they clicked on a brush face. If so, apply a decal where they clicked.
//
CMapDoc *pDoc = pView->GetMapDoc();
ULONG ulFace;
CMapClass *pObject;
if ((pObject = pView->NearestObjectAt( vPoint, ulFace)) != NULL)
{
CMapSolid *pSolid = dynamic_cast <CMapSolid *> (pObject);
if (pSolid == NULL)
{
return true;
}
//
// Build a ray to trace against the face that they clicked on to
// find the point of intersection.
//
Vector Start,End;
pView->GetCamera()->BuildRay( vPoint, Start, End);
Vector HitPos, HitNormal;
CMapFace *pFace = pSolid->GetFace(ulFace);
if (pFace->TraceLine(HitPos, HitNormal, Start, End))
{
GetHistory()->MarkUndoPosition(NULL, "Create decal");
CMapEntity *pEntity = new CMapEntity;
pEntity->SetKeyValue("texture", GetDefaultTextureName());
pEntity->SetPlaceholder(TRUE);
pEntity->SetOrigin(HitPos);
pEntity->SetClass("infodecal");
CMapWorld *pWorld = pDoc->GetMapWorld();
CMapDecal *pDecal = pEntity->GetChildOfType((CMapDecal *)NULL);
if (pDecal != NULL)
{
pDecal->DecalAllSolids(pWorld);
}
pEntity->CalcBounds(TRUE);
pDoc->AddObjectToWorld(pEntity);
GetHistory()->KeepNew(pEntity);
pDoc->SetModifiedFlag();
}
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Handles mouse move events in the 3D view.
// Input : Per CWnd::OnMouseMove.
// Output : Returns true if the message was handled, false if not.
//-----------------------------------------------------------------------------
bool CToolDecal::OnMouseMove3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
{
SetDecalCursor();
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Sets the cursor to the decal application cursor.
//-----------------------------------------------------------------------------
void CToolDecal::SetDecalCursor(void)
{
static HCURSOR hcurDecal;
if (!hcurDecal)
{
hcurDecal = LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_DECAL));
}
SetCursor(hcurDecal);
}
|