EmitterSizePropPage.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. // EmitterSizePropPage.cpp : implementation file
  19. //
  20. #include "Stdafx.H"
  21. #include "W3dview.H"
  22. #include "EmitterSizePropPage.H"
  23. #include "Utils.H"
  24. #include "ParticleSizeDialog.H"
  25. #include "EmitterInstanceList.H"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. /////////////////////////////////////////////////////////////////////////////
  32. // EmitterSizePropPageClass property page
  33. IMPLEMENT_DYNCREATE(EmitterSizePropPageClass, CPropertyPage)
  34. /////////////////////////////////////////////////////////////
  35. //
  36. // EmitterSizePropPageClass
  37. //
  38. /////////////////////////////////////////////////////////////
  39. EmitterSizePropPageClass::EmitterSizePropPageClass (EmitterInstanceListClass *pemitter)
  40. : m_pEmitterList (NULL),
  41. m_bValid (true),
  42. m_SizeBar (NULL),
  43. m_Lifetime (0),
  44. CPropertyPage(EmitterSizePropPageClass::IDD)
  45. {
  46. ::memset (&m_OrigSizes, 0, sizeof (m_OrigSizes));
  47. ::memset (&m_CurrentSizes, 0, sizeof (m_CurrentSizes));
  48. //{{AFX_DATA_INIT(EmitterSizePropPageClass)
  49. // NOTE: the ClassWizard will add member initialization here
  50. //}}AFX_DATA_INIT
  51. Initialize ();
  52. return ;
  53. }
  54. /////////////////////////////////////////////////////////////
  55. //
  56. // ~EmitterSizePropPageClass
  57. //
  58. /////////////////////////////////////////////////////////////
  59. EmitterSizePropPageClass::~EmitterSizePropPageClass (void)
  60. {
  61. // Free the original setting arrays
  62. SAFE_DELETE_ARRAY (m_OrigSizes.KeyTimes);
  63. SAFE_DELETE_ARRAY (m_OrigSizes.Values);
  64. // Free the current setting arrays
  65. SAFE_DELETE_ARRAY (m_CurrentSizes.KeyTimes);
  66. SAFE_DELETE_ARRAY (m_CurrentSizes.Values);
  67. return ;
  68. }
  69. /////////////////////////////////////////////////////////////
  70. //
  71. // DoDataExchange
  72. //
  73. /////////////////////////////////////////////////////////////
  74. void
  75. EmitterSizePropPageClass::DoDataExchange(CDataExchange* pDX)
  76. {
  77. CPropertyPage::DoDataExchange(pDX);
  78. //{{AFX_DATA_MAP(EmitterSizePropPageClass)
  79. DDX_Control(pDX, IDC_SIZE_RANDOM_SPIN, m_SizeRandomSpin);
  80. //}}AFX_DATA_MAP
  81. }
  82. BEGIN_MESSAGE_MAP(EmitterSizePropPageClass, CPropertyPage)
  83. //{{AFX_MSG_MAP(EmitterSizePropPageClass)
  84. //}}AFX_MSG_MAP
  85. END_MESSAGE_MAP()
  86. /////////////////////////////////////////////////////////////
  87. //
  88. // Initialize
  89. //
  90. /////////////////////////////////////////////////////////////
  91. void
  92. EmitterSizePropPageClass::Initialize (void)
  93. {
  94. SAFE_DELETE_ARRAY (m_OrigSizes.KeyTimes);
  95. SAFE_DELETE_ARRAY (m_OrigSizes.Values);
  96. SAFE_DELETE_ARRAY (m_CurrentSizes.KeyTimes);
  97. SAFE_DELETE_ARRAY (m_CurrentSizes.Values);
  98. if (m_pEmitterList != NULL) {
  99. m_Lifetime = m_pEmitterList->Get_Lifetime ();
  100. m_pEmitterList->Get_Size_Keyframes (m_OrigSizes);
  101. m_pEmitterList->Get_Size_Keyframes (m_CurrentSizes);
  102. //
  103. // Determine what the largest size is
  104. //
  105. m_MaxSize = m_OrigSizes.Start;
  106. for (UINT index = 0; index < m_OrigSizes.NumKeyFrames; index ++) {
  107. if (m_OrigSizes.Values[index] > m_MaxSize) {
  108. m_MaxSize = m_OrigSizes.Values[index];
  109. }
  110. }
  111. }
  112. return ;
  113. }
  114. /////////////////////////////////////////////////////////////
  115. //
  116. // OnInitDialog
  117. //
  118. /////////////////////////////////////////////////////////////
  119. BOOL
  120. EmitterSizePropPageClass::OnInitDialog (void)
  121. {
  122. // Allow the base class to process this message
  123. CPropertyPage::OnInitDialog ();
  124. m_SizeBar = ColorBarClass::Get_Color_Bar (::GetDlgItem (m_hWnd, IDC_SIZE_BAR));
  125. m_SizeBar->Set_Range (0, 1);
  126. //
  127. // Setup the spinners
  128. //
  129. Initialize_Spinner (m_SizeRandomSpin, m_OrigSizes.Rand, 0, 10000);
  130. //
  131. // Reset the color bars
  132. //
  133. m_SizeBar->Set_Range (0, 1);
  134. m_SizeBar->Clear_Points ();
  135. m_SizeBar->Modify_Point (0, 0, 0, 0, 0);
  136. m_SizeBar->Set_Graph_Percent (0, m_OrigSizes.Start / m_MaxSize);
  137. //
  138. // Set-up the color bar
  139. //
  140. for (UINT index = 0; index < m_OrigSizes.NumKeyFrames; index ++) {
  141. m_SizeBar->Modify_Point (index + 1,
  142. m_OrigSizes.KeyTimes[index] / m_Lifetime,
  143. 0,
  144. 0,
  145. 0);
  146. m_SizeBar->Set_Graph_Percent (index + 1, m_OrigSizes.Values[index] / m_MaxSize);
  147. }
  148. return TRUE;
  149. }
  150. /////////////////////////////////////////////////////////////
  151. //
  152. // OnApply
  153. //
  154. /////////////////////////////////////////////////////////////
  155. BOOL
  156. EmitterSizePropPageClass::OnApply (void)
  157. {
  158. /*SAFE_DELETE_ARRAY (m_OrigSizes.KeyTimes);
  159. SAFE_DELETE_ARRAY (m_OrigSizes.Values);
  160. //
  161. // Make the current values from the emitter the default values.
  162. //
  163. m_pEmitterList->Get_Size_Key_Frames (m_OrigSizes);*/
  164. // Allow the base class to process this message
  165. return CPropertyPage::OnApply ();
  166. }
  167. /////////////////////////////////////////////////////////////
  168. //
  169. // OnNotify
  170. //
  171. /////////////////////////////////////////////////////////////
  172. BOOL
  173. EmitterSizePropPageClass::OnNotify
  174. (
  175. WPARAM wParam,
  176. LPARAM lParam,
  177. LRESULT *pResult
  178. )
  179. {
  180. CBR_NMHDR *color_bar_hdr = (CBR_NMHDR *)lParam;
  181. //
  182. // Update the spinner controls if necessary
  183. //
  184. NMHDR *pheader = (NMHDR *)lParam;
  185. if ((pheader != NULL) && (pheader->code == UDN_DELTAPOS)) {
  186. LPNMUPDOWN pupdown = (LPNMUPDOWN)lParam;
  187. ::Update_Spinner_Buddy (pheader->hwndFrom, pupdown->iDelta);
  188. }
  189. //
  190. // Which control sent the notification?
  191. //
  192. switch (color_bar_hdr->hdr.idFrom)
  193. {
  194. case IDC_SIZE_BAR:
  195. {
  196. if (color_bar_hdr->hdr.code == CBRN_DBLCLK_POINT) {
  197. //
  198. // Allow the user to edit the keyframe
  199. //
  200. float size = m_SizeBar->Get_Graph_Percent (color_bar_hdr->key_index) * m_MaxSize;
  201. ParticleSizeDialogClass dialog (size, this);
  202. if (dialog.DoModal () == IDOK) {
  203. size = dialog.Get_Size ();
  204. m_SizeBar->Set_Redraw (false);
  205. m_SizeBar->Set_Graph_Percent (color_bar_hdr->key_index, size / m_MaxSize);
  206. //
  207. // Determine if the user changed the 'max' size
  208. //
  209. float new_max = size;
  210. int count = m_SizeBar->Get_Point_Count ();
  211. for (int index = 0; index < count; index ++) {
  212. float size = m_SizeBar->Get_Graph_Percent (index) * m_MaxSize;
  213. if (size > new_max) {
  214. new_max = size;
  215. }
  216. }
  217. //
  218. // Rescale the key frame points if necessary
  219. //
  220. if (new_max != m_MaxSize) {
  221. int count = m_SizeBar->Get_Point_Count ();
  222. for (int index = 0; index < count; index ++) {
  223. float percent = m_SizeBar->Get_Graph_Percent (index);
  224. m_SizeBar->Set_Graph_Percent (index, (percent * m_MaxSize) / new_max);
  225. }
  226. // Remember the new size maximum
  227. m_MaxSize = new_max;
  228. }
  229. m_SizeBar->Set_Redraw (true);
  230. //
  231. // Update the emitter
  232. //
  233. Update_Sizes ();
  234. m_pEmitterList->Set_Size_Keyframes (m_CurrentSizes);
  235. SetModified ();
  236. }
  237. } else if ((color_bar_hdr->hdr.code == CBRN_MOVING_POINT) ||
  238. (color_bar_hdr->hdr.code == CBRN_DELETED_POINT)) {
  239. //
  240. // Update the emitter
  241. //
  242. Update_Sizes ();
  243. m_pEmitterList->Set_Size_Keyframes (m_CurrentSizes);
  244. SetModified ();
  245. }
  246. }
  247. break;
  248. case IDC_SIZE_RANDOM_SPIN:
  249. {
  250. // Update the emitter
  251. m_CurrentSizes.Rand = ::GetDlgItemFloat (m_hWnd, IDC_SIZE_RANDOM_EDIT);
  252. m_pEmitterList->Set_Size_Keyframes (m_CurrentSizes);
  253. SetModified ();
  254. }
  255. break;
  256. }
  257. return CPropertyPage::OnNotify (wParam, lParam, pResult);
  258. }
  259. /////////////////////////////////////////////////////////////
  260. //
  261. // Update_Sizes
  262. //
  263. /////////////////////////////////////////////////////////////
  264. void
  265. EmitterSizePropPageClass::Update_Sizes (void)
  266. {
  267. float position = 0;
  268. float red = 0;
  269. float green = 0;
  270. float blue = 0;
  271. //
  272. // Setup the initial or 'starting' size
  273. //
  274. m_CurrentSizes.Start = m_SizeBar->Get_Graph_Percent (0) * m_MaxSize;
  275. //
  276. // Free the current setting arrays
  277. //
  278. SAFE_DELETE_ARRAY (m_CurrentSizes.KeyTimes);
  279. SAFE_DELETE_ARRAY (m_CurrentSizes.Values);
  280. //
  281. // Determine if we need to build the array of key frames or not
  282. //
  283. int count = m_SizeBar->Get_Point_Count ();
  284. m_CurrentSizes.NumKeyFrames = count - 1;
  285. if (count > 1) {
  286. m_CurrentSizes.KeyTimes = new float[count - 1];
  287. m_CurrentSizes.Values = new float[count - 1];
  288. //
  289. // Get all the size key frames and add them to our structure
  290. //
  291. for (int index = 1; index < count; index ++) {
  292. m_SizeBar->Get_Point (index, &position, &red, &green, &blue);
  293. m_CurrentSizes.KeyTimes[index - 1] = position * m_Lifetime;
  294. m_CurrentSizes.Values[index - 1] = m_SizeBar->Get_Graph_Percent (index) * m_MaxSize;
  295. }
  296. }
  297. return ;
  298. }
  299. /////////////////////////////////////////////////////////////
  300. //
  301. // OnCommand
  302. //
  303. /////////////////////////////////////////////////////////////
  304. BOOL
  305. EmitterSizePropPageClass::OnCommand
  306. (
  307. WPARAM wParam,
  308. LPARAM lParam
  309. )
  310. {
  311. switch (LOWORD (wParam))
  312. {
  313. case IDC_SIZE_RANDOM_EDIT:
  314. {
  315. // Update the emitter
  316. if ((HIWORD (wParam) == EN_KILLFOCUS) &&
  317. SendDlgItemMessage (LOWORD (wParam), EM_GETMODIFY)) {
  318. SendDlgItemMessage (LOWORD (wParam), EM_SETMODIFY, (WPARAM)0);
  319. m_CurrentSizes.Rand = ::GetDlgItemFloat (m_hWnd, IDC_SIZE_RANDOM_EDIT);
  320. m_pEmitterList->Set_Size_Keyframes (m_CurrentSizes);
  321. SetModified ();
  322. } else if (HIWORD (wParam) == EN_CHANGE) {
  323. SetModified ();
  324. }
  325. }
  326. break;
  327. }
  328. return CPropertyPage::OnCommand (wParam, lParam);
  329. }
  330. /////////////////////////////////////////////////////////////
  331. //
  332. // On_Lifetime_Changed
  333. //
  334. /////////////////////////////////////////////////////////////
  335. void
  336. EmitterSizePropPageClass::On_Lifetime_Changed (float lifetime)
  337. {
  338. if (m_Lifetime != lifetime) {
  339. float conversion = lifetime / m_Lifetime;
  340. //
  341. // Rescale the sizes
  342. //
  343. for (UINT index = 0; index < m_CurrentSizes.NumKeyFrames; index ++) {
  344. m_CurrentSizes.KeyTimes[index] *= conversion;
  345. }
  346. //
  347. // Update the emitter
  348. //
  349. m_pEmitterList->Set_Size_Keyframes (m_CurrentSizes);
  350. m_Lifetime = lifetime;
  351. }
  352. return ;
  353. }