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

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

00001 #include "StdAfx.h" 00002 #include "GUI.h" 00003 00004 CGUIWindow::CGUIWindow() 00005 { 00006 Initialize(); 00007 } 00008 00009 CGUIWindow::~CGUIWindow() 00010 { 00011 00012 } 00013 00014 void CGUIWindow::Initialize() 00015 { 00016 SetType(GUI_Window); 00017 m_iWindowState = GUI_WindowNormal; 00018 00019 m_strElementType = "Window"; 00020 } 00021 00022 int CGUIWindow::Create(CGUIElement *pParent, tRect WidgetRect, CGUIStatic *pStatusBar, CGUIStatic *pTitleBar, CGUIButton *pCloseButton, CGUIButton *pMinButton, CGUIButton *pMaxRestoreButton, CTexture *pTexture, CMaterial *pMaterial, bool bBorder) 00023 { 00024 if(!CGUIElement::Create(pParent, WidgetRect, pTexture, pMaterial, bBorder)) 00025 return 0; 00026 00027 if(pTitleBar !=NULL) 00028 { 00029 if(!IsChild(pTitleBar) && (GetChild(GUI_Window_StatusBar) == NULL)) 00030 { 00031 pTitleBar->SetName(CString("Status Bar")); 00032 pTitleBar->SetType(GUI_Window_StatusBar); 00033 00034 pTitleBar->SetParent(this); 00035 pTitleBar->RemoveChild(pTitleBar->GetChild(GUI_Border)); 00036 push_back(pTitleBar); 00037 00038 if(pMinButton !=NULL) 00039 { 00040 if(!pTitleBar->IsChild(pMinButton) && (pTitleBar->GetChild(GUI_Window_MinimizeButton) == NULL)) 00041 { 00042 pMinButton->SetName(CString("Minimize Button")); 00043 pMinButton->SetType(GUI_Window_MinimizeButton); 00044 pMinButton->SetParent(pTitleBar); 00045 00046 pMinButton->RemoveChild(pMinButton->GetChild(GUI_Border)); 00047 pTitleBar->push_back(pMinButton); 00048 } 00049 } 00050 00051 if(pMaxRestoreButton !=NULL) 00052 { 00053 if(!pTitleBar->IsChild(pMaxRestoreButton) && (pTitleBar->GetChild(GUI_Window_MaxRestoreButton) == NULL)) 00054 { 00055 pMaxRestoreButton->SetName(CString("Maximize Button")); 00056 pMaxRestoreButton->SetType(GUI_Window_MaxRestoreButton); 00057 pMaxRestoreButton->SetParent(pTitleBar); 00058 00059 pMaxRestoreButton->RemoveChild(pMaxRestoreButton->GetChild(GUI_Border)); 00060 pTitleBar->push_back(pMaxRestoreButton); 00061 } 00062 } 00063 00064 if(pCloseButton !=NULL) 00065 { 00066 if(!pTitleBar->IsChild(pCloseButton) && (pTitleBar->GetChild(GUI_Window_CloseButton) == NULL)) 00067 { 00068 pCloseButton->SetName(CString("Close Button")); 00069 pCloseButton->SetType(GUI_Window_CloseButton); 00070 pCloseButton->SetParent(pTitleBar); 00071 00072 pCloseButton->RemoveChild(pCloseButton->GetChild(GUI_Border)); 00073 pTitleBar->push_back(pCloseButton); 00074 } 00075 } 00076 } 00077 } 00078 00079 if(pStatusBar !=NULL) 00080 { 00081 if(!IsChild(pStatusBar) && (GetChild(GUI_Window_StatusBar) == NULL)) 00082 { 00083 pStatusBar->SetName(CString("Status Bar")); 00084 pStatusBar->SetType(GUI_Window_StatusBar); 00085 pStatusBar->SetParent(this); 00086 00087 pStatusBar->RemoveChild(pStatusBar->GetChild(GUI_Border)); 00088 push_back(pStatusBar); 00089 } 00090 } 00091 00092 return 1; 00093 } 00094 00095 int CGUIWindow::LoadXML(TiXmlNode *pDataNode, CString strFilename) 00096 { 00097 TiXmlElement* pXMLElement = NULL; 00098 const char *pcValue = NULL; 00099 00100 int iRetValue = CGUIElement::LoadXML(pDataNode, strFilename); // LoadXML the data of derivative 00101 if(iRetValue !=1) 00102 return iRetValue; 00103 00104 pXMLElement = m_pXMLElement; 00105 00106 for (UINT i=0; i<GetChildCount(); i++) 00107 { 00108 CGUIElement *pChild = GetChild(i); 00109 if(pChild->GetType() == GUI_Static) 00110 { 00111 if(pChild->GetName() == "TitleBar") 00112 { 00113 pChild->SetType(GUI_Window_TitleBar); 00114 pChild->SetFlag(GUI_Flag_RestrictMovementX, true); 00115 pChild->SetFlag(GUI_Flag_RestrictMovementY, true); 00116 00117 pChild->RemoveChild(pChild->GetChild(GUI_Border)); 00118 00119 for (int j=0; j<pChild->GetChildCount(); j++) 00120 { 00121 CGUIElement *pSubChild = pChild->GetChild(j); 00122 if(pSubChild->GetType() == GUI_Button) 00123 { 00124 if(pSubChild->GetName() == "Close Button") 00125 pSubChild->SetType(GUI_Window_CloseButton); 00126 else if(pSubChild->GetName() == "Max/Restore Button") 00127 pSubChild->SetType(GUI_Window_MaxRestoreButton); 00128 else if(pSubChild->GetName() == "Minimize Button") 00129 pSubChild->SetType(GUI_Window_MinimizeButton); 00130 00131 pSubChild->SetFlag(GUI_Flag_RestrictMovementX, true); 00132 pSubChild->SetFlag(GUI_Flag_RestrictMovementY, true); 00133 } 00134 } 00135 } 00136 else if(pChild->GetName() == "StatusBar") 00137 { 00138 pChild->SetType(GUI_Window_StatusBar); 00139 pChild->SetFlag(GUI_Flag_RestrictMovementX, true); 00140 pChild->SetFlag(GUI_Flag_RestrictMovementY, true); 00141 00142 pChild->RemoveChild(pChild->GetChild(GUI_Border)); 00143 } 00144 } 00145 00146 } 00147 00148 if(GetChild(GUI_Window_TitleBar) == NULL) 00149 { 00150 CGlobalLogger::GetSingleton().Write("\t**********General Warning\t**********\n"); 00151 CGlobalLogger::GetSingleton().Write("Window (Name: %s, ID: %d) doesn't have a Title Bar.", GetName(), GetID()); 00152 } 00153 00154 if(GetChild(GUI_Window_StatusBar) == NULL) 00155 { 00156 CGlobalLogger::GetSingleton().Write("\t**********General Warning\t**********\n"); 00157 CGlobalLogger::GetSingleton().Write("Window (Name: %s, ID: %d) doesn't have a Status Bar.", GetName(), GetID()); 00158 } 00159 00160 return iRetValue; 00161 } 00162 00163 int CGUIWindow::SaveXML(TiXmlNode *pDataNode, CString strFilename) 00164 { 00165 // Nowhere to save! Nothing to save! 00166 if(pDataNode == NULL && strFilename == "") 00167 return -1; 00168 00169 char Buf[128] = ""; 00170 TiXmlElement *pSaveXMLElement = NULL; 00171 00172 if(pDataNode != NULL) 00173 pSaveXMLElement = pDataNode->ToElement(); 00174 else 00175 pSaveXMLElement = new TiXmlElement("Window"); 00176 00177 // Window Saves here 00178 00179 int iRetValue = CGUIElement::SaveXML(pSaveXMLElement, strFilename); 00180 00181 if(pDataNode == NULL) 00182 SAFEDEL(pSaveXMLElement) 00183 00184 return iRetValue; 00185 } 00186 00187 void CGUIWindow::Draw() 00188 { 00189 CGUIElement *pTitleBar = GetChild(GUI_Window_TitleBar), 00190 *pStatusBar = GetChild(GUI_Window_StatusBar); 00191 00192 if(pStatusBar !=NULL) 00193 pStatusBar->RemoveChild(pStatusBar->GetChild(GUI_Border)); 00194 00195 if(pTitleBar !=NULL) 00196 pTitleBar->RemoveChild(pTitleBar->GetChild(GUI_Border)); 00197 00198 if(!Visible()) 00199 HideSiblings(); 00200 else 00201 ShowSiblings(); 00202 00203 CGUIElement::Draw(); 00204 } 00205 00206 int CGUIWindow::Resize(tRect& NewRect) 00207 { 00208 CGUIElement *pTitleBar = GetChild(GUI_Window_TitleBar), 00209 *pStatusBar = GetChild(GUI_Window_StatusBar); 00210 00211 UINT MinWidth = GUI_MINIMUM_WIDTH; 00212 UINT MinHeight = 0; 00213 if(m_iWindowState != GUI_WindowMinimized) 00214 MinHeight = GUI_MINIMUM_HEIGHT; 00215 00216 if(pTitleBar !=NULL) 00217 { 00218 if(pTitleBar->GetHeight() < GUI_DEFAULT_TITLEBAR_HEIGHT) 00219 pTitleBar->SetHeight(GUI_DEFAULT_TITLEBAR_HEIGHT); 00220 00221 UINT ButtonCount = 0; 00222 for (UINT i=0; i<pTitleBar->GetChildCount(); i++) 00223 { 00224 CGUIElement *pChild = pTitleBar->GetChild(i); 00225 if( pChild->GetType() == GUI_Window_MaxRestoreButton || 00226 pChild->GetType() == GUI_Window_MinimizeButton || 00227 pChild->GetType() == GUI_Window_CloseButton) 00228 ButtonCount++; 00229 } 00230 00231 MinWidth+= pTitleBar->GetHeight() * ButtonCount; 00232 if(NewRect.right - NewRect.left<= MinWidth) 00233 { 00234 SetRect(GetRect()); 00235 return 0; 00236 } 00237 00238 MinHeight+= pTitleBar->GetHeight(); 00239 } 00240 if(pStatusBar !=NULL && pStatusBar->Visible()) 00241 { 00242 if(pStatusBar->GetHeight() < GUI_DEFAULT_STATUSBAR_HEIGHT) 00243 pStatusBar->SetHeight(GUI_DEFAULT_STATUSBAR_HEIGHT); 00244 00245 MinHeight+= pStatusBar->GetHeight(); 00246 } 00247 00248 if((NewRect.top - NewRect.bottom) <= MinHeight) 00249 return CGUIElement::Resize(GetRect()); 00250 00251 tRect NewTitleBarRect, StatusBarRect; 00252 00253 if(pTitleBar !=NULL) 00254 { 00255 NewTitleBarRect.left = GetRect().left; 00256 NewTitleBarRect.right = GetRect().right; 00257 NewTitleBarRect.top = GetRect().top; 00258 NewTitleBarRect.bottom = GetRect().top - pTitleBar->GetHeight(); 00259 00260 pTitleBar->SetRect(NewTitleBarRect); 00261 00262 // Titlebar resized, let's assign its buttons rectangles 00263 if(pTitleBar->GetChildCount() != 0) 00264 { 00265 for (UINT i=0; i<pTitleBar->GetChildCount(); i++) 00266 { 00267 CGUIElement *pChild = pTitleBar->GetChild(i); 00268 if( pChild->GetType() == GUI_Window_MaxRestoreButton || 00269 pChild->GetType() == GUI_Window_MinimizeButton || 00270 pChild->GetType() == GUI_Window_CloseButton) 00271 { 00272 // There must be no border for the button! 00273 pChild->RemoveChild(pChild->GetChild(GUI_Border)); 00274 00275 tRect NewButtonRect; 00276 NewButtonRect.right = GetRect().right - (i) * pTitleBar->GetHeight(); 00277 NewButtonRect.left = GetRect().right - (i + 1) * pTitleBar->GetHeight(); 00278 NewButtonRect.top = pTitleBar->GetRect().top; 00279 NewButtonRect.bottom = pTitleBar->GetRect().bottom; 00280 00281 pChild->SetRect(NewButtonRect); 00282 } 00283 } 00284 } 00285 } 00286 00287 if(pStatusBar !=NULL) 00288 { 00289 StatusBarRect.left = GetRect().left; 00290 StatusBarRect.right = GetRect().right; 00291 StatusBarRect.bottom = GetRect().bottom; 00292 StatusBarRect.top = GetRect().bottom + pStatusBar->GetHeight(); 00293 00294 pStatusBar->SetRect(StatusBarRect); 00295 } 00296 00297 return CGUIElement::Resize(NewRect); 00298 } 00299 00300 void CGUIWindow::ProcessMessage(tGUIMessage& Message) 00301 { 00302 switch(Message.uiMessage) 00303 { 00304 case GUI_Message_MoveX: 00305 case GUI_Message_MoveY: 00306 case GUI_Message_MoveXY: 00307 if(Message.pSender == this) 00308 Resize(GetRect()); 00309 break; 00310 00311 case GUI_Message_ButtonPressed: 00312 { 00313 CGUIElement *pTitleBar = GetChild(GUI_Window_TitleBar); 00314 if(pTitleBar !=NULL) 00315 { 00316 if(pTitleBar->IsChild(Message.pSender)) 00317 { 00318 switch(Message.pSender->GetType()) 00319 { 00320 case GUI_Window_MinimizeButton: 00321 { 00322 if((m_iWindowState == GUI_WindowNormal) || (m_iWindowState ==GUI_WindowMaximized)) 00323 { 00324 if(m_iWindowState !=GUI_WindowMinimized) 00325 Minimize(); 00326 } 00327 else if(m_iWindowState == GUI_WindowMinimized) 00328 Restore(); 00329 00330 break; 00331 } 00332 00333 case GUI_Window_CloseButton: 00334 { 00335 Close(); 00336 break; 00337 } 00338 00339 case GUI_Window_MaxRestoreButton: 00340 { 00341 if(m_iWindowState == GUI_WindowMaximized) 00342 Restore(); 00343 else if(m_iWindowState == GUI_WindowNormal) 00344 Maximize(); 00345 00346 break; 00347 } 00348 } 00349 } 00350 } 00351 break; 00352 } 00353 } 00354 } 00355 00356 void CGUIWindow::Close() 00357 { 00358 Hide(); 00359 HideSiblings(); 00360 } 00361 00362 void CGUIWindow::Restore() 00363 { 00364 SetRect(m_BackupRect); 00365 Resize(GetRect()); 00366 00367 m_iWindowState = GUI_WindowNormal; 00368 00369 CGUIElement *pStatusBar = GetChild(GUI_Window_StatusBar); 00370 if(pStatusBar !=NULL) 00371 { 00372 pStatusBar->Show(); 00373 ((CGUIStatic *)pStatusBar)->ShowText(); 00374 } 00375 00376 CGUIElement *pTitleBar = GetChild(GUI_Window_TitleBar); 00377 if(pTitleBar !=NULL) 00378 { 00379 CGUIButton *pRestoreButton = (CGUIButton *)pTitleBar->GetChild(GUI_Window_MaxRestoreButton); 00380 if(pRestoreButton !=NULL) 00381 pRestoreButton->SetState(false, 0); 00382 } 00383 00384 CGUIBorder *pBorder = (CGUIBorder *)GetChild(GUI_Border); 00385 if(pBorder !=NULL) 00386 pBorder->SetFlag(GUI_Flag_BorderLock, false); 00387 } 00388 00389 void CGUIWindow::Maximize() 00390 { 00391 m_BackupRect = GetRect(); 00392 tRect FullRect = GetGUI()->GetRect(); 00393 00394 SetRect(FullRect); 00395 Resize(GetRect()); 00396 00397 m_iWindowState = GUI_WindowMaximized; 00398 00399 CGUIBorder *pBorder = (CGUIBorder *)GetChild(GUI_Border); 00400 if(pBorder !=NULL) 00401 pBorder->SetFlag(GUI_Flag_BorderLock, false); 00402 } 00403 00404 void CGUIWindow::Minimize() 00405 { 00406 m_BackupRect = GetRect(); 00407 CGUIElement *pTitleBar = GetChild(GUI_Window_TitleBar); 00408 if(pTitleBar !=NULL) 00409 SetHeight(pTitleBar->GetHeight()); 00410 00411 CGUIElement *pStatusBar = GetChild(GUI_Window_StatusBar); 00412 if(pStatusBar !=NULL) 00413 { 00414 pStatusBar->Hide(); 00415 ((CGUIStatic *)pStatusBar)->HideText(); 00416 } 00417 00418 m_iWindowState = GUI_WindowMinimized; 00419 00420 CGUIBorder *pBorder = (CGUIBorder *)GetChild(GUI_Border); 00421 if(pBorder !=NULL) 00422 pBorder->SetFlag(GUI_Flag_BorderLock, true); 00423 00424 Resize(GetRect()); 00425 } 00426 00427 bool CGUIWindow::IsOfType(eEntityType eType) 00428 { 00429 if(eType == Entity_GUIWindow) 00430 return true; 00431 00432 return CGUIElement::IsOfType(eType); 00433 00434 }

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