source: GTP/trunk/App/Demos/Geom/OgreStuff/include/OgreOverlayManager.h @ 1812

Revision 1812, 9.2 KB checked in by gumbau, 18 years ago (diff)
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-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#ifndef __OverlayManager_H__
26#define __OverlayManager_H__
27
28#include "OgrePrerequisites.h"
29#include "OgreSingleton.h"
30#include "OgreStringVector.h"
31#include "OgreOverlay.h"
32#include "OgreScriptLoader.h"
33
34namespace Ogre {
35
36    /** Manages Overlay objects, parsing them from .overlay files and
37        storing a lookup library of them. Alo manages the creation of
38                OverlayContainers and OverlayElements, used for non-interactive 2D
39                elements such as HUDs.
40    */
41    class _OgreExport OverlayManager : public Singleton<OverlayManager>, public ScriptLoader
42    {
43    public:
44        typedef std::map<String, Overlay*> OverlayMap;
45                typedef std::map<String, OverlayElement*> ElementMap;
46    protected:
47        OverlayMap mOverlayMap;
48        StringVector mScriptPatterns;
49
50        void parseNewElement( DataStreamPtr& chunk, String& elemType, String& elemName,
51            bool isContainer, Overlay* pOverlay, bool isTemplate, String templateName = String(""), OverlayContainer* container = 0);
52        void parseAttrib( const String& line, Overlay* pOverlay);
53        void parseElementAttrib( const String& line, Overlay* pOverlay, OverlayElement* pElement );
54        void skipToNextCloseBrace(DataStreamPtr& chunk);
55        void skipToNextOpenBrace(DataStreamPtr& chunk);
56       
57        int mLastViewportWidth, mLastViewportHeight;
58        bool mViewportDimensionsChanged;
59
60            bool parseChildren( DataStreamPtr& chunk, const String& line,
61            Overlay* pOverlay, bool isTemplate, OverlayContainer* parent = NULL);
62
63                typedef std::map<String, OverlayElementFactory*> FactoryMap;
64                FactoryMap mFactories;
65
66                ElementMap mInstances;
67                ElementMap mTemplates;
68
69                typedef std::set<String> LoadedScripts;
70                LoadedScripts mLoadedScripts;
71
72
73
74
75                ElementMap& getElementMap(bool isTemplate);
76
77                OverlayElement* createOverlayElementImpl(const String& typeName, const String& instanceName, ElementMap& elementMap);
78
79                OverlayElement* getOverlayElementImpl(const String& name, ElementMap& elementMap);
80
81                void destroyOverlayElementImpl(const String& instanceName, ElementMap& elementMap);
82
83                void destroyOverlayElementImpl(OverlayElement* pInstance, ElementMap& elementMap);
84
85                void destroyAllOverlayElementsImpl(ElementMap& elementMap);
86
87    public:
88        OverlayManager();
89        virtual ~OverlayManager();
90
91        /// @copydoc ScriptLoader::getScriptPatterns
92        const StringVector& getScriptPatterns(void) const;
93        /// @copydoc ScriptLoader::parseScript
94        void parseScript(DataStreamPtr& stream, const String& groupName);
95        /// @copydoc ScriptLoader::getLoadingOrder
96        Real getLoadingOrder(void) const;
97
98        /** Create a new Overlay. */
99        Overlay* create(const String& name);
100        /** Retrieve an Overlay by name
101        @returns A pointer to the Overlay, or 0 if not found
102        */
103        Overlay* getByName(const String& name);
104        /** Destroys an existing overlay by name */
105        void destroy(const String& name);
106        /** Destroys an existing overlay */
107        void destroy(Overlay* overlay);
108        /** Destroys all existing overlays */
109        void destroyAll(void);
110        typedef MapIterator<OverlayMap> OverlayMapIterator;
111        OverlayMapIterator getOverlayIterator(void);
112
113        /** Internal method for queueing the visible overlays for rendering. */
114        void _queueOverlaysForRendering(Camera* cam, RenderQueue* pQueue, Viewport *vp);
115
116        /** Method for determining if the viewport has changed dimensions.
117        @remarks This is used by pixel-based OverlayElements to work out if they need to
118            reclaculate their sizes.
119        */
120        bool hasViewportChanged(void) const;
121
122        /** Gets the height of the destination viewport in pixels. */
123        int getViewportHeight(void) const;
124       
125        /** Gets the width of the destination viewport in pixels. */
126        int getViewportWidth(void) const;
127        Real getViewportAspectRatio(void) const;
128
129
130                /** Creates a new OverlayElement of the type requested.
131                @remarks
132                The type of element to create is passed in as a string because this
133                allows plugins to register new types of component.
134                @param typeName The type of element to create.
135                @param instanceName The name to give the new instance.
136                */
137                OverlayElement* createOverlayElement(const String& typeName, const String& instanceName, bool isTemplate = false);
138
139                /** Gets a reference to an existing element. */
140                OverlayElement* getOverlayElement(const String& name, bool isTemplate = false);
141
142                /** Destroys a OverlayElement.
143                @remarks
144                Make sure you're not still using this in an Overlay. If in
145                doubt, let OGRE destroy elements on shutdown.
146                */
147                void destroyOverlayElement(const String& instanceName, bool isTemplate = false);
148
149                /** Destroys a OverlayElement.
150                @remarks
151                Make sure you're not still using this in an Overlay. If in
152                doubt, let OGRE destroy elements on shutdown.
153                */
154                void destroyOverlayElement(OverlayElement* pInstance, bool isTemplate = false);
155
156                /** Destroys all the OverlayElement  created so far.
157                @remarks
158                Best to leave this to the engine to call internally, there
159                should rarely be a need to call it yourself.
160                */
161                void destroyAllOverlayElements(bool isTemplate = false);
162
163                /** Registers a new OverlayElementFactory with this manager.
164                @remarks
165                Should be used by plugins or other apps wishing to provide
166                a new OverlayElement subclass.
167                */
168                void addOverlayElementFactory(OverlayElementFactory* elemFactory);
169
170                OverlayElement* createOverlayElementFromTemplate(const String& templateName, const String& typeName, const String& instanceName, bool isTemplate = false);
171                /**
172                *  @remarks
173                *  Creates a new OverlayElement object from the specified template name.  The new
174                *  object's name, and all of it's children, will be instanceName/orignalName.
175                */
176                OverlayElement* cloneOverlayElementFromTemplate(const String& templateName, const String& instanceName);
177
178                OverlayElement* createOverlayElementFromFactory(const String& typeName, const String& instanceName);
179
180                typedef MapIterator<ElementMap> TemplateIterator;
181                /** Returns an iterator over all templates in this manager.*/
182                TemplateIterator getTemplateIterator ()
183                {
184                        return TemplateIterator (mTemplates.begin (), mTemplates.end ()) ;
185                }
186                /* Returns whether the Element with the given name is a Template */
187                bool isTemplate (String strName) const {
188                        return (mTemplates.find (strName) != mTemplates.end()) ;
189                }
190
191
192        /** Override standard Singleton retrieval.
193        @remarks
194        Why do we do this? Well, it's because the Singleton
195        implementation is in a .h file, which means it gets compiled
196        into anybody who includes it. This is needed for the
197        Singleton template to work, but we actually only want it
198        compiled into the implementation of the class based on the
199        Singleton, not all of them. If we don't change this, we get
200        link errors when trying to use the Singleton-based class from
201        an outside dll.
202        @par
203        This method just delegates to the template version anyway,
204        but the implementation stays in this single compilation unit,
205        preventing link errors.
206        */
207        static OverlayManager& getSingleton(void);
208        /** Override standard Singleton retrieval.
209        @remarks
210        Why do we do this? Well, it's because the Singleton
211        implementation is in a .h file, which means it gets compiled
212        into anybody who includes it. This is needed for the
213        Singleton template to work, but we actually only want it
214        compiled into the implementation of the class based on the
215        Singleton, not all of them. If we don't change this, we get
216        link errors when trying to use the Singleton-based class from
217        an outside dll.
218        @par
219        This method just delegates to the template version anyway,
220        but the implementation stays in this single compilation unit,
221        preventing link errors.
222        */
223        static OverlayManager* getSingletonPtr(void);
224    };
225
226
227
228}
229
230
231#endif
Note: See TracBrowser for help on using the repository browser.