MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
unifieddim.h
1 //© Copyright 2010 - 2012 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 _uiunifieddim_h
42 #define _uiunifieddim_h
43 
44 #include "rect.h"
45 
46 namespace Mezzanine
47 {
48  namespace UI
49  {
50  ///////////////////////////////////////////////////////////////////////////////
51  /// @class UnifiedDim
52  /// @headerfile unifieddim.h
53  /// @brief This class represents both the relative and absolute values that can be expressed for the values on one dimension for a UI renderable.
54  /// @details
55  ///////////////////////////////////////
57  {
58  public:
59  ///////////////////////////////////////////////////////////////////////////////
60  // Public Data Members
61 
62  /// @brief The relative value on this dimension.
64  /// @brief The absolute value on this dimension.
66 
67  ///////////////////////////////////////////////////////////////////////////////
68  // Construction and Destruction
69 
70  /// @brief Class constructor.
71  UnifiedDim() : Rel(0), Abs(0) {}
72  /// @brief Descriptive constructor.
73  /// @param Relative The relative portion of this dimension.
74  /// @param Absolute The absolute portion of this dimension.
75  UnifiedDim(const Real& Relative, const Real& Absolute)
76  : Rel(Relative), Abs(Absolute) {}
77  /// @brief Copy constructor.
78  /// @param Other The other UnifiedDim to copy from.
79  UnifiedDim(const UnifiedDim& Other)
80  : Rel(Other.Rel), Abs(Other.Abs) {}
81  /// @brief Class destructor.
83 
84  ///////////////////////////////////////////////////////////////////////////////
85  // Utility
86 
87  /// @brief Sets the values of this dimension.
88  /// @param Relative The relative portion of this dimension.
89  /// @param Absolute The absolute portion of this dimension.
90  inline void SetValues(const Real& Relative, const Real& Absolute)
91  {
92  this->Rel = Relative;
93  this->Abs = Absolute;
94  }
95  /// @brief Sets all values of this dimension to zero.
96  inline void SetIdentity()
97  {
98  this->Rel = 0;
99  this->Abs = 0;
100  }
101 
102  /// @brief Calculates the actual value when a Real in pixels has this unified dim applied to it.
103  /// @param Actual A Real containing the actual(pixel) dimension to use as a base for the calculation.
104  /// @return Returns a Real containing the result dimension in actual (pixel) units.
105  inline Real CalculateActualDimension(const Real& Actual) const
106  {
107  return ( (this->Rel * Actual) + this->Abs );
108  }
109 
110  ///////////////////////////////////////////////////////////////////////////////
111  // Arithmetic Operators
112 
113  /// @brief Addition operator.
114  /// @param Other The other UnifiedDim to add to this.
115  /// @return Returns a new UnifiedDim that is the result of this operation.
116  inline UnifiedDim operator+(const UnifiedDim& Other) const
117  {
118  return UnifiedDim(this->Rel + Other.Rel, this->Abs + Other.Abs);
119  }
120  /// @brief Subtraction operator.
121  /// @param Other The other UnifiedDim to subtract from this.
122  /// @return Returns a new UnifiedDim that is the result of this operation.
123  inline UnifiedDim operator-(const UnifiedDim& Other) const
124  {
125  return UnifiedDim(this->Rel - Other.Rel, this->Abs - Other.Abs);
126  }
127  /// @brief Multiplication operator.
128  /// @param Other The other UnifiedDim to multiply by.
129  /// @return Returns a new UnifiedDim that is the result of this operation.
130  inline UnifiedDim operator*(const UnifiedDim& Other) const
131  {
132  return UnifiedDim(this->Rel * Other.Rel, this->Abs * Other.Abs);
133  }
134  /// @brief Division operator.
135  /// @param Other The other UnifiedDim to divide by.
136  /// @return Returns a new UnifiedDim that is the result of this operation.
137  inline UnifiedDim operator/(const UnifiedDim& Other) const
138  {
139  return UnifiedDim(Other.Rel == 0.0f ? 0.0f : this->Rel / Other.Rel,
140  Other.Abs == 0.0f ? 0.0f : this->Abs / Other.Abs);
141  }
142 
143  /// @brief Addition assignment operator.
144  /// @param Other The other UnifiedDim to add to this.
145  /// @return Returns a reference to this.
146  inline UnifiedDim& operator+=(const UnifiedDim& Other)
147  {
148  this->Rel += Other.Rel;
149  this->Abs += Other.Abs;
150  return *this;
151  }
152  /// @brief Subtraction assignment operator.
153  /// @param Other The other UnifiedDim to subtract from this.
154  /// @return Returns a reference to this.
155  inline UnifiedDim& operator-=(const UnifiedDim& Other)
156  {
157  this->Rel -= Other.Rel;
158  this->Abs -= Other.Abs;
159  return *this;
160  }
161  /// @brief Multiplication assignment operator.
162  /// @param Other The other UnifiedDim to multiply by.
163  /// @return Returns a reference to this.
164  inline UnifiedDim& operator*=(const UnifiedDim& Other)
165  {
166  this->Rel *= Other.Rel;
167  this->Abs *= Other.Abs;
168  return *this;
169  }
170  /// @brief Division assignment operator.
171  /// @param Other The other UnifiedDim to divide by.
172  /// @return Returns a reference to this.
173  inline UnifiedDim& operator/=(const UnifiedDim& Other)
174  {
175  this->Rel = (Other.Rel == 0.0f ? 0.0f : this->Rel / Other.Rel);
176  this->Abs = (Other.Abs == 0.0f ? 0.0f : this->Abs / Other.Abs);
177  return *this;
178  }
179 
180  ///////////////////////////////////////////////////////////////////////////////
181  // Arithmetic with Real Operators
182 
183  /// @brief Multiplication with Real operator.
184  /// @param Other The Real to multiply by.
185  /// @return Returns a new UnifiedDim that is the result of this operation.
186  inline UnifiedDim operator*(const Real& Other)
187  {
188  return UnifiedDim( this->Rel * Other, this->Abs * Other );
189  }
190  /// @brief Division with Real operator.
191  /// @param Other The Real to divide by.
192  /// @return Returns a new UnifiedDim that is the result of this operation.
193  inline UnifiedDim operator/(const Real& Other)
194  {
195  return UnifiedDim( ( Other == 0 ? 0.0 : this->Rel / Other ),
196  ( Other == 0 ? 0.0 : this->Abs / Other ) );
197  }
198 
199  /// @brief Multiplication assignment with Real operator.
200  /// @param Other The Real to multiply by.
201  /// @return Returns a reference to this.
202  inline UnifiedDim& operator*=(const Real& Other)
203  {
204  this->Rel *= Other;
205  this->Abs *= Other;
206  return *this;
207  }
208  /// @brief Division assignment with Real operator.
209  /// @param Other The Real to divide by.
210  /// @return Returns a reference to this.
211  inline UnifiedDim& operator/=(const Real& Other)
212  {
213  this->Rel /= Other;
214  this->Abs /= Other;
215  return *this;
216  }
217 
218  ///////////////////////////////////////////////////////////////////////////////
219  // Comparison Operators
220 
221  /// @brief Equality comparison operator.
222  /// @param Other The other UnifiedDim to compare to.
223  /// @return Returns true if these UnifiedDim's are equal, false otherwise.
224  inline bool operator==(const UnifiedDim& Other) const
225  {
226  return this->Rel == Other.Rel && this->Abs == Other.Abs;
227  }
228  /// @brief Inequality comparison operator.
229  /// @param Other The other UnifiedDim to compare to.
230  /// @return Returns true if these UnifiedDim's are not equal, false otherwise.
231  inline bool operator!=(const UnifiedDim& Other) const
232  {
233  return this->Rel != Other.Rel || this->Abs != Other.Abs;
234  }
235 
236  ///////////////////////////////////////////////////////////////////////////////
237  // Other Operators
238 
239  /// @brief Assignment operator.
240  /// @param Other The other UnifiedDim to be assign values from.
241  /// @return Returns a reference to this.
242  inline UnifiedDim& operator=(const UnifiedDim& Other)
243  {
244  this->Rel = Other.Rel;
245  this->Abs = Other.Abs;
246  return *this;
247  }
248 
249  ///////////////////////////////////////////////////////////////////////////////
250  // Serialization
251 
252  /// @brief Convert this class to an XML::Node ready for serialization.
253  /// @param ParentNode The point in the XML hierarchy that all this renderable should be appended to.
254  void ProtoSerialize(XML::Node& ParentNode) const
255  {
256  XML::Node DimNode = ParentNode.AppendChild( UnifiedDim::GetSerializableName() );
257 
258  if( DimNode.AppendAttribute("Version").SetValue("1") &&
259  DimNode.AppendAttribute("Rel").SetValue(this->Rel) &&
260  DimNode.AppendAttribute("Abs").SetValue(this->Abs) )
261  {
262  return;
263  }else{
264  SerializeError("Create XML Attribute Values",UnifiedDim::GetSerializableName(),true);
265  }
266  }
267  /// @brief Take the data stored in an XML Node and overwrite this object with it.
268  /// @param SelfRoot An XML::Node containing the data to populate this class with.
269  void ProtoDeSerialize(const XML::Node& SelfRoot)
270  {
271  XML::Attribute CurrAttrib;
272  if( SelfRoot.Name() == UnifiedDim::GetSerializableName() ) {
273  if(SelfRoot.GetAttribute("Version").AsInt() == 1) {
274  CurrAttrib = SelfRoot.GetAttribute("Rel");
275  if( !CurrAttrib.Empty() )
276  this->Rel = CurrAttrib.AsReal();
277 
278  CurrAttrib = SelfRoot.GetAttribute("Abs");
279  if( !CurrAttrib.Empty() )
280  this->Abs = CurrAttrib.AsReal();
281  }else{
282  MEZZ_EXCEPTION(Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + UnifiedDim::GetSerializableName() + ": Not Version 1.");
283  }
284  }else{
285  MEZZ_EXCEPTION(Exception::II_IDENTITY_NOT_FOUND_EXCEPTION,UnifiedDim::GetSerializableName() + " was not found in the provided XML node, which was expected.");
286  }
287  }
288  /// @brief Get the name of the the XML tag the Renderable class will leave behind as its instances are serialized.
289  /// @return A string containing the name of this class.
291  {
292  return "UnifiedDim";
293  }
294  };//UnifiedDim
295 
296  ///////////////////////////////////////////////////////////////////////////////
297  /// @class UnifiedVec2
298  /// @headerfile unifieddim.h
299  /// @brief This class represents a point in 2D space using UnifiedDim's.
300  /// @details
301  ///////////////////////////////////////
303  {
304  public:
305  ///////////////////////////////////////////////////////////////////////////////
306  // Public Data Members
307 
308  /// @brief The dimension on the X plane.
310  /// @brief The dimension on the Y plane.
312 
313  ///////////////////////////////////////////////////////////////////////////////
314  // Construction and Destruction
315 
316  /// @brief Class constructor.
318  {
319  this->X.SetIdentity();
320  this->Y.SetIdentity();
321  }
322  /// @brief UnifiedDim constructor.
323  /// @param x The dimension on the X plane.
324  /// @param y The dimension on the Y plane.
325  UnifiedVec2(const UnifiedDim& x, const UnifiedDim& y)
326  : X(x), Y(y) {}
327  /// @brief Real constructor.
328  /// @param Xrel The relative portion of the X dimension.
329  /// @param Yrel The relative portion of the Y dimension.
330  /// @param Xabs The absolute portion of the X dimension.
331  /// @param Yabs the absolute portion of the Y dimension.
332  UnifiedVec2(const Real& Xrel, const Real& Yrel, const Real& Xabs, const Real& Yabs)
333  {
334  this->X.SetValues(Xrel,Xabs);
335  this->Y.SetValues(Yrel,Yabs);
336  }
337  /// @brief Copy constructor.
338  /// @param Other The other UnifiedVec2 to copy from.
339  UnifiedVec2(const UnifiedVec2& Other)
340  : X(Other.X), Y(Other.Y) {}
341  /// @brief Class destructor.
343 
344  ///////////////////////////////////////////////////////////////////////////////
345  // Utility
346 
347  /// @brief Sets all data members of this unified vector explicitly.
348  /// @param x The dimension on the X plane.
349  /// @param y The dimension on the Y plane.
350  inline void SetValues(const UnifiedDim& x, const UnifiedDim& y)
351  {
352  this->X = x;
353  this->Y = y;
354  }
355  /// @brief Sets all data members of this unified vector explicitly.
356  /// @param Xrel The relative portion of the X dimension.
357  /// @param Yrel The relative portion of the Y dimension.
358  /// @param Xabs The absolute portion of the X dimension.
359  /// @param Yabs the absolute portion of the Y dimension.
360  inline void SetValues(const Real& Xrel, const Real& Yrel, const Real& Xabs, const Real& Yabs)
361  {
362  this->X.SetValues(Xrel,Xabs);
363  this->Y.SetValues(Yrel,Yabs);
364  }
365  /// @brief Sets all members of this unified vector to zero.
366  inline void SetIdentity()
367  {
368  this->X.SetIdentity();
369  this->Y.SetIdentity();
370  }
371 
372  /// @brief Calculates the actual values when a Vector2 with actual dimensions has this unified vector2 applied to it.
373  /// @param Actual A Vector2 containing the actual(pixel) dimensions to use as a base for the calculation.
374  /// @return Returns a Vector2 containing the result dimensions in actual (pixel) units.
375  inline Vector2 CalculateActualDimensions(const Vector2& Actual) const
376  {
377  return Vector2( this->X.CalculateActualDimension(Actual.X),
378  this->Y.CalculateActualDimension(Actual.Y) );
379  }
380 
381  ///////////////////////////////////////////////////////////////////////////////
382  // Arithmetic Operators
383 
384  /// @brief Addition operator.
385  /// @param Other The other UnifiedVec2 to add to this.
386  /// @return Returns a new UnifiedVec2 that is the result of this operation.
387  inline UnifiedVec2 operator+(const UnifiedVec2& Other) const
388  {
389  return UnifiedVec2(this->X + Other.X, this->Y + Other.Y);
390  }
391  /// @brief Subtraction operator.
392  /// @param Other The other UnifiedVec2 to subtract from this.
393  /// @return Returns a new UnifiedVec2 that is the result of this operation.
394  inline UnifiedVec2 operator-(const UnifiedVec2& Other) const
395  {
396  return UnifiedVec2(this->X - Other.X, this->Y - Other.Y);
397  }
398  /// @brief Multiplication operator.
399  /// @param Other The other UnifiedVec2 to multiply by.
400  /// @return Returns a new UnifiedVec2 that is the result of this operation.
401  inline UnifiedVec2 operator*(const UnifiedVec2& Other) const
402  {
403  return UnifiedVec2(this->X * Other.X, this->Y * Other.Y);
404  }
405  /// @brief Division operator.
406  /// @param Other The other UnifiedVec2 to divide by.
407  /// @return Returns a new UnifiedVec2 that is the result of this operation.
408  inline UnifiedVec2 operator/(const UnifiedVec2& Other) const
409  {
410  return UnifiedVec2(this->X / Other.X,
411  this->Y / Other.Y);
412  }
413 
414  /// @brief Addition assignment operator.
415  /// @param Other The other UnifiedVec2 to add to this.
416  /// @return Returns a reference to this.
417  inline UnifiedVec2& operator+=(const UnifiedVec2& Other)
418  {
419  this->X += Other.X;
420  this->Y += Other.Y;
421  return *this;
422  }
423  /// @brief Subtraction assignment operator.
424  /// @param Other The other UnifiedVec2 to subtract from this.
425  /// @return Returns a reference to this.
426  inline UnifiedVec2& operator-=(const UnifiedVec2& Other)
427  {
428  this->X -= Other.X;
429  this->Y -= Other.Y;
430  return *this;
431  }
432  /// @brief Multiplication assignment operator.
433  /// @param Other The other UnifiedVec2 to multiply by.
434  /// @return Returns a reference to this.
435  inline UnifiedVec2& operator*=(const UnifiedVec2& Other)
436  {
437  this->X *= Other.X;
438  this->Y *= Other.Y;
439  return *this;
440  }
441  /// @brief Division assignment operator.
442  /// @param Other The other UnifiedVec2 to divide by.
443  /// @return Returns a reference to this.
444  inline UnifiedVec2& operator/=(const UnifiedVec2& Other)
445  {
446  this->X = this->X / Other.X;
447  this->Y = this->Y / Other.Y;
448  return *this;
449  }
450 
451  ///////////////////////////////////////////////////////////////////////////////
452  // Arithmetic with UnifiedDim Operators
453 
454  /// @brief Addition with UnifiedDim operator.
455  /// @param Other The other UnifiedDim to add to this.
456  /// @return Returns a new UnifiedDim that is the result of this operation.
457  inline UnifiedVec2 operator+(const UnifiedDim& Other) const
458  {
459  return UnifiedVec2(this->X + Other, this->Y + Other);
460  }
461  /// @brief Subtraction with UnifiedDim operator.
462  /// @param Other The other UnifiedDim to subtract from this.
463  /// @return Returns a new UnifiedDim that is the result of this operation.
464  inline UnifiedVec2 operator-(const UnifiedDim& Other) const
465  {
466  return UnifiedVec2(this->X - Other, this->Y - Other);
467  }
468  /// @brief Multiplication with UnifiedDim operator.
469  /// @param Other The other UnifiedDim to multiply by.
470  /// @return Returns a new UnifiedDim that is the result of this operation.
471  inline UnifiedVec2 operator*(const UnifiedDim& Other) const
472  {
473  return UnifiedVec2(this->X * Other, this->Y * Other);
474  }
475  /// @brief Division with UnifiedDim operator.
476  /// @param Other The other UnifiedDim to divide by.
477  /// @return Returns a new UnifiedDim that is the result of this operation.
478  inline UnifiedVec2 operator/(const UnifiedDim& Other) const
479  {
480  return UnifiedVec2(this->X / Other,
481  this->Y / Other);
482  }
483 
484  /// @brief Addition assignment with UnifiedDim operator.
485  /// @param Other The other UnifiedDim to add to this.
486  /// @return Returns a reference to this.
487  inline UnifiedVec2& operator+=(const UnifiedDim& Other)
488  {
489  this->X += Other;
490  this->Y += Other;
491  return *this;
492  }
493  /// @brief Subtraction assignment with UnifiedDim operator.
494  /// @param Other The other UnifiedDim to subtract from this.
495  /// @return Returns a reference to this.
496  inline UnifiedVec2& operator-=(const UnifiedDim& Other)
497  {
498  this->X -= Other;
499  this->Y -= Other;
500  return *this;
501  }
502  /// @brief Multiplication assignment with UnifiedDim operator.
503  /// @param Other The other UnifiedDim to multiply by.
504  /// @return Returns a reference to this.
505  inline UnifiedVec2& operator*=(const UnifiedDim& Other)
506  {
507  this->X *= Other;
508  this->Y *= Other;
509  return *this;
510  }
511  /// @brief Division assignment with UnifiedDim operator.
512  /// @param Other The other UnifiedDim to divide by.
513  /// @return Returns a reference to this.
514  inline UnifiedVec2& operator/=(const UnifiedDim& Other)
515  {
516  this->X = this->X / Other;
517  this->Y = this->Y / Other;
518  return *this;
519  }
520 
521  ///////////////////////////////////////////////////////////////////////////////
522  // Arithmetic with Real Operators
523 
524  /// @brief Multiplication with Real operator.
525  /// @param Other The Real to multiply by.
526  /// @return Returns a new UnifiedVec2 that is the result of this operation.
527  inline UnifiedVec2 operator*(const Real& Other)
528  {
529  return UnifiedVec2( this->X * Other, this->Y * Other );
530  }
531  /// @brief Division with Real operator.
532  /// @param Other The Real to divide by.
533  /// @return Returns a new UnifiedVec2 that is the result of this operation.
534  inline UnifiedVec2 operator/(const Real& Other)
535  {
536  return UnifiedVec2( this->X / Other, this->Y / Other );
537  }
538 
539  /// @brief Multiplication assignment with Real operator.
540  /// @param Other The Real to multiply by.
541  /// @return Returns a reference to this.
542  inline UnifiedVec2& operator*=(const Real& Other)
543  {
544  this->X *= Other;
545  this->Y *= Other;
546  return *this;
547  }
548  /// @brief Division assignment with Real operator.
549  /// @param Other The Real to divide by.
550  /// @return Returns a reference to this.
551  inline UnifiedVec2& operator/=(const Real& Other)
552  {
553  this->X /= Other;
554  this->Y /= Other;
555  return *this;
556  }
557 
558  ///////////////////////////////////////////////////////////////////////////////
559  // Comparison Operators
560 
561  /// @brief Equality comparison operator.
562  /// @param Other The other UnifiedVec2 to compare to.
563  /// @return Returns true if these UnifiedVec2's are equal, false otherwise.
564  inline bool operator==(const UnifiedVec2& Other) const
565  {
566  return this->X == Other.X && this->Y == Other.Y;
567  }
568  /// @brief Inequality comparison operator.
569  /// @param Other The other UnifiedVec2 to compare to.
570  /// @return Returns true if these UnifiedVec2's are not equal, false otherwise.
571  inline bool operator!=(const UnifiedVec2& Other) const
572  {
573  return this->X != Other.X || this->Y != Other.Y;
574  }
575 
576  ///////////////////////////////////////////////////////////////////////////////
577  // Other Operators
578 
579  /// @brief Assignment operator.
580  /// @param Other The other UnifiedVec2 to be assign values from.
581  /// @return Returns a reference to this.
582  inline UnifiedVec2& operator=(const UnifiedVec2& Other)
583  {
584  this->X = Other.X;
585  this->Y = Other.Y;
586  return *this;
587  }
588 
589  ///////////////////////////////////////////////////////////////////////////////
590  // Serialization
591 
592  /// @brief Convert this class to an XML::Node ready for serialization.
593  /// @param ParentNode The point in the XML hierarchy that all this renderable should be appended to.
594  void ProtoSerialize(XML::Node& ParentNode) const
595  {
596  XML::Node Vec2Node = ParentNode.AppendChild( UnifiedVec2::GetSerializableName() );
597 
598  if( Vec2Node.AppendAttribute("Version").SetValue("1") &&
599  Vec2Node.AppendAttribute("XRel").SetValue(this->X.Rel) &&
600  Vec2Node.AppendAttribute("YRel").SetValue(this->Y.Rel) &&
601  Vec2Node.AppendAttribute("XAbs").SetValue(this->X.Abs) &&
602  Vec2Node.AppendAttribute("YAbs").SetValue(this->Y.Abs) )
603  {
604  return;
605  }else{
606  SerializeError("Create XML Attribute Values",UnifiedVec2::GetSerializableName(),true);
607  }
608  }
609  /// @brief Take the data stored in an XML Node and overwrite this object with it.
610  /// @param SelfRoot An XML::Node containing the data to populate this class with.
611  void ProtoDeSerialize(const XML::Node& SelfRoot)
612  {
613  XML::Attribute CurrAttrib;
614  if( SelfRoot.Name() == UnifiedVec2::GetSerializableName() ) {
615  if(SelfRoot.GetAttribute("Version").AsInt() == 1) {
616  CurrAttrib = SelfRoot.GetAttribute("XRel");
617  if( !CurrAttrib.Empty() )
618  this->X.Rel = CurrAttrib.AsReal();
619 
620  CurrAttrib = SelfRoot.GetAttribute("YRel");
621  if( !CurrAttrib.Empty() )
622  this->Y.Rel = CurrAttrib.AsReal();
623 
624  CurrAttrib = SelfRoot.GetAttribute("XAbs");
625  if( !CurrAttrib.Empty() )
626  this->X.Abs = CurrAttrib.AsReal();
627 
628  CurrAttrib = SelfRoot.GetAttribute("YAbs");
629  if( !CurrAttrib.Empty() )
630  this->Y.Abs = CurrAttrib.AsReal();
631  }else{
632  MEZZ_EXCEPTION(Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + UnifiedVec2::GetSerializableName() + ": Not Version 1.");
633  }
634  }else{
635  MEZZ_EXCEPTION(Exception::II_IDENTITY_NOT_FOUND_EXCEPTION,UnifiedVec2::GetSerializableName() + " was not found in the provided XML node, which was expected.");
636  }
637  }
638  /// @brief Get the name of the the XML tag the Renderable class will leave behind as its instances are serialized.
639  /// @return A string containing the name of this class.
641  {
642  return "UnifiedVec2";
643  }
644  };//UnifiedVec2
645 
646  ///////////////////////////////////////////////////////////////////////////////
647  /// @class UnifiedRect
648  /// @headerfile unifieddim.h
649  /// @brief This class represents a 2D rect which can express the size and position of a renderable on screen.
650  /// @details
651  ///////////////////////////////////////
653  {
654  public:
655  ///////////////////////////////////////////////////////////////////////////////
656  // Public Data Members
657 
658  /// @brief The top left position of this rect.
660  /// @brief The width and height of this rect.
662 
663  ///////////////////////////////////////////////////////////////////////////////
664  // Construction and Destruction
665 
666  /// @brief Class constructor.
668  {
669  this->Position.SetIdentity();
670  this->Size.SetIdentity();
671  }
672  /// @brief UnifiedVec2 constructor.
673  /// @param Pos The screen position of the rect.
674  /// @param Area The width and height of the rect.
675  UnifiedRect(const UnifiedVec2& Pos, const UnifiedVec2& Area)
676  : Position(Pos), Size(Area) {}
677  /// @brief UnifiedDim constructor.
678  /// @param PositionX The position on the X plane.
679  /// @param PositionY The position on the Y plane.
680  /// @param SizeX The size on the X plane.
681  /// @param SizeY The size on the Y plane.
682  UnifiedRect(const UnifiedDim& PositionX, const UnifiedDim& PositionY, const UnifiedDim& SizeX, const UnifiedDim& SizeY)
683  {
684  this->Position.SetValues(PositionX,PositionY);
685  this->Size.SetValues(SizeX,SizeY);
686  }
687  /// @brief Real constructor.
688  /// @param PositionXrel The relative position portion of the X dimension.
689  /// @param PositionYrel The relative position portion of the Y dimension.
690  /// @param SizeXrel The relative size portion of the X dimension.
691  /// @param SizeYrel The relative size portion of the Y dimension.
692  /// @param PositionXabs The absolute position portion of the X dimension.
693  /// @param PositionYabs the absolute position portion of the Y dimension.
694  /// @param SizeXabs The absolute size portion of the X dimension.
695  /// @param SizeYabs the absolute size portion of the Y dimension.
696  UnifiedRect(const Real& PositionXrel, const Real& PositionYrel, const Real& SizeXrel, const Real& SizeYrel,
697  const Real& PositionXabs, const Real& PositionYabs, const Real& SizeXabs, const Real& SizeYabs)
698  {
699  this->Position.SetValues(PositionXrel,PositionYrel,PositionXabs,PositionYabs);
700  this->Size.SetValues(SizeXrel,SizeYrel,SizeXabs,SizeYabs);
701  }
702  /// @brief Class destructor.
704 
705  ///////////////////////////////////////////////////////////////////////////////
706  // Utility
707 
708  /// @brief Sets all data members of this unified rect explicitly.
709  /// @param Position The screen position of the rect.
710  /// @param Area The width and height of the rect.
711  inline void SetValues(const UnifiedVec2& Pos, const UnifiedVec2& Area)
712  {
713  this->Position = Pos;
714  this->Size = Area;
715  }
716  /// @brief Sets all data members of this unified rect explicitly.
717  /// @param PositionX The position on the X plane.
718  /// @param PositionY The position on the Y plane.
719  /// @param SizeX The size on the X plane.
720  /// @param SizeY The size on the Y plane.
721  inline void SetValues(const UnifiedDim& PositionX, const UnifiedDim& PositionY, const UnifiedDim& SizeX, const UnifiedDim& SizeY)
722  {
723  this->Position.SetValues(PositionX,PositionY);
724  this->Size.SetValues(SizeX,SizeY);
725  }
726  /// @brief Sets all data members of this unified rect explicitly.
727  /// @param PositionXrel The relative position portion of the X dimension.
728  /// @param PositionYrel The relative position portion of the Y dimension.
729  /// @param SizeXrel The relative size portion of the X dimension.
730  /// @param SizeYrel The relative size portion of the Y dimension.
731  /// @param PositionXabs The absolute position portion of the X dimension.
732  /// @param PositionYabs the absolute position portion of the Y dimension.
733  /// @param SizeXabs The absolute size portion of the X dimension.
734  /// @param SizeYabs the absolute size portion of the Y dimension.
735  inline void SetValues(const Real& PositionXrel, const Real& PositionYrel, const Real& SizeXrel, const Real& SizeYrel,
736  const Real& PositionXabs, const Real& PositionYabs, const Real& SizeXabs, const Real& SizeYabs)
737  {
738  this->Position.SetValues(PositionXrel,PositionYrel,PositionXabs,PositionYabs);
739  this->Size.SetValues(SizeXrel,SizeYrel,SizeXabs,SizeYabs);
740  }
741  /// @brief Sets all members of this unified rect to zero.
742  inline void SetIdentity()
743  {
744  this->Position.SetIdentity();
745  this->Size.SetIdentity();
746  }
747 
748  /// @brief Calculates the actual values when a Rect with actual dimensions has this unified rect applied to it.
749  /// @param Actual A Rect containing the actual(pixel) position and size to use as a base for the calculation.
750  /// @return Returns a Rect containing the result position and size in actual (pixel) units.
751  inline Rect CalculateActualDimensions(const Rect& Actual, bool AsChild = true) const
752  {
753  Vector2 Pos = this->Position.CalculateActualDimensions(Actual.Size);
754  Vector2 Size = this->Size.CalculateActualDimensions(Actual.Size);
755  return Rect( ( AsChild ? Pos + Actual.Position : Pos ), Size );
756  }
757 
758  ///////////////////////////////////////////////////////////////////////////////
759  // Comparison Operators
760 
761  /// @brief Equality comparison operator.
762  /// @param Other The other UnifiedRect to compare to.
763  /// @return Returns true if these UnifiedRect's are equal, false otherwise.
764  inline bool operator==(const UnifiedRect& Other) const
765  {
766  return this->Position == Other.Position && this->Size == Other.Size;
767  }
768  /// @brief Inequality comparison operator.
769  /// @param Other The other UnifiedRect to compare to.
770  /// @return Returns true if these UnifiedRect's are not equal, false otherwise.
771  inline bool operator!=(const UnifiedRect& Other) const
772  {
773  return this->Position != Other.Position || this->Size != Other.Size;
774  }
775 
776  ///////////////////////////////////////////////////////////////////////////////
777  // Other Operators
778 
779  /// @brief Assignment operator.
780  /// @param Other The other UnifiedRect to be assign values from.
781  /// @return Returns a reference to this.
782  inline UnifiedRect& operator=(const UnifiedRect& Other)
783  {
784  this->Position = Other.Position;
785  this->Size = Other.Size;
786  return *this;
787  }
788 
789  ///////////////////////////////////////////////////////////////////////////////
790  // Serialization
791 
792  /// @brief Convert this class to an XML::Node ready for serialization.
793  /// @param ParentNode The point in the XML hierarchy that all this renderable should be appended to.
794  void ProtoSerialize(XML::Node& ParentNode) const
795  {
796  XML::Node RectNode = ParentNode.AppendChild( UnifiedRect::GetSerializableName() );
797 
798  if( RectNode.AppendAttribute("Version").SetValue("1") &&
799  RectNode.AppendAttribute("PositionXRel").SetValue(this->Position.X.Rel) &&
800  RectNode.AppendAttribute("PositionYRel").SetValue(this->Position.Y.Rel) &&
801  RectNode.AppendAttribute("SizeXRel").SetValue(this->Size.X.Rel) &&
802  RectNode.AppendAttribute("SizeYRel").SetValue(this->Size.Y.Rel) &&
803  RectNode.AppendAttribute("PositionXAbs").SetValue(this->Position.X.Abs) &&
804  RectNode.AppendAttribute("PositionYAbs").SetValue(this->Position.Y.Abs) &&
805  RectNode.AppendAttribute("SizeXAbs").SetValue(this->Size.X.Abs) &&
806  RectNode.AppendAttribute("SizeYAbs").SetValue(this->Size.Y.Abs) )
807  {
808  return;
809  }else{
810  SerializeError("Create XML Attribute Values",UnifiedRect::GetSerializableName(),true);
811  }
812  }
813  /// @brief Take the data stored in an XML Node and overwrite this object with it.
814  /// @param SelfRoot An XML::Node containing the data to populate this class with.
815  void ProtoDeSerialize(const XML::Node& SelfRoot)
816  {
817  XML::Attribute CurrAttrib;
818  if( SelfRoot.Name() == UnifiedRect::GetSerializableName() ) {
819  if(SelfRoot.GetAttribute("Version").AsInt() == 1) {
820  CurrAttrib = SelfRoot.GetAttribute("PositionXRel");
821  if( !CurrAttrib.Empty() )
822  this->Position.X.Rel = CurrAttrib.AsReal();
823 
824  CurrAttrib = SelfRoot.GetAttribute("PositionYRel");
825  if( !CurrAttrib.Empty() )
826  this->Position.Y.Rel = CurrAttrib.AsReal();
827 
828  CurrAttrib = SelfRoot.GetAttribute("SizeXRel");
829  if( !CurrAttrib.Empty() )
830  this->Size.X.Rel = CurrAttrib.AsReal();
831 
832  CurrAttrib = SelfRoot.GetAttribute("SizeYRel");
833  if( !CurrAttrib.Empty() )
834  this->Size.Y.Rel = CurrAttrib.AsReal();
835 
836  CurrAttrib = SelfRoot.GetAttribute("PositionXAbs");
837  if( !CurrAttrib.Empty() )
838  this->Position.X.Abs = CurrAttrib.AsReal();
839 
840  CurrAttrib = SelfRoot.GetAttribute("PositionYAbs");
841  if( !CurrAttrib.Empty() )
842  this->Position.Y.Abs = CurrAttrib.AsReal();
843 
844  CurrAttrib = SelfRoot.GetAttribute("SizeXAbs");
845  if( !CurrAttrib.Empty() )
846  this->Size.X.Abs = CurrAttrib.AsReal();
847 
848  CurrAttrib = SelfRoot.GetAttribute("SizeYAbs");
849  if( !CurrAttrib.Empty() )
850  this->Size.Y.Abs = CurrAttrib.AsReal();
851  }else{
852  MEZZ_EXCEPTION(Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + UnifiedRect::GetSerializableName() + ": Not Version 1.");
853  }
854  }else{
855  MEZZ_EXCEPTION(Exception::II_IDENTITY_NOT_FOUND_EXCEPTION,UnifiedRect::GetSerializableName() + " was not found in the provided XML node, which was expected.");
856  }
857  }
858  /// @brief Get the name of the the XML tag the Renderable class will leave behind as its instances are serialized.
859  /// @return A string containing the name of this class.
861  {
862  return "UnifiedRect";
863  }
864  };//UnifiedRect
865  }//UI
866 }//Mezzanine
867 
868 #endif