MainFrm.cpp
上传用户:cding2008
上传日期:2007-01-03
资源大小:1812k
文件大小:32k
- /////////////////////////////////////////////////////////////////////////////
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- // ModelMagic 3D and 'glOOP' (OpenGL Object Oriented Programming library)
- // Copyright (c) Craig Fahrnbach 1997, 1999
- //
- // 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.
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "ModelMagic3D.h"
- #include "SplashDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_WM_DESTROY()
- ON_COMMAND(ID_TOOLS_TREE_VIEW, OnToolsTreeCtrl)
- ON_COMMAND(ID_TOOLS_PALETTE, OnToolsPalette)
- ON_UPDATE_COMMAND_UI(ID_TOOLS_TREE_VIEW, OnUpdateToolsTreeCtrl)
- ON_UPDATE_COMMAND_UI(ID_TOOLS_PALETTE, OnUpdateToolsPalette)
- ON_WM_PALETTECHANGED()
- ON_WM_QUERYNEWPALETTE()
- ON_WM_KEYDOWN()
- ON_COMMAND(ID_WINDOW_NEW, OnWindowNew)
- ON_COMMAND(ID_VIEW_MULTIVIEW, OnViewMultiview)
- ON_UPDATE_COMMAND_UI(ID_VIEW_MULTIVIEW, OnUpdateViewMultiview)
- ON_COMMAND(ID_MATERIAL_EDIT, OnMaterialEdit)
- ON_UPDATE_COMMAND_UI(IDW_TOOLS_COMMAND_BAR, OnUpdateToolsCommandBar)
- ON_COMMAND(IDW_TOOLS_COMMAND_BAR, OnToolsCommandBar)
- ON_COMMAND(ID_COLORS_EDITCOLORS, OnColorsEdit)
- ON_COMMAND(ID_HELP_OPENGL_DIAGNOSTICS, OnHelpOpenGLDiagnostics)
- ON_COMMAND(IDW_TOOLS_KEYFRAME_BAR, OnToolsKeyframeBar)
- ON_UPDATE_COMMAND_UI(IDW_TOOLS_KEYFRAME_BAR, OnUpdateToolsKeyframeBar)
- ON_COMMAND(ID_KEYFRAME_DECREASE, OnKeyframeDecrease)
- ON_EN_UPDATE(ID_KEYFRAME_TIME, OnUpdateTime)
- ON_COMMAND(ID_KEYFRAME_INCREASE, OnKeyframeIncrease)
- ON_UPDATE_COMMAND_UI(ID_KEYFRAME_DECREASE, OnUpdateKeyframeDecrease)
- ON_COMMAND(ID_TOOLS_COORDINATES, OnToolsCoordinates)
- ON_UPDATE_COMMAND_UI(ID_TOOLS_COORDINATES, OnUpdateToolsCoordinates)
- ON_COMMAND(IDW_TOOLS_SELECT_BAR, OnToolsSelectBar)
- ON_UPDATE_COMMAND_UI(IDW_TOOLS_SELECT_BAR, OnUpdateToolsSelectBar)
- ON_COMMAND(IDW_TOOLS_2DSHAPE_BAR, OnTools2dshapeBar)
- ON_UPDATE_COMMAND_UI(IDW_TOOLS_2DSHAPE_BAR, OnUpdateTools2dshapeBar)
- ON_COMMAND(IDW_TOOLS_3DSHAPE_BAR, OnTools3dshapeBar)
- ON_UPDATE_COMMAND_UI(IDW_TOOLS_3DSHAPE_BAR, OnUpdateTools3dshapeBar)
- ON_COMMAND(IDW_TOOLS_SCENE_BAR, OnToolsSceneBar)
- ON_UPDATE_COMMAND_UI(IDW_TOOLS_SCENE_BAR, OnUpdateToolsSceneBar)
- //}}AFX_MSG_MAP
- // USER defined messages
- ON_MESSAGE( WM_REFRESH_DLG_BAR, OnRefreshDlgBar)
- // Global help commands
- ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
- ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
- ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
- ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame ToolBar Button Definitions
- static UINT BASED_CODE SceneButtons[] =
- {
- // same order as in the bitmap 'SceneBar.bmp'
- ID_OBJECT_NEW_LIGHT,
- ID_OBJECT_NEW_TERRAIN,
- ID_OBJECT_NEW_CLOUD,
- };
- static UINT BASED_CODE Shape2dButtons[] =
- {
- // same order as in the bitmap '2dShapeBar.bmp'
- ID_OBJECT_NEW_DISK,
- ID_OBJECT_NEW_TRIANGLE,
- ID_OBJECT_NEW_PLANE,
- ID_OBJECT_NEW_GRID,
- };
- static UINT BASED_CODE Shape3dButtons[] =
- {
- // same order as in the bitmap '3dShapeBar.bmp'
- ID_OBJECT_NEW_CONE,
- ID_OBJECT_NEW_CYLINDER,
- ID_OBJECT_NEW_CSG,
- ID_OBJECT_NEW_CUBE,
- ID_OBJECT_NEW_LATHE,
- ID_OBJECT_NEW_HSPLINE,
- ID_OBJECT_NEW_NURB,
- ID_OBJECT_NEW_SPHERE,
- ID_OBJECT_NEW_TORUS,
- ID_OBJECT_NEW_TTF,
- };
- static UINT BASED_CODE SelectButtons[] =
- {
- // same order as in the bitmap 'selectbar.bmp'
- ID_SELECT_CAMERA,
- ID_SELECT_PARENT,
- ID_SELECT_CHILD,
- ID_SELECT_OBJECT_AXIS,
- ID_SELECT_OBJECT_TEXTURE,
- ID_SELECT_OBJECT_TEXTURE_AXIS,
- ID_SELECT_OBJECT_EDGES,
- ID_SELECT_OBJECT_POINTS,
- ID_SELECT_POINTS,
- };
- static UINT BASED_CODE CommandButtons[] =
- {
- // same order as in the bitmap 'Commandb.bmp'
- ID_COMMAND_SELECT,
- ID_COMMAND_MOVE,
- ID_COMMAND_ROTATE,
- ID_COMMAND_SCALE,
- ID_COMMAND_PAINT,
- ID_COMMAND_POINTS_CREATE,
- ID_COORDINATE_X_AXIS,
- ID_COORDINATE_Y_AXIS,
- ID_COORDINATE_Z_AXIS,
- };
- static UINT BASED_CODE KeyFrameButtons[] =
- {
- // same order as in the bitmap 'Keyframe.bmp'
- ID_KEYFRAME_RECORD,
- ID_KEYFRAME_UNRECORD,
- ID_KEYFRAME_PLAY,
- ID_KEYFRAME_FIRST,
- ID_KEYFRAME_PREVIOUS,
- ID_KEYFRAME_NEXT,
- ID_KEYFRAME_LAST,
- ID_KEYFRAME_DECREASE,
- ID_SEPARATOR,
- ID_SEPARATOR, // marker for our CEdit Window
- ID_SEPARATOR,
- ID_KEYFRAME_INCREASE,
- };
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- // Buttons must be big enough to hold image
- // + 7 pixels on x
- // + 6 pixels on y
- SIZE sizeButton = {26, 25};
- SIZE sizeImage = {19, 19};
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- m_bWndInitialized = FALSE;
- m_bToolTips = TRUE;
- m_pColorDlg = NULL;
- m_pMaterialDlg = NULL;
- m_pActiveView = NULL;
- }
- CMainFrame::~CMainFrame()
- {
- if(m_pColorDlg)
- delete m_pColorDlg;
- if(m_pMaterialDlg)
- delete m_pMaterialDlg;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame methods
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- // cs.style |= (CS_OWNDC);
- return CMDIFrameWnd::PreCreateWindow(cs);
- }
- BOOL CMainFrame::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
- {
- // TODO: Add your specialized code here and/or call the base class
- LPCTSTR lpszName = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,
- ::LoadCursor(NULL, IDC_ARROW));
-
- return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- // Get the last setting of the window position from
- // the ini file and restore
- WINDOWPLACEMENT wp;
- GetWindowPlacement(&wp);
- if(!ReadWindowPlacement(&wp, "Settings", "MainFramePos"))
- {
- RECT rc;
- // The ini file is corrupt or does not exist, so get the size of the
- // CMDIFrameWnd client window and position it's window
- GetClientRect(&rc);
- wp.rcNormalPosition.top = rc.top;
- wp.rcNormalPosition.bottom = rc.bottom;
- wp.rcNormalPosition.left = rc.left;
- wp.rcNormalPosition.right = rc.right;
- }
-
- // Now restore (or set) our window position
- m_bWndInitialized = TRUE;
- SetWindowPlacement(&wp);
- // Create our floating toolbars and dialog bars..
- if (!m_wndToolBar.Create(this) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create the mainframe toolbarn");
- return -1; // fail to create
- }
- // TODO: Remove this if you don't want tool tips or a resizeable toolbar
- m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
- CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
-
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create the status barn");
- return -1; // fail to create
- }
- if (!m_wndTreeDlgBar.Create(this, ID_TOOLS_TREE_VIEW,
- CBRS_RIGHT | CBRS_SIZE_DYNAMIC,
- ID_TOOLS_TREE_VIEW)) {
- TRACE0("Failed to create the Tree dialogbarn");
- return -1; // fail to create
- }
- if (!m_wndColorDlgBar.Create(this, IDD_DIALOG_COLOR,
- CBRS_RIGHT | CBRS_SIZE_FIXED,
- IDD_DIALOG_COLOR, TRUE)) {
- TRACE0("Failed to create the Color dialogbarn");
- return -1; // fail to create
- }
- if (!m_wndCoordDlgBar.Create(this, IDD_DIALOG_COORDINATE,
- CBRS_RIGHT | CBRS_SIZE_FIXED,
- IDD_DIALOG_COORDINATE, TRUE)) {
- TRACE0("Failed to create the Coordinate dialogbarn");
- return -1; // fail to create
- }
- if (!m_wndSceneBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_DYNAMIC |
- CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_TOOLS_SCENE_BAR) ||
- !m_wndSceneBar.LoadBitmap(IDB_SCENEBAR) ||
- !m_wndSceneBar.SetButtons(SceneButtons, sizeof(SceneButtons)/sizeof(UINT)))
- {
- TRACE0("Failed to create the light toolbar.n");
- return -1; // fail to create
- }
- if (!m_wnd2dShapeBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_DYNAMIC |
- CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_TOOLS_2DSHAPE_BAR) ||
- !m_wnd2dShapeBar.LoadBitmap(IDB_2DSHAPEBAR) ||
- !m_wnd2dShapeBar.SetButtons(Shape2dButtons, sizeof(Shape2dButtons)/sizeof(UINT)))
- {
- TRACE0("Failed to create the shape toolbar.n");
- return -1; // fail to create
- }
- if (!m_wnd3dShapeBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_DYNAMIC |
- CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_TOOLS_3DSHAPE_BAR) ||
- !m_wnd3dShapeBar.LoadBitmap(IDB_3DSHAPEBAR) ||
- !m_wnd3dShapeBar.SetButtons(Shape3dButtons, sizeof(Shape3dButtons)/sizeof(UINT)))
- {
- TRACE0("Failed to create the shape toolbar.n");
- return -1; // fail to create
- }
- if (!m_wndSelectBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_FIXED |
- CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_TOOLS_SELECT_BAR) ||
- !m_wndSelectBar.LoadBitmap(IDB_SELECTBAR) ||
- !m_wndSelectBar.SetButtons(SelectButtons, sizeof(SelectButtons)/sizeof(UINT)))
- {
- TRACE0("Failed to create the Select toolbar.n");
- return -1; // fail to create
- }
- if (!m_wndCommandBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_FIXED |
- CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_TOOLS_COMMAND_BAR) ||
- !m_wndCommandBar.LoadBitmap(IDB_COMMANDBAR) ||
- !m_wndCommandBar.SetButtons(CommandButtons, sizeof(CommandButtons)/sizeof(UINT)))
- {
- TRACE0("Failed to create teh Command toolbar.n");
- return -1; // fail to create
- }
- if (!m_wndKeyFrameBar.Create(this, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | CBRS_SIZE_FIXED |
- CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_TOOLS_KEYFRAME_BAR) ||
- !m_wndKeyFrameBar.LoadBitmap(IDB_KEYFRAMEBAR) ||
- !m_wndKeyFrameBar.SetButtons(KeyFrameButtons, sizeof(KeyFrameButtons)/sizeof(UINT)))
- {
- TRACE0("Failed to create the KeyFrame toolbar.n");
- return -1; // fail to create
- }
- // Now that our Toolbars have been created, resize our
- // Toolbar Buttons and Images
- m_wndToolBar.SetSizes(sizeButton, sizeImage);
- m_wndSceneBar.SetSizes(sizeButton, sizeImage);
- m_wnd2dShapeBar.SetSizes(sizeButton, sizeImage);
- m_wnd3dShapeBar.SetSizes(sizeButton, sizeImage);
- m_wndKeyFrameBar.SetSizes(sizeButton, sizeImage);
- m_wndSelectBar.SetSizes(sizeButton, sizeImage);
- m_wndCommandBar.SetSizes(sizeButton, sizeImage);
-
- // Create the CEdit window for the KeyFrameBar
- // Design guide advises 12 pixel gap between combos and buttons
- m_wndKeyFrameBar.SetButtonInfo(8, ID_SEPARATOR, TBBS_SEPARATOR, 2);
- m_wndKeyFrameBar.SetButtonInfo(9, ID_KEYFRAME_TIME, TBBS_BUTTON, 20);
- m_wndKeyFrameBar.SetButtonInfo(10, ID_SEPARATOR, TBBS_SEPARATOR, 20);
- CRect rect;
- m_wndKeyFrameBar.GetItemRect(9, &rect);
- // rect.top = 3;
- rect.right = rect.right+18;
- if (!m_wndKeyFrameBar.m_EditBox.Create(
- WS_CHILD | WS_VISIBLE | // dwStyle
- WS_BORDER |
- ES_LEFT | ES_NOHIDESEL,
- rect, // rect
- &m_wndKeyFrameBar, // CWnd* pParentWnd
- ID_KEYFRAME_TIME)) // UINT nID
- {
- TRACE0("Failed to create Edit boxn");
- return FALSE;
- }
- char buf[10];
- sprintf(buf, "%3.1f", m_wndKeyFrameBar.m_fTime);
- m_wndKeyFrameBar.m_EditBox.ReplaceSel(buf, FALSE);
- // TODO: Delete these seven lines if you don't want the toolbars to
- // be dockable
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- m_wndTreeDlgBar.SetWindowText(_T("Tree View"));
- m_wndTreeDlgBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
- m_wndColorDlgBar.SetWindowText(_T("Color Palette"));
- m_wndColorDlgBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
- m_wndCoordDlgBar.SetWindowText(_T("Coordinate View"));
- m_wndCoordDlgBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
- m_wndSceneBar.SetWindowText(_T("Scene Objects"));
- m_wndSceneBar.EnableDocking(CBRS_ALIGN_ANY);
- m_wnd2dShapeBar.SetWindowText(_T("2d Shapes"));
- m_wnd2dShapeBar.EnableDocking(CBRS_ALIGN_ANY);
- m_wnd3dShapeBar.SetWindowText(_T("3d Shapes"));
- m_wnd3dShapeBar.EnableDocking(CBRS_ALIGN_ANY);
- m_wndSelectBar.SetWindowText(_T("Selection"));
- m_wndSelectBar.EnableDocking(CBRS_ALIGN_ANY);
- m_wndCommandBar.SetWindowText(_T("Commands"));
- m_wndCommandBar.EnableDocking(CBRS_ALIGN_ANY);
- m_wndKeyFrameBar.SetWindowText(_T("KeyFrame Animation Control"));
- m_wndKeyFrameBar.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar, AFX_IDW_DOCKBAR_TOP);
- DockControlBar(&m_wndTreeDlgBar, AFX_IDW_DOCKBAR_RIGHT);
- DockControlBar(&m_wndColorDlgBar, AFX_IDW_DOCKBAR_RIGHT);
- DockControlBar(&m_wndCoordDlgBar, AFX_IDW_DOCKBAR_RIGHT);
- DockControlBar(&m_wndSelectBar,AFX_IDW_DOCKBAR_LEFT);
- DockControlBar(&m_wndCommandBar,AFX_IDW_DOCKBAR_LEFT);
- DockControlBar(&m_wndSceneBar,AFX_IDW_DOCKBAR_BOTTOM);
- DockControlBar(&m_wnd2dShapeBar,AFX_IDW_DOCKBAR_BOTTOM);
- DockControlBar(&m_wnd3dShapeBar,AFX_IDW_DOCKBAR_BOTTOM);
- DockControlBar(&m_wndKeyFrameBar,AFX_IDW_DOCKBAR_BOTTOM);
- // LoadBarState loads everything but the number of Columns in the
- // Scene Objects, 2dShapes, 3dShapes, and CommandBar, so we need to do that
- // ourseleves.
- m_wndSceneBar.SetColumns(AfxGetApp()->GetProfileInt(_T("General"),_T("SceneBar Columns"), 1));
- m_wnd2dShapeBar.SetColumns(AfxGetApp()->GetProfileInt(_T("General"),_T("2dShapeBar Columns"), 1));
- m_wnd3dShapeBar.SetColumns(AfxGetApp()->GetProfileInt(_T("General"),_T("3dShapeBar Columns"), 1));
- m_wndSelectBar.SetColumns(AfxGetApp()->GetProfileInt(_T("General"),_T("SelectBar Columns"), 2));
- m_wndCommandBar.SetColumns(AfxGetApp()->GetProfileInt(_T("General"),_T("CommandBar Columns"), 2));
- m_wndKeyFrameBar.SetColumns(AfxGetApp()->GetProfileInt(_T("General"),_T("KeyFrameBar Columns"), 12));
- LoadBarState(_T("General"));
- // Do we show the splash screen or the splash dialog?
- CMyglApp* pApp = (CMyglApp*)AfxGetApp();
- ASSERT(pApp);
- if(pApp->m_bRegistered)
- // CG: The following line was added by the Splash Screen component.
- CSplashWnd::ShowSplashScreen(this);
- else
- CSplashDlg::ShowSplashDlg(this);
- return 0;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CMDIFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CMDIFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- /*
- BOOL CMainFrame::SetWindowPixelFormat(HDC hDC)
- {
- int nPixelFormat; // Pixel format index
- static PIXELFORMATDESCRIPTOR pfd = {
- sizeof(PIXELFORMATDESCRIPTOR), // Size of this structure
- 1, // Version of this structure
- PFD_DRAW_TO_WINDOW | // Draw to Window (not to bitmap)
- PFD_SUPPORT_OPENGL | // Support OpenGL calls in window
- PFD_DOUBLEBUFFER, // Double buffered mode
- PFD_TYPE_RGBA, // RGBA Color mode
- 24, // Want 24bit color
- 0,0,0,0,0,0, // Not used to select mode
- 0,0, // Not used to select mode
- 0,0,0,0,0, // Not used to select mode
- 16, // Size of depth buffer
- 16, // Size of the Stencel buffer
- 0, // Not used to select mode
- PFD_MAIN_PLANE, // Draw in main plane
- 0, // Not used to select mode
- 0,0,0 }; // Not used to select mode
- // Choose a pixel format that best matches that described in pfd
- nPixelFormat = ChoosePixelFormat(hDC, &pfd);
- if (nPixelFormat==0) { // Let's choose a default index.
- nPixelFormat = 1;
- if (DescribePixelFormat(hDC,
- nPixelFormat,
- sizeof(PIXELFORMATDESCRIPTOR),
- &pfd)==0)
- {
- return FALSE;
- }
- }
- DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
- if(pfd.dwFlags & PFD_GENERIC_FORMAT)
- int temp = 0;
-
- // Set the pixel format for the device context
- if(!SetPixelFormat(hDC, nPixelFormat, &pfd)){
- return FALSE;
- }
- return TRUE;
- }
- */
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- void CMainFrame::OnDestroy()
- {
- // Save our toolbars state information
- SaveBarState(_T("General"));
- // Save the state of our CMainFrame window
- WINDOWPLACEMENT wp;
- wp.length = sizeof wp;
- if (GetWindowPlacement(&wp))
- {
- wp.flags = 0;
- if (IsZoomed()) {
- wp.flags |= WPF_RESTORETOMAXIMIZED;
- // wp.showCmd |= SW_SHOWMAXIMIZED;
- }
- // and write it to the .INI file
- WriteWindowPlacement(&wp, "Settings", "MainFramePos");
- }
- CMDIFrameWnd::OnDestroy();
- }
- void CMainFrame::OnToolsTreeCtrl()
- {
- // Display or hide the Color Dialog Bar..
- if(m_wndTreeDlgBar)
- {
- if(m_wndTreeDlgBar.IsWindowVisible())
- ShowControlBar(&m_wndTreeDlgBar, FALSE, FALSE);
- else
- ShowControlBar(&m_wndTreeDlgBar, TRUE, FALSE);
- }
- }
- void CMainFrame::OnUpdateToolsTreeCtrl(CCmdUI* pCmdUI)
- {
- // Update the check state of the Tree Dialog Bar..
- if(m_wndTreeDlgBar) {
- if(m_wndTreeDlgBar.IsWindowVisible())
- pCmdUI->SetCheck(TRUE);
- else
- pCmdUI->SetCheck(FALSE);
- }
- else
- pCmdUI->SetCheck(FALSE);
- }
- long CMainFrame::OnRefreshDlgBar(WPARAM wParam, LPARAM lParam)
- {
- // User has switched views or is forcing an update of our dialog bars
- // as indicated in the wParam (wParam = RDB_FORCE_REFRESH)
- static C3dWorld* pCurrentWorld = NULL;
-
- BOOL bMaximized;
- CMDIChildWnd* pMDIChild = MDIGetActive(&bMaximized);
- if(pMDIChild)
- {
- // Save the pointer to our active CMyglView class
- m_pActiveView = (CMyglView*)pMDIChild->GetActiveView();
- ASSERT_VALID(m_pActiveView);
- CMyglDoc* pDoc = (CMyglDoc*)pMDIChild->GetActiveDocument();
- ASSERT_VALID(pDoc);
- // Save the pointer to our active C3dWorld
- m_pActiveWorld = pDoc->m_pWorld;
- }
- else
- {
- m_pActiveView = NULL;
- m_pActiveWorld = NULL;
- }
- // Update the tree control view only if different C3dWorld
- if(pCurrentWorld != m_pActiveWorld || wParam == RDB_FORCE_REFRESH)
- {
- pCurrentWorld = m_pActiveWorld;
- if(m_wndTreeDlgBar.IsWindowVisible())
- m_wndTreeDlgBar.DisplayTree(m_pActiveWorld);
- }
- return 0L;
- }
- void CMainFrame::OnToolsKeyframeBar()
- {
- // Display or hide the KeyFrame Animation Toolbar
- if(m_wndKeyFrameBar)
- {
- if(m_wndKeyFrameBar.IsWindowVisible())
- ShowControlBar(&m_wndKeyFrameBar, FALSE, FALSE);
- else
- ShowControlBar(&m_wndKeyFrameBar, TRUE, FALSE);
- }
- }
- void CMainFrame::OnUpdateToolsKeyframeBar(CCmdUI* pCmdUI)
- {
- // Update the check state of the KeyFrame Animation Toolbar..
- if(m_wndKeyFrameBar) {
- if(m_wndKeyFrameBar.IsWindowVisible())
- pCmdUI->SetCheck(TRUE);
- else
- pCmdUI->SetCheck(FALSE);
- }
- else
- pCmdUI->SetCheck(FALSE);
- }
- void CMainFrame::OnToolsSelectBar()
- {
- // Display or hide the Selection Toolbar
- if(m_wndSelectBar)
- {
- if(m_wndSelectBar.IsWindowVisible())
- ShowControlBar(&m_wndSelectBar, FALSE, FALSE);
- else
- ShowControlBar(&m_wndSelectBar, TRUE, FALSE);
- }
- }
- void CMainFrame::OnUpdateToolsSelectBar(CCmdUI* pCmdUI)
- {
- // Update the check state of the Select ToolBar..
- if(m_wndSelectBar) {
- if(m_wndSelectBar.IsWindowVisible())
- pCmdUI->SetCheck(TRUE);
- else
- pCmdUI->SetCheck(FALSE);
- }
- else
- pCmdUI->SetCheck(FALSE);
- }
- void CMainFrame::OnToolsCommandBar()
- {
- // Display or hide the Command Toolbar
- if(m_wndCommandBar)
- {
- if(m_wndCommandBar.IsWindowVisible())
- ShowControlBar(&m_wndCommandBar, FALSE, FALSE);
- else
- ShowControlBar(&m_wndCommandBar, TRUE, FALSE);
- }
- }
- void CMainFrame::OnUpdateToolsCommandBar(CCmdUI* pCmdUI)
- {
- // Update the check state of the Command ToolBar..
- if(m_wndCommandBar) {
- if(m_wndCommandBar.IsWindowVisible())
- pCmdUI->SetCheck(TRUE);
- else
- pCmdUI->SetCheck(FALSE);
- }
- else
- pCmdUI->SetCheck(FALSE);
- }
- void CMainFrame::OnTools2dshapeBar()
- {
- // Display or hide the Shape Dialog Toolbar
- if(m_wnd2dShapeBar)
- {
- if(m_wnd2dShapeBar.IsWindowVisible())
- ShowControlBar(&m_wnd2dShapeBar, FALSE, FALSE);
- else
- ShowControlBar(&m_wnd2dShapeBar, TRUE, FALSE);
- }
- }
- void CMainFrame::OnUpdateTools2dshapeBar(CCmdUI* pCmdUI)
- {
- // Update the check state of the Shape Dialog Toolbar..
- if(m_wnd2dShapeBar) {
- if(m_wnd2dShapeBar.IsWindowVisible())
- pCmdUI->SetCheck(TRUE);
- else
- pCmdUI->SetCheck(FALSE);
- }
- else
- pCmdUI->SetCheck(FALSE);
- }
- void CMainFrame::OnTools3dshapeBar()
- {
- // Display or hide the Shape Dialog Toolbar
- if(m_wnd3dShapeBar)
- {
- if(m_wnd3dShapeBar.IsWindowVisible())
- ShowControlBar(&m_wnd3dShapeBar, FALSE, FALSE);
- else
- ShowControlBar(&m_wnd3dShapeBar, TRUE, FALSE);
- }
- }
- void CMainFrame::OnUpdateTools3dshapeBar(CCmdUI* pCmdUI)
- {
- // Update the check state of the Shape Dialog Toolbar..
- if(m_wnd3dShapeBar) {
- if(m_wnd3dShapeBar.IsWindowVisible())
- pCmdUI->SetCheck(TRUE);
- else
- pCmdUI->SetCheck(FALSE);
- }
- else
- pCmdUI->SetCheck(FALSE);
- }
- void CMainFrame::OnToolsSceneBar()
- {
- // Display or hide the Light Dialog Toolbar
- if(m_wndSceneBar)
- {
- if(m_wndSceneBar.IsWindowVisible())
- ShowControlBar(&m_wndSceneBar, FALSE, FALSE);
- else
- ShowControlBar(&m_wndSceneBar, TRUE, FALSE);
- }
- }
- void CMainFrame::OnUpdateToolsSceneBar(CCmdUI* pCmdUI)
- {
- // Update the check state of the Light Dialog ToolBar..
- if(m_wndSceneBar) {
- if(m_wndSceneBar.IsWindowVisible())
- pCmdUI->SetCheck(TRUE);
- else
- pCmdUI->SetCheck(FALSE);
- }
- else
- pCmdUI->SetCheck(FALSE);
- }
- void CMainFrame::OnToolsPalette()
- {
- // Display or hide the Color Dialog Toolbar..
- if(m_wndColorDlgBar)
- {
- if(m_wndColorDlgBar.IsWindowVisible())
- ShowControlBar(&m_wndColorDlgBar, FALSE, FALSE);
- else
- ShowControlBar(&m_wndColorDlgBar, TRUE, FALSE);
- }
- }
- void CMainFrame::OnUpdateToolsPalette(CCmdUI* pCmdUI)
- {
- // Update the check state of the Palette Dialog Toolbar..
- if(m_wndColorDlgBar) {
- if(m_wndColorDlgBar.IsWindowVisible())
- pCmdUI->SetCheck(TRUE);
- else
- pCmdUI->SetCheck(FALSE);
- }
- else
- pCmdUI->SetCheck(FALSE);
- }
- void CMainFrame::OnToolsCoordinates()
- {
- // Display or hide the Coordinates Dialog Toolbar..
- if(m_wndCoordDlgBar)
- {
- if(m_wndCoordDlgBar.IsWindowVisible())
- ShowControlBar(&m_wndCoordDlgBar, FALSE, FALSE);
- else
- ShowControlBar(&m_wndCoordDlgBar, TRUE, FALSE);
- }
- }
- void CMainFrame::OnUpdateToolsCoordinates(CCmdUI* pCmdUI)
- {
- // Update the check state of the Coordinates Dialog Toolbar..
- if(m_wndCoordDlgBar)
- {
- if(m_wndCoordDlgBar.IsWindowVisible())
- pCmdUI->SetCheck(TRUE);
- else
- pCmdUI->SetCheck(FALSE);
- }
- else
- pCmdUI->SetCheck(FALSE);
- }
- void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd)
- {
- // CMDIFrameWnd::OnPaletteChanged(pFocusWnd);
-
- // Route message to CMDIChildWnd derived class, which will
- // inturn route the message to its' CView derived class.
- CMDIChildWnd* pChildWnd = MDIGetActive();
- if (pChildWnd) {
- // OnPaletteChanged is not public, so send a message.
- pChildWnd->SendMessage(WM_PALETTECHANGED,
- (WPARAM)(pFocusWnd->GetSafeHwnd()),
- (LPARAM)0);
- }
- // Route message to our Color Palette Dialog Bar
- if (m_wndColorDlgBar) {
- // OnPaletteChanged is not public, so send a message.
- m_wndColorDlgBar.SendMessage(WM_PALETTECHANGED,
- (WPARAM)(pFocusWnd->GetSafeHwnd()),
- (LPARAM)0);
- }
- }
- BOOL CMainFrame::OnQueryNewPalette()
- {
- // Route message to CMDIChildWnd derived class, which will
- // inturn route the message to its' CView derived class.
- CMDIChildWnd* pChildWnd = MDIGetActive();
- if (pChildWnd) {
- // OnPaletteChanged is not public, so send a message.
- pChildWnd->SendMessage(WM_QUERYNEWPALETTE,
- (WPARAM)0,
- (LPARAM)0);
- }
-
- // Route message to our Color Palette Dialog Bar
- if (m_wndColorDlgBar) {
- // OnPaletteChanged is not public, so send a message.
- m_wndColorDlgBar.SendMessage(WM_QUERYNEWPALETTE,
- (WPARAM)0,
- (LPARAM)0);
- }
- return CMDIFrameWnd::OnQueryNewPalette();
- }
- void CMainFrame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // Route message to CDialogBar derived CWnd class
- if (m_wndColorDlgBar) {
- // OnKeyDown is not public, so send a message.
- m_wndColorDlgBar.SendMessage(WM_KEYDOWN,
- (WPARAM)nChar,
- (LPARAM)nFlags<<16 | nRepCnt);
- }
-
- CMDIFrameWnd::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- void CMainFrame::OnWindowNew()
- {
- CMDIChildWnd* pMDIChildWnd = MDIGetActive();
- CDocument* pDocument;
- if(pMDIChildWnd == NULL || (pDocument = pMDIChildWnd->GetActiveDocument()) == NULL) {
- TRACE0("Warning: No active document for WindowNew commandn");
- AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
- return; // command failed
- }
- // otherwise, we have a new frame!
- CDocTemplate* pTemplate = ((CMyglApp*) AfxGetApp())->m_pDocTemplate;
- ASSERT_VALID(pTemplate);
- CFrameWnd* pFrame = pTemplate->CreateNewFrame(pDocument, pMDIChildWnd);
- if(pFrame == NULL) {
- TRACE0("Warning: failed to create new framen");
- AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
- return; // command failed
- }
- pTemplate->InitialUpdateFrame(pFrame, pDocument);
- }
- void CMainFrame::OnViewMultiview()
- {
- CMDIChildWnd* pMDIChildWnd = MDIGetActive();
- CDocument* pDocument;
- if(pMDIChildWnd == NULL || (pDocument = pMDIChildWnd->GetActiveDocument()) == NULL) {
- TRACE0("Warning: No active document for WindowNew commandn");
- AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
- return; // command failed
- }
- // Get a pointer to our Iso view CMyglView class
- CMyglView* pIsoView = (CMyglView*)pMDIChildWnd->GetActiveView();
- ASSERT_VALID(pIsoView);
- pIsoView->ViewIso();
- // otherwise, we have a new frame!
- for(int i=0; i<3; i++) {
- CDocTemplate* pTemplate = ((CMyglApp*) AfxGetApp())->m_pDocTemplate;
- ASSERT_VALID(pTemplate);
- CFrameWnd* pFrame = pTemplate->CreateNewFrame(pDocument, pMDIChildWnd);
- if(pFrame == NULL) {
- TRACE0("Warning: failed to create new framen");
- AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
- return; // command failed
- }
- pTemplate->InitialUpdateFrame(pFrame, pDocument);
- // Get a pointer to our newly created CMyglView class
- CMyglView* pView = (CMyglView*)pFrame->GetActiveView();
- ASSERT_VALID(pView);
- // Set the new CMyglView camera's depth equal to the original (iso)
- // CMyglView camera's depth. (same depth perspective)
- pView->m_Camera.m_fOrigin[Z] = pIsoView->m_Camera.m_fOrigin[Z];
- if(i == 0)
- pView->ViewSide();
- if(i == 1)
- pView->ViewFront();
- if(i == 2)
- pView->ViewTop();
- // Allow the 'child' views to share display lists..
- wglShareLists(pIsoView->m_hRC, // OpenGL rendering context with which to share display lists
- pView->m_hRC); // OpenGL rendering context to share display lists
- }
- MDITile(MDITILE_VERTICAL);
- }
- void CMainFrame::OnUpdateViewMultiview(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- }
- void CMainFrame::OnMaterialEdit()
- {
- if(!m_pActiveWorld) {
- AfxMessageBox("Please select a document view first, then edit the world's materials.", MB_OK);
- return;
- }
- // Display the Material modal dialog box
- // CEditMaterialDlg materialDlg(&m_pActiveWorld->m_MaterialList, &m_pActiveWorld->m_ColorList, this);
- // materialDlg.DoModal();
- // Modeless Dialog Creation
- if(!m_pMaterialDlg) {
- // Create a modeless dialog
- m_pMaterialDlg = new CEditMaterialDlg(&m_pActiveWorld->m_MaterialList, &m_pActiveWorld->m_ColorList, this);
- if (!m_pMaterialDlg->Create(IDD_EDIT_MATERIAL_DIALOG,
- NULL)) {
- delete m_pMaterialDlg;
- m_pMaterialDlg = NULL;
- return;
- }
- // Center and show the window..
- m_pMaterialDlg->CenterWindow(NULL);
- m_pMaterialDlg->ShowWindow(SW_SHOW);
- }
- else {
- // Reset the dialog so the list diaplay points to
- // the correct material list
- m_pMaterialDlg->ResetDlg(&m_pActiveWorld->m_MaterialList, &m_pActiveWorld->m_ColorList);
- if(m_pMaterialDlg->IsWindowVisible())
- m_pMaterialDlg->ShowWindow(SW_HIDE);
- else
- m_pMaterialDlg->ShowWindow(SW_SHOW);
- }
- // Force a repaint of the documents views
- if(m_pActiveView) {
- CDocument* pDoc = m_pActiveView->GetDocument();
- if(pDoc) {
- // Set the document as modified...
- pDoc->SetModifiedFlag(TRUE);
- // Force a repaint of the window
- pDoc->UpdateAllViews(NULL);
- }
- }
- }
- void CMainFrame::OnColorsEdit()
- {
- if(!m_pActiveWorld) {
- AfxMessageBox("Please select a document view first, then edit the world's materials.", MB_OK);
- return;
- }
- // Display the Material modal dialog box
- // CEditMaterialDlg materialDlg(pFirstView);
- // materialDlg.DoModal();
- if(!m_pColorDlg) {
- // Create a modeless dialog
- m_pColorDlg = new CEditColorsDlg(&m_pActiveWorld->m_ColorList, this);
- if (!m_pColorDlg->Create(IDD_EDIT_COLORS_DIALOG,
- NULL)) {
- delete m_pColorDlg;
- m_pColorDlg = NULL;
- return;
- }
- // Center and show the window..
- m_pColorDlg->CenterWindow(NULL);
- m_pColorDlg->ShowWindow(SW_SHOW);
- }
- else {
- // Reset the dialog so the list diaplay points to
- // the correct material list
- m_pColorDlg->ResetDlg(&m_pActiveWorld->m_ColorList);
- if(m_pColorDlg->IsWindowVisible())
- m_pColorDlg->ShowWindow(SW_HIDE);
- else
- m_pColorDlg->ShowWindow(SW_SHOW);
- }
- // Force a repaint of the documents views
- if(m_pActiveView) {
- CDocument* pDoc = m_pActiveView->GetDocument();
- if(pDoc) {
- // Set the document as modified...
- pDoc->SetModifiedFlag(TRUE);
- // Force a repaint of the window
- pDoc->UpdateAllViews(NULL);
- }
- }
- }
- void CMainFrame::OnHelpOpenGLDiagnostics()
- {
- CMyglView* pView = (CMyglView*)m_pActiveView;
- if(pView)
- {
- COpenGLDiagnostics dlgOpenGLDiag(pView->m_pDC->GetSafeHdc(), pView->m_hRC, this);
- // Display the About dialog box
- dlgOpenGLDiag.DoModal();
- }
- }
- void CMainFrame::OnKeyframeDecrease()
- {
- m_wndKeyFrameBar.m_fTime -= 1.0f;
- if(m_wndKeyFrameBar.m_fTime < 0.0f)
- m_wndKeyFrameBar.m_fTime = 0.0f;
- char buf[10];
- sprintf(buf, "%3.1f", m_wndKeyFrameBar.m_fTime);
- m_wndKeyFrameBar.m_EditBox.SetSel(0, -1, FALSE);
- m_wndKeyFrameBar.m_EditBox.Cut();
- m_wndKeyFrameBar.m_EditBox.ReplaceSel(buf, FALSE);
- // Get a pointer to our document and save the time index
- CMyglDoc* pDoc = (CMyglDoc*)m_pActiveView->GetDocument();
- ASSERT(pDoc);
- // pDoc->m_dTime = m_wndKeyFrameBar.m_fTime;
- // Force a repaint of the window
- // pDoc->UpdateAllViews(NULL);
- }
- void CMainFrame::OnUpdateKeyframeDecrease(CCmdUI* pCmdUI)
- {
- if(m_wndKeyFrameBar.m_fTime == 0.0f)
- pCmdUI->Enable(FALSE);
- else
- pCmdUI->Enable(TRUE);
- }
- void CMainFrame::OnUpdateTime()
- {
- char buf[10];
- int nChars = m_wndKeyFrameBar.m_EditBox.GetLine(0, &buf[0], 10);
- sscanf(&buf[0], "%f", &m_wndKeyFrameBar.m_fTime);
- }
- void CMainFrame::OnKeyframeIncrease()
- {
- UINT style = m_wndKeyFrameBar.GetButtonStyle(7);
- m_wndKeyFrameBar.SetButtonStyle(7, style|WS_VISIBLE);
- m_wndKeyFrameBar.m_fTime += 1.0f;
- char buf[10];
- sprintf(buf, "%3.1f", m_wndKeyFrameBar.m_fTime);
- m_wndKeyFrameBar.m_EditBox.SetSel(0, -1, FALSE);
- m_wndKeyFrameBar.m_EditBox.Cut();
- m_wndKeyFrameBar.m_EditBox.ReplaceSel(buf, FALSE);
- // Get a pointer to our document and save the time index
- CMyglDoc* pDoc = (CMyglDoc*)m_pActiveView->GetDocument();
- ASSERT(pDoc);
- // pDoc->m_dTime = m_wndKeyFrameBar.m_fTime;
- // Force a repaint of the window
- // pDoc->UpdateAllViews(NULL);
- }