Spinning Topp Logo BlackTopp Studios
inc
pageprovider.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 
41 #ifndef _uipageprovider_cpp
42 #define _uipageprovider_cpp
43 
44 #include "UI/pageprovider.h"
45 #include "UI/pagedcontainer.h"
46 #include "UI/screen.h"
47 
48 namespace Mezzanine
49 {
50  namespace UI
51  {
53  Widget(Parent),
54  Container(NULL)
55  { }
56 
57  PageProvider::PageProvider(const String& RendName, Screen* Parent) :
58  Widget(RendName,Parent),
59  Container(NULL)
60  { }
61 
62  PageProvider::PageProvider(const String& RendName, const UnifiedRect& RendRect, Screen* Parent) :
63  Widget(RendName,RendRect,Parent),
64  Container(NULL)
65  { }
66 
68  { }
69 
71  {
72  this->Widget::ProtoSerializeImpl(SelfRoot);
73  this->ProtoSerializePageData(SelfRoot);
74  }
75 
77  {
78  this->Widget::ProtoDeSerializeImpl(SelfRoot);
79  this->ProtoDeSerializePageData(SelfRoot);
80  }
81 
82  ///////////////////////////////////////////////////////////////////////////////
83  // Serialization
84 
86  {
87  if( this->Container != NULL ) {
88  XML::Node PageDataNode = SelfRoot.AppendChild( PageProvider::GetSerializableName() + "PageData" );
89 
90  if( PageDataNode.AppendAttribute("Version").SetValue("1") &&
91  PageDataNode.AppendAttribute("ContainerName").SetValue( this->Container->GetName() ) &&
92  PageDataNode.AppendAttribute("ProviderConfig").SetValue( static_cast<Whole>( this->Container->GetProviderConfig(this) ) ) )
93  {
94  return;
95  }else{
96  SerializeError("Create XML Attribute Values",PageProvider::GetSerializableName() + "PageData",true);
97  }
98  }
99  }
100 
102  {
103  XML::Attribute CurrAttrib;
104  XML::Node PageDataNode = SelfRoot.GetChild( PageProvider::GetSerializableName() + "PageData" );
105 
106  if( !PageDataNode.Empty() ) {
107  if(PageDataNode.GetAttribute("Version").AsInt() == 1) {
108  String ContainerName;
109  PagedContainer::ProviderMode ProviderConfig;
110 
111  CurrAttrib = PageDataNode.GetAttribute("ContainerName");
112  if( !CurrAttrib.Empty() )
113  ContainerName = CurrAttrib.AsString();
114 
115  CurrAttrib = PageDataNode.GetAttribute("ProviderConfig");
116  if( !CurrAttrib.Empty() )
117  ProviderConfig = static_cast<PagedContainer::ProviderMode>( CurrAttrib.AsWhole() );
118 
119  if( !ContainerName.empty() ) {
120  PagedContainer* ToSet = static_cast<PagedContainer*>( this->ParentScreen->GetWidget(ContainerName) );
121  if( ToSet != NULL ) {
122  switch( ProviderConfig )
123  {
124  case PagedContainer::PM_Single_X: ToSet->SetXProvider(this); break;
125  case PagedContainer::PM_Single_Y: ToSet->SetYProvider(this); break;
126  case PagedContainer::PM_Single_XY: ToSet->SetProviders(this,this); break;
127  default: /* Do Nothing */ break;
128  }
129  }
130  }
131  }else{
132  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + (PageProvider::GetSerializableName() + "PageData") + ": Not Version 1.");
133  }
134  }else{
135  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_NOT_FOUND_EXCEPTION,PageProvider::GetSerializableName() + "PageData" + " was not found in the provided XML node, which was expected.");
136  }
137  }
138 
139  ///////////////////////////////////////////////////////////////////////////////
140  // Internal Methods
141 
143  { this->Container = ToUpdate; }
144  }//UI
145 }//Mezzanine
146 
147 #endif
This is the base class for containers that have a render area and work area of different sizes...
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
There is only one PageProvider providing pages for both the X and Y axes of this container, or the queried provider is being used for both the X and Y axes be the container.
virtual void SetProviders(PageProvider *XProv, PageProvider *YProv)=0
Sets the page providers for both axes.
virtual void ProtoSerializePageData(XML::Node &SelfRoot) const
Convert the PageProvider data of this class to an XML::Node ready for serialization.
virtual void ProtoDeSerializePageData(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the PageProvider data of this object with it...
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
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.
static String GetSerializableName()
Get the name of the the XML tag the Renderable class will leave behind as its instances are serialize...
Definition: widget.cpp:433
virtual void _SetContainer(PagedContainer *ToUpdate)
Sets the container that is using this provider to update which renderables are visible.
bool Empty() const
Is this storing anything at all?
PagedContainer * Container
A pointer to the PagedContainer this scrollbar is providing page data for.
Definition: pageprovider.h:60
bool SetValue(const Char8 *rhs)
Set the value of this.
This class represents a 2D rect which can express the size and position of a renderable on screen...
Definition: unifieddim.h:661
Whole AsWhole(Whole def=0) const
Attempts to convert the value of the attribute to a Whole and returns the results.
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?
This is the base class for all widgets.
Definition: widget.h:126
virtual void SetXProvider(PageProvider *XProv)=0
Sets the PageProvider for the X axis.
virtual void ProtoDeSerializeImpl(const XML::Node &SelfRoot)
Implementation method for deseriailizing additional sets of data.
Definition: widget.cpp:105
virtual ProviderMode GetProviderConfig() const
Gets the current provider configuration of this container.
virtual void ProtoDeSerializeImpl(const XML::Node &SelfRoot)
Implementation method for deseriailizing additional sets of data.
There is only one PageProvider providing pages for the Y axis of this container, or the queried provi...
virtual void ProtoSerializeImpl(XML::Node &SelfRoot) const
Implementation method for serializing additional sets of data.
virtual Widget * GetWidget(const String &Name)
Gets a widget in this screen by name.
Definition: screen.cpp:573
virtual void ProtoSerializeImpl(XML::Node &SelfRoot) const
Implementation method for serializing additional sets of data.
Definition: widget.cpp:97
virtual void SetYProvider(PageProvider *YProv)=0
Sets the PageProvider for the Y axis.
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
ProviderMode
An enum describing how the providers for this container are configured and being used.
virtual ~PageProvider()
Standard destructor.
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.
PageProvider(Screen *Parent)
Blank constructor.
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.
There is only one PageProvider providing pages for the X axis of this container, or the queried provi...
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