3dPageColorMatl.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:6k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // 3dPageColorMatl.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 "EditTextureDlg.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
- //////////////////////////////////////////////////////////////////
- // C3dPageColorMatl
- IMPLEMENT_DYNCREATE(C3dPageColorMatl, CPropertyPage)
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageColorMatl dialog construction
- C3dPageColorMatl::C3dPageColorMatl()
- : CPropertyPage(C3dPageColorMatl::IDD)
- {
- m_pColorList = NULL;
- m_pMatlList = NULL;
- //{{AFX_DATA_INIT(C3dPageColorMatl)
- //}}AFX_DATA_INIT
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageColorMatl Destructor
- C3dPageColorMatl::~C3dPageColorMatl()
- {
- }
- void C3dPageColorMatl::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(C3dPageColorMatl)
- DDX_Control(pDX, IDC_COLOR_COMBO, m_ColorCombo);
- DDX_Control(pDX, IDC_MATL_COMBO, m_MatlCombo);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(C3dPageColorMatl, CPropertyPage)
- //{{AFX_MSG_MAP(C3dPageColorMatl)
- ON_CBN_SELCHANGE(IDC_MATL_COMBO, OnSelchangeMatlCombo)
- ON_BN_CLICKED(IDC_BUTTON_COLOR_WND, OnButtonColorWnd)
- ON_CBN_SELCHANGE(IDC_COLOR_COMBO, OnSelchangeColorCombo)
- ON_WM_DRAWITEM()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageColorMatl message handlers
- BOOL C3dPageColorMatl::OnInitDialog()
- {
- // let the base class do the default work
- CPropertyPage::OnInitDialog();
- // 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
- if(m_pColorList)
- // Fill the combo box with all colors in the list
- m_pColorList->LoadComboBox(&m_ColorCombo, &m_pObject->m_Color);
- if(m_pMatlList)
- {
- // Fill the combo box with all Materials in the list
- m_pMatlList->LoadComboBox(&m_MatlCombo);
- // if the object has a material attached, display the
- // material in the list box of the combo box
- if(m_pObject->m_pMaterial)
- m_MatlCombo.SelectString(-1, m_pObject->m_pMaterial->m_szName);
- }
- // 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 C3dPageColorMatl::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
- // Call the default handler first
- CPropertyPage::OnDrawItem(nIDCtl, lpDrawItemStruct);
- if(nIDCtl == IDC_BUTTON_COLOR_WND)
- PaintButtonWnd();
- }
- void C3dPageColorMatl::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 objects color and paint the color
- // button window
- m_pObject->m_Color.SetColor4fv(pColor);
- PaintButtonWnd();
- }
- }
- void C3dPageColorMatl::OnSelchangeMatlCombo()
- {
- C3dMaterial* pMatl;
- // Get the zero-based index of the item selected
- int index = m_MatlCombo.GetCurSel();
- // Cast the user selected list box items' lParam to
- // a C3dMaterial pointer..
- pMatl = (C3dMaterial*)m_MatlCombo.GetItemData(index);
- if(pMatl)
- {
- // Display the materials values
- m_pObject->SetMaterial(pMatl);
- }
- }
- void C3dPageColorMatl::OnButtonColorWnd()
- {
- if(m_pObject)
- {
- C3dColor cColor;
- cColor.SetColor4fv(&m_pObject->m_Color);
- // Create the dialog
- CEditColorDlg colorDlg(m_pColorList, &cColor, 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_pObject->m_Color.SetColor4fv(&colorDlg.m_Color);
- PaintButtonWnd();
- }
- }
- }
- void C3dPageColorMatl::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_pObject)
- {
- // Since this is an owner drawn button and CPropertyPage
- // will not accept extended window attributes, we will
- // draw the border for the button, then the selected color.
- // Draw the box color
- pDC->FillSolidRect(0,
- 0,
- rect.right-rect.left,
- rect.bottom-rect.top,
- COLORREF RGB(m_pObject->m_Color.m_fColor[0]*255,
- m_pObject->m_Color.m_fColor[1]*255,
- m_pObject->m_Color.m_fColor[2]*255));
- }
- ReleaseDC(pDC);
- }