3dPageGrid.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:6k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // 3dPageGrid.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 "3dObjectDialog.h"
- #include "MyColorPaletteWnd.h"
- #include "EditColorDlg.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageGrid
- IMPLEMENT_DYNCREATE(C3dPageGrid, CPropertyPage)
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageGrid dialog construction
- C3dPageGrid::C3dPageGrid()
- : CPropertyPage(C3dPageGrid::IDD)
- {
- m_pColorList = NULL;
- //{{AFX_DATA_INIT(C3dPageGrid)
- m_fDepth = 0.0f;
- m_fWidth = 0.0f;
- m_iDivisionsX = 0;
- m_iDivisionsY = 0;
- m_szName = _T("");
- //}}AFX_DATA_INIT
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageGrid Destructor
- C3dPageGrid::~C3dPageGrid()
- {
- }
- void C3dPageGrid::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(C3dPageGrid)
- DDX_Control(pDX, IDC_COLOR_GRID_COMBO, m_ColorCombo);
- DDX_Text(pDX, IDC_DEPTH, m_fDepth);
- DDX_Text(pDX, IDC_WIDTH, m_fWidth);
- DDX_Text(pDX, IDC_DIVISIONS_X, m_iDivisionsX);
- DDX_Text(pDX, IDC_DIVISIONS_Y, m_iDivisionsY);
- DDX_Text(pDX, IDC_NAME, m_szName);
- DDV_MaxChars(pDX, m_szName, 40);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(C3dPageGrid, CPropertyPage)
- //{{AFX_MSG_MAP(C3dPageGrid)
- ON_CBN_SELCHANGE(IDC_COLOR_GRID_COMBO, OnSelchangeColorCombo)
- ON_WM_DRAWITEM()
- ON_BN_CLICKED(IDC_BUTTON_COLOR_WND, OnButtonColorWnd)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageGrid Implementation
- void C3dPageGrid::PaintButtonWnd(C3dColor* pColor)
- {
- CRect rect; // window rect
- CDC* pDC; // pointer to a device context
- if(!pColor)
- return; // No color to paint!
- // 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(pColor->m_fColor[0]*255,
- pColor->m_fColor[1]*255,
- pColor->m_fColor[2]*255));
- }
- ReleaseDC(pDC);
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageGrid message handlers
- BOOL C3dPageGrid::OnInitDialog()
- {
- // let the base class do the default work
- CPropertyPage::OnInitDialog();
- // Set our local values to the Objects' values
- m_szName = m_pObject->m_szName;
- m_fWidth = m_pObject->m_fWidth;
- m_fDepth = m_pObject->m_fDepth;
- m_iDivisionsX = m_pObject->m_iDivisionsX;
- m_iDivisionsY = m_pObject->m_iDivisionsY;
- if(m_pColorList)
- // Fill the combo box with all colors in the list
- m_pColorList->LoadComboBox(&m_ColorCombo, &m_pObject->m_AltColor);
- // Create the owner drawn button color window
- CRect rect;
- GetDlgItem(IDC_BUTTON_COLOR_WND)->GetWindowRect(&rect);
- ScreenToClient(&rect);
- // Create the 'Alt 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
- // 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 C3dPageGrid::OnOK()
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- // Set our Objects' values to the local values
- m_pObject->m_szName = m_szName;
- m_pObject->m_fDepth = m_fDepth;
- m_pObject->m_fWidth = m_fWidth;
- m_pObject->m_iDivisionsX = m_iDivisionsX;
- m_pObject->m_iDivisionsY = m_iDivisionsY;
- // Force the object to rebuild its' display list
- m_pObject->m_bBuildLists = TRUE;
- CPropertyPage::OnOK();
- }
- void C3dPageGrid::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_AltColor.SetColor4fv(pColor);
- PaintButtonWnd(pColor);
- }
- }
- void C3dPageGrid::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
- // Call the default handler first
- CPropertyPage::OnDrawItem(nIDCtl, lpDrawItemStruct);
- if(nIDCtl == IDC_BUTTON_COLOR_WND)
- PaintButtonWnd(&m_pObject->m_AltColor);
- }
- void C3dPageGrid::OnButtonColorWnd()
- {
- if(m_pObject)
- {
- C3dColor cColor;
- cColor.SetColor4fv(&m_pObject->m_AltColor);
- // 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_AltColor.SetColor4fv(&colorDlg.m_Color);
- PaintButtonWnd(&m_pObject->m_AltColor);
- }
- }
- }