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

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

00001 #include "StdAfx.h" 00002 #include "GUI.h" 00003 00004 CGUITabControl::CGUITabControl() 00005 { 00006 Initialize(); 00007 } 00008 00009 CGUITabControl::~CGUITabControl() 00010 { 00011 00012 } 00013 00014 void CGUITabControl::Initialize() 00015 { 00016 SetType(GUI_TabControl); 00017 m_strElementType = "TabControl"; 00018 } 00019 00020 int CGUITabControl::Create(CGUIElement *pParent, tRect WidgetRect, UINT uiNumTabs, CGUIButton *pTabButton, CCustomFont *pFont, CTexture *pTexture, CMaterial *pMaterial, bool bBorder) 00021 { 00022 if(!CGUIStatic::Create(pParent, WidgetRect, pFont, pTexture, pMaterial, bBorder)) 00023 return 0; 00024 00025 if(uiNumTabs > 0 && pTabButton !=NULL) 00026 { 00027 if(!IsChild(pTabButton)) 00028 { 00029 pTabButton->SetName(CString("Tab Button")); 00030 pTabButton->SetType(GUI_TabButton); 00031 pTabButton->SetParent(this); 00032 00033 pTabButton->RemoveChild(pTabButton->GetChild(GUI_Border)); 00034 push_back(pTabButton); 00035 } 00036 } 00037 00038 return 1; 00039 } 00040 00041 int CGUITabControl::LoadXML(TiXmlNode *pDataNode, CString strFilename) 00042 { 00043 TiXmlElement* pXMLElement = NULL; 00044 const char *pcValue = NULL; 00045 00046 int iRetValue = CGUIRadioGroup::LoadXML(pDataNode, strFilename); 00047 if(iRetValue !=1) 00048 return iRetValue; 00049 00050 pXMLElement = m_pXMLElement; 00051 00052 CGUIElement *pIterElement = begin(); 00053 set_ptr(pIterElement); 00054 00055 while(pIterElement !=NULL) 00056 { 00057 if(pIterElement->GetType() == GUI_Button) 00058 pIterElement->SetType(GUI_TabButton); 00059 00060 pIterElement = next(); 00061 } 00062 00063 pIterElement = begin(); 00064 set_ptr(pIterElement); 00065 00066 while(pIterElement !=NULL) 00067 { 00068 if(pIterElement->GetType()!= GUI_TabButton && pIterElement->GetType()!= GUI_Border) 00069 { 00070 if(pIterElement->GetID() == GetCurSel()) 00071 { 00072 if(pIterElement->GetType()!= GUI_Element) 00073 ((CGUIStatic *)pIterElement)->ShowText(); 00074 00075 pIterElement->Show(); 00076 } 00077 else 00078 { 00079 if(pIterElement->GetType()!= GUI_Element) 00080 ((CGUIStatic *)pIterElement)->HideText(); 00081 00082 pIterElement->Hide(); 00083 } 00084 00085 } 00086 pIterElement = next(); 00087 } 00088 00089 return iRetValue; 00090 } 00091 00092 int CGUITabControl::SaveXML(TiXmlNode *pDataNode, CString strFilename) 00093 { 00094 // Nowhere to save! Nothing to save! 00095 if(pDataNode == NULL && strFilename == "") 00096 return -1; 00097 00098 char Buf[128] = ""; 00099 TiXmlElement *pSaveXMLElement = NULL; 00100 00101 if(pDataNode != NULL) 00102 pSaveXMLElement = pDataNode->ToElement(); 00103 else 00104 pSaveXMLElement = new TiXmlElement("TabControl"); 00105 00106 int iRetValue = CGUIRadioGroup::SaveXML(pSaveXMLElement, strFilename); 00107 00108 if(pDataNode == NULL) 00109 SAFEDEL(pSaveXMLElement) 00110 00111 return iRetValue; 00112 } 00113 00114 void CGUITabControl::Draw() 00115 { 00116 CGUIStatic::Draw(); 00117 } 00118 00119 void CGUITabControl::ProcessMessage(tGUIMessage& Message) 00120 { 00121 00122 switch(Message.uiMessage) 00123 { 00124 case GUI_Message_ButtonPressed: 00125 { 00126 if(IsChild(Message.pSender) && Message.pSender->GetType() == GUI_TabButton) 00127 { 00128 CGUIButton *pButton = (CGUIButton *)Message.pSender; 00129 pButton->SetState(false, 1); 00130 00131 UINT CurSel = 0; 00132 00133 CGUIElement *pIterElement = begin(); 00134 set_ptr(pIterElement); 00135 00136 while(pIterElement !=NULL) 00137 { 00138 if(pIterElement->GetType() == GUI_TabButton) 00139 { 00140 if(pIterElement !=Message.pSender) 00141 { 00142 ((CGUIButton *)pIterElement)->SetState(false, 0); 00143 CurSel++; 00144 } 00145 else 00146 SetCurSel(CurSel); 00147 } 00148 00149 pIterElement = next(); 00150 } 00151 00152 pIterElement = begin(); 00153 set_ptr(pIterElement); 00154 00155 while(pIterElement !=NULL) 00156 { 00157 if((pIterElement->GetType() != GUI_Border) && (pIterElement->GetType() !=GUI_TabButton)) 00158 { 00159 if(pIterElement->GetID() == GetCurSel()) 00160 { 00161 if(pIterElement->GetType()!= GUI_Element) 00162 ((CGUIStatic *)pIterElement)->ShowText(); 00163 00164 pIterElement->Show(); 00165 } 00166 else 00167 { 00168 if(pIterElement->GetType()!= GUI_Element) 00169 ((CGUIStatic *)pIterElement)->HideText(); 00170 00171 pIterElement->Hide(); 00172 } 00173 } 00174 00175 pIterElement = next(); 00176 } 00177 } 00178 } 00179 break; 00180 } 00181 } 00182 00183 void CGUITabControl::SetCurSel(int uiIndex) 00184 { 00185 if(uiIndex >= 0 && uiIndex < GetChildCount()) 00186 { 00187 m_iCurBtnSel = uiIndex; 00188 00189 CGUIElement *pIterElement = begin(); 00190 set_ptr(pIterElement); 00191 00192 UINT Count = 0; 00193 while(pIterElement !=NULL) 00194 { 00195 if(pIterElement->GetType() == GUI_TabButton) 00196 { 00197 if(Count == uiIndex) 00198 ((CGUIButton *)pIterElement)->SetState(false, 1); 00199 else 00200 ((CGUIButton *)pIterElement)->SetState(false, 0); 00201 00202 Count++; 00203 } 00204 00205 pIterElement = next(); 00206 } 00207 } 00208 else 00209 m_iCurBtnSel = -1; 00210 } 00211 00212 bool CGUITabControl::IsOfType(eEntityType eType) 00213 { 00214 if(eType == Entity_GUITabControl) 00215 return true; 00216 00217 return CGUIRadioGroup::IsOfType(eType); 00218 00219 } 00220 00221 bool CGUITabControl::PropertyChanging( const void* pvProperty , void* pvNewValue ) 00222 { 00223 bool bChangeOK = CGUIRadioGroup::PropertyChanging(pvProperty, pvNewValue); 00224 00225 if(pvProperty == &m_iCurBtnSel) 00226 { 00227 int TempNewValue = *(int *)pvNewValue; 00228 if(TempNewValue == 1000) 00229 { 00230 unsigned int uiCount = 0; 00231 CString strName; 00232 00233 CGUIElement *pIter = begin(); 00234 set_ptr(pIter); 00235 00236 while(pIter !=NULL) 00237 { 00238 if(pIter->GetType() == GUI_TabButton) 00239 uiCount++; 00240 00241 pIter = next(); 00242 } 00243 00244 strName.Format("Tab #%d", uiCount); 00245 CGUIButton *pNewTab = (CGUIButton *)InsertItem(strName); 00246 pNewTab->SetType(GUI_TabButton); 00247 00248 m_iCurBtnSel = -1; 00249 return false; 00250 } 00251 else 00252 SetCurSel(TempNewValue); 00253 } 00254 00255 return bChangeOK; 00256 } 00257 00258 void CGUITabControl::GetProperties( EPropList& PropList ) 00259 { 00260 CGUIRadioGroup::GetProperties(PropList); 00261 }

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