#define __I_GUI_ELEMENT_H_INCLUDED__\r
\r
#include "IReferenceCounted.h"\r
-#include "irrList.h"\r
#include "rect.h"\r
#include "irrString.h"\r
#include "IEventReceiver.h"\r
#include "EGUIAlignment.h"\r
#include "IAttributes.h"\r
#include "IGUIEnvironment.h"\r
+#include <cassert>\r
+#include <algorithm>\r
+#include <list>\r
+#include <vector>\r
\r
namespace irr\r
{\r
//! Destructor\r
virtual ~IGUIElement()\r
{\r
- // delete all children\r
- core::list<IGUIElement*>::Iterator it = Children.begin();\r
- for (; it != Children.end(); ++it)\r
- {\r
- (*it)->Parent = 0;\r
- (*it)->drop();\r
+ for (auto child : Children) {\r
+ child->Parent = nullptr;\r
+ child->drop();\r
}\r
}\r
\r
recalculateAbsolutePosition(false);\r
\r
// update all children\r
- core::list<IGUIElement*>::Iterator it = Children.begin();\r
- for (; it != Children.end(); ++it)\r
+ for (auto child : Children)\r
{\r
- (*it)->updateAbsolutePosition();\r
+ child->updateAbsolutePosition();\r
}\r
}\r
\r
{\r
IGUIElement* target = 0;\r
\r
- // we have to search from back to front, because later children\r
- // might be drawn over the top of earlier ones.\r
-\r
- core::list<IGUIElement*>::ConstIterator it = Children.getLast();\r
-\r
if (isVisible())\r
{\r
- while(it != Children.end())\r
+ // we have to search from back to front, because later children\r
+ // might be drawn over the top of earlier ones.\r
+ auto it = Children.rbegin();\r
+ auto ie = Children.rend();\r
+ while (it != ie)\r
{\r
target = (*it)->getElementFromPoint(point);\r
if (target)\r
return target;\r
\r
- --it;\r
+ ++it;\r
}\r
}\r
\r
//! Removes a child.\r
virtual void removeChild(IGUIElement* child)\r
{\r
- core::list<IGUIElement*>::Iterator it = Children.begin();\r
- for (; it != Children.end(); ++it)\r
- if ((*it) == child)\r
- {\r
- (*it)->Parent = 0;\r
- (*it)->drop();\r
- Children.erase(it);\r
- return;\r
- }\r
+ assert(child->Parent == this);\r
+ Children.erase(child->ParentPos);\r
+ child->Parent = nullptr;\r
+ child->drop();\r
}\r
\r
+ //! Removes all children.\r
+ virtual void removeAllChildren() {\r
+ while (!Children.empty()) {\r
+ auto child = Children.back();\r
+ child->remove();\r
+ }\r
+ }\r
\r
//! Removes this element from its parent.\r
virtual void remove()\r
{\r
if ( isVisible() )\r
{\r
- core::list<IGUIElement*>::Iterator it = Children.begin();\r
- for (; it != Children.end(); ++it)\r
- (*it)->draw();\r
+ for (auto child : Children)\r
+ child->draw();\r
}\r
}\r
\r
{\r
if ( isVisible() )\r
{\r
- core::list<IGUIElement*>::Iterator it = Children.begin();\r
- for (; it != Children.end(); ++it)\r
- (*it)->OnPostRender( timeMs );\r
+ for (auto child : Children)\r
+ child->OnPostRender( timeMs );\r
}\r
}\r
\r
\r
//! Brings a child to front\r
/** \return True if successful, false if not. */\r
- virtual bool bringToFront(IGUIElement* element)\r
+ virtual bool bringToFront(IGUIElement* child)\r
{\r
- core::list<IGUIElement*>::Iterator it = Children.begin();\r
- for (; it != Children.end(); ++it)\r
- {\r
- if (element == (*it))\r
- {\r
- Children.erase(it);\r
- Children.push_back(element);\r
- return true;\r
- }\r
- }\r
-\r
- return false;\r
+ if (child->Parent != this)\r
+ return false;\r
+ if (std::next(child->ParentPos) == Children.end()) // already there\r
+ return true;\r
+ Children.erase(child->ParentPos);\r
+ child->ParentPos = Children.insert(Children.end(), child);\r
+ return true;\r
}\r
\r
\r
/** \return True if successful, false if not. */\r
virtual bool sendToBack(IGUIElement* child)\r
{\r
- core::list<IGUIElement*>::Iterator it = Children.begin();\r
- if (child == (*it)) // already there\r
+ if (child->Parent != this)\r
+ return false;\r
+ if (child->ParentPos == Children.begin()) // already there\r
return true;\r
- for (; it != Children.end(); ++it)\r
- {\r
- if (child == (*it))\r
- {\r
- Children.erase(it);\r
- Children.push_front(child);\r
- return true;\r
- }\r
- }\r
-\r
- return false;\r
+ Children.erase(child->ParentPos);\r
+ child->ParentPos = Children.insert(Children.begin(), child);\r
+ return true;\r
}\r
\r
//! Returns list with children of this element\r
- virtual const core::list<IGUIElement*>& getChildren() const\r
+ virtual const std::list<IGUIElement*>& getChildren() const\r
{\r
return Children;\r
}\r
{\r
IGUIElement* e = 0;\r
\r
- core::list<IGUIElement*>::ConstIterator it = Children.begin();\r
- for (; it != Children.end(); ++it)\r
+ for (auto child : Children)\r
{\r
- if ((*it)->getID() == id)\r
- return (*it);\r
+ if (child->getID() == id)\r
+ return child;\r
\r
if (searchchildren)\r
- e = (*it)->getElementFromId(id, true);\r
+ e = child->getElementFromId(id, true);\r
\r
if (e)\r
return e;\r
if (wanted==-2)\r
wanted = 1073741824; // maximum s32\r
\r
- core::list<IGUIElement*>::ConstIterator it = Children.begin();\r
+ auto it = Children.begin();\r
\r
s32 closestOrder, currentOrder;\r
\r
child->remove(); // remove from old parent\r
child->LastParentRect = getAbsolutePosition();\r
child->Parent = this;\r
- Children.push_back(child);\r
+ child->ParentPos = Children.insert(Children.end(), child);\r
}\r
}\r
\r
+#ifndef NDEBUG\r
+ template<typename Iterator>\r
+ static size_t _fastSetChecksum(Iterator begin, Iterator end) {\r
+ std::hash<typename Iterator::value_type> hasher;\r
+ size_t checksum = 0;\r
+ for (Iterator it = begin; it != end; ++it) {\r
+ size_t h = hasher(*it);\r
+ checksum ^= 966073049 + (h * 3432918353) + ((h >> 16) * 461845907);\r
+ }\r
+ return checksum;\r
+ }\r
+#endif\r
+\r
+ // Reorder children [from, to) to the order given by `neworder`\r
+ void reorderChildren(\r
+ std::list<IGUIElement*>::iterator from,\r
+ std::list<IGUIElement*>::iterator to,\r
+ const std::vector<IGUIElement*> &neworder)\r
+ {\r
+ assert(_fastSetChecksum(from, to) == _fastSetChecksum(neworder.begin(), neworder.end()));\r
+ for (auto e : neworder)\r
+ {\r
+ *from = e;\r
+ e->ParentPos = from;\r
+ ++from;\r
+ }\r
+ assert(from == to);\r
+ }\r
+\r
+\r
// not virtual because needed in constructor\r
void recalculateAbsolutePosition(bool recursive)\r
{\r
if ( recursive )\r
{\r
// update all children\r
- core::list<IGUIElement*>::Iterator it = Children.begin();\r
- for (; it != Children.end(); ++it)\r
+ for (auto child : Children)\r
{\r
- (*it)->recalculateAbsolutePosition(recursive);\r
+ child->recalculateAbsolutePosition(recursive);\r
}\r
}\r
}\r
protected:\r
\r
//! List of all children of this element\r
- core::list<IGUIElement*> Children;\r
+ std::list<IGUIElement*> Children;\r
\r
//! Pointer to the parent\r
IGUIElement* Parent;\r
\r
+ //! Our position in the parent list. Only valid when Parent != nullptr\r
+ std::list<IGUIElement*>::iterator ParentPos;\r
+\r
//! relative rect of element\r
core::rect<s32> RelativeRect;\r
\r
#include "irrString.h"\r
#include "aabbox3d.h"\r
#include "matrix4.h"\r
-#include "irrList.h"\r
#include "IAttributes.h"\r
+#include <list>\r
\r
namespace irr\r
{\r
class ISceneManager;\r
\r
//! Typedef for list of scene nodes\r
- typedef core::list<ISceneNode*> ISceneNodeList;\r
+ typedef std::list<ISceneNode*> ISceneNodeList;\r
\r
//! Scene node interface.\r
/** A scene node is a node in the hierarchical scene graph. Every scene\r
{\r
if (IsVisible)\r
{\r
- ISceneNodeList::Iterator it = Children.begin();\r
+ ISceneNodeList::iterator it = Children.begin();\r
for (; it != Children.end(); ++it)\r
(*it)->OnRegisterSceneNode();\r
}\r
\r
// perform the post render process on all children\r
\r
- ISceneNodeList::Iterator it = Children.begin();\r
+ ISceneNodeList::iterator it = Children.begin();\r
for (; it != Children.end(); ++it)\r
(*it)->OnAnimate(timeMs);\r
}\r
e.g. because it couldn't be found in the children list. */\r
virtual bool removeChild(ISceneNode* child)\r
{\r
- ISceneNodeList::Iterator it = Children.begin();\r
+ ISceneNodeList::iterator it = Children.begin();\r
for (; it != Children.end(); ++it)\r
if ((*it) == child)\r
{\r
*/\r
virtual void removeAll()\r
{\r
- ISceneNodeList::Iterator it = Children.begin();\r
+ ISceneNodeList::iterator it = Children.begin();\r
for (; it != Children.end(); ++it)\r
{\r
(*it)->Parent = 0;\r
\r
//! Returns a const reference to the list of all children.\r
/** \return The list of all children of this node. */\r
- const core::list<ISceneNode*>& getChildren() const\r
+ const std::list<ISceneNode*>& getChildren() const\r
{\r
return Children;\r
}\r
\r
// clone children\r
\r
- ISceneNodeList::Iterator it = toCopyFrom->Children.begin();\r
+ ISceneNodeList::iterator it = toCopyFrom->Children.begin();\r
for (; it != toCopyFrom->Children.end(); ++it)\r
(*it)->clone(this, newManager);\r
}\r
{\r
SceneManager = newManager;\r
\r
- ISceneNodeList::Iterator it = Children.begin();\r
+ ISceneNodeList::iterator it = Children.begin();\r
for (; it != Children.end(); ++it)\r
(*it)->setSceneManager(newManager);\r
}\r
ISceneNode* Parent;\r
\r
//! List of all children of this node\r
- core::list<ISceneNode*> Children;\r
+ std::list<ISceneNode*> Children;\r
\r
//! Pointer to the scene manager\r
ISceneManager* SceneManager;\r
+++ /dev/null
-// Copyright (C) 2002-2012 Nikolaus Gebhardt\r
-// This file is part of the "Irrlicht Engine".\r
-// For conditions of distribution and use, see copyright notice in irrlicht.h\r
-\r
-#ifndef __IRR_LIST_H_INCLUDED__\r
-#define __IRR_LIST_H_INCLUDED__\r
-\r
-#include "irrTypes.h"\r
-#include "irrAllocator.h"\r
-#include "irrMath.h"\r
-\r
-namespace irr\r
-{\r
-namespace core\r
-{\r
-\r
-\r
-//! Doubly linked list template.\r
-template <class T>\r
-class list\r
-{\r
-private:\r
-\r
- //! List element node with pointer to previous and next element in the list.\r
- struct SKListNode\r
- {\r
- SKListNode(const T& e) : Next(0), Prev(0), Element(e) {}\r
-\r
- SKListNode* Next;\r
- SKListNode* Prev;\r
- T Element;\r
- };\r
-\r
-public:\r
- class ConstIterator;\r
-\r
- //! List iterator.\r
- class Iterator\r
- {\r
- public:\r
- Iterator() : Current(0) {}\r
-\r
- Iterator& operator ++() { Current = Current->Next; return *this; }\r
- Iterator& operator --() { Current = Current->Prev; return *this; }\r
- Iterator operator ++(s32) { Iterator tmp = *this; Current = Current->Next; return tmp; }\r
- Iterator operator --(s32) { Iterator tmp = *this; Current = Current->Prev; return tmp; }\r
-\r
- Iterator& operator +=(s32 num)\r
- {\r
- if(num > 0)\r
- {\r
- while (num-- && this->Current != 0) ++(*this);\r
- }\r
- else\r
- {\r
- while(num++ && this->Current != 0) --(*this);\r
- }\r
- return *this;\r
- }\r
-\r
- Iterator operator + (s32 num) const { Iterator tmp = *this; return tmp += num; }\r
- Iterator& operator -=(s32 num) { return (*this)+=(-num); }\r
- Iterator operator - (s32 num) const { return (*this)+ (-num); }\r
-\r
- bool operator ==(const Iterator& other) const { return Current == other.Current; }\r
- bool operator !=(const Iterator& other) const { return Current != other.Current; }\r
- bool operator ==(const ConstIterator& other) const { return Current == other.Current; }\r
- bool operator !=(const ConstIterator& other) const { return Current != other.Current; }\r
-\r
- T & operator * () { return Current->Element; }\r
- T * operator ->() { return &Current->Element; }\r
-\r
- private:\r
- explicit Iterator(SKListNode* begin) : Current(begin) {}\r
-\r
- SKListNode* Current;\r
-\r
- friend class list<T>;\r
- friend class ConstIterator;\r
- };\r
-\r
- //! List iterator for const access.\r
- class ConstIterator\r
- {\r
- public:\r
-\r
- ConstIterator() : Current(0) {}\r
- ConstIterator(const Iterator& iter) : Current(iter.Current) {}\r
-\r
- ConstIterator& operator ++() { Current = Current->Next; return *this; }\r
- ConstIterator& operator --() { Current = Current->Prev; return *this; }\r
- ConstIterator operator ++(s32) { ConstIterator tmp = *this; Current = Current->Next; return tmp; }\r
- ConstIterator operator --(s32) { ConstIterator tmp = *this; Current = Current->Prev; return tmp; }\r
-\r
- ConstIterator& operator +=(s32 num)\r
- {\r
- if(num > 0)\r
- {\r
- while(num-- && this->Current != 0) ++(*this);\r
- }\r
- else\r
- {\r
- while(num++ && this->Current != 0) --(*this);\r
- }\r
- return *this;\r
- }\r
-\r
- ConstIterator operator + (s32 num) const { ConstIterator tmp = *this; return tmp += num; }\r
- ConstIterator& operator -=(s32 num) { return (*this)+=(-num); }\r
- ConstIterator operator - (s32 num) const { return (*this)+ (-num); }\r
-\r
- bool operator ==(const ConstIterator& other) const { return Current == other.Current; }\r
- bool operator !=(const ConstIterator& other) const { return Current != other.Current; }\r
- bool operator ==(const Iterator& other) const { return Current == other.Current; }\r
- bool operator !=(const Iterator& other) const { return Current != other.Current; }\r
-\r
- const T & operator * () { return Current->Element; }\r
- const T * operator ->() { return &Current->Element; }\r
-\r
- ConstIterator & operator =(const Iterator & iterator) { Current = iterator.Current; return *this; }\r
-\r
- private:\r
- explicit ConstIterator(SKListNode* begin) : Current(begin) {}\r
-\r
- SKListNode* Current;\r
-\r
- friend class Iterator;\r
- friend class list<T>;\r
- };\r
-\r
- //! Default constructor for empty list.\r
- list()\r
- : First(0), Last(0), Size(0) {}\r
-\r
-\r
- //! Copy constructor.\r
- list(const list<T>& other) : First(0), Last(0), Size(0)\r
- {\r
- *this = other;\r
- }\r
-\r
-\r
- //! Destructor\r
- ~list()\r
- {\r
- clear();\r
- }\r
-\r
-\r
- //! Assignment operator\r
- void operator=(const list<T>& other)\r
- {\r
- if(&other == this)\r
- {\r
- return;\r
- }\r
-\r
- clear();\r
-\r
- SKListNode* node = other.First;\r
- while(node)\r
- {\r
- push_back(node->Element);\r
- node = node->Next;\r
- }\r
- }\r
-\r
-\r
- //! Returns amount of elements in list.\r
- /** \return Amount of elements in the list. */\r
- u32 size() const\r
- {\r
- return Size;\r
- }\r
- u32 getSize() const\r
- {\r
- return Size;\r
- }\r
-\r
-\r
- //! Clears the list, deletes all elements in the list.\r
- /** All existing iterators of this list will be invalid. */\r
- void clear()\r
- {\r
- while(First)\r
- {\r
- SKListNode * next = First->Next;\r
- allocator.destruct(First);\r
- allocator.deallocate(First);\r
- First = next;\r
- }\r
-\r
- //First = 0; handled by loop\r
- Last = 0;\r
- Size = 0;\r
- }\r
-\r
-\r
- //! Checks for empty list.\r
- /** \return True if the list is empty and false if not. */\r
- bool empty() const\r
- {\r
- return (First == 0);\r
- }\r
-\r
-\r
- //! Adds an element at the end of the list.\r
- /** \param element Element to add to the list. */\r
- void push_back(const T& element)\r
- {\r
- SKListNode* node = allocator.allocate(1);\r
- allocator.construct(node, element);\r
-\r
- ++Size;\r
-\r
- if (First == 0)\r
- First = node;\r
-\r
- node->Prev = Last;\r
-\r
- if (Last != 0)\r
- Last->Next = node;\r
-\r
- Last = node;\r
- }\r
-\r
-\r
- //! Adds an element at the begin of the list.\r
- /** \param element: Element to add to the list. */\r
- void push_front(const T& element)\r
- {\r
- SKListNode* node = allocator.allocate(1);\r
- allocator.construct(node, element);\r
-\r
- ++Size;\r
-\r
- if (First == 0)\r
- {\r
- Last = node;\r
- First = node;\r
- }\r
- else\r
- {\r
- node->Next = First;\r
- First->Prev = node;\r
- First = node;\r
- }\r
- }\r
-\r
-\r
- //! Gets first node.\r
- /** \return A list iterator pointing to the beginning of the list. */\r
- Iterator begin()\r
- {\r
- return Iterator(First);\r
- }\r
-\r
-\r
- //! Gets first node.\r
- /** \return A const list iterator pointing to the beginning of the list. */\r
- ConstIterator begin() const\r
- {\r
- return ConstIterator(First);\r
- }\r
-\r
-\r
- //! Gets end node.\r
- /** \return List iterator pointing to null. */\r
- Iterator end()\r
- {\r
- return Iterator(0);\r
- }\r
-\r
-\r
- //! Gets end node.\r
- /** \return Const list iterator pointing to null. */\r
- ConstIterator end() const\r
- {\r
- return ConstIterator(0);\r
- }\r
-\r
-\r
- //! Gets last element.\r
- /** \return List iterator pointing to the last element of the list. */\r
- Iterator getLast()\r
- {\r
- return Iterator(Last);\r
- }\r
-\r
-\r
- //! Gets last element.\r
- /** \return Const list iterator pointing to the last element of the list. */\r
- ConstIterator getLast() const\r
- {\r
- return ConstIterator(Last);\r
- }\r
-\r
-\r
- //! Inserts an element after an element.\r
- /** \param it Iterator pointing to element after which the new element\r
- should be inserted.\r
- \param element The new element to be inserted into the list.\r
- */\r
- void insert_after(const Iterator& it, const T& element)\r
- {\r
- SKListNode* node = allocator.allocate(1);\r
- allocator.construct(node, element);\r
-\r
- node->Next = it.Current->Next;\r
-\r
- if (it.Current->Next)\r
- it.Current->Next->Prev = node;\r
-\r
- node->Prev = it.Current;\r
- it.Current->Next = node;\r
- ++Size;\r
-\r
- if (it.Current == Last)\r
- Last = node;\r
- }\r
-\r
-\r
- //! Inserts an element before an element.\r
- /** \param it Iterator pointing to element before which the new element\r
- should be inserted.\r
- \param element The new element to be inserted into the list.\r
- */\r
- void insert_before(const Iterator& it, const T& element)\r
- {\r
- SKListNode* node = allocator.allocate(1);\r
- allocator.construct(node, element);\r
-\r
- node->Prev = it.Current->Prev;\r
-\r
- if (it.Current->Prev)\r
- it.Current->Prev->Next = node;\r
-\r
- node->Next = it.Current;\r
- it.Current->Prev = node;\r
- ++Size;\r
-\r
- if (it.Current == First)\r
- First = node;\r
- }\r
-\r
-\r
- //! Erases an element.\r
- /** \param it Iterator pointing to the element which shall be erased.\r
- \return Iterator pointing to next element. */\r
- Iterator erase(Iterator& it)\r
- {\r
- // suggest changing this to a const Iterator& and\r
- // working around line: it.Current = 0 (possibly with a mutable, or just let it be garbage?)\r
-\r
- Iterator returnIterator(it);\r
- ++returnIterator;\r
-\r
- if(it.Current == First)\r
- {\r
- First = it.Current->Next;\r
- }\r
- else\r
- {\r
- it.Current->Prev->Next = it.Current->Next;\r
- }\r
-\r
- if(it.Current == Last)\r
- {\r
- Last = it.Current->Prev;\r
- }\r
- else\r
- {\r
- it.Current->Next->Prev = it.Current->Prev;\r
- }\r
-\r
- allocator.destruct(it.Current);\r
- allocator.deallocate(it.Current);\r
- it.Current = 0;\r
- --Size;\r
-\r
- return returnIterator;\r
- }\r
-\r
- //! Swap the content of this list container with the content of another list\r
- /** Afterward this object will contain the content of the other object and the other\r
- object will contain the content of this object. Iterators will afterward be valid for\r
- the swapped object.\r
- \param other Swap content with this object */\r
- void swap(list<T>& other)\r
- {\r
- core::swap(First, other.First);\r
- core::swap(Last, other.Last);\r
- core::swap(Size, other.Size);\r
- core::swap(allocator, other.allocator); // memory is still released by the same allocator used for allocation\r
- }\r
-\r
- typedef T value_type;\r
- typedef u32 size_type;\r
-\r
-private:\r
-\r
- SKListNode* First;\r
- SKListNode* Last;\r
- u32 Size;\r
- irrAllocator<SKListNode> allocator;\r
-\r
-};\r
-\r
-\r
-} // end namespace core\r
-}// end namespace irr\r
-\r
-#endif\r
-\r
#include "IRandomizer.h"\r
#include "IRenderTarget.h"\r
#include "IrrlichtDevice.h"\r
-#include "irrList.h"\r
#include "irrMath.h"\r
#include "irrString.h"\r
#include "irrTypes.h"\r
//updateAbsolutePosition();\r
\r
// perform the post render process on all children\r
- ISceneNodeList::Iterator it = Children.begin();\r
+ ISceneNodeList::iterator it = Children.begin();\r
for (; it != Children.end(); ++it)\r
(*it)->OnAnimate(timeMs);\r
}\r
{\r
Node->updateAbsolutePosition();\r
\r
- ISceneNodeList::ConstIterator it = Node->getChildren().begin();\r
+ ISceneNodeList::const_iterator it = Node->getChildren().begin();\r
for (; it != Node->getChildren().end(); ++it)\r
{\r
helper_updateAbsolutePositionOfAllChildren( (*it) );\r
#include "CMemoryFile.h"\r
#include "CLimitReadFile.h"\r
#include "CWriteFile.h"\r
-#include "irrList.h"\r
+#include <list>\r
\r
#if defined (__STRICT_ANSI__)\r
#error Compiling with __STRICT_ANSI__ not supported. g++ does set this when compiling with -std=c++11 or -std=c++0x. Use instead -std=gnu++11 or -std=gnu++0x. Or use -U__STRICT_ANSI__ to disable strict ansi.\r
io::path path1, file, ext;\r
core::splitFilename(getAbsolutePath(filename), &path1, &file, &ext);\r
io::path path2(getAbsolutePath(directory));\r
- core::list<io::path> list1, list2;\r
+ std::list<io::path> list1, list2;\r
path1.split(list1, _IRR_TEXT("/\\"), 2);\r
path2.split(list2, _IRR_TEXT("/\\"), 2);\r
- u32 i=0;\r
- core::list<io::path>::ConstIterator it1,it2;\r
+ std::list<io::path>::const_iterator it1,it2;\r
it1=list1.begin();\r
it2=list2.begin();\r
\r
#endif\r
\r
\r
- for (; i<list1.size() && i<list2.size()\r
+ for (; it1 != list1.end() && it2 != list2.end()\r
#if defined (_IRR_WINDOWS_API_)\r
&& (io::path(*it1).make_lower()==io::path(*it2).make_lower())\r
#else\r
&& (*it1==*it2)\r
#endif\r
- ; ++i)\r
+ ;)\r
{\r
++it1;\r
++it2;\r
}\r
path1=_IRR_TEXT("");\r
- for (; i<list2.size(); ++i)\r
+ for (; it2 != list2.end(); ++it2)\r
path1 += _IRR_TEXT("../");\r
while (it1 != list1.end())\r
{\r
HoveredNoSubelement = 0;\r
}\r
\r
- // get the root's children in case the root changes in future\r
- const core::list<IGUIElement*>& children = getRootGUIElement()->getChildren();\r
-\r
- while (!children.empty())\r
- (*children.getLast())->remove();\r
+ getRootGUIElement()->removeAllChildren();\r
}\r
\r
\r
}\r
\r
// any child visible?\r
- bool visible = false;\r
- core::list<IGUIElement*>::ConstIterator it = Children.begin();\r
- for (; it != Children.end(); ++it)\r
+ for (const auto& child : Children)\r
{\r
- if ( (*it)->isVisible() )\r
- {\r
- visible = true;\r
- break;\r
- }\r
+ if ( child->isVisible() )\r
+ return true;\r
}\r
- return visible;\r
+ return false;\r
}\r
\r
bool CGUIModalScreen::isPointInside(const core::position2d<s32>& point) const\r
if ( !canTakeFocus(event.GUIEvent.Caller))\r
{\r
if ( !Children.empty() )\r
- Environment->setFocus(*(Children.begin()));\r
+ Environment->setFocus(Children.front());\r
else\r
Environment->setFocus(this);\r
}\r
if ( isMyChild(event.GUIEvent.Caller) )\r
{\r
if ( !Children.empty() )\r
- Environment->setFocus(*(Children.begin()));\r
+ Environment->setFocus(Children.front());\r
else\r
Environment->setFocus(this);\r
}\r
u32 now = os::Timer::getTime();\r
if (BlinkMode && now - MouseDownTime < 300 && (now / 70)%2)\r
{\r
- core::list<IGUIElement*>::Iterator it = Children.begin();\r
core::rect<s32> r;\r
video::SColor c = Environment->getSkin()->getColor(gui::EGDC_3D_HIGH_LIGHT);\r
\r
- for (; it != Children.end(); ++it)\r
+ for (auto child : Children)\r
{\r
- if ((*it)->isVisible())\r
+ if (child->isVisible())\r
{\r
- r = (*it)->getAbsolutePosition();\r
+ r = child->getAbsolutePosition();\r
r.LowerRightCorner.X += 1;\r
r.LowerRightCorner.Y += 1;\r
r.UpperLeftCorner.X -= 1;\r
parentwidth = Parent->getAbsolutePosition().getWidth();\r
s32 parentheight = Parent->getAbsolutePosition().getHeight();\r
\r
- const core::list<IGUIElement*>& children = parent->getChildren();\r
- core::list<IGUIElement*>::ConstIterator it = children.begin();\r
- for (; it != children.end(); ++it)\r
+ for (const auto& e : parent->getChildren())\r
{\r
- const IGUIElement* e = *it;\r
if ( e->hasType(EGUIET_CONTEXT_MENU) \r
|| e->hasType(EGUIET_MENU) \r
|| e->hasType(EGUIET_TOOL_BAR) )\r
\r
void CGUITreeViewNode::clearChildren()\r
{\r
- core::list<CGUITreeViewNode*>::Iterator it;\r
-\r
- for( it = Children.begin(); it != Children.end(); it++ )\r
+ for (auto child : Children)\r
{\r
- ( *it )->drop();\r
+ child->Parent = nullptr;\r
+ child->drop();\r
}\r
Children.clear();\r
}\r
void* data /*= 0*/,\r
IReferenceCounted* data2 /*= 0*/ )\r
{\r
- CGUITreeViewNode* newChild = new CGUITreeViewNode( Owner, this );\r
-\r
- Children.push_back( newChild );\r
+ auto newChild = new CGUITreeViewNode( Owner, this );\r
+ newChild->ParentPos = Children.insert(Children.end(), newChild);\r
newChild->Text = text;\r
newChild->Icon = icon;\r
newChild->ImageIndex = imageIndex;\r
void* data /*= 0*/,\r
IReferenceCounted* data2 /*= 0*/ )\r
{\r
- CGUITreeViewNode* newChild = new CGUITreeViewNode( Owner, this );\r
-\r
- Children.push_front( newChild );\r
+ auto newChild = new CGUITreeViewNode( Owner, this );\r
+ newChild->ParentPos = Children.insert(Children.begin(), newChild);\r
newChild->Text = text;\r
newChild->Icon = icon;\r
newChild->ImageIndex = imageIndex;\r
}\r
\r
IGUITreeViewNode* CGUITreeViewNode::insertChildAfter(\r
- IGUITreeViewNode* other,\r
+ IGUITreeViewNode* iother,\r
const wchar_t* text,\r
const wchar_t* icon /*= 0*/,\r
s32 imageIndex /*= -1*/,\r
void* data /*= 0*/,\r
IReferenceCounted* data2/* = 0*/ )\r
{\r
- core::list<CGUITreeViewNode*>::Iterator itOther;\r
- CGUITreeViewNode* newChild = 0;\r
-\r
- for( itOther = Children.begin(); itOther != Children.end(); itOther++ )\r
- {\r
- if( other == *itOther )\r
- {\r
- newChild = new CGUITreeViewNode( Owner, this );\r
- newChild->Text = text;\r
- newChild->Icon = icon;\r
- newChild->ImageIndex = imageIndex;\r
- newChild->SelectedImageIndex = selectedImageIndex;\r
- newChild->Data = data;\r
- newChild->Data2 = data2;\r
- if( data2 )\r
- {\r
- data2->grab();\r
- }\r
- Children.insert_after( itOther, newChild );\r
- break;\r
- }\r
- }\r
+ // This cast is needed to access the ParentPos member of `other`.\r
+ // The abstraction was already broken, because Children is a list of\r
+ // CGUITreeViewNode, not IGUITreeViewNode. The existing code was\r
+ // implicitly casting through pointer comparison.\r
+ auto other = static_cast<CGUITreeViewNode*>(iother);\r
+ assert(other->Parent == this);\r
+ auto newChild = new CGUITreeViewNode( Owner, this );\r
+ newChild->ParentPos = Children.insert(std::next(other->ParentPos), newChild);\r
+ newChild->Text = text;\r
+ newChild->Icon = icon;\r
+ newChild->ImageIndex = imageIndex;\r
+ newChild->SelectedImageIndex = selectedImageIndex;\r
+ newChild->Data = data;\r
+ newChild->Data2 = data2;\r
+ if( data2 )\r
+ data2->grab();\r
return newChild;\r
}\r
\r
IGUITreeViewNode* CGUITreeViewNode::insertChildBefore(\r
- IGUITreeViewNode* other,\r
+ IGUITreeViewNode* iother,\r
const wchar_t* text,\r
const wchar_t* icon /*= 0*/,\r
s32 imageIndex /*= -1*/,\r
void* data /*= 0*/,\r
IReferenceCounted* data2/* = 0*/ )\r
{\r
- core::list<CGUITreeViewNode*>::Iterator itOther;\r
- CGUITreeViewNode* newChild = 0;\r
-\r
- for( itOther = Children.begin(); itOther != Children.end(); itOther++ )\r
- {\r
- if( other == *itOther )\r
- {\r
- newChild = new CGUITreeViewNode( Owner, this );\r
- newChild->Text = text;\r
- newChild->Icon = icon;\r
- newChild->ImageIndex = imageIndex;\r
- newChild->SelectedImageIndex = selectedImageIndex;\r
- newChild->Data = data;\r
- newChild->Data2 = data2;\r
- if( data2 )\r
- {\r
- data2->grab();\r
- }\r
- Children.insert_before( itOther, newChild );\r
- break;\r
- }\r
- }\r
+ auto other = static_cast<CGUITreeViewNode*>(iother);\r
+ assert(other->Parent == this);\r
+ auto newChild = new CGUITreeViewNode( Owner, this );\r
+ newChild->ParentPos = Children.insert(other->ParentPos, newChild);\r
+ newChild->Text = text;\r
+ newChild->Icon = icon;\r
+ newChild->ImageIndex = imageIndex;\r
+ newChild->SelectedImageIndex = selectedImageIndex;\r
+ newChild->Data = data;\r
+ newChild->Data2 = data2;\r
+ if( data2 )\r
+ data2->grab();\r
return newChild;\r
}\r
\r
}\r
else\r
{\r
- return *( Children.begin() );\r
+ return Children.front();\r
}\r
}\r
\r
}\r
else\r
{\r
- return *( Children.getLast() );\r
+ return Children.back();\r
}\r
}\r
\r
IGUITreeViewNode* CGUITreeViewNode::getPrevSibling() const\r
{\r
- core::list<CGUITreeViewNode*>::Iterator itThis;\r
- core::list<CGUITreeViewNode*>::Iterator itOther;\r
- CGUITreeViewNode* other = 0;\r
-\r
- if( Parent )\r
- {\r
- for( itThis = Parent->Children.begin(); itThis != Parent->Children.end(); itThis++ )\r
- {\r
- if( this == *itThis )\r
- {\r
- if( itThis != Parent->Children.begin() )\r
- {\r
- other = *itOther;\r
- }\r
- break;\r
- }\r
- itOther = itThis;\r
- }\r
- }\r
- return other;\r
+ if (!Parent || ParentPos == Parent->Children.begin())\r
+ return nullptr;\r
+ return *std::prev(ParentPos);\r
}\r
\r
IGUITreeViewNode* CGUITreeViewNode::getNextSibling() const\r
{\r
- core::list<CGUITreeViewNode*>::Iterator itThis;\r
- CGUITreeViewNode* other = 0;\r
-\r
- if( Parent )\r
- {\r
- for( itThis = Parent->Children.begin(); itThis != Parent->Children.end(); itThis++ )\r
- {\r
- if( this == *itThis )\r
- {\r
- if( itThis != Parent->Children.getLast() )\r
- {\r
- other = *( ++itThis );\r
- }\r
- break;\r
- }\r
- }\r
- }\r
- return other;\r
+ if (!Parent)\r
+ return nullptr;\r
+ auto nextIt = std::next(ParentPos);\r
+ if (nextIt == Parent->Children.end())\r
+ return nullptr;\r
+ return *nextIt;\r
}\r
\r
IGUITreeViewNode* CGUITreeViewNode::getNextVisible() const\r
return next;\r
}\r
\r
-bool CGUITreeViewNode::deleteChild( IGUITreeViewNode* child )\r
+bool CGUITreeViewNode::deleteChild( IGUITreeViewNode* ichild )\r
{\r
- core::list<CGUITreeViewNode*>::Iterator itChild;\r
- bool deleted = false;\r
-\r
- for( itChild = Children.begin(); itChild != Children.end(); itChild++ )\r
- {\r
- if( child == *itChild )\r
- {\r
- child->drop();\r
- Children.erase( itChild );\r
- deleted = true;\r
- break;\r
- }\r
- }\r
- return deleted;\r
+ auto child = static_cast<CGUITreeViewNode*>(ichild);\r
+ assert(child->Parent == this);\r
+ Children.erase(child->ParentPos);\r
+ child->Parent = nullptr;\r
+ child->drop();\r
+ return true;\r
}\r
\r
-bool CGUITreeViewNode::moveChildUp( IGUITreeViewNode* child )\r
+bool CGUITreeViewNode::moveChildUp( IGUITreeViewNode* ichild )\r
{\r
- core::list<CGUITreeViewNode*>::Iterator itChild;\r
- core::list<CGUITreeViewNode*>::Iterator itOther;\r
- CGUITreeViewNode* nodeTmp;\r
- bool moved = false;\r
-\r
- for( itChild = Children.begin(); itChild != Children.end(); itChild++ )\r
- {\r
- if( child == *itChild )\r
- {\r
- if( itChild != Children.begin() )\r
- {\r
- nodeTmp = *itChild;\r
- *itChild = *itOther;\r
- *itOther = nodeTmp;\r
- moved = true;\r
- }\r
- break;\r
- }\r
- itOther = itChild;\r
- }\r
- return moved;\r
+ auto child = static_cast<CGUITreeViewNode*>(ichild);\r
+ assert(child->Parent == this);\r
+ if (child->ParentPos == Children.begin())\r
+ return false;\r
+ auto curPos = child->ParentPos;\r
+ auto prevPos = std::prev(child->ParentPos);\r
+ std::swap(*curPos, *prevPos);\r
+ std::swap((*curPos)->ParentPos, (*prevPos)->ParentPos);\r
+ return true;\r
}\r
\r
-bool CGUITreeViewNode::moveChildDown( IGUITreeViewNode* child )\r
+bool CGUITreeViewNode::moveChildDown( IGUITreeViewNode* ichild )\r
{\r
- core::list<CGUITreeViewNode*>::Iterator itChild;\r
- core::list<CGUITreeViewNode*>::Iterator itOther;\r
- CGUITreeViewNode* nodeTmp;\r
- bool moved = false;\r
-\r
- for( itChild = Children.begin(); itChild != Children.end(); itChild++ )\r
- {\r
- if( child == *itChild )\r
- {\r
- if( itChild != Children.getLast() )\r
- {\r
- itOther = itChild;\r
- ++itOther;\r
- nodeTmp = *itChild;\r
- *itChild = *itOther;\r
- *itOther = nodeTmp;\r
- moved = true;\r
- }\r
- break;\r
- }\r
- }\r
- return moved;\r
+ auto child = static_cast<CGUITreeViewNode*>(ichild);\r
+ assert(child->Parent == this);\r
+ auto nextPos = std::next(child->ParentPos);\r
+ if (nextPos == Children.end())\r
+ return false;\r
+ auto curPos = child->ParentPos;\r
+ std::swap(*curPos, *nextPos);\r
+ std::swap((*curPos)->ParentPos, (*nextPos)->ParentPos);\r
+ return true;\r
}\r
\r
void CGUITreeViewNode::setExpanded( bool expanded )\r
#define __C_GUI_TREE_VIEW_H_INCLUDED__\r
\r
#include "IGUITreeView.h"\r
-#include "irrList.h"\r
\r
\r
namespace irr\r
\r
//! returns the child item count\r
virtual u32 getChildCount() const _IRR_OVERRIDE_\r
- { return Children.getSize(); }\r
+ { return Children.size(); }\r
\r
//! removes all children (recursive) from this node\r
virtual void clearChildren() _IRR_OVERRIDE_;\r
void* Data;\r
IReferenceCounted* Data2;\r
bool Expanded;\r
- core::list<CGUITreeViewNode*> Children;\r
+ std::list<CGUITreeViewNode*> Children;\r
+ // Position of this node in Parent->Children.\r
+ // Only valid when Parent != NULL\r
+ std::list<CGUITreeViewNode*>::iterator ParentPos;\r
};\r
\r
\r
#include "CIrrDeviceOSX.h"
#include "IEventReceiver.h"
-#include "irrList.h"
#include "os.h"
#include "CTimer.h"
#include "irrString.h"
\r
#include "CIrrDeviceSDL.h"\r
#include "IEventReceiver.h"\r
-#include "irrList.h"\r
#include "os.h"\r
#include "CTimer.h"\r
#include "irrString.h"\r
\r
#include "CIrrDeviceWin32.h"\r
#include "IEventReceiver.h"\r
-#include "irrList.h"\r
#include "os.h"\r
\r
#include "CTimer.h"\r
ISceneNode* node = 0;\r
\r
const ISceneNodeList& list = start->getChildren();\r
- ISceneNodeList::ConstIterator it = list.begin();\r
+ ISceneNodeList::const_iterator it = list.begin();\r
for (; it!=list.end(); ++it)\r
{\r
node = getSceneNodeFromName(name, *it);\r
ISceneNode* node = 0;\r
\r
const ISceneNodeList& list = start->getChildren();\r
- ISceneNodeList::ConstIterator it = list.begin();\r
+ ISceneNodeList::const_iterator it = list.begin();\r
for (; it!=list.end(); ++it)\r
{\r
node = getSceneNodeFromId(id, *it);\r
ISceneNode* node = 0;\r
\r
const ISceneNodeList& list = start->getChildren();\r
- ISceneNodeList::ConstIterator it = list.begin();\r
+ ISceneNodeList::const_iterator it = list.begin();\r
for (; it!=list.end(); ++it)\r
{\r
node = getSceneNodeFromType(type, *it);\r
outNodes.push_back(start);\r
\r
const ISceneNodeList& list = start->getChildren();\r
- ISceneNodeList::ConstIterator it = list.begin();\r
+ ISceneNodeList::const_iterator it = list.begin();\r
\r
for (; it!=list.end(); ++it)\r
{\r