diff --git a/dw/fltkviewbase.cc b/dw/fltkviewbase.cc index 29906bc..840e741 100644 --- a/dw/fltkviewbase.cc +++ b/dw/fltkviewbase.cc @@ -99,8 +99,9 @@ void FltkViewBase::draw () if ((d & FL_DAMAGE_USER1) && !(d & FL_DAMAGE_EXPOSE)) { lout::container::typed::Iterator it; - for (it = drawRegion.rectangles (); it.hasNext (); ) { - draw (it.getNext (), DRAW_BUFFERED); + for( auto &rectangle: drawRegion ) + { + draw( rectangle.get(), DRAW_BUFFERED ); } drawRegion.clear (); diff --git a/dw/types.cc b/dw/types.cc index ba49bbd..e49847c 100644 --- a/dw/types.cc +++ b/dw/types.cc @@ -220,16 +220,6 @@ bool Polygon::isPointWithin (int x, int y) } } -Region::Region() -{ - rectangleList = new container::typed::List (true); -} - -Region::~Region() -{ - delete rectangleList; -} - /** * \brief Add a rectangle to the region and combine it with * existing rectangles if possible. @@ -238,13 +228,11 @@ Region::~Region() */ void Region::addRectangle (Rectangle *rPointer) { - container::typed::Iterator it; - Rectangle *r = new Rectangle (rPointer->x, rPointer->y, - rPointer->width, rPointer->height); - - for (it = rectangleList->iterator (); it.hasNext (); ) { - Rectangle *ownRect = it.getNext (); + auto r= std::make_unique< Rectangle >( rPointer->x, rPointer->y, + rPointer->width, rPointer->height ); + for( auto &ownRect: rectangleList ) + { int combinedHeight = misc::max(r->y + r->height, ownRect->y + ownRect->height) - misc::min(r->y, ownRect->y); @@ -252,7 +240,7 @@ void Region::addRectangle (Rectangle *rPointer) misc::max(r->x + r->width, ownRect->x + ownRect->width) - misc::min(r->x, ownRect->x); - if (rectangleList->size() >= 16 || + if (rectangleList.size() >= 16 || combinedWidth * combinedHeight <= ownRect->width * ownRect->height + r->width * r->height) { @@ -261,11 +249,11 @@ void Region::addRectangle (Rectangle *rPointer) r->width = combinedWidth; r->height = combinedHeight; - rectangleList->removeRef (ownRect); + rectangleList.remove( ownRect ); } } - rectangleList->append (r); + rectangleList.push_back( std::move( r ) ); } Content::Type Content::maskForSelection (bool followReferences) diff --git a/dw/types.hh b/dw/types.hh index dfff97b..999d06c 100644 --- a/dw/types.hh +++ b/dw/types.hh @@ -5,6 +5,9 @@ # error Do not include this file directly, use "core.hh" instead. #endif +#include +#include + namespace dw { namespace core { @@ -140,20 +143,22 @@ public: class Region { private: - lout::container::typed::List *rectangleList; + std::list< std::unique_ptr< Rectangle > > rectangleList; public: - Region (); - ~Region (); - - void clear () { rectangleList->clear (); }; + void clear () { rectangleList.clear(); } void addRectangle (Rectangle *r); - lout::container::typed::Iterator rectangles () + auto begin() { - return rectangleList->iterator (); - }; + return rectangleList.begin(); + } + + auto end() + { + return rectangleList.end(); + } }; /**