Spinning Topp Logo BlackTopp Studios
inc
resolution.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 _graphicsresolution_h
41 #define _graphicsresolution_h
42 
43 #include "datatypes.h"
44 #include "XML/xml.h"
45 
46 #include "serialization.h"
47 #include "exception.h"
48 
49 namespace Mezzanine
50 {
51  namespace Graphics
52  {
53  ///////////////////////////////////////////////////////////////////////////////
54  /// @brief This stores all the basic configuration options a game window supports.
55  /// @details
56  ///////////////////////////////////////
58  {
59  public:
60  ///////////////////////////////////////////////////////////////////////////////
61  // Public Data Members
62 
63  /// @brief The pixel width of the window.
65  /// @brief The pixel height of the window.
67 
68  ///////////////////////////////////////////////////////////////////////////////
69  // Construction and Destruction
70 
71  /// @brief Blank constructor.
73  Width(0),
74  Height(0)
75  { }
76 
77  /// @brief Descriptive constructor.
78  /// @param ResWidth The pixel width of the window.
79  /// @param ResHeight The pixel height of the window.
80  Resolution(const Whole ResWidth, const Whole ResHeight) :
81  Width(ResWidth),
82  Height(ResHeight)
83  { }
84 
85  /// @brief Class destructor.
87  { }
88 
89  ///////////////////////////////////////////////////////////////////////////////
90  // Utility
91 
92  /// @brief Sets the width and height of this resolution.
93  /// @param ResWidth The pixel width of the window.
94  /// @param ResHeight The pixel height of the window.
95  void SetResolution(const Whole ResWidth, const Whole ResHeight)
96  {
97  this->Width = ResWidth;
98  this->Height = ResHeight;
99  }
100 
101  /// @brief Converts the values of this Resolution to a human readable string.
102  /// @remarks The format for the presented string is "[Width]x[Height]". For example: "1024x768".
103  /// @return Returns a string containing the width and height of this resolution.
105  {
106  StringStream ResStream;
107  ResStream << this->Width << "x" << this->Height;
108  return ResStream.str();
109  }
110 
111  ///////////////////////////////////////////////////////////////////////////////
112  // Operators
113 
114  /// @brief Assignment operator.
115  /// @param Other The other Resolution to copy from.
116  /// @return Returns a reference to this.
118  {
119  this->Width = Other.Width;
120  this->Height = Other.Height;
121  return *this;
122  }
123 
124  /// @brief Equality comparison operator.
125  /// @param Other The other Resolution to compare with.
126  /// @return Returns true if this Resolution is equal to the other Resolution, false otherwise.
127  Boole operator==(const Resolution& Other) const
128  {
129  return ( this->Width == Other.Width && this->Height == Other.Height );
130  }
131  /// @brief Inequality comparison operator.
132  /// @param Other The other Resolution to compare with.
133  /// @return Returns true if this Resolution is not equal to the other Resolution, false otherwise.
134  Boole operator!=(const Resolution& Other) const
135  {
136  return ( this->Width != Other.Width || this->Height != Other.Height );
137  }
138  /// @brief Less-than operator.
139  /// @param Other The other Resolution to compare with.
140  /// @return Returns true if this Resolution is smaller than the other Resolution, false otherwise.
141  Boole operator<(const Resolution& Other) const
142  {
143  if( this->Width == Other.Width ) {
144  return ( this->Height < Other.Height );
145  }else{
146  return ( this->Width < Other.Width );
147  }
148  }
149  /// @brief Greater-than operator.
150  /// @param Other The other Resolution to compare with.
151  /// @return Returns true if this Resolution is larger than the other Resolution, false otherwise.
152  Boole operator>(const Resolution& Other) const
153  {
154  if( this->Width == Other.Width ) {
155  return ( this->Height > Other.Height );
156  }else{
157  return ( this->Width > Other.Width );
158  }
159  }
160 
161  ///////////////////////////////////////////////////////////////////////////////
162  // Serialization
163 
164  /// @brief Convert this class to an XML::Node ready for serialization.
165  /// @param ParentNode The point in the XML hierarchy that all this Resolution should be appended to.
166  void ProtoSerialize(XML::Node& ParentNode) const
167  {
168  XML::Node DimNode = ParentNode.AppendChild( Resolution::GetSerializableName() );
169 
170  if( DimNode.AppendAttribute("Version").SetValue("1") &&
171  DimNode.AppendAttribute("Width").SetValue(this->Width) &&
172  DimNode.AppendAttribute("Height").SetValue(this->Height) )
173  {
174  return;
175  }else{
176  SerializeError("Create XML Attribute Values",Resolution::GetSerializableName(),true);
177  }
178  }
179  /// @brief Take the data stored in an XML Node and overwrite this object with it.
180  /// @param SelfRoot An XML::Node containing the data to populate this class with.
181  void ProtoDeSerialize(const XML::Node& SelfRoot)
182  {
183  XML::Attribute CurrAttrib;
184  if( SelfRoot.Name() == Resolution::GetSerializableName() ) {
185  if(SelfRoot.GetAttribute("Version").AsInt() == 1) {
186  CurrAttrib = SelfRoot.GetAttribute("Width");
187  if( !CurrAttrib.Empty() )
188  this->Width = CurrAttrib.AsWhole();
189 
190  CurrAttrib = SelfRoot.GetAttribute("Height");
191  if( !CurrAttrib.Empty() )
192  this->Height = CurrAttrib.AsWhole();
193  }else{
194  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + Resolution::GetSerializableName() + ": Not Version 1.");
195  }
196  }else{
197  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_NOT_FOUND_EXCEPTION,Resolution::GetSerializableName() + " was not found in the provided XML node, which was expected.");
198  }
199  }
200  /// @brief Get the name of the the XML tag the class will leave behind as its instances are serialized.
201  /// @return A string containing the name of this class.
203  {
204  return "Resolution";
205  }
206  };//Resolution
207  }//Graphics
208 }//Mezzanine
209 
210 #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
Boole operator==(const Resolution &Other) const
Equality comparison operator.
Definition: resolution.h:127
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
Definition: resolution.h:181
Whole Height
The pixel height of the window.
Definition: resolution.h:66
void ProtoSerialize(XML::Node &ParentNode) const
Convert this class to an XML::Node ready for serialization.
Definition: resolution.h:166
Resolution & operator=(const Resolution &Other)
Assignment operator.
Definition: resolution.h:117
Thrown when the requested identity could not be found.
Definition: exception.h:94
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
All the definitions for datatypes as well as some basic conversion functions are defined here...
This stores all the basic configuration options a game window supports.
Definition: resolution.h:57
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
Definition: exception.h:112
This implements the exception hiearchy for Mezzanine.
std::stringstream StringStream
A Datatype used for streaming operations with strings.
Definition: datatypes.h:176
String GetAsString() const
Converts the values of this Resolution to a human readable string.
Definition: resolution.h:104
The interface for serialization.
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.
Whole Width
The pixel width of the window.
Definition: resolution.h:64
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
bool Empty() const
Is this storing anything at all?
Resolution()
Blank constructor.
Definition: resolution.h:72
Boole operator<(const Resolution &Other) const
Less-than operator.
Definition: resolution.h:141
static String GetSerializableName()
Get the name of the the XML tag the class will leave behind as its instances are serialized.
Definition: resolution.h:202
Resolution(const Whole ResWidth, const Whole ResHeight)
Descriptive constructor.
Definition: resolution.h:80
#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
Boole operator>(const Resolution &Other) const
Greater-than operator.
Definition: resolution.h:152
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.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
Boole operator!=(const Resolution &Other) const
Inequality comparison operator.
Definition: resolution.h:134
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
void SetResolution(const Whole ResWidth, const Whole ResHeight)
Sets the width and height of this resolution.
Definition: resolution.h:95
~Resolution()
Class destructor.
Definition: resolution.h:86