3dPageCloudColor.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:11k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // 3dPageCloudColor.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
- //////////////////////////////////////////////////////////////////
- // C3dPageCloudColor
- IMPLEMENT_DYNCREATE(C3dPageCloudColor, CPropertyPage)
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageCloudColor dialog construction
- C3dPageCloudColor::C3dPageCloudColor()
- :CPropertyPage(C3dPageCloudColor::IDD)
- {
- m_pWorld = NULL;
- m_pObject = NULL;
- m_pWndCloudPreview = new CMyCloudWnd;
- //{{AFX_DATA_INIT(C3dPageCloudColor)
- m_iColorSelect = 0;
- m_iSolidColor = -1;
- m_bReflect = FALSE;
- m_iTextureWrap = 0;
- //}}AFX_DATA_INIT
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageCloudColor Destructor
- C3dPageCloudColor::~C3dPageCloudColor()
- {
- if(m_pWndCloudPreview)
- delete m_pWndCloudPreview;
- }
- void C3dPageCloudColor::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(C3dPageCloudColor)
- DDX_Control(pDX, IDC_SLIDER_OPACITY, m_SliderOpacity);
- DDX_Control(pDX, IDC_COMBO_GRIDSIZE, m_ComboGridSize);
- DDX_Text(pDX, IDC_TILE, m_iTextureWrap);
- DDV_MinMaxInt(pDX, m_iTextureWrap, 1, 32767);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(C3dPageCloudColor, CPropertyPage)
- //{{AFX_MSG_MAP(C3dPageCloudColor)
- ON_WM_DRAWITEM()
- ON_BN_CLICKED(IDC_EDGE_BUTTON_COLOR_WND, OnEdgeButtonColorWnd)
- ON_BN_CLICKED(IDC_HIGHLIGHT_BUTTON_COLOR_WND, OnHighlightButtonColorWnd)
- ON_CBN_SELCHANGE(IDC_COMBO_GRIDSIZE, OnSelchangeComboGridsize)
- ON_EN_CHANGE(IDC_TILE, OnChangeTextureWrap)
- ON_WM_HSCROLL()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageCloudColor operations
- void C3dPageCloudColor::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);
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageCloudColor message handlers
- BOOL C3dPageCloudColor::OnInitDialog()
- {
- // let the base class do the default work
- CPropertyPage::OnInitDialog();
- if(!m_pWorld)
- return FALSE;
- if(!m_pWndCloudPreview->m_pCloudObject)
- {
- AfxMessageBox("Not enough memory to create preview window.", MB_OK);
- return FALSE;
- }
- // Create the owner drawn button color window
- CRect rect;
- GetDlgItem(IDC_EDGE_BUTTON_COLOR_WND)->GetWindowRect(&rect);
- ScreenToClient(&rect);
- m_wndEdgeButtonColor.Create(NULL, // lpszClassName
- NULL, // lpszWindowName
- WS_CHILD | WS_VISIBLE | // dwStyle
- WS_DLGFRAME,
- rect, // rect
- this, // CWnd* pParentWnd
- IDC_EDGE_BUTTON_COLOR_WND, // UINT nID
- 0); // pContext
- GetDlgItem(IDC_HIGHLIGHT_BUTTON_COLOR_WND)->GetWindowRect(&rect);
- ScreenToClient(&rect);
- m_wndHighlightButtonColor.Create(NULL, // lpszClassName
- NULL, // lpszWindowName
- WS_CHILD | WS_VISIBLE | // dwStyle
- WS_DLGFRAME,
- rect, // rect
- this, // CWnd* pParentWnd
- IDC_HIGHLIGHT_BUTTON_COLOR_WND, // UINT nID
- 0); // pContext
- GetDlgItem(IDC_CLOUD_PREVIEW_WND)->GetWindowRect(&rect);
- ScreenToClient(&rect);
- m_pWndCloudPreview->Create(NULL, // dwExtStyle
- NULL, // lpszClassName
- NULL, // lpszWindowName
- WS_CHILD | WS_VISIBLE | // dwStyle
- WS_DLGFRAME,
- rect, // rect
- this, // CWnd* pParentWnd
- IDC_CLOUD_PREVIEW_WND, // UINT nID
- 0); // pContext
- // Fill our combo boxes and set the default selections:
- // Reset or clear the contents of the light Type combo box
- m_ComboGridSize.ResetContent();
- // Load the light type selections
- m_ComboGridSize.AddString("32 x 32 Grid");
- m_ComboGridSize.AddString("64 x 64 Grid");
- m_ComboGridSize.AddString("128 x 128 Grid");
- m_ComboGridSize.AddString("256 x 256 Grid");
- m_ComboGridSize.AddString("512 x 512 Grid");
- // Set a default selection (brute force method..)
- // (I'm sure there is some algorthium, but I'm
- // anxious..)
- if(m_pObject->m_iSize == 5)
- m_ComboGridSize.SetCurSel(0);
- if(m_pObject->m_iSize == 6)
- m_ComboGridSize.SetCurSel(1);
- if(m_pObject->m_iSize == 7)
- m_ComboGridSize.SetCurSel(2);
- if(m_pObject->m_iSize == 8)
- m_ComboGridSize.SetCurSel(3);
- if(m_pObject->m_iSize == 9)
- m_ComboGridSize.SetCurSel(4);
- // Set our Opacity slider, scaled by 100
- m_SliderOpacity.SetRange(0, 100, TRUE);
- m_SliderOpacity.SetPos((int)(sqrt(m_pObject->m_fOpacity)*100));
- // Set the initial Texture Tile size
- m_iTextureWrap = m_pObject->m_iTextureWrap;
- // Initialize our preview window cloud object
- C3dObjectCloud::CopyParameters(m_pObject, m_pWndCloudPreview->m_pCloudObject);
- m_pWndCloudPreview->m_pCloudObject->m_bBuildLists = TRUE;
- // 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 C3dPageCloudColor::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
- CPropertyPage::OnDrawItem(nIDCtl, lpDrawItemStruct);
- C3dObjectCloud* pCloud = m_pWndCloudPreview->m_pCloudObject;
- if(nIDCtl == IDC_EDGE_BUTTON_COLOR_WND && m_wndEdgeButtonColor.m_hWnd)
- PaintButtonWnd(&m_wndEdgeButtonColor, &pCloud->m_Color);
- if(nIDCtl == IDC_HIGHLIGHT_BUTTON_COLOR_WND && m_wndHighlightButtonColor.m_hWnd)
- PaintButtonWnd(&m_wndHighlightButtonColor, &pCloud->m_ColorHighlight);
- }
- void C3dPageCloudColor::OnEdgeButtonColorWnd()
- {
- C3dColor SelColor;
- // The property page settings have been modified, so
- // Enable (TRUE) or disable (FALSE) the Apply Now button
- SetModified(TRUE);
- C3dObjectCloud* pCloud = m_pWndCloudPreview->m_pCloudObject;
- if(m_pWorld)
- {
- SelColor.SetColor4fv(&pCloud->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)
- {
- // Save any changes the user may have made
- pCloud->m_Color.SetColor4fv(&colorDlg.m_Color);
- // Repaint the color button
- PaintButtonWnd(&m_wndEdgeButtonColor, &colorDlg.m_Color);
- // Reinitialize our preview terrain data and update the window
- pCloud->m_bBuildLists = TRUE;
- m_pWndCloudPreview->RedrawWindow();
- }
- }
- }
- void C3dPageCloudColor::OnHighlightButtonColorWnd()
- {
- C3dColor SelColor;
- // The property page settings have been modified, so
- // Enable (TRUE) or disable (FALSE) the Apply Now button
- SetModified(TRUE);
- C3dObjectCloud* pCloud = m_pWndCloudPreview->m_pCloudObject;
- if(m_pWorld)
- {
- SelColor.SetColor4fv(&pCloud->m_ColorHighlight);
- // 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)
- {
- // Save any changes the user may have made
- pCloud->m_ColorHighlight.SetColor4fv(&colorDlg.m_Color);
- // Repaint the color button
- PaintButtonWnd(&m_wndHighlightButtonColor, &colorDlg.m_Color);
- // Reinitialize our preview terrain data and update the window
- pCloud->m_bBuildLists = TRUE;
- m_pWndCloudPreview->RedrawWindow();
- }
- }
- }
- void C3dPageCloudColor::OnSelchangeComboGridsize()
- {
- // The property page settings have been modified, so
- // Enable (TRUE) or disable (FALSE) the Apply Now button
- SetModified(TRUE);
- C3dObjectCloud* pCloud = m_pWndCloudPreview->m_pCloudObject;
- // Get the zero-based index of the item selected
- int count = m_ComboGridSize.GetCurSel();
- if(count == 0)
- pCloud->m_iSize = 5;
- if(count == 1)
- pCloud->m_iSize = 6;
- if(count == 2)
- pCloud->m_iSize = 7;
- if(count == 3)
- pCloud->m_iSize = 8;
- if(count == 4)
- pCloud->m_iSize = 9;
- // Reinitialize our preview terrain data and update the window
- pCloud->m_bBuildLists = TRUE;
- m_pWndCloudPreview->RedrawWindow();
- }
- void C3dPageCloudColor::OnChangeTextureWrap()
- {
- // The property page settings have been modified, so
- // Enable (TRUE) or disable (FALSE) the Apply Now button
- SetModified(TRUE);
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- m_pWndCloudPreview->m_pCloudObject->m_iTextureWrap = m_iTextureWrap;
- // Reinitialize our preview terrain data and update the window
- m_pWndCloudPreview->m_pCloudObject->m_bBuildLists = TRUE;
- m_pWndCloudPreview->RedrawWindow();
- }
- void C3dPageCloudColor::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // The property page settings have been modified, so
- // Enable (TRUE) or disable (FALSE) the Apply Now button
- SetModified(TRUE);
- C3dObjectCloud* pCloud = m_pWndCloudPreview->m_pCloudObject;
- // Get the position of our slider controls.
- int posn = m_SliderOpacity.GetPos();
- pCloud->m_fOpacity = (float)(posn/100.f)*(posn/100.f);
- // Reinitialize our preview terrain data and update the window
- pCloud->m_bBuildLists = TRUE;
- m_pWndCloudPreview->RedrawWindow();
- CPropertyPage::OnHScroll(nSBCode, nPos, pScrollBar);
- }
- void C3dPageCloudColor::OnOK()
- {
- CPropertyPage::OnOK();
- }
- BOOL C3dPageCloudColor::OnApply()
- {
- // The property page settings have been modified, so
- // Enable (TRUE) or disable (FALSE) the Apply Now button
- SetModified(FALSE);
- // 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
- C3dObjectCloud::CopyParameters(m_pWndCloudPreview->m_pCloudObject, m_pObject);
- // Force the object to rebuild its' display list
- m_pObject->m_bBuildLists = TRUE;
- return CPropertyPage::OnApply();
- }