www.pudn.com > MyMFCVega.rar > SetEnvDlg.cpp
// SetEnvDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MyMFCVega.h"
#include "SetEnvDlg.h"
#include "vg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSetEnvDlg dialog
CSetEnvDlg::CSetEnvDlg(CMyMFCVegaView* pParent /*=NULL*/)
: CDialog(CSetEnvDlg::IDD, pParent),m_pVegaView(pParent)
{
//{{AFX_DATA_INIT(CSetEnvDlg)
// NOTE: the ClassWizard will add member initialization here
m_showTod=_T("");
//}}AFX_DATA_INIT
if(Create(CSetEnvDlg::IDD,pParent))
{
ShowWindow(SW_SHOW);
}
}
void CSetEnvDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSetEnvDlg)
DDX_Control(pDX, IDC_SKYCOLOR, m_SkyColor);
DDX_Control(pDX, IDC_FOGCOLOR, m_FogColor);
DDX_Control(pDX, IDC_SLIDER_TOD, m_SldTod);
DDX_Control(pDX, IDC_CHECK_LIGHT, m_Light);
DDX_Control(pDX, IDC_CHECK_FOG, m_Fog);
DDX_Text(pDX, IDC_SHOWTOD, m_showTod);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSetEnvDlg, CDialog)
//{{AFX_MSG_MAP(CSetEnvDlg)
ON_BN_CLICKED(IDC_CHECK_FOG, OnCheckFog)
ON_BN_CLICKED(IDC_CHECK_LIGHT, OnCheckLight)
ON_WM_HSCROLL()
ON_WM_LBUTTONUP()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSetEnvDlg message handlers
//控制雾效果显示
void CSetEnvDlg::OnCheckFog()
{
// TODO: Add your control notification handler code here
m_pVegaView->toggleGfx(VGGFX_FOG);
}
//设置对话框显示时各控件的初始状态
BOOL CSetEnvDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
UpdateData(TRUE); //retrieve and validate dialog data
m_Fog.SetCheck(vgGetProp(m_pVegaView->gfx,VGGFX_FOG));
m_Light.SetCheck(vgGetProp(m_pVegaView->gfx,VGGFX_LIGHTING));
m_SldTod.SetRange(0,100,TRUE);
float tod=vgGetProp(m_pVegaView->env,VGENV_TOD);//VGENV_TOD: Specifies the time of day scaler
m_showTod.Format("%4.2f",tod);
m_SldTod.SetPos((int)(tod*100));
UpdateData(FALSE); //dialog box is being initialized
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//灯光效果显示
void CSetEnvDlg::OnCheckLight()
{
// TODO: Add your control notification handler code here
m_pVegaView->toggleGfx(VGGFX_LIGHTING);
}
void CSetEnvDlg::OnOK()
{
AfxGetMainWnd()->EnableWindow();
DestroyWindow();
}
//滑动滑块控制vega环境的时辰参数TOD
//OnHScroll: The framework calls this member function when the user clicks a window’s horizontal scroll bar
void CSetEnvDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
UpdateData(TRUE);
if(pScrollBar->GetDlgCtrlID()==IDC_SLIDER_TOD)
{
int tod=m_SldTod.GetPos();
float timeofday=tod/100.0f;
m_showTod.Format("%4.2f",timeofday);
vgProp(m_pVegaView->env,VGENV_TOD,timeofday);
}
UpdateData(FALSE);
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
//在IDC_FOGCOLOR和IDC_SKYCOLOR控件范围内单击,激活颜色选择对话框,为天空和雾选择颜色
void CSetEnvDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
UpdateData(TRUE);
CRect rect;
m_SkyColor.GetWindowRect(&rect);
ScreenToClient(&rect);
if(rect.PtInRect(point))
{
float r,g,b;
COLORREF color;
color=FillColor(IDC_SKYCOLOR);
r=GetRValue(color)/360.0f;
g=GetGValue(color)/360.0f;
b=GetBValue(color)/360.0f;
vgEnvColor(m_pVegaView->env,VGENV_SKYCOLOR,r,g,b);
}
m_FogColor.GetWindowRect(&rect);
ScreenToClient(&rect);
if(rect.PtInRect(point))
{
float r,g,b;
COLORREF color;
color=FillColor(IDC_FOGCOLOR);
r=GetRValue(color)/360.0f;
g=GetGValue(color)/360.0f;
b=GetBValue(color)/360.0f;
vgEnvColor(m_pVegaView->env,VGENV_VISCOLOR,r,g,b);
}
UpdateData(FALSE);
CDialog::OnLButtonUp(nFlags, point);
}
COLORREF CSetEnvDlg::FillColor(UINT nIDC)
{
CDC* dc;
CBrush *b;
CRect rect;
COLORREF c;
CColorDialog dlg;
if(dlg.DoModal()==IDOK)
{
c=dlg.GetColor();
b=new CBrush(c);
GetDlgItem(nIDC)->GetClientRect(&rect);
dc=GetDlgItem(nIDC)->GetDC();
dc->FillRect(rect,b);
GetDlgItem(nIDC)->ReleaseDC(dc);
delete b;
}
return c;
}
int CSetEnvDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
return 0;
}