AmbientLightDialog.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. // AmbientLightDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "W3DView.h"
  22. #include "AmbientLightDialog.h"
  23. #include "MainFrm.H"
  24. #include "W3DViewDoc.H"
  25. #include "ViewerScene.H"
  26. #include "Utils.H"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CAmbientLightDialog dialog
  34. CAmbientLightDialog::CAmbientLightDialog(CWnd* pParent /*=NULL*/)
  35. : CDialog(CAmbientLightDialog::IDD, pParent)
  36. {
  37. //{{AFX_DATA_INIT(CAmbientLightDialog)
  38. // NOTE: the ClassWizard will add member initialization here
  39. //}}AFX_DATA_INIT
  40. }
  41. void CAmbientLightDialog::DoDataExchange(CDataExchange* pDX)
  42. {
  43. CDialog::DoDataExchange(pDX);
  44. //{{AFX_DATA_MAP(CAmbientLightDialog)
  45. DDX_Control(pDX, IDC_SLIDER_BLUE, m_blueSlider);
  46. DDX_Control(pDX, IDC_SLIDER_GREEN, m_greenSlider);
  47. DDX_Control(pDX, IDC_SLIDER_RED, m_redSlider);
  48. //}}AFX_DATA_MAP
  49. }
  50. BEGIN_MESSAGE_MAP(CAmbientLightDialog, CDialog)
  51. //{{AFX_MSG_MAP(CAmbientLightDialog)
  52. ON_WM_HSCROLL()
  53. ON_BN_CLICKED(IDC_GRAYSCALE_CHECK, OnGrayscaleCheck)
  54. //}}AFX_MSG_MAP
  55. END_MESSAGE_MAP()
  56. /////////////////////////////////////////////////////////////
  57. //
  58. // OnInitDialog
  59. //
  60. BOOL
  61. CAmbientLightDialog::OnInitDialog (void)
  62. {
  63. // Allow the base class to process this message
  64. CDialog::OnInitDialog ();
  65. // Center the dialog around the data tree view instead
  66. // of the direct center of the screen
  67. ::CenterDialogAroundTreeView (m_hWnd);
  68. m_redSlider.SetRange (0, 100);
  69. m_greenSlider.SetRange (0, 100);
  70. m_blueSlider.SetRange (0, 100);
  71. // Get a pointer to the doc so we can get at the current scene
  72. // pointer.
  73. CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
  74. if (pCDoc && pCDoc->GetScene ())
  75. {
  76. Vector3 lightSettings = pCDoc->GetScene ()->Get_Ambient_Light ();
  77. // Remember these initial settings so we can restore them
  78. // if the user cancels
  79. m_initialRed = int(lightSettings.X * 100.00F);
  80. m_initialGreen = int(lightSettings.Y * 100.00F);
  81. m_initialBlue = int(lightSettings.Z * 100.00F);
  82. }
  83. if ((m_initialRed == m_initialGreen) &&
  84. (m_initialRed == m_initialBlue))
  85. {
  86. // Check the grayscale checkbox
  87. SendDlgItemMessage (IDC_GRAYSCALE_CHECK, BM_SETCHECK, (WPARAM)TRUE);
  88. }
  89. // Set the initial slider position
  90. m_redSlider.SetPos (m_initialRed);
  91. m_greenSlider.SetPos (m_initialGreen);
  92. m_blueSlider.SetPos (m_initialBlue);
  93. return TRUE;
  94. }
  95. //////////////////////////////////////////////////////////////
  96. //
  97. // OnHScroll
  98. //
  99. void
  100. CAmbientLightDialog::OnHScroll
  101. (
  102. UINT nSBCode,
  103. UINT nPos,
  104. CScrollBar* pScrollBar
  105. )
  106. {
  107. if (SendDlgItemMessage (IDC_GRAYSCALE_CHECK, BM_GETCHECK))
  108. {
  109. int iCurrentPos = 0;
  110. if (pScrollBar == GetDlgItem (IDC_SLIDER_RED))
  111. {
  112. iCurrentPos = m_redSlider.GetPos ();
  113. }
  114. else if (pScrollBar == GetDlgItem (IDC_SLIDER_GREEN))
  115. {
  116. iCurrentPos = m_greenSlider.GetPos ();
  117. }
  118. else
  119. {
  120. iCurrentPos = m_blueSlider.GetPos ();
  121. }
  122. // Make all the sliders the same pos
  123. m_redSlider.SetPos (iCurrentPos);
  124. m_greenSlider.SetPos (iCurrentPos);
  125. m_blueSlider.SetPos (iCurrentPos);
  126. }
  127. Vector3 lightSettings;
  128. lightSettings.X = float(m_redSlider.GetPos ()) / 100.00F;
  129. lightSettings.Y = float(m_greenSlider.GetPos ()) / 100.00F;
  130. lightSettings.Z = float(m_blueSlider.GetPos ()) / 100.00F;
  131. // Get a pointer to the document so we can change the scene's light
  132. // settings
  133. CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
  134. if (pCDoc && pCDoc->GetScene ())
  135. {
  136. // Modify the ambient light for this scene
  137. pCDoc->GetScene ()->Set_Ambient_Light (lightSettings);
  138. }
  139. // Allow the base class to process this message
  140. CDialog::OnHScroll (nSBCode, nPos, pScrollBar);
  141. return ;
  142. }
  143. //////////////////////////////////////////////////////////////
  144. //
  145. // OnCancel
  146. //
  147. void
  148. CAmbientLightDialog::OnCancel (void)
  149. {
  150. Vector3 lightSettings;
  151. lightSettings.X = float(m_initialRed) / 100.00F;
  152. lightSettings.Y = float(m_initialGreen) / 100.00F;
  153. lightSettings.Z = float(m_initialBlue) / 100.00F;
  154. // Get a pointer to the document so we can change the scene's light
  155. // settings
  156. CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
  157. if (pCDoc && pCDoc->GetScene ())
  158. {
  159. // Modify the ambient light for this scene
  160. pCDoc->GetScene ()->Set_Ambient_Light (lightSettings);
  161. }
  162. // Allow the base class to process this message
  163. CDialog::OnCancel();
  164. return ;
  165. }
  166. //////////////////////////////////////////////////////////////
  167. //
  168. // WindowProc
  169. //
  170. LRESULT
  171. CAmbientLightDialog::WindowProc
  172. (
  173. UINT message,
  174. WPARAM wParam,
  175. LPARAM lParam
  176. )
  177. {
  178. if (message == WM_PAINT)
  179. {
  180. // Paint the gradients for each color
  181. ::Paint_Gradient (::GetDlgItem (m_hWnd, IDC_RED_GRADIENT), 1, 0, 0);
  182. ::Paint_Gradient (::GetDlgItem (m_hWnd, IDC_GREEN_GRADIENT), 0, 1, 0);
  183. ::Paint_Gradient (::GetDlgItem (m_hWnd, IDC_BLUE_GRADIENT), 0, 0, 1);
  184. }
  185. // Allow the base class to process this message
  186. return CDialog::WindowProc (message, wParam, lParam);
  187. }
  188. //////////////////////////////////////////////////////////////
  189. //
  190. // OnGrayscaleCheck
  191. //
  192. void
  193. CAmbientLightDialog::OnGrayscaleCheck (void)
  194. {
  195. if (SendDlgItemMessage (IDC_GRAYSCALE_CHECK, BM_GETCHECK))
  196. {
  197. // Make the green and blue sliders the same as red
  198. m_greenSlider.SetPos (m_redSlider.GetPos ());
  199. m_blueSlider.SetPos (m_redSlider.GetPos ());
  200. Vector3 lightSettings;
  201. lightSettings.X = float(m_redSlider.GetPos ()) / 100.00F;
  202. lightSettings.Y = float(m_greenSlider.GetPos ()) / 100.00F;
  203. lightSettings.Z = float(m_blueSlider.GetPos ()) / 100.00F;
  204. // Get a pointer to the document so we can change the scene's light
  205. // settings
  206. CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
  207. if (pCDoc && pCDoc->GetScene ())
  208. {
  209. // Modify the ambient light for this scene
  210. pCDoc->GetScene ()->Set_Ambient_Light (lightSettings);
  211. }
  212. }
  213. return ;
  214. }