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 | #include "OgreStableHeaders.h"
|
---|
26 |
|
---|
27 | #include "OgreOverlayManager.h"
|
---|
28 | #include "OgreStringVector.h"
|
---|
29 | #include "OgreOverlayContainer.h"
|
---|
30 | #include "OgreStringConverter.h"
|
---|
31 | #include "OgreLogManager.h"
|
---|
32 | #include "OgreSceneManagerEnumerator.h"
|
---|
33 | #include "OgreSceneManager.h"
|
---|
34 | #include "OgreSceneNode.h"
|
---|
35 | #include "OgreEntity.h"
|
---|
36 | #include "OgreException.h"
|
---|
37 | #include "OgreViewport.h"
|
---|
38 | #include "OgreOverlayElementFactory.h"
|
---|
39 |
|
---|
40 | namespace Ogre {
|
---|
41 |
|
---|
42 | //---------------------------------------------------------------------
|
---|
43 | template<> OverlayManager *Singleton<OverlayManager>::ms_Singleton = 0;
|
---|
44 | OverlayManager* OverlayManager::getSingletonPtr(void)
|
---|
45 | {
|
---|
46 | return ms_Singleton;
|
---|
47 | }
|
---|
48 | OverlayManager& OverlayManager::getSingleton(void)
|
---|
49 | {
|
---|
50 | assert( ms_Singleton ); return ( *ms_Singleton );
|
---|
51 | }
|
---|
52 | //---------------------------------------------------------------------
|
---|
53 | OverlayManager::OverlayManager()
|
---|
54 | : mLastViewportWidth(0),
|
---|
55 | mLastViewportHeight(0),
|
---|
56 | mViewportDimensionsChanged(false)
|
---|
57 | {
|
---|
58 |
|
---|
59 | // Scripting is supported by this manager
|
---|
60 | mScriptPatterns.push_back("*.overlay");
|
---|
61 | ResourceGroupManager::getSingleton()._registerScriptLoader(this);
|
---|
62 |
|
---|
63 | }
|
---|
64 | //---------------------------------------------------------------------
|
---|
65 | OverlayManager::~OverlayManager()
|
---|
66 | {
|
---|
67 | destroyAllOverlayElements(false);
|
---|
68 | destroyAllOverlayElements(true);
|
---|
69 | destroyAll();
|
---|
70 |
|
---|
71 | // Unregister with resource group manager
|
---|
72 | ResourceGroupManager::getSingleton()._unregisterScriptLoader(this);
|
---|
73 | }
|
---|
74 | //---------------------------------------------------------------------
|
---|
75 | const StringVector& OverlayManager::getScriptPatterns(void) const
|
---|
76 | {
|
---|
77 | return mScriptPatterns;
|
---|
78 | }
|
---|
79 | //---------------------------------------------------------------------
|
---|
80 | Real OverlayManager::getLoadingOrder(void) const
|
---|
81 | {
|
---|
82 | // Load late
|
---|
83 | return 1100.0f;
|
---|
84 | }
|
---|
85 | //---------------------------------------------------------------------
|
---|
86 | Overlay* OverlayManager::create(const String& name)
|
---|
87 | {
|
---|
88 | Overlay* ret = 0;
|
---|
89 | OverlayMap::iterator i = mOverlayMap.find(name);
|
---|
90 |
|
---|
91 | if (i == mOverlayMap.end())
|
---|
92 | {
|
---|
93 | ret = new Overlay(name);
|
---|
94 | assert(ret && "Overlay creation failed");
|
---|
95 | mOverlayMap[name] = ret;
|
---|
96 | }
|
---|
97 | else
|
---|
98 | {
|
---|
99 | OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
|
---|
100 | "Overlay with name '" + name + "' already exists!",
|
---|
101 | "OverlayManager::create");
|
---|
102 | }
|
---|
103 |
|
---|
104 | return ret;
|
---|
105 |
|
---|
106 | }
|
---|
107 | //---------------------------------------------------------------------
|
---|
108 | Overlay* OverlayManager::getByName(const String& name)
|
---|
109 | {
|
---|
110 | OverlayMap::iterator i = mOverlayMap.find(name);
|
---|
111 | if (i == mOverlayMap.end())
|
---|
112 | {
|
---|
113 | return 0;
|
---|
114 | }
|
---|
115 | else
|
---|
116 | {
|
---|
117 | return i->second;
|
---|
118 | }
|
---|
119 |
|
---|
120 | }
|
---|
121 | //---------------------------------------------------------------------
|
---|
122 | void OverlayManager::destroy(const String& name)
|
---|
123 | {
|
---|
124 | OverlayMap::iterator i = mOverlayMap.find(name);
|
---|
125 | if (i == mOverlayMap.end())
|
---|
126 | {
|
---|
127 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
128 | "Overlay with name '" + name + "' not found.",
|
---|
129 | "OverlayManager::destroy");
|
---|
130 | }
|
---|
131 | else
|
---|
132 | {
|
---|
133 | delete i->second;
|
---|
134 | mOverlayMap.erase(i);
|
---|
135 | }
|
---|
136 | }
|
---|
137 | //---------------------------------------------------------------------
|
---|
138 | void OverlayManager::destroy(Overlay* overlay)
|
---|
139 | {
|
---|
140 | for (OverlayMap::iterator i = mOverlayMap.begin();
|
---|
141 | i != mOverlayMap.end(); ++i)
|
---|
142 | {
|
---|
143 | if (i->second == overlay)
|
---|
144 | {
|
---|
145 | delete i->second;
|
---|
146 | mOverlayMap.erase(i);
|
---|
147 | return;
|
---|
148 | }
|
---|
149 | }
|
---|
150 |
|
---|
151 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
152 | "Overlay not found.",
|
---|
153 | "OverlayManager::destroy");
|
---|
154 | }
|
---|
155 | //---------------------------------------------------------------------
|
---|
156 | void OverlayManager::destroyAll(void)
|
---|
157 | {
|
---|
158 | for (OverlayMap::iterator i = mOverlayMap.begin();
|
---|
159 | i != mOverlayMap.end(); ++i)
|
---|
160 | {
|
---|
161 | delete i->second;
|
---|
162 | }
|
---|
163 | mOverlayMap.clear();
|
---|
164 | mLoadedScripts.clear();
|
---|
165 | }
|
---|
166 | //---------------------------------------------------------------------
|
---|
167 | OverlayManager::OverlayMapIterator OverlayManager::getOverlayIterator(void)
|
---|
168 | {
|
---|
169 | return OverlayMapIterator(mOverlayMap.begin(), mOverlayMap.end());
|
---|
170 | }
|
---|
171 | //---------------------------------------------------------------------
|
---|
172 | void OverlayManager::parseScript(DataStreamPtr& stream, const String& groupName)
|
---|
173 | {
|
---|
174 | // check if we've seen this script before (can happen if included
|
---|
175 | // multiple times)
|
---|
176 | if (!stream->getName().empty() &&
|
---|
177 | mLoadedScripts.find(stream->getName()) != mLoadedScripts.end())
|
---|
178 | {
|
---|
179 | LogManager::getSingleton().logMessage(
|
---|
180 | "Skipping loading overlay include: '"
|
---|
181 | + stream->getName() + " as it is already loaded.");
|
---|
182 | return;
|
---|
183 | }
|
---|
184 | String line;
|
---|
185 | Overlay* pOverlay = 0;
|
---|
186 | bool skipLine;
|
---|
187 |
|
---|
188 | while(!stream->eof())
|
---|
189 | {
|
---|
190 | bool isTemplate = false;
|
---|
191 | skipLine = false;
|
---|
192 | line = stream->getLine();
|
---|
193 | // Ignore comments & blanks
|
---|
194 | if (!(line.length() == 0 || line.substr(0,2) == "//"))
|
---|
195 | {
|
---|
196 | if (line.substr(0,8) == "#include")
|
---|
197 | {
|
---|
198 | std::vector<String> params = StringUtil::split(line, "\t\n ()<>");
|
---|
199 | DataStreamPtr includeStream =
|
---|
200 | ResourceGroupManager::getSingleton().openResource(
|
---|
201 | params[1], groupName);
|
---|
202 | parseScript(includeStream, groupName);
|
---|
203 | continue;
|
---|
204 | }
|
---|
205 | if (!pOverlay)
|
---|
206 | {
|
---|
207 | // No current overlay
|
---|
208 |
|
---|
209 | // check to see if there is a template
|
---|
210 | if (line.substr(0,8) == "template")
|
---|
211 | {
|
---|
212 | isTemplate = true;
|
---|
213 |
|
---|
214 | }
|
---|
215 | else
|
---|
216 | {
|
---|
217 |
|
---|
218 | // So first valid data should be overlay name
|
---|
219 | pOverlay = create(line);
|
---|
220 | pOverlay->_notifyOrigin(stream->getName());
|
---|
221 | // Skip to and over next {
|
---|
222 | skipToNextOpenBrace(stream);
|
---|
223 | skipLine = true;
|
---|
224 | }
|
---|
225 | }
|
---|
226 | if ((pOverlay && !skipLine) || isTemplate)
|
---|
227 | {
|
---|
228 | // Already in overlay
|
---|
229 | std::vector<String> params = StringUtil::split(line, "\t\n ()");
|
---|
230 |
|
---|
231 |
|
---|
232 | uint skipParam = 0;
|
---|
233 | if (line == "}")
|
---|
234 | {
|
---|
235 | // Finished overlay
|
---|
236 | pOverlay = 0;
|
---|
237 | isTemplate = false;
|
---|
238 | }
|
---|
239 | else if (parseChildren(stream,line, pOverlay, isTemplate, NULL))
|
---|
240 |
|
---|
241 | {
|
---|
242 |
|
---|
243 | }
|
---|
244 | else if (params[0+skipParam] == "entity")
|
---|
245 | {
|
---|
246 | // new 3D element
|
---|
247 | if (params.size() != (3+skipParam))
|
---|
248 | {
|
---|
249 | LogManager::getSingleton().logMessage(
|
---|
250 | "Bad entity line: '"
|
---|
251 | + line + "' in " + pOverlay->getName() +
|
---|
252 | ", expecting 'entity meshName(entityName)'");
|
---|
253 | skipToNextCloseBrace(stream);
|
---|
254 | }
|
---|
255 | else
|
---|
256 | {
|
---|
257 | skipToNextOpenBrace(stream);
|
---|
258 | parseNewMesh(stream, params[1+skipParam], params[2+skipParam], pOverlay);
|
---|
259 | }
|
---|
260 |
|
---|
261 | }
|
---|
262 | else
|
---|
263 | {
|
---|
264 | // Attribute
|
---|
265 | if (!isTemplate)
|
---|
266 | {
|
---|
267 | parseAttrib(line, pOverlay);
|
---|
268 | }
|
---|
269 | }
|
---|
270 |
|
---|
271 | }
|
---|
272 |
|
---|
273 | }
|
---|
274 |
|
---|
275 |
|
---|
276 | }
|
---|
277 |
|
---|
278 | // record as parsed
|
---|
279 | mLoadedScripts.insert(stream->getName());
|
---|
280 |
|
---|
281 | }
|
---|
282 | //---------------------------------------------------------------------
|
---|
283 | void OverlayManager::_queueOverlaysForRendering(Camera* cam,
|
---|
284 | RenderQueue* pQueue, Viewport* vp)
|
---|
285 | {
|
---|
286 | // Flag for update pixel-based GUIElements if viewport has changed dimensions
|
---|
287 | if (mLastViewportWidth != vp->getActualWidth() ||
|
---|
288 | mLastViewportHeight != vp->getActualHeight())
|
---|
289 | {
|
---|
290 | mViewportDimensionsChanged = true;
|
---|
291 | mLastViewportWidth = vp->getActualWidth();
|
---|
292 | mLastViewportHeight = vp->getActualHeight();
|
---|
293 |
|
---|
294 | }
|
---|
295 | else
|
---|
296 | {
|
---|
297 | mViewportDimensionsChanged = false;
|
---|
298 | }
|
---|
299 |
|
---|
300 | OverlayMap::iterator i, iend;
|
---|
301 | iend = mOverlayMap.end();
|
---|
302 | for (i = mOverlayMap.begin(); i != iend; ++i)
|
---|
303 | {
|
---|
304 | Overlay* o = i->second;
|
---|
305 | o->_findVisibleObjects(cam, pQueue);
|
---|
306 | }
|
---|
307 | }
|
---|
308 | //---------------------------------------------------------------------
|
---|
309 | void OverlayManager::parseNewElement( DataStreamPtr& stream, String& elemType, String& elemName,
|
---|
310 | bool isContainer, Overlay* pOverlay, bool isTemplate, String templateName, OverlayContainer* container)
|
---|
311 | {
|
---|
312 | String line;
|
---|
313 |
|
---|
314 | OverlayElement* newElement = NULL;
|
---|
315 | newElement =
|
---|
316 | OverlayManager::getSingleton().createOverlayElementFromTemplate(templateName, elemType, elemName, isTemplate);
|
---|
317 |
|
---|
318 | // do not add a template to an overlay
|
---|
319 |
|
---|
320 | // add new element to parent
|
---|
321 | if (container)
|
---|
322 | {
|
---|
323 | // Attach to container
|
---|
324 | container->addChild(newElement);
|
---|
325 | }
|
---|
326 | // do not add a template to the overlay. For templates overlay = 0
|
---|
327 | else if (pOverlay)
|
---|
328 | {
|
---|
329 | pOverlay->add2D((OverlayContainer*)newElement);
|
---|
330 | }
|
---|
331 |
|
---|
332 | while(!stream->eof())
|
---|
333 | {
|
---|
334 | line = stream->getLine();
|
---|
335 | // Ignore comments & blanks
|
---|
336 | if (!(line.length() == 0 || line.substr(0,2) == "//"))
|
---|
337 | {
|
---|
338 | if (line == "}")
|
---|
339 | {
|
---|
340 | // Finished element
|
---|
341 | break;
|
---|
342 | }
|
---|
343 | else
|
---|
344 | {
|
---|
345 | if (isContainer && parseChildren(stream,line, pOverlay, isTemplate, static_cast<OverlayContainer*>(newElement)))
|
---|
346 | {
|
---|
347 | // nested children... don't reparse it
|
---|
348 | }
|
---|
349 | else
|
---|
350 | {
|
---|
351 | // Attribute
|
---|
352 | parseElementAttrib(line, pOverlay, newElement);
|
---|
353 | }
|
---|
354 | }
|
---|
355 | }
|
---|
356 | }
|
---|
357 | }
|
---|
358 |
|
---|
359 | //---------------------------------------------------------------------
|
---|
360 | bool OverlayManager::parseChildren( DataStreamPtr& stream, const String& line,
|
---|
361 | Overlay* pOverlay, bool isTemplate, OverlayContainer* parent)
|
---|
362 | {
|
---|
363 | bool ret = false;
|
---|
364 | std::vector<String> params;
|
---|
365 | uint skipParam =0;
|
---|
366 | params = StringUtil::split(line, "\t\n ()");
|
---|
367 |
|
---|
368 | if (isTemplate)
|
---|
369 | {
|
---|
370 | if (params[0] == "template")
|
---|
371 | {
|
---|
372 | skipParam++; // the first param = 'template' on a new child element
|
---|
373 | }
|
---|
374 | }
|
---|
375 |
|
---|
376 | // top level component cannot be an element, it must be a container unless it is a template
|
---|
377 | if (params[0+skipParam] == "container" || (params[0+skipParam] == "element" && (isTemplate || parent != NULL)) )
|
---|
378 | {
|
---|
379 | String templateName = "";
|
---|
380 | ret = true;
|
---|
381 | // nested container/element
|
---|
382 | if (params.size() > 3+skipParam)
|
---|
383 | {
|
---|
384 | if (params.size() != 5+skipParam)
|
---|
385 | {
|
---|
386 | LogManager::getSingleton().logMessage(
|
---|
387 | "Bad element/container line: '"
|
---|
388 | + line + "' in " + parent->getTypeName()+ " " + parent->getName() +
|
---|
389 | ", expecting ':' templateName");
|
---|
390 | skipToNextCloseBrace(stream);
|
---|
391 | // barf
|
---|
392 | return ret;
|
---|
393 | }
|
---|
394 | if (params[3+skipParam] != ":")
|
---|
395 | {
|
---|
396 | LogManager::getSingleton().logMessage(
|
---|
397 | "Bad element/container line: '"
|
---|
398 | + line + "' in " + parent->getTypeName()+ " " + parent->getName() +
|
---|
399 | ", expecting ':' for element inheritance");
|
---|
400 | skipToNextCloseBrace(stream);
|
---|
401 | // barf
|
---|
402 | return ret;
|
---|
403 | }
|
---|
404 |
|
---|
405 | templateName = params[4+skipParam];
|
---|
406 | }
|
---|
407 |
|
---|
408 | else if (params.size() != 3+skipParam)
|
---|
409 | {
|
---|
410 | LogManager::getSingleton().logMessage(
|
---|
411 | "Bad element/container line: '"
|
---|
412 | + line + "' in " + parent->getTypeName()+ " " + parent->getName() +
|
---|
413 | ", expecting 'element type(name)'");
|
---|
414 | skipToNextCloseBrace(stream);
|
---|
415 | // barf
|
---|
416 | return ret;
|
---|
417 | }
|
---|
418 |
|
---|
419 | skipToNextOpenBrace(stream);
|
---|
420 | parseNewElement(stream, params[1+skipParam], params[2+skipParam], true, pOverlay, isTemplate, templateName, (OverlayContainer*)parent);
|
---|
421 |
|
---|
422 | }
|
---|
423 |
|
---|
424 |
|
---|
425 | return ret;
|
---|
426 | }
|
---|
427 |
|
---|
428 | //---------------------------------------------------------------------
|
---|
429 | void OverlayManager::parseAttrib( const String& line, Overlay* pOverlay)
|
---|
430 | {
|
---|
431 | std::vector<String> vecparams;
|
---|
432 |
|
---|
433 | // Split params on first space
|
---|
434 | vecparams = StringUtil::split(line, "\t ", 1);
|
---|
435 |
|
---|
436 | // Look up first param (command setting)
|
---|
437 | StringUtil::toLowerCase(vecparams[0]);
|
---|
438 | if (vecparams[0] == "zorder")
|
---|
439 | {
|
---|
440 | pOverlay->setZOrder(StringConverter::parseUnsignedInt(vecparams[1]));
|
---|
441 | }
|
---|
442 | else
|
---|
443 | {
|
---|
444 | LogManager::getSingleton().logMessage("Bad overlay attribute line: '"
|
---|
445 | + line + "' for overlay " + pOverlay->getName());
|
---|
446 | }
|
---|
447 | }
|
---|
448 | //---------------------------------------------------------------------
|
---|
449 | void OverlayManager::parseElementAttrib( const String& line, Overlay* pOverlay, OverlayElement* pElement )
|
---|
450 | {
|
---|
451 | std::vector<String> vecparams;
|
---|
452 |
|
---|
453 | // Split params on first space
|
---|
454 | vecparams = StringUtil::split(line, "\t ", 1);
|
---|
455 |
|
---|
456 | // Look up first param (command setting)
|
---|
457 | StringUtil::toLowerCase(vecparams[0]);
|
---|
458 | if (!pElement->setParameter(vecparams[0], vecparams[1]))
|
---|
459 | {
|
---|
460 | // BAD command. BAD!
|
---|
461 | LogManager::getSingleton().logMessage("Bad element attribute line: '"
|
---|
462 | + line + "' for element " + pElement->getName() + " in overlay " +
|
---|
463 | (!pOverlay ? "" : pOverlay->getName().c_str() ));
|
---|
464 | }
|
---|
465 | }
|
---|
466 | //-----------------------------------------------------------------------
|
---|
467 | void OverlayManager::skipToNextCloseBrace(DataStreamPtr& stream)
|
---|
468 | {
|
---|
469 | String line = "";
|
---|
470 | while (!stream->eof() && line != "}")
|
---|
471 | {
|
---|
472 | line = stream->getLine();
|
---|
473 | }
|
---|
474 |
|
---|
475 | }
|
---|
476 | //-----------------------------------------------------------------------
|
---|
477 | void OverlayManager::skipToNextOpenBrace(DataStreamPtr& stream)
|
---|
478 | {
|
---|
479 | String line = "";
|
---|
480 | while (!stream->eof() && line != "{")
|
---|
481 | {
|
---|
482 | line = stream->getLine();
|
---|
483 | }
|
---|
484 |
|
---|
485 | }
|
---|
486 | //-----------------------------------------------------------------------
|
---|
487 | void OverlayManager::parseNewMesh(DataStreamPtr& stream, String& meshName, String& entityName,
|
---|
488 | Overlay* pOverlay)
|
---|
489 | {
|
---|
490 | String line;
|
---|
491 | StringVector params;
|
---|
492 |
|
---|
493 | // NB at this stage any scene manager will do, it's just for allocation not rendering
|
---|
494 | SceneManager* sm = SceneManagerEnumerator::getSingleton().getSceneManager(ST_GENERIC);
|
---|
495 |
|
---|
496 | // Create entity
|
---|
497 | Entity* ent = sm->createEntity(entityName, meshName);
|
---|
498 | // Add a new entity via a node
|
---|
499 | SceneNode* node = sm->createSceneNode(entityName + "_autoNode");
|
---|
500 |
|
---|
501 | node->attachObject(ent);
|
---|
502 |
|
---|
503 |
|
---|
504 | // parse extra info
|
---|
505 | while(!stream->eof())
|
---|
506 | {
|
---|
507 | line = stream->getLine();
|
---|
508 | // Ignore comments & blanks
|
---|
509 | if (!(line.length() == 0 || line.substr(0,2) == "//"))
|
---|
510 | {
|
---|
511 | if (line == "}")
|
---|
512 | {
|
---|
513 | // Finished
|
---|
514 | break;
|
---|
515 | }
|
---|
516 | else
|
---|
517 | {
|
---|
518 | if (line.substr(0, 8) == "position")
|
---|
519 | {
|
---|
520 | params = StringUtil::split(line, " \t");
|
---|
521 | if (params.size() != 4)
|
---|
522 | {
|
---|
523 | LogManager::getSingleton().logMessage("Bad position attribute line: '"
|
---|
524 | + line + "' for entity " + entityName + " in overlay " +
|
---|
525 | pOverlay->getName());
|
---|
526 | break;
|
---|
527 | }
|
---|
528 | node->translate(StringConverter::parseReal(params[1]),
|
---|
529 | StringConverter::parseReal(params[2]),
|
---|
530 | StringConverter::parseReal(params[3]));
|
---|
531 | }
|
---|
532 | else if (line.substr(0, 8) == "rotation")
|
---|
533 | {
|
---|
534 | params = StringUtil::split(line, " \t");
|
---|
535 | if (params.size() != 5)
|
---|
536 | {
|
---|
537 | LogManager::getSingleton().logMessage("Bad rotation attribute line: '"
|
---|
538 | + line + "' for entity " + entityName + " in overlay " +
|
---|
539 | pOverlay->getName());
|
---|
540 | break;
|
---|
541 | }
|
---|
542 | // in file it is angle axis_x axis_y axis_z
|
---|
543 | Vector3 axis(StringConverter::parseReal(params[2]),
|
---|
544 | StringConverter::parseReal(params[3]),
|
---|
545 | StringConverter::parseReal(params[4]));
|
---|
546 | node->rotate(axis, StringConverter::parseAngle(params[1]));
|
---|
547 | }
|
---|
548 | }
|
---|
549 | }
|
---|
550 | }
|
---|
551 |
|
---|
552 |
|
---|
553 |
|
---|
554 | // Attach node to overlay
|
---|
555 | pOverlay->add3D(node);
|
---|
556 |
|
---|
557 | }
|
---|
558 | //---------------------------------------------------------------------
|
---|
559 | bool OverlayManager::hasViewportChanged(void) const
|
---|
560 | {
|
---|
561 | return mViewportDimensionsChanged;
|
---|
562 | }
|
---|
563 | //---------------------------------------------------------------------
|
---|
564 | int OverlayManager::getViewportHeight(void) const
|
---|
565 | {
|
---|
566 | return mLastViewportHeight;
|
---|
567 | }
|
---|
568 | //---------------------------------------------------------------------
|
---|
569 | int OverlayManager::getViewportWidth(void) const
|
---|
570 | {
|
---|
571 | return mLastViewportWidth;
|
---|
572 | }
|
---|
573 | //---------------------------------------------------------------------
|
---|
574 | Real OverlayManager::getViewportAspectRatio(void) const
|
---|
575 | {
|
---|
576 | return (Real)mLastViewportHeight / (Real)mLastViewportWidth;
|
---|
577 | }
|
---|
578 | //---------------------------------------------------------------------
|
---|
579 | //---------------------------------------------------------------------
|
---|
580 | OverlayManager::ElementMap& OverlayManager::getElementMap(bool isTemplate)
|
---|
581 | {
|
---|
582 | return (isTemplate)?mTemplates:mInstances;
|
---|
583 | }
|
---|
584 |
|
---|
585 | //---------------------------------------------------------------------
|
---|
586 | OverlayElement* OverlayManager::createOverlayElementFromTemplate(const String& templateName, const String& typeName, const String& instanceName, bool isTemplate)
|
---|
587 | {
|
---|
588 |
|
---|
589 | OverlayElement* newObj = NULL;
|
---|
590 |
|
---|
591 | if (templateName == "")
|
---|
592 | {
|
---|
593 | newObj = createOverlayElement(typeName, instanceName, isTemplate);
|
---|
594 | }
|
---|
595 | else
|
---|
596 | {
|
---|
597 | // no template
|
---|
598 | OverlayElement* templateGui = getOverlayElement(templateName, true);
|
---|
599 |
|
---|
600 | String typeNameToCreate;
|
---|
601 | if (typeName == "")
|
---|
602 | {
|
---|
603 | typeNameToCreate = templateGui->getTypeName();
|
---|
604 | }
|
---|
605 | else
|
---|
606 | {
|
---|
607 | typeNameToCreate = typeName;
|
---|
608 | }
|
---|
609 |
|
---|
610 | newObj = createOverlayElement(typeNameToCreate, instanceName, isTemplate);
|
---|
611 |
|
---|
612 | ((OverlayContainer*)newObj)->copyFromTemplate(templateGui);
|
---|
613 | }
|
---|
614 |
|
---|
615 | return newObj;
|
---|
616 | }
|
---|
617 |
|
---|
618 |
|
---|
619 | //---------------------------------------------------------------------
|
---|
620 | OverlayElement* OverlayManager::cloneOverlayElementFromTemplate(const String& templateName, const String& instanceName)
|
---|
621 | {
|
---|
622 | OverlayElement* templateGui = getOverlayElement(templateName, true);
|
---|
623 | return templateGui->clone(instanceName);
|
---|
624 | }
|
---|
625 |
|
---|
626 | //---------------------------------------------------------------------
|
---|
627 | OverlayElement* OverlayManager::createOverlayElement(const String& typeName, const String& instanceName, bool isTemplate)
|
---|
628 | {
|
---|
629 | return createOverlayElementImpl(typeName, instanceName, getElementMap(isTemplate));
|
---|
630 | }
|
---|
631 |
|
---|
632 | //---------------------------------------------------------------------
|
---|
633 | OverlayElement* OverlayManager::createOverlayElementImpl(const String& typeName, const String& instanceName, ElementMap& elementMap)
|
---|
634 | {
|
---|
635 | // Check not duplicated
|
---|
636 | ElementMap::iterator ii = elementMap.find(instanceName);
|
---|
637 | if (ii != elementMap.end())
|
---|
638 | {
|
---|
639 | OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM, "OverlayElement with name " + instanceName +
|
---|
640 | " already exists.", "OverlayManager::createOverlayElement" );
|
---|
641 | }
|
---|
642 | OverlayElement* newElem = createOverlayElementFromFactory(typeName, instanceName);
|
---|
643 |
|
---|
644 | // Register
|
---|
645 | elementMap.insert(ElementMap::value_type(instanceName, newElem));
|
---|
646 |
|
---|
647 | return newElem;
|
---|
648 |
|
---|
649 |
|
---|
650 | }
|
---|
651 |
|
---|
652 | //---------------------------------------------------------------------
|
---|
653 | OverlayElement* OverlayManager::createOverlayElementFromFactory(const String& typeName, const String& instanceName)
|
---|
654 | {
|
---|
655 | // Look up factory
|
---|
656 | FactoryMap::iterator fi = mFactories.find(typeName);
|
---|
657 | if (fi == mFactories.end())
|
---|
658 | {
|
---|
659 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Cannot locate factory for element type " + typeName,
|
---|
660 | "OverlayManager::createOverlayElement");
|
---|
661 | }
|
---|
662 |
|
---|
663 | // create
|
---|
664 | return fi->second->createOverlayElement(instanceName);
|
---|
665 | }
|
---|
666 |
|
---|
667 | //---------------------------------------------------------------------
|
---|
668 | OverlayElement* OverlayManager::getOverlayElement(const String& name, bool isTemplate)
|
---|
669 | {
|
---|
670 | return getOverlayElementImpl(name, getElementMap(isTemplate));
|
---|
671 | }
|
---|
672 | //---------------------------------------------------------------------
|
---|
673 | OverlayElement* OverlayManager::getOverlayElementImpl(const String& name, ElementMap& elementMap)
|
---|
674 | {
|
---|
675 | // Locate instance
|
---|
676 | ElementMap::iterator ii = elementMap.find(name);
|
---|
677 | if (ii == elementMap.end())
|
---|
678 | {
|
---|
679 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "OverlayElement with name " + name +
|
---|
680 | " not found.", "OverlayManager::getOverlayElementImpl" );
|
---|
681 | }
|
---|
682 |
|
---|
683 | return ii->second;
|
---|
684 | }
|
---|
685 | //---------------------------------------------------------------------
|
---|
686 | void OverlayManager::destroyOverlayElement(const String& instanceName, bool isTemplate)
|
---|
687 | {
|
---|
688 | destroyOverlayElementImpl(instanceName, getElementMap(isTemplate));
|
---|
689 | }
|
---|
690 |
|
---|
691 | //---------------------------------------------------------------------
|
---|
692 | void OverlayManager::destroyOverlayElement(OverlayElement* pInstance, bool isTemplate)
|
---|
693 | {
|
---|
694 | destroyOverlayElementImpl(pInstance->getName(), getElementMap(isTemplate));
|
---|
695 | }
|
---|
696 |
|
---|
697 | //---------------------------------------------------------------------
|
---|
698 | void OverlayManager::destroyOverlayElementImpl(const String& instanceName, ElementMap& elementMap)
|
---|
699 | {
|
---|
700 | // Locate instance
|
---|
701 | ElementMap::iterator ii = elementMap.find(instanceName);
|
---|
702 | if (ii == elementMap.end())
|
---|
703 | {
|
---|
704 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "OverlayElement with name " + instanceName +
|
---|
705 | " not found.", "OverlayManager::destroyOverlayElement" );
|
---|
706 | }
|
---|
707 | // Look up factory
|
---|
708 | const String& typeName = ii->second->getTypeName();
|
---|
709 | FactoryMap::iterator fi = mFactories.find(typeName);
|
---|
710 | if (fi == mFactories.end())
|
---|
711 | {
|
---|
712 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Cannot locate factory for element type " + typeName,
|
---|
713 | "OverlayManager::destroyOverlayElement");
|
---|
714 | }
|
---|
715 |
|
---|
716 | fi->second->destroyOverlayElement(ii->second);
|
---|
717 | elementMap.erase(ii);
|
---|
718 | }
|
---|
719 | //---------------------------------------------------------------------
|
---|
720 | void OverlayManager::destroyAllOverlayElements(bool isTemplate)
|
---|
721 | {
|
---|
722 | destroyAllOverlayElementsImpl(getElementMap(isTemplate));
|
---|
723 | }
|
---|
724 | //---------------------------------------------------------------------
|
---|
725 | void OverlayManager::destroyAllOverlayElementsImpl(ElementMap& elementMap)
|
---|
726 | {
|
---|
727 | ElementMap::iterator i;
|
---|
728 |
|
---|
729 | while ((i = elementMap.begin()) != elementMap.end())
|
---|
730 | {
|
---|
731 | OverlayElement* element = i->second;
|
---|
732 |
|
---|
733 | // Get factory to delete
|
---|
734 | FactoryMap::iterator fi = mFactories.find(element->getTypeName());
|
---|
735 | if (fi == mFactories.end())
|
---|
736 | {
|
---|
737 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Cannot locate factory for element "
|
---|
738 | + element->getName(),
|
---|
739 | "OverlayManager::destroyAllOverlayElements");
|
---|
740 | }
|
---|
741 |
|
---|
742 | // remove from parent, if any
|
---|
743 | OverlayContainer* parent;
|
---|
744 | if ((parent = element->getParent()) != 0)
|
---|
745 | {
|
---|
746 | parent->_removeChild(element->getName());
|
---|
747 | }
|
---|
748 |
|
---|
749 | // children of containers will be auto-removed when container is destroyed.
|
---|
750 | // destroy the element and remove it from the list
|
---|
751 | fi->second->destroyOverlayElement(element);
|
---|
752 | elementMap.erase(i);
|
---|
753 | }
|
---|
754 | }
|
---|
755 | //---------------------------------------------------------------------
|
---|
756 | void OverlayManager::addOverlayElementFactory(OverlayElementFactory* elemFactory)
|
---|
757 | {
|
---|
758 | // Add / replace
|
---|
759 | mFactories[elemFactory->getTypeName()] = elemFactory;
|
---|
760 |
|
---|
761 | LogManager::getSingleton().logMessage("OverlayElementFactory for type " + elemFactory->getTypeName()
|
---|
762 | + " registered.");
|
---|
763 | }
|
---|
764 | }
|
---|
765 |
|
---|