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.

1488 lines
40 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include <stdafx.h>
  8. #include <afxcmn.h>
  9. #include "hammer.h"
  10. #include "MainFrm.h"
  11. #include "GlobalFunctions.h"
  12. #include "MapDoc.h"
  13. #include "FaceEdit_DispPage.h"
  14. #include "MapSolid.h"
  15. #include "MapFace.h"
  16. #include "MapDisp.h"
  17. #include "FaceEditSheet.h"
  18. #include "MapView3D.h"
  19. #include "History.h"
  20. #include "ToolDisplace.h"
  21. #include "ToolManager.h"
  22. #include "DispSew.h"
  23. #include "builddisp.h"
  24. // memdbgon must be the last include file in a .cpp file!!!
  25. #include <tier0/memdbgon.h>
  26. CToolDisplace* GetDisplacementTool() { return dynamic_cast<CToolDisplace*>(ToolManager()->GetToolForID(TOOL_FACEEDIT_DISP)); }
  27. //=============================================================================
  28. IMPLEMENT_DYNAMIC( CFaceEditDispPage, CPropertyPage )
  29. BEGIN_MESSAGE_MAP( CFaceEditDispPage, CPropertyPage )
  30. //{{AFX_MSG_MAP( CFaceEditDispPage )
  31. ON_BN_CLICKED( ID_DISP_MASK_SELECT, OnCheckMaskSelect )
  32. ON_BN_CLICKED( ID_DISP_MASK_GRID, OnCheckMaskGrid )
  33. ON_BN_CLICKED( ID_DISP_NOPHYSICS_COLL, OnCheckNoPhysicsCollide )
  34. ON_BN_CLICKED( ID_DISP_NOHULL_COLL, OnCheckNoHullCollide )
  35. ON_BN_CLICKED( ID_DISP_NORAY_COLL, OnCheckNoRayCollide )
  36. ON_BN_CLICKED( ID_DISP_SELECT2, OnButtonSelect )
  37. ON_BN_CLICKED( ID_DISP_CREATE, OnButtonCreate )
  38. ON_BN_CLICKED( ID_DISP_DESTROY, OnButtonDestroy )
  39. ON_BN_CLICKED( ID_DISP_NOISE, OnButtonNoise )
  40. ON_BN_CLICKED( ID_DISP_SUBDIVIDE, OnButtonSubdivide )
  41. ON_BN_CLICKED( ID_DISP_SEW, OnButtonSew )
  42. ON_BN_CLICKED( ID_DISP_PAINT_GEO, OnButtonPaintGeo )
  43. ON_BN_CLICKED( ID_DISP_PAINT_DATA, OnButtonPaintData )
  44. ON_BN_CLICKED( ID_DISP_TAG_WALK, OnButtonTagWalkable )
  45. ON_BN_CLICKED( ID_DISP_TAG_BUILD, OnButtonTagBuildable )
  46. ON_BN_CLICKED( ID_DISP_INVERT_ALPHA, OnButtonInvertAlpha )
  47. ON_BN_CLICKED( IDC_SELECT_ADJACENT, OnSelectAdjacent )
  48. ON_NOTIFY( UDN_DELTAPOS, ID_SPIN_DISP_POWER, OnSpinUpDown )
  49. ON_NOTIFY( UDN_DELTAPOS, ID_SPIN_DISP_ELEVATION, OnSpinUpDown )
  50. ON_BN_CLICKED( ID_DISP_APPLY, OnButtonApply )
  51. //}}AFX_MSG_MAP
  52. ON_BN_CLICKED(ID_DISP_SCULPT_PAINT, &CFaceEditDispPage::OnBnClickedDispSculptPaint)
  53. END_MESSAGE_MAP()
  54. //-----------------------------------------------------------------------------
  55. // Purpose: Constructor
  56. //-----------------------------------------------------------------------------
  57. CFaceEditDispPage::CFaceEditDispPage() : CPropertyPage( IDD )
  58. {
  59. m_uiTool = FACEEDITTOOL_SELECT;
  60. m_bForceShowWalkable = false;
  61. m_bForceShowBuildable = false;
  62. }
  63. //-----------------------------------------------------------------------------
  64. // Purpose: Deconstructor
  65. //-----------------------------------------------------------------------------
  66. CFaceEditDispPage::~CFaceEditDispPage()
  67. {
  68. }
  69. //-----------------------------------------------------------------------------
  70. //-----------------------------------------------------------------------------
  71. inline void CFaceEditDispPage::PostToolUpdate( void )
  72. {
  73. // update the mapdoc views
  74. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  75. if( pDoc )
  76. {
  77. pDoc->SetModifiedFlag();
  78. }
  79. // update the dialogs data
  80. UpdateDialogData();
  81. }
  82. //-----------------------------------------------------------------------------
  83. //-----------------------------------------------------------------------------
  84. void CFaceEditDispPage::ClickFace( CMapSolid *pSolid, int faceIndex, int cmd, int clickMode )
  85. {
  86. m_bIsEditable = ( pSolid ? pSolid->IsEditable() : true );
  87. UpdateDialogData();
  88. }
  89. //-----------------------------------------------------------------------------
  90. //-----------------------------------------------------------------------------
  91. void CFaceEditDispPage::UpdateEditControls( bool bAllDisps, bool bHasFace )
  92. {
  93. //
  94. // masks - always active!!
  95. //
  96. CButton *pcheckSelect = ( CButton* )GetDlgItem( ID_DISP_MASK_SELECT );
  97. CButton *pcheckGrid = ( CButton* )GetDlgItem( ID_DISP_MASK_GRID );
  98. pcheckSelect->EnableWindow( TRUE );
  99. pcheckGrid->EnableWindow( TRUE );
  100. //
  101. // tool buttons
  102. //
  103. CButton *pbuttonSelect = ( CButton* )GetDlgItem( ID_DISP_SELECT2 );
  104. CButton *pbuttonCreate = ( CButton* )GetDlgItem( ID_DISP_CREATE );
  105. CButton *pbuttonDestroy = ( CButton* )GetDlgItem( ID_DISP_DESTROY );
  106. CButton *pbuttonPaintGeo = ( CButton* )GetDlgItem( ID_DISP_PAINT_GEO );
  107. CButton *pbuttonPaintSculpt = ( CButton* )GetDlgItem( ID_DISP_SCULPT_PAINT );
  108. CButton *pbuttonPaintData = ( CButton* )GetDlgItem( ID_DISP_PAINT_DATA );
  109. CButton *pbuttonSubdiv = ( CButton* )GetDlgItem( ID_DISP_SUBDIVIDE );
  110. CButton *pbuttonSew = ( CButton* )GetDlgItem( ID_DISP_SEW );
  111. CButton *pbuttonNoise = ( CButton* )GetDlgItem( ID_DISP_NOISE );
  112. CButton *pButtonWalk = ( CButton* )GetDlgItem( ID_DISP_TAG_WALK );
  113. CButton *pButtonBuild = ( CButton* )GetDlgItem( ID_DISP_TAG_BUILD );
  114. pbuttonSelect->EnableWindow( TRUE );
  115. pbuttonCreate->EnableWindow( FALSE );
  116. pbuttonDestroy->EnableWindow( FALSE );
  117. pbuttonPaintGeo->EnableWindow( FALSE );
  118. pbuttonPaintSculpt->EnableWindow( FALSE );
  119. pbuttonPaintData->EnableWindow( FALSE );
  120. pbuttonSubdiv->EnableWindow( FALSE );
  121. pbuttonSew->EnableWindow( FALSE );
  122. pbuttonNoise->EnableWindow( FALSE );
  123. pButtonWalk->EnableWindow( TRUE );
  124. pButtonBuild->EnableWindow( TRUE );
  125. //
  126. // attributes (displacement info)
  127. //
  128. CEdit *peditPower = ( CEdit* )GetDlgItem( ID_DISP_POWER );
  129. CSpinButtonCtrl *pspinPower = ( CSpinButtonCtrl* )GetDlgItem( ID_SPIN_DISP_POWER );
  130. CEdit *peditElevation = ( CEdit* )GetDlgItem( ID_DISP_ELEVATION );
  131. CSpinButtonCtrl *pspinElevation = ( CSpinButtonCtrl* )GetDlgItem( ID_SPIN_DISP_ELEVATION );
  132. CEdit *peditScale = ( CEdit* )GetDlgItem( ID_DISP_SCALE );
  133. CButton *pbuttonApply = ( CButton* )GetDlgItem( ID_DISP_APPLY );
  134. CButton *pbuttonInvertAlpha = ( CButton* )GetDlgItem( ID_DISP_INVERT_ALPHA );
  135. CButton *pCheckNoPhysicsColl = ( CButton* )GetDlgItem( ID_DISP_NOPHYSICS_COLL );
  136. CButton *pCheckNoHullColl = ( CButton* )GetDlgItem( ID_DISP_NOHULL_COLL );
  137. CButton *pCheckNoRayColl = ( CButton* )GetDlgItem( ID_DISP_NORAY_COLL );
  138. peditPower->EnableWindow( FALSE );
  139. pspinPower->EnableWindow( FALSE );
  140. peditElevation->EnableWindow( FALSE );
  141. pspinElevation->EnableWindow( FALSE );
  142. peditScale->EnableWindow( FALSE );
  143. pbuttonApply->EnableWindow( FALSE );
  144. pbuttonInvertAlpha->EnableWindow( FALSE );
  145. pCheckNoPhysicsColl->EnableWindow( FALSE );
  146. pCheckNoHullColl->EnableWindow( FALSE );
  147. pCheckNoRayColl->EnableWindow( FALSE );
  148. // if there aren't any faces selected then the only active item should be selection
  149. if( !bHasFace )
  150. return;
  151. //
  152. // if not all selected faces are displacements then highlight only
  153. // SELECTION, CREATE, DESTROY, and SEW
  154. //
  155. if ( m_bIsEditable )
  156. {
  157. if( !bAllDisps )
  158. {
  159. pbuttonCreate->EnableWindow( TRUE );
  160. pbuttonDestroy->EnableWindow( TRUE );
  161. pbuttonSew->EnableWindow( TRUE );
  162. }
  163. // highlight all tool buttons, but CREATE
  164. else
  165. {
  166. pbuttonDestroy->EnableWindow( TRUE );
  167. pbuttonPaintGeo->EnableWindow( TRUE );
  168. pbuttonPaintSculpt->EnableWindow( TRUE );
  169. pbuttonPaintData->EnableWindow( TRUE );
  170. pbuttonSubdiv->EnableWindow( TRUE );
  171. pbuttonSew->EnableWindow( TRUE );
  172. pbuttonNoise->EnableWindow( TRUE );
  173. }
  174. // active attributes if in selection mode
  175. if( m_uiTool == FACEEDITTOOL_SELECT )
  176. {
  177. peditPower->EnableWindow( TRUE );
  178. pspinPower->EnableWindow( TRUE );
  179. peditElevation->EnableWindow( TRUE );
  180. pspinElevation->EnableWindow( TRUE );
  181. peditScale->EnableWindow( TRUE );
  182. pbuttonApply->EnableWindow( TRUE );
  183. pbuttonInvertAlpha->EnableWindow( TRUE );
  184. pCheckNoPhysicsColl->EnableWindow( TRUE );
  185. pCheckNoHullColl->EnableWindow( TRUE );
  186. pCheckNoRayColl->EnableWindow( TRUE );
  187. }
  188. }
  189. }
  190. //-----------------------------------------------------------------------------
  191. //-----------------------------------------------------------------------------
  192. void CFaceEditDispPage::FillEditControls( bool bAllDisps )
  193. {
  194. CString strText;
  195. //
  196. // if all selected face have displacements
  197. //
  198. if( bAllDisps )
  199. {
  200. int power = 0;
  201. bool bAllPower = true;
  202. float elevation = 0.0f;
  203. bool bAllElevation = true;
  204. float scale = 1.0f;
  205. bool bAllScale = true;
  206. bool bAllNoPhysics = true;
  207. bool bAllNoHull = true;
  208. bool bAllNoRay = true;
  209. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  210. if( pSheet )
  211. {
  212. int faceCount = pSheet->GetFaceListCount();
  213. if( faceCount > 0 )
  214. {
  215. CMapFace *pFace = pSheet->GetFaceListDataFace( 0 );
  216. EditDispHandle_t handle = pFace->GetDisp();
  217. CMapDisp *pDisp = EditDispMgr()->GetDisp( handle );
  218. power = pDisp->GetPower();
  219. elevation = pDisp->GetElevation();
  220. scale = pDisp->GetScale();
  221. }
  222. //
  223. // test all faces for "equal" attributes
  224. //
  225. for( int faceIndex = 0; faceIndex < faceCount; faceIndex++ )
  226. {
  227. CMapFace *pFace = pSheet->GetFaceListDataFace( faceIndex );
  228. EditDispHandle_t handle = pFace->GetDisp();
  229. CMapDisp *pDisp = EditDispMgr()->GetDisp( handle );
  230. // test power, elevation, and scale
  231. if( power != pDisp->GetPower() ) { bAllPower = false; }
  232. if( elevation != pDisp->GetElevation() ) { bAllElevation = false; }
  233. if( scale != pDisp->GetScale() ) { bAllScale = false; }
  234. if ( !pDisp->CheckFlags( CCoreDispInfo::SURF_NOPHYSICS_COLL ) ) { bAllNoPhysics = false; }
  235. if ( !pDisp->CheckFlags( CCoreDispInfo::SURF_NOHULL_COLL ) ) { bAllNoHull = false; }
  236. if ( !pDisp->CheckFlags( CCoreDispInfo::SURF_NORAY_COLL ) ) { bAllNoRay = false; }
  237. }
  238. // set displacement power value to 3 - 9x9
  239. SetDlgItemText( ID_DISP_POWER, "" );
  240. if( bAllPower )
  241. {
  242. SetDlgItemInt( ID_DISP_POWER, power );
  243. }
  244. // set elevation value
  245. SetDlgItemText( ID_DISP_ELEVATION, "" );
  246. if( bAllElevation )
  247. {
  248. strText.Format( "%4.2f", elevation );
  249. SetDlgItemText( ID_DISP_ELEVATION, strText );
  250. }
  251. // set scale value
  252. SetDlgItemText( ID_DISP_SCALE, "" );
  253. if( bAllScale )
  254. {
  255. strText.Format( "%4.4f", scale );
  256. SetDlgItemText( ID_DISP_SCALE, strText );
  257. }
  258. CButton *pCheckBox;
  259. pCheckBox = ( CButton* )GetDlgItem( ID_DISP_NOPHYSICS_COLL );
  260. pCheckBox->SetCheck( FALSE );
  261. if ( bAllNoPhysics )
  262. {
  263. pCheckBox->SetCheck( TRUE );
  264. }
  265. pCheckBox = ( CButton* )GetDlgItem( ID_DISP_NOHULL_COLL );
  266. pCheckBox->SetCheck( FALSE );
  267. if ( bAllNoHull )
  268. {
  269. pCheckBox->SetCheck( TRUE );
  270. }
  271. pCheckBox = ( CButton* )GetDlgItem( ID_DISP_NORAY_COLL );
  272. pCheckBox->SetCheck( FALSE );
  273. if ( bAllNoRay )
  274. {
  275. pCheckBox->SetCheck( TRUE );
  276. }
  277. }
  278. }
  279. else
  280. {
  281. // set initial displacement power value to 3 - 9x9
  282. CSpinButtonCtrl *pSpin = ( CSpinButtonCtrl* )GetDlgItem( ID_SPIN_DISP_POWER );
  283. pSpin->SetPos( 0 );
  284. SetDlgItemInt( ID_DISP_POWER, 0 );
  285. // set initial elevation value
  286. pSpin = ( CSpinButtonCtrl* )GetDlgItem( ID_SPIN_DISP_ELEVATION );
  287. pSpin->SetPos( 0 );
  288. SetDlgItemText( ID_DISP_ELEVATION, "" );
  289. // set initial scale value
  290. SetDlgItemText( ID_DISP_SCALE, "" );
  291. }
  292. //
  293. // get tool specific data for page
  294. //
  295. CToolDisplace *pDispTool = GetDisplacementTool();
  296. if( pDispTool )
  297. {
  298. CButton *checkBox;
  299. checkBox = ( CButton* )GetDlgItem( ID_DISP_MASK_SELECT );
  300. checkBox->SetCheck( pDispTool->HasSelectMask() );
  301. checkBox = ( CButton* )GetDlgItem( ID_DISP_MASK_GRID );
  302. checkBox->SetCheck( pDispTool->HasGridMask() );
  303. }
  304. }
  305. //-----------------------------------------------------------------------------
  306. //-----------------------------------------------------------------------------
  307. void CFaceEditDispPage::UpdateDialogData( void )
  308. {
  309. bool bAllDisps = false;
  310. bool bHasFace = false;
  311. //
  312. // get face and displacement info
  313. //
  314. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  315. if( pSheet )
  316. {
  317. int faceCount = pSheet->GetFaceListCount();
  318. if( faceCount > 0 )
  319. {
  320. bHasFace = true;
  321. bAllDisps = true;
  322. }
  323. for( int i = 0; i < faceCount; i++ )
  324. {
  325. CMapFace *pFace = pSheet->GetFaceListDataFace( i );
  326. if( !pFace->HasDisp() )
  327. {
  328. bAllDisps = false;
  329. }
  330. }
  331. }
  332. // fill in edit controls
  333. FillEditControls( bAllDisps );
  334. // update the edit controls
  335. UpdateEditControls( bAllDisps, bHasFace );
  336. }
  337. //-----------------------------------------------------------------------------
  338. //-----------------------------------------------------------------------------
  339. void CFaceEditDispPage::UpdatePaintDialogs( void )
  340. {
  341. m_PaintDistDlg.UpdateSpatialData();
  342. }
  343. //-----------------------------------------------------------------------------
  344. //-----------------------------------------------------------------------------
  345. void CFaceEditDispPage::OnCheckMaskSelect( void )
  346. {
  347. // get the displacement tool
  348. CToolDisplace *pDispTool = GetDisplacementTool();
  349. if( pDispTool )
  350. {
  351. pDispTool->ToggleSelectMask();
  352. }
  353. }
  354. //-----------------------------------------------------------------------------
  355. //-----------------------------------------------------------------------------
  356. void CFaceEditDispPage::OnCheckMaskGrid( void )
  357. {
  358. // get the displacement tool
  359. CToolDisplace *pDispTool = GetDisplacementTool();
  360. if( pDispTool )
  361. {
  362. pDispTool->ToggleGridMask();
  363. }
  364. }
  365. //-----------------------------------------------------------------------------
  366. //-----------------------------------------------------------------------------
  367. void CFaceEditDispPage::OnCheckNoPhysicsCollide( void )
  368. {
  369. // Toggle marked faces as collidable.
  370. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  371. if( pSheet )
  372. {
  373. // Check for a face list.
  374. int nFaceCount = pSheet->GetFaceListCount();
  375. if( nFaceCount == 0 )
  376. return;
  377. // Are we setting or reseting the collision flag?
  378. CButton *pCheckNoCollide = ( CButton* )GetDlgItem( ID_DISP_NOPHYSICS_COLL );
  379. bool bReset = false;
  380. if ( !pCheckNoCollide->GetCheck() )
  381. {
  382. bReset = true;
  383. }
  384. // Get faces with displacements and toggle the collide flag.
  385. int iFace = 0;
  386. for( iFace = 0; iFace < nFaceCount; iFace++ )
  387. {
  388. CMapFace *pFace = pSheet->GetFaceListDataFace( iFace );
  389. if( !pFace || !pFace->HasDisp() )
  390. continue;
  391. EditDispHandle_t hDisp = pFace->GetDisp();
  392. CMapDisp *pDisp = EditDispMgr()->GetDisp( hDisp );
  393. if( pDisp )
  394. {
  395. if ( bReset )
  396. {
  397. int nFlags = pDisp->GetFlags();
  398. nFlags &= ~CCoreDispInfo::SURF_NOPHYSICS_COLL;
  399. pDisp->SetFlags( nFlags );
  400. }
  401. else
  402. {
  403. int nFlags = pDisp->GetFlags();
  404. nFlags |= CCoreDispInfo::SURF_NOPHYSICS_COLL;
  405. pDisp->SetFlags( nFlags );
  406. }
  407. }
  408. }
  409. }
  410. }
  411. //-----------------------------------------------------------------------------
  412. //-----------------------------------------------------------------------------
  413. void CFaceEditDispPage::OnCheckNoHullCollide( void )
  414. {
  415. // Toggle marked faces as collidable.
  416. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  417. if( pSheet )
  418. {
  419. // Check for a face list.
  420. int nFaceCount = pSheet->GetFaceListCount();
  421. if( nFaceCount == 0 )
  422. return;
  423. // Are we setting or reseting the collision flag?
  424. CButton *pCheckNoCollide = ( CButton* )GetDlgItem( ID_DISP_NOHULL_COLL );
  425. bool bReset = false;
  426. if ( !pCheckNoCollide->GetCheck() )
  427. {
  428. bReset = true;
  429. }
  430. // Get faces with displacements and toggle the collide flag.
  431. int iFace = 0;
  432. for( iFace = 0; iFace < nFaceCount; iFace++ )
  433. {
  434. CMapFace *pFace = pSheet->GetFaceListDataFace( iFace );
  435. if( !pFace || !pFace->HasDisp() )
  436. continue;
  437. EditDispHandle_t hDisp = pFace->GetDisp();
  438. CMapDisp *pDisp = EditDispMgr()->GetDisp( hDisp );
  439. if( pDisp )
  440. {
  441. if ( bReset )
  442. {
  443. int nFlags = pDisp->GetFlags();
  444. nFlags &= ~CCoreDispInfo::SURF_NOHULL_COLL;
  445. pDisp->SetFlags( nFlags );
  446. }
  447. else
  448. {
  449. int nFlags = pDisp->GetFlags();
  450. nFlags |= CCoreDispInfo::SURF_NOHULL_COLL;
  451. pDisp->SetFlags( nFlags );
  452. }
  453. }
  454. }
  455. }
  456. }
  457. //-----------------------------------------------------------------------------
  458. //-----------------------------------------------------------------------------
  459. void CFaceEditDispPage::OnCheckNoRayCollide( void )
  460. {
  461. // Toggle marked faces as collidable.
  462. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  463. if( pSheet )
  464. {
  465. // Check for a face list.
  466. int nFaceCount = pSheet->GetFaceListCount();
  467. if( nFaceCount == 0 )
  468. return;
  469. // Are we setting or reseting the collision flag?
  470. CButton *pCheckNoCollide = ( CButton* )GetDlgItem( ID_DISP_NORAY_COLL );
  471. bool bReset = false;
  472. if ( !pCheckNoCollide->GetCheck() )
  473. {
  474. bReset = true;
  475. }
  476. // Get faces with displacements and toggle the collide flag.
  477. int iFace = 0;
  478. for( iFace = 0; iFace < nFaceCount; iFace++ )
  479. {
  480. CMapFace *pFace = pSheet->GetFaceListDataFace( iFace );
  481. if( !pFace || !pFace->HasDisp() )
  482. continue;
  483. EditDispHandle_t hDisp = pFace->GetDisp();
  484. CMapDisp *pDisp = EditDispMgr()->GetDisp( hDisp );
  485. if( pDisp )
  486. {
  487. if ( bReset )
  488. {
  489. int nFlags = pDisp->GetFlags();
  490. nFlags &= ~CCoreDispInfo::SURF_NORAY_COLL;
  491. pDisp->SetFlags( nFlags );
  492. }
  493. else
  494. {
  495. int nFlags = pDisp->GetFlags();
  496. nFlags |= CCoreDispInfo::SURF_NORAY_COLL;
  497. pDisp->SetFlags( nFlags );
  498. }
  499. }
  500. }
  501. }
  502. }
  503. //-----------------------------------------------------------------------------
  504. //-----------------------------------------------------------------------------
  505. void CFaceEditDispPage::SetTool( unsigned int tool )
  506. {
  507. if( m_uiTool == FACEEDITTOOL_PAINTGEO )
  508. {
  509. m_PaintDistDlg.DestroyWindow();
  510. }
  511. if( m_uiTool == FACEEDITTOOL_PAINTSCULPT )
  512. {
  513. m_PaintSculptDlg.DestroyWindow();
  514. }
  515. if( m_uiTool == FACEEDITTOOL_PAINTDATA )
  516. {
  517. m_PaintDataDlg.DestroyWindow();
  518. }
  519. if ( m_uiTool == FACEEDITTOOL_TAG_WALK )
  520. {
  521. ResetForceShows();
  522. }
  523. if ( m_uiTool == FACEEDITTOOL_TAG_BUILD )
  524. {
  525. ResetForceShows();
  526. }
  527. m_uiTool = tool;
  528. // set button checked
  529. CButton *pbuttonSelect = ( CButton* )GetDlgItem( ID_DISP_SELECT2 );
  530. CButton *pbuttonCreate = ( CButton* )GetDlgItem( ID_DISP_CREATE );
  531. CButton *pbuttonDestroy = ( CButton* )GetDlgItem( ID_DISP_DESTROY );
  532. CButton *pbuttonPaintGeo = ( CButton* )GetDlgItem( ID_DISP_PAINT_GEO );
  533. CButton *pbuttonPaintSculpt = ( CButton* )GetDlgItem( ID_DISP_SCULPT_PAINT );
  534. CButton *pbuttonPaintData = ( CButton* )GetDlgItem( ID_DISP_PAINT_DATA );
  535. CButton *pbuttonSubdiv = ( CButton* )GetDlgItem( ID_DISP_SUBDIVIDE );
  536. CButton *pbuttonSew = ( CButton* )GetDlgItem( ID_DISP_SEW );
  537. CButton *pbuttonNoise = ( CButton* )GetDlgItem( ID_DISP_NOISE );
  538. CButton *pButtonWalk = ( CButton* )GetDlgItem( ID_DISP_TAG_WALK );
  539. CButton *pButtonBuild = ( CButton* )GetDlgItem( ID_DISP_TAG_BUILD );
  540. pbuttonSelect->SetCheck( m_uiTool == FACEEDITTOOL_SELECT );
  541. pbuttonCreate->SetCheck( m_uiTool == FACEEDITTOOL_CREATE );
  542. pbuttonDestroy->SetCheck( m_uiTool == FACEEDITTOOL_DESTROY );
  543. pbuttonPaintGeo->SetCheck( m_uiTool == FACEEDITTOOL_PAINTGEO );
  544. pbuttonPaintSculpt->SetCheck( m_uiTool == FACEEDITTOOL_PAINTSCULPT );
  545. pbuttonPaintData->SetCheck( m_uiTool == FACEEDITTOOL_PAINTDATA );
  546. pbuttonSubdiv->SetCheck( m_uiTool == FACEEDITTOOL_SUBDIV );
  547. pbuttonSew->SetCheck( m_uiTool == FACEEDITTOOL_SEW );
  548. pbuttonNoise->SetCheck( m_uiTool == FACEEDITTOOL_NOISE );
  549. pButtonWalk->SetCheck( m_uiTool == FACEEDITTOOL_TAG_WALK );
  550. pButtonBuild->SetCheck( m_uiTool == FACEEDITTOOL_TAG_BUILD );
  551. // Update button state, etc.
  552. UpdateDialogData();
  553. }
  554. //-----------------------------------------------------------------------------
  555. //-----------------------------------------------------------------------------
  556. void CFaceEditDispPage::OnButtonSelect( void )
  557. {
  558. // set selection tool
  559. SetTool( FACEEDITTOOL_SELECT );
  560. // get the displacement tool and set selection tool active
  561. CToolDisplace *pDispTool = GetDisplacementTool();
  562. if( pDispTool )
  563. {
  564. pDispTool->SetTool( DISPTOOL_SELECT );
  565. UpdateDialogData();
  566. }
  567. }
  568. //-----------------------------------------------------------------------------
  569. //-----------------------------------------------------------------------------
  570. void CFaceEditDispPage::OnButtonCreate( void )
  571. {
  572. // set creation tool
  573. SetTool( FACEEDITTOOL_CREATE );
  574. //
  575. // "create" all selected faces
  576. //
  577. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  578. if( pSheet )
  579. {
  580. // check for faces to create
  581. int faceCount = pSheet->GetFaceListCount();
  582. if( faceCount == 0 )
  583. return;
  584. //
  585. // open the dialog and get the desired creation power
  586. //
  587. if( m_CreateDlg.DoModal() == IDCANCEL )
  588. {
  589. // reset selection tool
  590. SetTool( FACEEDITTOOL_SELECT );
  591. return;
  592. }
  593. // clamped the "power" (range [2..4])
  594. int power = m_CreateDlg.m_Power;
  595. //
  596. // get the active map doc and displacement manager
  597. //
  598. IWorldEditDispMgr *pDispMgr = GetActiveWorldEditDispManager();
  599. if( !pDispMgr )
  600. return;
  601. //
  602. // create faces
  603. //
  604. for( int ndxFace = 0; ndxFace < faceCount; ndxFace++ )
  605. {
  606. CMapFace *pFace = pSheet->GetFaceListDataFace( ndxFace );
  607. if( !pFace )
  608. continue;
  609. // make sure the face has the appropriate point count
  610. if( pFace->GetPointCount() != 4 )
  611. continue;
  612. // check to see if the face already has a displacement,
  613. // ignore it if so
  614. if( pFace->HasDisp() )
  615. continue;
  616. EditDispHandle_t dispHandle = EditDispMgr()->Create();
  617. CMapDisp *pDisp = EditDispMgr()->GetDisp( dispHandle );
  618. if( pDisp )
  619. {
  620. // set dependencies
  621. pFace->SetDisp( dispHandle );
  622. pDisp->SetParent( pFace );
  623. // get surface data
  624. pDisp->InitDispSurfaceData( pFace, true );
  625. // add displacement to world list (this should be done automatically!)
  626. pDispMgr->AddToWorld( dispHandle );
  627. // create a new displacement surface based on data
  628. pDisp->InitData( power );
  629. pDisp->Create();
  630. // Post a change to the solid.
  631. CMapSolid *pSolid = ( CMapSolid* )pFace->GetParent();
  632. pSolid->PostUpdate( Notify_Changed );
  633. // Update autovisgroups for the solid
  634. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  635. pDoc->RemoveFromAutoVisGroups( pSolid );
  636. pDoc->AddToAutoVisGroup( pSolid );
  637. }
  638. }
  639. }
  640. // reset selection tool
  641. SetTool( FACEEDITTOOL_SELECT );
  642. // update
  643. PostToolUpdate();
  644. }
  645. //-----------------------------------------------------------------------------
  646. //-----------------------------------------------------------------------------
  647. void CFaceEditDispPage::OnButtonDestroy( void )
  648. {
  649. // set destruction tool
  650. SetTool( FACEEDITTOOL_DESTROY );
  651. //
  652. // "destroy" all selected faces
  653. //
  654. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  655. if( pSheet )
  656. {
  657. // check for faces to destroy
  658. int faceCount = pSheet->GetFaceListCount();
  659. if( faceCount == 0 )
  660. return;
  661. // get the displacement manager
  662. IWorldEditDispMgr *pDispMgr = GetActiveWorldEditDispManager();
  663. if( !pDispMgr )
  664. return;
  665. // mark history position
  666. pDispMgr->PreUndo( "Displacement Destroy" );
  667. for( int ndxFace = 0; ndxFace < faceCount; ndxFace++ )
  668. {
  669. // get the current displacement
  670. // get current displacement
  671. CMapFace *pFace = pSheet->GetFaceListDataFace( ndxFace );
  672. if( !pFace || !pFace->HasDisp() )
  673. continue;
  674. CMapSolid *pSolid = ( CMapSolid* )pFace->GetParent();
  675. if ( pSolid && !pSolid->IsVisible() )
  676. continue;
  677. EditDispHandle_t handle = pFace->GetDisp();
  678. // setup for undo
  679. pDispMgr->Undo( handle, false );
  680. pDispMgr->RemoveFromWorld( handle );
  681. pFace->SetDisp( EDITDISPHANDLE_INVALID );
  682. // Post a change to the solid.
  683. pSolid->PostUpdate( Notify_Changed );
  684. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  685. pDoc->RemoveFromAutoVisGroups( pSolid );
  686. pDoc->AddToAutoVisGroup( pSolid );
  687. }
  688. pDispMgr->PostUndo();
  689. }
  690. // reset selection tool
  691. SetTool( FACEEDITTOOL_SELECT );
  692. // update
  693. PostToolUpdate();
  694. }
  695. //-----------------------------------------------------------------------------
  696. //-----------------------------------------------------------------------------
  697. void CFaceEditDispPage::OnButtonNoise( void )
  698. {
  699. // set noise tool
  700. SetTool( FACEEDITTOOL_NOISE );
  701. //
  702. // "noise" all selected faces
  703. //
  704. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  705. if( pSheet )
  706. {
  707. // check for faces to add noise to
  708. int faceCount = pSheet->GetFaceListCount();
  709. if( faceCount == 0 )
  710. return;
  711. //
  712. // open the dialog and get the desired noise parameters
  713. //
  714. if( m_NoiseDlg.DoModal() == IDCANCEL )
  715. {
  716. // reset selection tool
  717. SetTool( FACEEDITTOOL_SELECT );
  718. return;
  719. }
  720. // mark for undo
  721. // get the displacement manager
  722. IWorldEditDispMgr *pDispMgr = GetActiveWorldEditDispManager();
  723. if( !pDispMgr )
  724. return;
  725. pDispMgr->PreUndo( "Displacement Noise" );
  726. for( int ndxFace = 0; ndxFace < faceCount; ndxFace++ )
  727. {
  728. // get current displacement
  729. CMapFace *pFace = pSheet->GetFaceListDataFace( ndxFace );
  730. if( pFace )
  731. {
  732. if( pFace->HasDisp() )
  733. {
  734. EditDispHandle_t handle = pFace->GetDisp();
  735. // setup for undo
  736. pDispMgr->Undo( handle, false );
  737. CMapDisp *pDisp = EditDispMgr()->GetDisp( handle );
  738. pDisp->ApplyNoise( m_NoiseDlg.m_Min, m_NoiseDlg.m_Max, 1.0f );
  739. }
  740. }
  741. }
  742. pDispMgr->PostUndo();
  743. }
  744. // reset selection tool
  745. SetTool( FACEEDITTOOL_SELECT );
  746. // update
  747. PostToolUpdate();
  748. }
  749. //-----------------------------------------------------------------------------
  750. //-----------------------------------------------------------------------------
  751. void CFaceEditDispPage::OnButtonSubdivide( void )
  752. {
  753. // set subdivision tool
  754. SetTool( FACEEDITTOOL_SUBDIV );
  755. //
  756. // create selection list
  757. //
  758. IWorldEditDispMgr *pDispMgr = GetActiveWorldEditDispManager();
  759. if( !pDispMgr )
  760. return;
  761. pDispMgr->SelectClear();
  762. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  763. if( pSheet )
  764. {
  765. // check for faces to subdivide
  766. int faceCount = pSheet->GetFaceListCount();
  767. if( faceCount == 0 )
  768. return;
  769. for( int ndxFace = 0; ndxFace < faceCount; ndxFace++ )
  770. {
  771. // get current displacement
  772. CMapFace *pFace = pSheet->GetFaceListDataFace( ndxFace );
  773. if( pFace )
  774. {
  775. if( pFace->HasDisp() )
  776. {
  777. EditDispHandle_t handle = pFace->GetDisp();
  778. pDispMgr->AddToSelect( handle );
  779. CMapDisp *pDisp = EditDispMgr()->GetDisp( handle );
  780. pDisp->ResetTexelHitIndex();
  781. }
  782. }
  783. }
  784. }
  785. // subdivide
  786. pDispMgr->CatmullClarkSubdivide();
  787. // reset selection tool
  788. SetTool( FACEEDITTOOL_SELECT );
  789. // update
  790. PostToolUpdate();
  791. }
  792. //-----------------------------------------------------------------------------
  793. //-----------------------------------------------------------------------------
  794. void CFaceEditDispPage::OnButtonSew( void )
  795. {
  796. // set sew tool
  797. SetTool( FACEEDITTOOL_SEW );
  798. //
  799. // "sew" all selected faces
  800. //
  801. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  802. if( pSheet )
  803. {
  804. // check for faces to sew
  805. int faceCount = pSheet->GetFaceListCount();
  806. if( faceCount == 0 )
  807. return;
  808. // get the displacement manager
  809. IWorldEditDispMgr *pDispMgr = GetActiveWorldEditDispManager();
  810. if( !pDispMgr )
  811. return;
  812. // mark history position
  813. pDispMgr->PreUndo( "Displacement Sewing" );
  814. for( int ndxFace = 0; ndxFace < faceCount; ndxFace++ )
  815. {
  816. // get the current displacement
  817. // get current displacement
  818. CMapFace *pFace = pSheet->GetFaceListDataFace( ndxFace );
  819. if( pFace )
  820. {
  821. if( pFace->HasDisp() )
  822. {
  823. EditDispHandle_t handle = pFace->GetDisp();
  824. // setup for undo
  825. pDispMgr->Undo( handle, false );
  826. }
  827. }
  828. }
  829. pDispMgr->PostUndo();
  830. // sew faces
  831. FaceListSewEdges();
  832. // update the parents - force a rebuild
  833. for( int ndxFace = 0; ndxFace < faceCount; ndxFace++ )
  834. {
  835. // get current displacement
  836. CMapFace *pFace = pSheet->GetFaceListDataFace( ndxFace );
  837. if( pFace )
  838. {
  839. if( pFace->HasDisp() )
  840. {
  841. CMapSolid *pSolid = ( CMapSolid* )pFace->GetParent();
  842. pSolid->PostUpdate( Notify_Rebuild );
  843. }
  844. }
  845. }
  846. }
  847. // reset selection tool
  848. SetTool( FACEEDITTOOL_SELECT );
  849. // update
  850. PostToolUpdate();
  851. }
  852. //-----------------------------------------------------------------------------
  853. //-----------------------------------------------------------------------------
  854. void CFaceEditDispPage::OnButtonPaintGeo( void )
  855. {
  856. // set selection tool
  857. SetTool( FACEEDITTOOL_PAINTGEO );
  858. // get the displacement tool and set the paint tool active
  859. CToolDisplace *pDispTool = GetDisplacementTool();
  860. if( pDispTool )
  861. {
  862. pDispTool->SetTool( DISPTOOL_PAINT );
  863. UpdateDialogData();
  864. }
  865. if( !m_PaintDistDlg.Create( IDD_DISP_PAINT_DIST, this ) )
  866. return;
  867. m_PaintDistDlg.ShowWindow( SW_SHOW );
  868. }
  869. //-----------------------------------------------------------------------------
  870. // Purpose: handles the user clicking on the sculpt button
  871. //-----------------------------------------------------------------------------
  872. void CFaceEditDispPage::OnBnClickedDispSculptPaint( )
  873. {
  874. // set selection tool
  875. SetTool( FACEEDITTOOL_PAINTSCULPT );
  876. // get the displacement tool and set the paint tool active
  877. CToolDisplace *pDispTool = GetDisplacementTool();
  878. if( pDispTool )
  879. {
  880. pDispTool->SetTool( DISPTOOL_PAINT_SCULPT );
  881. UpdateDialogData();
  882. }
  883. if( !m_PaintSculptDlg.Create( IDD_DISP_PAINT_SCULPT, this ) )
  884. return;
  885. m_PaintSculptDlg.ShowWindow( SW_SHOW );
  886. }
  887. //-----------------------------------------------------------------------------
  888. //-----------------------------------------------------------------------------
  889. void CFaceEditDispPage::OnButtonPaintData( void )
  890. {
  891. // set selection tool
  892. SetTool( FACEEDITTOOL_PAINTDATA );
  893. // get the displacement tool and set the paint tool active
  894. CToolDisplace *pDispTool = GetDisplacementTool();
  895. if( pDispTool )
  896. {
  897. pDispTool->SetTool( DISPTOOL_PAINT );
  898. UpdateDialogData();
  899. }
  900. if( !m_PaintDataDlg.Create( IDD_DISP_PAINT_DATA, this ) )
  901. return;
  902. m_PaintDataDlg.ShowWindow( SW_SHOW );
  903. }
  904. //-----------------------------------------------------------------------------
  905. //-----------------------------------------------------------------------------
  906. void CFaceEditDispPage::OnButtonTagWalkable( void )
  907. {
  908. // Set walkalbe faces viewable -- if they are not already.
  909. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  910. if ( !pDoc )
  911. return;
  912. CToolDisplace *pDispTool = GetDisplacementTool();
  913. if( !pDispTool )
  914. return;
  915. // Toggle the functionality.
  916. if ( GetTool() == FACEEDITTOOL_TAG_WALK )
  917. {
  918. // Set the select tool.
  919. SetTool( FACEEDITTOOL_SELECT );
  920. pDispTool->SetTool( DISPTOOL_SELECT_DISP_FACE );
  921. if ( m_bForceShowWalkable )
  922. {
  923. pDoc->SetDispDrawWalkable( false );
  924. m_bForceShowWalkable = false;
  925. }
  926. }
  927. else
  928. {
  929. // Set the tag walkable tool.
  930. SetTool( FACEEDITTOOL_TAG_WALK );
  931. pDispTool->SetTool( DISPTOOL_TAG_WALKABLE );
  932. if ( !pDoc->IsDispDrawWalkable() )
  933. {
  934. pDoc->SetDispDrawWalkable( true );
  935. m_bForceShowWalkable = true;
  936. }
  937. }
  938. UpdateDialogData();
  939. }
  940. //-----------------------------------------------------------------------------
  941. //-----------------------------------------------------------------------------
  942. void CFaceEditDispPage::OnButtonTagBuildable( void )
  943. {
  944. // Set buildalbe faces viewable -- if they are not already.
  945. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  946. if ( !pDoc )
  947. return;
  948. CToolDisplace *pDispTool = GetDisplacementTool();
  949. if( !pDispTool )
  950. return;
  951. // Toggle the functionality.
  952. if ( GetTool() == FACEEDITTOOL_TAG_BUILD )
  953. {
  954. // Set the select tool.
  955. SetTool( FACEEDITTOOL_SELECT );
  956. pDispTool->SetTool( DISPTOOL_SELECT_DISP_FACE );
  957. if ( m_bForceShowBuildable )
  958. {
  959. pDoc->SetDispDrawBuildable( false );
  960. m_bForceShowBuildable = false;
  961. }
  962. }
  963. else
  964. {
  965. // Set the tag walkable tool.
  966. SetTool( FACEEDITTOOL_TAG_BUILD );
  967. pDispTool->SetTool( DISPTOOL_TAG_BUILDABLE );
  968. if ( !pDoc->IsDispDrawBuildable() )
  969. {
  970. pDoc->SetDispDrawBuildable( true );
  971. m_bForceShowBuildable = true;
  972. }
  973. }
  974. UpdateDialogData();
  975. }
  976. //-----------------------------------------------------------------------------
  977. // Purpose:
  978. //-----------------------------------------------------------------------------
  979. void CFaceEditDispPage::OnButtonInvertAlpha( void )
  980. {
  981. // Invert the alpha channel on all the selected displacements.
  982. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  983. if( pSheet )
  984. {
  985. int nFaceCount = pSheet->GetFaceListCount();
  986. for( int iFace = 0; iFace < nFaceCount; ++iFace )
  987. {
  988. CMapFace *pFace = pSheet->GetFaceListDataFace( iFace );
  989. if( pFace )
  990. {
  991. if( pFace->HasDisp() )
  992. {
  993. EditDispHandle_t handle = pFace->GetDisp();
  994. CMapDisp *pDisp = EditDispMgr()->GetDisp( handle );
  995. pDisp->InvertAlpha();
  996. }
  997. }
  998. }
  999. }
  1000. // Update
  1001. PostToolUpdate();
  1002. }
  1003. //-----------------------------------------------------------------------------
  1004. // Purpose: Select any displacement faces adjacent to the already-selected ones.
  1005. //-----------------------------------------------------------------------------
  1006. void CFaceEditDispPage::OnSelectAdjacent()
  1007. {
  1008. IWorldEditDispMgr *pDispMgr = GetActiveWorldEditDispManager();
  1009. bool bSelectedAny = false;
  1010. // For all selected displacements...
  1011. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  1012. if( !pSheet )
  1013. return;
  1014. // check for faces
  1015. int faceCount = pSheet->GetFaceListCount();
  1016. if( faceCount == 0 )
  1017. return;
  1018. for( int ndxFace = 0; ndxFace < faceCount; ndxFace++ )
  1019. {
  1020. // get current displacement
  1021. CMapFace *pFace = pSheet->GetFaceListDataFace( ndxFace );
  1022. if( !pFace || !pFace->HasDisp() )
  1023. continue;
  1024. EditDispHandle_t handle = pFace->GetDisp();
  1025. CMapDisp *pDisp = EditDispMgr()->GetDisp( handle );
  1026. // Now test all other disps in the world. We could do the code commented below, but then
  1027. // we won't be selecting adjacent neighbors of a different power.
  1028. //
  1029. //for ( int iEdge=0; iEdge < 4; iEdge++ )
  1030. //{
  1031. // EditDispHandle_t hNeighbor = pDisp->GetEdgeNeighbor( iEdge );
  1032. int totalDispCount = pDispMgr->WorldCount();
  1033. for ( int iTestDisp=0; iTestDisp < totalDispCount; iTestDisp++ )
  1034. {
  1035. int edge1[4], edge2[4];
  1036. CMapDisp *pNeighbor = pDispMgr->GetFromWorld( iTestDisp );
  1037. if ( !pNeighbor || pNeighbor == pDisp || pDispMgr->NumSharedPoints( pDisp, pNeighbor, edge1, edge2 ) != 2 )
  1038. continue;
  1039. // Get its map face and solid.
  1040. CMapFace *pFace = dynamic_cast< CMapFace* >( pNeighbor->GetParent() );
  1041. if ( !pFace || pFace->GetSelectionState() != SELECT_NONE )
  1042. continue;
  1043. CMapSolid *pSolid = dynamic_cast< CMapSolid* >( pFace->GetParent() );
  1044. if ( !pSolid || !pSolid->IsVisible() )
  1045. continue;
  1046. // The function we use to select a face wants the face's index into its CMapSolid, so we need that.
  1047. int iFaceIndex = pSolid->GetFaceIndex( pFace );
  1048. if ( iFaceIndex == -1 )
  1049. continue;
  1050. // Finally, select the face.
  1051. pSheet->ClickFace( pSolid, iFaceIndex, CFaceEditSheet::cfSelect, CFaceEditSheet::ModeSelect );
  1052. bSelectedAny = true;
  1053. }
  1054. }
  1055. if ( bSelectedAny )
  1056. {
  1057. CMapDoc::GetActiveMapDoc()->UpdateAllViews( MAPVIEW_UPDATE_TOOL );
  1058. }
  1059. }
  1060. //-----------------------------------------------------------------------------
  1061. // Resample
  1062. //-----------------------------------------------------------------------------
  1063. void CFaceEditDispPage::UpdatePower( CMapDisp *pDisp )
  1064. {
  1065. // input check
  1066. if( !pDisp )
  1067. return;
  1068. //
  1069. // get the power from the power edit box
  1070. //
  1071. CString strPower;
  1072. GetDlgItemText( ID_DISP_POWER, strPower );
  1073. int power = atoi( strPower );
  1074. if( power < 2 ) { power = 2; }
  1075. if( power > 4 ) { power = 4; }
  1076. // check for a change and resample if need be
  1077. if( power != pDisp->GetPower() )
  1078. {
  1079. pDisp->Resample( power );
  1080. }
  1081. }
  1082. //-----------------------------------------------------------------------------
  1083. //-----------------------------------------------------------------------------
  1084. void CFaceEditDispPage::UpdateElevation( CMapDisp *pDisp )
  1085. {
  1086. // input check
  1087. if( !pDisp )
  1088. return;
  1089. //
  1090. // get current elevation value
  1091. //
  1092. CString strElevation;
  1093. GetDlgItemText( ID_DISP_ELEVATION, strElevation );
  1094. int elevation = atof( strElevation );
  1095. // check for change and set new elevation if need be
  1096. if( elevation != pDisp->GetElevation() )
  1097. {
  1098. pDisp->Elevate( elevation );
  1099. }
  1100. }
  1101. //-----------------------------------------------------------------------------
  1102. // Purpose:
  1103. // Input : pNMHDR -
  1104. // pResult -
  1105. //-----------------------------------------------------------------------------
  1106. void CFaceEditDispPage::OnSpinUpDown( NMHDR *pNMHDR, LRESULT *pResult )
  1107. {
  1108. //
  1109. // get scroll up down edit box
  1110. //
  1111. NM_UPDOWN *pNMUpDown = ( NM_UPDOWN* )pNMHDR;
  1112. switch( pNMUpDown->hdr.idFrom )
  1113. {
  1114. case ID_SPIN_DISP_POWER:
  1115. {
  1116. CEdit *pEdit = ( CEdit* )GetDlgItem( ID_DISP_POWER );
  1117. CString strPower;
  1118. pEdit->GetWindowText( strPower );
  1119. int power = atoi( strPower );
  1120. power += ( -pNMUpDown->iDelta );
  1121. if( power < 2 ) { power = 2; }
  1122. if( power > 4 ) { power = 4; }
  1123. strPower.Format( "%d", power );
  1124. pEdit->SetWindowText( strPower );
  1125. *pResult = 0;
  1126. break;
  1127. }
  1128. case ID_SPIN_DISP_ELEVATION:
  1129. {
  1130. CEdit *pEdit = ( CEdit* )GetDlgItem( ID_DISP_ELEVATION );
  1131. CString strElevation;
  1132. pEdit->GetWindowText( strElevation );
  1133. float elevation = atof( strElevation );
  1134. elevation += 0.5f * ( -pNMUpDown->iDelta );
  1135. strElevation.Format( "%4.2f", elevation );
  1136. pEdit->SetWindowText( strElevation );
  1137. *pResult = 0;
  1138. break;
  1139. }
  1140. }
  1141. }
  1142. //-----------------------------------------------------------------------------
  1143. //-----------------------------------------------------------------------------
  1144. void CFaceEditDispPage::UpdateScale( CMapDisp *pDisp )
  1145. {
  1146. if( !pDisp )
  1147. return;
  1148. //
  1149. // get the current scale value
  1150. //
  1151. CString strScale;
  1152. GetDlgItemText( ID_DISP_SCALE, strScale );
  1153. float scale = atof( strScale );
  1154. // check for change and set new scale if need be
  1155. if( scale != pDisp->GetScale() )
  1156. {
  1157. pDisp->Scale( scale );
  1158. }
  1159. }
  1160. //-----------------------------------------------------------------------------
  1161. //-----------------------------------------------------------------------------
  1162. void CFaceEditDispPage::OnButtonApply( void )
  1163. {
  1164. //
  1165. // "create" all selected faces
  1166. //
  1167. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  1168. if( pSheet )
  1169. {
  1170. int faceCount = pSheet->GetFaceListCount();
  1171. for( int ndxFace = 0; ndxFace < faceCount; ndxFace++ )
  1172. {
  1173. // get current face
  1174. CMapFace *pFace = pSheet->GetFaceListDataFace( ndxFace );
  1175. if( pFace )
  1176. {
  1177. if( pFace->HasDisp() )
  1178. {
  1179. EditDispHandle_t handle = pFace->GetDisp();
  1180. CMapDisp *pDisp = EditDispMgr()->GetDisp( handle );
  1181. // update attribs
  1182. UpdatePower( pDisp );
  1183. UpdateElevation( pDisp );
  1184. UpdateScale( pDisp );
  1185. }
  1186. }
  1187. }
  1188. }
  1189. // update
  1190. PostToolUpdate();
  1191. }
  1192. //-----------------------------------------------------------------------------
  1193. //-----------------------------------------------------------------------------
  1194. void CFaceEditDispPage::CloseAllDialogs( void )
  1195. {
  1196. if( m_uiTool == FACEEDITTOOL_PAINTGEO )
  1197. {
  1198. m_PaintDistDlg.DestroyWindow();
  1199. }
  1200. if( m_uiTool == FACEEDITTOOL_PAINTSCULPT )
  1201. {
  1202. m_PaintSculptDlg.DestroyWindow();
  1203. }
  1204. if( m_uiTool == FACEEDITTOOL_PAINTDATA )
  1205. {
  1206. m_PaintDataDlg.DestroyWindow();
  1207. }
  1208. }
  1209. //-----------------------------------------------------------------------------
  1210. //-----------------------------------------------------------------------------
  1211. void CFaceEditDispPage::ResetForceShows( void )
  1212. {
  1213. // Walkable
  1214. if ( m_bForceShowWalkable )
  1215. {
  1216. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  1217. if ( pDoc )
  1218. {
  1219. pDoc->SetDispDrawWalkable( false );
  1220. }
  1221. m_bForceShowWalkable = false;
  1222. }
  1223. // Buildable
  1224. if ( m_bForceShowBuildable )
  1225. {
  1226. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  1227. if ( pDoc )
  1228. {
  1229. pDoc->SetDispDrawBuildable( false );
  1230. }
  1231. m_bForceShowBuildable = false;
  1232. }
  1233. }
  1234. //-----------------------------------------------------------------------------
  1235. //-----------------------------------------------------------------------------
  1236. BOOL CFaceEditDispPage::OnSetActive( void )
  1237. {
  1238. ToolManager()->SetTool( TOOL_FACEEDIT_DISP );
  1239. // set the selection as the tool to use!!!
  1240. OnButtonSelect();
  1241. return CPropertyPage::OnSetActive();
  1242. }
  1243. //-----------------------------------------------------------------------------
  1244. //-----------------------------------------------------------------------------
  1245. BOOL CFaceEditDispPage::OnKillActive( void )
  1246. {
  1247. CloseAllDialogs();
  1248. ResetForceShows();
  1249. return TRUE;
  1250. }
  1251. //-----------------------------------------------------------------------------
  1252. //-----------------------------------------------------------------------------
  1253. BOOL CFaceEditDispPage::PreTranslateMessage( MSG *pMsg )
  1254. {
  1255. HACCEL hAccel = GetMainWnd()->GetAccelTable();
  1256. if( !(hAccel && ::TranslateAccelerator( GetMainWnd()->m_hWnd, hAccel, pMsg ) ) )
  1257. {
  1258. return CPropertyPage::PreTranslateMessage( pMsg );
  1259. }
  1260. else
  1261. {
  1262. return TRUE;
  1263. }
  1264. }