00001
#include "StdAfx.h"
00002
#include "GUI.h"
00003
00004 CGUIRadioGroup::CGUIRadioGroup()
00005 {
00006
SetEntityType(Entity_GUIRadioGroup);
00007
Initialize();
00008 }
00009
00010 CGUIRadioGroup::~CGUIRadioGroup()
00011 {
00012
Destroy();
00013 }
00014
00015 void CGUIRadioGroup::Initialize()
00016 {
00017
SetType(GUI_RadioGroup);
00018
m_iCurBtnSel = -1;
00019
00020 m_strElementType =
"RadioGroup";
00021 }
00022
00023 int CGUIRadioGroup::Create(
CGUIElement *pParent, tRect WidgetRect,
CCustomFont *pFont,
CTexture *pTexture,
CMaterial *pMaterial,
bool bBorder)
00024 {
00025
return CGUIStatic::Create(pParent, WidgetRect, pFont, pTexture, pMaterial, bBorder);
00026 }
00027
00028 int CGUIRadioGroup::LoadXML(
TiXmlNode *pDataNode, CString strFilename)
00029 {
00030
TiXmlElement* pXMLElement = NULL;
00031
const char *pcValue = NULL;
00032
00033
int iRetValue =
CGUIStatic::LoadXML(pDataNode, strFilename);
00034
if(iRetValue !=1)
00035
return iRetValue;
00036
00037 pXMLElement = m_pXMLElement;
00038
00039 pcValue = pXMLElement->
Attribute(
"CurSel");
00040
if(pcValue !=NULL)
00041 {
00042
SetCurSel(atoi(pcValue));
00043 pcValue = NULL;
00044 }
00045
else
00046 {
00047
CGlobalLogger::GetSingleton().
Write(
"\t**********General Warning\t**********\n");
00048
CGlobalLogger::GetSingleton().
Write(
"RadioGroup (Name: %s, ID: %d) doesn't have Current iSelection (CurSel) Attribute specified. Assuming default...",
GetName(),
GetID());
00049 }
00050
00051
return iRetValue;
00052 }
00053
00054 int CGUIRadioGroup::SaveXML(
TiXmlNode *pDataNode, CString strFilename)
00055 {
00056
00057
if(pDataNode == NULL && strFilename ==
"")
00058
return -1;
00059
00060
char Buf[128] =
"";
00061
TiXmlElement *pSaveXMLElement = NULL;
00062
00063
if(pDataNode != NULL)
00064 pSaveXMLElement = pDataNode->
ToElement();
00065
else
00066 pSaveXMLElement =
new TiXmlElement(
"RadioGroup");
00067
00068 pSaveXMLElement->
SetAttribute(
"CurSel",
m_iCurBtnSel);
00069
00070
int iRetValue =
CGUIElement::SaveXML(pSaveXMLElement, strFilename);
00071
00072
if(pDataNode == NULL)
00073 SAFEDEL(pSaveXMLElement)
00074
00075
return iRetValue;
00076 }
00077
00078 void CGUIRadioGroup::Draw()
00079 {
00080
if(!
Visible())
00081
return;
00082
00083
00084
HideSiblings();
00085
CGUIStatic::Draw();
00086
ShowSiblings();
00087
00088
CGUIElement *pIterElement =
begin();
00089
set_ptr(pIterElement);
00090
00091
while(pIterElement !=NULL)
00092 {
00093
if(pIterElement->
GetType() == GUI_Button || pIterElement->
GetType() == GUI_Border)
00094 pIterElement->
Draw();
00095
00096 pIterElement =
next();
00097 }
00098 }
00099
00100 void CGUIRadioGroup::SetCurSel(
int uiIndex)
00101 {
00102
if(uiIndex >= 0 && uiIndex <
GetChildCount())
00103 {
00104
m_iCurBtnSel = uiIndex;
00105
00106
CGUIElement *pIterElement =
begin();
00107
set_ptr(pIterElement);
00108
00109 UINT Count = 0;
00110
while(pIterElement !=NULL)
00111 {
00112
if(pIterElement->
GetType() == GUI_Button)
00113 {
00114
if(Count == uiIndex)
00115 ((
CGUIButton *)pIterElement)->SetState(
false, 1);
00116
else
00117 ((
CGUIButton *)pIterElement)->SetState(
false, 0);
00118
00119 Count++;
00120 }
00121
00122 pIterElement =
next();
00123 }
00124 }
00125
else
00126
m_iCurBtnSel = -1;
00127 }
00128
00129 void CGUIRadioGroup::ProcessMessage(
tGUIMessage& Message)
00130 {
00131
switch(Message.uiMessage)
00132 {
00133
case GUI_Message_ButtonPressed:
00134 {
00135 UINT Count = 0;
00136
CGUIElement *pIterElement =
begin();
00137
set_ptr(pIterElement);
00138
00139
while(pIterElement !=NULL)
00140 {
00141
if(pIterElement->
GetType() == GUI_Button)
00142 {
00143
if((pIterElement == Message.
pSender))
00144 {
00145
SetCurSel(Count);
00146
return;
00147 }
00148
00149 Count++;
00150 }
00151
00152 pIterElement =
next();
00153 }
00154
00155
break;
00156 }
00157 }
00158 }
00159
00160 int CGUIRadioGroup::GetCurSel()
00161 {
00162
return m_iCurBtnSel;
00163 }
00164
00165 CGUIElement *
CGUIRadioGroup::InsertItem(CString& strItemText, UINT uiInsertAfter)
00166 {
00167
CGUIButton *pNewEntry =
new CGUIButton();
00168 pNewEntry->
Create(
this, tRect());
00169
00170 CFileDialog FileDialog(TRUE, NULL, NULL, OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,
"XML Files (*.xml)|*.xml|All Files (*.*)|*.*||", AfxGetMainWnd());
00171
if(FileDialog.DoModal() == IDOK)
00172 {
00173
if(pNewEntry->
LoadXML(NULL, GetFullPath(FileDialog.GetPathName())))
00174 {
00175 pNewEntry->
SetText(strItemText);
00176
push_back(pNewEntry);
00177
00178
Resize(
GetRect());
00179
00180
return pNewEntry;
00181 }
00182 }
00183
00184
return NULL;
00185 }
00186
00187 bool CGUIRadioGroup::IsOfType(eEntityType eType)
00188 {
00189
if(eType == Entity_GUIRadioGroup)
00190
return true;
00191
00192
return CGUIStatic::IsOfType(eType);
00193 }
00194
00195 bool CGUIRadioGroup::PropertyChanging(
const void* pvProperty ,
void* pvNewValue )
00196 {
00197
bool bChangeOK =
CGUIStatic::PropertyChanging(pvProperty, pvNewValue);
00198
00199
if(pvProperty == &
m_iCurBtnSel)
00200 {
00201
int TempNewValue = *(
int *)pvNewValue;
00202
if(TempNewValue == 1000)
00203 {
00204
CGUIElement *pNewItem =
InsertItem(CString(
"New Entry"));
00205
m_iCurBtnSel = -1;
00206
return false;
00207 }
00208
else
00209
SetCurSel(TempNewValue);
00210 }
00211
00212
return bChangeOK;
00213 }
00214
00215 void CGUIRadioGroup::GetProperties( EPropList& PropList )
00216 {
00217
CGUIStatic::GetProperties(PropList);
00218
00219 PropList.AddTab(
"RadioGroup");
00220 EPropertyCombo *pSelectedCombo = PropList.AddPropCombo(
this,
"Selected", &
m_iCurBtnSel);
00221 pSelectedCombo->AddString(
"New Item...", 1000);
00222
00223
int Count = 0;
00224
CGUIElement *pIter =
begin();
00225
set_ptr(pIter);
00226
00227
while(pIter !=NULL)
00228 {
00229
if(pIter->
GetType() == GUI_Button)
00230 {
00231 CString tmp;
00232 tmp.Format(
"%d", Count);
00233 pSelectedCombo->AddString(tmp, Count);
00234 Count++;
00235 }
00236
00237 pIter =
next();
00238 }
00239 }