Spinning Topp Logo BlackTopp Studios
inc
gridcontainer.cpp
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _uigridcontainer_cpp
41 #define _uigridcontainer_cpp
42 
43 #include "UI/gridcontainer.h"
44 #include "UI/pageprovider.h"
45 
46 #include "exception.h"
47 #include "serialization.h"
48 
49 namespace Mezzanine
50 {
51  namespace UI
52  {
53  ///////////////////////////////////////////////////////////////////////////////
54  // GridVector2 Methods
55 
56  ///////////////////////////////////////////////////////////////////////////////
57  // Construction and Destruction
58 
60  X(0), Y(0)
61  { }
62 
63  GridVector2::GridVector2(const Whole x, const Whole y) :
64  X(x), Y(y)
65  { }
66 
67  ///////////////////////////////////////////////////////////////////////////////
68  // Operators
69 
71  { return ( this->X == Other.X && this->Y == Other.Y ); }
72 
74  { return ( this->X != Other.X || this->Y != Other.Y ); }
75 
76  ///////////////////////////////////////////////////////////////////////////////
77  // GridRect Methods
78 
79  ///////////////////////////////////////////////////////////////////////////////
80  // Construction and Destruction
81 
83  { }
84 
85  GridRect::GridRect(const Whole XPos, const Whole YPos, const Whole XSize, const Whole YSize) :
86  Position(XPos,YPos),
87  Size(XSize,YSize)
88  { }
89 
90  ///////////////////////////////////////////////////////////////////////////////
91  // Utility
92 
94  { return this->Position.X; }
95 
97  { return this->Position.X + ( this->Size.X - 1); }
98 
100  { return this->Position.Y; }
101 
103  { return this->Position.Y + ( this->Size.Y - 1); }
104 
106  {
107  return ( this->GetLeftCell() <= Other.GetLeftCell() &&
108  this->GetRightCell() >= Other.GetRightCell() &&
109  this->GetTopCell() <= Other.GetTopCell() &&
110  this->GetBottomCell() >= Other.GetBottomCell() );
111  }
112 
113  void GridRect::ProtoSerialize(XML::Node& ParentNode) const
114  {
115  XML::Node SelfNode = ParentNode.AppendChild( GridRect::GetSerializableName() );
116 
117  if( SelfNode.AppendAttribute("Version").SetValue("1") &&
118  SelfNode.AppendAttribute("XPos").SetValue( this->Position.X ) &&
119  SelfNode.AppendAttribute("YPos").SetValue( this->Position.Y ) &&
120  SelfNode.AppendAttribute("XSize").SetValue( this->Size.X ) &&
121  SelfNode.AppendAttribute("YSize").SetValue( this->Size.Y ) )
122  {
123  return;
124  }else{
125  SerializeError("Create XML Attribute Values",GridRect::GetSerializableName(),true);
126  }
127  }
128 
129  void GridRect::ProtoDeSerialize(const XML::Node& SelfRoot)
130  {
131  XML::Attribute CurrAttrib;
132 
133  if( String(SelfRoot.Name()) == GridRect::GetSerializableName() ) {
134  if(SelfRoot.GetAttribute("Version").AsInt() == 1) {
135  CurrAttrib = SelfRoot.GetAttribute("XPos");
136  if( !CurrAttrib.Empty() )
137  this->Position.X = CurrAttrib.AsWhole();
138 
139  CurrAttrib = SelfRoot.GetAttribute("YPos");
140  if( !CurrAttrib.Empty() )
141  this->Position.Y = CurrAttrib.AsWhole();
142 
143  CurrAttrib = SelfRoot.GetAttribute("XSize");
144  if( !CurrAttrib.Empty() )
145  this->Size.X = CurrAttrib.AsWhole();
146 
147  CurrAttrib = SelfRoot.GetAttribute("YSize");
148  if( !CurrAttrib.Empty() )
149  this->Size.Y = CurrAttrib.AsWhole();
150  }else{
151  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + GridRect::GetSerializableName() + ": Not Version 1.");
152  }
153  }else{
154  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_NOT_FOUND_EXCEPTION,GridRect::GetSerializableName() + " was not found in the provided XML node, which was expected.");
155  }
156  }
157 
159  { return "GridRect"; }
160 
161  ///////////////////////////////////////////////////////////////////////////////
162  // Operators
163 
165  { return ( this->Position == Other.Position && this->Size == Other.Size ); }
166 
168  { return ( this->Position != Other.Position || this->Size != Other.Size ); }
169 
170  ///////////////////////////////////////////////////////////////////////////////
171  // GridContainer Static Members
172 
173  const String GridContainer::TypeName = "GridContainer";
174 
175  ///////////////////////////////////////////////////////////////////////////////
176  // GridContainer Methods
177 
179  PagedContainer(Parent)
180  { }
181 
182  GridContainer::GridContainer(const String& RendName, Screen* Parent) :
183  PagedContainer(RendName,Parent)
184  { }
185 
186  GridContainer::GridContainer(const String& RendName, const UnifiedRect& RendRect, Screen* Parent) :
187  PagedContainer(RendName,RendRect,Parent)
188  { }
189 
190  GridContainer::GridContainer(const XML::Node& XMLNode, Screen* Parent) :
191  PagedContainer(Parent)
192  { this->ProtoDeSerialize(XMLNode); }
193 
195  { }
196 
198  {
199  this->PagedContainer::ProtoSerializeImpl(SelfRoot);
200  this->ProtoSerializeGridRects(SelfRoot);
201  }
202 
204  {
205  this->PagedContainer::ProtoDeSerializeImpl(SelfRoot);
206  this->ProtoDeSerializeGridRects(SelfRoot);
207  }
208 
209  void GridContainer::UpdateContainerDimensionsImpl(const Rect& OldSelfRect, const Rect& NewSelfRect)
210  {
211  // Clear our old data.
212  this->VisibleChildren.clear();
213  this->WorkAreaSize.SetIdentity();
214 
215  // Get some of the data we're gonna use.
216  const GridVector2 GridSize = this->GetGridSize();
217  const Vector2 ActCellPadding = this->CellPadding.CalculateActualDimensions( this->ActDims.Size );
218  const Vector2 ActCellSize = this->CellSize.CalculateActualDimensions( this->ActDims.Size );
219 
220  // Since we're here, may as well update the work area size.
221  this->WorkAreaSize.X = ActCellSize.X * static_cast<Real>( GridSize.X );
222  this->WorkAreaSize.Y = ActCellSize.Y * static_cast<Real>( GridSize.Y );
223 
224  // Figure out how many cells we can fit onto a page.
225  const Real XCellsPerPage = this->ActDims.Size.X / ActCellSize.X;
226  const Real YCellsPerPage = this->ActDims.Size.Y / ActCellSize.Y;
227  Real CurrXPage = 1;
228  Real CurrYPage = 1;
229  if( this->XProvider != NULL && this->XProvider == this->YProvider ) {
231  CurrXPage = this->XProvider->GetCurrentXPage();
232  CurrYPage = this->YProvider->GetCurrentYPage();
233  }else if( this->XProvider != NULL ) {
235  CurrXPage = this->XProvider->GetCurrentXPage();
236  }else if( this->YProvider != NULL ) {
238  CurrXPage = this->YProvider->GetCurrentYPage();
239  }
240 
241  // Only continue if we know there are cells that can fit into the view area.
242  if( XCellsPerPage >= 1 && YCellsPerPage >= 1 ) {
243  // We need to get the view position within the work area.
244  Vector2 ViewPosition;
245  ViewPosition.X = ( CurrXPage - 1 ) * this->ActDims.Size.X;
246  ViewPosition.Y = ( CurrYPage - 1 ) * this->ActDims.Size.Y;
247 
248  // Next we need to convert the "view rect" into grid coordinates
249  GridRect ViewRect;
250  ViewRect.Position.X = static_cast<Whole>( ( CurrXPage - 1 ) * XCellsPerPage );
251  ViewRect.Position.Y = static_cast<Whole>( ( CurrYPage - 1 ) * YCellsPerPage );
252  ViewRect.Size.X = static_cast<Whole>( XCellsPerPage );
253  ViewRect.Size.Y = static_cast<Whole>( YCellsPerPage );
254 
255  // We already know the ChildRects container is sorted by ZOrder.
256  // So now we just need to iterate over them to see if the view rect envelopes any given child.
257  for( ChildRectIterator RectIt = this->ChildRects.begin() ; RectIt != this->ChildRects.end() ; ++RectIt )
258  {
259  // Check if our child is completely within the view area of the grid.
260  GridRect ChildGridRect = (*RectIt).second;
261  if( ViewRect.Envelopes( ChildGridRect ) ) {
262  // If so, perform our transform update.
263  const Rect OldChildRect = (*RectIt).first->GetRect();
264  Rect NewChildRect;
265 
266  // Set the Size
267  NewChildRect.Size.X = ( ActCellSize.X * static_cast<Real>( ChildGridRect.Size.X ) ) - ActCellPadding.X;
268  NewChildRect.Size.Y = ( ActCellSize.Y * static_cast<Real>( ChildGridRect.Size.Y ) ) - ActCellPadding.Y;
269  // Set the Position
270  // First get the column/row we're working with. Use base 0 for easier math later.
271  const Whole ChildColumn = ( ChildGridRect.Position.X - ViewRect.Position.X );
272  const Whole ChildRow = ( ChildGridRect.Position.Y - ViewRect.Position.Y );
273  // Now we can try to calculate the actual position.
274  // Multiply the size of a cell by the column/row we are in, which should get us the base offset for that child.
275  // Then add half the padding, since the padding is supposed to be the total on both sides of that axis.
276  // Lastly apply that to the container position to convert it into a screen position.
277  NewChildRect.Position.X = NewSelfRect.Position.X + ( ( ActCellSize.X * static_cast<Real>( ChildColumn ) ) + ( ActCellPadding.X * 0.5 ) );
278  NewChildRect.Position.Y = NewSelfRect.Position.Y + ( ( ActCellSize.Y * static_cast<Real>( ChildRow ) ) + ( ActCellPadding.Y * 0.5 ) );
279  // Perform the update.
280  (*RectIt).first->UpdateDimensions(OldChildRect,NewChildRect);
281 
282  // Finally add it to the container of visible children.
283  (*RectIt).first->SetVisible( this->GetVisible() );
284  this->VisibleChildren.push_back( (*RectIt).first );
285  }else{
286  const Rect OldChildRect = (*RectIt).first->GetRect();
287  Rect NewChildRect;
288  NewChildRect.Size = OldChildRect.Size;
289  NewChildRect.Position = NewSelfRect.Position;
290  (*RectIt).first->UpdateDimensions(OldChildRect,NewChildRect);
291  (*RectIt).first->Hide();
292  }
293  }
294  }
295  }
296 
297  ///////////////////////////////////////////////////////////////////////////////
298  // Utility
299 
301  {
302  GridVector2 GridSize = this->GetGridSize();
303  Vector2 ActCellSize = this->CellSize.CalculateActualDimensions( this->ActDims.Size );
304 
305  this->WorkAreaSize.X = ActCellSize.X * static_cast<Real>( GridSize.X );
306  this->WorkAreaSize.Y = ActCellSize.Y * static_cast<Real>( GridSize.Y );
307  }
308 
310  {
311  // This method doesn't provide enough information to do what is intended for this container.
312  // So do nothing. Wait for the slow version to do the update.
313  }
314 
316  {
318  }
319 
321  {
322  if( XProv != YProv ) {
323  this->SetXProvider(XProv);
324  this->SetYProvider(YProv);
325  }else{
326  // Clear out the X provider.
327  if( this->XProvider != NULL && this->XProvider != XProv ) {
328  this->UnbindProvider(this->XProvider);
329  }
330  // Clear out the Y provider.
331  if( this->YProvider != NULL && this->YProvider != YProv ) {
332  this->UnbindProvider(this->YProvider);
333  }
334 
335  // We know the two providers are passed in, so just check the validity for the XProvider.
336  if( XProv != NULL ) {
337  this->XProvider = XProv;
338  this->YProvider = YProv;
339 
340  this->XProvider->_SetContainer(this);
342  }
343  }
344  }
345 
347  {
348  if( XProv == this->YProvider ) {
349  this->SetProviders(XProv,XProv);
350  }else{
351  if( this->XProvider != NULL && this->XProvider != XProv ) {
352  this->UnbindProvider(this->XProvider);
353  }
354  this->XProvider = XProv;
355  this->XProvider->_SetContainer(this);
357  }
358  }
359 
361  {
362  if( YProv == this->XProvider ) {
363  this->SetProviders(YProv,YProv);
364  }else{
365  if( this->YProvider != NULL && this->YProvider != YProv ) {
366  this->UnbindProvider(this->YProvider);
367  }
368  this->YProvider = YProv;
369  this->YProvider->_SetContainer(this);
371  }
372  }
373 
375  {
376  return CellSize - CellPadding;
377  }
378 
379  ///////////////////////////////////////////////////////////////////////////////
380  // GridContainer Properties
381 
382  void GridContainer::SetCellSize(const Whole X, const Whole Y)
383  {
384  Real XRel = 1.0 / static_cast<Real>(X);
385  Real YRel = 1.0 / static_cast<Real>(Y);
386  this->SetCellSize( UnifiedVec2(XRel,YRel) );
387  }
388 
390  { this->CellSize = Size; }
391 
393  { return this->CellSize; }
394 
396  { this->CellPadding = Padding; }
397 
399  { return this->CellPadding; }
400 
401  ///////////////////////////////////////////////////////////////////////////////
402  // GridContainer Configuration
403 
405  {
406  GridVector2 Ret;
407  for( ConstChildRectIterator RectIt = this->ChildRects.begin() ; RectIt != this->ChildRects.end() ; ++RectIt )
408  {
409  if( Ret.X < (*RectIt).second.GetRightCell() ) {
410  Ret.X = (*RectIt).second.GetRightCell();
411  }
412  if( Ret.Y < (*RectIt).second.GetBottomCell() ) {
413  Ret.Y = (*RectIt).second.GetBottomCell();
414  }
415  }
416  return Ret;
417  }
418 
420  {
421  UInt16 Zorder = Child->GetZOrder();
422  ChildRectIterator RectEnd = this->ChildRects.end();
423  ChildRectIterator InsIt = RectEnd;
424  for( ChildRectIterator RectIt = this->ChildRects.begin() ; RectIt != RectEnd ; ++RectIt )
425  {
426  if( (*RectIt).first == Child ) {
427  (*RectIt).second = ChildTrans;
428  return false;
429  }else if( (*RectIt).first->GetZOrder() > Zorder && InsIt != RectEnd ) {
430  InsIt = RectIt;
431  }
432  }
433  this->ChildRects.insert(InsIt,ChildRectPair(Child,ChildTrans));
434  return ( InsIt != RectEnd );
435  }
436 
438  {
439  for( ConstChildRectIterator RectIt = this->ChildRects.begin() ; RectIt != this->ChildRects.end() ; ++RectIt )
440  {
441  if( (*RectIt).first == Child ) {
442  return (*RectIt).second;
443  }
444  }
445  return GridRect();
446  }
447 
449  {
450  for( ChildRectIterator RectIt = this->ChildRects.begin() ; RectIt != this->ChildRects.end() ; ++RectIt )
451  {
452  if( (*RectIt).first == Child ) {
453  this->ChildRects.erase(RectIt);
454  return true;
455  }
456  }
457  return false;
458  }
459 
460  ///////////////////////////////////////////////////////////////////////////////
461  // Child Management
462 
463  void GridContainer::AddChild(Widget* Child, const GridRect& GridTransform)
464  {
465  this->SetChildGridRect(Child,GridTransform);
466  this->AddChild(Child);
467  }
468 
469  void GridContainer::AddChild(Widget* Child, const UInt16 ZOrder, const GridRect& GridTransform)
470  {
471  this->SetChildGridRect(Child,GridTransform);
472  this->AddChild(Child,ZOrder);
473  }
474 
476  {
477  this->RemoveChildGridRect(ToBeRemoved);
478  this->PagedContainer::RemoveChild(ToBeRemoved);
479  }
480 
482  {
483  this->ChildRects.clear();
485  }
486 
487  void GridContainer::DestroyChild(Widget* ToBeDestroyed)
488  {
489  this->RemoveChildGridRect(ToBeDestroyed);
490  this->PagedContainer::DestroyChild(ToBeDestroyed);
491  }
492 
494  {
495  this->ChildRects.clear();
497  }
498 
499  ///////////////////////////////////////////////////////////////////////////////
500  // Serialization
501 
503  {
504  XML::Node GridRectsNode = SelfRoot.AppendChild( "ChildRects" );
505 
506  if( GridRectsNode.AppendAttribute("Version").SetValue("1") ) {
507  for( ConstChildRectIterator ChildRectIt = this->ChildRects.begin() ; ChildRectIt != this->ChildRects.end() ; ++ChildRectIt )
508  {
509  XML::Node ChildNode = GridRectsNode.AppendChild( "ChildRect" );
510 
511  if( ChildNode.AppendAttribute("Version").SetValue("1") &&
512  ChildNode.AppendAttribute("ChildName").SetValue( (*ChildRectIt).first->GetName() ) )
513  {
514  XML::Node CellRectNode = ChildNode.AppendChild("CellRect");
515  (*ChildRectIt).second.ProtoSerialize(CellRectNode);
516 
517  continue;
518  }else{
519  SerializeError("Create XML Version Attribute","ChildRect",true);
520  }
521  }
522  }else{
523  SerializeError("Create XML Version Attribute","ChildRects",true);
524  }
525  }
526 
528  {
530 
531  XML::Node PropertiesNode = SelfRoot.AppendChild( GridContainer::GetSerializableName() + "Properties" );
532 
533  if( PropertiesNode.AppendAttribute("Version").SetValue("1") )
534  {
535  XML::Node CellSizeNode = PropertiesNode.AppendChild("CellSize");
536  this->CellSize.ProtoSerialize(CellSizeNode);
537 
538  XML::Node CellPaddingNode = PropertiesNode.AppendChild("CellPadding");
539  this->CellPadding.ProtoSerialize(CellPaddingNode);
540 
541  return;
542  }else{
543  SerializeError("Create XML Attribute Values",GridContainer::GetSerializableName() + "Properties",true);
544  }
545  }
546 
548  {
549  this->ChildRects.clear();
550 
551  XML::Attribute CurrAttrib;
552  XML::Node ChildRectsNode = SelfRoot.GetChild( "ChildRects" );
553 
554  if( !ChildRectsNode.Empty() ) {
555  if( ChildRectsNode.GetAttribute("Version").AsInt() == 1 ) {
556  const GridRect EmptyRect;
557  for( XML::NodeIterator ChildRectNodeIt = ChildRectsNode.begin() ; ChildRectNodeIt != ChildRectsNode.end() ; ++ChildRectNodeIt )
558  {
559  if( (*ChildRectNodeIt).GetAttribute("Version").AsInt() == 1 ) {
560  GridRect CellRect;
561  String ChildName;
562 
563  CurrAttrib = (*ChildRectNodeIt).GetAttribute("ChildName");
564  if( !CurrAttrib.Empty() )
565  ChildName = CurrAttrib.AsString();
566 
567  XML::Node CellRectNode = SelfRoot.GetChild("CellRect").GetFirstChild();
568  if( !CellRectNode.Empty() )
569  CellRect.ProtoDeSerialize(CellRectNode);
570 
571  if( !ChildName.empty() && CellRect != EmptyRect ) {
572  Widget* GridChild = this->GetChild(ChildName);
573  if( GridChild != NULL ) {
574  this->ChildRects.push_back( ChildRectPair(GridChild,CellRect) );
575  }
576  }
577  }else{
578  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + String("ChildRects") + ": Not Version 1.");
579  }
580  }
581  }else{
582  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + String("ChildRects") + ": Not Version 1.");
583  }
584  }
585  }
586 
588  {
590 
591  //XML::Attribute CurrAttrib;
592  XML::Node PropertiesNode = SelfRoot.GetChild( GridContainer::GetSerializableName() + "Properties" );
593 
594  if( !PropertiesNode.Empty() ) {
595  if(PropertiesNode.GetAttribute("Version").AsInt() == 1) {
596  XML::Node CellSizeNode = PropertiesNode.GetChild("CellSize");
597  this->CellSize.ProtoDeSerialize(CellSizeNode);
598 
599  XML::Node CellPaddingNode = PropertiesNode.GetChild("CellPadding");
600  this->CellPadding.ProtoDeSerialize(CellPaddingNode);
601  }else{
602  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + (GridContainer::GetSerializableName() + "Properties") + ": Not Version 1.");
603  }
604  }else{
605  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_NOT_FOUND_EXCEPTION,GridContainer::GetSerializableName() + "Properties" + " was not found in the provided XML node, which was expected.");
606  }
607  }
608 
610  {
612  }
613 
614  ///////////////////////////////////////////////////////////////////////////////
615  // Internal Methods
616 
617  ///////////////////////////////////////////////////////////////////////////////
618  // GridContainerFactory Methods
619 
621  { return GridContainer::TypeName; }
622 
624  { return new GridContainer(RendName,Parent); }
625 
627  { return new GridContainer(RendName,RendRect,Parent); }
628 
630  { return new GridContainer(XMLNode,Parent); }
631 
633  { return new GridContainer(Parent); }
634 
635  Widget* GridContainerFactory::CreateWidget(const String& RendName, const NameValuePairMap& Params, Screen* Parent)
636  { return this->CreateGridContainer(RendName,Parent); }
637 
638  Widget* GridContainerFactory::CreateWidget(const String& RendName, const UnifiedRect& RendRect, const NameValuePairMap& Params, Screen* Parent)
639  { return this->CreateGridContainer(RendName,RendRect,Parent); }
640 
642  { return this->CreateGridContainer(XMLNode,Parent); }
643 
645  { delete static_cast<GridContainer*>( ToBeDestroyed ); }
646  }//UI
647 }//Mezzanine
648 
649 #endif
virtual String GetWidgetTypeName() const
Gets the name of the Widget that is created by this factory.
This is the base class for containers that have a render area and work area of different sizes...
GridRect()
Blank constructor.
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
A light-weight handle for manipulating attributes in DOM tree.
Definition: attribute.h:74
virtual Widget * CreateWidget(Screen *Parent)
Creates a Widget of the type represented by this factory.
GridVector2 Size
The Cell size of this rect.
Definition: gridcontainer.h:96
Boole operator==(const GridRect &Other)
Equality comparison operator.
static const String TypeName
String containing the type name for this class: "GricContainer".
virtual void ProtoSerializeGridRects(XML::Node &SelfRoot) const
Convert the GridRects data of this class to an XML::Node ready for serialization. ...
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
virtual GridVector2 GetGridSize() const
Gets the total used size of the Grid based on the current children.
virtual GridRect GetChildGridRect(Widget *Child) const
Gets the grid transform of a child in this container.
void ProtoSerialize(XML::Node &ParentNode) const
Convert this class to an XML::Node ready for serialization.
This is a container class for placing child objects on a 2 dimensional grid.
ChildRectContainer::iterator ChildRectIterator
Iterator type for GridRects in relation to the children they apply to.
Vector2 Size
Vector2 representing the width and height of the rect.
Definition: rect.h:71
virtual void ProtoDeSerializeGridRects(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the GridRects data of this object with it...
virtual Boole SetChildGridRect(Widget *Child, const GridRect &ChildTrans)
Sets the grid transform of a child in this container.
GridVector2 Position
The Cell position of this rect.
Definition: gridcontainer.h:94
virtual const UnifiedVec2 & GetCellSize() const
Gets the Unified size of a single cell in this container.
Thrown when the requested identity could not be found.
Definition: exception.h:94
virtual void DestroyChild(Widget *ToBeDestroyed)
Destroys a child Widget currently inside this QuadRenderable.
Node GetFirstChild() const
Get the first child Node of this Node.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
virtual void DestroyWidget(Widget *ToBeDestroyed)
Destroys a Widget created by this factory.
virtual void RemoveAllChildren()
Removes all child Widgets from this QuadRenderable.
Simple rect used to represent a complete transform on a grid.
Definition: gridcontainer.h:91
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
Definition: exception.h:112
const Char8 * AsString(const Char8 *def="") const
Attempts to convert the value of the attribute to a String and returns the results.
virtual void UpdateWorkAreaSize()
Checks the size of every child in this container and updates the work area to match the size needed...
virtual void ProtoDeSerializeImpl(const XML::Node &SelfRoot)
Implementation method for deseriailizing additional sets of data.
ChildRectContainer ChildRects
Container storing pairs of Grid rects and the children they apply to.
Whole GetRightCell() const
Gets the Right cell of this Rect.
This class represents a box shaped area on the screen.
Definition: rect.h:55
virtual void _SetContainer(PagedContainer *ToUpdate)
Sets the container that is using this provider to update which renderables are visible.
Whole Y
The Cell(s) on the Y axis.
Definition: gridcontainer.h:62
Whole GetBottomCell() const
Gets the Bottom cell of this Rect.
virtual void AddChild(Widget *Child, const GridRect &GridTransform)
Adds a Widget to this as a child of this quad.
virtual void SetYProvider(PageProvider *YProv)
Sets the PageProvider for the Y axis.
bool Empty() const
Is this storing anything at all?
virtual ~GridContainer()
Class destructor.
This implements the exception hiearchy for Mezzanine.
PageProvider * XProvider
A pointer to the X axis provider.
Vector2 CalculateActualDimensions(const Vector2 &Actual) const
Calculates the actual values when a Vector2 with actual dimensions has this unified vector2 applied t...
Definition: unifieddim.h:384
virtual void DestroyAllChildren()
Destroys all child Widgets currently inside this QuadRenderable.
virtual Widget * GetChild(const UInt16 Zorder) const
Gets a child by it's ZOrder.
virtual void ProtoDeSerializeImpl(const XML::Node &SelfRoot)
Implementation method for deseriailizing additional sets of data.
virtual Boole RemoveChildGridRect(Widget *Child)
Removes the grid transform of a child from this container.
static String GetSerializableName()
Get the name of the the XML tag this class will leave behind as its instances are serialized...
Boole operator==(const GridVector2 &Other)
Equality comparison operator.
Rect ActDims
The actual (pixel) position and size of this Quad on the screen it belongs to.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
The interface for serialization.
virtual const UInt16 & GetZOrder() const
Gets the currently set ZOrder of this QuadRenderable with it's parent.
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
virtual void DestroyAllChildren()
Destroys all child Widgets currently inside this QuadRenderable.
bool SetValue(const Char8 *rhs)
Set the value of this.
virtual Real GetCurrentYPage() const =0
Gets the current page position on the Y axis.
virtual GridContainer * CreateGridContainer(const String &RendName, Screen *Parent)
Creates a new GridContainer.
Whole GetLeftCell() const
Gets the Left cell of this Rect.
This class represents a 2D rect which can express the size and position of a renderable on screen...
Definition: unifieddim.h:661
uint16_t UInt16
An 16-bit unsigned integer.
Definition: datatypes.h:122
ChildRectContainer::const_iterator ConstChildRectIterator
Const Iterator type for GridRects in relation to the children they apply to.
Whole AsWhole(Whole def=0) const
Attempts to convert the value of the attribute to a Whole and returns the results.
virtual void ProtoSerializeImpl(XML::Node &SelfRoot) const
Implementation method for serializing additional sets of data.
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
Real Y
Coordinate on the Y vector.
Definition: vector2.h:69
Child node iterator (a bidirectional iterator over a collection of Node)
Definition: nodeiterator.h:77
GridContainer(Screen *Parent)
Blank constructor.
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
iterator begin() const
Get a Child node iterator that references the first child Node.
Whole GetTopCell() const
Gets the Top cell of this Rect.
Real X
Coordinate on the X vector.
Definition: vector2.h:67
Boole operator!=(const GridVector2 &Other)
Inequality comparison operator.
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
void ProtoSerialize(XML::Node &ParentNode) const
Convert this class to an XML::Node ready for serialization.
Definition: unifieddim.h:603
This is used to represent a point on a 2 dimentional area, such as a screen.
Definition: vector2.h:63
iterator end() const
Get a Child node iterator that references one past the last child Node.
bool Empty() const
Is this storing anything at all?
This is the base class for all widgets.
Definition: widget.h:126
virtual void UnbindProvider(PageProvider *Prov)
Unbinds a provider being used by this container.
void SetIdentity()
Sets the values of this vector2 to identity values(0,0).
Definition: vector2.cpp:99
UnifiedVec2 CellSize
The size of each cell in this grid.
virtual void SetCellPadding(const UnifiedVec2 &Padding)
Sets the Unified padding to be applied on each axis to each cell in this grid.
Simple class used to represent positions or sizes on a grid.
Definition: gridcontainer.h:57
virtual void RemoveChild(Widget *ToBeRemoved)
Removes a child Widget from this quadrenderable.
static String GetSerializableName()
Get the name of the the XML tag the Renderable class will leave behind as its instances are serialize...
virtual Boole GetVisible() const
Gets the visibility setting of this renderable.
UnifiedVec2 CellPadding
The amount of space on each side of each dimension of a given cell which will be considered unusable ...
virtual void QuickUpdateWorkAreaSize(const UnifiedVec2 &ChildSize, Boole Adding)
Quickly updates the work area size based on a single childs' dimensions.
Boole Envelopes(const GridRect &Other)
Gets whether or not this GridRect completely envelopes another GridRect.
virtual void SetXProvider(PageProvider *XProv)
Sets the PageProvider for the X axis.
virtual void SetProviders(PageProvider *XProv, PageProvider *YProv)
Sets the page providers for both axes.
Boole operator!=(const GridRect &Other)
Inequality comparison operator.
std::pair< Widget *, GridRect > ChildRectPair
Convenience typedef for a child of this container and it's grid rect.
PageProvider * YProvider
A pointer to the Y axis provider.
This is the base class for interpretting widget values to page positions.
Definition: pageprovider.h:55
virtual void SetCellSize(const Whole X, const Whole Y)
Convenience method that will set the cell size of this grid via the desired number of cells within th...
Vector2 WorkAreaSize
Vector2 storing the size for all pages of this container.
void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
Definition: unifieddim.h:620
GridVector2()
Blank constructor.
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
virtual void RemoveAllChildren()
Removes all child Widgets from this QuadRenderable.
virtual Real GetCurrentXPage() const =0
Gets the current page position on the X axis.
virtual void UpdateContainerDimensionsImpl(const Rect &OldSelfRect, const Rect &NewSelfRect)
The container specific logic for updating it's dimensions.
This class represents a point in 2D space using UnifiedDim's.
Definition: unifieddim.h:306
virtual void _NotifyContainerUpdated()=0
Notifies this provider that the container it is providing page data to has been updated.
virtual void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
const Char8 * Name() const
ptrdiff_tGet the name of this Node.
VisibleChildContainer VisibleChildren
A container of children that meet the criteria for rendering in this container.
Vector2 Position
Vector2 representing the top-left position of the rect.
Definition: rect.h:69
Whole X
The Cell(s) on the X axis.
Definition: gridcontainer.h:60
virtual const UnifiedVec2 & GetCellPadding() const
Gets the Unified padding to be applied on each axis to each cell in this grid.
void SerializeError(const String &FailedTo, const String &ClassName, Boole SOrD)
Simply does some string concatenation, then throws an Exception.
virtual void DestroyChild(Widget *ToBeDestroyed)
Destroys a child Widget currently inside this QuadRenderable.
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
virtual void RemoveChild(Widget *ToBeRemoved)
Removes a child Widget from this quadrenderable.
Node AppendChild(NodeType Type=NodeElement)
Creates a Node and makes it a child of this one.
std::map< String, String > NameValuePairMap
This is a datatype mostly used for describing settings or parameters that can't be declared in advanc...
Definition: datatypes.h:209
This class is a helper class for creating UI's. It is responsible for storing and keeping track of al...
Definition: screen.h:142
void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
virtual UnifiedVec2 GetCellClientArea() const
Gets the area available to a child widget when it's placed in a single cell.
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
virtual const String & GetTypeName() const
Gets the type of widget this is.
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.
virtual void ProtoSerializeImpl(XML::Node &SelfRoot) const
Implementation method for serializing additional sets of data.