Team Fortress 2 Source Code as on 22/4/2020
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.

1880 lines
53 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include <stdafx.h>
  8. #include "hammer.h"
  9. #include "MainFrm.h"
  10. #include "FaceEditSheet.h"
  11. #include "GlobalFunctions.h"
  12. #include "DispDlg.h"
  13. #include "MapFace.h"
  14. #include "MapDisp.h"
  15. #include "ToolDisplace.h"
  16. #include "ToolManager.h"
  17. #include "SculptOptions.h"
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include <tier0/memdbgon.h>
  20. #define DISPPAINT_DISTANCE_MIN 0
  21. #define DISPPAINT_DISTANCE_MAX 60
  22. #define DISPPAINT_SPATIALRADIUS_MIN 1
  23. #define DISPPAINT_SPATIALRADIUS_MAX 1024
  24. #define DISPPAINT_SPATIALRADIUS_STEP 16
  25. //=============================================================================
  26. //
  27. // Displacement Create Dialog Functions
  28. //
  29. BEGIN_MESSAGE_MAP(CDispCreateDlg, CDialog)
  30. //{{AFX_MSG_MAP(CDispCreateDlg)
  31. ON_WM_VSCROLL()
  32. //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34. extern CToolDisplace* GetDisplacementTool();
  35. //-----------------------------------------------------------------------------
  36. // Purpose: constructor
  37. //-----------------------------------------------------------------------------
  38. CDispCreateDlg::CDispCreateDlg( CWnd *pParent ) :
  39. CDialog( CDispCreateDlg::IDD, pParent )
  40. {
  41. m_Power = 0;
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose:
  45. //-----------------------------------------------------------------------------
  46. BOOL CDispCreateDlg::OnInitDialog(void)
  47. {
  48. CDialog::OnInitDialog();
  49. // set the initial power "3"
  50. SetDlgItemInt( ID_DISP_CREATE_POWER, 3 );
  51. // setup the spinner - set range (range [2..4])
  52. m_spinPower.SetBuddy( &m_editPower );
  53. m_spinPower.SetRange( 2, 4 );
  54. m_spinPower.SetPos( 3 );
  55. return TRUE;
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose:
  59. //-----------------------------------------------------------------------------
  60. void CDispCreateDlg::DoDataExchange( CDataExchange *pDX )
  61. {
  62. CDialog::DoDataExchange( pDX );
  63. //{{AFX_DATA_MAP(CDispCreateDlg)
  64. DDX_Control( pDX, ID_DISP_CREATE_POWER_SPIN, m_spinPower );
  65. DDX_Control( pDX, ID_DISP_CREATE_POWER, m_editPower );
  66. DDX_Text( pDX, ID_DISP_CREATE_POWER, m_Power );
  67. //}}AFX_DATA_MAP
  68. // clamp the power
  69. if( m_Power < 2 ) { m_Power = 2; }
  70. if( m_Power > 4 ) { m_Power = 4; }
  71. }
  72. //-----------------------------------------------------------------------------
  73. //-----------------------------------------------------------------------------
  74. void CDispCreateDlg::OnVScroll( UINT nSBCode, UINT nPos, CScrollBar *pScrollBar )
  75. {
  76. m_spinPower.SetPos( nPos );
  77. SetDlgItemInt( ID_DISP_CREATE_POWER, nPos );
  78. }
  79. //=============================================================================
  80. //
  81. // Displacement Noise Dialog Functions
  82. //
  83. BEGIN_MESSAGE_MAP(CDispNoiseDlg, CDialog)
  84. //{{AFX_MSG_MAP(CDispNoiseDlg)
  85. ON_NOTIFY( UDN_DELTAPOS, ID_DISP_NOISE_MIN_SPIN, OnSpinUpDown )
  86. ON_NOTIFY( UDN_DELTAPOS, ID_DISP_NOISE_MAX_SPIN, OnSpinUpDown )
  87. //}}AFX_MSG_MAP
  88. END_MESSAGE_MAP()
  89. //-----------------------------------------------------------------------------
  90. // Purpose: constructor
  91. //-----------------------------------------------------------------------------
  92. CDispNoiseDlg::CDispNoiseDlg( CWnd *pParent ) :
  93. CDialog( CDispNoiseDlg::IDD, pParent )
  94. {
  95. m_Min = m_Max = 0.0f;
  96. }
  97. //-----------------------------------------------------------------------------
  98. // Purpose:
  99. //-----------------------------------------------------------------------------
  100. BOOL CDispNoiseDlg::OnInitDialog(void)
  101. {
  102. CDialog::OnInitDialog();
  103. //
  104. // set min, max initially to zero!!
  105. //
  106. CString strZero = "0.0";
  107. SetDlgItemText( ID_DISP_NOISE_MIN, strZero );
  108. SetDlgItemText( ID_DISP_NOISE_MAX, strZero );
  109. //
  110. // setup spinners
  111. //
  112. m_spinMin.SetBuddy( &m_editMin );
  113. m_spinMax.SetBuddy( &m_editMax );
  114. return TRUE;
  115. }
  116. //-----------------------------------------------------------------------------
  117. // Purpose:
  118. //-----------------------------------------------------------------------------
  119. void CDispNoiseDlg::DoDataExchange( CDataExchange *pDX )
  120. {
  121. CDialog::DoDataExchange( pDX );
  122. //{{AFX_DATA_MAP(CDispNoiseDlg)
  123. DDX_Control( pDX, ID_DISP_NOISE_MIN_SPIN, m_spinMin );
  124. DDX_Control( pDX, ID_DISP_NOISE_MAX_SPIN, m_spinMax );
  125. DDX_Control( pDX, ID_DISP_NOISE_MIN, m_editMin );
  126. DDX_Control( pDX, ID_DISP_NOISE_MAX, m_editMax );
  127. DDX_Text( pDX, ID_DISP_NOISE_MIN, m_Min );
  128. DDX_Text( pDX, ID_DISP_NOISE_MAX, m_Max );
  129. //}}AFX_DATA_MAP
  130. }
  131. //-----------------------------------------------------------------------------
  132. // Purpose:
  133. //-----------------------------------------------------------------------------
  134. void CDispNoiseDlg::OnSpinUpDown( NMHDR *pNMHDR, LRESULT *pResult )
  135. {
  136. //
  137. // get scroll up down edit box
  138. //
  139. NM_UPDOWN *pNMUpDown = ( NM_UPDOWN* )pNMHDR;
  140. switch( pNMUpDown->hdr.idFrom )
  141. {
  142. case ID_DISP_NOISE_MIN_SPIN:
  143. {
  144. CEdit *pEdit = ( CEdit* )GetDlgItem( ID_DISP_NOISE_MIN );
  145. CString strMin;
  146. pEdit->GetWindowText( strMin );
  147. m_Min = atof( strMin );
  148. m_Min += 0.5f * ( -pNMUpDown->iDelta );
  149. strMin.Format( "%4.2f", m_Min );
  150. pEdit->SetWindowText( strMin );
  151. *pResult = 0;
  152. break;
  153. }
  154. case ID_DISP_NOISE_MAX_SPIN:
  155. {
  156. CEdit *pEdit = ( CEdit* )GetDlgItem( ID_DISP_NOISE_MAX );
  157. CString strMax;
  158. pEdit->GetWindowText( strMax );
  159. m_Max = atof( strMax );
  160. m_Max += 0.5f * ( -pNMUpDown->iDelta );
  161. strMax.Format( "%4.2f", m_Max );
  162. pEdit->SetWindowText( strMax );
  163. *pResult = 0;
  164. break;
  165. }
  166. }
  167. }
  168. //=============================================================================
  169. //
  170. // Displacement Paint Distance Dialog Functions
  171. //
  172. BEGIN_MESSAGE_MAP(CDispPaintDistDlg, CDialog)
  173. //{{AFX_MSG_MAP(CDispPaintDistDlg)
  174. ON_BN_CLICKED( ID_DISP_PAINT_DIST_RAISELOWER, OnEffectRaiseLowerGeo )
  175. ON_BN_CLICKED( ID_DISP_PAINT_DIST_RAISETO, OnEffectRaiseToGeo )
  176. ON_BN_CLICKED( ID_DISP_PAINT_DIST_SMOOTH, OnEffectSmoothGeo )
  177. ON_BN_CLICKED( ID_DISPPAINT_SOFTEDGE, OnBrushTypeSoftEdge )
  178. ON_BN_CLICKED( ID_DISPPAINT_HARDEDGE, OnBrushTypeHardEdge )
  179. ON_BN_CLICKED( ID_DISP_PAINT_DIST_SPATIAL, OnCheckSpatial )
  180. ON_BN_CLICKED( ID_DISP_PAINT_DIST_AUTOSEW, OnCheckAutoSew )
  181. ON_CBN_SELCHANGE( ID_DISP_PAINT_DIST_BRUSH, OnComboBoxBrushGeo )
  182. ON_CBN_SELCHANGE( ID_DISP_PAINT_DIST_AXIS, OnComboBoxAxis )
  183. ON_WM_HSCROLL()
  184. ON_EN_CHANGE( ID_DISP_PAINT_DIST_EDIT_DISTANCE, OnEditDistance )
  185. ON_EN_CHANGE( ID_DISP_PAINT_DIST_EDIT_RADIUS, OnEditRadius )
  186. ON_WM_CLOSE()
  187. ON_WM_DESTROY()
  188. //}}AFX_MSG_MAP
  189. END_MESSAGE_MAP()
  190. //-----------------------------------------------------------------------------
  191. // Purpose: constructor
  192. //-----------------------------------------------------------------------------
  193. CDispPaintDistDlg::CDispPaintDistDlg( CWnd *pParent ) :
  194. CDialog( CDispPaintDistDlg::IDD, pParent )
  195. {
  196. }
  197. //-----------------------------------------------------------------------------
  198. // Purpose:
  199. //-----------------------------------------------------------------------------
  200. CDispPaintDistDlg::~CDispPaintDistDlg()
  201. {
  202. if ( m_comboboxBrush.m_hWnd )
  203. {
  204. m_comboboxBrush.Detach();
  205. }
  206. }
  207. //-----------------------------------------------------------------------------
  208. // Purpose:
  209. //-----------------------------------------------------------------------------
  210. BOOL CDispPaintDistDlg::OnInitDialog( void )
  211. {
  212. static bool bInit = false;
  213. CDialog::OnInitDialog();
  214. CToolDisplace *pTool = GetDisplacementTool();
  215. if ( !pTool )
  216. return FALSE;
  217. // Set spatial tool flag.
  218. if ( !pTool->IsSpatialPainting() )
  219. {
  220. pTool->ToggleSpatialPainting();
  221. }
  222. if ( !bInit )
  223. {
  224. m_flPrevDistance = 1.0f;
  225. m_flPrevRadius = 1.0f;
  226. m_nPrevBrush = 0;
  227. m_nPrevEffect = pTool->GetEffect();
  228. pTool->GetPaintAxis( m_nPrevPaintAxis, m_vecPrevPaintAxis );
  229. bInit = true;
  230. }
  231. else
  232. {
  233. SetWindowPos( &wndTop, m_DialogPosRect.left, m_DialogPosRect.top,
  234. m_DialogPosRect.Width(), m_DialogPosRect.Height(), SWP_NOZORDER );
  235. }
  236. // Initialize the combo boxes.
  237. InitComboBoxBrushGeo();
  238. InitComboBoxAxis();
  239. // Initialize the sliders.
  240. InitDistance();
  241. InitRadius();
  242. // Initialize the brush types.
  243. InitBrushType();
  244. return TRUE;
  245. }
  246. //-----------------------------------------------------------------------------
  247. //-----------------------------------------------------------------------------
  248. void CDispPaintDistDlg::InitDistance( void )
  249. {
  250. // Set the slider range and initialize the "buddy."
  251. m_sliderDistance.SetBuddy( &m_editDistance, FALSE );
  252. m_sliderDistance.SetRange( DISPPAINT_DISTANCE_MIN, DISPPAINT_DISTANCE_MAX );
  253. // Get the displacement tool.
  254. CToolDisplace *pTool = GetDisplacementTool();
  255. if ( pTool )
  256. {
  257. pTool->GetChannel( DISPPAINT_CHANNEL_POSITION, m_flPrevDistance );
  258. // Initialize the distance slider and edit box.
  259. UpdateSliderDistance( m_flPrevDistance, true );
  260. UpdateEditBoxDistance( m_flPrevDistance, true );
  261. }
  262. else
  263. {
  264. // Init distance slider and edit box.
  265. UpdateSliderDistance( 1.0f, true );
  266. UpdateEditBoxDistance( 1.0f, true );
  267. }
  268. }
  269. //-----------------------------------------------------------------------------
  270. //-----------------------------------------------------------------------------
  271. void CDispPaintDistDlg::InitRadius( void )
  272. {
  273. // Set the slider range and initialize the "buddy."
  274. m_sliderRadius.SetBuddy( &m_editRadius, FALSE );
  275. m_sliderRadius.SetRange( DISPPAINT_SPATIALRADIUS_MIN, DISPPAINT_SPATIALRADIUS_MAX );
  276. m_sliderRadius.SetTicFreq( DISPPAINT_SPATIALRADIUS_STEP );
  277. // Get the displacement tool.
  278. CToolDisplace *pTool = GetDisplacementTool();
  279. if ( pTool )
  280. {
  281. CButton *pcheckSpatial = ( CButton* )GetDlgItem( ID_DISP_PAINT_DIST_SPATIAL );
  282. if ( pTool->IsSpatialPainting() )
  283. {
  284. pcheckSpatial->SetCheck( true );
  285. EnableSliderRadius();
  286. DisablePaintingComboBoxes();
  287. }
  288. else
  289. {
  290. pcheckSpatial->SetCheck( false );
  291. DisableSliderRadius();
  292. EnablePaintingComboBoxes();
  293. }
  294. }
  295. }
  296. //-----------------------------------------------------------------------------
  297. //-----------------------------------------------------------------------------
  298. void CDispPaintDistDlg::EnableSliderRadius( void )
  299. {
  300. // Enable the radius slider and edit box.
  301. m_sliderRadius.EnableWindow( TRUE );
  302. m_editRadius.EnableWindow( TRUE );
  303. // Get the displacement tool and restore the radius.
  304. CToolDisplace *pTool = GetDisplacementTool();
  305. if ( pTool )
  306. {
  307. m_flPrevRadius = pTool->GetSpatialRadius();
  308. // Update the radius slider and edit box.
  309. UpdateSliderRadius( m_flPrevRadius, true );
  310. UpdateEditBoxRadius( m_flPrevRadius, true );
  311. }
  312. else
  313. {
  314. // Set the radius slider and edit box with default values.
  315. UpdateSliderRadius( 1.0f, true );
  316. UpdateEditBoxRadius( 1.0f, true );
  317. }
  318. }
  319. //-----------------------------------------------------------------------------
  320. //-----------------------------------------------------------------------------
  321. void CDispPaintDistDlg::DisableSliderRadius( void )
  322. {
  323. // Disable the radius slider and edit box.
  324. m_sliderRadius.EnableWindow( FALSE );
  325. m_editRadius.EnableWindow( FALSE );
  326. }
  327. //-----------------------------------------------------------------------------
  328. //-----------------------------------------------------------------------------
  329. void CDispPaintDistDlg::UpdateSpatialData( void )
  330. {
  331. // Get the displacement tool and restore the radius.
  332. CToolDisplace *pTool = GetDisplacementTool();
  333. if ( pTool )
  334. {
  335. m_flPrevRadius = pTool->GetSpatialRadius();
  336. // Update the radius slider and edit box.
  337. UpdateSliderRadius( m_flPrevRadius, true );
  338. UpdateEditBoxRadius( m_flPrevRadius, true );
  339. }
  340. }
  341. //-----------------------------------------------------------------------------
  342. //-----------------------------------------------------------------------------
  343. bool CDispPaintDistDlg::InitComboBoxBrushGeo( void )
  344. {
  345. //
  346. // get the displacement paint brush icon combo box
  347. //
  348. m_comboboxBrush.Attach( GetDlgItem( ID_DISP_PAINT_DIST_BRUSH )->m_hWnd );
  349. m_comboboxBrush.Init();
  350. // reset the size of the combo box list item
  351. m_comboboxBrush.SetItemHeight( -1, m_comboboxBrush.m_IconSize.cy + 2 );
  352. // initialize the radio button/brush combo box geometry data
  353. CToolDisplace *pTool = GetDisplacementTool();
  354. if ( pTool )
  355. {
  356. pTool->SetEffect( m_nPrevEffect );
  357. switch ( m_nPrevEffect )
  358. {
  359. case DISPPAINT_EFFECT_RAISELOWER:
  360. {
  361. pTool->SetEffect( DISPPAINT_EFFECT_RAISELOWER );
  362. SetEffectButtonGeo( DISPPAINT_EFFECT_RAISELOWER );
  363. FilterComboBoxBrushGeo( DISPPAINT_EFFECT_RAISELOWER, true );
  364. break;
  365. }
  366. case DISPPAINT_EFFECT_RAISETO:
  367. {
  368. pTool->SetEffect( DISPPAINT_EFFECT_RAISETO );
  369. SetEffectButtonGeo( DISPPAINT_EFFECT_RAISETO );
  370. FilterComboBoxBrushGeo( DISPPAINT_EFFECT_RAISETO, true );
  371. break;
  372. }
  373. case DISPPAINT_EFFECT_SMOOTH:
  374. {
  375. pTool->SetEffect( DISPPAINT_EFFECT_SMOOTH );
  376. SetEffectButtonGeo( DISPPAINT_EFFECT_SMOOTH );
  377. FilterComboBoxBrushGeo( DISPPAINT_EFFECT_SMOOTH, true );
  378. break;
  379. }
  380. default:
  381. {
  382. return false;
  383. }
  384. }
  385. OnComboBoxBrushGeo();
  386. }
  387. else
  388. {
  389. OnEffectRaiseLowerGeo();
  390. OnComboBoxBrushGeo();
  391. }
  392. return true;
  393. }
  394. //-----------------------------------------------------------------------------
  395. //-----------------------------------------------------------------------------
  396. void CDispPaintDistDlg::InitBrushType( void )
  397. {
  398. CToolDisplace *pTool = GetDisplacementTool();
  399. if ( pTool )
  400. {
  401. unsigned int uiBrushType = pTool->GetBrushType();
  402. switch ( uiBrushType )
  403. {
  404. case DISPPAINT_BRUSHTYPE_SOFT:
  405. {
  406. SetBrushTypeButtonGeo( DISPPAINT_BRUSHTYPE_SOFT );
  407. break;
  408. }
  409. case DISPPAINT_BRUSHTYPE_HARD:
  410. {
  411. SetBrushTypeButtonGeo( DISPPAINT_BRUSHTYPE_HARD );
  412. break;
  413. }
  414. }
  415. if ( pTool->IsSpatialPainting() )
  416. {
  417. EnableBrushTypeButtons();
  418. }
  419. else
  420. {
  421. DisableBrushTypeButtons();
  422. }
  423. }
  424. }
  425. //-----------------------------------------------------------------------------
  426. //-----------------------------------------------------------------------------
  427. void CDispPaintDistDlg::FilterComboBoxBrushGeo( unsigned int nEffect, bool bInit )
  428. {
  429. //
  430. // remove all the old combo box data
  431. //
  432. int count = m_comboboxBrush.GetCount();
  433. for ( int ndx = count - 1; ndx >= 0; ndx-- )
  434. {
  435. m_comboboxBrush.DeleteIcon( ndx );
  436. }
  437. //
  438. // add the new combo box data based on the current paint "effect"
  439. //
  440. CToolDisplace *pTool = GetDisplacementTool();
  441. if ( pTool )
  442. {
  443. CDispMapImageFilterManager *pFilterMgr;
  444. switch ( nEffect )
  445. {
  446. case DISPPAINT_EFFECT_RAISELOWER: { pFilterMgr = pTool->GetFilterRaiseLowerMgr(); break; }
  447. case DISPPAINT_EFFECT_RAISETO: { pFilterMgr = pTool->GetFilterRaiseToMgr(); break; }
  448. case DISPPAINT_EFFECT_SMOOTH: { pFilterMgr = pTool->GetFilterSmoothMgr(); break; }
  449. default: return;
  450. }
  451. if( pFilterMgr )
  452. {
  453. //
  454. // for each filter - add its icon to the icon combo box
  455. //
  456. for ( int iFilter = 0; iFilter < pFilterMgr->GetFilterCount(); iFilter++ )
  457. {
  458. // get the current filter
  459. CDispMapImageFilter *pFilter = pFilterMgr->GetFilter( iFilter );
  460. // get the application directory
  461. char appDir[MAX_PATH];
  462. APP()->GetDirectory( DIR_PROGRAM, appDir );
  463. // append the filters directory name
  464. strcat( appDir, "filters\\" );
  465. // append the directory prefix to the icon name
  466. CString iconFilename = appDir + pFilter->m_Name;
  467. // add the icon to the icon combo box
  468. m_comboboxBrush.AddIcon( iconFilename );
  469. }
  470. // set initial paint brush
  471. if( bInit )
  472. {
  473. m_comboboxBrush.SetCurSel( m_nPrevBrush );
  474. }
  475. else
  476. {
  477. m_comboboxBrush.SetCurSel( 0 );
  478. }
  479. }
  480. }
  481. }
  482. //-----------------------------------------------------------------------------
  483. //-----------------------------------------------------------------------------
  484. bool CDispPaintDistDlg::InitComboBoxAxis( void )
  485. {
  486. //
  487. // add the paint types to the combo box -- keep them in their "defined" order
  488. //
  489. CString strPaintDir;
  490. // axial x direction
  491. strPaintDir = "X-Axis";
  492. m_comboboxAxis.AddString( strPaintDir );
  493. // axial y direction
  494. strPaintDir = "Y-Axis";
  495. m_comboboxAxis.AddString( strPaintDir );
  496. // axial z direction
  497. strPaintDir = "Z-Axis";
  498. m_comboboxAxis.AddString( strPaintDir );
  499. // subdivision direction
  500. strPaintDir = "Subdiv Normal";
  501. m_comboboxAxis.AddString( strPaintDir );
  502. // face normal direction
  503. strPaintDir = "Face Normal";
  504. m_comboboxAxis.AddString( strPaintDir );
  505. // set initial value
  506. CToolDisplace *pTool = GetDisplacementTool();
  507. if ( pTool )
  508. {
  509. m_comboboxAxis.SetCurSel( m_nPrevPaintAxis );
  510. pTool->SetPaintAxis( m_nPrevPaintAxis, m_vecPrevPaintAxis );
  511. }
  512. else
  513. {
  514. m_comboboxAxis.SetCurSel( 4 );
  515. OnComboBoxAxis();
  516. }
  517. return true;
  518. }
  519. //-----------------------------------------------------------------------------
  520. // Purpose:
  521. //-----------------------------------------------------------------------------
  522. void CDispPaintDistDlg::EnablePaintingComboBoxes( void )
  523. {
  524. m_comboboxBrush.EnableWindow( TRUE );
  525. }
  526. //-----------------------------------------------------------------------------
  527. // Purpose:
  528. //-----------------------------------------------------------------------------
  529. void CDispPaintDistDlg::DisablePaintingComboBoxes( void )
  530. {
  531. m_comboboxBrush.EnableWindow( FALSE );
  532. }
  533. //-----------------------------------------------------------------------------
  534. // Purpose:
  535. //-----------------------------------------------------------------------------
  536. void CDispPaintDistDlg::EnableBrushTypeButtons( void )
  537. {
  538. CButton *pRadioButton;
  539. pRadioButton = ( CButton* )GetDlgItem( ID_DISPPAINT_SOFTEDGE );
  540. pRadioButton->EnableWindow( TRUE );
  541. pRadioButton = ( CButton* )GetDlgItem( ID_DISPPAINT_HARDEDGE );
  542. pRadioButton->EnableWindow( TRUE );
  543. }
  544. //-----------------------------------------------------------------------------
  545. // Purpose:
  546. //-----------------------------------------------------------------------------
  547. void CDispPaintDistDlg::DisableBrushTypeButtons( void )
  548. {
  549. CButton *pRadioButton;
  550. pRadioButton = ( CButton* )GetDlgItem( ID_DISPPAINT_SOFTEDGE );
  551. pRadioButton->EnableWindow( FALSE );
  552. pRadioButton = ( CButton* )GetDlgItem( ID_DISPPAINT_HARDEDGE );
  553. pRadioButton->EnableWindow( FALSE );
  554. }
  555. //-----------------------------------------------------------------------------
  556. // Purpose:
  557. //-----------------------------------------------------------------------------
  558. void CDispPaintDistDlg::DoDataExchange( CDataExchange *pDX )
  559. {
  560. CDialog::DoDataExchange( pDX );
  561. //{{AFX_DATA_MAP(CDispPaintDistDlg)
  562. DDX_Control( pDX, ID_DISP_PAINT_DIST_SLIDER_DISTANCE, m_sliderDistance );
  563. DDX_Control( pDX, ID_DISP_PAINT_DIST_SLIDER_RADIUS, m_sliderRadius );
  564. DDX_Control( pDX, ID_DISP_PAINT_DIST_EDIT_DISTANCE, m_editDistance );
  565. DDX_Control( pDX, ID_DISP_PAINT_DIST_EDIT_RADIUS, m_editRadius );
  566. DDX_Control( pDX, ID_DISP_PAINT_DIST_AXIS, m_comboboxAxis );
  567. //}}AFX_DATA_MAP
  568. }
  569. //-----------------------------------------------------------------------------
  570. //-----------------------------------------------------------------------------
  571. void CDispPaintDistDlg::OnComboBoxBrushGeo( void )
  572. {
  573. // get the displacement's filter manager
  574. CToolDisplace *pTool = GetDisplacementTool();
  575. if ( pTool )
  576. {
  577. // get current selection
  578. int iSel = m_comboboxBrush.GetCurSel();
  579. if ( iSel == LB_ERR )
  580. return;
  581. unsigned int nEffect = pTool->GetEffect();
  582. CDispMapImageFilterManager *pFilterMgr;
  583. switch ( nEffect )
  584. {
  585. case DISPPAINT_EFFECT_RAISELOWER: { pFilterMgr = pTool->GetFilterRaiseLowerMgr(); break; }
  586. case DISPPAINT_EFFECT_RAISETO: { pFilterMgr = pTool->GetFilterRaiseToMgr(); break; }
  587. case DISPPAINT_EFFECT_SMOOTH: { pFilterMgr = pTool->GetFilterSmoothMgr(); break; }
  588. default: return;
  589. }
  590. if ( pFilterMgr )
  591. {
  592. pFilterMgr->SetActiveFilter( iSel );
  593. }
  594. }
  595. }
  596. //-----------------------------------------------------------------------------
  597. //-----------------------------------------------------------------------------
  598. void CDispPaintDistDlg::OnComboBoxAxis( void )
  599. {
  600. // get the displacement tool
  601. CToolDisplace *pTool = GetDisplacementTool();
  602. if ( pTool )
  603. {
  604. //
  605. // get the current paint type selection
  606. //
  607. int ndxSel = m_comboboxAxis.GetCurSel();
  608. if ( ndxSel == LB_ERR )
  609. return;
  610. // update the paint type
  611. UpdateAxis( ndxSel );
  612. }
  613. }
  614. //-----------------------------------------------------------------------------
  615. //-----------------------------------------------------------------------------
  616. void CDispPaintDistDlg::UpdateAxis( int nAxis )
  617. {
  618. // get the displacement tool
  619. CToolDisplace *pTool = GetDisplacementTool();
  620. if ( !pTool )
  621. return;
  622. //
  623. // update the paint type - direction
  624. //
  625. switch ( nAxis )
  626. {
  627. case DISPPAINT_AXIS_X: { pTool->SetPaintAxis( nAxis, Vector( 1.0f, 0.0f, 0.0f ) ); return; }
  628. case DISPPAINT_AXIS_Y: { pTool->SetPaintAxis( nAxis, Vector( 0.0f, 1.0f, 0.0f ) ); return; }
  629. case DISPPAINT_AXIS_Z: { pTool->SetPaintAxis( nAxis, Vector( 0.0f, 0.0f, 1.0f ) ); return; }
  630. case DISPPAINT_AXIS_SUBDIV: { pTool->SetPaintAxis( nAxis, Vector( 0.0f, 0.0f, 0.0f ) ); return; }
  631. case DISPPAINT_AXIS_FACE: { pTool->SetPaintAxis( nAxis, Vector( 0.0f, 0.0f, 1.0f ) ); return; }
  632. default: { return; }
  633. }
  634. }
  635. //-----------------------------------------------------------------------------
  636. //-----------------------------------------------------------------------------
  637. void CDispPaintDistDlg::OnCheckAutoSew( void )
  638. {
  639. // get the displacement tool
  640. CToolDisplace *pTool = GetDisplacementTool();
  641. if ( pTool )
  642. {
  643. pTool->ToggleAutoSew();
  644. }
  645. }
  646. //-----------------------------------------------------------------------------
  647. //-----------------------------------------------------------------------------
  648. void CDispPaintDistDlg::OnCheckSpatial( void )
  649. {
  650. // Get the displacement tool and toggle the spatial painting bit.
  651. CToolDisplace *pTool = GetDisplacementTool();
  652. if ( pTool )
  653. {
  654. pTool->ToggleSpatialPainting();
  655. if ( pTool->IsSpatialPainting() )
  656. {
  657. EnableSliderRadius();
  658. DisablePaintingComboBoxes();
  659. EnableBrushTypeButtons();
  660. }
  661. else
  662. {
  663. DisableSliderRadius();
  664. EnablePaintingComboBoxes();
  665. DisableBrushTypeButtons();
  666. }
  667. }
  668. }
  669. //-----------------------------------------------------------------------------
  670. //-----------------------------------------------------------------------------
  671. void CDispPaintDistDlg::SetEffectButtonGeo( unsigned int nEffect )
  672. {
  673. CButton *radiobutton;
  674. radiobutton = ( CButton* )GetDlgItem( ID_DISP_PAINT_DIST_RAISELOWER );
  675. radiobutton->SetCheck( nEffect == DISPPAINT_EFFECT_RAISELOWER );
  676. radiobutton = ( CButton* )GetDlgItem( ID_DISP_PAINT_DIST_RAISETO );
  677. radiobutton->SetCheck( nEffect == DISPPAINT_EFFECT_RAISETO );
  678. radiobutton = ( CButton* )GetDlgItem( ID_DISP_PAINT_DIST_SMOOTH );
  679. radiobutton->SetCheck( nEffect == DISPPAINT_EFFECT_SMOOTH );
  680. }
  681. //-----------------------------------------------------------------------------
  682. // Purpose:
  683. //-----------------------------------------------------------------------------
  684. void CDispPaintDistDlg::SetBrushTypeButtonGeo( unsigned int uiBrushType )
  685. {
  686. CButton *pRadioButton;
  687. pRadioButton = ( CButton* )GetDlgItem( ID_DISPPAINT_SOFTEDGE );
  688. pRadioButton->SetCheck( uiBrushType == DISPPAINT_BRUSHTYPE_SOFT );
  689. pRadioButton = ( CButton* )GetDlgItem( ID_DISPPAINT_HARDEDGE );
  690. pRadioButton->SetCheck( uiBrushType == DISPPAINT_BRUSHTYPE_HARD );
  691. }
  692. //-----------------------------------------------------------------------------
  693. //-----------------------------------------------------------------------------
  694. void CDispPaintDistDlg::OnEffectRaiseLowerGeo( void )
  695. {
  696. // get the displacement tool
  697. CToolDisplace *pTool = GetDisplacementTool();
  698. if ( pTool )
  699. {
  700. pTool->SetEffect( DISPPAINT_EFFECT_RAISELOWER );
  701. SetEffectButtonGeo( DISPPAINT_EFFECT_RAISELOWER );
  702. FilterComboBoxBrushGeo( DISPPAINT_EFFECT_RAISELOWER, false );
  703. OnComboBoxBrushGeo();
  704. }
  705. }
  706. //-----------------------------------------------------------------------------
  707. //-----------------------------------------------------------------------------
  708. void CDispPaintDistDlg::OnEffectRaiseToGeo( void )
  709. {
  710. // get the displacement tool
  711. CToolDisplace *pTool = GetDisplacementTool();
  712. if( pTool )
  713. {
  714. pTool->SetEffect( DISPPAINT_EFFECT_RAISETO );
  715. SetEffectButtonGeo( DISPPAINT_EFFECT_RAISETO );
  716. FilterComboBoxBrushGeo( DISPPAINT_EFFECT_RAISETO, false );
  717. OnComboBoxBrushGeo();
  718. }
  719. }
  720. //-----------------------------------------------------------------------------
  721. //-----------------------------------------------------------------------------
  722. void CDispPaintDistDlg::OnEffectSmoothGeo( void )
  723. {
  724. // get the displacement tool
  725. CToolDisplace *pTool = GetDisplacementTool();
  726. if( pTool )
  727. {
  728. pTool->SetEffect( DISPPAINT_EFFECT_SMOOTH );
  729. SetEffectButtonGeo( DISPPAINT_EFFECT_SMOOTH );
  730. FilterComboBoxBrushGeo( DISPPAINT_EFFECT_SMOOTH, false );
  731. OnComboBoxBrushGeo();
  732. }
  733. }
  734. //-----------------------------------------------------------------------------
  735. // Purpose:
  736. //-----------------------------------------------------------------------------
  737. void CDispPaintDistDlg::OnBrushTypeSoftEdge( void )
  738. {
  739. CToolDisplace *pTool = GetDisplacementTool();
  740. if ( pTool )
  741. {
  742. pTool->SetBrushType( DISPPAINT_BRUSHTYPE_SOFT );
  743. SetBrushTypeButtonGeo( DISPPAINT_BRUSHTYPE_SOFT );
  744. }
  745. }
  746. //-----------------------------------------------------------------------------
  747. // Purpose:
  748. //-----------------------------------------------------------------------------
  749. void CDispPaintDistDlg::OnBrushTypeHardEdge( void )
  750. {
  751. CToolDisplace *pTool = GetDisplacementTool();
  752. if ( pTool )
  753. {
  754. pTool->SetBrushType( DISPPAINT_BRUSHTYPE_HARD );
  755. SetBrushTypeButtonGeo( DISPPAINT_BRUSHTYPE_HARD );
  756. }
  757. }
  758. //-----------------------------------------------------------------------------
  759. //-----------------------------------------------------------------------------
  760. void CDispPaintDistDlg::UpdateSliderDistance( float flDistance, bool bForceInit )
  761. {
  762. if ( ( flDistance != m_flPrevDistance ) || bForceInit )
  763. {
  764. int nDistance = ( int )flDistance;
  765. // clamp
  766. if( nDistance < DISPPAINT_DISTANCE_MIN ) { nDistance = DISPPAINT_DISTANCE_MIN; }
  767. if( nDistance > DISPPAINT_DISTANCE_MAX ) { nDistance = DISPPAINT_DISTANCE_MAX; }
  768. m_sliderDistance.SetPos( nDistance );
  769. }
  770. }
  771. //-----------------------------------------------------------------------------
  772. //-----------------------------------------------------------------------------
  773. void CDispPaintDistDlg::UpdateEditBoxDistance( float flDistance, bool bForceInit )
  774. {
  775. if ( ( flDistance != m_flPrevDistance ) || bForceInit )
  776. {
  777. CString strDistance;
  778. strDistance.Format( "%4.2f", flDistance );
  779. m_editDistance.SetWindowText( strDistance );
  780. }
  781. }
  782. //-----------------------------------------------------------------------------
  783. //-----------------------------------------------------------------------------
  784. void CDispPaintDistDlg::UpdateSliderRadius( float flRadius, bool bForceInit )
  785. {
  786. if ( ( flRadius != m_flPrevRadius ) || bForceInit )
  787. {
  788. int nRadius = ( int )flRadius;
  789. // clamp
  790. if( nRadius < DISPPAINT_SPATIALRADIUS_MIN ) { nRadius = DISPPAINT_SPATIALRADIUS_MIN; }
  791. if( nRadius > DISPPAINT_SPATIALRADIUS_MAX ) { nRadius = DISPPAINT_SPATIALRADIUS_MAX; }
  792. m_sliderRadius.SetPos( nRadius );
  793. }
  794. }
  795. //-----------------------------------------------------------------------------
  796. //-----------------------------------------------------------------------------
  797. void CDispPaintDistDlg::UpdateEditBoxRadius( float flRadius, bool bForceInit )
  798. {
  799. if ( ( flRadius != m_flPrevRadius ) || bForceInit )
  800. {
  801. CString strRadius;
  802. strRadius.Format( "%4.2f", flRadius );
  803. m_editRadius.SetWindowText( strRadius );
  804. }
  805. }
  806. //-----------------------------------------------------------------------------
  807. //-----------------------------------------------------------------------------
  808. void CDispPaintDistDlg::OnHScroll( UINT nSBCode, UINT nPos, CScrollBar *pScrollBar )
  809. {
  810. // Get the displacement tool.
  811. CToolDisplace *pTool = GetDisplacementTool();
  812. if ( pTool )
  813. {
  814. // Get the distance slider control.
  815. CSliderCtrl *pDistSlider = ( CSliderCtrl* )GetDlgItem( ID_DISP_PAINT_DIST_SLIDER_DISTANCE );
  816. if ( pDistSlider )
  817. {
  818. // Get the slider position.
  819. int nDistPos = pDistSlider->GetPos();
  820. if ( nDistPos != m_flPrevDistance )
  821. {
  822. // Update the displacement tool info.
  823. pTool->SetChannel( DISPPAINT_CHANNEL_POSITION, ( float )nDistPos );
  824. // Update the "buddy" edit box.
  825. CString strDistance;
  826. strDistance.Format( "%4.2f", ( float )nDistPos );
  827. m_editDistance.SetWindowText( strDistance );
  828. }
  829. }
  830. // Get the radius slider control.
  831. CSliderCtrl *pRadiusSlider = ( CSliderCtrl* )GetDlgItem( ID_DISP_PAINT_DIST_SLIDER_RADIUS );
  832. if ( pRadiusSlider )
  833. {
  834. // Get the slider position.
  835. int nRadiusPos = pRadiusSlider->GetPos();
  836. if ( nRadiusPos != m_flPrevRadius )
  837. {
  838. // Update the displacement tool info.
  839. pTool->SetSpatialRadius( ( float )nRadiusPos );
  840. // Update the "buddy" edit box.
  841. CString strRadius;
  842. strRadius.Format( "%4.2f", ( float )nRadiusPos );
  843. m_editRadius.SetWindowText( strRadius );
  844. }
  845. }
  846. }
  847. }
  848. //-----------------------------------------------------------------------------
  849. //-----------------------------------------------------------------------------
  850. void CDispPaintDistDlg::OnEditDistance( void )
  851. {
  852. //
  853. // get the edit box distance data
  854. //
  855. CString strDistance;
  856. m_editDistance.GetWindowText( strDistance );
  857. float flDistance = atof( strDistance );
  858. // get the displacement tool
  859. CToolDisplace *pTool = GetDisplacementTool();
  860. if ( pTool )
  861. {
  862. UpdateSliderDistance( flDistance, false );
  863. pTool->SetChannel( DISPPAINT_CHANNEL_POSITION, flDistance );
  864. // Save the change in the distance.
  865. m_flPrevDistance = flDistance;
  866. }
  867. }
  868. //-----------------------------------------------------------------------------
  869. //-----------------------------------------------------------------------------
  870. void CDispPaintDistDlg::OnEditRadius( void )
  871. {
  872. //
  873. // Get the edit box radius data.
  874. //
  875. CString strRadius;
  876. m_editRadius.GetWindowText( strRadius );
  877. float flRadius = atof( strRadius );
  878. // get the displacement tool
  879. CToolDisplace *pTool = GetDisplacementTool();
  880. if ( pTool )
  881. {
  882. UpdateSliderRadius( flRadius, false );
  883. pTool->SetSpatialRadius( flRadius );
  884. // Save the change in the spatial radius.
  885. m_flPrevRadius = flRadius;
  886. }
  887. }
  888. //-----------------------------------------------------------------------------
  889. //-----------------------------------------------------------------------------
  890. void CDispPaintDistDlg::OnClose( void )
  891. {
  892. // get the displacement tool and set selection tool active
  893. CToolDisplace *pDispTool = GetDisplacementTool();
  894. if( pDispTool )
  895. {
  896. pDispTool->SetTool( DISPTOOL_SELECT );
  897. }
  898. // set "select" as the current tool - this should destroy this dialog!!
  899. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  900. if ( pSheet )
  901. {
  902. pSheet->m_DispPage.SetTool( CFaceEditDispPage::FACEEDITTOOL_SELECT );
  903. }
  904. }
  905. //-----------------------------------------------------------------------------
  906. //-----------------------------------------------------------------------------
  907. void CDispPaintDistDlg::OnDestroy( void )
  908. {
  909. //
  910. // save the current dialog data - window position, effect, etc...
  911. //
  912. GetWindowRect( &m_DialogPosRect );
  913. CToolDisplace *pTool = GetDisplacementTool();
  914. if ( pTool )
  915. {
  916. m_nPrevEffect = pTool->GetEffect();
  917. pTool->GetPaintAxis( m_nPrevPaintAxis, m_vecPrevPaintAxis );
  918. // Reset spatial tool flag.
  919. if ( pTool->IsSpatialPainting() )
  920. {
  921. pTool->ToggleSpatialPainting();
  922. }
  923. }
  924. m_nPrevBrush = m_comboboxBrush.GetCurSel();
  925. // detach the brush combo box!!
  926. m_comboboxBrush.Detach();
  927. }
  928. //=============================================================================
  929. //
  930. // Paint Scult Dialog Functions
  931. //
  932. BEGIN_MESSAGE_MAP(CPaintSculptDlg, CDialog)
  933. //{{AFX_MSG_MAP(CPaintSculptDlg)
  934. ON_BN_CLICKED( ID_DISP_PAINT_DIST_AUTOSEW, OnCheckAutoSew )
  935. ON_WM_CLOSE()
  936. ON_WM_DESTROY()
  937. ON_BN_CLICKED(IDC_SCULPT_PUSH, &CPaintSculptDlg::OnBnClickedSculptPush)
  938. ON_BN_CLICKED(IDC_SCULPT_CARVE, &CPaintSculptDlg::OnBnClickedSculptCarve)
  939. ON_BN_CLICKED(IDC_SCULPT_PROJECT, &CPaintSculptDlg::OnBnClickedSculptProject)
  940. ON_WM_LBUTTONUP()
  941. ON_WM_LBUTTONDOWN()
  942. ON_WM_MOUSEMOVE()
  943. //}}AFX_MSG_MAP
  944. END_MESSAGE_MAP()
  945. //-----------------------------------------------------------------------------
  946. // Purpose: constructor
  947. //-----------------------------------------------------------------------------
  948. CPaintSculptDlg::CPaintSculptDlg( CWnd *pParent ) :
  949. CDialog( CPaintSculptDlg::IDD, pParent )
  950. {
  951. m_bAutoSew = true;
  952. m_SculptMode = SCULPT_MODE_PUSH;
  953. m_PushOptions = new CSculptPushOptions();
  954. m_CarveOptions = new CSculptCarveOptions();
  955. // m_ProjectOptions = new CSculptProjectOptions();
  956. }
  957. //-----------------------------------------------------------------------------
  958. // Purpose: destructor
  959. //-----------------------------------------------------------------------------
  960. CPaintSculptDlg::~CPaintSculptDlg( )
  961. {
  962. delete m_PushOptions;
  963. delete m_CarveOptions;
  964. // delete m_ProjectOptions;
  965. }
  966. //-----------------------------------------------------------------------------
  967. // Purpose: intialized the dialog
  968. // Output : returns true if successful
  969. //-----------------------------------------------------------------------------
  970. BOOL CPaintSculptDlg::OnInitDialog( )
  971. {
  972. static bool bInit = false;
  973. CDialog::OnInitDialog();
  974. CToolDisplace *pTool = GetDisplacementTool();
  975. if ( !pTool )
  976. {
  977. return FALSE;
  978. }
  979. #if 0
  980. // Set spatial tool flag.
  981. if ( !pTool->IsSpatialPainting() )
  982. {
  983. pTool->ToggleSpatialPainting();
  984. }
  985. #endif
  986. if ( !bInit )
  987. {
  988. bInit = true;
  989. }
  990. else
  991. {
  992. SetWindowPos( &wndTop, m_DialogPosRect.left, m_DialogPosRect.top, m_DialogPosRect.Width(), m_DialogPosRect.Height(), SWP_NOZORDER );
  993. }
  994. m_AutoSew.SetCheck( m_bAutoSew );
  995. m_PushOptions->SetPaintOwner( this );
  996. m_CarveOptions->SetPaintOwner( this );
  997. // m_ProjectOptions->SetPaintOwner( this );
  998. if( !m_PushOptions->Create( IDD_DISP_SCULPT_PUSH_OPTIONS, this ) )
  999. {
  1000. return FALSE;
  1001. }
  1002. if( !m_CarveOptions->Create( IDD_DISP_SCULPT_CARVE_OPTIONS, this ) )
  1003. {
  1004. return FALSE;
  1005. }
  1006. #if 0
  1007. if( !m_ProjectOptions->Create( IDD_DISP_SCULPT_PROJECT_OPTIONS, this ) )
  1008. {
  1009. return FALSE;
  1010. }
  1011. #endif
  1012. RECT OptionsLoc, ThisLoc;
  1013. m_SculptOptionsLoc.GetWindowRect( &OptionsLoc );
  1014. GetWindowRect( &ThisLoc );
  1015. m_PushOptions->SetWindowPos( NULL, 10, OptionsLoc.top - ThisLoc.top - 20, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW );
  1016. m_CarveOptions->SetWindowPos( NULL, 10, OptionsLoc.top - ThisLoc.top - 20, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW );
  1017. // m_ProjectOptions->SetWindowPos( NULL, 10, OptionsLoc.top - ThisLoc.top - 20, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW );
  1018. m_PushOptions->ShowWindow( SW_HIDE );
  1019. m_CarveOptions->ShowWindow( SW_HIDE );
  1020. // m_ProjectOptions->ShowWindow( SW_HIDE );
  1021. m_ProjectButton.EnableWindow( FALSE );
  1022. SetActiveMode( m_SculptMode );
  1023. return TRUE;
  1024. }
  1025. //-----------------------------------------------------------------------------
  1026. // Purpose: set up the data exchange between the dialog and variables
  1027. // Input : pDX - data exchange object
  1028. //-----------------------------------------------------------------------------
  1029. void CPaintSculptDlg::DoDataExchange( CDataExchange *pDX )
  1030. {
  1031. CDialog::DoDataExchange( pDX );
  1032. //{{AFX_DATA_MAP(CPaintSculptDlg)
  1033. //}}AFX_DATA_MAP
  1034. DDX_Control(pDX, IDC_SCULPT_OPTIONS_LOC, m_SculptOptionsLoc);
  1035. DDX_Control(pDX, ID_DISP_PAINT_DIST_AUTOSEW, m_AutoSew);
  1036. DDX_Control(pDX, IDC_SCULPT_PUSH, m_PushButton);
  1037. DDX_Control(pDX, IDC_SCULPT_CARVE, m_CarveButton);
  1038. DDX_Control(pDX, IDC_SCULPT_PROJECT, m_ProjectButton);
  1039. }
  1040. //-----------------------------------------------------------------------------
  1041. // Purpose: Sets the autosew option
  1042. //-----------------------------------------------------------------------------
  1043. void CPaintSculptDlg::OnCheckAutoSew( )
  1044. {
  1045. m_bAutoSew = ( m_AutoSew.GetCheck() != 0 );
  1046. }
  1047. //-----------------------------------------------------------------------------
  1048. // Purpose: handles shutting down the dialog
  1049. //-----------------------------------------------------------------------------
  1050. void CPaintSculptDlg::OnClose( )
  1051. {
  1052. // get the displacement tool and set selection tool active
  1053. CToolDisplace *pDispTool = GetDisplacementTool();
  1054. if( pDispTool )
  1055. {
  1056. pDispTool->SetTool( DISPTOOL_SELECT );
  1057. }
  1058. // set "select" as the current tool - this should destroy this dialog!!
  1059. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  1060. if ( pSheet )
  1061. {
  1062. pSheet->m_DispPage.SetTool( CFaceEditDispPage::FACEEDITTOOL_SELECT );
  1063. }
  1064. }
  1065. //-----------------------------------------------------------------------------
  1066. // Purpose: Handles the left button up
  1067. // Input : nFlags - button flags
  1068. // point - the location of the click
  1069. //-----------------------------------------------------------------------------
  1070. void CPaintSculptDlg::OnLButtonUp( UINT nFlags, CPoint point )
  1071. {
  1072. CToolDisplace *pDispTool = GetDisplacementTool();
  1073. CSculptPainter *painter = dynamic_cast< CSculptPainter * >( pDispTool->GetSculptPainter() );
  1074. if ( painter )
  1075. {
  1076. painter->OnLButtonUpDialog( nFlags, point );
  1077. }
  1078. __super::OnLButtonUp(nFlags, point);
  1079. }
  1080. //-----------------------------------------------------------------------------
  1081. // Purpose: Handles the left button down
  1082. // Input : nFlags - button flags
  1083. // point - the location of the click
  1084. //-----------------------------------------------------------------------------
  1085. void CPaintSculptDlg::OnLButtonDown( UINT nFlags, CPoint point )
  1086. {
  1087. CToolDisplace *pDispTool = GetDisplacementTool();
  1088. CSculptPainter *painter = dynamic_cast< CSculptPainter * >( pDispTool->GetSculptPainter() );
  1089. if ( painter )
  1090. {
  1091. painter->OnLButtonDownDialog( nFlags, point );
  1092. }
  1093. __super::OnLButtonDown(nFlags, point);
  1094. }
  1095. //-----------------------------------------------------------------------------
  1096. // Purpose: Handles mouse move
  1097. // Input : nFlags - button flags
  1098. // point - the location of the click
  1099. //-----------------------------------------------------------------------------
  1100. void CPaintSculptDlg::OnMouseMove( UINT nFlags, CPoint point )
  1101. {
  1102. CToolDisplace *pDispTool = GetDisplacementTool();
  1103. CSculptPainter *painter = dynamic_cast< CSculptPainter * >( pDispTool->GetSculptPainter() );
  1104. if ( painter )
  1105. {
  1106. painter->OnMouseMoveDialog( nFlags, point );
  1107. }
  1108. __super::OnMouseMove(nFlags, point);
  1109. }
  1110. //-----------------------------------------------------------------------------
  1111. // Purpose: handles the destruction of the window
  1112. //-----------------------------------------------------------------------------
  1113. void CPaintSculptDlg::OnDestroy( )
  1114. {
  1115. //
  1116. // save the current dialog data - window position, effect, etc...
  1117. //
  1118. GetWindowRect( &m_DialogPosRect );
  1119. #if 0
  1120. CToolDisplace *pTool = GetDisplacementTool();
  1121. if ( pTool )
  1122. {
  1123. // Reset spatial tool flag.
  1124. if ( pTool->IsSpatialPainting() )
  1125. {
  1126. pTool->ToggleSpatialPainting();
  1127. }
  1128. }
  1129. #endif
  1130. }
  1131. //-----------------------------------------------------------------------------
  1132. // Purpose: sets the active mode to push
  1133. //-----------------------------------------------------------------------------
  1134. void CPaintSculptDlg::OnBnClickedSculptPush( )
  1135. {
  1136. SetActiveMode( SCULPT_MODE_PUSH );
  1137. }
  1138. //-----------------------------------------------------------------------------
  1139. // Purpose: sets the active mode to carve
  1140. //-----------------------------------------------------------------------------
  1141. void CPaintSculptDlg::OnBnClickedSculptCarve( )
  1142. {
  1143. SetActiveMode( SCULPT_MODE_CARVE );
  1144. }
  1145. //-----------------------------------------------------------------------------
  1146. // Purpose: sets the active mode to sculpt
  1147. //-----------------------------------------------------------------------------
  1148. void CPaintSculptDlg::OnBnClickedSculptProject( )
  1149. {
  1150. // SetActiveMode( SCULPT_MODE_PROJECT );
  1151. }
  1152. #if 0
  1153. //-----------------------------------------------------------------------------
  1154. // Purpose:
  1155. // Input :
  1156. // Output :
  1157. //-----------------------------------------------------------------------------
  1158. BOOL CPaintSculptDlg::PreTranslateMessage( MSG* pMsg )
  1159. {
  1160. return __super::PreTranslateMessage( pMsg );
  1161. }
  1162. #endif
  1163. //-----------------------------------------------------------------------------
  1164. // Purpose: sets the active mode
  1165. // Input : NewMode - the mode we are going to
  1166. //-----------------------------------------------------------------------------
  1167. void CPaintSculptDlg::SetActiveMode( SculptMode NewMode )
  1168. {
  1169. m_SculptMode = NewMode;
  1170. m_PushButton.SetCheck( m_SculptMode == SCULPT_MODE_PUSH );
  1171. m_CarveButton.SetCheck( m_SculptMode == SCULPT_MODE_CARVE );
  1172. m_ProjectButton.SetCheck( m_SculptMode == SCULPT_MODE_PROJECT );
  1173. CToolDisplace *pDispTool = GetDisplacementTool();
  1174. if( pDispTool )
  1175. {
  1176. CDialog *painter = dynamic_cast< CDialog * >( pDispTool->GetSculptPainter() );
  1177. if ( painter )
  1178. {
  1179. painter->ShowWindow( SW_HIDE );
  1180. }
  1181. switch( m_SculptMode )
  1182. {
  1183. case SCULPT_MODE_PUSH:
  1184. m_PushOptions->ShowWindow( SW_SHOW );
  1185. pDispTool->SetSculptPainter( m_PushOptions );
  1186. break;
  1187. case SCULPT_MODE_CARVE:
  1188. m_CarveOptions->ShowWindow( SW_SHOW );
  1189. pDispTool->SetSculptPainter( m_CarveOptions );
  1190. break;
  1191. #if 0
  1192. case SCULPT_MODE_PROJECT:
  1193. m_ProjectOptions->ShowWindow( SW_SHOW );
  1194. pDispTool->SetSculptPainter( m_ProjectOptions );
  1195. break;
  1196. #endif
  1197. }
  1198. }
  1199. }
  1200. //=============================================================================
  1201. //
  1202. // Set Paint Distance Dialog Functions
  1203. //
  1204. BEGIN_MESSAGE_MAP(CDispPaintDataDlg, CDialog)
  1205. //{{AFX_MSG_MAP(CDispPaintDataDlg)
  1206. ON_BN_CLICKED( ID_DISP_PAINT_DATA_RAISELOWER, OnEffectRaiseLowerData )
  1207. ON_BN_CLICKED( ID_DISP_PAINT_DATA_RAISETO, OnEffectRaiseToData )
  1208. ON_BN_CLICKED( ID_DISP_PAINT_DATA_SMOOTH, OnEffectSmoothData )
  1209. ON_CBN_SELCHANGE( ID_DISP_PAINT_DATA_BRUSH, OnComboBoxBrushData )
  1210. ON_CBN_SELCHANGE( ID_DISP_PAINT_DATA_TYPE, OnComboBoxType )
  1211. ON_WM_HSCROLL()
  1212. ON_EN_CHANGE( ID_DISP_PAINT_DATA_EDIT_VALUE, OnEditValue )
  1213. ON_WM_CLOSE()
  1214. ON_WM_DESTROY()
  1215. //}}AFX_MSG_MAP
  1216. END_MESSAGE_MAP()
  1217. //-----------------------------------------------------------------------------
  1218. // Purpose: constructor
  1219. //-----------------------------------------------------------------------------
  1220. CDispPaintDataDlg::CDispPaintDataDlg( CWnd *pParent ) :
  1221. CDialog( CDispPaintDataDlg::IDD, pParent )
  1222. {
  1223. }
  1224. //-----------------------------------------------------------------------------
  1225. // Purpose:
  1226. //-----------------------------------------------------------------------------
  1227. CDispPaintDataDlg::~CDispPaintDataDlg()
  1228. {
  1229. if( m_comboboxBrush.m_hWnd )
  1230. {
  1231. m_comboboxBrush.Detach();
  1232. }
  1233. }
  1234. //-----------------------------------------------------------------------------
  1235. // Purpose:
  1236. //-----------------------------------------------------------------------------
  1237. BOOL CDispPaintDataDlg::OnInitDialog(void)
  1238. {
  1239. static bool bInit = false;
  1240. CDialog::OnInitDialog();
  1241. if( !bInit )
  1242. {
  1243. CToolDisplace *pDispTool = GetDisplacementTool();
  1244. if( pDispTool )
  1245. {
  1246. m_uiPrevEffect = pDispTool->GetEffect();
  1247. pDispTool->GetChannel( DISPPAINT_CHANNEL_ALPHA, m_fPrevPaintValue );
  1248. m_iPrevBrush = 0;
  1249. bInit = true;
  1250. }
  1251. }
  1252. else
  1253. {
  1254. SetWindowPos( &wndTop, m_DialogPosRect.left, m_DialogPosRect.top,
  1255. m_DialogPosRect.Width(), m_DialogPosRect.Height(), SWP_NOZORDER );
  1256. }
  1257. // initialize the sliders
  1258. InitValue();
  1259. // initialize the combo boxes
  1260. InitComboBoxBrushData();
  1261. InitComboBoxType();
  1262. return TRUE;
  1263. }
  1264. //-----------------------------------------------------------------------------
  1265. //-----------------------------------------------------------------------------
  1266. void CDispPaintDataDlg::InitValue( void )
  1267. {
  1268. // init slider value
  1269. m_sliderValue.SetBuddy( &m_editValue, FALSE );
  1270. m_sliderValue.SetRange( 1, 255 );
  1271. m_sliderValue.SetTicFreq( 25 );
  1272. CToolDisplace *pDispTool = GetDisplacementTool();
  1273. if( pDispTool )
  1274. {
  1275. pDispTool->SetChannel( DISPPAINT_CHANNEL_ALPHA, m_fPrevPaintValue );
  1276. // init slider value
  1277. UpdateSliderValue( m_fPrevPaintValue );
  1278. // initialize the value edit box
  1279. CString strValue;
  1280. strValue.Format( "%4.2f", m_fPrevPaintValue );
  1281. m_editValue.SetWindowText( strValue );
  1282. }
  1283. else
  1284. {
  1285. UpdateSliderValue( 15.0f );
  1286. // initialize the value edit box
  1287. m_editValue.SetWindowText( "15.00" );
  1288. }
  1289. }
  1290. //-----------------------------------------------------------------------------
  1291. //-----------------------------------------------------------------------------
  1292. bool CDispPaintDataDlg::InitComboBoxBrushData( void )
  1293. {
  1294. //
  1295. // get the displacement paint brush icon combo box
  1296. //
  1297. m_comboboxBrush.Attach( GetDlgItem( ID_DISP_PAINT_DATA_BRUSH )->m_hWnd );
  1298. m_comboboxBrush.Init();
  1299. // reset the size of the combo box list item
  1300. m_comboboxBrush.SetItemHeight( -1, m_comboboxBrush.m_IconSize.cy + 2 );
  1301. // set initial radio button/brush combo box data
  1302. // initialize the radio button/brush combo box geometry data
  1303. CToolDisplace *pDispTool = GetDisplacementTool();
  1304. if( pDispTool )
  1305. {
  1306. pDispTool->SetEffect( m_uiPrevEffect );
  1307. switch( m_uiPrevEffect )
  1308. {
  1309. case DISPPAINT_EFFECT_RAISELOWER:
  1310. {
  1311. pDispTool->SetEffect( DISPPAINT_EFFECT_RAISELOWER );
  1312. SetEffectButtonData( DISPPAINT_EFFECT_RAISELOWER );
  1313. FilterComboBoxBrushData( DISPPAINT_EFFECT_RAISELOWER, true );
  1314. break;
  1315. }
  1316. case DISPPAINT_EFFECT_RAISETO:
  1317. {
  1318. pDispTool->SetEffect( DISPPAINT_EFFECT_RAISETO );
  1319. SetEffectButtonData( DISPPAINT_EFFECT_RAISETO );
  1320. FilterComboBoxBrushData( DISPPAINT_EFFECT_RAISETO, true );
  1321. break;
  1322. }
  1323. case DISPPAINT_EFFECT_SMOOTH:
  1324. {
  1325. pDispTool->SetEffect( DISPPAINT_EFFECT_SMOOTH );
  1326. SetEffectButtonData( DISPPAINT_EFFECT_SMOOTH );
  1327. FilterComboBoxBrushData( DISPPAINT_EFFECT_SMOOTH, true );
  1328. break;
  1329. }
  1330. default:
  1331. {
  1332. return false;
  1333. }
  1334. }
  1335. OnComboBoxBrushData();
  1336. }
  1337. else
  1338. {
  1339. OnEffectRaiseLowerData();
  1340. OnComboBoxBrushData();
  1341. }
  1342. return true;
  1343. }
  1344. //-----------------------------------------------------------------------------
  1345. //-----------------------------------------------------------------------------
  1346. void CDispPaintDataDlg::FilterComboBoxBrushData( unsigned int uiEffect, bool bInit )
  1347. {
  1348. //
  1349. // remove all the old combo box data
  1350. //
  1351. int count = m_comboboxBrush.GetCount();
  1352. for( int ndx = count - 1; ndx >= 0; ndx-- )
  1353. {
  1354. m_comboboxBrush.DeleteIcon( ndx );
  1355. }
  1356. //
  1357. // add the new combo box data based on the current paint "effect"
  1358. //
  1359. CToolDisplace *pDispTool = GetDisplacementTool();
  1360. if( pDispTool )
  1361. {
  1362. CDispMapImageFilterManager *pFilterMgr;
  1363. switch( uiEffect )
  1364. {
  1365. case DISPPAINT_EFFECT_RAISELOWER: { pFilterMgr = pDispTool->GetFilterRaiseLowerMgr(); break; }
  1366. case DISPPAINT_EFFECT_RAISETO: { pFilterMgr = pDispTool->GetFilterRaiseToMgr(); break; }
  1367. case DISPPAINT_EFFECT_SMOOTH: { pFilterMgr = pDispTool->GetFilterSmoothMgr(); break; }
  1368. default: return;
  1369. }
  1370. if( pFilterMgr )
  1371. {
  1372. //
  1373. // for each filter - add its icon to the icon combo box
  1374. //
  1375. for( int ndxFilter = 0; ndxFilter < pFilterMgr->GetFilterCount(); ndxFilter++ )
  1376. {
  1377. // get the current filter
  1378. CDispMapImageFilter *pFilter = pFilterMgr->GetFilter( ndxFilter );
  1379. // get the application directory
  1380. char appDir[MAX_PATH];
  1381. APP()->GetDirectory( DIR_PROGRAM, appDir );
  1382. // append the filters directory name
  1383. strcat( appDir, "filters\\" );
  1384. // append the directory prefix to the icon name
  1385. CString iconFilename = appDir + pFilter->m_Name;
  1386. // add the icon to the icon combo box
  1387. m_comboboxBrush.AddIcon( iconFilename );
  1388. }
  1389. // set initial paint brush
  1390. if( bInit )
  1391. {
  1392. m_comboboxBrush.SetCurSel( m_iPrevBrush );
  1393. }
  1394. else
  1395. {
  1396. m_comboboxBrush.SetCurSel( 0 );
  1397. }
  1398. }
  1399. }
  1400. }
  1401. //-----------------------------------------------------------------------------
  1402. //-----------------------------------------------------------------------------
  1403. bool CDispPaintDataDlg::InitComboBoxType( void )
  1404. {
  1405. // alpha type
  1406. CString strType = "Alpha";
  1407. m_comboboxType.AddString( strType );
  1408. m_comboboxType.SetCurSel( 0 );
  1409. // turn off for now
  1410. m_comboboxType.EnableWindow( FALSE );
  1411. return true;
  1412. }
  1413. //-----------------------------------------------------------------------------
  1414. // Purpose:
  1415. //-----------------------------------------------------------------------------
  1416. void CDispPaintDataDlg::DoDataExchange( CDataExchange *pDX )
  1417. {
  1418. CDialog::DoDataExchange( pDX );
  1419. //{{AFX_DATA_MAP(CDispPaintDistDlg)
  1420. DDX_Control( pDX, ID_DISP_PAINT_DATA_SLIDER_VALUE, m_sliderValue );
  1421. DDX_Control( pDX, ID_DISP_PAINT_DATA_EDIT_VALUE, m_editValue );
  1422. DDX_Control( pDX, ID_DISP_PAINT_DATA_TYPE, m_comboboxType );
  1423. //}}AFX_DATA_MAP
  1424. }
  1425. //-----------------------------------------------------------------------------
  1426. //-----------------------------------------------------------------------------
  1427. void CDispPaintDataDlg::OnComboBoxBrushData( void )
  1428. {
  1429. // get the displacement's filter manager
  1430. CToolDisplace *pDispTool = GetDisplacementTool();
  1431. if( pDispTool )
  1432. {
  1433. // get current selection
  1434. int iSel = m_comboboxBrush.GetCurSel();
  1435. if( iSel == LB_ERR )
  1436. return;
  1437. unsigned int uiEffect = pDispTool->GetEffect();
  1438. CDispMapImageFilterManager *pFilterMgr;
  1439. switch( uiEffect )
  1440. {
  1441. case DISPPAINT_EFFECT_RAISELOWER: { pFilterMgr = pDispTool->GetFilterRaiseLowerMgr(); break; }
  1442. case DISPPAINT_EFFECT_RAISETO: { pFilterMgr = pDispTool->GetFilterRaiseToMgr(); break; }
  1443. case DISPPAINT_EFFECT_SMOOTH: { pFilterMgr = pDispTool->GetFilterSmoothMgr(); break; }
  1444. default: return;
  1445. }
  1446. if( pFilterMgr )
  1447. {
  1448. pFilterMgr->SetActiveFilter( iSel );
  1449. }
  1450. }
  1451. }
  1452. //-----------------------------------------------------------------------------
  1453. //-----------------------------------------------------------------------------
  1454. void CDispPaintDataDlg::OnComboBoxType( void )
  1455. {
  1456. return;
  1457. }
  1458. //-----------------------------------------------------------------------------
  1459. //-----------------------------------------------------------------------------
  1460. void CDispPaintDataDlg::SetEffectButtonData( unsigned int effect )
  1461. {
  1462. CButton *radiobutton;
  1463. radiobutton = ( CButton* )GetDlgItem( ID_DISP_PAINT_DATA_RAISELOWER );
  1464. radiobutton->SetCheck( effect == DISPPAINT_EFFECT_RAISELOWER );
  1465. radiobutton = ( CButton* )GetDlgItem( ID_DISP_PAINT_DATA_RAISETO );
  1466. radiobutton->SetCheck( effect == DISPPAINT_EFFECT_RAISETO );
  1467. radiobutton = ( CButton* )GetDlgItem( ID_DISP_PAINT_DATA_SMOOTH );
  1468. radiobutton->SetCheck( effect == DISPPAINT_EFFECT_SMOOTH );
  1469. }
  1470. //-----------------------------------------------------------------------------
  1471. //-----------------------------------------------------------------------------
  1472. void CDispPaintDataDlg::OnEffectRaiseLowerData( void )
  1473. {
  1474. // get the displacement tool
  1475. CToolDisplace *pDispTool = GetDisplacementTool();
  1476. if( pDispTool )
  1477. {
  1478. pDispTool->SetEffect( DISPPAINT_EFFECT_RAISELOWER );
  1479. SetEffectButtonData( DISPPAINT_EFFECT_RAISELOWER );
  1480. FilterComboBoxBrushData( DISPPAINT_EFFECT_RAISELOWER, false );
  1481. OnComboBoxBrushData();
  1482. }
  1483. }
  1484. //-----------------------------------------------------------------------------
  1485. //-----------------------------------------------------------------------------
  1486. void CDispPaintDataDlg::OnEffectRaiseToData( void )
  1487. {
  1488. // get the displacement tool
  1489. CToolDisplace *pDispTool = GetDisplacementTool();
  1490. if( pDispTool )
  1491. {
  1492. pDispTool->SetEffect( DISPPAINT_EFFECT_RAISETO );
  1493. SetEffectButtonData( DISPPAINT_EFFECT_RAISETO );
  1494. FilterComboBoxBrushData( DISPPAINT_EFFECT_RAISETO, false );
  1495. OnComboBoxBrushData();
  1496. }
  1497. }
  1498. //-----------------------------------------------------------------------------
  1499. //-----------------------------------------------------------------------------
  1500. void CDispPaintDataDlg::OnEffectSmoothData( void )
  1501. {
  1502. // get the displacement tool
  1503. CToolDisplace *pDispTool = GetDisplacementTool();
  1504. if( pDispTool )
  1505. {
  1506. pDispTool->SetEffect( DISPPAINT_EFFECT_SMOOTH );
  1507. SetEffectButtonData( DISPPAINT_EFFECT_SMOOTH );
  1508. FilterComboBoxBrushData( DISPPAINT_EFFECT_SMOOTH, false );
  1509. OnComboBoxBrushData();
  1510. }
  1511. }
  1512. //-----------------------------------------------------------------------------
  1513. //-----------------------------------------------------------------------------
  1514. void CDispPaintDataDlg::UpdateSliderValue( float fValue )
  1515. {
  1516. int iValue = ( int )fValue;
  1517. // clamp
  1518. if( iValue < 1 ) { iValue = 1; }
  1519. if( iValue > 255 ) { iValue = 255; }
  1520. m_sliderValue.SetPos( iValue );
  1521. }
  1522. //-----------------------------------------------------------------------------
  1523. //-----------------------------------------------------------------------------
  1524. void CDispPaintDataDlg::OnHScroll( UINT nSBCode, UINT nPos, CScrollBar *pScrollBar )
  1525. {
  1526. // get the displacement tool
  1527. CToolDisplace *pDispTool = GetDisplacementTool();
  1528. if( pDispTool )
  1529. {
  1530. // get the slider control
  1531. CSliderCtrl *pSlider = ( CSliderCtrl* )GetDlgItem( ID_DISP_PAINT_DATA_SLIDER_VALUE );
  1532. if( pSlider )
  1533. {
  1534. // get the slider position
  1535. int pos = pSlider->GetPos();
  1536. pDispTool->SetChannel( DISPPAINT_CHANNEL_ALPHA, ( float )pos );
  1537. //
  1538. // update "the buddy" the disp value cedit box
  1539. //
  1540. CString strValue;
  1541. strValue.Format( "%4.2f", ( float )pos );
  1542. m_editValue.SetWindowText( strValue );
  1543. }
  1544. }
  1545. }
  1546. //-----------------------------------------------------------------------------
  1547. //-----------------------------------------------------------------------------
  1548. void CDispPaintDataDlg::OnEditValue( void )
  1549. {
  1550. //
  1551. // get the edit box distance data
  1552. //
  1553. CString strValue;
  1554. m_editValue.GetWindowText( strValue );
  1555. float fValue = atof( strValue );
  1556. // get the displacement tool
  1557. CToolDisplace *pDispTool = GetDisplacementTool();
  1558. if( pDispTool )
  1559. {
  1560. UpdateSliderValue( fValue );
  1561. pDispTool->SetChannel( DISPPAINT_CHANNEL_ALPHA, fValue );
  1562. }
  1563. }
  1564. //-----------------------------------------------------------------------------
  1565. //-----------------------------------------------------------------------------
  1566. void CDispPaintDataDlg::OnClose( void )
  1567. {
  1568. // get the displacement tool and set selection tool active
  1569. CToolDisplace *pDispTool = GetDisplacementTool();
  1570. if( pDispTool )
  1571. {
  1572. pDispTool->SetTool( DISPTOOL_SELECT );
  1573. }
  1574. // set "select" as the current tool - this should destroy this dialog!!
  1575. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  1576. if( pSheet )
  1577. {
  1578. pSheet->m_DispPage.SetTool( CFaceEditDispPage::FACEEDITTOOL_SELECT );
  1579. }
  1580. }
  1581. //-----------------------------------------------------------------------------
  1582. //-----------------------------------------------------------------------------
  1583. void CDispPaintDataDlg::OnDestroy( void )
  1584. {
  1585. // save the current window position
  1586. GetWindowRect( &m_DialogPosRect );
  1587. CToolDisplace *pDispTool = GetDisplacementTool();
  1588. if( pDispTool )
  1589. {
  1590. m_uiPrevEffect = pDispTool->GetEffect();
  1591. pDispTool->GetChannel( DISPPAINT_CHANNEL_ALPHA, m_fPrevPaintValue );
  1592. }
  1593. m_iPrevBrush = m_comboboxBrush.GetCurSel();
  1594. // detach the brush combo box!!
  1595. m_comboboxBrush.Detach();
  1596. }