Spinning Topp Logo BlackTopp Studios
inc
sizinginfo.h
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 _uisizinginfo_h
41 #define _uisizinginfo_h
42 
43 #include "uienumerations.h"
44 #include "UI/unifieddim.h"
45 #include "vector2.h"
46 
47 namespace Mezzanine
48 {
49  namespace UI
50  {
51  ///////////////////////////////////////////////////////////////////////////////
52  /// @brief This is a helper class designed to describe the behaviors of a quad when it needs to be resized.
53  /// @details This struct contains all the information necessary to define complete behavior of
54  /// sizing child quads within a quad.
55  ///////////////////////////////////////
57  {
58  public:
59  ///////////////////////////////////////////////////////////////////////////////
60  // Public Data Members
61 
62  /// @brief Unified dimensions to be used if the resize rules permits it.
64  /// @brief The maximum permitted size.
66  /// @brief The minumum permitted size.
68  /// @brief Rules for resizing on the Y axis.
70  /// @brief Rules for resizing on the X axis.
72  /// @brief Rule for determining aspect ratio lock.
74 
75  ///////////////////////////////////////////////////////////////////////////////
76  // Construction and Destruction
77 
78  /// @brief Class constructor.
80  VerticalRules(UI::SR_Unified_Dims), HorizontalRules(UI::SR_Unified_Dims), RatioLock(UI::ARL_Ratio_Unlocked) { }
81  /// @brief Size constructor.
82  /// @param Size A UnifiedVector2 to be used if the rules provided permit it on sizing.
83  SizingInfo(const UnifiedVec2& Size) :
84  USize(Size), VerticalRules(UI::SR_Unified_Dims), HorizontalRules(UI::SR_Unified_Dims), RatioLock(UI::ARL_Ratio_Unlocked) { }
85  /// @brief Rules constructor.
86  /// @param HRules The rules to be used for resizing on the X axis.
87  /// @param VRules The rules to be used for resizing on the Y axis.
88  SizingInfo(const UI::SizingRules HRules, const UI::SizingRules VRules) :
89  VerticalRules(VRules), HorizontalRules(HRules), RatioLock(UI::ARL_Ratio_Unlocked) { }
90  /// @brief Descriptive constructor.
91  /// @param HRules The rules to be used for resizing on the X axis.
92  /// @param VRules The rules to be used for resizing on the Y axis.
93  /// @param Size A UnifiedVector2 to be used if the rules provided permit it on sizing.
94  SizingInfo(const UI::SizingRules HRules, const UI::SizingRules VRules, const UnifiedVec2& Size) :
95  USize(Size), VerticalRules(VRules), HorizontalRules(HRules), RatioLock(UI::ARL_Ratio_Unlocked) { }
96  /// @brief Copy constructor.
97  /// @param Other The other SizingInfo to copy from.
98  SizingInfo(const SizingInfo& Other) :
99  USize(Other.USize), MaxSize(Other.MaxSize), MinSize(Other.MinSize),
100  VerticalRules(Other.VerticalRules), HorizontalRules(Other.HorizontalRules), RatioLock(Other.RatioLock) { }
101  /// @brief Class destructor.
103 
104  ///////////////////////////////////////////////////////////////////////////////
105  // Utility
106 
107  /// @brief Checks to see if this will expand horizontally.
108  /// @return Returns true if this will expand on the X axis.
110  { return (this->HorizontalRules & UI::SR_Fill_Available); }
111  /// @brief Checks to see if this will expand vertically.
112  /// @return Returns true if this will expand on the Y axis.
113  inline Boole CanExpandVertically() const
114  { return (this->VerticalRules & UI::SR_Fill_Available); }
115  /// @brief Cheacks to see if this will expand horizontally or vertically.
116  /// @return Returns true if this will expand on either axis.
117  inline Boole CanExpand() const
118  { return (this->CanExpandHorizontally() || this->CanExpandVertically()); }
119 
120  ///////////////////////////////////////////////////////////////////////////////
121  // Comparison Operators
122 
123  /// @brief Equality comparison operator.
124  /// @param Other The other SizingInfo to compare to.
125  /// @return Returns true if these SizingInfo's are equal, false otherwise.
126  inline Boole operator==(const SizingInfo& Other) const
127  {
128  return ( this->USize == Other.USize &&
129  this->MaxSize == Other.MaxSize &&
130  this->MinSize == Other.MinSize &&
131  this->RatioLock == Other.RatioLock &&
132  this->VerticalRules == Other.VerticalRules &&
133  this->HorizontalRules == Other.HorizontalRules );
134  }
135  /// @brief Inequality comparison operator.
136  /// @param Other The other SizingInfo to compare to.
137  /// @return Returns true if these SizingInfo's are not equal, false otherwise.
138  inline Boole operator!=(const SizingInfo& Other) const
139  {
140  return ( this->USize != Other.USize ||
141  this->MaxSize != Other.MaxSize ||
142  this->MinSize != Other.MinSize ||
143  this->RatioLock != Other.RatioLock ||
144  this->VerticalRules != Other.VerticalRules ||
145  this->HorizontalRules != Other.HorizontalRules );
146  }
147 
148  ///////////////////////////////////////////////////////////////////////////////
149  // Serialization
150 
151  /// @brief Convert this class to an XML::Node ready for serialization.
152  /// @param ParentNode The point in the XML hierarchy that all this renderable should be appended to.
153  void ProtoSerialize(XML::Node& ParentNode) const
154  {
155  XML::Node SizingNode = ParentNode.AppendChild( SizingInfo::GetSerializableName() );
156 
157  if( SizingNode.AppendAttribute("Version").SetValue("1") &&
158  SizingNode.AppendAttribute("HorizontalRules").SetValue(this->HorizontalRules) &&
159  SizingNode.AppendAttribute("VerticalRules").SetValue(this->VerticalRules) &&
160  SizingNode.AppendAttribute("RatioLock").SetValue(static_cast<UInt32>(this->RatioLock)) )
161  {
162  XML::Node MinSizeNode = SizingNode.AppendChild("MinSize");
163  this->MinSize.ProtoSerialize( MinSizeNode );
164 
165  XML::Node MaxSizeNode = SizingNode.AppendChild("MaxSize");
166  this->MaxSize.ProtoSerialize( MaxSizeNode );
167 
168  XML::Node USizeNode = SizingNode.AppendChild("USize");
169  this->USize.ProtoSerialize( USizeNode );
170 
171  return;
172  }else{
173  SerializeError("Create XML Attribute Values",SizingInfo::GetSerializableName(),true);
174  }
175  }
176  /// @brief Take the data stored in an XML Node and overwrite this object with it.
177  /// @param SelfRoot An XML::Node containing the data to populate this class with.
178  void ProtoDeSerialize(const XML::Node& SelfRoot)
179  {
180  XML::Attribute CurrAttrib;
181  if( SelfRoot.Name() == SizingInfo::GetSerializableName() ) {
182  if(SelfRoot.GetAttribute("Version").AsInt() == 1) {
183  CurrAttrib = SelfRoot.GetAttribute("HorizontalRules");
184  if( !CurrAttrib.Empty() )
185  this->HorizontalRules = CurrAttrib.AsUint();
186 
187  CurrAttrib = SelfRoot.GetAttribute("VerticalRules");
188  if( !CurrAttrib.Empty() )
189  this->VerticalRules = CurrAttrib.AsUint();
190 
191  CurrAttrib = SelfRoot.GetAttribute("RatioLock");
192  if( !CurrAttrib.Empty() )
193  this->RatioLock = static_cast<UI::AspectRatioLock>(CurrAttrib.AsUint());
194 
195  XML::Node MinSizeNode = SelfRoot.GetChild("MinSize").GetFirstChild();
196  if( !MinSizeNode.Empty() )
197  this->MinSize.ProtoDeSerialize(MinSizeNode);
198 
199  XML::Node MaxSizeNode = SelfRoot.GetChild("MaxSize").GetFirstChild();
200  if( !MaxSizeNode.Empty() )
201  this->MaxSize.ProtoDeSerialize(MaxSizeNode);
202 
203  XML::Node USizeNode = SelfRoot.GetChild("USize").GetFirstChild();
204  if( !USizeNode.Empty() )
205  this->USize.ProtoDeSerialize(USizeNode);
206  }else{
207  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + SizingInfo::GetSerializableName() + ": Not Version 1.");
208  }
209  }else{
210  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_NOT_FOUND_EXCEPTION,SizingInfo::GetSerializableName() + " was not found in the provided XML node, which was expected.");
211  }
212  }
213  /// @brief Get the name of the the XML tag the Renderable class will leave behind as its instances are serialized.
214  /// @return A string containing the name of this class.
216  {
217  return "SizingInfo";
218  }
219  };//SizingInfo
220  }//UI
221 }//Mezzanine
222 
223 #endif
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
A light-weight handle for manipulating attributes in DOM tree.
Definition: attribute.h:74
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
SizingInfo(const UnifiedVec2 &Size)
Size constructor.
Definition: sizinginfo.h:83
Boole CanExpandVertically() const
Checks to see if this will expand vertically.
Definition: sizinginfo.h:113
SizingInfo(const UI::SizingRules HRules, const UI::SizingRules VRules)
Rules constructor.
Definition: sizinginfo.h:88
SizingInfo()
Class constructor.
Definition: sizinginfo.h:79
Boole operator!=(const SizingInfo &Other) const
Inequality comparison operator.
Definition: sizinginfo.h:138
Unified dimensions are ignored and will instead us all available space.
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
SizingInfo(const SizingInfo &Other)
Copy constructor.
Definition: sizinginfo.h:98
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
Definition: exception.h:112
UI::AspectRatioLock RatioLock
Rule for determining aspect ratio lock.
Definition: sizinginfo.h:73
bool Empty() const
Is this storing anything at all?
Whole VerticalRules
Rules for resizing on the Y axis.
Definition: sizinginfo.h:69
bool SetValue(const Char8 *rhs)
Set the value of this.
SizingInfo(const UI::SizingRules HRules, const UI::SizingRules VRules, const UnifiedVec2 &Size)
Descriptive constructor.
Definition: sizinginfo.h:94
AspectRatioLock
Used by sizing behavior classes to determine how resizes that preserve aspect ratio should behave...
Resizing will use the provided unified dimensions with no further alterations. This is the default fo...
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
unsigned int AsUint(unsigned int def=0) const
Attempts to convert the value of the attribute to an unsigned int and returns the results...
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
Boole CanExpand() const
Cheacks to see if this will expand horizontally or vertically.
Definition: sizinginfo.h:117
bool Empty() const
Is this storing anything at all?
Boole operator==(const SizingInfo &Other) const
Equality comparison operator.
Definition: sizinginfo.h:126
void ProtoSerialize(XML::Node &ParentNode) const
Convert this class to an XML::Node ready for serialization.
Definition: sizinginfo.h:153
Boole CanExpandHorizontally() const
Checks to see if this will expand horizontally.
Definition: sizinginfo.h:109
static String GetSerializableName()
Get the name of the the XML tag the Renderable class will leave behind as its instances are serialize...
Definition: sizinginfo.h:215
void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
Definition: unifieddim.h:620
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
SizingRules
Used by UI container classes to determine their resize behavior on a given axis when the container is...
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
UnifiedVec2 MinSize
The minumum permitted size.
Definition: sizinginfo.h:67
The aspect ratio is not locked and both dimensions can resize freely.
UnifiedVec2 USize
Unified dimensions to be used if the resize rules permits it.
Definition: sizinginfo.h:63
This class represents a point in 2D space using UnifiedDim's.
Definition: unifieddim.h:306
const Char8 * Name() const
ptrdiff_tGet the name of this Node.
Whole HorizontalRules
Rules for resizing on the X axis.
Definition: sizinginfo.h:71
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.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
~SizingInfo()
Class destructor.
Definition: sizinginfo.h:102
UnifiedVec2 MaxSize
The maximum permitted size.
Definition: sizinginfo.h:65
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.