00001
#include "StdAfx.h"
00002
#include "GUI.h"
00003
00004 CGUIBorder::CGUIBorder()
00005 {
00006
SetEntityType(Entity_GUIBorder);
00007
SetType(GUI_Border);
00008
Initialize();
00009 }
00010
00011 CGUIBorder::~CGUIBorder()
00012 {
00013
Destroy();
00014 }
00015
00016 void CGUIBorder::Initialize()
00017 {
00018 m_iBorderWidth = 0;
00019 m_iBorderSpacing = 1;
00020 m_uiDragElement = -1;
00021 m_strElementType =
"Border";
00022 }
00023
00024 int CGUIBorder::Create(
CGUIElement *pParent)
00025 {
00026
if(pParent == NULL)
00027
return 0;
00028
00029
return CGUIElement::Create(pParent,
GetRect());
00030 }
00031
00032 void CGUIBorder::Draw()
00033 {
00034
CGUIElement::Draw();
00035 }
00036
00037 int CGUIBorder::LoadXML(
TiXmlNode *pDataNode, CString strFilename)
00038 {
00039
TiXmlElement* pXMLElement = NULL;
00040
const char *pcValue = NULL;
00041
00042
int iRetValue =
CGUIElement::LoadXML(pDataNode, strFilename);
00043
if(iRetValue !=1)
00044
return iRetValue;
00045
00046 pXMLElement = m_pXMLElement;
00047
00048 pcValue = pXMLElement->
Attribute(
"Width");
00049
if(pcValue !=NULL)
00050 {
00051
SetBorderWidth((UINT)atoi(pcValue));
00052 pcValue = NULL;
00053 }
00054
else
00055 {
00056
CGlobalLogger::GetSingleton().
Write(
"\n\t\t**********General Warning**********\n");
00057
CGlobalLogger::GetSingleton().
Write(
"Border (Name: %s, ID: %d) doesn't have Width Attribute (Width) specified. Assuming default...",
GetName(),
GetID());
00058 }
00059
00060 pcValue = pXMLElement->
Attribute(
"Spacing");
00061
if(pcValue !=NULL)
00062 {
00063
SetBorderSpacing((UINT)atoi(pcValue));
00064 pcValue = NULL;
00065 }
00066
else
00067 {
00068
CGlobalLogger::GetSingleton().
Write(
"\t**********General Warning\t**********\n");
00069
CGlobalLogger::GetSingleton().
Write(
"Border (Name: %s, ID: %d) doesn't have Spacing Attribute (Spacing) specified. Assuming default...",
GetName(),
GetID());
00070 }
00071
00072
return 1;
00073 }
00074
00075 int CGUIBorder::SaveXML(
TiXmlNode *pDataNode, CString strFilename)
00076 {
00077
00078
if(pDataNode == NULL && strFilename ==
"")
00079
return -1;
00080
00081
char Buf[128] =
"";
00082
TiXmlElement *pSaveXMLElement = NULL;
00083
00084
if(pDataNode != NULL)
00085 pSaveXMLElement = pDataNode->
ToElement();
00086
else
00087 pSaveXMLElement =
new TiXmlElement(
"Border");
00088
00089
if(
GetFilename() !=
"")
00090 pSaveXMLElement->
SetAttribute(
"strFilename", GetRelPath(
GetFilename()));
00091
00092
if(pDataNode == NULL)
00093 SAFEDEL(pSaveXMLElement)
00094
00095
return 1;
00096 }
00097
00098 int CGUIBorder::Resize(tRect& NewRect)
00099 {
00100
00101 tRect BorderRectangle[8];
00102
00103 tRect RefRect;
00104
if(
GetParent() !=NULL)
00105 RefRect =
GetParent()->
GetRect();
00106
else
00107 RefRect = NewRect;
00108
00109 BorderRectangle[0].left = RefRect.left - m_iBorderWidth - m_iBorderSpacing;
00110 BorderRectangle[0].right = RefRect.left - m_iBorderSpacing;
00111 BorderRectangle[0].top = RefRect.top + m_iBorderSpacing;
00112 BorderRectangle[0].bottom = RefRect.bottom - m_iBorderSpacing;
00113
00114
00115 BorderRectangle[1].left = RefRect.right + m_iBorderSpacing;
00116 BorderRectangle[1].right = RefRect.right + m_iBorderWidth + m_iBorderSpacing;
00117 BorderRectangle[1].top = RefRect.top + m_iBorderSpacing;
00118 BorderRectangle[1].bottom = RefRect.bottom - m_iBorderSpacing;
00119
00120
00121 BorderRectangle[2].left = RefRect.left - m_iBorderSpacing;
00122 BorderRectangle[2].right = RefRect.right + m_iBorderSpacing;
00123 BorderRectangle[2].top = RefRect.top + m_iBorderWidth + m_iBorderSpacing;
00124 BorderRectangle[2].bottom = RefRect.top + m_iBorderSpacing;
00125
00126
00127 BorderRectangle[3].left = RefRect.left - m_iBorderSpacing;
00128 BorderRectangle[3].right = RefRect.right + m_iBorderSpacing;
00129 BorderRectangle[3].top = RefRect.bottom - m_iBorderSpacing;
00130 BorderRectangle[3].bottom = RefRect.bottom - m_iBorderWidth - m_iBorderSpacing;
00131
00132
00133 BorderRectangle[4].left = BorderRectangle[0].left;
00134 BorderRectangle[4].right = BorderRectangle[0].right;
00135 BorderRectangle[4].top = BorderRectangle[0].top + m_iBorderWidth;
00136 BorderRectangle[4].bottom = BorderRectangle[0].top;
00137
00138
00139 BorderRectangle[5].left = BorderRectangle[1].left;
00140 BorderRectangle[5].right = BorderRectangle[1].right;
00141 BorderRectangle[5].top = BorderRectangle[1].top + m_iBorderWidth;
00142 BorderRectangle[5].bottom = BorderRectangle[1].top;
00143
00144
00145 BorderRectangle[6].left = BorderRectangle[0].left;
00146 BorderRectangle[6].right = BorderRectangle[0].right;
00147 BorderRectangle[6].top = BorderRectangle[0].bottom;
00148 BorderRectangle[6].bottom = BorderRectangle[0].bottom - m_iBorderWidth;
00149
00150
00151 BorderRectangle[7].left = BorderRectangle[1].left;
00152 BorderRectangle[7].right = BorderRectangle[1].right;
00153 BorderRectangle[7].top = BorderRectangle[1].bottom;
00154 BorderRectangle[7].bottom = BorderRectangle[1].bottom - m_iBorderWidth;
00155
00156
for (
int i=0; i<8; i++)
00157 {
00158
if(
at(i) !=NULL)
00159
at(i)->
SetRect(BorderRectangle[i]);
00160 }
00161
00162
return 1;
00163 }
00164
00165 int CGUIBorder::OnLMouseDown(UINT x, UINT y)
00166 {
00167
00168
00169 UINT Count = 0;
00170
CGUIElement *pIterElement =
begin();
00171
set_ptr(pIterElement);
00172
00173
while(pIterElement !=NULL)
00174 {
00175
if(pIterElement->
GetType() == GUI_Element)
00176 {
00177
if(pIterElement->
OnLMouseDown(x, y) == 1)
00178 {
00179 m_uiDragElement = Count;
00180
return 1;
00181 }
00182 }
00183
00184 Count++;
00185 pIterElement =
next();
00186 }
00187
00188
return CGUIElement::OnLMouseDown(x, y);
00189 }
00190
00191 int CGUIBorder::OnLMouseUp(UINT x, UINT y)
00192 {
00193
00194 m_uiDragElement = -1;
00195
return CGUIElement::OnLMouseUp(x, y);
00196 }
00197
00198 int CGUIBorder::OnMouseMove(UINT x, UINT y)
00199 {
00200
00201
if(m_uiDragElement !=-1)
00202 {
00203
00204
CGUIElement *pDragElement =
at(m_uiDragElement);
00205 tRect oldRect = pDragElement->
GetRect();
00206 tRect oldParentRect =
GetParent()->
GetRect();
00207
00208
CGUIElement::OnMouseMove(x, y);
00209
00210
00211
00212
00213 tRect newRect = pDragElement->
GetRect();
00214 tRect DiffRect;
00215 DiffRect.left = newRect.left - oldRect.left;
00216 DiffRect.right = newRect.right - oldRect.right;
00217 DiffRect.top = newRect.top - oldRect.top;
00218 DiffRect.bottom = newRect.bottom - oldRect.bottom;
00219
00220 tRect newParentRect = oldParentRect;
00221
00222
00223
00224
00225
if(m_uiDragElement == 0 || m_uiDragElement == 4 || m_uiDragElement == 6)
00226 newParentRect.left =
GetParent()->
GetRect().left + DiffRect.left;
00227
00228
00229
if(m_uiDragElement == 1 || m_uiDragElement == 5 || m_uiDragElement == 7)
00230 newParentRect.right =
GetParent()->
GetRect().right + DiffRect.right;
00231
00232
00233
if(m_uiDragElement == 2 || m_uiDragElement == 4 || m_uiDragElement == 5)
00234 newParentRect.top =
GetParent()->
GetRect().top + DiffRect.top;
00235
00236
00237
if(m_uiDragElement == 3 || m_uiDragElement == 6 || m_uiDragElement == 7)
00238 newParentRect.bottom =
GetParent()->
GetRect().bottom + DiffRect.bottom;
00239
00240
00241
if(!
GetParent()->
Resize(newParentRect))
00242
return Resize(oldParentRect);
00243
else
00244
return Resize(newParentRect);
00245 }
00246
00247
return 0;
00248 }
00249
00250 void CGUIBorder::SetBorderWidth(UINT uiWidth)
00251 {
00252 m_iBorderWidth = uiWidth;
00253 }
00254
00255 UINT
CGUIBorder::GetBorderWidth()
00256 {
00257
00258
return m_iBorderWidth;
00259 }
00260
00261 void CGUIBorder::SetBorderSpacing(UINT uiSpacing)
00262 {
00263 m_iBorderSpacing = uiSpacing;
00264 }
00265
00266 UINT
CGUIBorder::GetBorderSpacing()
00267 {
00268
return m_iBorderSpacing;
00269 }
00270
00271 void CGUIBorder::ProcessMessage(
tGUIMessage& Message)
00272 {
00273
switch(Message.uiMessage)
00274 {
00275
case GUI_Message_MoveX:
00276
case GUI_Message_MoveY:
00277
case GUI_Message_MoveXY:
00278
case GUI_Message_SizeX:
00279
case GUI_Message_SizeY:
00280
case GUI_Message_SizeXY:
00281 {
00282
if(Message.
pSender ==
GetParent())
00283
Resize(
GetParent()->
GetRect());
00284
00285
break;
00286 }
00287 }
00288 }
00289
00290 bool CGUIBorder::IsOfType(eEntityType eType)
00291 {
00292
if(eType == Entity_GUIBorder)
00293
return true;
00294
00295
return CGUIElement::IsOfType(eType);
00296 }
00297
00298 bool CGUIBorder::PropertyChanging(
const void* pvProperty ,
void* pvNewValue )
00299 {
00300
bool bChangeOK =
CGUIElement::PropertyChanging(pvProperty, pvNewValue);
00301
00302
return bChangeOK;
00303 }
00304
00305 void CGUIBorder::GetProperties( EPropList& PropList )
00306 {
00307
if(m_uiDragElement !=-1)
00308
GetChild(m_uiDragElement)->
GetProperties(PropList);
00309
00310 PropList.AddTab(
"Border");
00311 PropList.AddPropInt(
this,
"Width", &m_iBorderWidth,
"",
true)->SetComment(
"Border' Width");
00312 PropList.AddPropInt(
this,
"Spacing", &m_iBorderSpacing,
"",
true)->SetComment(
"Border' Spacing from parent element");
00313 }