forked from nillerusr/source-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToolClipper.h
186 lines (131 loc) · 5.06 KB
/
ToolClipper.h
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef CLIPPER3D_H
#define CLIPPER3D_H
#ifdef _WIN32
#pragma once
#endif
#include "MapClass.h" // For CMapObjectList
#include "Tool3D.h"
#include "ToolInterface.h"
#include "Render2D.h"
#include "MapFace.h"
class CMapSolid;
//=============================================================================
//
// CClipGroup
//
class CClipGroup
{
public:
enum { FRONT = 0, BACK };
inline CClipGroup();
~CClipGroup();
inline void SetOrigSolid( CMapSolid *pSolid );
inline CMapSolid *GetOrigSolid( void );
inline void SetClipSolid( CMapSolid *pSolid, int side );
inline CMapSolid *GetClipSolid( int side );
private:
CMapSolid *m_pOrigSolid;
CMapSolid *m_pClipSolids[2]; // front, back
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
inline CClipGroup::CClipGroup()
{
m_pOrigSolid = NULL;
m_pClipSolids[0] = NULL;
m_pClipSolids[1] = NULL;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
inline void CClipGroup::SetOrigSolid( CMapSolid *pSolid )
{
m_pOrigSolid = pSolid;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
inline CMapSolid *CClipGroup::GetOrigSolid( void )
{
return m_pOrigSolid;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
inline void CClipGroup::SetClipSolid( CMapSolid *pSolid, int side )
{
m_pClipSolids[side] = pSolid;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
inline CMapSolid *CClipGroup::GetClipSolid( int side )
{
return m_pClipSolids[side];
}
class Clipper3D : public Tool3D
{
friend BOOL AddToClipList( CMapSolid *pSolid, Clipper3D *pClipper );
public:
enum { FRONT = 0, BACK, BOTH };
Clipper3D();
~Clipper3D();
void IterateClipMode( void );
inline void ToggleMeasurements( void );
//
// Tool3D implementation.
//
virtual int HitTest( CMapView *pView, const Vector2D &vPoint, bool bTestHandles = false );
virtual unsigned int GetConstraints(unsigned int nKeyFlags);
//
// CBaseTool implementation.
//
virtual void OnActivate();
virtual void OnDeactivate();
virtual ToolID_t GetToolID(void) { return TOOL_CLIPPER; }
virtual void RenderTool2D(CRender2D *pRender);
virtual void RenderTool3D(CRender3D *pRender);
virtual bool OnKeyDown2D(CMapView2D *pView, UINT nChar, UINT nRepCnt, UINT nFlags);
virtual bool OnKeyDown3D(CMapView3D *pView, UINT nChar, UINT nRepCnt, UINT nFlags);
virtual bool OnLMouseDown2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint);
virtual bool OnLMouseUp2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint);
virtual bool OnMouseMove2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint);
protected:
//
// Tool3D implementation.
//
virtual bool UpdateTranslation( const Vector &vUpdate, UINT uFlags = 0 );
virtual void FinishTranslation( bool bSave );
private:
void OnEscape(void);
void SetClipObjects( const CMapObjectList *pList );
void SetClipPlane( PLANE *pPlane );
void BuildClipPlane( void );
void SaveClipResults( void );
void GetClipResults( void );
void CalcClipResults( void );
void ResetClipResults( void );
void RemoveOrigSolid( CMapSolid *pOrigSolid );
void SaveClipSolid( CMapSolid *pSolid, CMapSolid *pOrigSolid );
void DrawBrushExtents(CRender2D *pRender, CMapSolid *pSolid, int nFlags);
int m_Mode; // current clipping mode { back, front, both }
PLANE m_ClipPlane; // the clipping plane -- front/back is uneccesary
Vector m_ClipPoints[2]; // 2D clipping points -- used to create the clip plane
int m_ClipPointHit; // the clipping that was "hit" {0, 1, -1}
Vector m_vOrgPos;
const CMapObjectList *m_pOrigObjects; // list of the initial objects to clip
CUtlVector<CClipGroup*> m_ClipResults; // list of clipped objects
bool m_bDrawMeasurements; // Whether to draw brush dimensions in the 2D view.
CRender2D m_Render2D; // 2d renderer
};
//-----------------------------------------------------------------------------
// Purpose: Toggles the clipper's rendering of brush measurements in the 2D view.
//-----------------------------------------------------------------------------
inline void Clipper3D::ToggleMeasurements( void )
{
m_bDrawMeasurements = !m_bDrawMeasurements;
m_pDocument->UpdateAllViews( MAPVIEW_UPDATE_TOOL );
}
#endif // CLIPPER3D_H