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

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

00001 #include "StdAfx.h" 00002 #include "GUI.h" 00003 00004 CGUIMenuEntry::CGUIMenuEntry() 00005 { 00006 Initialize(); 00007 } 00008 00009 CGUIMenuEntry::~CGUIMenuEntry() 00010 { 00011 Destroy(); 00012 } 00013 00014 void CGUIMenuEntry::Initialize() 00015 { 00016 SetType(GUI_MenuEntry); 00017 m_iHExpand = 0; 00018 m_iVExpand = 0; 00019 m_iCurSel = -1; 00020 m_strElementType = "MenuEntry"; 00021 m_pExpandedChild = NULL; 00022 } 00023 00024 int CGUIMenuEntry::Create(CGUIElement *pParent, tRect WidgetRect, CCustomFont *pFont, CTexture *pTexture, CMaterial *pMaterial, bool bBorder) 00025 { 00026 if(!CGUIButton::Create(pParent, WidgetRect, pFont, pTexture, pMaterial, bBorder)) 00027 return 0; 00028 00029 if(GetType() == GUI_MenuEntry) 00030 RemoveChild(GetChild(GUI_Border)); 00031 return 1; 00032 } 00033 00034 void CGUIMenuEntry::SetExpand(int iHorizontal, int iVertical) 00035 { 00036 m_iHExpand = iHorizontal; 00037 m_iVExpand = iVertical; 00038 } 00039 00040 int CGUIMenuEntry::VExpand() 00041 { 00042 return m_iVExpand; 00043 } 00044 00045 int CGUIMenuEntry::HExpand() 00046 { 00047 return m_iHExpand; 00048 } 00049 00050 CGUIElement *CGUIMenuEntry::InsertItem(CString& strItemText, UINT uiInsertAfter) 00051 { 00052 CGUIMenuEntry *pNewEntry = new CGUIMenuEntry(); 00053 pNewEntry->Create(this, tRect()); 00054 00055 CFileDialog FileDialog(TRUE, NULL, NULL, OFN_HIDEREADONLY|OFN_FILEMUSTEXIST, "XML Files (*.xml)|*.xml|All Files (*.*)|*.*||", AfxGetMainWnd()); 00056 if(FileDialog.DoModal() == IDOK) 00057 { 00058 if(pNewEntry->LoadXML(NULL, GetFullPath(FileDialog.GetPathName()))) 00059 { 00060 pNewEntry->SetText(strItemText); 00061 pNewEntry->GetParent()->Resize(pNewEntry->GetParent()->GetRect()); 00062 pNewEntry->SetExpand(1, 0); 00063 00064 pNewEntry->SetFlag(GUI_Flag_RestrictMovementX, true); 00065 pNewEntry->SetFlag(GUI_Flag_RestrictMovementY, true); 00066 push_front(pNewEntry); 00067 00068 Resize(GetRect()); 00069 return pNewEntry; 00070 } 00071 } 00072 00073 return NULL; 00074 } 00075 00076 int CGUIMenuEntry::LoadXML(TiXmlNode *pDataNode, CString strFilename) 00077 { 00078 TiXmlElement* pXMLElement = NULL; 00079 const char *pcValue = NULL; 00080 00081 int iRetValue = CGUIButton::LoadXML(pDataNode, strFilename); // LoadXML the data of derivative 00082 if(iRetValue !=1) 00083 return iRetValue; 00084 00085 pXMLElement = m_pXMLElement; 00086 00087 pcValue = pXMLElement->Attribute("ExpandX"); 00088 if(pcValue !=NULL) 00089 { 00090 if(stricmp(pcValue, "left") == 0) 00091 m_iHExpand = -1; 00092 else if(stricmp(pcValue,"right") == 0) 00093 m_iHExpand = 1; 00094 else 00095 { 00096 m_iHExpand = atoi(pcValue); 00097 SetAutoCalc(false); 00098 } 00099 00100 pcValue = NULL; 00101 } 00102 else 00103 { 00104 CGlobalLogger::GetSingleton().Write("\t**********General Warning\t**********\n"); 00105 CGlobalLogger::GetSingleton().Write("Menu Entry (Name: %s, ID: %d) doesn't have Horizontal Expansion Path (HExpand) Attribute specified. Assuming default...", GetName(), GetID()); 00106 } 00107 00108 pcValue = pXMLElement->Attribute("ExpandY"); 00109 if(pcValue !=NULL) 00110 { 00111 if(stricmp(pcValue, "up") == 0) 00112 m_iVExpand = 1; 00113 else if(stricmp(pcValue,"down") == 0) 00114 m_iVExpand = -1; 00115 else 00116 { 00117 m_iVExpand = atoi(pcValue); 00118 SetAutoCalc(false); 00119 } 00120 00121 pcValue = NULL; 00122 } 00123 else 00124 { 00125 CGlobalLogger::GetSingleton().Write("\t**********General Warning\t**********\n"); 00126 CGlobalLogger::GetSingleton().Write("Menu Entry (Name: %s, ID: %d) doesn't have Vertical Expansion Path (VExpand) Attribute specified. Assuming default...", GetName(), GetID()); 00127 } 00128 00129 HideSiblings(); 00130 HideSiblingsText(); 00131 00132 00133 return iRetValue; 00134 } 00135 00136 int CGUIMenuEntry::SaveXML(TiXmlNode *pDataNode, CString strFilename) 00137 { 00138 // Nowhere to save! Nothing to save! 00139 if(pDataNode == NULL && strFilename == "") 00140 return -1; 00141 00142 char Buf[128] = ""; 00143 TiXmlElement *pSaveXMLElement = NULL; 00144 00145 if(pDataNode != NULL) 00146 pSaveXMLElement = pDataNode->ToElement(); 00147 else 00148 pSaveXMLElement = new TiXmlElement("MenuEntry"); 00149 00150 if(m_iHExpand == -1) 00151 pSaveXMLElement->SetAttribute("ExpandX", "Left"); 00152 else if(m_iHExpand == 1) 00153 pSaveXMLElement->SetAttribute("ExpandX", "Right"); 00154 00155 if(m_iVExpand == -1) 00156 pSaveXMLElement->SetAttribute("ExpandY", "Down"); 00157 else if(m_iVExpand == 1) 00158 pSaveXMLElement->SetAttribute("ExpandY", "Up"); 00159 00160 int iRetValue = CGUIButton::SaveXML(pSaveXMLElement, strFilename); 00161 00162 if(pDataNode == NULL) 00163 SAFEDEL(pSaveXMLElement) 00164 00165 return iRetValue; 00166 } 00167 00168 void CGUIMenuEntry::HideSiblingsText(int iDeep) 00169 { 00170 CGUIMenuEntry *pIterElement = (CGUIMenuEntry *)begin(); 00171 set_ptr(pIterElement); 00172 00173 while(pIterElement !=NULL) 00174 { 00175 if(pIterElement->GetType() == GUI_MenuEntry) 00176 { 00177 pIterElement->HideText(); 00178 00179 if(iDeep > 0) 00180 pIterElement->HideSiblingsText(iDeep - 1); 00181 else if(iDeep == -1) 00182 pIterElement->HideSiblingsText(iDeep); 00183 else if(iDeep == 0) 00184 return; 00185 } 00186 00187 pIterElement = (CGUIMenuEntry *)next(); 00188 } 00189 } 00190 00191 void CGUIMenuEntry::ShowSiblingsText(int iDeep) 00192 { 00193 CGUIMenuEntry *pIterElement = (CGUIMenuEntry *)begin(); 00194 set_ptr(pIterElement); 00195 00196 while(pIterElement !=NULL) 00197 { 00198 if(pIterElement->GetType() == GUI_MenuEntry) 00199 { 00200 if(iDeep > 0) 00201 { 00202 pIterElement->ShowText(); 00203 pIterElement->ShowSiblingsText(iDeep - 1); 00204 } 00205 else if(iDeep == -1) 00206 { 00207 pIterElement->ShowText(); 00208 pIterElement->ShowSiblingsText(iDeep); 00209 } 00210 else if(iDeep == 0) 00211 return; 00212 } 00213 00214 pIterElement = (CGUIMenuEntry *)next(); 00215 } 00216 } 00217 00218 bool CGUIMenuEntry::PropertyChanging( const void* pvProperty , void* pvNewValue ) 00219 { 00220 bool bChangeOK = CGUIButton::PropertyChanging(pvProperty, pvNewValue); 00221 00222 if(pvProperty == &m_iCurSel) 00223 { 00224 int TempNewValue = *(int *)pvNewValue; 00225 if(TempNewValue == 1000) 00226 { 00227 CGUIElement *pNewItem = InsertItem(CString("New Entry")); 00228 m_iCurSel = -1; 00229 return false; 00230 } 00231 } 00232 00233 if(pvProperty == &m_iHExpand) 00234 { 00235 m_iHExpand = *(int *)pvNewValue; 00236 GetParent()->Resize(GetRect()); 00237 } 00238 00239 if(pvProperty == &m_iVExpand) 00240 { 00241 m_iVExpand = *(int *)pvNewValue; 00242 GetParent()->Resize(GetRect()); 00243 } 00244 00245 return bChangeOK; 00246 } 00247 00248 void CGUIMenuEntry::Expand() 00249 { 00250 ShowSiblings(1); 00251 ShowSiblingsText(1); 00252 } 00253 00254 void CGUIMenuEntry::Draw() 00255 { 00256 CGUIMenuEntry *pIter = (CGUIMenuEntry *)begin(); 00257 set_ptr(pIter); 00258 00259 while(pIter !=NULL) 00260 { 00261 if(pIter->GetType() == GUI_MenuEntry) 00262 { 00263 if(PointInRect(pIter->GetRect(), CInputEngine::GetSingleton().GetMouse()->GetCursorPos().x, 00264 CInputEngine::GetSingleton().GetMouse()->GetCursorPos().y)) 00265 { 00266 if(pIter->GetChildCount() > 0) 00267 { 00268 m_pExpandedChild = pIter; 00269 m_pExpandedChild->Expand(); 00270 } 00271 } 00272 else 00273 { 00274 if(pIter->PointInChildRects()) 00275 { 00276 m_pExpandedChild = pIter; 00277 m_pExpandedChild->Expand(); 00278 } 00279 else 00280 pIter->Collapse(); 00281 } 00282 } 00283 00284 pIter = (CGUIMenuEntry *)next(); 00285 } 00286 00287 CGUIButton::Draw(); 00288 } 00289 00290 int CGUIMenuEntry::Resize(tRect &NewRect) 00291 { 00292 CGUIElement *pIter = begin(); 00293 set_ptr(pIter); 00294 00295 tRect Rect = NewRect; 00296 int iOffsetX = 0; 00297 int iOffsetY = 0; 00298 00299 while(pIter !=NULL) 00300 { 00301 if(pIter->GetType() == GUI_MenuEntry || pIter->GetType() == GUI_Menu) 00302 { 00303 tRect ChildRect; 00304 00305 CGUIMenuEntry *pChild = (CGUIMenuEntry *)pIter; 00306 if(pChild->VExpand() < 0) // Down 00307 { 00308 if(pChild->IsAutoCalc()) 00309 iOffsetY-= Rect.Height(); 00310 else 00311 iOffsetY+= pChild->VExpand(); 00312 } 00313 else if(pChild->VExpand() > 0) // Up 00314 { 00315 if(pChild->IsAutoCalc()) 00316 iOffsetY+= Rect.Height(); 00317 else 00318 iOffsetY+= pChild->VExpand(); 00319 } 00320 00321 if(pChild->HExpand() > 0) // Right 00322 { 00323 if(pChild->IsAutoCalc()) 00324 iOffsetX+= Rect.Width(); 00325 else 00326 iOffsetX+= pChild->HExpand(); 00327 } 00328 else if(pChild->HExpand() < 0) // Left 00329 { 00330 if(pChild->IsAutoCalc()) 00331 iOffsetX-= Rect.Width(); 00332 else 00333 iOffsetX-= pChild->HExpand(); 00334 } 00335 00336 ChildRect.left = Rect.left + iOffsetX; 00337 ChildRect.right = ChildRect.left + Rect.Width(); 00338 ChildRect.top = iOffsetY + Rect.top; 00339 ChildRect.bottom = ChildRect.top - Rect.Height(); 00340 00341 pChild->Resize(ChildRect); 00342 } 00343 00344 pIter = next(); 00345 } 00346 00347 return CGUIButton::Resize(NewRect); 00348 } 00349 00350 void CGUIMenuEntry::Collapse() 00351 { 00352 HideSiblings(); 00353 HideSiblingsText(); 00354 } 00355 00356 const CGUIMenuEntry *CGUIMenuEntry::GetExpanded() 00357 { 00358 return m_pExpandedChild; 00359 } 00360 00361 void CGUIMenuEntry::ProcessMessage(tGUIMessage& Message) 00362 { 00363 switch(Message.uiMessage) 00364 { 00365 case GUI_Message_MoveX: 00366 case GUI_Message_MoveY: 00367 case GUI_Message_MoveXY: 00368 { 00369 if(Message.pSender == GetParent()) 00370 Resize(GetRect()); 00371 break; 00372 } 00373 } 00374 } 00375 00376 bool CGUIMenuEntry::IsOfType(eEntityType eType) 00377 { 00378 if(eType == Entity_GUIMenuEntry) 00379 return true; 00380 00381 return CGUIButton::IsOfType(eType); 00382 } 00383 00384 void CGUIMenuEntry::GetProperties( EPropList& PropList ) 00385 { 00386 CGUIButton::GetProperties(PropList); 00387 00388 PropList.AddPropSeparator(this, "Menu (Entry)"); 00389 EPropertyCombo *pSelectedCombo = PropList.AddPropCombo(this, "Selected", &m_iCurSel); 00390 pSelectedCombo->AddString("New Item...", 1000); 00391 00392 int Count = 0; 00393 CGUIElement *pIter = begin(); 00394 set_ptr(pIter); 00395 00396 while(pIter !=NULL) 00397 { 00398 if(pIter->GetType() == GUI_Button) 00399 { 00400 CString tmp; 00401 tmp.Format("%d", Count); 00402 pSelectedCombo->AddString(tmp, Count); 00403 Count++; 00404 } 00405 00406 pIter = next(); 00407 } 00408 00409 if(!IsAutoCalc()) 00410 { 00411 PropList.AddPropInt(this, "H. Offset", &m_iHExpand)->SetComment("H. Offset"); 00412 PropList.AddPropInt(this, "V. Offset", &m_iVExpand)->SetComment("V. Offset"); 00413 } 00414 00415 else 00416 { 00417 EPropertyCombo *pHExpandCombo = PropList.AddPropCombo(this, "H. Expand", &m_iHExpand); 00418 pHExpandCombo->AddString("Left", -1); 00419 pHExpandCombo->AddString("None", 0); 00420 pHExpandCombo->AddString("Right", 1); 00421 00422 EPropertyCombo *pVExpandCombo = PropList.AddPropCombo(this, "V. Expand", &m_iVExpand); 00423 pVExpandCombo->AddString("Up", 1); 00424 pVExpandCombo->AddString("None", 0); 00425 pVExpandCombo->AddString("Down", -1); 00426 } 00427 } 00428 00429 void CGUIMenuEntry::Destroy() 00430 { 00431 00432 } 00433 00434 bool CGUIMenuEntry::PointInChildRects() 00435 { 00436 UINT x = CInputEngine::GetSingleton().GetMouse()->GetCursorPos().x; 00437 UINT y = CInputEngine::GetSingleton().GetMouse()->GetCursorPos().y; 00438 00439 CGUIElement *pIter = begin(); 00440 set_ptr(pIter); 00441 00442 while(pIter !=NULL) 00443 { 00444 if(pIter->GetType() == GUI_MenuEntry) 00445 { 00446 if(PointInRect(pIter->GetRect(), x, y) && pIter->Visible()) 00447 return true; 00448 else if(((CGUIMenuEntry *)pIter)->PointInChildRects()) 00449 return true; 00450 } 00451 00452 pIter = next(); 00453 } 00454 00455 return false; 00456 }

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