Spinning Topp Logo BlackTopp Studios
inc
linearcontainer.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 
41 #ifndef _uilinearcontainer_cpp
42 #define _uilinearcontainer_cpp
43 
44 #include "UI/linearcontainer.h"
45 #include "UI/layoutstrategy.h"
46 
47 namespace Mezzanine
48 {
49  namespace UI
50  {
52  PagedContainer(Parent),
53  ForcedSizingRules(SE_None),
54  VisibleChildAlign(UI::LA_TopLeft)
55  { }
56 
57  LinearContainer::LinearContainer(const String& RendName, Screen* Parent) :
58  PagedContainer(RendName,Parent),
59  ForcedSizingRules(SE_None),
60  VisibleChildAlign(UI::LA_TopLeft)
61  { }
62 
63  LinearContainer::LinearContainer(const String& RendName, const UnifiedRect& RendRect, Screen* Parent) :
64  PagedContainer(RendName,RendRect,Parent),
65  ForcedSizingRules(SE_None),
66  VisibleChildAlign(UI::LA_TopLeft)
67  { }
68 
70  { }
71 
72  ///////////////////////////////////////////////////////////////////////////////
73  // Utility
74 
75  void LinearContainer::SetChildSizing(const SizingInfo& ForcedSize, const Whole Enforcement)
76  {
77  this->SetChildSize(ForcedSize);
78  this->SetChildSizeEnforcement(Enforcement);
79  }
80 
81  void LinearContainer::SetChildSize(const SizingInfo& ForcedSize)
82  { this->ChildSizing = ForcedSize; }
83 
85  { return this->ChildSizing; }
86 
88  { this->ForcedSizingRules = Enforcement; }
89 
91  { return this->ForcedSizingRules; }
92 
94  { this->LinearPadding = Padding; }
95 
97  { return this->LinearPadding; }
98 
100  { this->VisibleChildAlign = ChildAlign; }
101 
103  { return this->VisibleChildAlign; }
104 
105  ///////////////////////////////////////////////////////////////////////////////
106  // Child Management
107 
109  {
110  if( this->ForcedSizingRules & SE_OnAdd ) {
111  Child->SetSizingPolicy( this->ChildSizing );
112  }
113 
114  this->PagedContainer::AddChild(Child);
115  }
116 
117  void LinearContainer::AddChild(Widget* Child, const UInt16 ZOrder)
118  {
119  this->PagedContainer::AddChild(Child,ZOrder);
120  }
121 
122  ///////////////////////////////////////////////////////////////////////////////
123  // Serialization
124 
126  {
128  XML::Node PropertiesNode = SelfRoot.AppendChild( LinearContainer::GetSerializableName() + "Properties" );
129 
130  if( PropertiesNode.AppendAttribute("Version").SetValue("1") &&
131  PropertiesNode.AppendAttribute("ForcedSizingRules").SetValue( this->ForcedSizingRules ) &&
132  PropertiesNode.AppendAttribute("VisibleChildAlign").SetValue( static_cast<Whole>( this->VisibleChildAlign ) ) )
133  {
134  XML::Node ChildSizingNode = PropertiesNode.AppendChild("ChildSizing");
135  this->ChildSizing.ProtoSerialize( ChildSizingNode );
136  XML::Node LinearPaddingNode = PropertiesNode.AppendChild("LinearPadding");
137  this->LinearPadding.ProtoSerialize( LinearPaddingNode );
138 
139  return;
140  }else{
141  SerializeError("Create XML Attribute Values",LinearContainer::GetSerializableName() + "Properties",true);
142  }
143  }
144 
146  {
148 
149  XML::Attribute CurrAttrib;
150  XML::Node PropertiesNode = SelfRoot.GetChild( LinearContainer::GetSerializableName() + "Properties" );
151 
152  if( !PropertiesNode.Empty() ) {
153  if(PropertiesNode.GetAttribute("Version").AsInt() == 1) {
154  // Get the single data type properties
155  CurrAttrib = PropertiesNode.GetAttribute("ForcedSizingRules");
156  if( !CurrAttrib.Empty() )
157  this->ForcedSizingRules = CurrAttrib.AsWhole();
158 
159  CurrAttrib = PropertiesNode.GetAttribute("VisibleChildAlign");
160  if( !CurrAttrib.Empty() )
161  this->VisibleChildAlign = static_cast<UI::LinearAlignment>( CurrAttrib.AsWhole() );
162 
163  // Get the properties that need their own nodes
164  XML::Node ChildSizingNode = PropertiesNode.GetChild("ChildSizing").GetFirstChild();
165  if( !ChildSizingNode.Empty() )
166  this->PositioningPolicy.ProtoDeSerialize(ChildSizingNode);
167 
168  XML::Node LinearPaddingNode = PropertiesNode.GetChild("LinearPadding").GetFirstChild();
169  if( !LinearPaddingNode.Empty() )
170  this->SizingPolicy.ProtoDeSerialize(LinearPaddingNode);
171  }else{
172  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + (PagedContainer::GetSerializableName() + "Properties") + ": Not Version 1.");
173  }
174  }else{
175  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_NOT_FOUND_EXCEPTION,PagedContainer::GetSerializableName() + "Properties" + " was not found in the provided XML node, which was expected.");
176  }
177  }
178 
180  {
181  return "LinearContainer";
182  }
183 
184  ///////////////////////////////////////////////////////////////////////////////
185  // Internal Methods
186  }//UI
187 }//Mezzanine
188 
189 #endif
This is the base class for containers that have a render area and work area of different sizes...
The preset size for children of this container will only be applied when they are added to this conta...
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
UnifiedDim LinearPadding
The amount of space to add to both sides of a child object on the relevant axis.
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 void AddChild(Widget *Child)
Adds a Widget to this as a child of this quad.
PositioningInfo PositioningPolicy
This stores all the information needed to determine the specific behaviors this Quad should have when...
virtual void SetChildSizing(const SizingInfo &ForcedSize, const Whole Enforcement)
Sets both the size and enforcement rules for forced child sizing in this container.
SizingInfo SizingPolicy
This stores all the information needed to determine the specific behaviors this Quad should have when...
Thrown when the requested identity could not be found.
Definition: exception.h:94
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
This is a helper class designed to describe the behaviors of a quad when it needs to be resized...
Definition: sizinginfo.h:56
static String GetSerializableName()
Get the name of the the XML tag the Renderable class will leave behind as its instances are serialize...
virtual void SetPadding(const UnifiedDim &Padding)
Sets the spacing to be split between both sides of each child quad on the relevant axis...
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
Definition: exception.h:112
void ProtoSerialize(XML::Node &ParentNode) const
Convert this class to an XML::Node ready for serialization.
Definition: unifieddim.h:258
bool Empty() const
Is this storing anything at all?
LinearAlignment
Used by various UI classes to determine the alignment of their child objects, such as text in text li...
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
bool SetValue(const Char8 *rhs)
Set the value of this.
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
Whole AsWhole(Whole def=0) const
Attempts to convert the value of the attribute to a Whole and returns the results.
virtual const SizingInfo & GetChildSize() const
Gets the size to be given to children processed by this container if forced sizing is enabled...
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
virtual ~LinearContainer()
Class destructor.
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
Whole ForcedSizingRules
The current enforcement for child size in this container.
bool Empty() const
Is this storing anything at all?
This is the base class for all widgets.
Definition: widget.h:126
void ProtoSerialize(XML::Node &ParentNode) const
Convert this class to an XML::Node ready for serialization.
Definition: sizinginfo.h:153
virtual void SetChildSize(const SizingInfo &ForcedSize)
Sets the size to be given to children processed by this container if forced sizing is enabled...
virtual void AddChild(Widget *Child)
Adds a Widget to this as a child of this quad.
virtual void SetVisibleChildAlignment(const UI::LinearAlignment ChildAlign)
Sets the alignment for visible children of this container when they don't take up all the visible spa...
virtual void SetChildSizeEnforcement(const Whole Enforcement)
Sets when the set child sizing will be applied to any given child.
SizingInfo ChildSizing
The size given to children layed out by this container.
This class represents both the relative and absolute values that can be expressed for the values on o...
Definition: unifieddim.h:56
virtual void SetSizingPolicy(const SizingInfo &Policy)
Sets the behavior to be used when this QuadRenderable is sized.
LinearContainer(Screen *Parent)
Blank constructor.
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 Whole GetChildSizeEnforcement() const
Gets when the set child sizing will be applied to any given child.
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
void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
Definition: sizinginfo.h:178
virtual const UnifiedDim & GetPadding() const
Gets the spacing being split between both sides of each child quad on the relevant axis...
UI::LinearAlignment VisibleChildAlign
The alignment to be given to the sequence of children visible in this container.
static String GetSerializableName()
Get the name of the the XML tag the Renderable class will leave behind as its instances are serialize...
virtual UI::LinearAlignment GetVisibleChildAlignment() const
Gets the alignment for visible children of this container when they don't take up all the visible spa...
void SerializeError(const String &FailedTo, const String &ClassName, Boole SOrD)
Simply does some string concatenation, then throws an Exception.
Node AppendChild(NodeType Type=NodeElement)
Creates a Node and makes it a child of this one.
This class is a helper class for creating UI's. It is responsible for storing and keeping track of al...
Definition: screen.h:142
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.