VolumeRandomDialog.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. ** Command & Conquer Renegade(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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : W3DView *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/W3DView/VolumeRandomDialog.cpp $Modtime:: $*
  25. * *
  26. * $Revision:: 2 $*
  27. * *
  28. *---------------------------------------------------------------------------------------------*
  29. * Functions: *
  30. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  31. #include "Stdafx.H"
  32. #include "W3DView.H"
  33. #include "VolumeRandomDialog.H"
  34. #include "V3_Rnd.H"
  35. #include "Utils.H"
  36. #ifdef _DEBUG
  37. #define new DEBUG_NEW
  38. #undef THIS_FILE
  39. static char THIS_FILE[] = __FILE__;
  40. #endif
  41. ////////////////////////////////////////////////////////////////////
  42. //
  43. // VolumeRandomDialogClass
  44. //
  45. ////////////////////////////////////////////////////////////////////
  46. VolumeRandomDialogClass::VolumeRandomDialogClass (Vector3Randomizer *randomizer, CWnd *pParent)
  47. : m_Randomizer (randomizer),
  48. CDialog (VolumeRandomDialogClass::IDD, pParent)
  49. {
  50. //{{AFX_DATA_INIT(VolumeRandomDialogClass)
  51. // NOTE: the ClassWizard will add member initialization here
  52. //}}AFX_DATA_INIT
  53. return ;
  54. }
  55. ////////////////////////////////////////////////////////////////////
  56. //
  57. // DoDataExchange
  58. //
  59. ////////////////////////////////////////////////////////////////////
  60. void
  61. VolumeRandomDialogClass::DoDataExchange (CDataExchange *pDX)
  62. {
  63. CDialog::DoDataExchange(pDX);
  64. //{{AFX_DATA_MAP(VolumeRandomDialogClass)
  65. DDX_Control(pDX, IDC_SPHERE_RADIUS_SPIN, m_SphereRadiusSpin);
  66. DDX_Control(pDX, IDC_CYLINDER_RADIUS_SPIN, m_CylinderRadiusSpin);
  67. DDX_Control(pDX, IDC_CYLINDER_HEIGHT_SPIN, m_CylinderHeightSpin);
  68. DDX_Control(pDX, IDC_BOX_Z_SPIN, m_BoxZSpin);
  69. DDX_Control(pDX, IDC_BOX_Y_SPIN, m_BoxYSpin);
  70. DDX_Control(pDX, IDC_BOX_X_SPIN, m_BoxXSpin);
  71. //}}AFX_DATA_MAP
  72. return ;
  73. }
  74. BEGIN_MESSAGE_MAP(VolumeRandomDialogClass, CDialog)
  75. //{{AFX_MSG_MAP(VolumeRandomDialogClass)
  76. ON_BN_CLICKED(IDC_BOX_RADIO, OnBoxRadio)
  77. ON_BN_CLICKED(IDC_CYLINDER_RADIO, OnCylinderRadio)
  78. ON_BN_CLICKED(IDC_SPHERE_RADIO, OnSphereRadio)
  79. //}}AFX_MSG_MAP
  80. END_MESSAGE_MAP()
  81. ////////////////////////////////////////////////////////////////////
  82. //
  83. // OnOK
  84. //
  85. ////////////////////////////////////////////////////////////////////
  86. void
  87. VolumeRandomDialogClass::OnOK (void)
  88. {
  89. if (SendDlgItemMessage (IDC_BOX_RADIO, BM_GETCHECK) == 1) {
  90. //
  91. // Create a box randomizer
  92. //
  93. Vector3 extents (0, 0, 0);
  94. extents.X = ::GetDlgItemFloat (m_hWnd, IDC_BOX_X_EDIT);
  95. extents.Y = ::GetDlgItemFloat (m_hWnd, IDC_BOX_Y_EDIT);
  96. extents.Z = ::GetDlgItemFloat (m_hWnd, IDC_BOX_Z_EDIT);
  97. m_Randomizer = new Vector3SolidBoxRandomizer (extents);
  98. } else if (SendDlgItemMessage (IDC_SPHERE_RADIO, BM_GETCHECK) == 1) {
  99. //
  100. // What type of sphere is this, hollow or solid?
  101. //
  102. float radius = ::GetDlgItemFloat (m_hWnd, IDC_SPHERE_RADIUS_EDIT);
  103. if (SendDlgItemMessage (IDC_SPHERE_HOLLOW_CHECK, BM_GETCHECK) == 1) {
  104. m_Randomizer = new Vector3HollowSphereRandomizer (radius);
  105. } else {
  106. m_Randomizer = new Vector3SolidSphereRandomizer (radius);
  107. }
  108. } else if (SendDlgItemMessage (IDC_CYLINDER_RADIO, BM_GETCHECK) == 1) {
  109. //
  110. // Create a cylinder randomizer
  111. //
  112. float radius = ::GetDlgItemFloat (m_hWnd, IDC_CYLINDER_RADIUS_EDIT);
  113. float height = ::GetDlgItemFloat (m_hWnd, IDC_CYLINDER_HEIGHT_EDIT);
  114. m_Randomizer = new Vector3SolidCylinderRandomizer (height, radius);
  115. }
  116. CDialog::OnOK ();
  117. return ;
  118. }
  119. ////////////////////////////////////////////////////////////////////
  120. //
  121. // OnInitDialog
  122. //
  123. ////////////////////////////////////////////////////////////////////
  124. BOOL
  125. VolumeRandomDialogClass::OnInitDialog (void)
  126. {
  127. CDialog::OnInitDialog ();
  128. //
  129. // Start with some default values
  130. //
  131. Vector3 initial_box (1, 1, 1);
  132. float initial_sphere_radius = 1.0F;
  133. bool initial_sphere_hollow = false;
  134. float initial_cylinder_radius = 1.0F;
  135. float initial_cylinder_height = 1.0F;
  136. UINT initial_type = IDC_BOX_RADIO;
  137. //
  138. // Initialize from the provided randomizer
  139. //
  140. if (m_Randomizer != NULL) {
  141. // What type of randomizer is this?
  142. switch (m_Randomizer->Class_ID ())
  143. {
  144. case Vector3Randomizer::CLASSID_SOLIDBOX:
  145. initial_type = IDC_BOX_RADIO;
  146. initial_box = ((Vector3SolidBoxRandomizer *)m_Randomizer)->Get_Extents ();
  147. break;
  148. case Vector3Randomizer::CLASSID_SOLIDSPHERE:
  149. initial_type = IDC_SPHERE_RADIO;
  150. initial_sphere_radius = ((Vector3SolidSphereRandomizer *)m_Randomizer)->Get_Radius();
  151. initial_sphere_hollow = false;
  152. break;
  153. case Vector3Randomizer::CLASSID_HOLLOWSPHERE:
  154. initial_type = IDC_SPHERE_RADIO;
  155. initial_sphere_radius = ((Vector3HollowSphereRandomizer *)m_Randomizer)->Get_Radius ();
  156. initial_sphere_hollow = true;
  157. break;
  158. case Vector3Randomizer::CLASSID_SOLIDCYLINDER:
  159. initial_type = IDC_CYLINDER_RADIO;
  160. initial_cylinder_radius = ((Vector3SolidCylinderRandomizer *)m_Randomizer)->Get_Radius ();
  161. initial_cylinder_height = ((Vector3SolidCylinderRandomizer *)m_Randomizer)->Get_Height ();
  162. break;
  163. default:
  164. ASSERT (0);
  165. break;
  166. }
  167. }
  168. //
  169. // Initialize the box controls
  170. //
  171. ::Initialize_Spinner (m_BoxXSpin, initial_box.X, -10000, 10000);
  172. ::Initialize_Spinner (m_BoxYSpin, initial_box.Y, -10000, 10000);
  173. ::Initialize_Spinner (m_BoxZSpin, initial_box.Z, -10000, 10000);
  174. //
  175. // Initialize the sphere controls
  176. //
  177. ::Initialize_Spinner (m_SphereRadiusSpin, initial_sphere_radius, 0, 10000);
  178. SendDlgItemMessage (IDC_SPHERE_HOLLOW_CHECK, BM_SETCHECK, (WPARAM)initial_sphere_hollow);
  179. //
  180. // Initialize the cylinder controls
  181. //
  182. ::Initialize_Spinner (m_CylinderRadiusSpin, initial_cylinder_radius, 0, 10000);
  183. ::Initialize_Spinner (m_CylinderHeightSpin, initial_cylinder_height, 0, 10000);
  184. //
  185. // Check the appropriate radio
  186. //
  187. SendDlgItemMessage (initial_type, BM_SETCHECK, (WPARAM)TRUE);
  188. Update_Enable_State ();
  189. return TRUE;
  190. }
  191. ////////////////////////////////////////////////////////////////////
  192. //
  193. // OnBoxRadio
  194. //
  195. ////////////////////////////////////////////////////////////////////
  196. void
  197. VolumeRandomDialogClass::OnBoxRadio (void)
  198. {
  199. Update_Enable_State ();
  200. return ;
  201. }
  202. ////////////////////////////////////////////////////////////////////
  203. //
  204. // OnCylinderRadio
  205. //
  206. ////////////////////////////////////////////////////////////////////
  207. void
  208. VolumeRandomDialogClass::OnCylinderRadio (void)
  209. {
  210. Update_Enable_State ();
  211. return ;
  212. }
  213. ////////////////////////////////////////////////////////////////////
  214. //
  215. // OnSphereRadio
  216. //
  217. ////////////////////////////////////////////////////////////////////
  218. void
  219. VolumeRandomDialogClass::OnSphereRadio (void)
  220. {
  221. Update_Enable_State ();
  222. return ;
  223. }
  224. ////////////////////////////////////////////////////////////////////
  225. //
  226. // Update_Enable_State
  227. //
  228. ////////////////////////////////////////////////////////////////////
  229. void
  230. VolumeRandomDialogClass::Update_Enable_State (void)
  231. {
  232. bool enable_box_ctrls = (SendDlgItemMessage (IDC_BOX_RADIO, BM_GETCHECK) == 1);
  233. bool enable_sphere_ctrls = (SendDlgItemMessage (IDC_SPHERE_RADIO, BM_GETCHECK) == 1);
  234. bool enable_cylinder_ctrls = (SendDlgItemMessage (IDC_CYLINDER_RADIO, BM_GETCHECK) == 1);
  235. //
  236. // Update the box controls
  237. //
  238. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_BOX_X_EDIT), enable_box_ctrls);
  239. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_BOX_Y_EDIT), enable_box_ctrls);
  240. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_BOX_Z_EDIT), enable_box_ctrls);
  241. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_BOX_X_SPIN), enable_box_ctrls);
  242. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_BOX_Y_SPIN), enable_box_ctrls);
  243. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_BOX_Z_SPIN), enable_box_ctrls);
  244. //
  245. // Update the sphere controls
  246. //
  247. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SPHERE_RADIUS_EDIT), enable_sphere_ctrls);
  248. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SPHERE_RADIUS_SPIN), enable_sphere_ctrls);
  249. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SPHERE_HOLLOW_CHECK), enable_sphere_ctrls);
  250. //
  251. // Update the cylinder controls
  252. //
  253. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_CYLINDER_RADIUS_EDIT), enable_cylinder_ctrls);
  254. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_CYLINDER_RADIUS_SPIN), enable_cylinder_ctrls);
  255. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_CYLINDER_HEIGHT_EDIT), enable_cylinder_ctrls);
  256. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_CYLINDER_HEIGHT_SPIN), enable_cylinder_ctrls);
  257. return ;
  258. }
  259. ////////////////////////////////////////////////////////////////////
  260. //
  261. // OnNotify
  262. //
  263. ////////////////////////////////////////////////////////////////////
  264. BOOL
  265. VolumeRandomDialogClass::OnNotify
  266. (
  267. WPARAM wParam,
  268. LPARAM lParam,
  269. LRESULT *pResult
  270. )
  271. {
  272. //
  273. // Update the spinner control if necessary
  274. //
  275. NMHDR *pheader = (NMHDR *)lParam;
  276. if ((pheader != NULL) && (pheader->code == UDN_DELTAPOS)) {
  277. LPNMUPDOWN pupdown = (LPNMUPDOWN)lParam;
  278. ::Update_Spinner_Buddy (pheader->hwndFrom, pupdown->iDelta);
  279. }
  280. // Allow the base class to process this message
  281. return CDialog::OnNotify (wParam, lParam, pResult);
  282. }