1 /***********************************************************************
2     created:    Mon Jun 13 2005
3     author:     Paul D Turner <paul@cegui.org.uk>
4 *************************************************************************/
5 /***************************************************************************
6  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
7  *
8  *   Permission is hereby granted, free of charge, to any person obtaining
9  *   a copy of this software and associated documentation files (the
10  *   "Software"), to deal in the Software without restriction, including
11  *   without limitation the rights to use, copy, modify, merge, publish,
12  *   distribute, sublicense, and/or sell copies of the Software, and to
13  *   permit persons to whom the Software is furnished to do so, subject to
14  *   the following conditions:
15  *
16  *   The above copyright notice and this permission notice shall be
17  *   included in all copies or substantial portions of the Software.
18  *
19  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  *   OTHER DEALINGS IN THE SOFTWARE.
26  ***************************************************************************/
27 #include "CEGUI/falagard/StateImagery.h"
28 #include "CEGUI/falagard/XMLHandler.h"
29 #include "CEGUI/GeometryBuffer.h"
30 #include "CEGUI/System.h"
31 #include "CEGUI/Renderer.h"
32 #include <iostream>
33 
34 // Start of CEGUI namespace section
35 namespace CEGUI
36 {
37 
StateImagery(const String & name)38 StateImagery::StateImagery(const String& name) :
39     d_stateName(name),
40     d_clipToDisplay(false)
41 {}
42 
render(Window & srcWindow,const ColourRect * modcols,const Rectf * clipper) const43 void StateImagery::render(Window& srcWindow, const ColourRect* modcols, const Rectf* clipper) const
44 {
45     srcWindow.getGeometryBuffer().setClippingActive(!d_clipToDisplay);
46 
47     // render all layers defined for this state
48     for(LayersList::const_iterator curr = d_layers.begin(); curr != d_layers.end(); ++curr)
49         (*curr).render(srcWindow, modcols, clipper, d_clipToDisplay);
50 }
51 
render(Window & srcWindow,const Rectf & baseRect,const ColourRect * modcols,const Rectf * clipper) const52 void StateImagery::render(Window& srcWindow, const Rectf& baseRect, const ColourRect* modcols, const Rectf* clipper) const
53 {
54     srcWindow.getGeometryBuffer().setClippingActive(!d_clipToDisplay);
55 
56     // render all layers defined for this state
57     for(LayersList::const_iterator curr = d_layers.begin(); curr != d_layers.end(); ++curr)
58         (*curr).render(srcWindow, baseRect, modcols, clipper, d_clipToDisplay);
59 }
60 
addLayer(const LayerSpecification & layer)61 void StateImagery::addLayer(const LayerSpecification& layer)
62 {
63     d_layers.insert(layer);
64 }
65 
clearLayers()66 void StateImagery::clearLayers()
67 {
68     d_layers.clear();
69 }
70 
getName() const71 const String& StateImagery::getName() const
72 {
73     return d_stateName;
74 }
75 
setName(const String & name)76 void StateImagery::setName(const String& name)
77 {
78     d_stateName = name;
79 }
80 
isClippedToDisplay() const81 bool StateImagery::isClippedToDisplay() const
82 {
83     return d_clipToDisplay;
84 }
85 
setClippedToDisplay(bool setting)86 void StateImagery::setClippedToDisplay(bool setting)
87 {
88     d_clipToDisplay = setting;
89 }
90 
writeXMLToStream(XMLSerializer & xml_stream) const91 void StateImagery::writeXMLToStream(XMLSerializer& xml_stream) const
92 {
93     xml_stream.openTag(Falagard_xmlHandler::StateImageryElement)
94         .attribute(Falagard_xmlHandler::NameAttribute, d_stateName);
95 
96     if (d_clipToDisplay)
97         xml_stream.attribute(Falagard_xmlHandler::ClippedAttribute, PropertyHelper<bool>::False);
98 
99     // output all layers defined for this state
100     for(LayersList::const_iterator curr = d_layers.begin(); curr != d_layers.end(); ++curr)
101         (*curr).writeXMLToStream(xml_stream);
102     // write closing </StateImagery> tag
103     xml_stream.closeTag();
104 }
105 
106 StateImagery::LayerIterator
getLayerIterator() const107 StateImagery::getLayerIterator() const
108 {
109     return LayerIterator(d_layers.begin(),d_layers.end());
110 }
111 
getLayerSpecificationPointers()112 StateImagery::LayerSpecificationPointerList StateImagery::getLayerSpecificationPointers()
113 {
114     StateImagery::LayerSpecificationPointerList pointerList;
115 
116     LayersList::iterator layerSpecIter = d_layers.begin();
117     LayersList::iterator layerSpecIterEnd = d_layers.end();
118     while( layerSpecIter != layerSpecIterEnd )
119     {
120         //! This hack is necessary because in newer C++ versions the multiset and sets return only const iterators.
121         //! \deprecated This will be replaced with proper types and behaviour in the next version.
122         LayerSpecification* layerSpec = const_cast<LayerSpecification*>(&(*layerSpecIter));
123         pointerList.push_back(layerSpec);
124         ++layerSpecIter;
125     }
126 
127     return pointerList;
128 }
129 
sort()130 void StateImagery::sort()
131 {
132     //! \deprecated Deprecated behaviour: We have to remove all elements and re-add them to force them to be sorted.
133     std::vector<LayerSpecification> temporaryList;
134 
135     LayersList::iterator layerSpecMapIter = d_layers.begin();
136     LayersList::iterator layerSpecMapIterEnd = d_layers.end();
137     while( layerSpecMapIter != layerSpecMapIterEnd )
138     {
139         temporaryList.push_back(*layerSpecMapIter);
140         ++layerSpecMapIter;
141     }
142 
143     clearLayers();
144 
145     std::vector<LayerSpecification>::iterator layerSpecVecIter = temporaryList.begin();
146     std::vector<LayerSpecification>::iterator layerSpecVecIterEnd = temporaryList.end();
147     while( layerSpecVecIter != layerSpecVecIterEnd )
148     {
149         addLayer(*layerSpecVecIter);
150         ++layerSpecVecIter;
151     }
152 }
153 
154 } // End of  CEGUI namespace section
155