Spinning Topp Logo BlackTopp Studios
inc
positioninginfo.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 _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 determining the position of a quad on the X axis.
66  /// @brief Rules for determining the position of a quad on the Y axis.
68 
69  ///////////////////////////////////////////////////////////////////////////////
70  // Construction and Destruction
71 
72  /// @brief Class constructor.
74  HorizontalRules(UI::PF_Unified_Pos), VerticalRules(UI::PF_Unified_Pos) { }
75  /// @brief PositionFlags constructor.
76  /// @param HRules The rules for determining the position of an object on the X axis during a transform update.
77  /// @param VRules The rules for determining the position of an object on the Y axis during a transform update.
78  PositioningInfo(const Whole HRules, const Whole VRules) :
79  HorizontalRules(HRules), VerticalRules(VRules) { }
80  /// @brief Position constructor.
81  /// @param Position The unified position to use if the rules permit it.
82  PositioningInfo(const UnifiedVec2& Position) :
83  UPosition(Position), HorizontalRules(UI::PF_Unified_Pos), VerticalRules(UI::PF_Unified_Pos) { }
84  /// @brief Descriptive constructor.
85  /// @param HRules The rules for determining the position of an object on the X axis during a transform update.
86  /// @param VRules The rules for determining the position of an object on the Y axis during a transform update.
87  /// @param Position The unified position to use if the rules permit it.
88  PositioningInfo(const Whole HRules, const Whole VRules, const UnifiedVec2& Position) :
89  UPosition(Position), HorizontalRules(HRules), VerticalRules(VRules) { }
90  /// @brief Copy constructor.
91  /// @param Other The other PositioningInfo to copy from.
93  UPosition(Other.UPosition), HorizontalRules(Other.HorizontalRules), VerticalRules(Other.VerticalRules) { }
94  /// @brief Class destructor.
96 
97  ///////////////////////////////////////////////////////////////////////////////
98  // Utility
99 
100  ///////////////////////////////////////////////////////////////////////////////
101  // Comparison Operators
102 
103  /// @brief Equality comparison operator.
104  /// @param Other The other PositioningInfo to compare to.
105  /// @return Returns true if these PositioningInfo's are equal, false otherwise.
106  inline Boole operator==(const PositioningInfo& Other) const
107  { return this->UPosition == Other.UPosition && this->HorizontalRules == Other.HorizontalRules && this->VerticalRules == Other.VerticalRules; }
108  /// @brief Inequality comparison operator.
109  /// @param Other The other PositioningInfo to compare to.
110  /// @return Returns true if these PositioningInfo's are not equal, false otherwise.
111  inline Boole operator!=(const PositioningInfo& Other) const
112  { return this->UPosition != Other.UPosition || this->HorizontalRules != Other.HorizontalRules || this->VerticalRules == Other.VerticalRules; }
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("HorizontalRules").SetValue( this->HorizontalRules ) &&
125  PositioningNode.AppendAttribute("VerticalRules").SetValue( this->VerticalRules ) )
126  {
127  XML::Node UPositionNode = PositioningNode.AppendChild("UPosition");
128  this->UPosition.ProtoSerialize( UPositionNode );
129 
130  return;
131  }else{
132  SerializeError("Create XML Attribute Values",PositioningInfo::GetSerializableName(),true);
133  }
134  }
135  /// @brief Take the data stored in an XML Node and overwrite this object with it.
136  /// @param SelfRoot An XML::Node containing the data to populate this class with.
137  void ProtoDeSerialize(const XML::Node& SelfRoot)
138  {
139  XML::Attribute CurrAttrib;
140  if( SelfRoot.Name() == PositioningInfo::GetSerializableName() ) {
141  if(SelfRoot.GetAttribute("Version").AsInt() == 1) {
142  CurrAttrib = SelfRoot.GetAttribute("HorizontalRules");
143  if( !CurrAttrib.Empty() )
144  this->HorizontalRules = CurrAttrib.AsWhole();
145 
146  CurrAttrib = SelfRoot.GetAttribute("VerticalRules");
147  if( !CurrAttrib.Empty() )
148  this->VerticalRules = CurrAttrib.AsWhole();
149 
150  XML::Node PositionNode = SelfRoot.GetChild("UPosition").GetFirstChild();
151  if( !PositionNode.Empty() )
152  this->UPosition.ProtoDeSerialize(PositionNode);
153  }else{
154  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + PositioningInfo::GetSerializableName() + ": Not Version 1.");
155  }
156  }else{
157  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_NOT_FOUND_EXCEPTION,PositioningInfo::GetSerializableName() + " was not found in the provided XML node, which was expected.");
158  }
159  }
160  /// @brief Get the name of the the XML tag the Renderable class will leave behind as its instances are serialized.
161  /// @return A string containing the name of this class.
163  { return "PositioningInfo"; }
164  };//PositioningInfo
165  }//UI
166 }//Mezzanine
167 
168 #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
static String GetSerializableName()
Get the name of the the XML tag the Renderable class will leave behind as its instances are serialize...
Does not anchor to any side, using only the provided unified dimensions.
PositioningInfo(const Whole HRules, const Whole VRules)
PositionFlags constructor.
Whole VerticalRules
Rules for determining the position of a quad on the Y axis.
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
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.
bool Empty() const
Is this storing anything at all?
PositioningInfo()
Class constructor.
PositioningInfo(const UnifiedVec2 &Position)
Position constructor.
bool SetValue(const Char8 *rhs)
Set the value of this.
Whole AsWhole(Whole def=0) const
Attempts to convert the value of the attribute to a Whole and returns the results.
~PositioningInfo()
Class destructor.
Boole operator!=(const PositioningInfo &Other) const
Inequality comparison operator.
PositioningInfo(const PositioningInfo &Other)
Copy constructor.
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. ...
void ProtoSerialize(XML::Node &ParentNode) const
Convert this class to an XML::Node ready for serialization.
Definition: unifieddim.h:603
bool Empty() const
Is this storing anything at all?
Whole HorizontalRules
Rules for determining the position of a quad on the X axis.
UnifiedVec2 UPosition
Unified dimensions to be used if the resize rules permits it.
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...
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
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.
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.
Boole operator==(const PositioningInfo &Other) const
Equality comparison operator.
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.
This is a helper class designed to describe the behaviors of a quad when it needs to be repositioned...
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.
PositioningInfo(const Whole HRules, const Whole VRules, const UnifiedVec2 &Position)
Descriptive constructor.