00001
#include "StdAfx.h"
00002
#include "GUI.h"
00003
00004 CGUIElement::CGUIElement()
00005 {
00006
SetEntityType(Entity_GUIElement);
00007
Initialize();
00008
m_pParent = NULL;
00009
00010
m_strElementType =
"Element";
00011
m_iMaterialIndex =
m_iTextureIndex = 1000;
00012
m_iMaterialShininess = 0;
00013
SetType(GUI_Element);
00014
m_pTexture = NULL;
00015
m_pMaterial = NULL;
00016 }
00017
00018 CGUIElement::~CGUIElement()
00019 {
00020
Destroy();
00021 }
00022
00023 void CGUIElement::Initialize()
00024 {
00025
m_pGUI = NULL;
00026
m_dwFlags = 0;
00027
m_pMaterial = NULL;
00028
m_pTexture = NULL;
00029
00030
m_TexCoord[0].
x = 0;
00031
m_TexCoord[0].
y = 1;
00032
00033
m_TexCoord[1].
x = 1;
00034
m_TexCoord[1].
y = 1;
00035
00036
m_TexCoord[2].
x = 1;
00037
m_TexCoord[2].
y = 0;
00038
00039
m_TexCoord[3].
x = 0;
00040
m_TexCoord[3].
y = 0;
00041
00042
m_bAutoCalc =
m_bAllowSizeX =
m_bAllowSizeY =
m_bAllowMoveX =
m_bAllowMoveY =
true;
00043
m_bVisible =
true;
00044 }
00045
00046 int CGUIElement::Create(
CGUIElement *pParent, tRect WidgetRect,
CTexture *pTexture,
CMaterial *pMaterial,
bool bBorder)
00047 {
00048
if(pParent == NULL)
00049
return 0;
00050
00051
SetParent(pParent);
00052
SetRect(WidgetRect);
00053
00054
if(
m_pTexture == NULL && pTexture !=NULL)
00055
m_pTexture = pTexture;
00056
00057
if(
m_pMaterial == NULL && pMaterial !=NULL)
00058
m_pMaterial = pMaterial;
00059
00060
if(
GetGUI() !=NULL)
00061 {
00062
00063
00064 }
00065
00066
return 1;
00067 }
00068
00069 int CGUIElement::LoadXML(
TiXmlNode *pDataNode, CString strFilename)
00070 {
00071
TiXmlElement* pXMLElement = NULL;
00072
const char *pcValue = NULL;
00073
00074
int iRetValue =
CXMLResource::LoadXML(pDataNode, strFilename);
00075
if(iRetValue !=1)
00076
return iRetValue;
00077
00078 pXMLElement = m_pXMLElement;
00079
00080 pcValue = pXMLElement->
Attribute(
"Rect");
00081
if(pcValue !=NULL)
00082 {
00083 sscanf(pcValue,
"%d,%d,%d,%d", &
m_Rect.left, &
m_Rect.right, &
m_Rect.top, &
m_Rect.bottom);
00084 pcValue = NULL;
00085 }
00086
else
00087 {
00088 pcValue = pXMLElement->
Attribute(
"XPos");
00089
if(pcValue !=NULL)
00090 {
00091
m_Rect.left = atoi(pcValue);
00092 pcValue = NULL;
00093 }
00094
else
00095 {
00096
CGlobalLogger::GetSingleton().
Write(
"\n\t\t!!!!!!!!!!General Error!!!!!!!!!!!!\n");
00097
CGlobalLogger::GetSingleton().
Write(
"Element (Type: %s, Name: %s, ID: %d) doesn't have Rectangle X Position in absence of \"Rect\" Attribute.",
m_strElementType,
GetName(),
GetID());
00098 }
00099
00100 pcValue = pXMLElement->
Attribute(
"YPos");
00101
if(pcValue !=NULL)
00102 {
00103
m_Rect.top = atoi(pcValue);
00104 pcValue = NULL;
00105 }
00106
else
00107 {
00108
CGlobalLogger::GetSingleton().
Write(
"\n\t\t!!!!!!!!!!General Error!!!!!!!!!!!!\n");
00109
CGlobalLogger::GetSingleton().
Write(
"Element (Type: %s, Name: %s, ID: %d) doesn't have Rectangle Y Position in absence of \"Rect\" Attribute.",
m_strElementType,
GetName(),
GetID());
00110 }
00111
00112 pcValue = pXMLElement->
Attribute(
"Width");
00113
if(pcValue !=NULL)
00114 {
00115
m_Rect.right =
m_Rect.left + atoi(pcValue);
00116 pcValue = NULL;
00117 }
00118
else
00119 {
00120
CGlobalLogger::GetSingleton().
Write(
"\n\t\t!!!!!!!!!!General Error!!!!!!!!!!!!\n");
00121
CGlobalLogger::GetSingleton().
Write(
"Element (Type: %s, Name: %s, ID: %d) doesn't have Width Attribute in absence of \"Rect\" Attribute.",
m_strElementType,
GetName(),
GetID());
00122 }
00123
00124 pcValue = pXMLElement->
Attribute(
"Height");
00125
if(pcValue !=NULL)
00126 {
00127
m_Rect.bottom =
m_Rect.top - atoi(pcValue);
00128 pcValue = NULL;
00129 }
00130
else
00131 {
00132
CGlobalLogger::GetSingleton().
Write(
"\n\t\t!!!!!!!!!!General Error!!!!!!!!!!!!\n");
00133
CGlobalLogger::GetSingleton().
Write(
"Element (Type: %s, Name: %s, ID: %d) doesn't have Height Attribute in absence of \"Rect\" Attribute.",
m_strElementType,
GetName(),
GetID());
00134 }
00135 }
00136
00137 pcValue = pXMLElement->
Attribute(
"MovementFlags");
00138
if(pcValue !=NULL)
00139 {
00140
int RestrictX = 0, RestrictY = 0;
00141 sscanf(pcValue,
"%d,%d", &RestrictX, &RestrictY);
00142
00143
if(RestrictX)
00144 {
00145
m_bAllowMoveX =
false;
00146
m_dwFlags &= GUI_Flag_RestrictMovementX;
00147 }
00148
00149
if(RestrictY)
00150 {
00151
m_bAllowMoveY =
false;
00152
m_dwFlags &= GUI_Flag_RestrictMovementY;
00153 }
00154
00155 pcValue = NULL;
00156 }
00157
00158 pcValue = pXMLElement->
Attribute(
"ResizeFlags");
00159
if(pcValue !=NULL)
00160 {
00161
int ResizeX = 0, ResizeY = 0;
00162 sscanf(pcValue,
"%d,%d", &ResizeX, &ResizeY);
00163
00164
if(ResizeX)
00165 {
00166
m_bAllowSizeX =
false;
00167
m_dwFlags &= GUI_Flag_RestrictSizeX;
00168 }
00169
00170
if(ResizeY)
00171 {
00172
m_bAllowSizeY =
false;
00173
m_dwFlags &= GUI_Flag_RestrictSizeY;
00174 }
00175
00176 pcValue = NULL;
00177 }
00178
00179 pcValue = pXMLElement->
Attribute(
"UV");
00180
if(pcValue !=NULL)
00181 {
00182 sscanf(pcValue,
"(%f,%f),(%f,%f),(%f,%f),(%f,%f)",
00183 &
m_TexCoord[0].x, &
m_TexCoord[0].y,
00184 &
m_TexCoord[1].x, &
m_TexCoord[1].y,
00185 &
m_TexCoord[2].x, &
m_TexCoord[2].y,
00186 &
m_TexCoord[3].x, &
m_TexCoord[3].y);
00187
00188 pcValue = NULL;
00189 }
00190
00191
CTexture *pNewTexture =
CTextureManager::GetSingleton().
LoadResource(m_pXMLElement,
"");
00192
if(pNewTexture !=NULL)
00193
m_pTexture = pNewTexture;
00194
00195
CMaterial *pNewMaterial =
CMaterialManager::GetSingleton().
LoadResource(m_pXMLElement,
"");
00196
if(pNewMaterial !=NULL)
00197
m_pMaterial = pNewMaterial;
00198
00199
00200 UINT WidgetCount = 0;
00201
TiXmlNode *pIterXMLNode = pXMLElement->
FirstChild();
00202
while(pIterXMLNode !=NULL)
00203 {
00204
CGUIElement *NewWidget = NULL;
00205
if(stricmp(pIterXMLNode->
pcValue(),
"Element") == 0)
00206 NewWidget =
new CGUIElement;
00207
else if(stricmp(pIterXMLNode->
pcValue(),
"Border") == 0)
00208 NewWidget =
new CGUIBorder;
00209
else if(stricmp(pIterXMLNode->
pcValue(),
"Element") == 0)
00210 NewWidget =
new CGUIElement;
00211
else if(stricmp(pIterXMLNode->
pcValue(),
"Static") == 0)
00212 NewWidget =
new CGUIStatic;
00213
else if(stricmp(pIterXMLNode->
pcValue(),
"TextBox") == 0)
00214 NewWidget =
new CGUITextBox;
00215
else if(stricmp(pIterXMLNode->
pcValue(),
"Button") == 0)
00216 NewWidget =
new CGUIButton;
00217
else if(stricmp(pIterXMLNode->
pcValue(),
"ScrollBar") == 0)
00218 NewWidget =
new CGUIScrollBar;
00219
else if(stricmp(pIterXMLNode->
pcValue(),
"ProgressBar") == 0)
00220 NewWidget =
new CGUIProgressBar;
00221
else if(stricmp(pIterXMLNode->
pcValue(),
"DropList") == 0)
00222 NewWidget =
new CGUIDropList;
00223
else if(stricmp(pIterXMLNode->
pcValue(),
"RadioGroup") == 0)
00224 NewWidget =
new CGUIRadioGroup;
00225
else if(stricmp(pIterXMLNode->
pcValue(),
"ListBox") == 0)
00226 NewWidget =
new CGUIListBox;
00227
else if(stricmp(pIterXMLNode->
pcValue(),
"MenuEntry") == 0)
00228 NewWidget =
new CGUIMenuEntry;
00229
else if(stricmp(pIterXMLNode->
pcValue(),
"Menu") == 0)
00230 NewWidget =
new CGUIMenu;
00231
else if(stricmp(pIterXMLNode->
pcValue(),
"TabControl") == 0)
00232 NewWidget =
new CGUITabControl;
00233
else if(stricmp(pIterXMLNode->
pcValue(),
"Window") == 0)
00234 NewWidget =
new CGUIWindow;
00235
00236
00237
if(NewWidget !=NULL)
00238 {
00239 NewWidget->
SetParent(
this);
00240
00241
if(NewWidget->
LoadXML(pIterXMLNode,
""))
00242 {
00243
push_back(NewWidget);
00244 WidgetCount++;
00245 }
00246 }
00247
00248 pIterXMLNode = pXMLElement->
IterateChildren(pIterXMLNode);
00249 }
00250
00251
Resize(
m_Rect);
00252
return 1;
00253 }
00254
00255 int CGUIElement::SaveXML(
TiXmlNode *pDataNode, CString strFilename)
00256 {
00257
00258
if(pDataNode == NULL && strFilename ==
"")
00259
return -1;
00260
00261
char Buf[128] =
"";
00262
TiXmlElement *pSaveXMLElement = NULL;
00263
00264
if(pDataNode != NULL)
00265 pSaveXMLElement = pDataNode->
ToElement();
00266
else
00267 pSaveXMLElement =
new TiXmlElement(
"Element");
00268
00269
00270
if(
GetParent() !=NULL)
00271 {
00272
if(
GetParent()->
GetType() !=GUI_Border)
00273 {
00274
if(!(
m_Rect.left == 0 &&
m_Rect.right == 0 &&
m_Rect.top == 0 &&
m_Rect.bottom == 0))
00275 {
00276 sprintf(Buf,
"%i,%i,%i,%i",
m_Rect.left,
m_Rect.right,
m_Rect.top,
m_Rect.bottom);
00277 pSaveXMLElement->
SetAttribute(
"Rect", Buf);
00278
00279 memset(Buf, 0,
sizeof(
char) * 128);
00280 }
00281 }
00282 }
00283
00284
if(
GetName() !=
"")
00285 pSaveXMLElement->
SetAttribute(
"strName",
GetName());
00286
00287 pSaveXMLElement->
SetAttribute(
"Visible", (
int)
Visible());
00288
00289
if(
GetID() !=0)
00290 {
00291 sprintf((
char *)Buf,
"%d",
GetID());
00292 pSaveXMLElement->
SetAttribute(
"uiID", Buf);
00293
00294 memset(Buf, 0,
sizeof(
char) * 128);
00295 }
00296
00297 memset(Buf, 0,
sizeof(
char) * 128);
00298
00299 sprintf(Buf,
"%d,%d", (
int)!
m_bAllowMoveX, (
int)!
m_bAllowMoveY);
00300 pSaveXMLElement->
SetAttribute(
"MovementFlags", (
char *)Buf);
00301
00302 sprintf(Buf,
"%d,%d", (
int)!
m_bAllowSizeX, (
int)!
m_bAllowSizeY);
00303 pSaveXMLElement->
SetAttribute(
"ResizeFlags", (
char *)Buf);
00304
00305 memset(Buf, 0,
sizeof(
char) * 128);
00306
00307
#ifdef GUI_USE_ACTIVE_INACTIVE
00308
00309
if(
m_ActiveColor != GUI_DEFAULT_ACTIVE_COLOR)
00310 {
00311 sprintf(Buf,
"%d,%d,%d",
m_ActiveColor.r,
m_ActiveColor.g,
m_ActiveColor.b);
00312 pSaveXMLElement->
SetAttribute(
"ActiveColor", Buf);
00313 }
00314
00315
if(
m_InactiveColor !=GUI_DEFAULT_INACTIVE_COLOR)
00316 {
00317 memset(Buf, 0,
sizeof(
char) * 128);
00318 sprintf(Buf,
"%d,%d,%d",
m_InactiveColor.r,
m_InactiveColor.g,
m_InactiveColor.b);
00319 pSaveXMLElement->
SetAttribute(
"InactiveColor", Buf);
00320 }
00321
#else
00322
if(
m_pMaterial !=NULL)
00323 pSaveXMLElement->
SetAttribute(
"MatByName",
m_pMaterial->
GetName());
00324
#endif
00325
00326
if(
m_pTexture !=NULL)
00327 pSaveXMLElement->
SetAttribute(
"TexByName",
m_pTexture->
GetName());
00328
00329
if((
m_TexCoord[0].
x !=0 &&
m_TexCoord[0].
y !=1) &&
00330 (
m_TexCoord[1].
x !=1 &&
m_TexCoord[1].
y !=1) &&
00331 (
m_TexCoord[2].
x !=1 &&
m_TexCoord[2].
y !=0) &&
00332 (
m_TexCoord[3].
x !=0 &&
m_TexCoord[3].
y !=0))
00333 {
00334 sprintf(Buf,
"(%f,%f),(%f,%f),(%f,%f),(%f,%f)",
00335
m_TexCoord[0].x,
m_TexCoord[0].y,
00336
m_TexCoord[1].x,
m_TexCoord[1].y,
00337
m_TexCoord[2].x,
m_TexCoord[2].y,
00338
m_TexCoord[3].x,
m_TexCoord[3].y);
00339
00340 pSaveXMLElement->
SetAttribute(
"UV", Buf);
00341
00342 memset(Buf, 0,
sizeof(
char) * 128);
00343 }
00344
00345
CGUIElement *pIterElement =
begin();
00346
set_ptr(pIterElement);
00347
00348
while(pIterElement !=NULL)
00349 {
00350 TiXmlElement SaveChildXMLElement(pIterElement->
m_strElementType);
00351 pIterElement->
SaveXML(&SaveChildXMLElement,
"");
00352
00353 pSaveXMLElement->
InsertEndChild(SaveChildXMLElement);
00354 pIterElement =
next();
00355 }
00356
00357
if(pDataNode == NULL && strFilename !=
"")
00358 {
00359
TiXmlDocument SaveDoc;
00360 SaveDoc.
InsertEndChild(*pSaveXMLElement);
00361
int iRetValue = SaveDoc.
SaveFile(strFilename);
00362 SAFEDEL(pSaveXMLElement)
00363
00364
return iRetValue;
00365 }
00366
00367
return 1;
00368 }
00369
00370 int CGUIElement::OnLMouseDown(UINT x, UINT y)
00371 {
00372
CGUIElement *IterElement =
end();
00373
set_ptr(IterElement);
00374
00375
while(IterElement !=NULL)
00376 {
00377
if(IterElement->
OnLMouseDown(x, y))
00378
return 1;
00379 IterElement =
prev();
00380 }
00381
00382
if(
GetType() !=GUI)
00383 {
00384
if(PointInRect(
GetRect(), x, y))
00385 {
00386
GetGUI()->
SetActiveElement(
this);
00387
GetGUI()->
Lock();
00388
return 1;
00389 }
00390 }
00391
00392
return 0;
00393 }
00394
00395 int CGUIElement::OnLMouseUp(UINT x, UINT y)
00396 {
00397
CGUIElement *IterElement =
end();
00398
set_ptr(IterElement);
00399
00400
while(IterElement !=NULL)
00401 {
00402
if(IterElement->
OnLMouseUp(x, y))
00403
return 1;
00404 IterElement =
prev();
00405 }
00406
00407
if(
GetType() !=GUI)
00408 {
00409
if(PointInRect(
GetRect(), x, y))
00410 {
00411
GetGUI()->
PostMessage(
this, NULL, GUI_Message_AquireFocus);
00412
return 1;
00413 }
00414 }
00415
00416
return 0;
00417 }
00418
00419 int CGUIElement::OnMouseMove(UINT x, UINT y)
00420 {
00421
if(x == 0 && y == 0)
00422
return 0;
00423
00424
int iRetValue = 0;
00425
CGUIElement *IterElement =
end();
00426
set_ptr(IterElement);
00427
00428
while(IterElement !=NULL)
00429 {
00430 iRetValue|=IterElement->
OnMouseMove(x, y);
00431 IterElement =
prev();
00432 }
00433
00434
if(
GetType() !=GUI)
00435 {
00436
if(
Visible())
00437 {
00438
00439
if(
GetGUI()->
IsLocked())
00440 {
00441
tVERTEX2d CursorPos =
CInputEngine::GetSingleton().
GetMouse()->
GetCursorPos();
00442
tVERTEX2d PrevCursorPos =
CInputEngine::GetSingleton().
GetMouse()->
GetPrevCursorPos();
00443
00444
if(
GetGUI()->
GetActiveElement() ==
this)
00445 {
00446
OnMove(CursorPos.
x - PrevCursorPos.
x, CursorPos.
y - PrevCursorPos.
y);
00447
return 1;
00448 }
00449 }
00450
00451
if(PointInRect(
m_Rect, x, y))
00452 iRetValue = 1;
00453 }
00454 }
00455
00456
return iRetValue;
00457 }
00458
00459
00460 int CGUIElement::OnRMouseDown(UINT x, UINT y)
00461 {
00462
00463
return 0;
00464 }
00465
00466 int CGUIElement::OnRMouseUp(UINT x, UINT y)
00467 {
00468
00469
return 0;
00470 }
00471
00472 int CGUIElement::OnMove(UINT x, UINT y)
00473 {
00474
if(
GetType() == GUI)
00475
return 0;
00476
00477
int mx = GUI_Message_Default, my = GUI_Message_Default;
00478
if(
Visible())
00479 {
00480
00481
if(
m_bAllowMoveX && (x !=0))
00482 {
00483
m_Rect.left+= x;
00484
m_Rect.right+= x;
00485 mx = GUI_Message_MoveX;
00486 }
00487
00488
if(
m_bAllowMoveY && (y !=0))
00489 {
00490
m_Rect.top+= y;
00491
m_Rect.bottom+= y;
00492 my = GUI_Message_MoveY;
00493 }
00494 }
00495
00496
if(mx != GUI_Message_Default && my != GUI_Message_Default)
00497 {
00498
GetGUI()->
PostMessage(
this, NULL, GUI_Message_MoveXY, x, y);
00499
return GUI_Message_MoveXY;
00500 }
00501
else if(mx == GUI_Message_MoveX && my == GUI_Message_Default)
00502 {
00503
GetGUI()->
PostMessage(
this, NULL, GUI_Message_MoveX, x, 0);
00504
return GUI_Message_MoveX;
00505 }
00506
else if(my == GUI_Message_MoveY && mx == GUI_Message_Default)
00507 {
00508
GetGUI()->
PostMessage(
this, NULL, GUI_Message_MoveY, 0, y);
00509
return GUI_Message_MoveY;
00510 }
00511
00512
return 0;
00513 }
00514
00515 void CGUIElement::Draw()
00516 {
00517
if(!
Visible())
00518
return;
00519
00520
int left =
m_Rect.left;
00521
int right =
m_Rect.right;
00522
int top =
m_Rect.top;
00523
int bottom =
m_Rect.bottom;
00524
00525
if(
m_pTexture == NULL)
00526 {
00527 glDisable(GL_TEXTURE_2D);
00528
00529
if(
m_pMaterial !=NULL)
00530 {
00531 glDisable(GL_LIGHTING);
00532 glColor4fv(
m_pMaterial->
GetAmbient().RGBA);
00533
00534 }
00535
else
00536 {
00537 glDisable(GL_LIGHTING);
00538 glColor3d(255, 255, 255);
00539 }
00540
00541 glBegin(GL_QUADS);
00542 glVertex3d(left, bottom, 0);
00543 glVertex3d(right, bottom, 0);
00544 glVertex3d(right, top, 0);
00545 glVertex3d(left, top, 0);
00546 glEnd();
00547 }
00548
else
00549 {
00550
m_pTexture->
Bind();
00551
00552
if(
m_pMaterial !=NULL)
00553 {
00554 glDisable(GL_LIGHTING);
00555 glColor3f(
m_pMaterial->
GetAmbient().R / 255.0f,
m_pMaterial->
GetAmbient().G / 255.0f,
m_pMaterial->
GetAmbient().B / 255.0f);
00556
00557 }
00558
else
00559 glColor3d(1, 1, 1);
00560
00561
00562
if(
m_pTexture->
IsMasked())
00563 {
00564 glAlphaFunc(GL_GREATER, 0.0f);
00565 glEnable(GL_ALPHA_TEST);
00566 }
00567
00568 glBegin(GL_QUADS);
00569
00570 glTexCoord2f(
m_TexCoord[0].x,
m_TexCoord[0].y); glVertex3d(left, bottom, 0);
00571
00572 glTexCoord2f(
m_TexCoord[1].x,
m_TexCoord[1].y); glVertex3d(right, bottom, 0);
00573
00574 glTexCoord2f(
m_TexCoord[2].x,
m_TexCoord[2].y); glVertex3d(right, top, 0);
00575
00576 glTexCoord2f(
m_TexCoord[3].x,
m_TexCoord[3].y); glVertex3d(left, top, 0);
00577 glEnd();
00578
00579
if(
m_pTexture->
IsMasked())
00580 glDisable(GL_ALPHA_TEST);
00581 }
00582
00583
CGUIElement *Iter =
begin();
00584
set_ptr(Iter);
00585
00586
while(Iter !=NULL)
00587 {
00588 Iter->
Draw();
00589 Iter =
next();
00590 }
00591 }
00592
00593 int CGUIElement::OnKeyUp(UINT uiKey)
00594 {
00595
00596
return 1;
00597 }
00598
00599 int CGUIElement::OnKeyDown(UINT uiKey)
00600 {
00601
00602
return 1;
00603 }
00604
00605 int CGUIElement::Resize(tRect& NewRect)
00606 {
00607
int ResizeX = 0, ResizeY = 0;
00608
if((NewRect.right - NewRect.left) >= GUI_MINIMUM_WIDTH)
00609 {
00610
if((NewRect.top - NewRect.bottom) >= GUI_MINIMUM_HEIGHT)
00611 {
00612
if(
m_bAllowSizeY)
00613 {
00614
m_Rect.top = NewRect.top;
00615
m_Rect.bottom = NewRect.bottom;
00616 ResizeY = GUI_Message_SizeY;
00617 }
00618 }
00619
00620
if(
m_bAllowSizeX)
00621 {
00622
m_Rect.left = NewRect.left;
00623
m_Rect.right = NewRect.right;
00624 ResizeX = GUI_Message_SizeX;
00625 }
00626 }
00627
00628
00629
00630
if(
GetType() == GUI)
00631
return 1;
00632
00633
if(ResizeX && ResizeY)
00634 {
00635
GetGUI()->
PostMessage(
this,
GetChild(GUI_Border), GUI_Message_SizeXY);
00636
return GUI_Message_SizeXY;
00637 }
00638
00639
if(ResizeX == GUI_Message_SizeX && ResizeY == 0)
00640 {
00641
GetGUI()->
PostMessage(
this,
GetChild(GUI_Border), GUI_Message_SizeX);
00642
return GUI_Message_SizeX;
00643 }
00644
00645
else if(ResizeY == GUI_Message_SizeY && ResizeX == 0)
00646 {
00647
GetGUI()->
PostMessage(
this,
GetChild(GUI_Border), GUI_Message_SizeY);
00648
return GUI_Message_SizeY;
00649 }
00650
00651
return 0;
00652 }
00653
00654 void CGUIElement::SetType(eGUIControlType eWidgetType)
00655 {
00656
m_eControlType = eWidgetType;
00657 }
00658
00659 eGUIControlType&
CGUIElement::GetType()
00660 {
00661
return m_eControlType;
00662 }
00663
00664 CGUI *
CGUIElement::GetGUI()
00665 {
00666
if(
GetParent() !=NULL)
00667 {
00668
if(
GetParent()->
GetType() == GUI)
00669
return (
CGUI *)
GetParent();
00670
else
00671
return GetParent()->
GetGUI();
00672 }
00673
00674
return NULL;
00675 }
00676
00677 void CGUIElement::SetGUI(
CGUI *Root)
00678 {
00679
m_pGUI = Root;
00680 }
00681
00682 void CGUIElement::SetParent(
CGUIElement *Parent)
00683 {
00684
m_pParent = Parent;
00685 }
00686
00687 CGUIElement *
CGUIElement::GetParent()
00688 {
00689
return m_pParent;
00690 }
00691
00692 void CGUIElement::ProcessMessage(
tGUIMessage& Message)
00693 {
00694
00695 }
00696
00697 void CGUIElement::ProcessMessages()
00698 {
00699
tGUIMessage *pMessage = NULL;
00700
00701
for (UINT i=0; i<
GetGUI()->
GetMessageCount(); i++)
00702 {
00703 pMessage =
GetGUI()->
GetMessage(i);
00704
if(pMessage->uiMessage !=-1)
00705
ProcessMessage(*pMessage);
00706 }
00707
00708
CGUIElement *pIterElement =
begin();
00709
set_ptr(pIterElement);
00710
00711
while(pIterElement !=NULL)
00712 {
00713 pIterElement->
ProcessMessages();
00714 pIterElement =
next();
00715 }
00716 }
00717
00718 tRect&
CGUIElement::GetRect()
00719 {
00720
return m_Rect;
00721 }
00722
00723 UINT
CGUIElement::GetHeight()
00724 {
00725
return (
m_Rect.top -
m_Rect.bottom);
00726 }
00727
00728 UINT
CGUIElement::GetWidth()
00729 {
00730
return (
m_Rect.right -
m_Rect.left);
00731 }
00732
00733 void CGUIElement::SetHeight(UINT Height)
00734 {
00735
m_Rect.bottom =
m_Rect.top - Height;
00736 }
00737
00738 void CGUIElement::SetTexCoord(UINT uiIndex,
float U,
float V)
00739 {
00740
if(uiIndex >=0 && uiIndex < 4)
00741 {
00742
m_TexCoord[uiIndex].
x = U;
00743
m_TexCoord[uiIndex].
y = V;
00744 }
00745 }
00746
00747 tVERTEX2f&
CGUIElement::GetTexCoord(UINT uiIndex)
00748 {
00749
if(uiIndex >=0 && uiIndex < 4)
00750
return m_TexCoord[uiIndex];
00751
00752
return tVERTEX2f(-1, -1);
00753 }
00754
00755 CGUIElement *
CGUIElement::GetChild(eGUIControlType eWidgetType)
00756 {
00757
CGUIElement *pIterElement =
begin();
00758
set_ptr(pIterElement);
00759
00760
while(pIterElement !=NULL)
00761 {
00762
if(pIterElement->
GetType() == eWidgetType)
00763
return pIterElement;
00764
00765 pIterElement =
next();
00766 }
00767
00768
return NULL;
00769 }
00770
00771 CGUIElement *
CGUIElement::GetChild(UINT uiIndex)
00772 {
00773
if(uiIndex >=0 && uiIndex <
GetChildCount())
00774
return at(uiIndex);
00775
00776
return NULL;
00777 }
00778
00779 UINT
CGUIElement::GetChildCount()
00780 {
00781
return size();
00782 }
00783
00784 CTexture *
CGUIElement::GetTexture()
00785 {
00786
return m_pTexture;
00787 }
00788
00789 void CGUIElement::SetTexture(
CTexture *pTexture)
00790 {
00791
m_pTexture = pTexture;
00792 }
00793
00794 CMaterial *
CGUIElement::GetMaterial()
00795 {
00796
return m_pMaterial;
00797 }
00798
00799 void CGUIElement::SetMaterial(
CMaterial *pMaterial)
00800 {
00801
m_pMaterial = pMaterial;
00802 }
00803
00804 void CGUIElement::HideSiblings(
int iDeep)
00805 {
00806
CGUIElement *pIterElement =
begin();
00807
set_ptr(pIterElement);
00808
00809
while(pIterElement !=NULL)
00810 {
00811 pIterElement->
Hide();
00812
00813
if(iDeep > 0)
00814 pIterElement->
HideSiblings(iDeep - 1);
00815
else if(iDeep == -1)
00816 pIterElement->
HideSiblings(iDeep);
00817
else if(iDeep == 0)
00818
return;
00819
00820 pIterElement =
next();
00821 }
00822 }
00823
00824 void CGUIElement::ShowSiblings(
int iDeep)
00825 {
00826
CGUIElement *pIterElement =
begin();
00827
set_ptr(pIterElement);
00828
00829
while(pIterElement !=NULL)
00830 {
00831
if(iDeep > 0)
00832 {
00833 pIterElement->
Show();
00834 pIterElement->
ShowSiblings(iDeep - 1);
00835 }
00836
else if(iDeep == -1)
00837 {
00838 pIterElement->
Show();
00839 pIterElement->
ShowSiblings(iDeep);
00840 }
00841
else if(iDeep == 0)
00842
return;
00843
00844 pIterElement =
next();
00845 }
00846 }
00847
00848 void CGUIElement::Show()
00849 {
00850
m_bVisible =
true;
00851 }
00852
00853 void CGUIElement::Hide()
00854 {
00855
m_bVisible =
false;
00856 }
00857
00858 bool CGUIElement::Visible()
00859 {
00860
return m_bVisible;
00861 }
00862
00863 void CGUIElement::SetFlag(eGUIFlag eFlag,
bool bSet)
00864 {
00865
if(eFlag == GUI_Flag_RestrictMovementX)
00866
m_bAllowMoveX = !bSet;
00867
else if(eFlag == GUI_Flag_RestrictMovementY)
00868
m_bAllowMoveY = !bSet;
00869
else if(eFlag == GUI_Flag_RestrictSizeX)
00870
m_bAllowSizeX = !bSet;
00871
else if(eFlag == GUI_Flag_RestrictSizeY)
00872
m_bAllowSizeY = !bSet;
00873 }
00874
00875 bool CGUIElement::IsFlagSet(eGUIFlag eFlag)
00876 {
00877
if(eFlag == GUI_Flag_RestrictMovementX)
00878
return m_bAllowMoveX;
00879
else if(eFlag == GUI_Flag_RestrictMovementY)
00880
return m_bAllowMoveY;
00881
else if(eFlag == GUI_Flag_RestrictSizeX)
00882
return m_bAllowSizeX;
00883
else if(eFlag == GUI_Flag_RestrictSizeY)
00884
return m_bAllowSizeY;
00885
00886
return false;
00887 }
00888
00889 bool CGUIElement::IsChild(
CGUIElement *pElement)
00890 {
00891
CGUIElement *pIterElement =
begin();
00892
set_ptr(pIterElement);
00893
00894
while(pIterElement !=NULL)
00895 {
00896
if(pIterElement == pElement)
00897
return true;
00898
00899 pIterElement =
next();
00900 }
00901
00902
return false;
00903 }
00904
00905
00906 void CGUIElement::SetZOrder(UINT uiZOrder)
00907 {
00908
CGUIElement *pParent =
GetParent();
00909
if(pParent !=NULL)
00910 {
00911
if(uiZOrder >=0 && uiZOrder < pParent->
size())
00912 pParent->
move_to(uiZOrder,
this);
00913 }
00914 }
00915
00916 unsigned int CGUIElement::GetZOrder()
00917 {
00918
CGUIElement *parent =
GetParent();
00919
if(parent == 0)
00920
return 0;
00921
else
00922 {
00923
for (UINT i=0; i<parent->
GetChildCount(); i++)
00924 {
00925
if(parent->
GetChild(i) ==
this)
00926
return i;
00927 }
00928 }
00929
return 1;
00930 }
00931
00932 void CGUIElement::SetRect(tRect& NewRect)
00933 {
00934
m_Rect = NewRect;
00935 }
00936
00937 void CGUIElement::RemoveChild(
CGUIElement *pChild)
00938 {
00939
if(pChild == NULL)
00940
return;
00941
00942
CGUIElement *pIterElement =
begin();
00943
set_ptr(pIterElement);
00944
00945
while(pIterElement !=NULL)
00946 {
00947
if(pIterElement == pChild)
00948 {
00949
delete remove(pChild);
00950
return;
00951 }
00952
00953 pIterElement =
next();
00954 }
00955 }
00956
00957 bool CGUIElement::PropertyChanging(
const void* pvProperty ,
void* pvNewValue )
00958 {
00959
bool bChangeOK =
CXMLResource::PropertyChanging(pvProperty, pvNewValue);
00960
00961
if(pvProperty == &
m_iMaterialIndex)
00962 {
00963
m_iMaterialIndex = *(
int *)pvNewValue;
00964
if(
m_iMaterialIndex!= 1000)
00965
m_pMaterial =
CMaterialManager::GetSingleton().
GetResource(
m_iMaterialIndex);
00966
else
00967
m_pMaterial = NULL;
00968 }
00969
00970
if(pvProperty == &
m_iTextureIndex)
00971 {
00972
m_iTextureIndex = *(
int *)pvNewValue;
00973
if(
m_iTextureIndex !=1000)
00974
m_pTexture =
CTextureManager::GetSingleton().
GetResource(
m_iTextureIndex);
00975
else
00976
m_pTexture = NULL;
00977
00978 }
00979
00980
for (
int i=0; i<4; i++)
00981 {
00982
if(pvProperty == &
m_TexCoord[i].
x)
00983 m_TexCoord[i].x = *(
float *)pvNewValue;
00984
else if(pvProperty == &m_TexCoord[i].y)
00985 m_TexCoord[i].y = *(
float *)pvNewValue;
00986 }
00987
00988
if(pvProperty == &
m_bAutoCalc)
00989
m_bAutoCalc = *(
bool *)pvNewValue;
00990
00991
if(pvProperty == &
m_strRectangle)
00992 {
00993
if(!
IsAutoCalc())
00994 {
00995 tRect NewRect;
00996
if(sscanf((*(CString *)pvNewValue),
"%i,%i,%i,%i", &NewRect.left, &NewRect.top, &NewRect.right, &NewRect.bottom))
00997 {
00998
Resize(NewRect);
00999
return true;
01000 }
01001
else
01002
return false;
01003 }
01004 }
01005
01006
if(pvProperty == &m_strFilename)
01007 {
01008 tRect BackupRect =
m_Rect;
01009
01010
Destroy();
01011 CString NewFilename = *(CString *)pvNewValue;
01012
01013
if(
LoadXML(NULL, GetFullPath(NewFilename)))
01014 {
01015 m_strFilename = NewFilename;
01016
Resize(BackupRect);
01017 }
01018 }
01019
01020 m_bUpdateRequired =
true;
01021
return bChangeOK;
01022 }
01023
01024 void CGUIElement::GetProperties( EPropList& PropList )
01025 {
01026
CXMLResource::GetProperties(PropList);
01027
01028 PropList.AddPropSeparator(
this,
"Element");
01029 PropList.AddPropString(
this,
"Type", &
m_strElementType,
false)->SetComment(
"Control Type");
01030
01031 PropList.AddPropCheck(
this,
"Auto. Param Calc.", &
m_bAutoCalc);
01032
01033
m_iChildren =
size();
01034 PropList.AddPropInt(
this,
"Children", &
m_iChildren,
"",
false)->SetComment(
"Children Count");
01035
01036 PropList.AddPropCheck(
this,
"Visible", &
m_bVisible)->SetComment(
"Element Visibility");
01037
01038
m_strRectangle.Format(
"%d,%d,%d,%d",
m_Rect.left,
m_Rect.top,
m_Rect.right,
m_Rect.bottom);
01039 PropList.AddPropString(
this,
"Rectangle", &
m_strRectangle,
true)->SetComment(
"Element' Left, Top, Right and Bottom coordinates");
01040
01041 PropList.AddPropCheck(
this,
"Size X", &
m_bAllowSizeX)->SetComment(
"Can the element' width be changed");
01042 PropList.AddPropCheck(
this,
"Size Y", &
m_bAllowSizeY)->SetComment(
"Can the element' height be changed");
01043
01044 PropList.AddPropCheck(
this,
"Move X", &
m_bAllowMoveX)->SetComment(
"Can the element' be moved horizontally");
01045 PropList.AddPropCheck(
this,
"Move Y", &
m_bAllowMoveY)->SetComment(
"Can the element' be moved vertically");
01046
01047
#ifndef GUI_USE_ACTIVE_INACTIVE
01048
01049 PropList.AddPropSeparator(
this,
"Material");
01050 EPropertyCombo *pMaterialCombo = (EPropertyCombo *)PropList.AddPropCombo(
this,
"From Database...", &
m_iMaterialIndex)->SetComment(
"Material selection");
01051 pMaterialCombo->AddString(
"No Material...", 1000);
01052
01053
for (
int i=0; i<
CMaterialManager::GetSingleton().
size(); i++)
01054 {
01055
CMaterial *pMaterial = (
CMaterial *)
CMaterialManager::GetSingleton().
at(i);
01056
01057
if(
m_pMaterial !=NULL &&
m_pMaterial == pMaterial)
01058
m_iMaterialIndex = i;
01059
01060 pMaterialCombo->AddString(pMaterial->
GetName(), i);
01061 }
01062
01063
if(
m_pMaterial !=NULL)
01064 {
01065
m_MaterialAmbient = RGB(
m_pMaterial->
GetAmbient().R,
m_pMaterial->
GetAmbient().G,
m_pMaterial->
GetAmbient().B);
01066
m_MaterialDiffuse = RGB(
m_pMaterial->
GetDiffuse().R,
m_pMaterial->
GetDiffuse().G,
m_pMaterial->
GetDiffuse().B);
01067
m_MaterialSpecular = RGB(
m_pMaterial->
GetSpecular().R,
m_pMaterial->
GetSpecular().G,
m_pMaterial->
GetSpecular().B);
01068
m_MaterialEmissive = RGB(
m_pMaterial->
GetEmissive().R,
m_pMaterial->
GetEmissive().G,
m_pMaterial->
GetEmissive().B);
01069
01070
m_iMaterialShininess =
m_pMaterial->
GetShininess();
01071
01072 PropList.AddPropColor(
this,
"Ambient", &
m_MaterialAmbient,
false)->SetComment(
"Material' Ambient component");
01073 PropList.AddPropColor(
this,
"Diffuse", &
m_MaterialDiffuse,
false)->SetComment(
"Material' Diffuse component");
01074 PropList.AddPropColor(
this,
"Specular", &
m_MaterialSpecular,
false)->SetComment(
"Material' Specular component");
01075 PropList.AddPropColor(
this,
"Emissive", &
m_MaterialEmissive,
false)->SetComment(
"Material' Emissive component");
01076 PropList.AddPropInt(
this,
"Shininess", &
m_iMaterialShininess,
"",
false)->SetComment(
"Material' Shininess");
01077 }
01078
#elif
01079
PropList.AddPropSeparator(
this,
"Color(s)");
01080 PropList.AddPropColor(
this,
"Active", &
m_ActiveColor,
true)->SetComment(
"Element' Active color");
01081 PropList.AddPropColor(
this,
"Inactive", &
m_InactiveColor,
true)->SetComment(
"Element' Inactive color");
01082
#endif
01083
01084 PropList.AddPropSeparator(
this,
"Texture");
01085 EPropertyCombo *pTextureCombo = (EPropertyCombo *)PropList.AddPropCombo(
this,
"From Database...", &
m_iTextureIndex);
01086 pTextureCombo->AddString(
"No Texture...", 1000);
01087
01088
for (
int i=0; i<
CTextureManager::GetSingleton().
size(); i++)
01089 {
01090
CTexture *pTexture = (
CTexture *)
CTextureManager::GetSingleton().
at(i);
01091
01092 pTextureCombo->AddString(pTexture->
GetName(), i);
01093
01094
if(
m_pTexture !=NULL &&
m_pTexture == pTexture)
01095
m_iTextureIndex = i;
01096 }
01097
01098
if(
m_pTexture !=NULL)
01099 {
01100
m_strTextureFilename =
m_pTexture->
GetTextureFilename();
01101
m_strTextureName =
m_pTexture->
GetName();
01102
01103 PropList.AddPropString(
this,
"strFilename", &
m_strTextureFilename,
false)->SetComment(
"Texture' strFilename");
01104
01105 PropList.AddTab(
"Texturing");
01106 PropList.AddPropSeparator(
this,
"Texture Mapping");
01107
01108 PropList.AddPropSeparator(
this,
"Top Left");
01109 PropList.AddPropFloat(
this,
"0X", &
m_TexCoord[3].x,
"", 0, 100,
true);
01110 PropList.AddPropFloat(
this,
"1Y", &
m_TexCoord[3].y,
"", 0, 100,
true);
01111
01112 PropList.AddPropSeparator(
this,
"Top Right");
01113 PropList.AddPropFloat(
this,
"0X", &
m_TexCoord[2].x,
"", 0, 100,
true);
01114 PropList.AddPropFloat(
this,
"1Y", &
m_TexCoord[2].y,
"", 0, 100,
true);
01115
01116 PropList.AddPropSeparator(
this,
"Bottom Right");
01117 PropList.AddPropFloat(
this,
"0X", &
m_TexCoord[1].x,
"", 0, 100,
true);
01118 PropList.AddPropFloat(
this,
"1Y", &
m_TexCoord[1].y,
"", 0, 100,
true);
01119
01120 PropList.AddPropSeparator(
this,
"Bottom Left");
01121 PropList.AddPropFloat(
this,
"0X", &
m_TexCoord[0].x,
"", 0, 100,
true);
01122 PropList.AddPropFloat(
this,
"0Y", &
m_TexCoord[0].y,
"", 0, 100,
true);
01123 }
01124 }
01125
01126 bool CGUIElement::IsAutoCalc()
01127 {
01128
return m_bAutoCalc;
01129 }
01130
01131 void CGUIElement::SetAutoCalc(
bool bAutoCalc)
01132 {
01133
m_bAutoCalc = bAutoCalc;
01134 }
01135
01136 void CGUIElement::Destroy()
01137 {
01138
erase();
01139 }
01140
01141 bool CGUIElement::IsOfType(eEntityType eType)
01142 {
01143
if(eType == Entity_GUIElement)
01144
return true;
01145
01146
return CXMLResource::IsOfType(eType);
01147 }