SunlightDialog.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. // SunlightDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "SunlightDialog.h"
  23. #include "Utils.H"
  24. #include "Light.H"
  25. #include "SceneEditor.H"
  26. #include "Utils.h"
  27. #include "colorpickerdialogclass.h"
  28. #include "phys.h"
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. /////////////////////////////////////////////////////////////////////////////
  35. // SunlightDialogClass dialog
  36. SunlightDialogClass::SunlightDialogClass(CWnd* pParent /*=NULL*/)
  37. : m_pSunlight (NULL),
  38. CDialog(SunlightDialogClass::IDD, pParent)
  39. {
  40. //{{AFX_DATA_INIT(SunlightDialogClass)
  41. // NOTE: the ClassWizard will add member initialization here
  42. //}}AFX_DATA_INIT
  43. }
  44. SunlightDialogClass::~SunlightDialogClass (void)
  45. {
  46. MEMBER_RELEASE (m_pSunlight);
  47. return ;
  48. }
  49. void SunlightDialogClass::DoDataExchange(CDataExchange* pDX)
  50. {
  51. CDialog::DoDataExchange(pDX);
  52. //{{AFX_DATA_MAP(SunlightDialogClass)
  53. DDX_Control(pDX, IDC_YAW_SLIDER, m_YawSlider);
  54. DDX_Control(pDX, IDC_PITCH_SLIDER, m_PitchSlider);
  55. DDX_Control(pDX, IDC_INTENSITY_SLIDER, m_IntensitySlider);
  56. //}}AFX_DATA_MAP
  57. }
  58. BEGIN_MESSAGE_MAP(SunlightDialogClass, CDialog)
  59. //{{AFX_MSG_MAP(SunlightDialogClass)
  60. ON_WM_HSCROLL()
  61. ON_BN_CLICKED(IDC_COLOR, OnColor)
  62. ON_WM_DRAWITEM()
  63. ON_EN_UPDATE(IDC_PITCH_EDIT, OnUpdatePitchEdit)
  64. ON_EN_KILLFOCUS(IDC_PITCH_EDIT, OnKillfocusPitchEdit)
  65. ON_EN_KILLFOCUS(IDC_YAW_EDIT, OnKillfocusYawEdit)
  66. ON_EN_UPDATE(IDC_YAW_EDIT, OnUpdateYawEdit)
  67. //}}AFX_MSG_MAP
  68. END_MESSAGE_MAP()
  69. /////////////////////////////////////////////////////////////////////////////
  70. //
  71. // OnInitDialog
  72. //
  73. /////////////////////////////////////////////////////////////////////////////
  74. BOOL
  75. SunlightDialogClass::OnInitDialog (void)
  76. {
  77. // Allow the base class to process this message
  78. CDialog::OnInitDialog ();
  79. m_pSunlight = ::Get_Scene_Editor ()->Get_Sun_Light ();
  80. ASSERT (m_pSunlight != NULL);
  81. m_pSunlight->Get_Diffuse (&m_Color);
  82. ::Get_Scene_Editor ()->Get_Sun_Light_Orientation (&m_Yaw, &m_Pitch);
  83. m_Intensity = m_pSunlight->Get_Intensity ();
  84. m_Yaw = WWMath::Wrap (m_Yaw, 0, DEG_TO_RADF (360));
  85. m_Pitch = WWMath::Wrap (m_Pitch, 0, DEG_TO_RADF (90));
  86. m_YawSlider.SetRange (0, 360);
  87. m_PitchSlider.SetRange (0, 90);
  88. m_IntensitySlider.SetRange (0, 100);
  89. m_YawSlider.SetPos ((int)(RAD_TO_DEG (m_Yaw) + 0.5F));
  90. m_PitchSlider.SetPos ((int)(RAD_TO_DEG (m_Pitch) + 0.5F));
  91. m_IntensitySlider.SetPos ((m_Intensity * 100));
  92. ::SetDlgItemFloat (m_hWnd, IDC_YAW_EDIT, (float)m_YawSlider.GetPos ());
  93. ::SetDlgItemFloat (m_hWnd, IDC_PITCH_EDIT, (float)m_PitchSlider.GetPos ());
  94. return TRUE;
  95. }
  96. /////////////////////////////////////////////////////////////////////////////
  97. //
  98. // OnHScroll
  99. //
  100. /////////////////////////////////////////////////////////////////////////////
  101. void
  102. SunlightDialogClass::OnHScroll
  103. (
  104. UINT nSBCode,
  105. UINT nPos,
  106. CScrollBar* pScrollBar
  107. )
  108. {
  109. if (pScrollBar == GetDlgItem (IDC_YAW_SLIDER)) {
  110. m_Yaw = DEG_TO_RAD ((float)m_YawSlider.GetPos ());
  111. ::Get_Scene_Editor ()->Set_Sun_Light_Orientation (m_Yaw, m_Pitch);
  112. ::Get_Scene_Editor ()->Update_Lighting ();
  113. ::SetDlgItemFloat (m_hWnd, IDC_YAW_EDIT, (float)m_YawSlider.GetPos ());
  114. ::Get_Scene_Editor ()->Update_Lighting ();
  115. } else if (pScrollBar == GetDlgItem (IDC_PITCH_SLIDER)) {
  116. m_Pitch = DEG_TO_RAD ((float)m_PitchSlider.GetPos ());
  117. ::Get_Scene_Editor ()->Set_Sun_Light_Orientation (m_Yaw, m_Pitch);
  118. ::Get_Scene_Editor ()->Update_Lighting ();
  119. ::SetDlgItemFloat (m_hWnd, IDC_PITCH_EDIT, (float)m_PitchSlider.GetPos ());
  120. ::Get_Scene_Editor ()->Update_Lighting ();
  121. } else if (pScrollBar == GetDlgItem (IDC_INTENSITY_SLIDER)) {
  122. int pos = m_IntensitySlider.GetPos ();
  123. m_Intensity = ((float)pos) / 100.0F;
  124. m_pSunlight->Set_Intensity (m_Intensity);
  125. ::Get_Scene_Editor ()->Update_Lighting ();
  126. }
  127. ::Refresh_Main_View ();
  128. // Allow the base class to process this message
  129. CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
  130. return ;
  131. }
  132. /////////////////////////////////////////////////////////////////////////////
  133. //
  134. // OnColor
  135. //
  136. /////////////////////////////////////////////////////////////////////////////
  137. void
  138. SunlightDialogClass::OnColor (void)
  139. {
  140. int red = m_Color.X * 255;
  141. int green = m_Color.Y * 255;
  142. int blue = m_Color.Z * 255;
  143. //
  144. // Display a dialog to the user that will allow them to select a color
  145. //
  146. if (::Show_Color_Picker (&red, &green, &blue)) {
  147. //
  148. // Get the color from the picker and pass it onto the manager
  149. //
  150. m_Color.X = ((float)red) / 255.0F;
  151. m_Color.Y = ((float)green) / 255.0F;
  152. m_Color.Z = ((float)blue) / 255.0F;
  153. m_pSunlight->Set_Diffuse (m_Color);
  154. //
  155. // Repaint the views
  156. //
  157. ::InvalidateRect (::GetDlgItem (m_hWnd, IDC_BK_COLOR), NULL, TRUE);
  158. ::Get_Scene_Editor ()->Update_Lighting ();
  159. ::Refresh_Main_View ();
  160. }
  161. return ;
  162. }
  163. /////////////////////////////////////////////////////////////////////////////
  164. //
  165. // OnDrawItem
  166. //
  167. /////////////////////////////////////////////////////////////////////////////
  168. void
  169. SunlightDialogClass::OnDrawItem
  170. (
  171. int nIDCtl,
  172. LPDRAWITEMSTRUCT lpDrawItemStruct
  173. )
  174. {
  175. // Determine what state to draw the button in (pushed or normal)
  176. UINT state = DFCS_BUTTONPUSH | DFCS_ADJUSTRECT;
  177. if (lpDrawItemStruct->itemState & ODS_SELECTED) {
  178. state |= DFCS_PUSHED;
  179. }
  180. // Draw the button's outline
  181. CRect rect = lpDrawItemStruct->rcItem;
  182. ::DrawFrameControl (lpDrawItemStruct->hDC, rect, DFC_BUTTON, state);
  183. // Fill the button with the appropriate color
  184. CDC temp_dc;
  185. temp_dc.Attach (lpDrawItemStruct->hDC);
  186. temp_dc.FillSolidRect (&rect, RGB (int(m_Color.X * 255), int(m_Color.Y * 255), int(m_Color.Z * 255)));
  187. temp_dc.Detach ();
  188. // Draw the focus rectangle if necessary
  189. if (lpDrawItemStruct->itemState & ODS_FOCUS) {
  190. ::DrawFocusRect (lpDrawItemStruct->hDC, &rect);
  191. }
  192. // Allow the base class to process this message
  193. CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
  194. return ;
  195. }
  196. /////////////////////////////////////////////////////////////////////////////
  197. //
  198. // OnUpdatePitchEdit
  199. //
  200. /////////////////////////////////////////////////////////////////////////////
  201. void
  202. SunlightDialogClass::OnUpdatePitchEdit (void)
  203. {
  204. float pitch_deg = ::GetDlgItemFloat (m_hWnd, IDC_PITCH_EDIT);
  205. m_Pitch = DEG_TO_RAD (pitch_deg);
  206. ::Get_Scene_Editor ()->Set_Sun_Light_Orientation (m_Yaw, m_Pitch);
  207. ::Get_Scene_Editor ()->Update_Lighting ();
  208. m_PitchSlider.SetPos ((int)pitch_deg);
  209. ::Refresh_Main_View ();
  210. return ;
  211. }
  212. /////////////////////////////////////////////////////////////////////////////
  213. //
  214. // OnKillfocusPitchEdit
  215. //
  216. /////////////////////////////////////////////////////////////////////////////
  217. void
  218. SunlightDialogClass::OnKillfocusPitchEdit (void)
  219. {
  220. float pitch_deg = ::GetDlgItemFloat (m_hWnd, IDC_PITCH_EDIT);
  221. if (pitch_deg > 90.0F) {
  222. pitch_deg = 90.0F;
  223. ::SetDlgItemFloat (m_hWnd, IDC_PITCH_EDIT, pitch_deg);
  224. m_Pitch = DEG_TO_RAD (pitch_deg);
  225. ::Get_Scene_Editor ()->Set_Sun_Light_Orientation (m_Yaw, m_Pitch);
  226. ::Get_Scene_Editor ()->Update_Lighting ();
  227. ::Refresh_Main_View ();
  228. }
  229. return ;
  230. }
  231. /////////////////////////////////////////////////////////////////////////////
  232. //
  233. // OnKillfocusYawEdit
  234. //
  235. /////////////////////////////////////////////////////////////////////////////
  236. void
  237. SunlightDialogClass::OnKillfocusYawEdit (void)
  238. {
  239. float yaw_deg = ::GetDlgItemFloat (m_hWnd, IDC_YAW_EDIT);
  240. if (yaw_deg > 360.0F) {
  241. yaw_deg = 360.0F;
  242. ::SetDlgItemFloat (m_hWnd, IDC_YAW_EDIT, yaw_deg);
  243. m_Yaw = DEG_TO_RAD (yaw_deg);
  244. ::Get_Scene_Editor ()->Set_Sun_Light_Orientation (m_Yaw, m_Pitch);
  245. ::Get_Scene_Editor ()->Update_Lighting ();
  246. ::Refresh_Main_View ();
  247. }
  248. return ;
  249. }
  250. /////////////////////////////////////////////////////////////////////////////
  251. //
  252. // OnUpdateYawEdit
  253. //
  254. /////////////////////////////////////////////////////////////////////////////
  255. void
  256. SunlightDialogClass::OnUpdateYawEdit (void)
  257. {
  258. float yaw_deg = ::GetDlgItemFloat (m_hWnd, IDC_YAW_EDIT);
  259. m_Yaw = DEG_TO_RAD (yaw_deg);
  260. ::Get_Scene_Editor ()->Set_Sun_Light_Orientation (m_Yaw, m_Pitch);
  261. ::Get_Scene_Editor ()->Update_Lighting ();
  262. m_YawSlider.SetPos ((int)yaw_deg);
  263. ::Refresh_Main_View ();
  264. return ;
  265. }