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.

450 lines
14 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include <stdafx.h>
  7. #include "materialdlg.h"
  8. #include "FaceEditSheet.h"
  9. #include "mapdoc.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include <tier0/memdbgon.h>
  12. //=============================================================================
  13. //
  14. // Face Smoothing Dialog Functions
  15. //
  16. BEGIN_MESSAGE_MAP( CFaceSmoothingDlg, CDialog )
  17. //{{AFX_MSG_MAP(CFaceSmoothingDlg)
  18. ON_COMMAND_EX( ID_SMOOTHING_GROUP_1, OnButtonGroup )
  19. ON_COMMAND_EX( ID_SMOOTHING_GROUP_2, OnButtonGroup )
  20. ON_COMMAND_EX( ID_SMOOTHING_GROUP_3, OnButtonGroup )
  21. ON_COMMAND_EX( ID_SMOOTHING_GROUP_4, OnButtonGroup )
  22. ON_COMMAND_EX( ID_SMOOTHING_GROUP_5, OnButtonGroup )
  23. ON_COMMAND_EX( ID_SMOOTHING_GROUP_6, OnButtonGroup )
  24. ON_COMMAND_EX( ID_SMOOTHING_GROUP_7, OnButtonGroup )
  25. ON_COMMAND_EX( ID_SMOOTHING_GROUP_8, OnButtonGroup )
  26. ON_COMMAND_EX( ID_SMOOTHING_GROUP_9, OnButtonGroup )
  27. ON_COMMAND_EX( ID_SMOOTHING_GROUP_10, OnButtonGroup )
  28. ON_COMMAND_EX( ID_SMOOTHING_GROUP_11, OnButtonGroup )
  29. ON_COMMAND_EX( ID_SMOOTHING_GROUP_12, OnButtonGroup )
  30. ON_COMMAND_EX( ID_SMOOTHING_GROUP_13, OnButtonGroup )
  31. ON_COMMAND_EX( ID_SMOOTHING_GROUP_14, OnButtonGroup )
  32. ON_COMMAND_EX( ID_SMOOTHING_GROUP_15, OnButtonGroup )
  33. ON_COMMAND_EX( ID_SMOOTHING_GROUP_16, OnButtonGroup )
  34. ON_COMMAND_EX( ID_SMOOTHING_GROUP_17, OnButtonGroup )
  35. ON_COMMAND_EX( ID_SMOOTHING_GROUP_18, OnButtonGroup )
  36. ON_COMMAND_EX( ID_SMOOTHING_GROUP_19, OnButtonGroup )
  37. ON_COMMAND_EX( ID_SMOOTHING_GROUP_20, OnButtonGroup )
  38. ON_COMMAND_EX( ID_SMOOTHING_GROUP_21, OnButtonGroup )
  39. ON_COMMAND_EX( ID_SMOOTHING_GROUP_22, OnButtonGroup )
  40. ON_COMMAND_EX( ID_SMOOTHING_GROUP_23, OnButtonGroup )
  41. ON_COMMAND_EX( ID_SMOOTHING_GROUP_24, OnButtonGroup )
  42. ON_COMMAND_EX( ID_SMOOTHING_GROUP_25, OnButtonGroup )
  43. ON_COMMAND_EX( ID_SMOOTHING_GROUP_26, OnButtonGroup )
  44. ON_COMMAND_EX( ID_SMOOTHING_GROUP_27, OnButtonGroup )
  45. ON_COMMAND_EX( ID_SMOOTHING_GROUP_28, OnButtonGroup )
  46. ON_COMMAND_EX( ID_SMOOTHING_GROUP_29, OnButtonGroup )
  47. ON_COMMAND_EX( ID_SMOOTHING_GROUP_30, OnButtonGroup )
  48. ON_COMMAND_EX( ID_SMOOTHING_GROUP_31, OnButtonGroup )
  49. ON_COMMAND_EX( ID_SMOOTHING_GROUP_32, OnButtonGroup )
  50. ON_WM_CLOSE()
  51. ON_WM_DESTROY()
  52. //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP()
  54. //-----------------------------------------------------------------------------
  55. // Purpose: Constructor
  56. //-----------------------------------------------------------------------------
  57. CFaceSmoothingDlg::CFaceSmoothingDlg( CWnd *pParent ) : CDialog( CFaceSmoothingDlg::IDD, pParent )
  58. {
  59. InitButtonIDs();
  60. }
  61. //-----------------------------------------------------------------------------
  62. // Purpose: Deconstructor
  63. //-----------------------------------------------------------------------------
  64. CFaceSmoothingDlg::~CFaceSmoothingDlg()
  65. {
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose:
  69. //-----------------------------------------------------------------------------
  70. BOOL CFaceSmoothingDlg::OnInitDialog( void )
  71. {
  72. static bool bInit = false;
  73. CDialog::OnInitDialog();
  74. if ( bInit )
  75. {
  76. SetWindowPos( &wndTop, m_DialogPosRect.left, m_DialogPosRect.top,
  77. m_DialogPosRect.Width(), m_DialogPosRect.Height(), SWP_NOZORDER );
  78. }
  79. // Update the controls.
  80. UpdateControls();
  81. // Initialized.
  82. bInit = true;
  83. return TRUE;
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Purpose:
  87. //-----------------------------------------------------------------------------
  88. void CFaceSmoothingDlg::OnClose( void )
  89. {
  90. // Get the parent and set the material tool as the current tool.
  91. CFaceEditSheet *pSheet = static_cast<CFaceEditSheet*>( GetParent() );
  92. if ( pSheet )
  93. {
  94. pSheet->m_MaterialPage.SetMaterialPageTool( CFaceEditMaterialPage::MATERIALPAGETOOL_MATERIAL );
  95. }
  96. }
  97. //-----------------------------------------------------------------------------
  98. // Purpose:
  99. //-----------------------------------------------------------------------------
  100. void CFaceSmoothingDlg::OnDestroy( void )
  101. {
  102. // Save the current window position.
  103. GetWindowRect( &m_DialogPosRect );
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Purpose:
  107. //-----------------------------------------------------------------------------
  108. void CFaceSmoothingDlg::InitButtonIDs( void )
  109. {
  110. m_ButtonIDs[0] = 0; // Default - no button!
  111. m_ButtonIDs[1] = ID_SMOOTHING_GROUP_1;
  112. m_ButtonIDs[2] = ID_SMOOTHING_GROUP_2;
  113. m_ButtonIDs[3] = ID_SMOOTHING_GROUP_3;
  114. m_ButtonIDs[4] = ID_SMOOTHING_GROUP_4;
  115. m_ButtonIDs[5] = ID_SMOOTHING_GROUP_5;
  116. m_ButtonIDs[6] = ID_SMOOTHING_GROUP_6;
  117. m_ButtonIDs[7] = ID_SMOOTHING_GROUP_7;
  118. m_ButtonIDs[8] = ID_SMOOTHING_GROUP_8;
  119. m_ButtonIDs[9] = ID_SMOOTHING_GROUP_9;
  120. m_ButtonIDs[10] = ID_SMOOTHING_GROUP_10;
  121. m_ButtonIDs[11] = ID_SMOOTHING_GROUP_11;
  122. m_ButtonIDs[12] = ID_SMOOTHING_GROUP_12;
  123. m_ButtonIDs[13] = ID_SMOOTHING_GROUP_13;
  124. m_ButtonIDs[14] = ID_SMOOTHING_GROUP_14;
  125. m_ButtonIDs[15] = ID_SMOOTHING_GROUP_15;
  126. m_ButtonIDs[16] = ID_SMOOTHING_GROUP_16;
  127. m_ButtonIDs[17] = ID_SMOOTHING_GROUP_17;
  128. m_ButtonIDs[18] = ID_SMOOTHING_GROUP_18;
  129. m_ButtonIDs[19] = ID_SMOOTHING_GROUP_19;
  130. m_ButtonIDs[20] = ID_SMOOTHING_GROUP_20;
  131. m_ButtonIDs[21] = ID_SMOOTHING_GROUP_21;
  132. m_ButtonIDs[22] = ID_SMOOTHING_GROUP_22;
  133. m_ButtonIDs[23] = ID_SMOOTHING_GROUP_23;
  134. m_ButtonIDs[24] = ID_SMOOTHING_GROUP_24;
  135. m_ButtonIDs[25] = ID_SMOOTHING_GROUP_25;
  136. m_ButtonIDs[26] = ID_SMOOTHING_GROUP_26;
  137. m_ButtonIDs[27] = ID_SMOOTHING_GROUP_27;
  138. m_ButtonIDs[28] = ID_SMOOTHING_GROUP_28;
  139. m_ButtonIDs[29] = ID_SMOOTHING_GROUP_29;
  140. m_ButtonIDs[30] = ID_SMOOTHING_GROUP_30;
  141. m_ButtonIDs[31] = ID_SMOOTHING_GROUP_31;
  142. m_ButtonIDs[32] = ID_SMOOTHING_GROUP_32;
  143. }
  144. //-----------------------------------------------------------------------------
  145. // Purpose:
  146. //-----------------------------------------------------------------------------
  147. BOOL CFaceSmoothingDlg::OnButtonGroup( UINT uCmd )
  148. {
  149. int iGroup = GetSmoothingGroup( uCmd );
  150. if ( iGroup == -1 )
  151. return FALSE;
  152. // Add or remove.
  153. CButton *pGroupButton = ( CButton* )GetDlgItem( uCmd );
  154. if ( !pGroupButton )
  155. return FALSE;
  156. bool bAdd = ( pGroupButton->GetCheck() != 0 );
  157. // Get the selected faces and add them to the appropriate group.
  158. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  159. if ( pSheet )
  160. {
  161. int nFaceCount = pSheet->GetFaceListCount();
  162. for ( int iFace = 0; iFace < nFaceCount; ++iFace )
  163. {
  164. CMapFace *pFace = pSheet->GetFaceListDataFace( iFace );
  165. if ( pFace )
  166. {
  167. if ( bAdd )
  168. {
  169. pFace->AddSmoothingGroup( iGroup );
  170. }
  171. else
  172. {
  173. pFace->RemoveSmoothingGroup( iGroup );
  174. }
  175. }
  176. }
  177. }
  178. UpdateControls();
  179. return TRUE;
  180. }
  181. //-----------------------------------------------------------------------------
  182. // Purpose:
  183. //-----------------------------------------------------------------------------
  184. UINT CFaceSmoothingDlg::GetSmoothingGroup( UINT uCmd )
  185. {
  186. for ( int iGroup = 1; iGroup <= SMOOTHING_GROUP_MAX_COUNT; ++iGroup )
  187. {
  188. if ( m_ButtonIDs[iGroup] == uCmd )
  189. return iGroup;
  190. }
  191. return 0xFFFFFFFF;
  192. }
  193. //-----------------------------------------------------------------------------
  194. // Purpose:
  195. //-----------------------------------------------------------------------------
  196. int CFaceSmoothingDlg::GetActiveSmoothingGroup( void )
  197. {
  198. for ( int iButton = 1; iButton <= SMOOTHING_GROUP_MAX_COUNT; ++iButton )
  199. {
  200. CButton *pGroupButton = ( CButton* )GetDlgItem( m_ButtonIDs[iButton] );
  201. if ( !pGroupButton )
  202. continue;
  203. if ( pGroupButton->GetCheck() != 0 )
  204. return iButton;
  205. }
  206. return 0xFFFFFFFF;
  207. }
  208. //-----------------------------------------------------------------------------
  209. // Purpose:
  210. //-----------------------------------------------------------------------------
  211. void CFaceSmoothingDlg::UpdateControls( void )
  212. {
  213. // Get the selected faces and add them to the appropriate group.
  214. CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
  215. if ( !pSheet )
  216. return;
  217. // Check for a face count.
  218. int nFaceCount = pSheet->GetFaceListCount();
  219. if ( nFaceCount == 0 )
  220. return;
  221. // Keep a list of used groups.
  222. int nGroupCounts[SMOOTHING_GROUP_MAX_COUNT+1];
  223. for ( int iGroup = 0; iGroup <= SMOOTHING_GROUP_MAX_COUNT; ++iGroup )
  224. {
  225. nGroupCounts[iGroup] = 0;
  226. }
  227. for ( int iFace = 0; iFace < nFaceCount; ++iFace )
  228. {
  229. CMapFace *pFace = pSheet->GetFaceListDataFace( iFace );
  230. if ( pFace )
  231. {
  232. for ( int iGroup = 1; iGroup <= SMOOTHING_GROUP_MAX_COUNT; ++iGroup )
  233. {
  234. if ( pFace->InSmoothingGroup( iGroup ) )
  235. {
  236. nGroupCounts[iGroup]++;
  237. }
  238. }
  239. }
  240. }
  241. CheckGroupButtons( nGroupCounts, nFaceCount );
  242. }
  243. //-----------------------------------------------------------------------------
  244. // Purpose:
  245. //-----------------------------------------------------------------------------
  246. void CFaceSmoothingDlg::CheckGroupButtons( int *pGroupCounts, int nFaceCount )
  247. {
  248. m_bColorOverride = true;
  249. for ( int iButton = 1; iButton <= SMOOTHING_GROUP_MAX_COUNT; ++iButton )
  250. {
  251. CButton *pGroupButton = ( CButton* )GetDlgItem( m_ButtonIDs[iButton] );
  252. if ( !pGroupButton )
  253. continue;
  254. pGroupButton->SetCheck( FALSE );
  255. if ( pGroupCounts[iButton] == 0 )
  256. continue;
  257. if ( pGroupCounts[iButton] == nFaceCount )
  258. {
  259. pGroupButton->SetCheck( TRUE );
  260. }
  261. else
  262. {
  263. // Todo: Come up with a better effect here!
  264. CDC *pDC = pGroupButton->GetDC();
  265. m_Brush.CreateSolidBrush( pDC->GetTextColor() );
  266. CRect buttonRect;
  267. pGroupButton->GetClientRect( buttonRect );
  268. pDC->FillRect( buttonRect, &m_Brush );
  269. m_Brush.DeleteObject();
  270. pGroupButton->ReleaseDC( pDC );
  271. }
  272. }
  273. m_bColorOverride = false;
  274. }
  275. //=============================================================================
  276. BEGIN_MESSAGE_MAP( CFaceSmoothingVisualDlg, CDialog )
  277. //{{AFX_MSG_MAP(CFaceSmoothingVisualDlg)
  278. ON_COMMAND_EX( ID_SG_VISUAL_1, OnButtonGroup )
  279. ON_COMMAND_EX( ID_SG_VISUAL_2, OnButtonGroup )
  280. ON_COMMAND_EX( ID_SG_VISUAL_3, OnButtonGroup )
  281. ON_COMMAND_EX( ID_SG_VISUAL_4, OnButtonGroup )
  282. ON_COMMAND_EX( ID_SG_VISUAL_5, OnButtonGroup )
  283. ON_COMMAND_EX( ID_SG_VISUAL_6, OnButtonGroup )
  284. ON_COMMAND_EX( ID_SG_VISUAL_7, OnButtonGroup )
  285. ON_COMMAND_EX( ID_SG_VISUAL_8, OnButtonGroup )
  286. ON_COMMAND_EX( ID_SG_VISUAL_9, OnButtonGroup )
  287. ON_COMMAND_EX( ID_SG_VISUAL_10, OnButtonGroup )
  288. ON_COMMAND_EX( ID_SG_VISUAL_11, OnButtonGroup )
  289. ON_COMMAND_EX( ID_SG_VISUAL_12, OnButtonGroup )
  290. ON_COMMAND_EX( ID_SG_VISUAL_13, OnButtonGroup )
  291. ON_COMMAND_EX( ID_SG_VISUAL_14, OnButtonGroup )
  292. ON_COMMAND_EX( ID_SG_VISUAL_15, OnButtonGroup )
  293. ON_COMMAND_EX( ID_SG_VISUAL_16, OnButtonGroup )
  294. ON_COMMAND_EX( ID_SG_VISUAL_17, OnButtonGroup )
  295. ON_COMMAND_EX( ID_SG_VISUAL_18, OnButtonGroup )
  296. ON_COMMAND_EX( ID_SG_VISUAL_19, OnButtonGroup )
  297. ON_COMMAND_EX( ID_SG_VISUAL_20, OnButtonGroup )
  298. ON_COMMAND_EX( ID_SG_VISUAL_21, OnButtonGroup )
  299. ON_COMMAND_EX( ID_SG_VISUAL_22, OnButtonGroup )
  300. ON_COMMAND_EX( ID_SG_VISUAL_23, OnButtonGroup )
  301. ON_COMMAND_EX( ID_SG_VISUAL_24, OnButtonGroup )
  302. ON_COMMAND_EX( ID_SG_VISUAL_25, OnButtonGroup )
  303. ON_COMMAND_EX( ID_SG_VISUAL_26, OnButtonGroup )
  304. ON_COMMAND_EX( ID_SG_VISUAL_27, OnButtonGroup )
  305. ON_COMMAND_EX( ID_SG_VISUAL_28, OnButtonGroup )
  306. ON_COMMAND_EX( ID_SG_VISUAL_29, OnButtonGroup )
  307. ON_COMMAND_EX( ID_SG_VISUAL_30, OnButtonGroup )
  308. ON_COMMAND_EX( ID_SG_VISUAL_31, OnButtonGroup )
  309. ON_COMMAND_EX( ID_SG_VISUAL_32, OnButtonGroup )
  310. //}}AFX_MSG_MAP
  311. END_MESSAGE_MAP()
  312. //-----------------------------------------------------------------------------
  313. // Purpose: Constructor
  314. //-----------------------------------------------------------------------------
  315. CFaceSmoothingVisualDlg::CFaceSmoothingVisualDlg( CWnd *pParent ) : CDialog( CFaceSmoothingDlg::IDD, pParent )
  316. {
  317. InitButtonIDs();
  318. }
  319. //-----------------------------------------------------------------------------
  320. // Purpose: Deconstructor
  321. //-----------------------------------------------------------------------------
  322. CFaceSmoothingVisualDlg::~CFaceSmoothingVisualDlg()
  323. {
  324. }
  325. //-----------------------------------------------------------------------------
  326. // Purpose:
  327. //-----------------------------------------------------------------------------
  328. BOOL CFaceSmoothingVisualDlg::OnInitDialog( void )
  329. {
  330. CDialog::OnInitDialog();
  331. // SetWindowPos( &wndTop, m_DialogPosRect.left, m_DialogPosRect.top,
  332. // m_DialogPosRect.Width(), m_DialogPosRect.Height(), SWP_NOZORDER );
  333. return TRUE;
  334. }
  335. //-----------------------------------------------------------------------------
  336. // Purpose:
  337. //-----------------------------------------------------------------------------
  338. BOOL CFaceSmoothingVisualDlg::OnButtonGroup( UINT uCmd )
  339. {
  340. int iGroup = GetSmoothingGroup( uCmd );
  341. if ( iGroup == -1 )
  342. return FALSE;
  343. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  344. if ( pDoc )
  345. {
  346. pDoc->SetSmoothingGroupVisual( iGroup );
  347. }
  348. return TRUE;
  349. }
  350. //-----------------------------------------------------------------------------
  351. // Purpose:
  352. //-----------------------------------------------------------------------------
  353. void CFaceSmoothingVisualDlg::InitButtonIDs( void )
  354. {
  355. m_ButtonIDs[0] = 0; // Default - no button!
  356. m_ButtonIDs[1] = ID_SG_VISUAL_1;
  357. m_ButtonIDs[2] = ID_SG_VISUAL_2;
  358. m_ButtonIDs[3] = ID_SG_VISUAL_3;
  359. m_ButtonIDs[4] = ID_SG_VISUAL_4;
  360. m_ButtonIDs[5] = ID_SG_VISUAL_5;
  361. m_ButtonIDs[6] = ID_SG_VISUAL_6;
  362. m_ButtonIDs[7] = ID_SG_VISUAL_7;
  363. m_ButtonIDs[8] = ID_SG_VISUAL_8;
  364. m_ButtonIDs[9] = ID_SG_VISUAL_9;
  365. m_ButtonIDs[10] = ID_SG_VISUAL_10;
  366. m_ButtonIDs[11] = ID_SG_VISUAL_11;
  367. m_ButtonIDs[12] = ID_SG_VISUAL_12;
  368. m_ButtonIDs[13] = ID_SG_VISUAL_13;
  369. m_ButtonIDs[14] = ID_SG_VISUAL_14;
  370. m_ButtonIDs[15] = ID_SG_VISUAL_15;
  371. m_ButtonIDs[16] = ID_SG_VISUAL_16;
  372. m_ButtonIDs[17] = ID_SG_VISUAL_17;
  373. m_ButtonIDs[18] = ID_SG_VISUAL_18;
  374. m_ButtonIDs[19] = ID_SG_VISUAL_19;
  375. m_ButtonIDs[20] = ID_SG_VISUAL_20;
  376. m_ButtonIDs[21] = ID_SG_VISUAL_21;
  377. m_ButtonIDs[22] = ID_SG_VISUAL_22;
  378. m_ButtonIDs[23] = ID_SG_VISUAL_23;
  379. m_ButtonIDs[24] = ID_SG_VISUAL_24;
  380. m_ButtonIDs[25] = ID_SG_VISUAL_25;
  381. m_ButtonIDs[26] = ID_SG_VISUAL_26;
  382. m_ButtonIDs[27] = ID_SG_VISUAL_27;
  383. m_ButtonIDs[28] = ID_SG_VISUAL_28;
  384. m_ButtonIDs[29] = ID_SG_VISUAL_29;
  385. m_ButtonIDs[30] = ID_SG_VISUAL_30;
  386. m_ButtonIDs[31] = ID_SG_VISUAL_31;
  387. m_ButtonIDs[32] = ID_SG_VISUAL_32;
  388. }
  389. //-----------------------------------------------------------------------------
  390. // Purpose:
  391. //-----------------------------------------------------------------------------
  392. UINT CFaceSmoothingVisualDlg::GetSmoothingGroup( UINT uCmd )
  393. {
  394. for ( int iGroup = 1; iGroup <= SMOOTHING_GROUP_MAX_COUNT; ++iGroup )
  395. {
  396. if ( m_ButtonIDs[iGroup] == uCmd )
  397. return iGroup;
  398. }
  399. return 0xFFFFFFFF;
  400. }