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