/*========================================================================= * * SECTdVis.cpp : Visual Environment dialog - Implementation file * * * Version 1.0 * Creation date * Revision date * * Shaitan *=======================================================================*/ /* #include "stdafx.h" #include "acp_base.h" #include "SECTint.hpp" #include "SECdVis.hpp" #include "SECmodif.hpp" #include "SECdEnv.hpp" #include "SEClEnvs.hpp" #include "SECdEnvs.hpp" #include "SECdSrfs.hpp" #include "..\Main\Inc\_EditID.h" #include "TUT.h" */ //################################################################################# // SECT_DialogVis dialog //################################################################################# /*---------------------------------------- ----------------------------------------*/ /* SECT_DialogVis::SECT_DialogVis(CWnd* pParent) : CFormView(SECT_DialogVis::IDD) { //{{AFX_DATA_INIT(SECT_DialogVis) //}}AFX_DATA_INIT } */ /*---------------------------------------- ----------------------------------------*/ /* void SECT_DialogVis::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(SECT_DialogVis) DDX_Control(pDX, SECT_IDC_VISNAME, m_cName); DDX_Control(pDX, SECT_IDC_VISDEFAULT, m_cDefault); DDX_Control(pDX, SECT_IDC_VISSAVE, m_cSave); DDX_Control(pDX, SECT_IDC_VISCANCEL, m_cCancel); DDX_Control(pDX, SECT_IDC_NEAR, m_cNear); DDX_Control(pDX, SECT_IDC_FAR, m_cFar); DDX_Control(pDX, SECT_IDC_BLENDNEAR, m_cBlendNear); DDX_Control(pDX, SECT_IDC_BLENDFAR, m_cBlendFar); DDX_Control(pDX, SECT_IDC_INFINITE, m_cInfinite); DDX_Control(pDX, SECT_IDC_COLOR, m_cColor); DDX_Control(pDX, SECT_IDC_REDSLIDER, m_cRSlider); DDX_Control(pDX, SECT_IDC_GREENSLIDER, m_cGSlider); DDX_Control(pDX, SECT_IDC_BLUESLIDER, m_cBSlider); //}}AFX_DATA_MAP } */ /*---------------------------------------- ----------------------------------------*/ /* BEGIN_MESSAGE_MAP(SECT_DialogVis, CFormView) //{{AFX_MSG_MAP(SECT_DialogVis) ON_WM_SIZE() ON_WM_DESTROY() ON_WM_DRAWITEM() ON_BN_CLICKED(SECT_IDC_VISSAVE, OnSave) ON_BN_CLICKED(SECT_IDC_VISCANCEL, OnCancel) ON_EN_KILLFOCUS(SECT_IDC_VISNAME, OnChangeName) ON_BN_CLICKED(SECT_IDC_VISDEFAULT, OnDefault) ON_EN_KILLFOCUS(SECT_IDC_NEAR, OnChangeNear) ON_EN_KILLFOCUS(SECT_IDC_FAR, OnChangeFar) ON_EN_KILLFOCUS(SECT_IDC_INFINITE, OnChangeInfinite) ON_WM_VSCROLL() ON_WM_HSCROLL() ON_BN_DOUBLECLICKED(SECT_IDC_COLOR, OnEditColor) //}}AFX_MSG_MAP END_MESSAGE_MAP() */ //################################################################################# // SECT_DialogVis Inits //################################################################################# /*=========================================================================== * Description: Init dialog * Creation date: * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ /* void SECT_DialogVis::fn_vInitDialog (Sector_Interface *p_oDLL, CWnd *pParent) { // create the dialog m_bInitialised = FALSE; m_pSectorInterface = p_oDLL; CFormView::Create(NULL, "", AFX_WS_DEFAULT_VIEW, CRect(0,0,120,180), pParent, AFX_IDW_PANE_FIRST, NULL); // init data for dialog CFormView::UpdateData(FALSE); // FOR TUTORIAL TUT_M_vGetTutDll(); // visual environment TUT_M_vRegisterControl(m_cName.m_hWnd, "OSC_DVIS_EDIT_VISENV", TUT_e_TextEdit); TUT_M_vRegisterControl(m_cDefault.m_hWnd, "OSC_DVIS_BUTTON_DEFAULT", TUT_e_Button); TUT_M_vRegisterControl(m_cCancel.m_hWnd, "OSC_DVIS_BUTTON_CANCEL", TUT_e_Button); TUT_M_vRegisterControl(m_cSave.m_hWnd, "OSC_DVIS_BUTTON_SAVE", TUT_e_Button); // parameters TUT_M_vRegisterControl(m_cNear.m_hWnd, "OSC_DVIS_EDIT_NEAR", TUT_e_TextEdit); TUT_M_vRegisterControl(m_cFar.m_hWnd, "OSC_DVIS_EDIT_FAR", TUT_e_TextEdit); TUT_M_vRegisterControl(m_cInfinite.m_hWnd, "OSC_DVIS_EDIT_INFINITE", TUT_e_TextEdit); TUT_M_vRegisterControl(m_cBlendNear.m_hWnd, "OSC_DVIS_EDIT_BLENDNEAR", TUT_e_Slider); TUT_M_vRegisterControl(m_cBlendFar.m_hWnd, "OSC_DVIS_EDIT_BLENDFAR", TUT_e_Slider); // color TUT_M_vRegisterControl(m_cRSlider.m_hWnd, "OSC_DVIS_SLIDER_RED", TUT_e_Slider); TUT_M_vRegisterControl(m_cGSlider.m_hWnd, "OSC_DVIS_SLIDER_GREEN", TUT_e_Slider); TUT_M_vRegisterControl(m_cBSlider.m_hWnd, "OSC_DVIS_SLIDER_BLUE", TUT_e_Slider); TUT_M_vRegisterControl(m_cColor.m_hWnd, "OSC_DVIS_BUTTON_COLOR", TUT_e_Button); // END TUTORIAL // init blend m_cBlendNear.SetRange(0, 255); m_cBlendFar.SetRange(0, 255); // init range m_cRSlider.SetRange(0, 254); m_cGSlider.SetRange(0, 254); m_cBSlider.SetRange(0, 254); // init environment values m_pDefaultVisEnv = NULL; fn_vInitVisEnvironment(NULL, FALSE); m_bInitialised = TRUE; } */ /*=========================================================================== * Description: Init default vis env * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ /* void SECT_DialogVis::fn_vReinitDialog (void) { if (!m_pDefaultVisEnv) { m_pDefaultVisEnv = new SECT_VisEnvironment(m_pSectorInterface, ""); m_pDefaultVisEnv->fn_bUnValidate(); m_pDefaultVisEnv->fn_vNotifyUnSave(); } } */ /*=========================================================================== * Description: Init controls * Creation date: * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ /* void SECT_DialogVis::fn_vInitControls (BOOL bEnable) { // init button states m_cSave.EnableWindow(bEnable); m_cCancel.EnableWindow(bEnable); // init name m_cName.SetReadOnly(!bEnable); m_cDefault.EnableWindow(bEnable); // init fog controls m_cNear.SetReadOnly(!bEnable); m_cFar.SetReadOnly(!bEnable); m_cBlendNear.EnableWindow(bEnable); m_cBlendFar.EnableWindow(bEnable); m_cInfinite.SetReadOnly(!bEnable); // init color controls m_cRSlider.EnableWindow(bEnable); m_cGSlider.EnableWindow(bEnable); m_cBSlider.EnableWindow(bEnable); } */ /*=========================================================================== * Description: register initial values * Creation date: * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ /* void SECT_DialogVis::fn_vInitVisEnvironment (SECT_VisEnvironment *pVisEnv, BOOL bEnable) { char szVal[256]; int iRValue, iGValue, iBValue; // update or create mec env if ((!pVisEnv) && bEnable) m_pVisEnv = m_pDefaultVisEnv; else m_pVisEnv = pVisEnv; // update all controls fn_vInitControls(bEnable); // init name m_csName = (m_pVisEnv) ? m_pVisEnv->GetName() : ""; // init fog parameters m_xNear = (m_pVisEnv) ? m_pVisEnv->GetFogNear() : 0; m_xFar = (m_pVisEnv) ? m_pVisEnv->GetFogFar() : 0; m_xBlendNear = (m_pVisEnv) ? m_pVisEnv->GetFogBlendNear() : 0; m_xBlendFar = (m_pVisEnv) ? m_pVisEnv->GetFogBlendFar() : 0; m_xInfinite = (m_pVisEnv) ? m_pVisEnv->GetFogInfinite() : 0; // init fog color iRValue = (m_pVisEnv) ? (int) (254 * m_pVisEnv->GetFogColor()->xR) : 0; iGValue = (m_pVisEnv) ? (int) (254 * m_pVisEnv->GetFogColor()->xG) : 0; iBValue = (m_pVisEnv) ? (int) (254 * m_pVisEnv->GetFogColor()->xB) : 0; m_stColor = RGB(iRValue, iGValue, iBValue); // init controls if (!m_pVisEnv) { m_cName.SetWindowText(""); m_cNear.SetWindowText(""); m_cFar.SetWindowText(""); m_cBlendNear.SetPos((int) m_xBlendNear); m_cBlendFar.SetPos((int) m_xBlendFar); m_cInfinite.SetWindowText(""); fn_vUpdateSliders(); fn_vUpdateColor(); } else { // name m_cName.SetWindowText(m_csName); // near sprintf(szVal, "%5.2f", m_xNear); m_cNear.SetWindowText(szVal); // far sprintf(szVal, "%5.2f", m_xFar); m_cFar.SetWindowText(szVal); // blend near m_cBlendNear.SetPos((int) m_xBlendNear); // blend far m_cBlendFar.SetPos((int) m_xBlendFar); // infinite sprintf(szVal, "%5.2f", m_xInfinite); m_cInfinite.SetWindowText(szVal); // color fn_vUpdateSliders(); fn_vUpdateColor(); } } */ /*=========================================================================== * Description: Update sliders * Creation date: * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ /* void SECT_DialogVis::fn_vUpdateSliders (void) { m_cRSlider.SetPos(254 - GetRValue(m_stColor)); m_cGSlider.SetPos(254 - GetGValue(m_stColor)); m_cBSlider.SetPos(254 - GetBValue(m_stColor)); } */ /*=========================================================================== * Description: Update Color * Creation date: * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ /* void SECT_DialogVis::fn_vUpdateColor (void) { RECT rColor; CDC *pColorDC; // get controls parameters pColorDC = m_cColor.GetDC(); m_cColor.GetClientRect(&rColor); // fill control pColorDC->FillSolidRect(&rColor, m_stColor); } */ //################################################################################# // SECT_DialogVis Messages //################################################################################# /*---------------------------------------- ----------------------------------------*/ /* void SECT_DialogVis::OnChangeName (void) { CString csFinalName; char szNewName[256]; // no mec env => no changes if ((!m_pVisEnv)||(!m_cName.GetModify())) return; // get corresponding name m_cName.GetWindowText(szNewName, 255); if (!strcmp(szNewName, "")) { m_cName.SetWindowText(m_csName); return; } // get prefixed name csFinalName = m_pSectorInterface->GetInterface()->GetPrefixedName(szNewName); // check name validity if (m_pVisEnv->fn_eCheckValidity(csFinalName) == E_mc_None) m_csName = csFinalName; // update window m_cName.SetWindowText(m_csName); m_cName.SetModify(FALSE); } */ /*---------------------------------------- ----------------------------------------*/ /* void SECT_DialogVis::OnChangeNear (void) { float xNear; char szVal[15]; if (m_cNear.GetModify()) { m_cNear.GetWindowText(szVal, 15); xNear = (float) atof(szVal); if ((xNear <= m_xFar) && (xNear <= m_xInfinite) && (xNear >= 0)) m_xNear = xNear; else { sprintf(szVal, "%5.2f", m_xNear); m_cNear.SetWindowText(szVal); } m_cNear.SetModify(FALSE); } } /*---------------------------------------- ----------------------------------------*/ /* void SECT_DialogVis::OnChangeFar (void) { float xFar; char szVal[15]; if (m_cFar.GetModify()) { m_cFar.GetWindowText(szVal, 15); xFar = (float) atof(szVal); if ((xFar >= m_xNear) && (xFar <= m_xInfinite) && (xFar >= 0)) m_xFar = xFar; else { sprintf(szVal, "%5.2f", m_xFar); m_cFar.SetWindowText(szVal); } m_cFar.SetModify(FALSE); } } */ /*---------------------------------------- ----------------------------------------*/ /* void SECT_DialogVis::OnChangeInfinite (void) { float xInfinite; char szVal[15]; if (m_cInfinite.GetModify()) { m_cInfinite.GetWindowText(szVal, 15); xInfinite = (float) atof(szVal); if ((xInfinite >= m_xNear) && (xInfinite >= m_xFar) && (xInfinite >= 0)) m_xInfinite = xInfinite; else { sprintf(szVal, "%5.2f", m_xInfinite); m_cInfinite.SetWindowText(szVal); } m_cInfinite.SetModify(FALSE); } } */ /*---------------------------------------- ----------------------------------------*/ /* void SECT_DialogVis::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { int iRValue, iGValue, iBValue; // color if ((pScrollBar == (void*) &m_cRSlider) || (pScrollBar == (void*) &m_cGSlider) || (pScrollBar == (void*) &m_cBSlider)) { // update color iRValue = 254 - m_cRSlider.GetPos(); iGValue = 254 - m_cGSlider.GetPos(); iBValue = 254 - m_cBSlider.GetPos(); m_stColor = RGB(iRValue, iGValue, iBValue); // update control fn_vUpdateColor(); } CFormView::OnVScroll(nSBCode, nPos, pScrollBar); } */ /*---------------------------------------- ----------------------------------------*/ /* void SECT_DialogVis::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { if (pScrollBar == (void*) &m_cBlendNear) { // get new near value m_xBlendNear = (float) m_cBlendNear.GetPos(); // if necessary, update far value if (m_xBlendFar < m_xBlendNear) { m_xBlendFar = m_xBlendNear + 1; m_cBlendFar.SetPos((int)m_xBlendFar); } } if (pScrollBar == (void*) &m_cBlendFar) { // get new far value m_xBlendFar = (float) m_cBlendFar.GetPos(); // if necessary, update near value if (m_xBlendFar < m_xBlendNear) { m_xBlendNear = m_xBlendFar - 1; m_cBlendNear.SetPos((int)m_xBlendNear); } } CFormView::OnHScroll(nSBCode, nPos, pScrollBar); } */ /*---------------------------------------- ----------------------------------------*/ /* void SECT_DialogVis::OnEditColor () { CColorDialog oColorDialog; // display color dialog if (oColorDialog.DoModal() == IDOK) { // get selected color m_stColor = oColorDialog.GetColor(); // update controls fn_vUpdateSliders(); fn_vUpdateColor(); } } */ /*---------------------------------------- ----------------------------------------*/ /* void SECT_DialogVis::OnSave() { SECT_ModifVisEnvParams *pModif; GLI_tdstColor stColor; int iRValue, iGValue, iBValue; // no mec env => no changes if (!m_pVisEnv) return; // default mec env => create new one if (m_pVisEnv == m_pDefaultVisEnv) m_pVisEnv = new SECT_VisEnvironment(m_pSectorInterface, m_csName); // get real color iRValue = GetRValue(m_stColor); iGValue = GetGValue(m_stColor); iBValue = GetBValue(m_stColor); stColor.xR = ((float) iRValue) / ((float) 254.0); stColor.xG = ((float) iGValue) / ((float) 254.0); stColor.xB = ((float) iBValue) / ((float) 254.0); // modif pModif = new SECT_ModifVisEnvParams(m_pSectorInterface, E_tm_ModifVisEnv, m_pVisEnv, m_csName, m_xNear, m_xFar, m_xBlendNear, m_xBlendFar, m_xInfinite, &stColor); m_pSectorInterface->M_GetEditManager()->AskFor(pModif); // give controtl to dialog env & update combo meca m_pSectorInterface->GetDialogEnv()->fn_vInitVisListBox(); m_pSectorInterface->GetDialogEnv()->fn_vSelectVisual(m_pVisEnv); m_pSectorInterface->GetDialogEnv()->fn_vInitControls(TRUE); m_pSectorInterface->GetDialogSrf()->fn_vInitControls(TRUE); m_pSectorInterface->GetDialogEnvs()->fn_vInitControls(TRUE); m_pSectorInterface->GetDialogEnvList()->fn_vInitControls(TRUE); } */ /*---------------------------------------- ----------------------------------------*/ /* void SECT_DialogVis::OnCancel() { // new mec env => cancel if (m_pVisEnv == m_pDefaultVisEnv) m_pVisEnv = NULL; // reinit controls fn_vInitVisEnvironment(m_pVisEnv, FALSE); // give controtl to dialog env m_pSectorInterface->GetDialogEnv()->fn_vInitControls(TRUE); m_pSectorInterface->GetDialogSrf()->fn_vInitControls(TRUE); m_pSectorInterface->GetDialogEnvs()->fn_vInitControls(TRUE); m_pSectorInterface->GetDialogEnvList()->fn_vInitControls(TRUE); } */ /*---------------------------------------- ----------------------------------------*/ /* void SECT_DialogVis::OnDefault() { if (m_cName.GetModify()) { OnChangeName(); m_cName.SetFocus(); } if (m_cNear.GetModify()) { OnChangeNear(); m_cNear.SetFocus(); } if (m_cFar.GetModify()) { OnChangeFar(); m_cFar.SetFocus(); } if (m_cInfinite.GetModify()) { OnChangeInfinite(); m_cInfinite.SetFocus(); } } */ /*---------------------------------------- ----------------------------------------*/ /* void SECT_DialogVis::OnSize(UINT, int, int) { RECT WindowPosition; int ecx, ecy; if (!m_bInitialised) return; // calculate name position GetWindowRect(&WindowPosition); ecx = WindowPosition.right - WindowPosition.left; ecx = (ecx < 160) ? 10 : ecx - 150; ecy = WindowPosition.bottom - WindowPosition.top; ecy = (ecy < 180) ? 0 : ecy-180; // buttons m_cCancel.MoveWindow(ecx/2, 5, 40, 16); m_cSave.MoveWindow(ecx/2+110, 5, 40, 16); // name m_cName.MoveWindow(ecx/2, 25, 150, 20); // Fog GetDlgItem(SECT_IDC_STATICFOG)->MoveWindow(ecx/2, 50, 150, 120); // parameters GetDlgItem(SECT_IDC_STATICINFINITE)->MoveWindow(ecx/2+5, 65, 40, 15); GetDlgItem(SECT_IDC_STATICNEAR)->MoveWindow(ecx/2+5, 80, 40 , 15); GetDlgItem(SECT_IDC_STATICFAR)->MoveWindow(ecx/2+5, 95, 40, 15); m_cInfinite.MoveWindow(ecx/2+50, 65, 45, 15); m_cNear.MoveWindow(ecx/2+50, 80, 45, 15); m_cFar.MoveWindow(ecx/2+50, 95, 45, 15); GetDlgItem(SECT_IDC_STATICBLEND)->MoveWindow(ecx/2+100, 65, 45 , 15); m_cBlendNear.MoveWindow(ecx/2+100, 80, 45, 15); m_cBlendFar.MoveWindow(ecx/2+100, 95, 45, 15); // color GetDlgItem(SECT_IDC_STATICCOLOR)->MoveWindow(ecx/2+5, 133, 40, 15); m_cColor.MoveWindow(ecx/2+100, 117, 40, 40); m_cRSlider.MoveWindow(ecx/2+50, 123, 15, 40); m_cGSlider.MoveWindow(ecx/2+67, 123, 15, 40); m_cBSlider.MoveWindow(ecx/2+84, 123, 15, 40); // update fn_vUpdateColor(); } */ /*---------------------------------------- ----------------------------------------*/ /* void SECT_DialogVis::OnDrawItem (int nIDCtl, LPDRAWITEMSTRUCT lpDIS) { // not interested => default handling if ((lpDIS->itemID == LB_ERR) || (nIDCtl != SECT_IDC_COLOR)) return; // draw item fn_vUpdateColor(); } */ /*---------------------------------------- ----------------------------------------*/ /* void SECT_DialogVis::OnDestroy (void) { // FOR TUTORIAL TUT_M_vGetTutDll(); // visual environment TUT_M_vUnregisterControl(m_cName.m_hWnd); TUT_M_vUnregisterControl(m_cDefault.m_hWnd); TUT_M_vUnregisterControl(m_cCancel.m_hWnd); TUT_M_vUnregisterControl(m_cSave.m_hWnd); // parameters TUT_M_vUnregisterControl(m_cNear.m_hWnd); TUT_M_vUnregisterControl(m_cFar.m_hWnd); TUT_M_vUnregisterControl(m_cInfinite.m_hWnd); // color TUT_M_vUnregisterControl(m_cRSlider.m_hWnd); TUT_M_vUnregisterControl(m_cGSlider.m_hWnd); TUT_M_vUnregisterControl(m_cBSlider.m_hWnd); TUT_M_vUnregisterControl(m_cColor.m_hWnd); // END TUTORIAL CFormView::OnDestroy(); } */