3dPageBackgroundFog.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:9k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageBackgroundFog.cpp : implementation file
- //
- // glOOP (OpenGL Object Oriented Programming library)
- // Copyright (c) Craig Fahrnbach 1997, 1998
- //
- // OpenGL is a registered trademark of Silicon Graphics
- //
- //
- // This program is provided for educational and personal use only and
- // is provided without guarantee or warrantee expressed or implied.
- //
- // Commercial use is strickly prohibited without written permission
- // from ImageWare Development.
- //
- // This program is -not- in the public domain.
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "glOOP.h"
- #include "MyColorPaletteWnd.h"
- #include "EditColorDlg.h"
- #include "3dObjectDialog.h"
- #include "3dBackgroundDialog.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
- //////////////////////////////////////////////////////////////////
- // C3dPageBackgroundFog
- IMPLEMENT_DYNCREATE(C3dPageBackgroundFog, CPropertyPage)
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageBackgroundFog dialog construction
- C3dPageBackgroundFog::C3dPageBackgroundFog()
- : CPropertyPage(C3dPageBackgroundFog::IDD)
- {
- m_pWorld = NULL;
- //{{AFX_DATA_INIT(C3dPageBackgroundFog)
- m_fDensity = 0.0f;
- m_fEnd = 0.0f;
- m_fStart = 0.0f;
- m_iFogEnable = -1;
- m_iHint = -1;
- m_iMode = -1;
- m_fAlpha = 0.0f;
- //}}AFX_DATA_INIT
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageBackgroundFog Destructor
- C3dPageBackgroundFog::~C3dPageBackgroundFog()
- {
- }
- void C3dPageBackgroundFog::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(C3dPageBackgroundFog)
- DDX_Control(pDX, IDC_COLOR_COMBO, m_ColorCombo);
- DDX_Text(pDX, IDC_DENSITY, m_fDensity);
- DDV_MinMaxFloat(pDX, m_fDensity, 0.f, 1.f);
- DDX_Text(pDX, IDC_END, m_fEnd);
- DDX_Text(pDX, IDC_START, m_fStart);
- DDX_Radio(pDX, IDC_FOG_ENABLE, m_iFogEnable);
- DDX_Radio(pDX, IDC_HINT_FASTEST, m_iHint);
- DDX_Radio(pDX, IDC_MODE_LINEAR, m_iMode);
- DDX_Text(pDX, IDC_ALPHA, m_fAlpha);
- DDV_MinMaxFloat(pDX, m_fAlpha, 0.f, 1.f);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(C3dPageBackgroundFog, CPropertyPage)
- //{{AFX_MSG_MAP(C3dPageBackgroundFog)
- ON_BN_CLICKED(IDC_BUTTON_COLOR_WND, OnButtonColorWnd)
- ON_WM_DRAWITEM()
- ON_CBN_SELCHANGE(IDC_COLOR_COMBO, OnSelchangeColorCombo)
- ON_BN_CLICKED(IDC_FOG_ENABLE, OnFogEnable)
- ON_BN_CLICKED(IDC_HINT_FASTEST, OnHintFastest)
- ON_BN_CLICKED(IDC_HINT_NICEST, OnHintNicest)
- ON_BN_CLICKED(IDC_MODE_LINEAR, OnModeLinear)
- ON_BN_CLICKED(IDC_MODE_EXPOTENTIAL, OnModeExpotential)
- ON_BN_CLICKED(IDC_MODE_EXPOTENTIAL2, OnModeExpotential2)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageBackgroundFog message handlers
- BOOL C3dPageBackgroundFog::OnInitDialog()
- {
- // let the base class do the default work
- CPropertyPage::OnInitDialog();
- if(!m_pWorld)
- return FALSE;
- // Is fog enabled?
- if(m_pWorld->m_bFogEnable)
- m_iFogEnable = 0;
- else
- m_iFogEnable = 1;
- // Set the Environment Mode
- if(m_pWorld->m_Fog.m_enumMode == GL_LINEAR)
- {
- m_iMode = 0;
- GetDlgItem(IDC_DENSITY)->EnableWindow(FALSE);
- }
- if(m_pWorld->m_Fog.m_enumMode == GL_EXP)
- {
- m_iMode = 1;
- // GetDlgItem(IDC_START)->EnableWindow(FALSE);
- // GetDlgItem(IDC_END)->EnableWindow(FALSE);
- }
- if(m_pWorld->m_Fog.m_enumMode == GL_EXP2)
- {
- m_iMode = 2;
- // GetDlgItem(IDC_START)->EnableWindow(FALSE);
- // GetDlgItem(IDC_END)->EnableWindow(FALSE);
- }
- // Set the display Hint
- if(m_pWorld->m_Fog.m_enumHint == GL_FASTEST)
- m_iHint = 0;
- if(m_pWorld->m_Fog.m_enumHint == GL_NICEST)
- m_iHint = 1;
- // Initialize our dialog data
- m_fStart = m_pWorld->m_Fog.m_fStart;
- m_fEnd = m_pWorld->m_Fog.m_fEnd;
- m_fDensity = m_pWorld->m_Fog.m_fDensity;
- m_fAlpha = m_pWorld->m_Fog.m_Color.m_fColor[3];
- // Create the owner drawn button color window
- CRect rect;
- GetDlgItem(IDC_BUTTON_COLOR_WND)->GetWindowRect(&rect);
- ScreenToClient(&rect);
- // Create the 'Selected Color' window
- m_wndSelColor.Create(NULL, // lpszClassName
- NULL, // lpszWindowName
- WS_CHILD | WS_VISIBLE |// dwStyle
- WS_DLGFRAME,
- rect, // rect
- this, // CWnd* pParentWnd
- IDC_BUTTON_COLOR_WND, // UINT nID
- 0); // pContext
- // Load the Color Combo box
- if(m_pWorld)
- m_pWorld->m_ColorList.LoadComboBox(&m_ColorCombo, &m_pWorld->m_BackgroundColor);
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void C3dPageBackgroundFog::OnOK()
- {
- GetDialogData();
- CPropertyPage::OnOK();
- }
- void C3dPageBackgroundFog::OnButtonColorWnd()
- {
- if(m_pWorld)
- {
- // Create the dialog
- CEditColorDlg colorDlg(&m_pWorld->m_ColorList, &m_pWorld->m_Fog.m_Color, this);
- // Invoke the modal dialog box and return the
- // dialog-box result when done.
- if(colorDlg.DoModal() == IDOK)
- {
- // Save any changes the user may have made
- m_pWorld->m_Fog.m_Color.SetColor3fv(&colorDlg.m_Color);
- PaintButtonWnd();
- }
- }
- }
- void C3dPageBackgroundFog::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
- // TODO: Add your message handler code here and/or call default
- CPropertyPage::OnDrawItem(nIDCtl, lpDrawItemStruct);
- if(nIDCtl == IDC_BUTTON_COLOR_WND)
- PaintButtonWnd();
- }
- void C3dPageBackgroundFog::PaintButtonWnd()
- {
- CRect rect; // window rect
- CDC* pDC; // pointer to a device context
- // Get the size of the gradient window
- m_wndSelColor.GetWindowRect(&rect);
- // Get a pointer to the windows device context
- pDC = m_wndSelColor.GetDC();
- if(pDC && m_pWorld)
- {
- // Draw the box color
- pDC->FillSolidRect(0,
- 0,
- rect.right-rect.left,
- rect.bottom-rect.top,
- COLORREF RGB(m_pWorld->m_Fog.m_Color.m_fColor[0]*255,
- m_pWorld->m_Fog.m_Color.m_fColor[1]*255,
- m_pWorld->m_Fog.m_Color.m_fColor[2]*255));
- }
- ReleaseDC(pDC);
- }
- void C3dPageBackgroundFog::OnSelchangeColorCombo()
- {
- C3dColor* pColor;
- // Get the zero-based index of the item selected
- int index = m_ColorCombo.GetCurSel();
- // Cast the user selected list box items' lParam to
- // a C3dColor pointer..
- pColor = (C3dColor*)m_ColorCombo.GetItemData(index);
- if(pColor)
- {
- // Set the fog color and paint the color
- // button window
- m_pWorld->m_Fog.m_Color.SetColor3fv(pColor);
- PaintButtonWnd();
- }
- }
- void C3dPageBackgroundFog::OnFogEnable()
- {
- GetDialogData();
- // Toggle the radio selection
- if(m_pWorld->m_bFogEnable) {
- m_pWorld->m_bFogEnable = FALSE;
- m_iFogEnable = -1;
- }
- else {
- m_pWorld->m_bFogEnable = TRUE;
- m_iFogEnable = 0;
- }
- SetDialogData();
- }
- void C3dPageBackgroundFog::OnModeLinear()
- {
- // Set the Environment Mode
- m_pWorld->m_Fog.m_enumMode = GL_LINEAR;
- m_iMode = 0;
- // Set the data window enable/disable states
- GetDlgItem(IDC_DENSITY)->EnableWindow(FALSE);
- // GetDlgItem(IDC_START)->EnableWindow(TRUE);
- // GetDlgItem(IDC_END)->EnableWindow(TRUE);
- SetDialogData();
- }
- void C3dPageBackgroundFog::OnModeExpotential()
- {
- GetDialogData();
- // Set the Environment Mode
- m_pWorld->m_Fog.m_enumMode = GL_EXP;
- m_iMode = 1;
- // Set the data window enable/disable states
- GetDlgItem(IDC_DENSITY)->EnableWindow(TRUE);
- // GetDlgItem(IDC_START)->EnableWindow(FALSE);
- // GetDlgItem(IDC_END)->EnableWindow(FALSE);
- SetDialogData();
- }
- void C3dPageBackgroundFog::OnModeExpotential2()
- {
- GetDialogData();
- // Set the Environment Mode
- m_pWorld->m_Fog.m_enumMode = GL_EXP2;
- m_iMode = 2;
- // Set the data window enable/disable states
- GetDlgItem(IDC_DENSITY)->EnableWindow(TRUE);
- // GetDlgItem(IDC_START)->EnableWindow(FALSE);
- // GetDlgItem(IDC_END)->EnableWindow(FALSE);
- SetDialogData();
- }
- void C3dPageBackgroundFog::OnHintFastest()
- {
- GetDialogData();
- // Set the display Hint
- m_pWorld->m_Fog.m_enumHint = GL_FASTEST;
- m_iHint = 0;
- SetDialogData();
- }
- void C3dPageBackgroundFog::OnHintNicest()
- {
- GetDialogData();
- // Set the display Hint
- m_pWorld->m_Fog.m_enumHint = GL_NICEST;
- m_iHint = 1;
- SetDialogData();
- }
- void C3dPageBackgroundFog::GetDialogData()
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- // Set the world's fog attributes
- m_pWorld->m_Fog.m_fStart = m_fStart;
- m_pWorld->m_Fog.m_fEnd = m_fEnd;
- m_pWorld->m_Fog.m_fDensity = m_fDensity;
- m_pWorld->m_Fog.m_Color.m_fColor[3]= m_fAlpha;
- }
- void C3dPageBackgroundFog::SetDialogData()
- {
- // Set the world's fog attributes
- m_fStart = m_pWorld->m_Fog.m_fStart;
- m_fEnd = m_pWorld->m_Fog.m_fEnd;
- m_fDensity = m_pWorld->m_Fog.m_fDensity;
- m_fAlpha = m_pWorld->m_Fog.m_Color.m_fColor[3];
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }