MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sizinginfo.h
1 //© Copyright 2010 - 2013 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 Rule for determining aspect ratio lock.
70  /// @brief Rules for resizing on the Y axis.
72  /// @brief Rules for resizing on the X axis.
74 
75  ///////////////////////////////////////////////////////////////////////////////
76  // Construction and Destruction
77 
78  /// @brief Class constructor.
80  RatioLock(UI::ARL_Ratio_Unlocked), VerticalRules(UI::SR_Unified_Dims), HorizontalRules(UI::SR_Unified_Dims) { }
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), RatioLock(UI::ARL_Ratio_Unlocked), VerticalRules(UI::SR_Unified_Dims), HorizontalRules(UI::SR_Unified_Dims) { }
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  RatioLock(UI::ARL_Ratio_Unlocked), VerticalRules(VRules), HorizontalRules(HRules) { }
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), RatioLock(UI::ARL_Ratio_Unlocked), VerticalRules(VRules), HorizontalRules(HRules) { }
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), RatioLock(Other.RatioLock),
100  VerticalRules(Other.VerticalRules), HorizontalRules(Other.HorizontalRules) { }
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.
109  inline bool CanExpandHorizontally() const
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 bool 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 bool 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 bool 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 bool 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(static_cast<UInt32>(this->HorizontalRules)) &&
159  SizingNode.AppendAttribute("VerticalRules").SetValue(static_cast<UInt32>(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 = static_cast<UI::SizingRules>(CurrAttrib.AsUint());
186 
187  CurrAttrib = SelfRoot.GetAttribute("VerticalRules");
188  if( !CurrAttrib.Empty() )
189  this->VerticalRules = static_cast<UI::SizingRules>(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(Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + SizingInfo::GetSerializableName() + ": Not Version 1.");
208  }
209  }else{
210  MEZZ_EXCEPTION(Exception::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