3dPageLightColor.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:10k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // 3dPageLightColor.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"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
- //////////////////////////////////////////////////////////////////
- // C3dPageLightColor
- IMPLEMENT_DYNCREATE(C3dPageLightColor, CPropertyPage)
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageLightColor dialog construction
- C3dPageLightColor::C3dPageLightColor()
- :CPropertyPage(C3dPageLightColor::IDD)
- {
- m_pWorld = NULL;
- m_pLight = NULL;
- //{{AFX_DATA_INIT(C3dPageLightColor)
- m_fSpotExp = 0.0f;
- //}}AFX_DATA_INIT
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageLightColor Destructor
- C3dPageLightColor::~C3dPageLightColor()
- {
- }
- void C3dPageLightColor::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(C3dPageLightColor)
- DDX_Control(pDX, IDC_SLIDER_SPEC_HIGHLIGHT, m_SliderSpecHighlight);
- DDX_Control(pDX, IDC_COLOR_SPC_COMBO, m_ComboSpc);
- DDX_Control(pDX, IDC_COLOR_DIF_COMBO, m_ComboDif);
- DDX_Control(pDX, IDC_COLOR_AMB_COMBO, m_ComboAmb);
- DDX_Text(pDX, IDC_SPC_POWER, m_fSpotExp);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(C3dPageLightColor, CPropertyPage)
- //{{AFX_MSG_MAP(C3dPageLightColor)
- ON_BN_CLICKED(IDC_BUTTON_AMB_COLOR_WND, OnButtonAmbColorWnd)
- ON_BN_CLICKED(IDC_BUTTON_DIF_COLOR_WND, OnButtonDifColorWnd)
- ON_BN_CLICKED(IDC_BUTTON_SPC_COLOR_WND, OnButtonSpcColorWnd)
- ON_CBN_SELCHANGE(IDC_COLOR_AMB_COMBO, OnSelchangeColorAmbCombo)
- ON_CBN_SELCHANGE(IDC_COLOR_DIF_COMBO, OnSelchangeColorDifCombo)
- ON_CBN_SELCHANGE(IDC_COLOR_SPC_COMBO, OnSelchangeColorSpcCombo)
- ON_WM_DRAWITEM()
- ON_WM_HSCROLL()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageLightColor operations
- void C3dPageLightColor::PaintButtonWnd(CWnd* pWnd, C3dColor* pColor)
- {
- CRect rect; // window rect
- CDC* pDC; // pointer to a device context
- // Get the size of the gradient window
- pWnd->GetWindowRect(&rect);
- // Get a pointer to the windows device context
- pDC = pWnd->GetDC();
- if(pDC)
- pDC->FillSolidRect(0,
- 0,
- rect.right-rect.left,
- rect.bottom-rect.top,
- COLORREF RGB(pColor->m_fColor[0]*255,
- pColor->m_fColor[1]*255,
- pColor->m_fColor[2]*255));
- ReleaseDC(pDC);
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageLightColor message handlers
- BOOL C3dPageLightColor::OnInitDialog()
- {
- // let the base class do the default work
- CPropertyPage::OnInitDialog();
- if(!m_pWorld)
- return FALSE;
- // Create the owner drawn button color window
- CRect rect;
- GetDlgItem(IDC_BUTTON_AMB_COLOR_WND)->GetWindowRect(&rect);
- ScreenToClient(&rect);
- m_wndAmbButtonColor.Create(NULL, // lpszClassName
- NULL, // lpszWindowName
- WS_CHILD | WS_VISIBLE | // dwStyle
- WS_DLGFRAME,
- rect, // rect
- this, // CWnd* pParentWnd
- IDC_BUTTON_AMB_COLOR_WND,// UINT nID
- 0); // pContext
- GetDlgItem(IDC_BUTTON_DIF_COLOR_WND)->GetWindowRect(&rect);
- ScreenToClient(&rect);
- m_wndDifButtonColor.Create(NULL, // lpszClassName
- NULL, // lpszWindowName
- WS_CHILD | WS_VISIBLE | // dwStyle
- WS_DLGFRAME,
- rect, // rect
- this, // CWnd* pParentWnd
- IDC_BUTTON_DIF_COLOR_WND,// UINT nID
- 0); // pContext
- GetDlgItem(IDC_BUTTON_SPC_COLOR_WND)->GetWindowRect(&rect);
- ScreenToClient(&rect);
- m_wndSpcButtonColor.Create(NULL, // lpszClassName
- NULL, // lpszWindowName
- WS_CHILD | WS_VISIBLE | // dwStyle
- WS_DLGFRAME,
- rect, // rect
- this, // CWnd* pParentWnd
- IDC_BUTTON_SPC_COLOR_WND,// UINT nID
- 0); // pContext
- // Load the Color Combo boxes
- if(m_pWorld)
- {
- m_pWorld->m_ColorList.LoadComboBox(&m_ComboAmb, &m_pLight->m_ColorAmbient);
- m_pWorld->m_ColorList.LoadComboBox(&m_ComboDif, &m_pLight->m_ColorDiffuse);
- m_pWorld->m_ColorList.LoadComboBox(&m_ComboSpc, &m_pLight->m_ColorSpecular);
- }
- // Initialize the dialog data
- m_pLight->GetSpecularPwr(&m_fSpotExp);
- // Get a pointer to our attenuation slider, set its range and position.
- CSliderCtrl* pSlider = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_SPEC_HIGHLIGHT);
- // Note that OpenGL defines the spot exponent from 0 to 128
- pSlider->SetRange(0, 128, TRUE);
- pSlider->SetPos((int)(m_fSpotExp));
- // 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 C3dPageLightColor::OnOK()
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- // Get the dialog data and set the Directional lights' properties
- m_pLight->SetSpecularPwr(m_fSpotExp);
- // Force the light to rebuild its' display list
- m_pLight->m_bBuildLists = TRUE;
- CPropertyPage::OnOK();
- }
- void C3dPageLightColor::OnButtonAmbColorWnd()
- {
- if(m_pWorld && m_pLight)
- {
- // Create the dialog
- CEditColorDlg colorDlg(&m_pWorld->m_ColorList, &m_pLight->m_ColorAmbient, 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_pLight->m_ColorAmbient.SetColor4fv(&colorDlg.m_Color);
- PaintButtonWnd(&m_wndAmbButtonColor, &m_pLight->m_ColorAmbient);
- }
- }
- }
- void C3dPageLightColor::OnButtonDifColorWnd()
- {
- if(m_pWorld && m_pLight)
- {
- // Create the dialog
- CEditColorDlg colorDlg(&m_pWorld->m_ColorList, &m_pLight->m_ColorDiffuse, 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_pLight->m_ColorDiffuse.SetColor4fv(&colorDlg.m_Color);
- PaintButtonWnd(&m_wndDifButtonColor, &m_pLight->m_ColorDiffuse);
- }
- }
- }
- void C3dPageLightColor::OnButtonSpcColorWnd()
- {
- if(m_pWorld && m_pLight)
- {
- // Create the dialog
- CEditColorDlg colorDlg(&m_pWorld->m_ColorList, &m_pLight->m_ColorSpecular, 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_pLight->m_ColorSpecular.SetColor4fv(&colorDlg.m_Color);
- PaintButtonWnd(&m_wndSpcButtonColor, &m_pLight->m_ColorSpecular);
- }
- }
- }
- void C3dPageLightColor::OnSelchangeColorAmbCombo()
- {
- C3dColor* pColor;
- // Get the zero-based index of the item selected
- int index = m_ComboAmb.GetCurSel();
- // Cast the user selected list box items' lParam to
- // a C3dColor pointer..
- pColor = (C3dColor*)m_ComboAmb.GetItemData(index);
- if(pColor)
- {
- // Set the light ambient color and paint button
- // window
- m_pLight->m_ColorAmbient.SetColor4fv(pColor);
- PaintButtonWnd(&m_wndAmbButtonColor, pColor);
- }
- }
- void C3dPageLightColor::OnSelchangeColorDifCombo()
- {
- C3dColor* pColor;
- // Get the zero-based index of the item selected
- int index = m_ComboDif.GetCurSel();
- // Cast the user selected list box items' lParam to
- // a C3dColor pointer..
- pColor = (C3dColor*)m_ComboDif.GetItemData(index);
- if(pColor)
- {
- // Set the light ambient color and paint button
- // window
- m_pLight->m_ColorDiffuse.SetColor4fv(pColor);
- PaintButtonWnd(&m_wndDifButtonColor, pColor);
- }
- }
- void C3dPageLightColor::OnSelchangeColorSpcCombo()
- {
- C3dColor* pColor;
- // Get the zero-based index of the item selected
- int index = m_ComboSpc.GetCurSel();
- // Cast the user selected list box items' lParam to
- // a C3dColor pointer..
- pColor = (C3dColor*)m_ComboSpc.GetItemData(index);
- if(pColor)
- {
- // Set the light ambient color and paint button
- // window
- m_pLight->m_ColorSpecular.SetColor4fv(pColor);
- PaintButtonWnd(&m_wndSpcButtonColor, pColor);
- }
- }
- void C3dPageLightColor::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
- CPropertyPage::OnDrawItem(nIDCtl, lpDrawItemStruct);
- if(nIDCtl == IDC_BUTTON_AMB_COLOR_WND && m_wndAmbButtonColor.m_hWnd)
- PaintButtonWnd(&m_wndAmbButtonColor, &m_pLight->m_ColorAmbient);
- if(nIDCtl == IDC_BUTTON_DIF_COLOR_WND && m_wndDifButtonColor.m_hWnd)
- PaintButtonWnd(&m_wndDifButtonColor, &m_pLight->m_ColorDiffuse);
- if(nIDCtl == IDC_BUTTON_SPC_COLOR_WND && m_wndSpcButtonColor.m_hWnd)
- PaintButtonWnd(&m_wndSpcButtonColor, &m_pLight->m_ColorSpecular);
- }
- void C3dPageLightColor::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // Note: MFC maps vertically oriented CSliderCtrl to WM_VSCROLL
- // and horizontally oriented CSliderCtrl to WM_HSCROLL
- // Get the position of our color slider and calculate the
- // difference in position to our initial position
- int posn = m_SliderSpecHighlight.GetPos();
- if(nSBCode == SB_LINELEFT) // nSBCode = 0
- {
- }
- if(nSBCode == SB_LINERIGHT) // nSBCode = 1
- {
- }
- if(nSBCode == SB_PAGELEFT) // nSBCode = 2
- {
- }
- if(nSBCode == SB_PAGERIGHT) // nSBCode = 3
- {
- }
- if(nSBCode == SB_THUMBPOSITION) // nSBCode = 4
- {
- m_fSpotExp = (float)posn;
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- if(nSBCode == SB_THUMBTRACK) // nSBCode = 5
- {
- m_fSpotExp = (float)posn;
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- CPropertyPage::OnHScroll(nSBCode, nPos, pScrollBar);
- }