00001 00002 /* 00003 ----------------------------------------------------------------------------- 00004 This source file is part of OGRE 00005 (Object-oriented Graphics Rendering Engine) 00006 For the latest info, see http://www.ogre3d.org/ 00007 00008 Copyright © 2000-2002 The OGRE Team 00009 Also see acknowledgements in Readme.html 00010 00011 This program is free software you can redistribute it and/or modify it under 00012 the terms of the GNU Lesser General Public License as published by the Free Software 00013 Foundation either version 2 of the License, or (at your option) any later 00014 version. 00015 00016 This program is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS 00018 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public License along with 00021 this program if not, write to the Free Software Foundation, Inc., 59 Temple 00022 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00023 http://www.gnu.org/copyleft/lesser.txt. 00024 ----------------------------------------------------------------------------- 00025 */ 00026 #include "OgreStableHeaders.h" 00027 00028 #include "OgreGuiContainer.h" 00029 #include "OgreException.h" 00030 #include "OgreMouseEvent.h" 00031 #include "OgreGuiManager.h" 00032 00033 namespace Ogre { 00034 00035 //--------------------------------------------------------------------- 00036 GuiContainer::GuiContainer(const String& name) 00037 : GuiElement(name), 00038 mChildrenProcessEvents(true) 00039 { 00040 } 00041 //--------------------------------------------------------------------- 00042 GuiContainer::~GuiContainer() 00043 { 00044 } 00045 //--------------------------------------------------------------------- 00046 void GuiContainer::addChild(GuiElement* elem) 00047 { 00048 if (elem->isContainer()) 00049 { 00050 addChildImpl(static_cast<GuiContainer*>(elem)); 00051 } 00052 else 00053 { 00054 addChildImpl(elem); 00055 } 00056 00057 } 00058 //--------------------------------------------------------------------- 00059 void GuiContainer::addChildImpl(GuiElement* elem) 00060 { 00061 String name = elem->getName(); 00062 ChildMap::iterator i = mChildren.find(name); 00063 if (i != mChildren.end()) 00064 { 00065 Except(Exception::ERR_DUPLICATE_ITEM, "Child with name " + name + 00066 " already defined.", "GuiContainer::addChild"); 00067 } 00068 00069 mChildren.insert(ChildMap::value_type(name, elem)); 00070 // tell child about parent & ZOrder 00071 elem->_notifyParent(this, mOverlay); 00072 elem->_notifyZOrder(mZOrder + 1); 00073 00074 } 00075 //--------------------------------------------------------------------- 00076 void GuiContainer::addChildImpl(GuiContainer* cont) 00077 { 00078 // Add to main map first 00079 // This will pick up duplicates 00080 GuiElement* pElem = cont; 00081 addChildImpl(pElem); 00082 cont->_notifyParent(this, mOverlay); 00083 cont->_notifyZOrder(mZOrder + 1); 00084 00085 // tell children of new container the current overlay 00086 ChildIterator it = cont->getChildIterator(); 00087 while (it.hasMoreElements()) 00088 { 00089 // Give children ZOrder 1 higher than this 00090 GuiElement* pElemChild = it.getNext(); 00091 pElemChild->_notifyParent(cont, mOverlay); 00092 pElemChild->_notifyZOrder(cont->getZOrder() + 1); 00093 } 00094 // Now add to specific map too 00095 mChildContainers.insert(ChildContainerMap::value_type(cont->getName(), cont)); 00096 00097 } 00098 //--------------------------------------------------------------------- 00099 void GuiContainer::removeChild(const String& name) 00100 { 00101 ChildMap::iterator i = mChildren.find(name); 00102 if (i == mChildren.end()) 00103 { 00104 Except(Exception::ERR_ITEM_NOT_FOUND, "Child with name " + name + 00105 " not found.", "GuiContainer::removeChild"); 00106 } 00107 00108 mChildren.erase(i); 00109 00110 } 00111 //--------------------------------------------------------------------- 00112 GuiElement* GuiContainer::getChild(const String& name) 00113 { 00114 ChildMap::iterator i = mChildren.find(name); 00115 if (i == mChildren.end()) 00116 { 00117 Except(Exception::ERR_ITEM_NOT_FOUND, "Child with name " + name + 00118 " not found.", "GuiContainer::getChild"); 00119 } 00120 00121 return i->second; 00122 } 00123 //--------------------------------------------------------------------- 00124 GuiContainer::ChildIterator GuiContainer::getChildIterator(void) 00125 { 00126 return ChildIterator(mChildren.begin(), mChildren.end()); 00127 } 00128 //--------------------------------------------------------------------- 00129 GuiContainer::ChildContainerIterator GuiContainer::getChildContainerIterator(void) 00130 { 00131 return ChildContainerIterator(mChildContainers.begin(), mChildContainers.end()); 00132 } 00133 00134 //--------------------------------------------------------------------- 00135 void GuiContainer::_positionsOutOfDate(void) 00136 { 00137 GuiElement::_positionsOutOfDate(); 00138 00139 ChildIterator it = getChildIterator(); 00140 while (it.hasMoreElements()) 00141 { 00142 it.getNext()->_positionsOutOfDate(); 00143 } 00144 } 00145 00146 //--------------------------------------------------------------------- 00147 void GuiContainer::_update(void) 00148 { 00149 // call superclass 00150 GuiElement::_update(); 00151 00152 // Update children 00153 ChildIterator it = getChildIterator(); 00154 while (it.hasMoreElements()) 00155 { 00156 it.getNext()->_update(); 00157 } 00158 00159 00160 } 00161 //--------------------------------------------------------------------- 00162 void GuiContainer::_notifyZOrder(ushort newZOrder) 00163 { 00164 GuiElement::_notifyZOrder(newZOrder); 00165 00166 // Update children 00167 ChildIterator it = getChildIterator(); 00168 while (it.hasMoreElements()) 00169 { 00170 // Give children ZOrder 1 higher than this 00171 it.getNext()->_notifyZOrder(newZOrder + 1); 00172 } 00173 00174 } 00175 //--------------------------------------------------------------------- 00176 void GuiContainer::_notifyParent(GuiContainer* parent, Overlay* overlay) 00177 { 00178 GuiElement::_notifyParent(parent, overlay); 00179 00180 // Update children 00181 ChildIterator it = getChildIterator(); 00182 while (it.hasMoreElements()) 00183 { 00184 // Notify the children of the overlay 00185 it.getNext()->_notifyParent(this, overlay); 00186 } 00187 } 00188 00189 //--------------------------------------------------------------------- 00190 void GuiContainer::_updateRenderQueue(RenderQueue* queue) 00191 { 00192 if (mVisible) 00193 { 00194 00195 GuiElement::_updateRenderQueue(queue); 00196 00197 // Also add children 00198 ChildIterator it = getChildIterator(); 00199 while (it.hasMoreElements()) 00200 { 00201 // Give children ZOrder 1 higher than this 00202 it.getNext()->_updateRenderQueue(queue); 00203 } 00204 } 00205 00206 } 00207 00208 00209 GuiElement* GuiContainer::findElementAt(Real x, Real y) // relative to parent 00210 { 00211 00212 GuiElement* ret = NULL; 00213 00214 int currZ = -1; 00215 00216 if (mVisible) 00217 { 00218 ret = GuiElement::findElementAt(x,y); //default to the current container if no others are found 00219 if (ret && mChildrenProcessEvents) 00220 { 00221 ChildIterator it = getChildIterator(); 00222 while (it.hasMoreElements()) 00223 { 00224 GuiElement* currentGuiElement = it.getNext(); 00225 if (currentGuiElement->isVisible() && currentGuiElement->isEnabled()) 00226 { 00227 int z = currentGuiElement->getZOrder(); 00228 if (z > currZ) 00229 { 00230 GuiElement* elementFound = currentGuiElement->findElementAt(x ,y ); 00231 if (elementFound) 00232 { 00233 currZ = z; 00234 ret = elementFound; 00235 } 00236 } 00237 } 00238 } 00239 } 00240 } 00241 return ret; 00242 } 00243 00244 void GuiContainer::copyFromTemplate(GuiElement* templateGui) 00245 { 00246 00247 GuiElement::copyFromTemplate(templateGui); 00248 00249 if (templateGui->isContainer() && isContainer()) 00250 { 00251 GuiContainer::ChildIterator it = static_cast<GuiContainer*>(templateGui)->getChildIterator(); 00252 while (it.hasMoreElements()) 00253 { 00254 00255 GuiElement* oldChildElement = it.getNext(); 00256 if (oldChildElement->isCloneable()) 00257 { 00258 GuiElement* newChildElement = 00259 GuiManager::getSingleton().createGuiElement(oldChildElement->getTypeName(), mName+"/"+oldChildElement->getName()); 00260 oldChildElement->copyParametersTo(newChildElement); 00261 00262 00263 addChild((GuiContainer*)newChildElement); 00264 } 00265 } 00266 } 00267 } 00268 00269 } 00270
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:12 2004