MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
simplerenderer.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 
41 #ifndef _uisimplerenderer_h
42 #define _uisimplerenderer_h
43 
44 #include "UI/vertex.h"
45 #include "XML/xml.h"
46 
47 namespace Mezzanine
48 {
49  namespace UI
50  {
51  ///////////////////////////////////////////////////////////////////////////////
52  /// @class SimpleRenderer
53  /// @headerfile simplerenderer.h
54  /// @brief A simple class providing basic methods to generate vertices with.
55  /// @details
56  ///////////////////////////////////////
58  {
59  protected:
60  /// @internal
61  /// @brief This determines whether or not the verticies in this renderer need to be refreshed.
62  bool Dirty;
63  /// @internal
64  /// @brief This contains the name of the atlas that will be used as default when one isn't specified.
66  /// @internal
67  /// @brief This is a container storing all the Verticies generated by this renderer.
68  std::vector<VertexData> RenderVertices;
69  /// @internal
70  /// @brief Provides the class specific implementation for regenerating vertices for this renderable.
71  virtual void RedrawImpl(bool Force) = 0;
72  /// @internal
73  /// @brief Collects all the relevant information for a single vertex and pushes it to a vector.
74  virtual void PushVertex(const Real& X, const Real& Y, const Vector2& UV, const ColourValue& Colour, const String& Atlas);
75  /// @internal
76  /// @brief Pushes vertex information for a triangle to a vector. Equivalent to calling "PushVertex" three times.
77  virtual void PushTriangle(const Vector2& A, const Vector2& B, const Vector2& C, const Vector2& UV, const ColourValue& Colour, const String& Atlas);
78  //public:
79  /// @brief Class constructor.
81  /// @brief Class destructor.
82  virtual ~SimpleRenderer();
83  public:
84  ///////////////////////////////////////////////////////////////////////////////
85  // Utility Methods
86 
87  /// @brief Sets the Atlas to be assumed when one isn't provided for atlas related tasks.
88  /// @param Atlas The name of the atlas to be used.
89  virtual void SetPrimaryAtlas(const String& Atlas);
90  /// @brief Gets the currently set primary atlas.
91  /// @return Returns a string containing the name of the primary atlas that is set, or an empty string if none.
92  virtual String GetPrimaryAtlas() const;
93 
94  ///////////////////////////////////////////////////////////////////////////////
95  // Serialization
96 
97  /// @brief Convert this class to an XML::Node ready for serialization.
98  /// @param ParentNode The point in the XML hierarchy that all this renderable should be appended to.
99  virtual void ProtoSerialize(XML::Node& ParentNode) const;
100  /// @brief Convert the properties of this class to an XML::Node ready for serialization.
101  /// @param SelfRoot The root node containing all the serialized data for this instance.
102  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
103 
104  /// @brief Take the data stored in an XML Node and overwrite this object with it.
105  /// @param SelfRoot An XML::Node containing the data to populate this class with.
106  virtual void ProtoDeSerialize(const XML::Node& SelfRoot);
107  /// @brief Take the data stored in an XML Node and overwrite the properties of this object with it.
108  /// @param SelfRoot An XML::Node containing the data to populate this class with.
109  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
110 
111  /// @brief Gets the most derived serializable name of this Renderable.
112  /// @note When creating a new Renderable class verify this method has a valid return for it in order for serialization to work properly.
113  /// @return Returns the name of the XML tag from the most derived class of "this".
114  virtual String GetDerivedSerializableName() const;
115  /// @brief Get the name of the the XML tag the Renderable class will leave behind as its instances are serialized.
116  /// @return A string containing the name of this class.
117  static String GetSerializableName();
118 
119  ///////////////////////////////////////////////////////////////////////////////
120  // Internal Methods
121 
122  /// @internal
123  /// @brief Marks this renderable as well as all parent objects as dirty.
124  virtual void _MarkDirty() = 0;
125  /// @internal
126  /// @brief Gets whether or not this renderer is dirty.
127  /// @return Returns true if this renderer is dirty, false otherwise.
128  bool _IsDirty();
129  /// @internal
130  /// @brief Regenerates the verticies in this renderable.
131  /// @param Force If true this will force this object to redraw it's verticies regardless of whether it is dirty.
132  void _Redraw(bool Force);
133  /// @internal
134  /// @brief Appends the vertices of this renderable to another vector.
135  /// @param Vertices The vector of vertex's to append to.
136  void _AppendVertices(std::vector<VertexData>& Vertices);
137  };//SimpleRenderer
138  }//UI
139 }//Mezzanine
140 
141 #endif