| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- // SunlightDialog.cpp : implementation file
- //
- #include "stdafx.h"
- #include "leveledit.h"
- #include "SunlightDialog.h"
- #include "Utils.H"
- #include "Light.H"
- #include "SceneEditor.H"
- #include "Utils.h"
- #include "colorpickerdialogclass.h"
- #include "phys.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // SunlightDialogClass dialog
- SunlightDialogClass::SunlightDialogClass(CWnd* pParent /*=NULL*/)
- : m_pSunlight (NULL),
- CDialog(SunlightDialogClass::IDD, pParent)
- {
- //{{AFX_DATA_INIT(SunlightDialogClass)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- SunlightDialogClass::~SunlightDialogClass (void)
- {
- MEMBER_RELEASE (m_pSunlight);
- return ;
- }
- void SunlightDialogClass::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(SunlightDialogClass)
- DDX_Control(pDX, IDC_YAW_SLIDER, m_YawSlider);
- DDX_Control(pDX, IDC_PITCH_SLIDER, m_PitchSlider);
- DDX_Control(pDX, IDC_INTENSITY_SLIDER, m_IntensitySlider);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(SunlightDialogClass, CDialog)
- //{{AFX_MSG_MAP(SunlightDialogClass)
- ON_WM_HSCROLL()
- ON_BN_CLICKED(IDC_COLOR, OnColor)
- ON_WM_DRAWITEM()
- ON_EN_UPDATE(IDC_PITCH_EDIT, OnUpdatePitchEdit)
- ON_EN_KILLFOCUS(IDC_PITCH_EDIT, OnKillfocusPitchEdit)
- ON_EN_KILLFOCUS(IDC_YAW_EDIT, OnKillfocusYawEdit)
- ON_EN_UPDATE(IDC_YAW_EDIT, OnUpdateYawEdit)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnInitDialog
- //
- /////////////////////////////////////////////////////////////////////////////
- BOOL
- SunlightDialogClass::OnInitDialog (void)
- {
- // Allow the base class to process this message
- CDialog::OnInitDialog ();
-
- m_pSunlight = ::Get_Scene_Editor ()->Get_Sun_Light ();
- ASSERT (m_pSunlight != NULL);
- m_pSunlight->Get_Diffuse (&m_Color);
-
- ::Get_Scene_Editor ()->Get_Sun_Light_Orientation (&m_Yaw, &m_Pitch);
- m_Intensity = m_pSunlight->Get_Intensity ();
- m_Yaw = WWMath::Wrap (m_Yaw, 0, DEG_TO_RADF (360));
- m_Pitch = WWMath::Wrap (m_Pitch, 0, DEG_TO_RADF (90));
- m_YawSlider.SetRange (0, 360);
- m_PitchSlider.SetRange (0, 90);
- m_IntensitySlider.SetRange (0, 100);
- m_YawSlider.SetPos ((int)(RAD_TO_DEG (m_Yaw) + 0.5F));
- m_PitchSlider.SetPos ((int)(RAD_TO_DEG (m_Pitch) + 0.5F));
- m_IntensitySlider.SetPos ((m_Intensity * 100));
- ::SetDlgItemFloat (m_hWnd, IDC_YAW_EDIT, (float)m_YawSlider.GetPos ());
- ::SetDlgItemFloat (m_hWnd, IDC_PITCH_EDIT, (float)m_PitchSlider.GetPos ());
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnHScroll
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- SunlightDialogClass::OnHScroll
- (
- UINT nSBCode,
- UINT nPos,
- CScrollBar* pScrollBar
- )
- {
- if (pScrollBar == GetDlgItem (IDC_YAW_SLIDER)) {
- m_Yaw = DEG_TO_RAD ((float)m_YawSlider.GetPos ());
- ::Get_Scene_Editor ()->Set_Sun_Light_Orientation (m_Yaw, m_Pitch);
- ::Get_Scene_Editor ()->Update_Lighting ();
- ::SetDlgItemFloat (m_hWnd, IDC_YAW_EDIT, (float)m_YawSlider.GetPos ());
- ::Get_Scene_Editor ()->Update_Lighting ();
- } else if (pScrollBar == GetDlgItem (IDC_PITCH_SLIDER)) {
- m_Pitch = DEG_TO_RAD ((float)m_PitchSlider.GetPos ());
- ::Get_Scene_Editor ()->Set_Sun_Light_Orientation (m_Yaw, m_Pitch);
- ::Get_Scene_Editor ()->Update_Lighting ();
- ::SetDlgItemFloat (m_hWnd, IDC_PITCH_EDIT, (float)m_PitchSlider.GetPos ());
- ::Get_Scene_Editor ()->Update_Lighting ();
- } else if (pScrollBar == GetDlgItem (IDC_INTENSITY_SLIDER)) {
- int pos = m_IntensitySlider.GetPos ();
- m_Intensity = ((float)pos) / 100.0F;
- m_pSunlight->Set_Intensity (m_Intensity);
- ::Get_Scene_Editor ()->Update_Lighting ();
- }
-
- ::Refresh_Main_View ();
- // Allow the base class to process this message
- CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnColor
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- SunlightDialogClass::OnColor (void)
- {
- int red = m_Color.X * 255;
- int green = m_Color.Y * 255;
- int blue = m_Color.Z * 255;
-
- //
- // Display a dialog to the user that will allow them to select a color
- //
- if (::Show_Color_Picker (&red, &green, &blue)) {
-
- //
- // Get the color from the picker and pass it onto the manager
- //
- m_Color.X = ((float)red) / 255.0F;
- m_Color.Y = ((float)green) / 255.0F;
- m_Color.Z = ((float)blue) / 255.0F;
- m_pSunlight->Set_Diffuse (m_Color);
- //
- // Repaint the views
- //
- ::InvalidateRect (::GetDlgItem (m_hWnd, IDC_BK_COLOR), NULL, TRUE);
- ::Get_Scene_Editor ()->Update_Lighting ();
- ::Refresh_Main_View ();
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnDrawItem
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- SunlightDialogClass::OnDrawItem
- (
- int nIDCtl,
- LPDRAWITEMSTRUCT lpDrawItemStruct
- )
- {
- // Determine what state to draw the button in (pushed or normal)
- UINT state = DFCS_BUTTONPUSH | DFCS_ADJUSTRECT;
- if (lpDrawItemStruct->itemState & ODS_SELECTED) {
- state |= DFCS_PUSHED;
- }
- // Draw the button's outline
- CRect rect = lpDrawItemStruct->rcItem;
- ::DrawFrameControl (lpDrawItemStruct->hDC, rect, DFC_BUTTON, state);
- // Fill the button with the appropriate color
- CDC temp_dc;
- temp_dc.Attach (lpDrawItemStruct->hDC);
- temp_dc.FillSolidRect (&rect, RGB (int(m_Color.X * 255), int(m_Color.Y * 255), int(m_Color.Z * 255)));
- temp_dc.Detach ();
-
- // Draw the focus rectangle if necessary
- if (lpDrawItemStruct->itemState & ODS_FOCUS) {
- ::DrawFocusRect (lpDrawItemStruct->hDC, &rect);
- }
-
- // Allow the base class to process this message
- CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnUpdatePitchEdit
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- SunlightDialogClass::OnUpdatePitchEdit (void)
- {
- float pitch_deg = ::GetDlgItemFloat (m_hWnd, IDC_PITCH_EDIT);
- m_Pitch = DEG_TO_RAD (pitch_deg);
- ::Get_Scene_Editor ()->Set_Sun_Light_Orientation (m_Yaw, m_Pitch);
- ::Get_Scene_Editor ()->Update_Lighting ();
- m_PitchSlider.SetPos ((int)pitch_deg);
- ::Refresh_Main_View ();
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnKillfocusPitchEdit
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- SunlightDialogClass::OnKillfocusPitchEdit (void)
- {
- float pitch_deg = ::GetDlgItemFloat (m_hWnd, IDC_PITCH_EDIT);
- if (pitch_deg > 90.0F) {
- pitch_deg = 90.0F;
- ::SetDlgItemFloat (m_hWnd, IDC_PITCH_EDIT, pitch_deg);
- m_Pitch = DEG_TO_RAD (pitch_deg);
- ::Get_Scene_Editor ()->Set_Sun_Light_Orientation (m_Yaw, m_Pitch);
- ::Get_Scene_Editor ()->Update_Lighting ();
- ::Refresh_Main_View ();
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnKillfocusYawEdit
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- SunlightDialogClass::OnKillfocusYawEdit (void)
- {
- float yaw_deg = ::GetDlgItemFloat (m_hWnd, IDC_YAW_EDIT);
- if (yaw_deg > 360.0F) {
- yaw_deg = 360.0F;
- ::SetDlgItemFloat (m_hWnd, IDC_YAW_EDIT, yaw_deg);
- m_Yaw = DEG_TO_RAD (yaw_deg);
- ::Get_Scene_Editor ()->Set_Sun_Light_Orientation (m_Yaw, m_Pitch);
- ::Get_Scene_Editor ()->Update_Lighting ();
- ::Refresh_Main_View ();
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnUpdateYawEdit
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- SunlightDialogClass::OnUpdateYawEdit (void)
- {
- float yaw_deg = ::GetDlgItemFloat (m_hWnd, IDC_YAW_EDIT);
- m_Yaw = DEG_TO_RAD (yaw_deg);
- ::Get_Scene_Editor ()->Set_Sun_Light_Orientation (m_Yaw, m_Pitch);
- ::Get_Scene_Editor ()->Update_Lighting ();
- m_YawSlider.SetPos ((int)yaw_deg);
- ::Refresh_Main_View ();
- return ;
- }
|