EmitterLineGroupPropPage.cpp 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. // EmitterLineGroupPropPage.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "w3dview.h"
  22. #include "EmitterLineGroupPropPage.h"
  23. #include "w3d_file.h"
  24. #include "EmitterInstanceList.h"
  25. #include "Utils.h"
  26. #include "ColorBar.H"
  27. #include "ParticleBlurTimeKeyDialog.H"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. /////////////////////////////////////////////////////////////////////////////
  34. // EmitterLineGroupPropPageClass property page
  35. IMPLEMENT_DYNCREATE(EmitterLineGroupPropPageClass, CPropertyPage)
  36. EmitterLineGroupPropPageClass::EmitterLineGroupPropPageClass() :
  37. CPropertyPage(EmitterLineGroupPropPageClass::IDD),
  38. m_pEmitterList(NULL),
  39. m_bValid(true),
  40. m_BlurTimeBar(NULL),
  41. m_Lifetime(0),
  42. m_MinBlurTime(0),
  43. m_MaxBlurTime(1)
  44. {
  45. ::memset (&m_BlurTimes, 0, sizeof (m_BlurTimes));
  46. //{{AFX_DATA_INIT(EmitterLineGroupPropPageClass)
  47. // NOTE: the ClassWizard will add member initialization here
  48. //}}AFX_DATA_INIT
  49. Initialize();
  50. }
  51. EmitterLineGroupPropPageClass::~EmitterLineGroupPropPageClass()
  52. {
  53. // Free the blur time arrays
  54. SAFE_DELETE_ARRAY (m_BlurTimes.KeyTimes);
  55. SAFE_DELETE_ARRAY (m_BlurTimes.Values);
  56. }
  57. void EmitterLineGroupPropPageClass::DoDataExchange(CDataExchange* pDX)
  58. {
  59. CPropertyPage::DoDataExchange(pDX);
  60. //{{AFX_DATA_MAP(EmitterLineGroupPropPageClass)
  61. DDX_Control(pDX, IDC_BLUR_TIME_RANDOM_SPIN, m_BlurTimeRandomSpin);
  62. //}}AFX_DATA_MAP
  63. }
  64. BEGIN_MESSAGE_MAP(EmitterLineGroupPropPageClass, CPropertyPage)
  65. //{{AFX_MSG_MAP(EmitterLineGroupPropPageClass)
  66. //}}AFX_MSG_MAP
  67. END_MESSAGE_MAP()
  68. /////////////////////////////////////////////////////////////
  69. //
  70. // Initialize
  71. //
  72. /////////////////////////////////////////////////////////////
  73. void
  74. EmitterLineGroupPropPageClass::Initialize (void)
  75. {
  76. SAFE_DELETE_ARRAY (m_BlurTimes.KeyTimes);
  77. SAFE_DELETE_ARRAY (m_BlurTimes.Values);
  78. if (m_pEmitterList != NULL) {
  79. m_Lifetime = m_pEmitterList->Get_Lifetime ();
  80. m_pEmitterList->Get_Blur_Time_Keyframes (m_BlurTimes);
  81. //
  82. // Determine what the min and max blur times are
  83. //
  84. m_MaxBlurTime = WWMath::Max(m_BlurTimes.Start,1.0f);
  85. m_MinBlurTime = WWMath::Min(m_BlurTimes.Start,0.0f);
  86. for (UINT index = 0; index < m_BlurTimes.NumKeyFrames; index ++) {
  87. if (m_BlurTimes.Values[index] > m_MaxBlurTime) {
  88. m_MaxBlurTime = m_BlurTimes.Values[index];
  89. }
  90. if (m_BlurTimes.Values[index] < m_MinBlurTime) {
  91. m_MinBlurTime = m_BlurTimes.Values[index];
  92. }
  93. }
  94. }
  95. return ;
  96. }
  97. /////////////////////////////////////////////////////////////////////////////
  98. // EmitterLineGroupPropPageClass message handlers
  99. BOOL EmitterLineGroupPropPageClass::OnInitDialog()
  100. {
  101. CPropertyPage::OnInitDialog();
  102. //
  103. // Create the keyframe control
  104. //
  105. m_BlurTimeBar = ColorBarClass::Get_Color_Bar (::GetDlgItem (m_hWnd, IDC_BLUR_TIME_BAR));
  106. //
  107. // Setup the spinners
  108. //
  109. Initialize_Spinner (m_BlurTimeRandomSpin, m_BlurTimes.Rand, 0, 10000);
  110. //
  111. // Reset the keyframe control
  112. //
  113. m_BlurTimeBar->Set_Range (0, 1);
  114. m_BlurTimeBar->Clear_Points ();
  115. m_BlurTimeBar->Modify_Point (0, 0, 0, 0, 0);
  116. m_BlurTimeBar->Set_Graph_Percent (0, Normalize_Blur_Time(m_BlurTimes.Start));
  117. //
  118. // Load the current set of frame keyframes into the control
  119. //
  120. for (UINT index = 0; index < m_BlurTimes.NumKeyFrames; index ++) {
  121. m_BlurTimeBar->Modify_Point (index + 1,
  122. m_BlurTimes.KeyTimes[index] / m_Lifetime,
  123. 0,
  124. 0,
  125. 0);
  126. m_BlurTimeBar->Set_Graph_Percent (index + 1, Normalize_Blur_Time(m_BlurTimes.Values[index]));
  127. }
  128. return TRUE; // return TRUE unless you set the focus to a control
  129. // EXCEPTION: OCX Property Pages should return FALSE
  130. }
  131. /////////////////////////////////////////////////////////////
  132. //
  133. // Update_Blur_Times
  134. //
  135. /////////////////////////////////////////////////////////////
  136. void
  137. EmitterLineGroupPropPageClass::Update_Blur_Times (void)
  138. {
  139. float position = 0;
  140. float red = 0;
  141. float green = 0;
  142. float blue = 0;
  143. //
  144. // Setup the initial or 'starting' size
  145. //
  146. m_BlurTimes.Start = Denormalize_Blur_Time(m_BlurTimeBar->Get_Graph_Percent (0));
  147. //
  148. // Free the current setting arrays
  149. //
  150. SAFE_DELETE_ARRAY (m_BlurTimes.KeyTimes);
  151. SAFE_DELETE_ARRAY (m_BlurTimes.Values);
  152. //
  153. // Determine if we need to build the array of key frames or not
  154. //
  155. int count = m_BlurTimeBar->Get_Point_Count ();
  156. m_BlurTimes.NumKeyFrames = count - 1;
  157. if (count > 1) {
  158. m_BlurTimes.KeyTimes = new float[count - 1];
  159. m_BlurTimes.Values = new float[count - 1];
  160. //
  161. // Get all the key frames and add them to our structure
  162. //
  163. for (int index = 1; index < count; index ++) {
  164. m_BlurTimeBar->Get_Point (index, &position, &red, &green, &blue);
  165. m_BlurTimes.KeyTimes[index - 1] = position * m_Lifetime;
  166. m_BlurTimes.Values[index - 1] = Denormalize_Blur_Time(m_BlurTimeBar->Get_Graph_Percent (index) );
  167. }
  168. }
  169. return ;
  170. }
  171. /////////////////////////////////////////////////////////////
  172. //
  173. // On_Lifetime_Changed
  174. //
  175. /////////////////////////////////////////////////////////////
  176. void
  177. EmitterLineGroupPropPageClass::On_Lifetime_Changed (float lifetime)
  178. {
  179. if (m_Lifetime != lifetime) {
  180. float conversion = lifetime / m_Lifetime;
  181. //
  182. // Rescale the sizes
  183. //
  184. for (UINT index = 0; index < m_BlurTimes.NumKeyFrames; index ++) {
  185. m_BlurTimes.KeyTimes[index] *= conversion;
  186. }
  187. //
  188. // Update the emitter
  189. //
  190. m_pEmitterList->Set_Blur_Time_Keyframes (m_BlurTimes);
  191. m_Lifetime = lifetime;
  192. }
  193. return ;
  194. }
  195. BOOL EmitterLineGroupPropPageClass::OnCommand(WPARAM wParam, LPARAM lParam)
  196. {
  197. switch (LOWORD (wParam))
  198. {
  199. case IDC_BLUR_TIME_RANDOM_EDIT:
  200. {
  201. // Update the emitter
  202. if ((HIWORD (wParam) == EN_KILLFOCUS) &&
  203. SendDlgItemMessage (LOWORD (wParam), EM_GETMODIFY))
  204. {
  205. SendDlgItemMessage (LOWORD (wParam), EM_SETMODIFY, (WPARAM)0);
  206. m_BlurTimes.Rand = ::GetDlgItemFloat (m_hWnd, IDC_BLUR_TIME_RANDOM_EDIT);
  207. m_pEmitterList->Set_Blur_Time_Keyframes (m_BlurTimes);
  208. SetModified ();
  209. } else if (HIWORD (wParam) == EN_CHANGE) {
  210. SetModified ();
  211. }
  212. }
  213. break;
  214. }
  215. return CPropertyPage::OnCommand(wParam, lParam);
  216. }
  217. BOOL EmitterLineGroupPropPageClass::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  218. {
  219. CBR_NMHDR *color_bar_hdr = (CBR_NMHDR *)lParam;
  220. //
  221. // Update the spinner controls if necessary
  222. //
  223. NMHDR *pheader = (NMHDR *)lParam;
  224. if ((pheader != NULL) && (pheader->code == UDN_DELTAPOS)) {
  225. LPNMUPDOWN pupdown = (LPNMUPDOWN)lParam;
  226. ::Update_Spinner_Buddy (pheader->hwndFrom, pupdown->iDelta);
  227. }
  228. //
  229. // Which control sent the notification?
  230. //
  231. switch (color_bar_hdr->hdr.idFrom)
  232. {
  233. case IDC_BLUR_TIME_BAR:
  234. {
  235. if (color_bar_hdr->hdr.code == CBRN_DBLCLK_POINT) {
  236. //
  237. // Allow the user to edit the keyframe
  238. //
  239. float blur_time = Denormalize_Blur_Time(m_BlurTimeBar->Get_Graph_Percent (color_bar_hdr->key_index));
  240. ParticleBlurTimeKeyDialogClass dialog (blur_time, this);
  241. if (dialog.DoModal () == IDOK) {
  242. blur_time = dialog.Get_Blur_Time ();
  243. float norm_val = Normalize_Blur_Time(blur_time);
  244. m_BlurTimeBar->Set_Redraw (false);
  245. m_BlurTimeBar->Set_Graph_Percent (color_bar_hdr->key_index, norm_val);
  246. //
  247. // Determine if the user changed the 'max' or 'min' frame
  248. //
  249. float new_max = WWMath::Max(blur_time,1.0f);
  250. float new_min = WWMath::Min(blur_time,0.0f);
  251. int count = m_BlurTimeBar->Get_Point_Count ();
  252. for (int index = 0; index < count; index ++) {
  253. float tmp = Denormalize_Blur_Time(m_BlurTimeBar->Get_Graph_Percent (index) );
  254. if (tmp > new_max) {
  255. new_max = tmp;
  256. }
  257. if (tmp < new_min) {
  258. new_min = tmp;
  259. }
  260. }
  261. //
  262. // Renormalize the BlurTimeBar key frame points if necessary
  263. //
  264. if ((new_max != m_MaxBlurTime) || (new_min != m_MinBlurTime)) {
  265. int count = m_BlurTimeBar->Get_Point_Count ();
  266. for (int index = 0; index < count; index ++) {
  267. float frame = Denormalize_Blur_Time(m_BlurTimeBar->Get_Graph_Percent (index));
  268. float new_norm = Normalize_Blur_Time(frame,new_min,new_max);
  269. m_BlurTimeBar->Set_Graph_Percent (index, new_norm);
  270. }
  271. // Remember the new min and max
  272. m_MinBlurTime = new_min;
  273. m_MaxBlurTime = new_max;
  274. }
  275. m_BlurTimeBar->Set_Redraw (true);
  276. //
  277. // Update the emitter
  278. //
  279. Update_Blur_Times ();
  280. m_pEmitterList->Set_Blur_Time_Keyframes (m_BlurTimes);
  281. SetModified ();
  282. }
  283. } else if ((color_bar_hdr->hdr.code == CBRN_MOVING_POINT) ||
  284. (color_bar_hdr->hdr.code == CBRN_DELETED_POINT)) {
  285. //
  286. // Update the emitter
  287. //
  288. Update_Blur_Times ();
  289. m_pEmitterList->Set_Blur_Time_Keyframes (m_BlurTimes);
  290. SetModified ();
  291. }
  292. }
  293. break;
  294. case IDC_BLUR_TIME_RANDOM_SPIN:
  295. {
  296. // Update the emitter
  297. m_BlurTimes.Rand = ::GetDlgItemFloat (m_hWnd, IDC_BLUR_TIME_RANDOM_EDIT);
  298. m_pEmitterList->Set_Blur_Time_Keyframes (m_BlurTimes);
  299. SetModified ();
  300. }
  301. break;
  302. }
  303. return CPropertyPage::OnNotify(wParam, lParam, pResult);
  304. }
  305. float EmitterLineGroupPropPageClass::Normalize_Blur_Time(float blur)
  306. {
  307. return (blur - m_MinBlurTime) / (m_MaxBlurTime - m_MinBlurTime);
  308. }
  309. float EmitterLineGroupPropPageClass::Normalize_Blur_Time(float blur,float min,float max)
  310. {
  311. return (blur - min) / (max - min);
  312. }
  313. float EmitterLineGroupPropPageClass::Denormalize_Blur_Time(float normalized_val)
  314. {
  315. return normalized_val * (m_MaxBlurTime - m_MinBlurTime) + m_MinBlurTime;
  316. }