MeshDeformPanel.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando / G 3D engine *
  23. * *
  24. * File Name : MeshDeformPanel.cpp *
  25. * *
  26. * Programmer : Patrick Smith *
  27. * *
  28. * Start Date : 04/22/99 *
  29. * *
  30. * Last Update :
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "MeshDeformPanel.H"
  36. #include "Resource.H"
  37. #include "Util.H"
  38. #include "MeshDeform.H"
  39. ///////////////////////////////////////////////////////////////////////////
  40. //
  41. // Local constants
  42. //
  43. ///////////////////////////////////////////////////////////////////////////
  44. const char * const PANEL_OBJ_PROP = "WWPANELOBJ";
  45. ///////////////////////////////////////////////////////////////////////////
  46. //
  47. // Message_Proc
  48. //
  49. ///////////////////////////////////////////////////////////////////////////
  50. BOOL WINAPI
  51. MeshDeformPanelClass::Message_Proc
  52. (
  53. HWND hwnd,
  54. UINT message,
  55. WPARAM wparam,
  56. LPARAM lparam
  57. )
  58. {
  59. // Lookup the controlling object for this panel
  60. MeshDeformPanelClass *panel_obj = MeshDeformPanelClass::Get_Object (hwnd);
  61. BOOL result = FALSE;
  62. switch (message)
  63. {
  64. // Create the controlling panel-object
  65. case WM_INITDIALOG:
  66. panel_obj = new MeshDeformPanelClass (hwnd);
  67. SetProp (hwnd, PANEL_OBJ_PROP, (HANDLE)panel_obj);
  68. break;
  69. case WM_DESTROY:
  70. result = panel_obj->On_Message (message, wparam, lparam);
  71. RemoveProp (hwnd, PANEL_OBJ_PROP);
  72. SAFE_DELETE (panel_obj);
  73. break;
  74. }
  75. // Pass the message onto the controlling panel-object
  76. if (panel_obj != NULL) {
  77. result = panel_obj->On_Message (message, wparam, lparam);
  78. }
  79. // Return the TRUE/FALSE result code
  80. return result;
  81. }
  82. ///////////////////////////////////////////////////////////////////////////
  83. //
  84. // Get_Object
  85. //
  86. ///////////////////////////////////////////////////////////////////////////
  87. MeshDeformPanelClass *
  88. MeshDeformPanelClass::Get_Object (HWND hwnd)
  89. {
  90. return (MeshDeformPanelClass *)::GetProp (hwnd, PANEL_OBJ_PROP);
  91. }
  92. ///////////////////////////////////////////////////////////////////////////
  93. //
  94. // On_Message
  95. //
  96. ///////////////////////////////////////////////////////////////////////////
  97. BOOL
  98. MeshDeformPanelClass::On_Message
  99. (
  100. UINT message,
  101. WPARAM wparam,
  102. LPARAM lparam
  103. )
  104. {
  105. switch (message)
  106. {
  107. case WM_INITDIALOG:
  108. m_pColorSwatch = ::GetIColorSwatch (::GetDlgItem (m_hWnd, IDC_VERTEX_COLOR), RGB (0, 0, 0), "Vertex Color");
  109. m_pMaxSetsEdit = ::GetICustEdit (::GetDlgItem (m_hWnd, IDC_MAX_SETS_EDIT));
  110. m_pMaxSetsSpin = ::GetISpinner (::GetDlgItem (m_hWnd, IDC_MAX_SETS_SPIN));
  111. m_pLockSetsButton = ::GetICustButton (::GetDlgItem (m_hWnd, IDC_LOCK_SETS));
  112. //
  113. // Setup the 'max-sets' controls
  114. //
  115. m_pMaxSetsSpin->LinkToEdit (::GetDlgItem (m_hWnd, IDC_MAX_SETS_EDIT), EDITTYPE_INT);
  116. m_pMaxSetsSpin->SetLimits (1, 20);
  117. m_pMaxSetsEdit->SetText (1);
  118. m_pMaxSetsSpin->SetValue (1, FALSE);
  119. ::SetDlgItemInt (m_hWnd, IDC_CURRENT_SET_STATIC, 1, FALSE);
  120. //
  121. // Setup the edit button
  122. //
  123. m_pLockSetsButton->SetType (CBT_CHECK);
  124. m_pLockSetsButton->SetCheck (FALSE);
  125. m_pLockSetsButton->SetHighlightColor (GREEN_WASH);
  126. //m_pEditButton->SetType (CBT_CHECK);
  127. //m_pEditButton->SetCheck (FALSE);
  128. //m_pEditButton->SetHighlightColor (GREEN_WASH);
  129. //
  130. // Setup the sliders
  131. //
  132. ::SendDlgItemMessage (m_hWnd, IDC_CURRENT_SET_SLIDER, TBM_SETRANGE, (WPARAM)TRUE, MAKELONG (1, 1));
  133. ::SendDlgItemMessage (m_hWnd, IDC_CURRENT_SET_SLIDER, TBM_SETPOS, (WPARAM)TRUE, 0L);
  134. ::SendDlgItemMessage (m_hWnd, IDC_STATE_SLIDER, TBM_SETRANGE, (WPARAM)FALSE, MAKELONG (0, 10));
  135. ::SendDlgItemMessage (m_hWnd, IDC_STATE_SLIDER, TBM_SETPOS, (WPARAM)FALSE, 9L);
  136. //
  137. // Ensure the sliders are repainted
  138. //
  139. //::InvalidateRect (::GetDlgItem (m_hWnd, IDC_STATE_SLIDER), NULL, TRUE);
  140. //::InvalidateRect (::GetDlgItem (m_hWnd, IDC_CURRENT_SET_SLIDER), NULL, TRUE);
  141. break;
  142. case WM_DESTROY:
  143. ::ReleaseIColorSwatch (m_pColorSwatch);
  144. ::ReleaseICustEdit (m_pMaxSetsEdit);
  145. ::ReleaseISpinner (m_pMaxSetsSpin);
  146. //::ReleaseICustButton (m_pEditButton);
  147. m_pColorSwatch = NULL;
  148. m_pMaxSetsEdit = NULL;
  149. m_pMaxSetsSpin = NULL;
  150. //m_pEditButton = NULL;
  151. break;
  152. case WM_COMMAND:
  153. On_Command (wparam, lparam);
  154. break;
  155. case CC_COLOR_CHANGE:
  156. {
  157. // Pass the new color onto the mesh deformer
  158. COLORREF color_ref = m_pColorSwatch->GetColor ();
  159. VertColor color;
  160. color.x = GetRValue (color_ref) / 255.0F;
  161. color.y = GetGValue (color_ref) / 255.0F;
  162. color.z = GetBValue (color_ref) / 255.0F;
  163. m_pMeshDeformer->Set_Vertex_Color (color, HIWORD (wparam) != 0);
  164. }
  165. break;
  166. case WM_CUSTEDIT_ENTER:
  167. case CC_SPINNER_CHANGE:
  168. {
  169. Set_Max_Sets (m_pMaxSetsEdit->GetInt (), true);
  170. }
  171. break;
  172. case WM_HSCROLL:
  173. if ((HWND)lparam == ::GetDlgItem (m_hWnd, IDC_CURRENT_SET_SLIDER)) {
  174. int pos = ::SendDlgItemMessage (m_hWnd, IDC_CURRENT_SET_SLIDER, TBM_GETPOS, 0, 0L);
  175. Set_Current_Set (pos - 1, true);
  176. } else {
  177. int pos = ::SendDlgItemMessage (m_hWnd, IDC_STATE_SLIDER, TBM_GETPOS, 0, 0L);
  178. m_pMeshDeformer->Set_Deform_State (((float)pos) / 10.0F);
  179. if (pos > 0) {
  180. m_pColorSwatch->Enable ();
  181. } else {
  182. m_pColorSwatch->Disable ();
  183. }
  184. }
  185. break;
  186. }
  187. return FALSE;
  188. }
  189. ///////////////////////////////////////////////////////////////////////////
  190. //
  191. // On_Command
  192. //
  193. ///////////////////////////////////////////////////////////////////////////
  194. void
  195. MeshDeformPanelClass::On_Command
  196. (
  197. WPARAM wparam,
  198. LPARAM lparam
  199. )
  200. {
  201. switch (LOWORD (wparam))
  202. {
  203. case IDC_MANUALAPPLY:
  204. {
  205. m_pMeshDeformer->Auto_Apply (Get_Auto_Apply_Check ());
  206. }
  207. break;
  208. //case IDC_EDIT_BUTTON:
  209. /*if (m_pEditButton->IsChecked ()) {
  210. ::SendDlgItemMessage (m_hWnd, IDC_STATE_SLIDER, TBM_SETPOS, (WPARAM)TRUE, 100L);
  211. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_STATE_SLIDER), FALSE);
  212. m_pColorSwatch->Enable ();
  213. m_pMeshDeformer->Set_Deform_State (1.0F);
  214. } else {
  215. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_STATE_SLIDER), TRUE);
  216. m_pColorSwatch->Disable ();
  217. }*/
  218. //break;
  219. case IDC_MAX_SETS_EDIT:
  220. break;
  221. }
  222. return ;
  223. }
  224. ///////////////////////////////////////////////////////////////////////////
  225. //
  226. // Set_Deformer
  227. //
  228. ///////////////////////////////////////////////////////////////////////////
  229. void
  230. MeshDeformPanelClass::Set_Deformer (MeshDeformClass *obj)
  231. {
  232. if (m_pMeshDeformer != obj) {
  233. m_pMeshDeformer = obj;
  234. // Set the slider position based on the current state of the deformer
  235. float state = m_pMeshDeformer->Get_Deform_State ();
  236. ::SendDlgItemMessage (m_hWnd, IDC_STATE_SLIDER, TBM_SETPOS, (WPARAM)TRUE, LPARAM(state * 10.0F));
  237. // Now update the current vertex color
  238. Update_Vertex_Color ();
  239. }
  240. return ;
  241. }
  242. ///////////////////////////////////////////////////////////////////////////
  243. //
  244. // Update_Vertex_Color
  245. //
  246. ///////////////////////////////////////////////////////////////////////////
  247. void
  248. MeshDeformPanelClass::Update_Vertex_Color (void)
  249. {
  250. if (m_pMeshDeformer != NULL) {
  251. // Update the color swatch with data from the deformer
  252. Point3 color;
  253. m_pMeshDeformer->Get_Vertex_Color (color);
  254. m_pColorSwatch->SetColor (RGB (int(color.x * 255.0F), int(color.y * 255.0F), int(color.z * 255.0F)), FALSE);
  255. }
  256. return ;
  257. }
  258. ///////////////////////////////////////////////////////////////////////////
  259. //
  260. // Set_Max_Sets
  261. //
  262. ///////////////////////////////////////////////////////////////////////////
  263. void
  264. MeshDeformPanelClass::Set_Max_Sets
  265. (
  266. int max,
  267. bool notify
  268. )
  269. {
  270. // Update the UI
  271. ::SendDlgItemMessage (m_hWnd, IDC_CURRENT_SET_SLIDER, TBM_SETRANGE, (WPARAM)TRUE, MAKELONG (1, max));
  272. ::SetDlgItemInt (m_hWnd, IDC_CURRENT_SET_STATIC, max, TRUE);
  273. if (notify == false) {
  274. m_pMaxSetsSpin->SetValue (max, TRUE);
  275. } else if (m_pMeshDeformer != NULL) {
  276. // Update the deformer
  277. m_pMeshDeformer->Set_Max_Deform_Sets (max);
  278. }
  279. return ;
  280. }
  281. ///////////////////////////////////////////////////////////////////////////
  282. //
  283. // Set_Current_Set
  284. //
  285. ///////////////////////////////////////////////////////////////////////////
  286. void
  287. MeshDeformPanelClass::Set_Current_Set
  288. (
  289. int set,
  290. bool notify
  291. )
  292. {
  293. // Update the UI
  294. ::SetDlgItemInt (m_hWnd, IDC_CURRENT_SET_STATIC, set + 1, TRUE);
  295. if (notify == false) {
  296. ::SendDlgItemMessage (m_hWnd, IDC_CURRENT_SET_SLIDER, TBM_SETPOS, (WPARAM)TRUE, set + 1);
  297. } else if (m_pMeshDeformer != NULL) {
  298. // Update the deformer
  299. m_pMeshDeformer->Set_Current_Set (set, true);
  300. }
  301. return ;
  302. }
  303. ///////////////////////////////////////////////////////////////////////////
  304. //
  305. // Set_Current_State
  306. //
  307. ///////////////////////////////////////////////////////////////////////////
  308. void
  309. MeshDeformPanelClass::Set_Current_State (float state)
  310. {
  311. ::SendDlgItemMessage (m_hWnd, IDC_STATE_SLIDER, TBM_SETPOS, (WPARAM)TRUE, LPARAM(state * 10.0F));
  312. return ;
  313. }