LightAmbientForm.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. // LightAmbientFormClass.cpp : implementation file
  19. //
  20. #include "Stdafx.H"
  21. #include "LevelEdit.H"
  22. #include "LightAmbientForm.H"
  23. #include "Vector3.H"
  24. #include "Utils.H"
  25. #include "SceneEditor.H"
  26. #include "rendobj.h"
  27. #include "phys.h"
  28. #include "colorpickerdialogclass.h"
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. /////////////////////////////////////////////////////////////////////////////
  35. // Forward declarations
  36. /////////////////////////////////////////////////////////////////////////////
  37. void ColorUpdateCallback (int red, int green, int blue, void *arg);
  38. /////////////////////////////////////////////////////////////////////////////
  39. //
  40. // LightAmbientFormClass
  41. //
  42. /////////////////////////////////////////////////////////////////////////////
  43. LightAmbientFormClass::LightAmbientFormClass()
  44. : m_ColorForm (NULL),
  45. DockableFormClass(LightAmbientFormClass::IDD)
  46. {
  47. //{{AFX_DATA_INIT(LightAmbientFormClass)
  48. // NOTE: the ClassWizard will add member initialization here
  49. //}}AFX_DATA_INIT
  50. return ;
  51. }
  52. /////////////////////////////////////////////////////////////////////////////
  53. //
  54. // ~LightAmbientFormClass
  55. //
  56. LightAmbientFormClass::~LightAmbientFormClass()
  57. {
  58. return ;
  59. }
  60. /////////////////////////////////////////////////////////////////////////////
  61. //
  62. // DoDataExchange
  63. //
  64. void
  65. LightAmbientFormClass::DoDataExchange (CDataExchange* pDX)
  66. {
  67. DockableFormClass::DoDataExchange(pDX);
  68. //{{AFX_DATA_MAP(LightAmbientFormClass)
  69. //}}AFX_DATA_MAP
  70. return ;
  71. }
  72. BEGIN_MESSAGE_MAP(LightAmbientFormClass, DockableFormClass)
  73. //{{AFX_MSG_MAP(LightAmbientFormClass)
  74. //}}AFX_MSG_MAP
  75. END_MESSAGE_MAP()
  76. /////////////////////////////////////////////////////////////////////////////
  77. // LightAmbientFormClass diagnostics
  78. #ifdef _DEBUG
  79. void LightAmbientFormClass::AssertValid() const
  80. {
  81. DockableFormClass::AssertValid();
  82. }
  83. void LightAmbientFormClass::Dump(CDumpContext& dc) const
  84. {
  85. DockableFormClass::Dump(dc);
  86. }
  87. #endif //_DEBUG
  88. /////////////////////////////////////////////////////////////////////////////
  89. //
  90. // HandleInitDialog
  91. //
  92. /////////////////////////////////////////////////////////////////////////////
  93. void
  94. LightAmbientFormClass::HandleInitDialog (void)
  95. {
  96. //
  97. // Create the color picker
  98. //
  99. m_ColorForm = Create_Color_Picker_Form (m_hWnd, 0, 0, 0);
  100. Set_Update_Callback (m_ColorForm, ColorUpdateCallback);
  101. ::ShowWindow (m_ColorForm, SW_SHOW);
  102. Update_Settings ();
  103. return ;
  104. }
  105. //////////////////////////////////////////////////////////////
  106. //
  107. // Update_Settings
  108. //
  109. //////////////////////////////////////////////////////////////
  110. void
  111. LightAmbientFormClass::Update_Settings (void)
  112. {
  113. //
  114. // Get the current ambient light settings
  115. //
  116. Vector3 light_settings = ::Get_Scene_Editor()->Get_Ambient_Light ();
  117. int red = light_settings.X * 255;
  118. int green = light_settings.Y * 255;
  119. int blue = light_settings.Z * 255;
  120. //
  121. // Pass these colors onto the form
  122. //
  123. Set_Form_Original_Color (m_ColorForm, red, green, blue);
  124. Set_Form_Color (m_ColorForm, red, green, blue);
  125. ::Get_Scene_Editor ()->Update_Lighting ();
  126. return ;
  127. }
  128. //////////////////////////////////////////////////////////////
  129. //
  130. // ColorUpdateCallback
  131. //
  132. //////////////////////////////////////////////////////////////
  133. void
  134. ColorUpdateCallback (int red, int green, int blue, void *arg)
  135. {
  136. //
  137. // Convert the settings to a vector3
  138. //
  139. Vector3 light;
  140. light.X = ((float)red) / 255;
  141. light.Y = ((float)green) / 255;
  142. light.Z = ((float)blue) / 255;
  143. //
  144. // Update the scene's abmient light
  145. //
  146. ::Get_Scene_Editor()->Set_Ambient_Light (light);
  147. ::Get_Scene_Editor()->Update_Lighting ();
  148. ::Refresh_Main_View ();
  149. return ;
  150. }