Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

334 lines
9.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A page in a tabbed dialog that allows the editing of face properties.
  4. //
  5. //=============================================================================//
  6. #include <stdafx.h>
  7. #include "hammer.h"
  8. #include "MainFrm.h"
  9. #include "GlobalFunctions.h"
  10. #include "FaceEditSheet.h"
  11. #include "MapSolid.h"
  12. #include "MapFace.h"
  13. #include "MapDisp.h"
  14. #include "ToolManager.h"
  15. #include "mapdoc.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include <tier0/memdbgon.h>
  18. IMPLEMENT_DYNAMIC( CFaceEditSheet, CPropertySheet )
  19. BEGIN_MESSAGE_MAP( CFaceEditSheet, CPropertySheet )
  20. //{{AFX_MSG_MAP( CFaceEdtiSheet )
  21. ON_WM_CLOSE()
  22. //}}AFX_MSG_MAP
  23. END_MESSAGE_MAP()
  24. //-----------------------------------------------------------------------------
  25. //-----------------------------------------------------------------------------
  26. CFaceEditSheet::CFaceEditSheet( LPCTSTR pszCaption, CWnd *pParentWnd, UINT iSelectPage ) :
  27. CPropertySheet( pszCaption, pParentWnd, iSelectPage )
  28. {
  29. m_ClickMode = -1;
  30. m_bEnableUpdate = true;
  31. }
  32. //-----------------------------------------------------------------------------
  33. //-----------------------------------------------------------------------------
  34. CFaceEditSheet::~CFaceEditSheet()
  35. {
  36. }
  37. //-----------------------------------------------------------------------------
  38. //-----------------------------------------------------------------------------
  39. void CFaceEditSheet::SetupPages( void )
  40. {
  41. //
  42. // add pages to sheet
  43. //
  44. AddPage( &m_MaterialPage );
  45. AddPage( &m_DispPage );
  46. }
  47. //-----------------------------------------------------------------------------
  48. //-----------------------------------------------------------------------------
  49. void CFaceEditSheet::Setup( void )
  50. {
  51. SetupPages();
  52. }
  53. //-----------------------------------------------------------------------------
  54. //-----------------------------------------------------------------------------
  55. BOOL CFaceEditSheet::Create( CWnd *pParentWnd )
  56. {
  57. if( !CPropertySheet::Create( pParentWnd ) )
  58. return FALSE;
  59. //
  60. // touch all pages so they create the hWnd for each
  61. //
  62. SetActivePage( &m_DispPage );
  63. SetActivePage( &m_MaterialPage );
  64. //
  65. // initialize the pages
  66. //
  67. m_MaterialPage.Init();
  68. // m_DispPage.Init();
  69. return TRUE;
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Purpose: Disables window updates when adding a large number of faces to the
  73. // dialog at once. When updates are re-enabled, the window is updated.
  74. // Input : bEnable - true to enable updates, false to disable them.
  75. //-----------------------------------------------------------------------------
  76. void CFaceEditSheet::EnableUpdate( bool bEnable )
  77. {
  78. bool bOld = m_bEnableUpdate;
  79. m_bEnableUpdate = bEnable;
  80. if( ( bEnable ) && ( !bOld ) )
  81. {
  82. m_MaterialPage.UpdateDialogData();
  83. }
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Purpose: Called when a new material is detected.
  87. //-----------------------------------------------------------------------------
  88. void CFaceEditSheet::NotifyNewMaterial( IEditorTexture *pTex )
  89. {
  90. m_MaterialPage.NotifyNewMaterial( pTex );
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Purpose: Clear the face list.
  94. //-----------------------------------------------------------------------------
  95. void CFaceEditSheet::ClearFaceList( void )
  96. {
  97. //
  98. // reset selection state of all faces currently in the list
  99. //
  100. for( int i = 0; i < m_Faces.Count(); i++ )
  101. {
  102. m_Faces[i].pMapFace->SetSelectionState( SELECT_NONE );
  103. EditDispHandle_t handle = m_Faces[i].pMapFace->GetDisp();
  104. CMapDisp *pDisp = EditDispMgr()->GetDisp( handle );
  105. if( pDisp )
  106. {
  107. pDisp->ResetTexelHitIndex();
  108. }
  109. }
  110. //
  111. // reset the list
  112. //
  113. m_Faces.Purge();
  114. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  115. if ( pDoc )
  116. pDoc->UpdateAllViews( MAPVIEW_UPDATE_ONLY_3D );
  117. }
  118. void CFaceEditSheet::ClearFaceListByMapDoc( CMapDoc *pDoc )
  119. {
  120. // Remove any faces from our list that came from this CMapDoc.
  121. for( int i = 0; i < m_Faces.Count(); i++ )
  122. {
  123. if ( m_Faces[i].pMapDoc == pDoc )
  124. {
  125. m_Faces.Remove( i );
  126. --i;
  127. }
  128. }
  129. }
  130. //-----------------------------------------------------------------------------
  131. // Purpose: Search for the given face in the face selection list. If found,
  132. // return the index of the face in the list. Otherwise, return -1.
  133. //-----------------------------------------------------------------------------
  134. int CFaceEditSheet::FindFaceInList( CMapFace *pFace )
  135. {
  136. for( int i = 0; i < m_Faces.Count(); i++ )
  137. {
  138. if( m_Faces[i].pMapFace == pFace )
  139. return i;
  140. }
  141. return -1;
  142. }
  143. //-----------------------------------------------------------------------------
  144. // It is really lame that I have to have material/displacement specific code
  145. // here! It is unfortunately necessary - see CMapDoc (SelectFace). ClickFace
  146. // not only specifies face selection (which it should do only!!!), but also
  147. // specifies the "mode" (material specific) of the click -- LAME!!!! This will
  148. // be a problem spot if/when we make face selection general. cab
  149. //-----------------------------------------------------------------------------
  150. void CFaceEditSheet::ClickFace( CMapSolid *pSolid, int faceIndex, int cmd, int clickMode )
  151. {
  152. //
  153. // set the click mode (either to new mode or previously used)
  154. //
  155. if( clickMode == -1 )
  156. {
  157. clickMode = m_ClickMode;
  158. }
  159. //
  160. // clear the face list?
  161. //
  162. if( cmd & cfClear )
  163. {
  164. ClearFaceList();
  165. }
  166. cmd &= ~cfClear;
  167. //
  168. // check for valid solid
  169. //
  170. if( !pSolid )
  171. return;
  172. //
  173. // check for face in list, -1 from FindFaceInList indicates face not found
  174. //
  175. CMapFace *pFace = pSolid->GetFace( faceIndex );
  176. int selectIndex = FindFaceInList( pFace );
  177. bool bFoundInList = ( selectIndex != -1 );
  178. //
  179. // handle the face list selection
  180. //
  181. if( ( clickMode == ModeSelect ) || ( clickMode == ModeLiftSelect ) )
  182. {
  183. // toggle selection if necessary
  184. if( cmd == cfToggle )
  185. {
  186. cmd = bFoundInList ? cfUnselect : cfSelect;
  187. }
  188. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  189. if( ( cmd == cfSelect ) && !bFoundInList )
  190. {
  191. // add face to list
  192. StoredFace_t sf;
  193. sf.pMapDoc = pDoc;
  194. sf.pMapFace = pFace;
  195. sf.pMapSolid = pSolid;
  196. m_Faces.AddToTail( sf );
  197. pFace->SetSelectionState( SELECT_NORMAL );
  198. }
  199. else if( ( cmd == cfUnselect ) && bFoundInList )
  200. {
  201. // remove from list
  202. m_Faces.Remove( selectIndex );
  203. pFace->SetSelectionState( SELECT_NONE );
  204. EditDispHandle_t handle = pFace->GetDisp();
  205. CMapDisp *pDisp = EditDispMgr()->GetDisp( handle );
  206. if( pDisp )
  207. {
  208. pDisp->ResetTexelHitIndex();
  209. }
  210. }
  211. if ( pDoc )
  212. pDoc->UpdateAllViews( MAPVIEW_UPDATE_ONLY_3D );
  213. }
  214. //
  215. // pass to children (pages)
  216. //
  217. m_MaterialPage.ClickFace( pSolid, faceIndex, cmd, clickMode );
  218. m_DispPage.ClickFace( pSolid, faceIndex, cmd, clickMode );
  219. }
  220. //-----------------------------------------------------------------------------
  221. //-----------------------------------------------------------------------------
  222. void CFaceEditSheet::SetVisibility( bool bVisible )
  223. {
  224. if( bVisible )
  225. {
  226. ShowWindow( SW_SHOW );
  227. SetActivePage( &m_DispPage ); // gross hack to active the default button!!!!
  228. SetActivePage( &m_MaterialPage );
  229. m_MaterialPage.UpdateDialogData();
  230. m_DispPage.UpdateDialogData();
  231. }
  232. else
  233. {
  234. ShowWindow( SW_HIDE );
  235. }
  236. }
  237. //-----------------------------------------------------------------------------
  238. //-----------------------------------------------------------------------------
  239. BOOL CFaceEditSheet::PreTranslateMessage( MSG *pMsg )
  240. {
  241. HACCEL hAccel = GetMainWnd()->GetAccelTable();
  242. if( !(hAccel && ::TranslateAccelerator( GetMainWnd()->m_hWnd, hAccel, pMsg ) ) )
  243. {
  244. if (IsDialogMessage(pMsg))
  245. {
  246. return(TRUE);
  247. }
  248. return CWnd::PreTranslateMessage( pMsg );
  249. }
  250. return TRUE;
  251. }
  252. //-----------------------------------------------------------------------------
  253. //-----------------------------------------------------------------------------
  254. void CFaceEditSheet::OnClose( void )
  255. {
  256. // make sure all dialogs are closed upon exit!!
  257. m_DispPage.CloseAllDialogs();
  258. m_DispPage.ResetForceShows();
  259. // toggle the face edit sheet and texture bar!
  260. GetMainWnd()->ShowFaceEditSheetOrTextureBar( false );
  261. // Force the material page to the original tool. This will clear out all
  262. // dialogs
  263. m_MaterialPage.SetMaterialPageTool( CFaceEditMaterialPage::MATERIALPAGETOOL_MATERIAL );
  264. // set the tool pointer as default tool
  265. ToolManager()->SetTool(TOOL_POINTER);
  266. }
  267. //-----------------------------------------------------------------------------
  268. //-----------------------------------------------------------------------------
  269. void CFaceEditSheet::CloseAllPageDialogs( void )
  270. {
  271. // Make sure all dialogs are closed upon exit!
  272. m_DispPage.CloseAllDialogs();
  273. m_DispPage.ResetForceShows();
  274. }
  275. //-----------------------------------------------------------------------------
  276. //-----------------------------------------------------------------------------
  277. void CFaceEditSheet::UpdateControls( void )
  278. {
  279. // Currently this is only needed for the material page.
  280. m_MaterialPage.UpdateDialogData();
  281. }