LightSettingsPage.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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 : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/LightSettingsPage.cpp $Modtime:: $*
  25. * *
  26. * $Revision:: 2 $*
  27. * *
  28. *---------------------------------------------------------------------------------------------*
  29. * Functions: *
  30. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  31. #include "StdAfx.H"
  32. #include "LevelEdit.H"
  33. #include "LightSettingsPage.H"
  34. #include "Utils.H"
  35. #include "ColorSelectionDialog.H"
  36. #ifdef _DEBUG
  37. #define new DEBUG_NEW
  38. #undef THIS_FILE
  39. static char THIS_FILE[] = __FILE__;
  40. #endif
  41. /////////////////////////////////////////////////////////////////////////////
  42. //
  43. // LightSettingsPageClass
  44. //
  45. LightSettingsPageClass::LightSettingsPageClass (void)
  46. : m_pLight (NULL),
  47. DockableFormClass (LightSettingsPageClass::IDD)
  48. {
  49. return ;
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. //
  53. // LightSettingsPageClass
  54. //
  55. LightSettingsPageClass::LightSettingsPageClass (LightSettingsClass *plight)
  56. : m_pLight (plight),
  57. DockableFormClass (LightSettingsPageClass::IDD)
  58. {
  59. //{{AFX_DATA_INIT(LightSettingsPageClass)
  60. // NOTE: the ClassWizard will add member initialization here
  61. //}}AFX_DATA_INIT
  62. return ;
  63. }
  64. /////////////////////////////////////////////////////////////////////////////
  65. //
  66. // ~LightSettingsPageClass
  67. //
  68. LightSettingsPageClass::~LightSettingsPageClass (void)
  69. {
  70. return;
  71. }
  72. /////////////////////////////////////////////////////////////////////////////
  73. //
  74. // DoDataExchange
  75. //
  76. void
  77. LightSettingsPageClass::DoDataExchange (CDataExchange* pDX)
  78. {
  79. DockableFormClass::DoDataExchange(pDX);
  80. //{{AFX_DATA_MAP(LightSettingsPageClass)
  81. DDX_Control(pDX, IDC_INTENSITY_SLIDER, m_IntensitySlider);
  82. DDX_Control(pDX, IDC_OUTER_ATTEN_SLIDER, m_OuterAttenSlider);
  83. DDX_Control(pDX, IDC_INNER_ATTEN_SLIDER, m_InnerAttenSlider);
  84. //}}AFX_DATA_MAP
  85. return ;
  86. }
  87. BEGIN_MESSAGE_MAP(LightSettingsPageClass, DockableFormClass)
  88. //{{AFX_MSG_MAP(LightSettingsPageClass)
  89. ON_WM_DRAWITEM()
  90. ON_EN_CHANGE(IDC_INNER_ATTEN_EDIT, OnChangeInnerAttenEdit)
  91. ON_EN_CHANGE(IDC_OUTER_ATTEN_EDIT, OnChangeOuterAttenEdit)
  92. ON_WM_HSCROLL()
  93. ON_EN_KILLFOCUS(IDC_OUTER_ATTEN_EDIT, OnKillfocusOuterAttenEdit)
  94. ON_EN_KILLFOCUS(IDC_INNER_ATTEN_EDIT, OnKillfocusInnerAttenEdit)
  95. ON_BN_CLICKED(IDC_AMBIENT_BUTTON, OnAmbientButton)
  96. ON_BN_CLICKED(IDC_DIFFUSE_BUTTON, OnDiffuseButton)
  97. ON_BN_CLICKED(IDC_SPECULAR_BUTTON, OnSpecularButton)
  98. //}}AFX_MSG_MAP
  99. END_MESSAGE_MAP()
  100. /////////////////////////////////////////////////////////////////////////////
  101. // LightSettingsPageClass diagnostics
  102. #ifdef _DEBUG
  103. void LightSettingsPageClass::AssertValid() const
  104. {
  105. DockableFormClass::AssertValid();
  106. }
  107. void LightSettingsPageClass::Dump(CDumpContext& dc) const
  108. {
  109. DockableFormClass::Dump(dc);
  110. }
  111. #endif //_DEBUG
  112. /////////////////////////////////////////////////////////////////////////////
  113. //
  114. // HandleInitDialog
  115. //
  116. void
  117. LightSettingsPageClass::HandleInitDialog (void)
  118. {
  119. ASSERT (m_pLight != NULL);
  120. // Record the light's original settings so we can
  121. // restore them if we need to.
  122. m_OrigAmbient = m_pLight->Get_Ambient_Color ();
  123. m_OrigDiffuse = m_pLight->Get_Diffuse_Color ();
  124. m_OrigSpecular = m_pLight->Get_Specular_Color ();
  125. m_OrigIntensity = m_pLight->Get_Intensity ();
  126. m_pLight->Get_Attenuation (m_OrigInnerAttenuation, m_OrigOuterAttenuation);
  127. // Set up the sliders
  128. m_IntensitySlider.SetRange (0, 100);
  129. m_InnerAttenSlider.SetRange (0, 100000);
  130. m_OuterAttenSlider.SetRange (0, 100000);
  131. m_IntensitySlider.SetPos (int(m_OrigIntensity * 100.00F));
  132. m_InnerAttenSlider.SetPos (int(m_OrigInnerAttenuation * 100.00F));
  133. m_OuterAttenSlider.SetPos (int(m_OrigOuterAttenuation * 100.00F));
  134. // Put the attenuation values into the edit fields
  135. ::SetDlgItemFloat (m_hWnd, IDC_INNER_ATTEN_EDIT, m_OrigInnerAttenuation);
  136. ::SetDlgItemFloat (m_hWnd, IDC_OUTER_ATTEN_EDIT, m_OrigOuterAttenuation);
  137. return ;
  138. }
  139. /////////////////////////////////////////////////////////////////////////////
  140. //
  141. // Apply_Changes
  142. //
  143. bool
  144. LightSettingsPageClass::Apply_Changes (void)
  145. {
  146. // Return true to allow the dialog to close
  147. return true;
  148. }
  149. /////////////////////////////////////////////////////////////////////////////
  150. //
  151. // Discard_Changes
  152. //
  153. void
  154. LightSettingsPageClass::Discard_Changes (void)
  155. {
  156. // Give the original values back to the light
  157. m_pLight->Set_Ambient_Color (m_OrigAmbient);
  158. m_pLight->Set_Diffuse_Color (m_OrigDiffuse);
  159. m_pLight->Set_Specular_Color (m_OrigSpecular);
  160. m_pLight->Set_Intensity (m_OrigIntensity);
  161. m_pLight->Set_Attenuation (m_OrigInnerAttenuation, m_OrigOuterAttenuation);
  162. // Now update the light with these changes
  163. m_pLight->Update_Light ();
  164. return ;
  165. }
  166. /////////////////////////////////////////////////////////////////////////////
  167. //
  168. // OnDrawItem
  169. //
  170. void
  171. LightSettingsPageClass::OnDrawItem
  172. (
  173. int nIDCtl,
  174. LPDRAWITEMSTRUCT lpDrawItemStruct
  175. )
  176. {
  177. // Determine what color to paint the button
  178. Vector3 color (0, 0, 0);
  179. if (nIDCtl == IDC_AMBIENT_BUTTON) {
  180. color = m_pLight->Get_Ambient_Color ();
  181. } else if (nIDCtl == IDC_DIFFUSE_BUTTON) {
  182. color = m_pLight->Get_Diffuse_Color ();
  183. } else if (nIDCtl == IDC_SPECULAR_BUTTON) {
  184. color = m_pLight->Get_Specular_Color ();
  185. }
  186. // Determine what state to draw the button in (pushed or normal)
  187. UINT state = DFCS_BUTTONPUSH | DFCS_ADJUSTRECT;
  188. if (lpDrawItemStruct->itemState & ODS_SELECTED) {
  189. state |= DFCS_PUSHED;
  190. }
  191. // Draw the button's outline
  192. CRect rect = lpDrawItemStruct->rcItem;
  193. ::DrawFrameControl (lpDrawItemStruct->hDC, rect, DFC_BUTTON, state);
  194. // Fill the button with the appropriate color
  195. CDC temp_dc;
  196. temp_dc.Attach (lpDrawItemStruct->hDC);
  197. temp_dc.FillSolidRect (&rect, RGB (int(color.X * 255), int(color.Y * 255), int(color.Z * 255)));
  198. temp_dc.Detach ();
  199. // Draw the focus rectangle if necessary
  200. if (lpDrawItemStruct->itemState & ODS_FOCUS) {
  201. ::DrawFocusRect (lpDrawItemStruct->hDC, &rect);
  202. }
  203. // Allow the base class to process this message
  204. //DockableFormClass::OnDrawItem (nIDCtl, lpDrawItemStruct);
  205. return;
  206. }
  207. /////////////////////////////////////////////////////////////////////////////
  208. //
  209. // OnChangeInnerAttenEdit
  210. //
  211. void
  212. LightSettingsPageClass::OnChangeInnerAttenEdit (void)
  213. {
  214. float inner = ::GetDlgItemFloat (m_hWnd, IDC_INNER_ATTEN_EDIT);
  215. float outer = ::GetDlgItemFloat (m_hWnd, IDC_OUTER_ATTEN_EDIT);
  216. m_InnerAttenSlider.SetPos (int(inner * 100.00F));
  217. // Update the light with these new settings
  218. m_pLight->Set_Attenuation (inner, outer);
  219. m_pLight->Update_Light ();
  220. ::Refresh_Main_View ();
  221. return ;
  222. }
  223. /////////////////////////////////////////////////////////////////////////////
  224. //
  225. // OnChangeOuterAttenEdit
  226. //
  227. void
  228. LightSettingsPageClass::OnChangeOuterAttenEdit (void)
  229. {
  230. float inner = ::GetDlgItemFloat (m_hWnd, IDC_INNER_ATTEN_EDIT);
  231. float outer = ::GetDlgItemFloat (m_hWnd, IDC_OUTER_ATTEN_EDIT);
  232. m_OuterAttenSlider.SetPos (int(outer * 100.00F));
  233. // Update the light with these new settings
  234. m_pLight->Set_Attenuation (inner, outer);
  235. m_pLight->Update_Light ();
  236. ::Refresh_Main_View ();
  237. return ;
  238. }
  239. /////////////////////////////////////////////////////////////////////////////
  240. //
  241. // OnChangeOuterAttenEdit
  242. //
  243. void
  244. LightSettingsPageClass::OnHScroll
  245. (
  246. UINT nSBCode,
  247. UINT nPos,
  248. CScrollBar *pScrollBar
  249. )
  250. {
  251. if (pScrollBar == GetDlgItem (IDC_INTENSITY_SLIDER)) {
  252. // Pass the new intensity onto the UI and the light
  253. int position = m_IntensitySlider.GetPos ();
  254. m_pLight->Set_Intensity ((((float)position) / 100.00F));
  255. } else if (pScrollBar == GetDlgItem (IDC_OUTER_ATTEN_SLIDER)) {
  256. // Determine the radii of the inner and outer attenuation spheres
  257. int position = m_OuterAttenSlider.GetPos ();
  258. float outer = (((float)position) / 100.00F);
  259. float inner = ::GetDlgItemFloat (m_hWnd, IDC_INNER_ATTEN_EDIT);
  260. if (outer < inner) {
  261. outer = inner;
  262. m_OuterAttenSlider.SetPos (int(outer * 100.00F));
  263. }
  264. // Reset the UI and the light to match these settings
  265. ::SetDlgItemFloat (m_hWnd, IDC_OUTER_ATTEN_EDIT, outer);
  266. m_pLight->Set_Attenuation (inner, outer);
  267. } else {
  268. // Determine the radii of the inner and outer attenuation spheres
  269. int position = m_InnerAttenSlider.GetPos ();
  270. float inner = (((float)position) / 100.00F);
  271. float outer = ::GetDlgItemFloat (m_hWnd, IDC_OUTER_ATTEN_EDIT);
  272. if (outer < inner) {
  273. inner = outer;
  274. m_InnerAttenSlider.SetPos (int(inner * 100.00F));
  275. }
  276. // Reset the UI and the light to match these settings
  277. ::SetDlgItemFloat (m_hWnd, IDC_INNER_ATTEN_EDIT, inner);
  278. m_pLight->Set_Attenuation (inner, outer);
  279. }
  280. // Now update the light with these changes
  281. m_pLight->Update_Light ();
  282. // Make sure the scene is painted
  283. ::Refresh_Main_View ();
  284. // Allow the base class to process this message
  285. DockableFormClass::OnHScroll (nSBCode, nPos, pScrollBar);
  286. return ;
  287. }
  288. /////////////////////////////////////////////////////////////////////////////
  289. //
  290. // OnKillfocusOuterAttenEdit
  291. //
  292. void
  293. LightSettingsPageClass::OnKillfocusOuterAttenEdit (void)
  294. {
  295. float inner = ::GetDlgItemFloat (m_hWnd, IDC_INNER_ATTEN_EDIT);
  296. float outer = ::GetDlgItemFloat (m_hWnd, IDC_OUTER_ATTEN_EDIT);
  297. // If we need to normalize the data, then do so now...
  298. if (outer < inner) {
  299. // Reset the UI
  300. outer = inner;
  301. ::SetDlgItemFloat (m_hWnd, IDC_OUTER_ATTEN_EDIT, outer);
  302. m_OuterAttenSlider.SetPos (int(outer * 100.00F));
  303. // Update the light with these new settings
  304. m_pLight->Set_Attenuation (inner, outer);
  305. m_pLight->Update_Light ();
  306. ::Refresh_Main_View ();
  307. }
  308. return ;
  309. }
  310. /////////////////////////////////////////////////////////////////////////////
  311. //
  312. // OnKillfocusInnerAttenEdit
  313. //
  314. void
  315. LightSettingsPageClass::OnKillfocusInnerAttenEdit (void)
  316. {
  317. float inner = ::GetDlgItemFloat (m_hWnd, IDC_INNER_ATTEN_EDIT);
  318. float outer = ::GetDlgItemFloat (m_hWnd, IDC_OUTER_ATTEN_EDIT);
  319. // If we need to normalize the data, then do so now...
  320. if (outer < inner) {
  321. // Reset the UI
  322. inner = outer;
  323. ::SetDlgItemFloat (m_hWnd, IDC_INNER_ATTEN_EDIT, inner);
  324. m_InnerAttenSlider.SetPos (int(outer * 100.00F));
  325. // Update the light with these new settings
  326. m_pLight->Set_Attenuation (inner, outer);
  327. m_pLight->Update_Light ();
  328. ::Refresh_Main_View ();
  329. }
  330. return ;
  331. }
  332. /////////////////////////////////////////////////////////////////////////////
  333. //
  334. // OnAmbientButton
  335. //
  336. void
  337. LightSettingsPageClass::OnAmbientButton (void)
  338. {
  339. // Display a dialog to the user that will allow them to select a color
  340. ColorSelectionDialogClass dialog (m_pLight->Get_Ambient_Color (), this);
  341. if (dialog.DoModal () == IDOK) {
  342. m_pLight->Set_Ambient_Color (dialog.Get_Color ());
  343. m_pLight->Update_Light ();
  344. // Repaint the views
  345. ::InvalidateRect (::GetDlgItem (m_hWnd, IDC_AMBIENT_BUTTON), NULL, TRUE);
  346. ::Refresh_Main_View ();
  347. }
  348. return ;
  349. }
  350. /////////////////////////////////////////////////////////////////////////////
  351. //
  352. // OnDiffuseButton
  353. //
  354. void
  355. LightSettingsPageClass::OnDiffuseButton (void)
  356. {
  357. // Display a dialog to the user that will allow them to select a color
  358. ColorSelectionDialogClass dialog (m_pLight->Get_Diffuse_Color (), this);
  359. if (dialog.DoModal () == IDOK) {
  360. m_pLight->Set_Diffuse_Color (dialog.Get_Color ());
  361. m_pLight->Update_Light ();
  362. // Repaint the views
  363. ::InvalidateRect (::GetDlgItem (m_hWnd, IDC_DIFFUSE_BUTTON), NULL, TRUE);
  364. ::Refresh_Main_View ();
  365. }
  366. return;
  367. }
  368. /////////////////////////////////////////////////////////////////////////////
  369. //
  370. // OnSpecularButton
  371. //
  372. void
  373. LightSettingsPageClass::OnSpecularButton (void)
  374. {
  375. // Display a dialog to the user that will allow them to select a color
  376. ColorSelectionDialogClass dialog (m_pLight->Get_Specular_Color (), this);
  377. if (dialog.DoModal () == IDOK) {
  378. m_pLight->Set_Specular_Color (dialog.Get_Color ());
  379. m_pLight->Update_Light ();
  380. // Repaint the views
  381. ::InvalidateRect (::GetDlgItem (m_hWnd, IDC_SPECULAR_BUTTON), NULL, TRUE);
  382. ::Refresh_Main_View ();
  383. }
  384. return;
  385. }