Spinning Topp Logo BlackTopp Studios
inc
renderlayergroup.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 _uirenderlayergroup_cpp
41 #define _uirenderlayergroup_cpp
42 
43 #include "UI/renderlayergroup.h"
44 #include "UI/renderlayer.h"
45 #include "UI/quadrenderable.h"
46 
47 namespace Mezzanine
48 {
49  namespace UI
50  {
52  ParentQuad(Creator),
53  GroupID(ID)
54  { }
55 
57  { }
58 
59  ///////////////////////////////////////////////////////////////////////////////
60  // Utility
61 
63  { return this->GroupID; }
64 
66  {
67  for( RenderLayerIterator It = this->RenderLayers.begin() ; It != this->RenderLayers.end() ; ++It )
68  { (*It).second->NotifyActive(); }
69  }
70 
72  {
73  for( RenderLayerIterator It = this->RenderLayers.begin() ; It != this->RenderLayers.end() ; ++It )
74  { (*It).second->NotifyInactive(); }
75  }
76 
77  ///////////////////////////////////////////////////////////////////////////////
78  // RenderLayer Management
79 
81  {
82  for( RenderLayerIterator It = this->RenderLayers.begin() ; It != this->RenderLayers.end() ; ++It )
83  {
84  if( (*It).first > ZOrder ) {
85  this->RenderLayers.insert(It,RenderLayerPair(ZOrder,RL));
86  if( this->ParentQuad->GetActiveGroup() == this ) {
87  this->ParentQuad->_MarkDirty();
88  }
89  return;
90  }
91  }
92  this->RenderLayers.push_back(RenderLayerPair(ZOrder,RL));
93  if( this->ParentQuad->GetActiveGroup() == this ) {
94  this->ParentQuad->_MarkDirty();
95  }
96  return;
97  }
98 
100  {
101  return this->RenderLayers.at(Index).second;
102  }
103 
105  {
106  for( ConstRenderLayerIterator RendIt = this->RenderLayers.begin() ; RendIt != this->RenderLayers.end() ; ++RendIt )
107  {
108  if( (*RendIt).first == ZOrder )
109  return (*RendIt).second;
110  }
111  return NULL;
112  }
113 
115  {
116  return this->RenderLayers.size();
117  }
118 
120  {
121  this->RenderLayers.swap( OtherGroup->RenderLayers );
122  if( this->ParentQuad->GetActiveGroup() == this ) {
123  this->ParentQuad->_MarkDirty();
124  }
125  }
126 
128  {
129  for( RenderLayerIterator It = this->RenderLayers.begin() ; It != this->RenderLayers.end() ; ++It )
130  {
131  if( (*It).second == RL ) {
132  this->RenderLayers.erase(It);
133  if( this->ParentQuad->GetActiveGroup() == this ) {
134  this->ParentQuad->_MarkDirty();
135  }
136  return;
137  }
138  }
139  }
140 
142  {
143  // We don't own them, QuadRenderables do, so just clear
144  this->RenderLayers.clear();
145  }
146 
148  { return this->RenderLayers.begin(); }
149 
151  { return this->RenderLayers.end(); }
152 
154  { return this->RenderLayers.begin(); }
155 
157  { return this->RenderLayers.end(); }
158 
159  ///////////////////////////////////////////////////////////////////////////////
160  // Serialization
161 
163  { return "RenderLayerGroup"; }
164  }//UI
165 }//Mezzanine
166 
167 #endif
void NotifyActive()
Notifies this RenderLayerGroup that it has become the active group.
RenderLayerContainer::const_iterator ConstRenderLayerIterator
Const Iterator type for RenderLayerPair instances stored by this class.
std::pair< UInt16, RenderLayer * > RenderLayerPair
An std::pair type for storing ZOrders in relation to RenderLayer instances.
void SwapLayers(RenderLayerGroup *OtherGroup)
Swaps the layers contained by this group and another group.
void RemoveLayer(RenderLayer *RL)
Removes a layer from this group.
~RenderLayerGroup()
Class destructor.
static String GetSerializableName()
Get the name of the the XML tag the Renderable class will leave behind as its instances are serialize...
UInt16 GetGroupID() const
Gets the ID of this RenderLayerGroup.
RenderLayer * GetLayerByZOrder(const UInt16 ZOrder) const
Gets a RenderLayer in this group by it's ZOrder.
void RemoveAllLayers()
Removes every layer in this group, from this group.
uint16_t UInt16
An 16-bit unsigned integer.
Definition: datatypes.h:122
void NotifyInactive()
Notifies this RenderLayerGroup that it is no longer the active group.
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
RenderLayerContainer::iterator RenderLayerIterator
Iterator type for RenderLayerPair instances stored by this class.
RenderLayerIterator RenderLayerEnd()
Gets an iterator to one passed the last RenderLayer.
RenderLayerIterator RenderLayerBegin()
Gets an iterator to the first RenderLayer.
RenderLayer * GetLayer(const Whole Index) const
Gets a RenderLayer in this group by it's index.
RenderLayerGroup * GetActiveGroup() const
Gets the current RenderLayerGroup used for rendering.
RenderLayerContainer RenderLayers
Container storing all the layers that belong to this group and their ZOrders.
This class stores a group of render layers that can be set to be rendered.
QuadRenderable * ParentQuad
A pointer to the host QuadRenderable.
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
RenderLayerGroup(const UInt16 ID, QuadRenderable *Creator)
Class constructor.
UInt16 GroupID
The ID of this group.
This represents a nestable quad for an object in a GUI layout.
virtual void _MarkDirty()
Marks this renderable as dirty, and informs other renderables if needed.
UInt32 GetNumRenderLayers() const
Gets the number of RenderLayers assigned to this group.
void AddLayer(RenderLayer *RL, const UInt16 ZOrder)
Adds a layer to this group by it's ZOrder.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
This is the base class for the types of layers that can be added to a renderable. ...
Definition: renderlayer.h:58