MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
positioninginfo.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 _uipositioninginfo_h
41 #define _uipositioninginfo_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 repositioned.
53  /// @details This struct contains all the information necessary to define complete behavior of
54  /// positioning 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 Rules for resizing on the X axis.
66 
67  ///////////////////////////////////////////////////////////////////////////////
68  // Construction and Destruction
69 
70  /// @brief Class constructor.
72  PositionRules(UI::PF_Unified_Pos) { }
73  /// @brief PositionFlags constructor.
74  /// @param Rules The rules for determining the position of the object on a transform update.
76  PositionRules(Rules) { }
77  /// @brief Position constructor.
78  /// @param Position The unified position to use if the rules permit it.
79  PositioningInfo(const UnifiedVec2& Position) :
80  UPosition(Position), PositionRules(UI::PF_Unified_Pos) { }
81  /// @brief Descriptive constructor.
82  /// @param Rules The rules for determining the position of the object on a transform update.
83  /// @param Position The unified position to use if the rules permit it.
84  PositioningInfo(const UI::PositioningFlags Rules, const UnifiedVec2& Position) :
85  UPosition(Position), PositionRules(Rules) { }
86  /// @brief Copy constructor.
87  /// @param Other The other PositioningInfo to copy from.
89  UPosition(Other.UPosition), PositionRules(Other.PositionRules) { }
90  /// @brief Class destructor.
92 
93  ///////////////////////////////////////////////////////////////////////////////
94  // Utility
95 
96  ///////////////////////////////////////////////////////////////////////////////
97  // Comparison Operators
98 
99  /// @brief Equality comparison operator.
100  /// @param Other The other PositioningInfo to compare to.
101  /// @return Returns true if these PositioningInfo's are equal, false otherwise.
102  inline bool operator==(const PositioningInfo& Other) const
103  {
104  return this->UPosition == Other.UPosition && this->PositionRules == Other.PositionRules;
105  }
106  /// @brief Inequality comparison operator.
107  /// @param Other The other PositioningInfo to compare to.
108  /// @return Returns true if these PositioningInfo's are not equal, false otherwise.
109  inline bool operator!=(const PositioningInfo& Other) const
110  {
111  return this->UPosition != Other.UPosition || this->PositionRules != Other.PositionRules;
112  }
113 
114  ///////////////////////////////////////////////////////////////////////////////
115  // Serialization
116 
117  /// @brief Convert this class to an XML::Node ready for serialization.
118  /// @param ParentNode The point in the XML hierarchy that all this renderable should be appended to.
119  void ProtoSerialize(XML::Node& ParentNode) const
120  {
121  XML::Node PositioningNode = ParentNode.AppendChild( PositioningInfo::GetSerializableName() );
122 
123  if( PositioningNode.AppendAttribute("Version").SetValue("1") &&
124  PositioningNode.AppendAttribute("PositionRules").SetValue(static_cast<UInt32>(this->PositionRules)) )
125  {
126  XML::Node UPositionNode = PositioningNode.AppendChild("UPosition");
127  this->UPosition.ProtoSerialize( UPositionNode );
128 
129  return;
130  }else{
131  SerializeError("Create XML Attribute Values",PositioningInfo::GetSerializableName(),true);
132  }
133  }
134  /// @brief Take the data stored in an XML Node and overwrite this object with it.
135  /// @param SelfRoot An XML::Node containing the data to populate this class with.
136  void ProtoDeSerialize(const XML::Node& SelfRoot)
137  {
138  XML::Attribute CurrAttrib;
139  if( SelfRoot.Name() == PositioningInfo::GetSerializableName() ) {
140  if(SelfRoot.GetAttribute("Version").AsInt() == 1) {
141  CurrAttrib = SelfRoot.GetAttribute("PositionRules");
142  if( !CurrAttrib.Empty() )
143  this->PositionRules = static_cast<UI::PositioningFlags>(CurrAttrib.AsUint());
144 
145  XML::Node PositionNode = SelfRoot.GetChild("UPosition").GetFirstChild();
146  if( !PositionNode.Empty() )
147  this->UPosition.ProtoDeSerialize(PositionNode);
148  }else{
149  MEZZ_EXCEPTION(Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + PositioningInfo::GetSerializableName() + ": Not Version 1.");
150  }
151  }else{
152  MEZZ_EXCEPTION(Exception::II_IDENTITY_NOT_FOUND_EXCEPTION,PositioningInfo::GetSerializableName() + " was not found in the provided XML node, which was expected.");
153  }
154  }
155  /// @brief Get the name of the the XML tag the Renderable class will leave behind as its instances are serialized.
156  /// @return A string containing the name of this class.
158  {
159  return "PositioningInfo";
160  }
161  };//PositioningInfo
162  }//UI
163 }//Mezzanine
164 
165 #endif