Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/Overlay/OgreOverlayManager.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

File size: 9.9 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef __OverlayManager_H__
29#define __OverlayManager_H__
30
31#include "OgreOverlayPrerequisites.h"
32#include "OgreSingleton.h"
33#include "OgreStringVector.h"
34#include "OgreOverlay.h"
35#include "OgreScriptLoader.h"
36#include "OgreFrustum.h"
37
38namespace Ogre {
39
40        /** \addtogroup Core
41        *  @{
42        */
43        /** \addtogroup Overlays
44        *  @{
45        */
46        /** Manages Overlay objects, parsing them from .overlay files and
47        storing a lookup library of them. Also manages the creation of
48                OverlayContainers and OverlayElements, used for non-interactive 2D
49                elements such as HUDs.
50    */
51    class _OgreOverlayExport OverlayManager : public Singleton<OverlayManager>, public ScriptLoader, public OverlayAlloc
52    {
53    public:
54        typedef map<String, Overlay*>::type OverlayMap;
55                typedef map<String, OverlayElement*>::type ElementMap;
56                typedef map<String, OverlayElementFactory*>::type FactoryMap;
57    protected:
58        OverlayMap mOverlayMap;
59        StringVector mScriptPatterns;
60
61        void parseNewElement( DataStreamPtr& chunk, String& elemType, String& elemName, 
62            bool isContainer, Overlay* pOverlay, bool isTemplate, String templateName = String(""), OverlayContainer* container = 0);
63        void parseAttrib( const String& line, Overlay* pOverlay);
64        void parseElementAttrib( const String& line, Overlay* pOverlay, OverlayElement* pElement );
65        void skipToNextCloseBrace(DataStreamPtr& chunk);
66        void skipToNextOpenBrace(DataStreamPtr& chunk);
67       
68        int mLastViewportWidth, mLastViewportHeight;
69        bool mViewportDimensionsChanged;
70        OrientationMode mLastViewportOrientationMode;
71
72            bool parseChildren( DataStreamPtr& chunk, const String& line,
73            Overlay* pOverlay, bool isTemplate, OverlayContainer* parent = NULL);
74
75                FactoryMap mFactories;
76
77                ElementMap mInstances;
78                ElementMap mTemplates;
79
80                typedef set<String>::type LoadedScripts;
81                LoadedScripts mLoadedScripts;
82
83
84
85
86                ElementMap& getElementMap(bool isTemplate);
87
88                OverlayElement* createOverlayElementImpl(const String& typeName, const String& instanceName, ElementMap& elementMap);
89
90                OverlayElement* getOverlayElementImpl(const String& name, ElementMap& elementMap);
91               
92                bool hasOverlayElementImpl(const String& name, ElementMap& elementMap);
93
94                void destroyOverlayElementImpl(const String& instanceName, ElementMap& elementMap);
95
96                void destroyOverlayElementImpl(OverlayElement* pInstance, ElementMap& elementMap);
97
98                void destroyAllOverlayElementsImpl(ElementMap& elementMap);
99
100    public:
101        OverlayManager();
102        virtual ~OverlayManager();
103
104        /// @copydoc ScriptLoader::getScriptPatterns
105        const StringVector& getScriptPatterns(void) const;
106        /// @copydoc ScriptLoader::parseScript
107        void parseScript(DataStreamPtr& stream, const String& groupName);
108        /// @copydoc ScriptLoader::getLoadingOrder
109        Real getLoadingOrder(void) const;
110
111        /** Create a new Overlay. */
112        Overlay* create(const String& name);
113        /** Retrieve an Overlay by name
114        @return A pointer to the Overlay, or 0 if not found
115        */
116        Overlay* getByName(const String& name);
117        /** Destroys an existing overlay by name */
118        void destroy(const String& name);
119        /** Destroys an existing overlay */
120        void destroy(Overlay* overlay);
121        /** Destroys all existing overlays */
122        void destroyAll(void);
123        typedef MapIterator<OverlayMap> OverlayMapIterator;
124        OverlayMapIterator getOverlayIterator(void);
125
126        /** Internal method for queueing the visible overlays for rendering. */
127        void _queueOverlaysForRendering(Camera* cam, RenderQueue* pQueue, Viewport *vp);
128
129        /** Method for determining if the viewport has changed dimensions.
130        @remarks This is used by pixel-based OverlayElements to work out if they need to
131            recalculate their sizes.
132        */
133        bool hasViewportChanged(void) const;
134
135        /** Gets the height of the destination viewport in pixels. */
136        int getViewportHeight(void) const;
137       
138        /** Gets the width of the destination viewport in pixels. */
139        int getViewportWidth(void) const;
140        Real getViewportAspectRatio(void) const;
141
142        /** Gets the orientation mode of the destination viewport. */
143        OrientationMode getViewportOrientationMode(void) const;
144
145                /** Creates a new OverlayElement of the type requested.
146                @remarks
147                The type of element to create is passed in as a string because this
148                allows plugins to register new types of component.
149                @param typeName The type of element to create.
150                @param instanceName The name to give the new instance.
151                */
152                OverlayElement* createOverlayElement(const String& typeName, const String& instanceName, bool isTemplate = false);
153
154                /** Gets a reference to an existing element. */
155                OverlayElement* getOverlayElement(const String& name, bool isTemplate = false);
156
157                /** Tests if an element exists. */
158                bool hasOverlayElement(const String& name, bool isTemplate = false);
159               
160                /** Destroys a OverlayElement.
161                @remarks
162                Make sure you're not still using this in an Overlay. If in
163                doubt, let OGRE destroy elements on shutdown.
164                */
165                void destroyOverlayElement(const String& instanceName, bool isTemplate = false);
166
167                /** Destroys a OverlayElement.
168                @remarks
169                Make sure you're not still using this in an Overlay. If in
170                doubt, let OGRE destroy elements on shutdown.
171                */
172                void destroyOverlayElement(OverlayElement* pInstance, bool isTemplate = false);
173
174                /** Destroys all the OverlayElement  created so far.
175                @remarks
176                Best to leave this to the engine to call internally, there
177                should rarely be a need to call it yourself.
178                */
179                void destroyAllOverlayElements(bool isTemplate = false);
180
181                /** Registers a new OverlayElementFactory with this manager.
182                @remarks
183                Should be used by plugins or other apps wishing to provide
184                a new OverlayElement subclass.
185                */
186                void addOverlayElementFactory(OverlayElementFactory* elemFactory);
187               
188                /** Get const access to the list of registered OverlayElement factories. */
189                const FactoryMap& getOverlayElementFactoryMap() const {
190                        return mFactories;
191                }
192
193                OverlayElement* createOverlayElementFromTemplate(const String& templateName, const String& typeName, const String& instanceName, bool isTemplate = false);
194                /**
195                *  @remarks
196                *  Creates a new OverlayElement object from the specified template name.  The new
197                *  object's name, and all of it's children, will be instanceName/orignalName.
198                */
199                OverlayElement* cloneOverlayElementFromTemplate(const String& templateName, const String& instanceName);
200
201                OverlayElement* createOverlayElementFromFactory(const String& typeName, const String& instanceName);
202
203                typedef MapIterator<ElementMap> TemplateIterator;
204                /** Returns an iterator over all templates in this manager.*/
205                TemplateIterator getTemplateIterator ()
206                {
207                        return TemplateIterator (mTemplates.begin (), mTemplates.end ()) ;
208                }
209                /* Returns whether the Element with the given name is a Template */
210                bool isTemplate (String strName) const {
211                        return (mTemplates.find (strName) != mTemplates.end()) ;
212                }
213
214
215        /** Override standard Singleton retrieval.
216        @remarks
217        Why do we do this? Well, it's because the Singleton
218        implementation is in a .h file, which means it gets compiled
219        into anybody who includes it. This is needed for the
220        Singleton template to work, but we actually only want it
221        compiled into the implementation of the class based on the
222        Singleton, not all of them. If we don't change this, we get
223        link errors when trying to use the Singleton-based class from
224        an outside dll.
225        @par
226        This method just delegates to the template version anyway,
227        but the implementation stays in this single compilation unit,
228        preventing link errors.
229        */
230        static OverlayManager& getSingleton(void);
231        /** Override standard Singleton retrieval.
232        @remarks
233        Why do we do this? Well, it's because the Singleton
234        implementation is in a .h file, which means it gets compiled
235        into anybody who includes it. This is needed for the
236        Singleton template to work, but we actually only want it
237        compiled into the implementation of the class based on the
238        Singleton, not all of them. If we don't change this, we get
239        link errors when trying to use the Singleton-based class from
240        an outside dll.
241        @par
242        This method just delegates to the template version anyway,
243        but the implementation stays in this single compilation unit,
244        preventing link errors.
245        */
246        static OverlayManager* getSingletonPtr(void);
247    };
248
249
250        /** @} */
251        /** @} */
252
253}
254
255
256#endif
Note: See TracBrowser for help on using the repository browser.