3dPageTerrainColor.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:11k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // 3dPageTerrainColor.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
- //////////////////////////////////////////////////////////////////
- // C3dPageTerrainColor
- IMPLEMENT_DYNCREATE(C3dPageTerrainColor, CPropertyPage)
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageTerrainColor dialog construction
- C3dPageTerrainColor::C3dPageTerrainColor()
- :CPropertyPage(C3dPageTerrainColor::IDD)
- {
- m_pWorld = NULL;
- m_pObject = NULL;
- m_pWndTerrainPreview = new CMyTerrainWnd;
- //{{AFX_DATA_INIT(C3dPageTerrainColor)
- m_iColorSelect = 0;
- m_iSolidColor = -1;
- m_bReflect = FALSE;
- //}}AFX_DATA_INIT
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageTerrainColor Destructor
- C3dPageTerrainColor::~C3dPageTerrainColor()
- {
- if(m_pWndTerrainPreview)
- delete m_pWndTerrainPreview;
- }
- void C3dPageTerrainColor::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(C3dPageTerrainColor)
- DDX_Radio(pDX, IDC_RADIO_SNOW, m_iColorSelect);
- DDX_Radio(pDX, IDC_RADIO_COLOR_SOLID, m_iSolidColor);
- DDX_Check(pDX, IDC_CHECK_REFLECT, m_bReflect);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(C3dPageTerrainColor, CPropertyPage)
- //{{AFX_MSG_MAP(C3dPageTerrainColor)
- ON_BN_CLICKED(IDC_BUTTON_COLOR_WND, OnButtonColorWnd)
- ON_WM_DRAWITEM()
- ON_BN_CLICKED(IDC_RADIO_COLOR_GRADIENT, OnRadioColorGradient)
- ON_BN_CLICKED(IDC_RADIO_COLOR_SOLID, OnRadioColorSolid)
- ON_BN_CLICKED(IDC_RADIO_GRASS, OnRadioGrass)
- ON_BN_CLICKED(IDC_RADIO_ROCK, OnRadioRock)
- ON_BN_CLICKED(IDC_RADIO_SNOW, OnRadioSnow)
- ON_BN_CLICKED(IDC_RADIO_WATER, OnRadioWater)
- ON_BN_CLICKED(IDC_CHECK_REFLECT, OnCheckReflect)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageTerrainColor operations
- void C3dPageTerrainColor::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);
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageTerrainColor message handlers
- BOOL C3dPageTerrainColor::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_COLOR_WND)->GetWindowRect(&rect);
- ScreenToClient(&rect);
- m_wndButtonColor.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
- GetDlgItem(IDC_TERRAIN_PREVIEW_WND)->GetWindowRect(&rect);
- ScreenToClient(&rect);
- m_pWndTerrainPreview->Create(NULL, // dwExtStyle
- NULL, // lpszClassName
- NULL, // lpszWindowName
- WS_CHILD | WS_VISIBLE | // dwStyle
- WS_DLGFRAME,
- rect, // rect
- this, // CWnd* pParentWnd
- IDC_TERRAIN_PREVIEW_WND,// UINT nID
- 0); // pContext
- if(!m_pWndTerrainPreview->m_pTerrainObject)
- {
- AfxMessageBox("Not enough memory to create preview terrain.", MB_OK);
- return FALSE;
- }
- if(m_pObject->m_bSolidColor)
- {
- m_iSolidColor = 0;
- // Set the data window enable/disable states
- GetDlgItem(IDC_RADIO_SNOW)->EnableWindow(FALSE);
- GetDlgItem(IDC_RADIO_ROCK)->EnableWindow(FALSE);
- GetDlgItem(IDC_RADIO_GRASS)->EnableWindow(FALSE);
- GetDlgItem(IDC_RADIO_WATER)->EnableWindow(FALSE);
- GetDlgItem(IDC_CHECK_REFLECT)->EnableWindow(FALSE);
- }
- else
- m_iSolidColor = 1;
- m_bReflect = m_pObject->m_bReflect;
- // Initialize our preview window Terrain object
- m_pObject->CopyParameters(m_pWndTerrainPreview->m_pTerrainObject);
- m_pWndTerrainPreview->m_pTerrainObject->m_bBuildLists = TRUE;
- m_pWndTerrainPreview->m_pTerrainObject->InitTerrain();
- // 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 C3dPageTerrainColor::OnOK()
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- // Copy the parameters from the preview window to our terrain object
- m_pWndTerrainPreview->m_pTerrainObject->CopyParameters(m_pObject);
- // Force the object to rebuild its' display list
- m_pObject->m_bBuildLists = TRUE;
- // Rebuild our objects vertices and color table
- m_pObject->InitTerrain();
- CPropertyPage::OnOK();
- }
- void C3dPageTerrainColor::OnButtonColorWnd()
- {
- C3dColor SelColor;
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- C3dObjectTerrain* pTerrain = m_pWndTerrainPreview->m_pTerrainObject;
- if(m_pWorld && pTerrain)
- {
- if(!pTerrain->m_bSolidColor)
- {
- if(m_iColorSelect == 0)
- SelColor.SetColor4fv(&pTerrain->m_ColorSnow);
- else if(m_iColorSelect == 1)
- SelColor.SetColor4fv(&pTerrain->m_ColorRock);
- else if(m_iColorSelect == 2)
- SelColor.SetColor4fv(&pTerrain->m_ColorGrass);
- else
- SelColor.SetColor4fv(&pTerrain->m_ColorWater);
- }
- else
- SelColor.SetColor4fv(&pTerrain->m_Color);
- // Create the dialog
- CEditColorDlg colorDlg(&m_pWorld->m_ColorList, &SelColor, this);
- // Invoke the modal dialog box and return the
- // dialog-box result when done.
- if(colorDlg.DoModal() == IDOK)
- {
- if(!pTerrain->m_bSolidColor)
- {
- // Save any changes the user may have made
- if(m_iColorSelect == 0)
- pTerrain->m_ColorSnow.SetColor4fv(&colorDlg.m_Color);
- else if(m_iColorSelect == 1)
- pTerrain->m_ColorRock.SetColor4fv(&colorDlg.m_Color);
- else if(m_iColorSelect == 2)
- pTerrain->m_ColorGrass.SetColor4fv(&colorDlg.m_Color);
- else
- pTerrain->m_ColorWater.SetColor4fv(&colorDlg.m_Color);
- }
- else
- pTerrain->m_Color.SetColor4fv(&colorDlg.m_Color);
- // Repaint the color button
- PaintButtonWnd(&m_wndButtonColor, &colorDlg.m_Color);
- // Reinitialize our preview terrain data and update the window
- pTerrain->m_bBuildLists = TRUE;
- pTerrain->InitTerrain();
- m_pWndTerrainPreview->RedrawWindow();
- }
- }
- }
- void C3dPageTerrainColor::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
- CPropertyPage::OnDrawItem(nIDCtl, lpDrawItemStruct);
- C3dObjectTerrain* pTerrain = m_pWndTerrainPreview->m_pTerrainObject;
- if(nIDCtl == IDC_BUTTON_COLOR_WND && m_wndButtonColor.m_hWnd)
- {
- if(!pTerrain->m_bSolidColor)
- {
- if(m_iColorSelect == 0)
- PaintButtonWnd(&m_wndButtonColor, &pTerrain->m_ColorSnow);
- else if(m_iColorSelect == 1)
- PaintButtonWnd(&m_wndButtonColor, &pTerrain->m_ColorRock);
- else if(m_iColorSelect == 2)
- PaintButtonWnd(&m_wndButtonColor, &pTerrain->m_ColorGrass);
- else
- PaintButtonWnd(&m_wndButtonColor, &pTerrain->m_ColorWater);
- }
- else
- PaintButtonWnd(&m_wndButtonColor, &pTerrain->m_Color);
- }
- }
- void C3dPageTerrainColor::OnRadioColorGradient()
- {
- C3dObjectTerrain* pTerrain = m_pWndTerrainPreview->m_pTerrainObject;
- // Set the data window enable/disable states
- GetDlgItem(IDC_RADIO_SNOW)->EnableWindow(TRUE);
- GetDlgItem(IDC_RADIO_ROCK)->EnableWindow(TRUE);
- GetDlgItem(IDC_RADIO_GRASS)->EnableWindow(TRUE);
- GetDlgItem(IDC_RADIO_WATER)->EnableWindow(TRUE);
- GetDlgItem(IDC_CHECK_REFLECT)->EnableWindow(TRUE);
- // Repaint the color button
- if(m_iColorSelect == 0)
- PaintButtonWnd(&m_wndButtonColor, &pTerrain->m_ColorSnow);
- else if(m_iColorSelect == 1)
- PaintButtonWnd(&m_wndButtonColor, &pTerrain->m_ColorRock);
- else if(m_iColorSelect == 2)
- PaintButtonWnd(&m_wndButtonColor, &pTerrain->m_ColorGrass);
- else
- PaintButtonWnd(&m_wndButtonColor, &pTerrain->m_ColorWater);
- // Re-initialize our terrain data and update the preview window
- pTerrain->m_bSolidColor = FALSE;
- pTerrain->m_bBuildLists = TRUE;
- pTerrain->InitTerrain();
- m_pWndTerrainPreview->RedrawWindow();
- }
- void C3dPageTerrainColor::OnRadioColorSolid()
- {
- C3dObjectTerrain* pTerrain = m_pWndTerrainPreview->m_pTerrainObject;
- PaintButtonWnd(&m_wndButtonColor, &pTerrain->m_Color);
- // Set the data window enable/disable states
- GetDlgItem(IDC_RADIO_SNOW)->EnableWindow(FALSE);
- GetDlgItem(IDC_RADIO_ROCK)->EnableWindow(FALSE);
- GetDlgItem(IDC_RADIO_GRASS)->EnableWindow(FALSE);
- GetDlgItem(IDC_RADIO_WATER)->EnableWindow(FALSE);
- GetDlgItem(IDC_CHECK_REFLECT)->EnableWindow(FALSE);
- // Re-initialize our terrain data and update the preview window
- pTerrain->m_bSolidColor = TRUE;
- pTerrain->m_bBuildLists = TRUE;
- pTerrain->InitTerrain();
- m_pWndTerrainPreview->RedrawWindow();
- }
- void C3dPageTerrainColor::OnRadioGrass()
- {
- C3dObjectTerrain* pTerrain = m_pWndTerrainPreview->m_pTerrainObject;
- PaintButtonWnd(&m_wndButtonColor, &pTerrain->m_ColorGrass);
- }
- void C3dPageTerrainColor::OnRadioRock()
- {
- C3dObjectTerrain* pTerrain = m_pWndTerrainPreview->m_pTerrainObject;
- PaintButtonWnd(&m_wndButtonColor, &pTerrain->m_ColorRock);
- }
- void C3dPageTerrainColor::OnRadioSnow()
- {
- C3dObjectTerrain* pTerrain = m_pWndTerrainPreview->m_pTerrainObject;
- PaintButtonWnd(&m_wndButtonColor, &pTerrain->m_ColorSnow);
- }
- void C3dPageTerrainColor::OnRadioWater()
- {
- C3dObjectTerrain* pTerrain = m_pWndTerrainPreview->m_pTerrainObject;
- PaintButtonWnd(&m_wndButtonColor, &pTerrain->m_ColorWater);
- }
- void C3dPageTerrainColor::OnCheckReflect()
- {
- C3dObjectTerrain* pTerrain = m_pWndTerrainPreview->m_pTerrainObject;
- pTerrain->m_bReflect = !pTerrain->m_bReflect;
- // Re-initialize our terrain data and redraw our
- // preview window.
- pTerrain->m_bBuildLists = TRUE;
- pTerrain->InitTerrain();
- m_pWndTerrainPreview->RedrawWindow();
- }