Spinning Topp Logo BlackTopp Studios
inc
renderable.cpp
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 _uirenderable_cpp
41 #define _uirenderable_cpp
42 
43 #include "UI/renderable.h"
44 #include "UI/uimanager.h"
45 #include "stringtool.h"
46 #include "serialization.h"
47 
48 namespace Mezzanine
49 {
50  namespace UI
51  {
53  ParentScreen(Parent),
54  Visible(true),
55  Dirty(true)
56  { }
57 
58  Renderable::Renderable(const String& RendName, Screen* Parent) :
59  ParentScreen(Parent),
60  Visible(true),
61  Dirty(true),
62  Name(RendName)
63  { }
64 
66  { }
67 
69  { this->ProtoSerializeProperties(SelfRoot); }
70 
72  { this->ProtoDeSerializeProperties(SelfRoot); }
73 
74  ///////////////////////////////////////////////////////////////////////////////
75  // Utility Methods
76 
77  const String& Renderable::GetName() const
78  { return this->Name; }
79 
81  { return this->ParentScreen; }
82 
84  { return this->GetRenderableType() == Renderable::RT_Widget; }
85 
87  { return this->GetRenderableType() == Renderable::RT_Screen; }
88 
89  ///////////////////////////////////////////////////////////////////////////////
90  // Serialization
91 
92  void Renderable::ProtoSerialize(XML::Node& ParentNode) const
93  {
94  XML::Node SelfRoot = ParentNode.AppendChild(this->GetDerivedSerializableName());
95 
96  this->ProtoSerializeImpl(SelfRoot);
97  }
98 
100  {
101  XML::Node PropertiesNode = SelfRoot.AppendChild( Renderable::GetSerializableName() + "Properties" );
102 
103  if( PropertiesNode.AppendAttribute("Version").SetValue("1") &&
104  PropertiesNode.AppendAttribute("Name").SetValue(this->Name) &&
105  PropertiesNode.AppendAttribute("Visible").SetValue( Visible ? "true" : "false" ) )
106  {
107  return;
108  }else{
109  SerializeError("Create XML Attribute Values",Renderable::GetSerializableName() + "Properties",true);
110  }
111  }
112 
114  {
115  this->ProtoDeSerializeImpl(SelfRoot);
116  }
117 
119  {
120  XML::Attribute CurrAttrib;
121  XML::Node PropertiesNode = SelfRoot.GetChild( Renderable::GetSerializableName() + "Properties" );
122 
123  if( !PropertiesNode.Empty() ) {
124  if(PropertiesNode.GetAttribute("Version").AsInt() == 1) {
125  CurrAttrib = PropertiesNode.GetAttribute("Name");
126  if( !CurrAttrib.Empty() )
127  this->Name = CurrAttrib.AsString();
128 
129  CurrAttrib = PropertiesNode.GetAttribute("Visible");
130  if( !CurrAttrib.Empty() )
131  this->Visible = CurrAttrib.AsBool();
132  }else{
133  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + (Renderable::GetSerializableName() + "Properties") + ": Not Version 1.");
134  }
135  }else{
136  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_NOT_FOUND_EXCEPTION,Renderable::GetSerializableName() + "Properties" + " was not found in the provided XML node, which was expected.");
137  }
138  }
139 
141  { return Renderable::GetSerializableName(); }
142 
144  { return "Renderable"; }
145 
146  ///////////////////////////////////////////////////////////////////////////////
147  // Internal Methods
148 
150  { return this->Dirty; }
151  }//UI
152 }//Mezzanine
153 
154 #endif
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
const String & GetName() const
Gets the name of this renderable.
Definition: renderable.cpp:77
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
Renderable(Screen *Parent)
Blank constructor.
Definition: renderable.cpp:52
bool AsBool(bool def=false) const
Attempts to convert the value of the attribute to a float and returns the results.
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
virtual void ProtoDeSerializeImpl(const XML::Node &SelfRoot)
Implementation method for deseriailizing additional sets of data.
Definition: renderable.cpp:71
virtual ~Renderable()
Class destructor.
Definition: renderable.cpp:65
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
Definition: exception.h:112
const Char8 * AsString(const Char8 *def="") const
Attempts to convert the value of the attribute to a String and returns the results.
Boole Visible
Stores whether this Renderable is to be rendered (also dependent on parent visibility).
Definition: renderable.h:75
Screen * GetScreen() const
Gets the parent screen of this renderable.
Definition: renderable.cpp:80
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
Definition: renderable.cpp:99
bool Empty() const
Is this storing anything at all?
virtual RenderableType GetRenderableType() const =0
Gets the type of renderable this is.
The interface for serialization.
bool SetValue(const Char8 *rhs)
Set the value of this.
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?
Boole _IsDirty() const
Gets whether or not this renderable is dirty.
Definition: renderable.cpp:149
virtual void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
Definition: renderable.cpp:113
String Name
The unique name of this Renderable.
Definition: renderable.h:81
virtual void ProtoSerialize(XML::Node &ParentNode) const
Convert this class to an XML::Node ready for serialization.
Definition: renderable.cpp:92
Boole IsScreen() const
Gets whether or not this renderable is a Screen.
Definition: renderable.cpp:86
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
Definition: renderable.cpp:118
static String GetSerializableName()
Get the name of the the XML tag the Renderable class will leave behind as its instances are serialize...
Definition: renderable.cpp:143
virtual String GetDerivedSerializableName() const
Gets the most derived serializable name of this Renderable.
Definition: renderable.cpp:140
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
Boole IsWidget() const
Gets whether or not this renderable is a Widget.
Definition: renderable.cpp:83
Boole Dirty
Stores whether this Renderables vertices need to be regenerated.
Definition: renderable.h:78
void SerializeError(const String &FailedTo, const String &ClassName, Boole SOrD)
Simply does some string concatenation, then throws an Exception.
virtual void ProtoSerializeImpl(XML::Node &SelfRoot) const
Implementation method for serializing additional sets of data.
Definition: renderable.cpp:68
Node AppendChild(NodeType Type=NodeElement)
Creates a Node and makes it a child of this one.
This class is a helper class for creating UI's. It is responsible for storing and keeping track of al...
Definition: screen.h:142
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.
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.
Screen * ParentScreen
A pointer to the Screen that created this Renderable.
Definition: renderable.h:72