00001
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
00023
00024 BEGIN_MESSAGE_MAP(CGUIEditorApp, CWinApp)
00025
00026 ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
00027
00028
00029
00030
00031
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
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
00057
00058 }
00059
00061
00062
00063 CGUIEditorApp theApp;
00064
00066
00067
00068 BOOL CGUIEditorApp::InitInstance()
00069 {
00070 AfxEnableControlContainer();
00071
00072
00073
00074
00075
00076
00077
#ifdef _AFXDLL
00078
Enable3dControls();
00079
#else
00080
Enable3dControlsStatic();
00081
#endif
00082
00083
00084
00085
00086 SetRegistryKey(_T(
"Local AppWizard-Generated Applications"));
00087
00088 LoadStdProfileSettings();
00089
00090
00091
00092
00093 CMultiDocTemplate* pDocTemplate;
00094 pDocTemplate =
new CMultiDocTemplate(
00095 IDR_MAINFRAME,
00096 RUNTIME_CLASS(CGUIEditorDoc),
00097 RUNTIME_CLASS(CChildFrame),
00098 RUNTIME_CLASS(CGUIEditorView));
00099 AddDocTemplate(pDocTemplate);
00100
00101
00102 CMainFrame *pMainFrame =
new CMainFrame;
00103
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
00104
return FALSE;
00105 m_pMainWnd = pMainFrame;
00106
00107
00108 CCommandLineInfo cmdInfo;
00109
00110
00111 ParseCommandLine(cmdInfo);
00112
00113
00114
if (!ProcessShellCommand(cmdInfo))
00115
return FALSE;
00116
00117
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
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
00153
00154 m_lNextTime = timeGetTime ();
00155 m_dTimeScale = 0.001;
00156 }
00157
00158
00159
00160 CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
00161
00162
00163
00164
00165 CGUIEditorView *pView = (CGUIEditorView *) pChild->GetActiveView();
00166
00167 m_lLastTime = m_lNextTime;
00168
00169
while ( TRUE ) {
00170
00171
00172 pFrame = (CMainFrame *)AfxGetApp()->m_pMainWnd;
00173
00174 pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
00175
00176
00177
00178
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
00191 {
00192
if ( !PumpMessage () )
00193
return ExitInstance ();
00194 }
while ( ::PeekMessage ( &msg, NULL, 0, 0, PM_NOREMOVE ) );
00195 }
else {
00196
00197
00198
00199
00200
if ( m_bPerFlag ) {
00201 QueryPerformanceCounter ( ( LARGE_INTEGER * ) &m_lCurTime );
00202 }
else {
00203 m_lCurTime=timeGetTime ();
00204 }
00205
00206
00207
00208
if ( m_lCurTime > m_lNextTime ) {
00209
00210
00211
00212 m_dTimeElapsed = ( m_lCurTime - m_lLastTime ) * m_dTimeScale;
00213
00214
00215
00216
00217 m_lLastTime = m_lCurTime;
00218
00219
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
00251
00252
00253
00254
00255 }
00256
00257
00258
00259 m_lNextTime = m_lCurTime + m_dwTimeCount;
00260
00261 }
00262
00263 }
00264
00265 }
00266
return msg.wParam;
00267
00268 }
00270
00271
00272
class CAboutDlg :
public CDialog
00273 {
00274
public:
00275 CAboutDlg();
00276
00277
00278
00279
enum { IDD = IDD_ABOUTBOX };
00280
00281
00282
00283
00284
protected:
00285
virtual void DoDataExchange(CDataExchange* pDX);
00286
00287
00288
00289
protected:
00290
00291
00292
00293 DECLARE_MESSAGE_MAP()
00294 public:
00295 };
00296
00297 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
00298 {
00299
00300
00301 }
00302
00303
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
00304 {
00305 CDialog::DoDataExchange(pDX);
00306
00307
00308 }
00309
00310 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
00311
00312
00313
00314 END_MESSAGE_MAP()
00315
00316
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 }