RingColorPropPage.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. // RingColorPropPage.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "w3dview.h"
  22. #include "ringcolorproppage.h"
  23. #include "opacitysettingsdialog.h"
  24. #include "colorutils.h"
  25. #include "utils.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. IMPLEMENT_DYNCREATE(RingColorPropPageClass, CPropertyPage)
  32. /////////////////////////////////////////////////////////////
  33. //
  34. // RingColorPropPageClass
  35. //
  36. /////////////////////////////////////////////////////////////
  37. RingColorPropPageClass::RingColorPropPageClass (RingRenderObjClass *ring)
  38. : m_RenderObj (ring),
  39. m_bValid (true),
  40. m_ColorBar (NULL),
  41. m_OpacityBar (NULL),
  42. CPropertyPage(RingColorPropPageClass::IDD)
  43. {
  44. //{{AFX_DATA_INIT(RingColorPropPageClass)
  45. // NOTE: the ClassWizard will add member initialization here
  46. //}}AFX_DATA_INIT
  47. Initialize ();
  48. return ;
  49. }
  50. /////////////////////////////////////////////////////////////
  51. //
  52. // ~RingColorPropPageClass
  53. //
  54. /////////////////////////////////////////////////////////////
  55. RingColorPropPageClass::~RingColorPropPageClass (void)
  56. {
  57. return ;
  58. }
  59. /////////////////////////////////////////////////////////////
  60. //
  61. // DoDataExchange
  62. //
  63. /////////////////////////////////////////////////////////////
  64. void
  65. RingColorPropPageClass::DoDataExchange (CDataExchange* pDX)
  66. {
  67. CPropertyPage::DoDataExchange(pDX);
  68. //{{AFX_DATA_MAP(RingColorPropPageClass)
  69. // NOTE: the ClassWizard will add DDX and DDV calls here
  70. //}}AFX_DATA_MAP
  71. return ;
  72. }
  73. BEGIN_MESSAGE_MAP(RingColorPropPageClass, CPropertyPage)
  74. //{{AFX_MSG_MAP(RingColorPropPageClass)
  75. ON_WM_DESTROY()
  76. //}}AFX_MSG_MAP
  77. END_MESSAGE_MAP()
  78. /////////////////////////////////////////////////////////////
  79. //
  80. // Initialize
  81. //
  82. /////////////////////////////////////////////////////////////
  83. void
  84. RingColorPropPageClass::Initialize (void)
  85. {
  86. m_ColorChannel.Reset ();
  87. m_OrigColorChannel.Reset ();
  88. m_AlphaChannel.Reset ();
  89. m_OrigAlphaChannel.Reset ();
  90. if (m_RenderObj != NULL) {
  91. m_ColorChannel = m_RenderObj->Get_Color_Channel ();
  92. m_OrigColorChannel = m_RenderObj->Get_Color_Channel ();
  93. m_AlphaChannel = m_RenderObj->Get_Alpha_Channel ();
  94. m_OrigAlphaChannel = m_RenderObj->Get_Alpha_Channel ();
  95. if (m_ColorChannel.Get_Key_Count () == 0) {
  96. m_ColorChannel.Add_Key (m_RenderObj->Get_Color (), 0);
  97. m_OrigColorChannel.Add_Key (m_RenderObj->Get_Color (), 0);
  98. }
  99. if (m_AlphaChannel.Get_Key_Count () == 0) {
  100. m_AlphaChannel.Add_Key (m_RenderObj->Get_Alpha (), 0);
  101. m_OrigAlphaChannel.Add_Key (m_RenderObj->Get_Alpha(), 0);
  102. }
  103. }
  104. return ;
  105. }
  106. /////////////////////////////////////////////////////////////
  107. //
  108. // OnInitDialog
  109. //
  110. /////////////////////////////////////////////////////////////
  111. BOOL
  112. RingColorPropPageClass::OnInitDialog (void)
  113. {
  114. // Allow the base class to process this message
  115. CPropertyPage::OnInitDialog ();
  116. m_ColorBar = ColorBarClass::Get_Color_Bar (::GetDlgItem (m_hWnd, IDC_COLOR_BAR));
  117. m_OpacityBar = ColorBarClass::Get_Color_Bar (::GetDlgItem (m_hWnd, IDC_OPACITY_BAR));
  118. //
  119. // Setup the color bars
  120. //
  121. m_ColorBar->Set_Range (0, 1);
  122. m_OpacityBar->Set_Range (0, 1);
  123. //
  124. // Set-up the color bar
  125. //
  126. for (int index = 0; index < m_OrigColorChannel.Get_Key_Count (); index ++) {
  127. m_ColorBar->Modify_Point ( index,
  128. m_OrigColorChannel[index].Get_Time (),
  129. m_OrigColorChannel[index].Get_Value ().X * 255,
  130. m_OrigColorChannel[index].Get_Value ().Y * 255,
  131. m_OrigColorChannel[index].Get_Value ().Z * 255);
  132. }
  133. //
  134. // Set-up the opacity bar
  135. //
  136. for (index = 0; index < m_OrigAlphaChannel.Get_Key_Count (); index ++) {
  137. m_OpacityBar->Modify_Point ( index,
  138. m_OrigAlphaChannel[index].Get_Time (),
  139. m_OrigAlphaChannel[index].Get_Value () * 255,
  140. m_OrigAlphaChannel[index].Get_Value () * 255,
  141. m_OrigAlphaChannel[index].Get_Value () * 255);
  142. }
  143. //
  144. // Ensure our initial 'current' values are up-to-date
  145. //
  146. Update_Colors ();
  147. Update_Opacities ();
  148. return TRUE;
  149. }
  150. /////////////////////////////////////////////////////////////
  151. //
  152. // OnApply
  153. //
  154. /////////////////////////////////////////////////////////////
  155. BOOL
  156. RingColorPropPageClass::OnApply (void)
  157. {
  158. // Allow the base class to process this message
  159. return CPropertyPage::OnApply ();
  160. }
  161. /////////////////////////////////////////////////////////////
  162. //
  163. // OnDestroy
  164. //
  165. /////////////////////////////////////////////////////////////
  166. void
  167. RingColorPropPageClass::OnDestroy (void)
  168. {
  169. CPropertyPage::OnDestroy();
  170. return ;
  171. }
  172. /////////////////////////////////////////////////////////////
  173. //
  174. // OnNotify
  175. //
  176. /////////////////////////////////////////////////////////////
  177. BOOL
  178. RingColorPropPageClass::OnNotify
  179. (
  180. WPARAM wParam,
  181. LPARAM lParam,
  182. LRESULT *pResult
  183. )
  184. {
  185. CBR_NMHDR *color_bar_hdr = (CBR_NMHDR *)lParam;
  186. //
  187. // Which control sent the notification?
  188. //
  189. switch (color_bar_hdr->hdr.idFrom)
  190. {
  191. case IDC_OPACITY_BAR:
  192. {
  193. if (color_bar_hdr->hdr.code == CBRN_DBLCLK_POINT) {
  194. //
  195. // Allow the user to edit the keyframe
  196. //
  197. OpacitySettingsDialogClass dialog (color_bar_hdr->red / 255, this);
  198. if (dialog.DoModal () == IDOK) {
  199. m_OpacityBar->Modify_Point ( color_bar_hdr->key_index,
  200. color_bar_hdr->position,
  201. dialog.Get_Opacity () * 255,
  202. dialog.Get_Opacity () * 255,
  203. dialog.Get_Opacity () * 255);
  204. //
  205. // Update the object
  206. //
  207. Update_Opacities ();
  208. SetModified ();
  209. }
  210. } else if ((color_bar_hdr->hdr.code == CBRN_MOVING_POINT) ||
  211. (color_bar_hdr->hdr.code == CBRN_DELETED_POINT))
  212. {
  213. //
  214. // Update the object
  215. //
  216. Update_Opacities ();
  217. SetModified ();
  218. }
  219. }
  220. break;
  221. case IDC_COLOR_BAR:
  222. {
  223. if (color_bar_hdr->hdr.code == CBRN_DBLCLK_POINT) {
  224. //
  225. // Allow the user to edit the keyframe
  226. //
  227. int red = (int)color_bar_hdr->red;
  228. int green = (int)color_bar_hdr->green;
  229. int blue = (int)color_bar_hdr->blue;
  230. if (Show_Color_Picker (&red, &green, &blue)) {
  231. m_ColorBar->Modify_Point ( color_bar_hdr->key_index,
  232. color_bar_hdr->position,
  233. red,
  234. green,
  235. blue);
  236. //
  237. // Update the object
  238. //
  239. Update_Colors ();
  240. SetModified ();
  241. }
  242. } else if ((color_bar_hdr->hdr.code == CBRN_MOVING_POINT) ||
  243. (color_bar_hdr->hdr.code == CBRN_DELETED_POINT))
  244. {
  245. //
  246. // Update the object
  247. //
  248. Update_Colors ();
  249. SetModified ();
  250. }
  251. }
  252. break;
  253. }
  254. return CPropertyPage::OnNotify (wParam, lParam, pResult);
  255. }
  256. /////////////////////////////////////////////////////////////
  257. //
  258. // OnCancel
  259. //
  260. /////////////////////////////////////////////////////////////
  261. void
  262. RingColorPropPageClass::OnCancel (void)
  263. {
  264. //
  265. // Reset the object to its original state
  266. //
  267. m_RenderObj->Set_Color_Channel (m_OrigColorChannel);
  268. m_RenderObj->Set_Alpha_Channel (m_OrigAlphaChannel);
  269. CPropertyPage::OnCancel ();
  270. return ;
  271. }
  272. /////////////////////////////////////////////////////////////
  273. //
  274. // Update_Opacities
  275. //
  276. /////////////////////////////////////////////////////////////
  277. void
  278. RingColorPropPageClass::Update_Opacities (void)
  279. {
  280. m_AlphaChannel.Reset ();
  281. float position = 0;
  282. float red = 0;
  283. float green = 0;
  284. float blue = 0;
  285. //
  286. // Build the channel
  287. //
  288. int count = m_OpacityBar->Get_Point_Count ();
  289. for (int index = 0; index < count; index ++) {
  290. m_OpacityBar->Get_Point (index, &position, &red, &green, &blue);
  291. m_AlphaChannel.Add_Key (red / 255, position);
  292. }
  293. //
  294. // Update the object
  295. //
  296. m_RenderObj->Set_Alpha_Channel (m_AlphaChannel);
  297. m_RenderObj->Restart_Animation ();
  298. return ;
  299. }
  300. /////////////////////////////////////////////////////////////
  301. //
  302. // Update_Colors
  303. //
  304. /////////////////////////////////////////////////////////////
  305. void
  306. RingColorPropPageClass::Update_Colors (void)
  307. {
  308. m_ColorChannel.Reset ();
  309. float position = 0;
  310. float red = 0;
  311. float green = 0;
  312. float blue = 0;
  313. //
  314. // Build the channel
  315. //
  316. int count = m_ColorBar->Get_Point_Count ();
  317. for (int index = 0; index < count; index ++) {
  318. m_ColorBar->Get_Point (index, &position, &red, &green, &blue);
  319. m_ColorChannel.Add_Key (Vector3 (red / 255, green / 255, blue / 255), position);
  320. }
  321. //
  322. // Update the object
  323. //
  324. m_RenderObj->Set_Color_Channel (m_ColorChannel);
  325. m_RenderObj->Restart_Animation ();
  326. return ;
  327. }