3dPageBackground.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:9k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageBackground.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 "3dObjectDialog.h"
- #include "3dBackgroundDialog.h"
- #include "EditColorDlg.h"
- #include "EditTextureDlg.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
- //////////////////////////////////////////////////////////////////
- // C3dPageBackground
- IMPLEMENT_DYNCREATE(C3dPageBackground, CPropertyPage)
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageBackground dialog construction
- C3dPageBackground::C3dPageBackground()
- : CPropertyPage(C3dPageBackground::IDD)
- {
- //{{AFX_DATA_INIT(C3dPageBackground)
- m_szBkgndFileName = _T("<None>");
- //}}AFX_DATA_INIT
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageBackground Destructor
- C3dPageBackground::~C3dPageBackground()
- {
- }
- void C3dPageBackground::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(C3dPageBackground)
- DDX_Control(pDX, IDC_COLOR_COMBO, m_ColorCombo);
- DDX_Text(pDX, IDC_IMAGE_NAME, m_szBkgndFileName);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(C3dPageBackground, CPropertyPage)
- //{{AFX_MSG_MAP(C3dPageBackground)
- ON_CBN_SELCHANGE(IDC_COLOR_COMBO, OnSelchangeColorCombo)
- ON_BN_CLICKED(IDC_BUTTON_COLOR_WND, OnButtonColorWnd)
- ON_WM_DRAWITEM()
- ON_BN_CLICKED(IDC_TEXTURE_OPEN, OnTextureOpen)
- ON_BN_CLICKED(IDC_TEXTURE_EDIT, OnTextureEdit)
- ON_BN_CLICKED(IDC_TEXTURE_REMOVE, OnTextureRemove)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageBackground message handlers
- BOOL C3dPageBackground::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_wndBkgndColor.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
- // Fill the combo box with all colors in the list
- m_pWorld->m_ColorList.LoadComboBox(&m_ColorCombo, &m_pWorld->m_BackgroundColor);
- // If our 3dWorld has a background Texture map, copy its name to
- // the CEdit box.
- if(m_pWorld->m_pBkgndTexture)
- {
- if(m_pWorld->m_pBkgndTexture->m_szFileName.GetLength())
- m_szBkgndFileName = m_pWorld->m_pBkgndTexture->m_szFileName;
- }
- // 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 C3dPageBackground::OnOK()
- {
- // Get the dialog data
- UpdateData(TRUE);
- // Set the Objects Translate..
- // m_pObject->m_fTranslate[0] = m_fTranslateX;
- // m_pObject->m_fTranslate[1] = m_fTranslateY;
- // m_pObject->m_fTranslate[2] = m_fTranslateZ;
- CPropertyPage::OnOK();
- }
- void C3dPageBackground::OnSelchangeColorCombo()
- {
- C3dColor* pColor;
- // Get the zero-based index of the item selected
- int index = m_ColorCombo.GetCurSel();
- if(index == CB_ERR)
- return;
- // Cast the user selected list box items' lParam to
- // a C3dColor pointer..
- pColor = (C3dColor*)m_ColorCombo.GetItemData(index);
- if(pColor)
- {
- // Set the world's background color and name, then
- // and paint the color button window
- m_pWorld->m_BackgroundColor.SetColor4fv(pColor);
- m_pWorld->m_BackgroundColor.m_szName = pColor->m_szName;
- PaintButtonWnd();
- }
- }
- void C3dPageBackground::OnButtonColorWnd()
- {
- if(m_pWorld)
- {
- C3dColor cColor;
- cColor.SetColor4fv(&m_pWorld->m_BackgroundColor);
- // Create the dialog
- CEditColorDlg colorDlg(&m_pWorld->m_ColorList, &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_pWorld->m_BackgroundColor.SetColor4fv(&colorDlg.m_Color);
- PaintButtonWnd();
- }
- }
- }
- void C3dPageBackground::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 C3dPageBackground::PaintButtonWnd()
- {
- CRect rect; // window rect
- CDC* pDC; // pointer to a device context
- // Get the size of the color button window
- m_wndBkgndColor.GetWindowRect(&rect);
- // Get a pointer to the windows device context
- pDC = m_wndBkgndColor.GetDC();
- if(pDC && m_pWorld)
- {
- // 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 shading highlights
- pDC->FillSolidRect(0,
- 0,
- rect.right-rect.left,
- rect.bottom-rect.top,
- COLORREF RGB(96, 96, 96)); // dark gray
- // Draw box shading
- pDC->FillSolidRect(0,
- 0,
- (rect.right-rect.left)-2,
- (rect.bottom-rect.top)-2,
- COLORREF RGB(239, 239, 239));// very light gray
- // Draw shading in lower left corner
- pDC->SetPixel(1, rect.bottom-1,
- COLORREF RGB(239, 239, 239)); // very light gray
- // Draw shading in top right corner
- pDC->SetPixel(rect.right-1, 1,
- COLORREF RGB(239, 239, 239)); // very light gray
- */
- // Draw the box color
- pDC->FillSolidRect(0,
- 0,
- rect.right-rect.left,
- rect.bottom-rect.top,
- COLORREF RGB(m_pWorld->m_BackgroundColor.m_fColor[0]*255,
- m_pWorld->m_BackgroundColor.m_fColor[1]*255,
- m_pWorld->m_BackgroundColor.m_fColor[2]*255));
- }
- ReleaseDC(pDC);
- }
- void C3dPageBackground::OnTextureOpen()
- {
- CFileDialog fileDlg(TRUE, NULL, NULL);
- fileDlg.m_ofn.lpstrFilter = "Texture Files (*.bmp) *.bmp DIB Files (*.dib) *.dib AVI Files (*.avi) *.avi All Files (*.*) *.* ";
- fileDlg.m_ofn.lpstrTitle = "Open Texture Map";
- if(!m_pWorld)
- return;
- int retn = fileDlg.DoModal();
- if(retn == IDOK) {
- CString szFile = fileDlg.GetFileName();
- CString szPath = fileDlg.GetPathName();
- CString szFileExt = fileDlg.GetFileExt();
- if(szFileExt.Compare("bmp") == 0 ||
- szFileExt.Compare("dib") == 0 ||
- szFileExt.Compare("avi") == 0)
- {
- if(m_pWorld->AddTexture(szPath.GetBuffer(128)))
- {
- // Set the magnification filter to nearest for clearest
- // image quality
- m_pWorld->m_pBkgndTexture->m_iMagfilter = GL_NEAREST;
- // }
- // if(m_pWorld->m_pBkgndTexture->OpenTextureMap(szPath.GetBuffer(128), the3dEngine.m_hPalette))
- // {
- m_szBkgndFileName = szPath;
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- }
- else
- AfxMessageBox("Unsupported File Extension! Select files with either 'bmp' or 'dib' extensions.", MB_OK, NULL);
- }
- }
- void C3dPageBackground::OnTextureEdit()
- {
- // Get a pointer to our 3dWorld background texture
- if(m_pWorld)
- {
- if(m_pWorld->m_pBkgndTexture)
- {
- CTexture* pTexture = m_pWorld->m_pBkgndTexture;
- ASSERT(pTexture);
- CEditTextureDlg textureDlg(pTexture, CWnd::GetActiveWindow());
- textureDlg.DoModal();
- // Force a repaint of the window
- pTexture->m_bApplyImage = TRUE;
- }
- else
- AfxMessageBox("There are no background textures to edit!", MB_OK, 0);
- }
- }
- void C3dPageBackground::OnTextureRemove()
- {
- if(m_pWorld)
- {
- if(m_pWorld->m_pBkgndTexture) {
- // Delete the background texture map
- m_pWorld->DeleteTexture();
- m_szBkgndFileName = _T("<None>");
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- }
- }