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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: A page in a tabbed dialog that allows the editing of face properties.
//
//=============================================================================//
#include <stdafx.h>
#include "hammer.h"
#include "MainFrm.h"
#include "GlobalFunctions.h"
#include "FaceEditSheet.h"
#include "MapSolid.h"
#include "MapFace.h"
#include "MapDisp.h"
#include "ToolManager.h"
#include "mapdoc.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
IMPLEMENT_DYNAMIC( CFaceEditSheet, CPropertySheet )
BEGIN_MESSAGE_MAP( CFaceEditSheet, CPropertySheet )
//{{AFX_MSG_MAP( CFaceEdtiSheet )
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
CFaceEditSheet::CFaceEditSheet( LPCTSTR pszCaption, CWnd *pParentWnd, UINT iSelectPage ) :
CPropertySheet( pszCaption, pParentWnd, iSelectPage )
{
m_ClickMode = -1;
m_bEnableUpdate = true;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
CFaceEditSheet::~CFaceEditSheet()
{
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CFaceEditSheet::SetupPages( void )
{
//
// add pages to sheet
//
AddPage( &m_MaterialPage );
AddPage( &m_DispPage );
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CFaceEditSheet::Setup( void )
{
SetupPages();
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
BOOL CFaceEditSheet::Create( CWnd *pParentWnd )
{
if( !CPropertySheet::Create( pParentWnd ) )
return FALSE;
//
// touch all pages so they create the hWnd for each
//
SetActivePage( &m_DispPage );
SetActivePage( &m_MaterialPage );
//
// initialize the pages
//
m_MaterialPage.Init();
// m_DispPage.Init();
return TRUE;
}
//-----------------------------------------------------------------------------
// Purpose: Disables window updates when adding a large number of faces to the
// dialog at once. When updates are re-enabled, the window is updated.
// Input : bEnable - true to enable updates, false to disable them.
//-----------------------------------------------------------------------------
void CFaceEditSheet::EnableUpdate( bool bEnable )
{
bool bOld = m_bEnableUpdate;
m_bEnableUpdate = bEnable;
if( ( bEnable ) && ( !bOld ) )
{
m_MaterialPage.UpdateDialogData();
}
}
//-----------------------------------------------------------------------------
// Purpose: Called when a new material is detected.
//-----------------------------------------------------------------------------
void CFaceEditSheet::NotifyNewMaterial( IEditorTexture *pTex )
{
m_MaterialPage.NotifyNewMaterial( pTex );
}
//-----------------------------------------------------------------------------
// Purpose: Clear the face list.
//-----------------------------------------------------------------------------
void CFaceEditSheet::ClearFaceList( void )
{
//
// reset selection state of all faces currently in the list
//
for( int i = 0; i < m_Faces.Count(); i++ )
{
m_Faces[i].pMapFace->SetSelectionState( SELECT_NONE );
EditDispHandle_t handle = m_Faces[i].pMapFace->GetDisp();
CMapDisp *pDisp = EditDispMgr()->GetDisp( handle );
if( pDisp )
{
pDisp->ResetTexelHitIndex();
}
}
//
// reset the list
//
m_Faces.Purge();
CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
if ( pDoc )
pDoc->UpdateAllViews( MAPVIEW_UPDATE_ONLY_3D );
}
void CFaceEditSheet::ClearFaceListByMapDoc( CMapDoc *pDoc )
{
// Remove any faces from our list that came from this CMapDoc.
for( int i = 0; i < m_Faces.Count(); i++ )
{
if ( m_Faces[i].pMapDoc == pDoc )
{
m_Faces.Remove( i );
--i;
}
}
}
//-----------------------------------------------------------------------------
// Purpose: Search for the given face in the face selection list. If found,
// return the index of the face in the list. Otherwise, return -1.
//-----------------------------------------------------------------------------
int CFaceEditSheet::FindFaceInList( CMapFace *pFace )
{
for( int i = 0; i < m_Faces.Count(); i++ )
{
if( m_Faces[i].pMapFace == pFace )
return i;
}
return -1;
}
//-----------------------------------------------------------------------------
// It is really lame that I have to have material/displacement specific code
// here! It is unfortunately necessary - see CMapDoc (SelectFace). ClickFace
// not only specifies face selection (which it should do only!!!), but also
// specifies the "mode" (material specific) of the click -- LAME!!!! This will
// be a problem spot if/when we make face selection general. cab
//-----------------------------------------------------------------------------
void CFaceEditSheet::ClickFace( CMapSolid *pSolid, int faceIndex, int cmd, int clickMode )
{
//
// set the click mode (either to new mode or previously used)
//
if( clickMode == -1 )
{
clickMode = m_ClickMode;
}
//
// clear the face list?
//
if( cmd & cfClear )
{
ClearFaceList();
}
cmd &= ~cfClear;
//
// check for valid solid
//
if( !pSolid )
return;
//
// check for face in list, -1 from FindFaceInList indicates face not found
//
CMapFace *pFace = pSolid->GetFace( faceIndex );
int selectIndex = FindFaceInList( pFace );
bool bFoundInList = ( selectIndex != -1 );
//
// handle the face list selection
//
if( ( clickMode == ModeSelect ) || ( clickMode == ModeLiftSelect ) )
{
// toggle selection if necessary
if( cmd == cfToggle )
{
cmd = bFoundInList ? cfUnselect : cfSelect;
}
CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
if( ( cmd == cfSelect ) && !bFoundInList )
{
// add face to list
StoredFace_t sf;
sf.pMapDoc = pDoc;
sf.pMapFace = pFace;
sf.pMapSolid = pSolid;
m_Faces.AddToTail( sf );
pFace->SetSelectionState( SELECT_NORMAL );
}
else if( ( cmd == cfUnselect ) && bFoundInList )
{
// remove from list
m_Faces.Remove( selectIndex );
pFace->SetSelectionState( SELECT_NONE );
EditDispHandle_t handle = pFace->GetDisp();
CMapDisp *pDisp = EditDispMgr()->GetDisp( handle );
if( pDisp )
{
pDisp->ResetTexelHitIndex();
}
}
if ( pDoc )
pDoc->UpdateAllViews( MAPVIEW_UPDATE_ONLY_3D );
}
//
// pass to children (pages)
//
m_MaterialPage.ClickFace( pSolid, faceIndex, cmd, clickMode );
m_DispPage.ClickFace( pSolid, faceIndex, cmd, clickMode );
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CFaceEditSheet::SetVisibility( bool bVisible )
{
if( bVisible )
{
ShowWindow( SW_SHOW );
SetActivePage( &m_DispPage ); // gross hack to active the default button!!!!
SetActivePage( &m_MaterialPage );
m_MaterialPage.UpdateDialogData();
m_DispPage.UpdateDialogData();
}
else
{
ShowWindow( SW_HIDE );
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
BOOL CFaceEditSheet::PreTranslateMessage( MSG *pMsg )
{
HACCEL hAccel = GetMainWnd()->GetAccelTable();
if( !(hAccel && ::TranslateAccelerator( GetMainWnd()->m_hWnd, hAccel, pMsg ) ) )
{
if (IsDialogMessage(pMsg))
{
return(TRUE);
}
return CWnd::PreTranslateMessage( pMsg );
}
return TRUE;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CFaceEditSheet::OnClose( void )
{
// make sure all dialogs are closed upon exit!!
m_DispPage.CloseAllDialogs();
m_DispPage.ResetForceShows();
// toggle the face edit sheet and texture bar!
GetMainWnd()->ShowFaceEditSheetOrTextureBar( false );
// Force the material page to the original tool. This will clear out all
// dialogs
m_MaterialPage.SetMaterialPageTool( CFaceEditMaterialPage::MATERIALPAGETOOL_MATERIAL );
// set the tool pointer as default tool
ToolManager()->SetTool(TOOL_POINTER);
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CFaceEditSheet::CloseAllPageDialogs( void )
{
// Make sure all dialogs are closed upon exit!
m_DispPage.CloseAllDialogs();
m_DispPage.ResetForceShows();
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CFaceEditSheet::UpdateControls( void )
{
// Currently this is only needed for the material page.
m_MaterialPage.UpdateDialogData();
}
|