lugre_SortedOverlayContainer.cpp

Go to the documentation of this file.
00001 #include "lugre_SortedOverlayContainer.h"
00002 #include <OgreOverlayElementFactory.h>
00003 #include <OgreOverlayManager.h>
00004 #include <OgrePrerequisites.h>
00005 #include <algorithm>
00006 
00007 
00008 using namespace Ogre;
00009 
00010 
00011 
00012 namespace Lugre {
00013 
00014 String cSortedOverlayContainer::msTypeName = "SortedOverlayContainer";
00015 
00016 // ***** ***** ***** ***** ***** Factory
00017 
00019 class /*_OgreExport*/ SortedOverlayContainerElementFactory: public OverlayElementFactory { public:
00021     OverlayElement* createOverlayElement(const String& instanceName) {
00022         return new cSortedOverlayContainer(instanceName);
00023     }
00025     const String& getTypeName(void) const {
00026         return cSortedOverlayContainer::msTypeName;
00027     }
00028 };
00029 
00030 //SiENcE
00031 void    cSortedOverlayContainer::RegisterFactory () {
00032     OverlayManager::getSingleton().addOverlayElementFactory(new SortedOverlayContainerElementFactory());
00033 }
00034         
00035 
00036 
00037 // ***** ***** ***** ***** ***** cSortedOverlayContainer
00038 
00039 
00040 
00041 cSortedOverlayContainer::cSortedOverlayContainer(const Ogre::String& name) : 
00042     cColourClipPaneOverlay(name), miRankFactor(3) {}
00043     
00044 cSortedOverlayContainer::~cSortedOverlayContainer() {}
00045 
00046 void    cSortedOverlayContainer::SetRankFactor      (const int iRankFactor) {
00047     miRankFactor = iRankFactor;
00048     _notifyZOrder(mZOrder);
00049 }
00050 
00051 void    cSortedOverlayContainer::ChildBringToFront  (Ogre::OverlayElement* child) {
00052     mlSortedList.remove(child);
00053     mlSortedList.push_back(child);
00054     _notifyZOrder(mZOrder);
00055 }
00056 
00057 void    cSortedOverlayContainer::ChildSendToBack    (Ogre::OverlayElement* child) {
00058     mlSortedList.remove(child);
00059     mlSortedList.push_front(child);
00060     _notifyZOrder(mZOrder);
00061 }
00062 
00063 void    cSortedOverlayContainer::ChildInsertAfter   (Ogre::OverlayElement* child,Ogre::OverlayElement* other) {
00064     mlSortedList.remove(child);
00065     std::list<OverlayElement*>::iterator itor = find(mlSortedList.begin(),mlSortedList.end(),other);
00066     if (itor != mlSortedList.end()) 
00067             mlSortedList.insert(++itor,child); 
00068     else    mlSortedList.push_back(child);
00069     _notifyZOrder(mZOrder);
00070 }
00071 
00072 void    cSortedOverlayContainer::ChildInsertBefore  (Ogre::OverlayElement* child,Ogre::OverlayElement* other) {
00073     mlSortedList.remove(child);
00074     std::list<OverlayElement*>::iterator itor = find(mlSortedList.begin(),mlSortedList.end(),other);
00075     if (itor != mlSortedList.end()) 
00076             mlSortedList.insert(itor,child); 
00077     else    mlSortedList.push_front(child);
00078     _notifyZOrder(mZOrder);
00079 }
00080 
00082 int     cSortedOverlayContainer::GetChildRank       (OverlayElement* elem) {
00083     int i=0;
00084     for (std::list<OverlayElement*>::iterator itor=mlSortedList.begin();itor!=mlSortedList.end();++itor,++i) 
00085         if (*itor == elem) return i*miRankFactor;
00086     return 0;
00087 }
00088 
00089 
00090 //---------------------------------------------------------------------
00091 void cSortedOverlayContainer::addChildImpl(OverlayElement* elem)
00092 {
00093     OverlayContainer::addChildImpl(elem);
00094     mlSortedList.push_back(elem);
00095     elem->_notifyZOrder(mZOrder + 1 + GetChildRank(elem));
00096 }
00097     
00098 //---------------------------------------------------------------------
00099 void cSortedOverlayContainer::removeChild(const String& name)
00100 {
00101     ChildMap::iterator i = mChildren.find(name);
00102     if (i == mChildren.end())
00103     {
00104         OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Child with name " + name + 
00105             " not found.", "cSortedOverlayContainer::removeChild");
00106     }
00107     OverlayElement* element = i->second;
00108     mlSortedList.remove(element);
00109         
00110     OverlayContainer::removeChild(name);
00111     _notifyZOrder(mZOrder); // reorder the others
00112 }
00113 
00114 //---------------------------------------------------------------------
00115 #if OGRE_VERSION >= 0x10600 // shoggoth
00116 Ogre::ushort cSortedOverlayContainer::_notifyZOrder(Ogre::ushort newZOrder) {
00117 #else
00118 void cSortedOverlayContainer::_notifyZOrder(Ogre::ushort newZOrder) {
00119 #endif
00120     mZOrder = newZOrder;
00121     cColourClipPaneOverlay::_notifyZOrder(mZOrder);
00122 
00123     // Update children
00124     int i=0;
00125     for (std::list<OverlayElement*>::iterator itor=mlSortedList.begin();itor!=mlSortedList.end();++itor,++i)
00126         (*itor)->_notifyZOrder(mZOrder + 1 + i*miRankFactor);
00127     #if OGRE_VERSION >= 0x10600 // shoggoth
00128         // Return the next zordering number available. For single elements, this is simply newZOrder + 1, but for containers, they increment it once for each child (more if those children are also containers). 
00129         return newZOrder + 1;
00130     #endif
00131 }
00132 
00134 const String& cSortedOverlayContainer::getTypeName(void) const {
00135     return msTypeName;
00136 }
00137 
00138 };

Generated on Wed May 23 06:00:15 2012 for cpp by  doxygen 1.5.6