ColorSelectionDialog.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. // ColorSelectionDialog.cpp : implementation file
  19. //
  20. #include "StdAfx.H"
  21. #include "LevelEdit.H"
  22. #include "ColorSelectionDialog.H"
  23. #include "Utils.H"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////
  30. //
  31. // ColorSelectionDialogClass
  32. //
  33. ColorSelectionDialogClass::ColorSelectionDialogClass
  34. (
  35. const Vector3 &def_color,
  36. CWnd *pParent
  37. )
  38. : m_Color (def_color),
  39. m_PaintColor (def_color),
  40. CDialog(ColorSelectionDialogClass::IDD, pParent)
  41. {
  42. //{{AFX_DATA_INIT(ColorSelectionDialogClass)
  43. // NOTE: the ClassWizard will add member initialization here
  44. //}}AFX_DATA_INIT
  45. return ;
  46. }
  47. /////////////////////////////////////////////////////////////////
  48. //
  49. // DoDataExchange
  50. //
  51. void
  52. ColorSelectionDialogClass::DoDataExchange (CDataExchange* pDX)
  53. {
  54. CDialog::DoDataExchange(pDX);
  55. //{{AFX_DATA_MAP(ColorSelectionDialogClass)
  56. DDX_Control(pDX, IDC_COLOR_WINDOW, m_ColorWindow);
  57. DDX_Control(pDX, IDC_SLIDER_BLUE, m_BlueSlider);
  58. DDX_Control(pDX, IDC_SLIDER_GREEN, m_GreenSlider);
  59. DDX_Control(pDX, IDC_SLIDER_RED, m_RedSlider);
  60. //}}AFX_DATA_MAP
  61. return ;
  62. }
  63. BEGIN_MESSAGE_MAP(ColorSelectionDialogClass, CDialog)
  64. //{{AFX_MSG_MAP(ColorSelectionDialogClass)
  65. ON_WM_HSCROLL()
  66. ON_WM_PAINT()
  67. ON_BN_CLICKED(IDC_GRAYSCALE_CHECK, OnGrayscaleCheck)
  68. //}}AFX_MSG_MAP
  69. END_MESSAGE_MAP()
  70. /////////////////////////////////////////////////////////////////
  71. //
  72. // ColorSelectionDialogClass
  73. //
  74. BOOL
  75. ColorSelectionDialogClass::OnInitDialog (void)
  76. {
  77. // Allow the base class to process this message
  78. CDialog::OnInitDialog ();
  79. // Set the ranges of the slider controls
  80. m_RedSlider.SetRange (0, 100);
  81. m_GreenSlider.SetRange (0, 100);
  82. m_BlueSlider.SetRange (0, 100);
  83. // Determine the initial settings (in integers)
  84. int red_value = int(m_Color.X * 100.00F);
  85. int green_value = int(m_Color.Y * 100.00F);
  86. int blue_value = int(m_Color.Z * 100.00F);
  87. if ((red_value == green_value) &&
  88. (red_value == blue_value)) {
  89. // Check the grayscale checkbox
  90. SendDlgItemMessage (IDC_GRAYSCALE_CHECK, BM_SETCHECK, (WPARAM)TRUE);
  91. }
  92. // Set the initial slider positions
  93. m_RedSlider.SetPos (red_value);
  94. m_GreenSlider.SetPos (green_value);
  95. m_BlueSlider.SetPos (blue_value);
  96. return TRUE;
  97. }
  98. /////////////////////////////////////////////////////////////////
  99. //
  100. // ColorSelectionDialogClass
  101. //
  102. void
  103. ColorSelectionDialogClass::OnOK (void)
  104. {
  105. // Record the color
  106. m_Color = m_PaintColor;
  107. // Allow the base class to process this message
  108. CDialog::OnOK ();
  109. return ;
  110. }
  111. /////////////////////////////////////////////////////////////////
  112. //
  113. // OnHScroll
  114. //
  115. void
  116. ColorSelectionDialogClass::OnHScroll
  117. (
  118. UINT nSBCode,
  119. UINT nPos,
  120. CScrollBar *pScrollBar
  121. )
  122. {
  123. // Are the sliders moving together?
  124. if (SendDlgItemMessage (IDC_GRAYSCALE_CHECK, BM_GETCHECK)) {
  125. int position = 0;
  126. // Determine which slider sent this message and
  127. // use its current positions
  128. if (pScrollBar == GetDlgItem (IDC_SLIDER_RED)) {
  129. position = m_RedSlider.GetPos ();
  130. } else if (pScrollBar == GetDlgItem (IDC_SLIDER_GREEN)) {
  131. position = m_GreenSlider.GetPos ();
  132. } else {
  133. position = m_BlueSlider.GetPos ();
  134. }
  135. // Make all the sliders the same pos
  136. m_RedSlider.SetPos (position);
  137. m_GreenSlider.SetPos (position);
  138. m_BlueSlider.SetPos (position);
  139. }
  140. // Record the selected color for later use
  141. m_PaintColor.X = float(m_RedSlider.GetPos ()) / 100.00F;
  142. m_PaintColor.Y = float(m_GreenSlider.GetPos ()) / 100.00F;
  143. m_PaintColor.Z = float(m_BlueSlider.GetPos ()) / 100.00F;
  144. // Update the window that displays the color the user has selected
  145. Paint_Color_Window ();
  146. // Allow the base class to process this message
  147. CDialog::OnHScroll (nSBCode, nPos, pScrollBar);
  148. return ;
  149. }
  150. /////////////////////////////////////////////////////////////////
  151. //
  152. // OnPaint
  153. //
  154. void
  155. ColorSelectionDialogClass::OnPaint (void)
  156. {
  157. CPaintDC dc (this);
  158. // Paint the gradients for each color
  159. ::Paint_Gradient (::GetDlgItem (m_hWnd, IDC_RED_GRADIENT), 1, 0, 0);
  160. ::Paint_Gradient (::GetDlgItem (m_hWnd, IDC_GREEN_GRADIENT), 0, 1, 0);
  161. ::Paint_Gradient (::GetDlgItem (m_hWnd, IDC_BLUE_GRADIENT), 0, 0, 1);
  162. // Update the window that displays the color the user has selected
  163. Paint_Color_Window ();
  164. return ;
  165. }
  166. /////////////////////////////////////////////////////////////////
  167. //
  168. // Paint_Color_Window
  169. //
  170. void
  171. ColorSelectionDialogClass::Paint_Color_Window (void)
  172. {
  173. // Get the client coords of the 'color' window
  174. CRect rect;
  175. m_ColorWindow.GetClientRect (&rect);
  176. // Fill the window with the selected color
  177. CDC *pdc = m_ColorWindow.GetDC ();
  178. ::FrameRect (*pdc, &rect, (HBRUSH)::GetStockObject (BLACK_BRUSH));
  179. rect.DeflateRect (1, 1);
  180. pdc->FillSolidRect (&rect, RGB (int(m_PaintColor.X * 255), int(m_PaintColor.Y * 255), int(m_PaintColor.Z * 255)));
  181. m_ColorWindow.ReleaseDC (pdc);
  182. // Let the window know it doesn't need to be repainted
  183. m_ColorWindow.ValidateRect (NULL);
  184. return;
  185. }
  186. /////////////////////////////////////////////////////////////////
  187. //
  188. // OnGrayscaleCheck
  189. //
  190. void
  191. ColorSelectionDialogClass::OnGrayscaleCheck (void)
  192. {
  193. // Is the checkbox checked?
  194. if (SendDlgItemMessage (IDC_GRAYSCALE_CHECK, BM_GETCHECK)) {
  195. // Make the green and blue sliders the same as red
  196. m_GreenSlider.SetPos (m_RedSlider.GetPos ());
  197. m_BlueSlider.SetPos (m_RedSlider.GetPos ());
  198. Vector3 light_settings;
  199. light_settings.X = float(m_RedSlider.GetPos ()) / 100.00F;
  200. light_settings.Y = float(m_GreenSlider.GetPos ()) / 100.00F;
  201. light_settings.Z = float(m_BlueSlider.GetPos ()) / 100.00F;
  202. // Update the window that displays the color the user has selected
  203. Paint_Color_Window ();
  204. }
  205. return ;
  206. }