BackgroundColorDialog.cpp 6.9 KB

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