Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages

D:/Programming/GUI Editor (Source)/GUIEditor.cpp

00001 // GUIEditApp.cpp : Defines the class behaviors for the application. 00002 // 00003 00004 #include "stdafx.h" 00005 #include "GUIEditor.h" 00006 00007 #include "MainFrm.h" 00008 #include "ChildFrm.h" 00009 #include "GUIEditorDoc.h" 00010 #include "GUIEditorView.h" 00011 #include <mmsystem.h> 00012 #include ".\guieditor.h" 00013 #pragma comment( lib, "winmm.lib" ) 00014 00015 #ifdef _DEBUG 00016 #define new DEBUG_NEW 00017 #undef THIS_FILE 00018 static char THIS_FILE[] = __FILE__; 00019 #endif 00020 00022 // CGUIEditorApp 00023 00024 BEGIN_MESSAGE_MAP(CGUIEditorApp, CWinApp) 00025 //{{AFX_MSG_MAP(CGUIEditorApp) 00026 ON_COMMAND(ID_APP_ABOUT, OnAppAbout) 00027 // NOTE - the ClassWizard will add and remove mapping macros here. 00028 // DO NOT EDIT what you see in these blocks of generated code! 00029 //}}AFX_MSG_MAP 00030 // Standard file based document commands 00031 // Standard print setup command 00032 ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup) 00033 ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) 00034 ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) 00035 ON_COMMAND(ID_FILE_NEW, OnFileNew) 00036 ON_COMMAND(ID_FILE_SAVE, OnFileSave) 00037 ON_COMMAND(ID_MENU_FILE_SAVE, OnMenuFileSave) 00038 END_MESSAGE_MAP() 00039 00041 // CGUIEditorApp construction 00042 00043 CGUIEditorApp::CGUIEditorApp() 00044 { 00045 m_uiGUIUID = 0; 00046 m_lCurTime = 0; 00047 m_dwTimeCount = 8; 00048 m_lPerfCounter = 1; 00049 m_bPerFlag = FALSE; 00050 m_lNextTime = 0; 00051 m_lLastTime = 0; 00052 m_dTimeElapsed = 0.0; 00053 m_dTimeScale = 0.0; 00054 m_lFramesPerSecond = 90; 00055 m_pLastView = NULL; 00056 // TODO: add construction code here, 00057 // Place all significant initialization in InitInstance 00058 } 00059 00061 // The one and only CGUIEditorApp object 00062 00063 CGUIEditorApp theApp; 00064 00066 // CGUIEditorApp initialization 00067 00068 BOOL CGUIEditorApp::InitInstance() 00069 { 00070 AfxEnableControlContainer(); 00071 00072 // Standard initialization 00073 // If you are not using these features and wish to reduce the size 00074 // of your final executable, you should remove from the following 00075 // the specific initialization routines you do not need. 00076 00077 #ifdef _AFXDLL 00078 Enable3dControls(); // Call this when using MFC in a shared DLL 00079 #else 00080 Enable3dControlsStatic(); // Call this when linking to MFC statically 00081 #endif 00082 00083 // Change the registry key under which our settings are stored. 00084 // TODO: You should modify this CString to be something appropriate 00085 // such as the name of your company or organization. 00086 SetRegistryKey(_T("Local AppWizard-Generated Applications")); 00087 00088 LoadStdProfileSettings(); // Load standard INI file options (including MRU) 00089 00090 // Register the application's document templates. Document templates 00091 // serve as the connection between documents, frame windows and views. 00092 00093 CMultiDocTemplate* pDocTemplate; 00094 pDocTemplate = new CMultiDocTemplate( 00095 IDR_MAINFRAME, 00096 RUNTIME_CLASS(CGUIEditorDoc), 00097 RUNTIME_CLASS(CChildFrame), // custom MDI child frame 00098 RUNTIME_CLASS(CGUIEditorView)); 00099 AddDocTemplate(pDocTemplate); 00100 00101 // create main MDI Frame window 00102 CMainFrame *pMainFrame = new CMainFrame; 00103 if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) 00104 return FALSE; 00105 m_pMainWnd = pMainFrame; 00106 00107 // Parse command line for standard shell commands, DDE, file open 00108 CCommandLineInfo cmdInfo; 00109 00110 // Change m_nShellCommand value to FileNothing 00111 ParseCommandLine(cmdInfo); 00112 00113 // Dispatch commands specified on the command line 00114 if (!ProcessShellCommand(cmdInfo)) 00115 return FALSE; 00116 00117 // The main window has been initialized, so show and update it. 00118 pMainFrame->ShowWindow(m_nCmdShow); 00119 pMainFrame->UpdateWindow(); 00120 00121 if(pMainFrame->MDIGetActive() !=NULL) 00122 { 00123 CGUIEditorView *pActiveView = (CGUIEditorView *)pMainFrame->MDIGetActive()->GetActiveView(); 00124 if(pActiveView !=NULL) 00125 { 00126 pMainFrame->SetWindowPixelFormat(pActiveView->m_hDC); 00127 pMainFrame->CreateViewGLContext(pActiveView->m_hDC); 00128 } 00129 } 00130 00131 LoadApp("application.xml"); 00132 return TRUE; 00133 } 00134 00135 00136 int CGUIEditorApp::Run() 00137 { 00138 if (!m_pMainWnd) 00139 AfxPostQuitMessage(0); 00140 00141 MSG msg; 00142 CMainFrame* pFrame = (CMainFrame *)AfxGetMainWnd(); 00143 00144 if ( QueryPerformanceFrequency ( ( LARGE_INTEGER *) &m_lPerfCounter ) ) { 00145 00146 // yes, set m_dwTimeCount and timer choice flag 00147 m_bPerFlag = TRUE; 00148 m_dwTimeCount = unsigned long(m_lPerfCounter / m_lFramesPerSecond); 00149 QueryPerformanceCounter ( ( LARGE_INTEGER * ) &m_lNextTime ); 00150 m_dTimeScale = 1.0 / m_lPerfCounter; 00151 } else { 00152 // no performance counter, read in using timeGetTime 00153 00154 m_lNextTime = timeGetTime (); 00155 m_dTimeScale = 0.001; 00156 } 00157 // save time of last frame 00158 00159 // Get the active MDI child window. 00160 CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); 00161 /* or CMDIChildWnd *pChild = 00162 pFrame->MDIGetActive(); 00163 */ 00164 // Get the active view attached to the active MDI child window. 00165 CGUIEditorView *pView = (CGUIEditorView *) pChild->GetActiveView(); 00166 00167 m_lLastTime = m_lNextTime; 00168 00169 while ( TRUE ) { 00170 //see if there is a message waiting 00171 00172 pFrame = (CMainFrame *)AfxGetApp()->m_pMainWnd; 00173 // Get the active MDI child window. 00174 pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); 00175 /* or CMDIChildWnd *pChild = 00176 pFrame->MDIGetActive(); 00177 */ 00178 // Get the active view attached to the active MDI child window. 00179 CGUIEditorView *pView = (CGUIEditorView *) pChild->GetActiveView(); 00180 if(m_pLastView !=pView) 00181 { 00182 if(m_pLastView !=NULL) 00183 wglMakeCurrent(((CGUIEditorView *)m_pLastView)->m_hDC, NULL); 00184 00185 m_pLastView = pView; 00186 if(pView !=NULL) 00187 wglMakeCurrent(pView->m_hDC, pFrame->m_hRC); 00188 } 00189 if ( ::PeekMessage ( &msg, NULL, 0, 0, PM_NOREMOVE ) ) { 00190 do //if there is pump all waiting 00191 { 00192 if ( !PumpMessage () ) 00193 return ExitInstance (); 00194 } while ( ::PeekMessage ( &msg, NULL, 0, 0, PM_NOREMOVE ) ); 00195 } else { 00196 00197 // use the appropriate method to get time 00198 // and calculate elapsed time since last frame 00199 00200 if ( m_bPerFlag ) { 00201 QueryPerformanceCounter ( ( LARGE_INTEGER * ) &m_lCurTime ); 00202 } else { 00203 m_lCurTime=timeGetTime (); 00204 } 00205 00206 // is it time to render the frame? 00207 00208 if ( m_lCurTime > m_lNextTime ) { 00209 00210 // calculate elapsed time 00211 00212 m_dTimeElapsed = ( m_lCurTime - m_lLastTime ) * m_dTimeScale; 00213 00214 00215 // save frame time 00216 00217 m_lLastTime = m_lCurTime; 00218 00219 // yes, render the frame 00220 00221 if ( !pFrame->m_bAppIsActive ) 00222 WaitMessage(); 00223 else 00224 { 00225 if(pView !=NULL) 00226 { 00227 pView->RenderGLScene(); 00228 00229 if(CInputEngine::GetSingletonPtr() !=NULL) 00230 { 00231 CInputEngine::GetSingleton().Poll(); 00232 00233 CMouse *pMouse = CInputEngine::GetSingleton().GetMouse(); 00234 tVERTEX2d MousePos = pMouse->GetCursorPos(); 00235 00236 POINT MP; 00237 MP.x = MousePos.x; 00238 MP.y = MousePos.y; 00239 pView->ScreenToClient(&MP); 00240 00241 #ifdef OPENGL 00242 int Viewport[4]; 00243 glGetIntegerv(GL_VIEWPORT, Viewport); 00244 MP.y = Viewport[3] - MP.y; 00245 #endif 00246 00247 pMouse->SetCursorPos(MP.x, MP.y); 00248 } 00249 } 00250 // if(pFrame->m_wndManager.fps !=NULL) 00251 // { 00252 // progress+=1; 00253 // pFrame->m_wndManager.fps->OnUpdate(progress); 00254 // } 00255 } 00256 00257 // set time for next frame 00258 00259 m_lNextTime = m_lCurTime + m_dwTimeCount; 00260 00261 } // end if 00262 00263 } // end if else 00264 00265 } // end while 00266 return msg.wParam; 00267 00268 } 00270 // CAboutDlg dialog used for App About 00271 00272 class CAboutDlg : public CDialog 00273 { 00274 public: 00275 CAboutDlg(); 00276 00277 // Dialog Data 00278 //{{AFX_DATA(CAboutDlg) 00279 enum { IDD = IDD_ABOUTBOX }; 00280 //}}AFX_DATA 00281 00282 // ClassWizard generated virtual function overrides 00283 //{{AFX_VIRTUAL(CAboutDlg) 00284 protected: 00285 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 00286 //}}AFX_VIRTUAL 00287 00288 // Implementation 00289 protected: 00290 //{{AFX_MSG(CAboutDlg) 00291 // No message handlers 00292 //}}AFX_MSG 00293 DECLARE_MESSAGE_MAP() 00294 public: 00295 }; 00296 00297 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) 00298 { 00299 //{{AFX_DATA_INIT(CAboutDlg) 00300 //}}AFX_DATA_INIT 00301 } 00302 00303 void CAboutDlg::DoDataExchange(CDataExchange* pDX) 00304 { 00305 CDialog::DoDataExchange(pDX); 00306 //{{AFX_DATA_MAP(CAboutDlg) 00307 //}}AFX_DATA_MAP 00308 } 00309 00310 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 00311 //{{AFX_MSG_MAP(CAboutDlg) 00312 // No message handlers 00313 //}}AFX_MSG_MAP 00314 END_MESSAGE_MAP() 00315 00316 // App command to run the dialog 00317 void CGUIEditorApp::OnAppAbout() 00318 { 00319 CAboutDlg aboutDlg; 00320 aboutDlg.DoModal(); 00321 } 00322 00323 void CGUIEditorApp::LoadApp(CString strFilename) 00324 { 00325 TiXmlDocument AppDoc; 00326 TiXmlNode *pAppNode = NULL; 00327 00328 if(AppDoc.LoadFile(strFilename)) 00329 { 00330 const char *pcValue = NULL; 00331 pAppNode = AppDoc.FirstChild(); 00332 00333 if(CTextureManager::GetSingletonPtr() !=NULL) 00334 { 00335 pcValue = pAppNode->ToElement()->Attribute("TextureDatabase"); 00336 if(pcValue !=NULL) 00337 { 00338 CTextureManager::GetSingleton().LoadXML(NULL, pcValue); 00339 pcValue = NULL; 00340 } 00341 } 00342 00343 if(CMaterialManager::GetSingletonPtr() !=NULL) 00344 { 00345 pcValue = pAppNode->ToElement()->Attribute("MaterialDatabase"); 00346 if(pcValue !=NULL) 00347 { 00348 CMaterialManager::GetSingleton().LoadXML(NULL, pcValue); 00349 pcValue = NULL; 00350 } 00351 } 00352 00353 if(CAnimationManager::GetSingletonPtr() !=NULL) 00354 { 00355 pcValue = pAppNode->ToElement()->Attribute("AnimationDatabase"); 00356 if(pcValue !=NULL) 00357 { 00358 CAnimationManager::GetSingleton().LoadXML(NULL, pcValue); 00359 pcValue = NULL; 00360 } 00361 } 00362 00363 if(CFontManager::GetSingletonPtr() !=NULL) 00364 { 00365 pcValue = pAppNode->ToElement()->Attribute("FontDatabase"); 00366 if(pcValue !=NULL) 00367 { 00368 CFontManager::GetSingleton().LoadXML(NULL, pcValue); 00369 pcValue = NULL; 00370 } 00371 } 00372 00373 POSITION posTemplate = GetFirstDocTemplatePosition(); 00374 CDocTemplate * pTemplate = GetNextDocTemplate(posTemplate); 00375 00376 TiXmlNode *pIterNode = pAppNode->FirstChild(); 00377 while(pIterNode !=NULL) 00378 { 00379 CGUIEditorDoc *pNewDoc = (CGUIEditorDoc *)pTemplate->CreateNewDocument(); 00380 pNewDoc->OnNewDocument(); 00381 CMainFrame *pMainFrame = (CMainFrame *)AfxGetMainWnd(); 00382 00383 CChildFrame *pNewFrame = (CChildFrame *)pTemplate->CreateNewFrame(pNewDoc, pMainFrame); 00384 00385 CView *pActiveView = (CView *)pNewFrame->GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE); 00386 pNewFrame->SetActiveView(pActiveView); 00387 00388 if(pNewDoc->GetGUI() !=NULL) 00389 pNewDoc->GetGUI()->LoadXML(pIterNode, ""); 00390 00391 pNewFrame->SetWindowText(pNewDoc->GetGUI()->GetName()); 00392 00393 pIterNode = pAppNode->IterateChildren(pIterNode); 00394 } 00395 } 00396 00397 } 00398 00399 void CGUIEditorApp::OnFileSave() 00400 { 00401 00402 } 00403 00404 void CGUIEditorApp::OnMenuFileSave() 00405 { 00406 TiXmlDocument XMLAppDoc; 00407 TiXmlElement AppXMLElement("Application"); 00408 00409 CString AppPath = GetAppPath(); 00410 00411 AppXMLElement.SetAttribute("TextureDatabase", "texture_database.xml"); 00412 CTextureManager::GetSingleton().SaveXML(NULL, AppPath + "texture_database.xml"); 00413 00414 AppXMLElement.SetAttribute("MaterialDatabase", "material_database.xml"); 00415 CMaterialManager::GetSingleton().SaveXML(NULL, AppPath + "material_database.xml"); 00416 00417 AppXMLElement.SetAttribute("AnimationDatabase", "animation_database.xml"); 00418 CAnimationManager::GetSingleton().SaveXML(NULL, AppPath + "animation_database.xml"); 00419 00420 AppXMLElement.SetAttribute("FontDatabase", "font_database.xml"); 00421 CFontManager::GetSingleton().SaveXML(NULL, AppPath + "font_database.xml"); 00422 00423 POSITION posTemplate = GetFirstDocTemplatePosition(); 00424 while (posTemplate != 0) 00425 { 00426 CDocTemplate * pTemplate = GetNextDocTemplate(posTemplate); 00427 POSITION posDoc = pTemplate->GetFirstDocPosition(); 00428 while (posDoc != 0) 00429 { 00430 CDocument *pDoc = pTemplate->GetNextDoc(posDoc); 00431 if (! pDoc->IsKindOf(RUNTIME_CLASS(CGUIEditorDoc))) 00432 continue; 00433 00434 CGUIEditorDoc * pGUIDoc = reinterpret_cast<CGUIEditorDoc*>(pDoc); 00435 if(pGUIDoc->GetGUI() !=NULL) 00436 { 00437 if(pGUIDoc->GetGUI()->size() > 0) 00438 { 00439 TiXmlElement GUIXMLElement("GUI"); 00440 pGUIDoc->GetGUI()->SaveXML(&GUIXMLElement, ""); 00441 AppXMLElement.InsertEndChild(GUIXMLElement); 00442 } 00443 } 00444 } 00445 } 00446 00447 XMLAppDoc.InsertEndChild(AppXMLElement); 00448 XMLAppDoc.SaveFile(AppPath + "application.xml"); 00449 }

Generated on Sun Jul 17 21:34:26 2005 for OpenGL GUI by doxygen 1.3.8