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

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

00001 // MainFrm.cpp : implementation of the CMainFrame class 00002 // 00003 00004 #include "stdafx.h" 00005 #include "GUIEditor.h" 00006 #include "GUIEditorView.h" 00007 00008 #include "MainFrm.h" 00009 #include ".\mainfrm.h" 00010 00011 #ifdef _DEBUG 00012 #define new DEBUG_NEW 00013 #undef THIS_FILE 00014 static char THIS_FILE[] = __FILE__; 00015 #endif 00016 00018 // CMainFrame 00019 00020 IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd) 00021 00022 BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) 00023 //{{AFX_MSG_MAP(CMainFrame) 00024 ON_WM_CREATE() 00025 ON_WM_TIMER() 00026 ON_WM_MDIACTIVATE() 00027 ON_COMMAND(ID_ALIGN_LEFT, OnAlignLeft) 00028 ON_COMMAND(ID_ALIGN_TOP, OnAlignTop) 00029 ON_COMMAND(ID_ALIGN_RIGHT, OnAlignRight) 00030 ON_COMMAND(ID_ALIGN_BOTTOM, OnAlignBottom) 00031 ON_COMMAND(ID_SAME_WIDTH, OnSameWidth) 00032 ON_COMMAND(ID_SAME_HEIGHT, OnSameHeight) 00033 ON_COMMAND(ID_SAME_SIZE, OnSameSize) 00034 //}}AFX_MSG_MAP 00035 ON_WM_ACTIVATEAPP() 00036 ON_WM_DESTROY() 00037 END_MESSAGE_MAP() 00038 00039 static UINT indicators[] = 00040 { 00041 ID_SEPARATOR, // status line indicator 00042 ID_INDICATOR_CAPS, 00043 ID_INDICATOR_NUM, 00044 ID_INDICATOR_SCRL, 00045 }; 00046 00048 // CMainFrame construction/destruction 00049 00050 CMainFrame::CMainFrame() 00051 { 00052 m_pActiveFrame = NULL; 00053 m_pGUIElement = NULL; 00054 CGlobalLogger *pLogger = new CGlobalLogger("GlobalLog.txt"); 00055 CInputEngine *pInputEngine = new CInputEngine; 00056 CTextureManager *pTextureManager = new CTextureManager; 00057 CMaterialManager *pMaterialManager = new CMaterialManager; 00058 CFontManager *pFontManager = new CFontManager; 00059 CAnimationManager *pAnimationManager = new CAnimationManager; 00060 00061 m_pGUIElement = NULL; 00062 m_pTextureSettings = new CAddTextureSettings; 00063 m_pMaterialSettings = new CAddMaterialSettings; 00064 m_pAnimationSettings = new CAddAnimationSettings; 00065 m_pFontSettings = new CAddFontSettings; 00066 00067 pInputEngine->Create(); 00068 m_pResourceSettings = m_pAnimationSettings; 00069 00070 m_bAppIsActive = FALSE; 00071 m_hRC = 0; 00072 } 00073 00074 CMainFrame::~CMainFrame() 00075 { 00076 delete CMaterialManager::GetSingletonPtr(); 00077 delete CTextureManager::GetSingletonPtr(); 00078 delete CAnimationManager::GetSingletonPtr(); 00079 delete CFontManager::GetSingletonPtr(); 00080 delete CInputEngine::GetSingletonPtr(); 00081 00082 SAFEDEL(m_pTextureSettings) 00083 SAFEDEL(m_pMaterialSettings) 00084 SAFEDEL(m_pAnimationSettings) 00085 SAFEDEL(m_pFontSettings) 00086 00087 m_pGUIElement = NULL; 00088 delete CGlobalLogger::GetSingletonPtr(); 00089 } 00090 00091 /******************************************** 00092 // CreateViewGLContext 00093 // Create an OpenGL rendering context 00094 //********************************************/ 00095 BOOL CMainFrame::CreateViewGLContext(HDC hDC) 00096 { 00097 if(m_hRC == NULL) 00098 m_hRC = wglCreateContext(hDC); 00099 00100 if(m_hRC == NULL) 00101 return FALSE; 00102 00103 if(wglMakeCurrent(hDC, m_hRC) == FALSE) 00104 return FALSE; 00105 00106 return TRUE; 00107 } 00108 00109 //******************************************** 00110 // SetWindowPixelFormat 00111 //******************************************** 00112 BOOL CMainFrame::SetWindowPixelFormat(HDC hDC) 00113 { 00114 static PIXELFORMATDESCRIPTOR pixelDesc= // pfd Tells Windows How We Want Things To Be 00115 { 00116 sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 00117 1, // Version Number 00118 PFD_DRAW_TO_WINDOW | // Format Must Support Window 00119 PFD_SUPPORT_OPENGL | // Format Must Support OpenGL 00120 PFD_DOUBLEBUFFER, // Must Support Double Buffering 00121 PFD_TYPE_RGBA, // Request An RGBA Format 00122 32, // Select Our Color Depth 00123 0, 0, 0, 0, 0, 0, // Color Bits Ignored 00124 0, // No Alpha Buffer 00125 0, // Shift Bit Ignored 00126 0, // No Accumulation Buffer 00127 0, 0, 0, 0, // Accumulation Bits Ignored 00128 16, // 16Bit Z-Buffer (Depth Buffer) 00129 0, // No Stencil Buffer 00130 0, // No Auxiliary Buffer 00131 PFD_MAIN_PLANE, // Main Drawing Layer 00132 0, // Reserved 00133 0, 0, 0 // Layer Masks Ignored 00134 }; 00135 00136 GLuint PixelIndex = ChoosePixelFormat(hDC, &pixelDesc); 00137 if(PixelIndex == 0) // Choose default 00138 { 00139 PixelIndex = 1; 00140 if(DescribePixelFormat(hDC, PixelIndex, 00141 sizeof(PIXELFORMATDESCRIPTOR), &pixelDesc)==0) 00142 return FALSE; 00143 } 00144 00145 if(!SetPixelFormat(hDC, PixelIndex, &pixelDesc)) 00146 return FALSE; 00147 return TRUE; 00148 } 00149 00150 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 00151 { 00152 if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) 00153 return -1; 00154 00155 SetTitle("GUI Editor"); 00156 00157 InitMenu(IDR_MENU); 00158 InitToolBar(IDR_TOOLBAR); 00159 InitStatusBar(indicators,sizeof(indicators)/sizeof(UINT)); 00160 // TODO: Delete these three lines if you don't want the toolbar to 00161 // be dockable 00162 00163 EnableDocking(CBRS_ALIGN_ANY); 00164 m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); 00165 m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY); 00166 m_wndMenuBar.SetSaveHistory("MyHistory1", TRUE); 00167 00168 DockControlBar(&m_wndMenuBar, m_dockTop); 00169 DockControlBar(&m_wndToolBar, m_dockTop); 00170 m_wndStatusBar.SetStyle(CGuiStatusBar::OFFICE); 00171 00172 InitMDITabbed(); 00173 m_MdiTabbed.SetTabsMenu(IDR_MENUTABS); 00174 SetTimer(1,150,0); 00175 00176 m_bStyleSet = false; 00177 00178 m_ResourceSettingsDlg.Create(IDD_SETTINGS, this); 00179 //m_ResourceSettingsDlg.ShowWindow(SW_SHOW); 00180 00181 m_GUISettingsDlg.Create(IDD_SETTINGS, this); 00182 m_GUISettingsDlg.ShowWindow(SW_SHOW); 00183 00184 return 0; 00185 } 00186 00187 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) 00188 { 00189 if( !CMDIFrameWnd::PreCreateWindow(cs) ) 00190 return FALSE; 00191 // TODO: Modify the Window class or styles here by modifying 00192 // the CREATESTRUCT cs 00193 return TRUE; 00194 } 00195 00197 // CMainFrame diagnostics 00198 00199 #ifdef _DEBUG 00200 void CMainFrame::AssertValid() const 00201 { 00202 CMDIFrameWnd::AssertValid(); 00203 } 00204 00205 void CMainFrame::Dump(CDumpContext& dc) const 00206 { 00207 CMDIFrameWnd::Dump(dc); 00208 } 00209 00210 #endif //_DEBUG 00211 00213 // CMainFrame message handlers 00214 00215 void CMainFrame::OnTimer(UINT nIDEvent) 00216 { 00217 // TODO: Add your message handler code here and/or call default 00218 CMDIChildWnd *pFrameWnd = MDIGetActive(); 00219 CChildFrame *pActiveChild = (CChildFrame *)pFrameWnd; 00220 if(m_pResourceSettings !=NULL) 00221 { 00222 if(m_pResourceSettings->m_bUpdateRequired) 00223 { 00224 m_ResourceSettingsDlg.SetPropPointer(m_pResourceSettings); 00225 m_pResourceSettings->m_bUpdateRequired = false; 00226 // Database updated 00227 if(m_pGUIElement !=NULL) 00228 m_pGUIElement->m_bUpdateRequired = true; 00229 } 00230 00231 if(m_pResourceSettings == m_pTextureSettings) 00232 m_ResourceSettingsDlg.SetWindowText("Texture(s) Management"); 00233 else if(m_pResourceSettings == m_pMaterialSettings) 00234 m_ResourceSettingsDlg.SetWindowText("Material(s) Management"); 00235 else if(m_pResourceSettings == m_pAnimationSettings) 00236 m_ResourceSettingsDlg.SetWindowText("Animation(s) Management"); 00237 else if(m_pResourceSettings == m_pFontSettings) 00238 m_ResourceSettingsDlg.SetWindowText("Font(s) Management"); 00239 } 00240 00241 if(m_pGUIElement !=NULL && m_pGUIElement->m_bUpdateRequired) 00242 { 00243 m_GUISettingsDlg.SetPropPointer(m_pGUIElement); 00244 m_pGUIElement->m_bUpdateRequired = false; 00245 } 00246 00247 if(m_pActiveFrame !=pActiveChild) 00248 m_pActiveFrame = pActiveChild; 00249 00250 if(!m_bStyleSet) 00251 { 00252 m_ResourceSettingsDlg.SetPropPointer(m_pTextureSettings); 00253 m_ResourceSettingsDlg.SetPropPointer(m_pMaterialSettings); 00254 00255 StyleDispl(GUISTYLE_2003); 00256 00257 m_ResourceSettingsDlg.SetPropPointer(m_pResourceSettings); 00258 m_GUISettingsDlg.SetPropPointer(m_pGUIElement); 00259 00260 m_bStyleSet = true; 00261 } 00262 } 00263 00264 void CMainFrame::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd ) 00265 { 00266 CMDIFrameWnd::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd); 00267 } 00268 00269 void CMainFrame::OnAlignLeft() 00270 { 00271 CChildFrame *pChildFrame = (CChildFrame *)this->GetActiveFrame(); 00272 if(pChildFrame !=NULL) 00273 { 00274 CGUIEditorView *pView = (CGUIEditorView *)pChildFrame->GetActiveView(); 00275 if(pView !=NULL) 00276 { 00277 if(pView->GetSelectionCount() == 0) 00278 return; 00279 00280 int LeftMost = 1000000; 00281 CGUIElement *pIter = pView->GetFirstSelection(); 00282 while(pIter !=NULL) 00283 { 00284 if((pIter->GetParent() == pIter->GetGUI()) || (pIter->GetParent()->GetType() == GUI_RadioGroup)) 00285 { 00286 if(pIter->GetRect().left < LeftMost) 00287 LeftMost = pIter->GetRect().left; 00288 } 00289 00290 pIter = pView->GetNextSelection(); 00291 } 00292 00293 pIter = pView->GetFirstSelection(); 00294 while(pIter !=NULL) 00295 { 00296 if((pIter->GetParent() == pIter->GetGUI()) || (pIter->GetParent()->GetType() == GUI_RadioGroup)) 00297 { 00298 int Width = pIter->GetWidth(); 00299 pIter->GetRect().left = LeftMost; 00300 pIter->GetRect().right = pIter->GetRect().left + Width; 00301 00302 pIter->Resize(pIter->GetRect()); 00303 } 00304 pIter = pView->GetNextSelection(); 00305 } 00306 } 00307 } 00308 } 00309 00310 void CMainFrame::OnAlignTop() 00311 { 00312 CChildFrame *pChildFrame = (CChildFrame *)this->GetActiveFrame(); 00313 if(pChildFrame !=NULL) 00314 { 00315 CGUIEditorView *pView = (CGUIEditorView *)pChildFrame->GetActiveView(); 00316 if(pView !=NULL) 00317 { 00318 if(pView->GetSelectionCount() == 0) 00319 return; 00320 00321 int TopMost = 0; 00322 CGUIElement *pIter = pView->GetFirstSelection(); 00323 while(pIter !=NULL) 00324 { 00325 if((pIter->GetParent() == pIter->GetGUI()) || (pIter->GetParent()->GetType() == GUI_RadioGroup)) 00326 { 00327 if(pIter->GetRect().top > TopMost) 00328 TopMost = pIter->GetRect().top; 00329 } 00330 00331 pIter = pView->GetNextSelection(); 00332 } 00333 00334 pIter = pView->GetFirstSelection(); 00335 while(pIter !=NULL) 00336 { 00337 if((pIter->GetParent() == pIter->GetGUI()) || (pIter->GetParent()->GetType() == GUI_RadioGroup)) 00338 { 00339 int Height = pIter->GetHeight(); 00340 pIter->GetRect().top = TopMost; 00341 pIter->GetRect().bottom = pIter->GetRect().top - Height; 00342 00343 pIter->Resize(pIter->GetRect()); 00344 } 00345 pIter = pView->GetNextSelection(); 00346 } 00347 } 00348 } 00349 } 00350 00351 void CMainFrame::OnAlignRight() 00352 { 00353 CChildFrame *pChildFrame = (CChildFrame *)this->GetActiveFrame(); 00354 if(pChildFrame !=NULL) 00355 { 00356 CGUIEditorView *pView = (CGUIEditorView *)pChildFrame->GetActiveView(); 00357 if(pView !=NULL) 00358 { 00359 if(pView->GetSelectionCount() == 0) 00360 return; 00361 00362 int RightMost = 0; 00363 CGUIElement *pIter = pView->GetFirstSelection(); 00364 while(pIter !=NULL) 00365 { 00366 if((pIter->GetParent() == pIter->GetGUI()) || (pIter->GetParent()->GetType() == GUI_RadioGroup)) 00367 { 00368 if(pIter->GetRect().right > RightMost) 00369 RightMost = pIter->GetRect().right; 00370 } 00371 00372 pIter = pView->GetNextSelection(); 00373 } 00374 00375 pIter = pView->GetFirstSelection(); 00376 while(pIter !=NULL) 00377 { 00378 if((pIter->GetParent() == pIter->GetGUI()) || (pIter->GetParent()->GetType() == GUI_RadioGroup)) 00379 { 00380 int Width = pIter->GetWidth(); 00381 pIter->GetRect().right = RightMost; 00382 pIter->GetRect().left = pIter->GetRect().right - Width; 00383 00384 pIter->Resize(pIter->GetRect()); 00385 } 00386 pIter = pView->GetNextSelection(); 00387 } 00388 } 00389 } 00390 } 00391 00392 void CMainFrame::OnAlignBottom() 00393 { 00394 CChildFrame *pChildFrame = (CChildFrame *)this->GetActiveFrame(); 00395 if(pChildFrame !=NULL) 00396 { 00397 CGUIEditorView *pView = (CGUIEditorView *)pChildFrame->GetActiveView(); 00398 if(pView !=NULL) 00399 { 00400 if(pView->GetSelectionCount() == 0) 00401 return; 00402 00403 int BottomMost = 10000; 00404 CGUIElement *pIter = pView->GetFirstSelection(); 00405 while(pIter !=NULL) 00406 { 00407 if((pIter->GetParent() == pIter->GetGUI()) || (pIter->GetParent()->GetType() == GUI_RadioGroup)) 00408 { 00409 if(pIter->GetRect().bottom < BottomMost) 00410 BottomMost = pIter->GetRect().bottom; 00411 } 00412 00413 pIter = pView->GetNextSelection(); 00414 } 00415 00416 pIter = pView->GetFirstSelection(); 00417 while(pIter !=NULL) 00418 { 00419 if((pIter->GetParent() == pIter->GetGUI()) || (pIter->GetParent()->GetType() == GUI_RadioGroup)) 00420 { 00421 int Height = pIter->GetHeight(); 00422 pIter->GetRect().bottom = BottomMost; 00423 pIter->GetRect().top = pIter->GetRect().bottom + Height; 00424 00425 pIter->Resize(pIter->GetRect()); 00426 } 00427 pIter = pView->GetNextSelection(); 00428 } 00429 } 00430 } 00431 } 00432 00433 void CMainFrame::OnSameWidth() 00434 { 00435 CChildFrame *pChildFrame = (CChildFrame *)this->GetActiveFrame(); 00436 if(pChildFrame !=NULL) 00437 { 00438 CGUIEditorView *pView = (CGUIEditorView *)pChildFrame->GetActiveView(); 00439 if(pView !=NULL) 00440 { 00441 if(pView->GetSelectionCount() == 0) 00442 return; 00443 00444 if((pView->GetFirstSelection()->GetParent() == pView->GetFirstSelection()->GetGUI()) || (pView->GetFirstSelection()->GetType() == GUI_RadioGroup)) 00445 { 00446 int Width = pView->GetFirstSelection()->GetWidth(); 00447 00448 CGUIElement *pIter = pView->GetFirstSelection(); 00449 while(pIter !=NULL) 00450 { 00451 if((pIter->GetParent() == pIter->GetGUI()) || (pIter->GetParent()->GetType() == GUI_RadioGroup)) 00452 { 00453 pIter->GetRect().right = pIter->GetRect().left + Width; 00454 pIter->Resize(pIter->GetRect()); 00455 } 00456 pIter = pView->GetNextSelection(); 00457 } 00458 } 00459 } 00460 } 00461 } 00462 00463 void CMainFrame::OnSameHeight() 00464 { 00465 CChildFrame *pChildFrame = (CChildFrame *)this->GetActiveFrame(); 00466 if(pChildFrame !=NULL) 00467 { 00468 CGUIEditorView *pView = (CGUIEditorView *)pChildFrame->GetActiveView(); 00469 if(pView !=NULL) 00470 { 00471 if(pView->GetSelectionCount() == 0) 00472 return; 00473 00474 if((pView->GetFirstSelection()->GetParent() == pView->GetFirstSelection()->GetGUI()) || (pView->GetFirstSelection()->GetType() == GUI_RadioGroup)) 00475 { 00476 int Height = pView->GetFirstSelection()->GetHeight(); 00477 00478 CGUIElement *pIter = pView->GetFirstSelection(); 00479 while(pIter !=NULL) 00480 { 00481 if((pIter->GetParent() == pIter->GetGUI()) || (pIter->GetParent()->GetType() == GUI_RadioGroup)) 00482 { 00483 pIter->GetRect().bottom = pIter->GetRect().top - Height; 00484 pIter->Resize(pIter->GetRect()); 00485 } 00486 pIter = pView->GetNextSelection(); 00487 } 00488 } 00489 } 00490 } 00491 } 00492 00493 void CMainFrame::OnSameSize() 00494 { 00495 OnSameWidth(); 00496 OnSameHeight(); 00497 } 00498 00499 00500 void CMainFrame::SelectElement(CGUIElement *pElement) 00501 { 00502 m_pGUIElement = pElement; 00503 m_GUISettingsDlg.SetPropPointer(NULL); 00504 } 00505 00506 void CMainFrame::OnActivateApp(BOOL bActive, DWORD dwThreadID) 00507 { 00508 CGuiMDIFrame::OnActivateApp(bActive, dwThreadID); 00509 m_bAppIsActive = bActive; 00510 } 00511 00512 void CMainFrame::OnDestroy() 00513 { 00514 CGuiMDIFrame::OnDestroy(); 00515 wglDeleteContext(m_hRC); 00516 }

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