Rectangles list is STL now.

This commit is contained in:
2025-08-07 23:54:51 -04:00
parent eaee41750d
commit 905fdbf0dd
3 changed files with 23 additions and 29 deletions

View File

@ -99,8 +99,9 @@ void FltkViewBase::draw ()
if ((d & FL_DAMAGE_USER1) && !(d & FL_DAMAGE_EXPOSE)) { if ((d & FL_DAMAGE_USER1) && !(d & FL_DAMAGE_EXPOSE)) {
lout::container::typed::Iterator <core::Rectangle> it; lout::container::typed::Iterator <core::Rectangle> it;
for (it = drawRegion.rectangles (); it.hasNext (); ) { for( auto &rectangle: drawRegion )
draw (it.getNext (), DRAW_BUFFERED); {
draw( rectangle.get(), DRAW_BUFFERED );
} }
drawRegion.clear (); drawRegion.clear ();

View File

@ -220,16 +220,6 @@ bool Polygon::isPointWithin (int x, int y)
} }
} }
Region::Region()
{
rectangleList = new container::typed::List <Rectangle> (true);
}
Region::~Region()
{
delete rectangleList;
}
/** /**
* \brief Add a rectangle to the region and combine it with * \brief Add a rectangle to the region and combine it with
* existing rectangles if possible. * existing rectangles if possible.
@ -238,13 +228,11 @@ Region::~Region()
*/ */
void Region::addRectangle (Rectangle *rPointer) void Region::addRectangle (Rectangle *rPointer)
{ {
container::typed::Iterator <Rectangle> it; auto r= std::make_unique< Rectangle >( rPointer->x, rPointer->y,
Rectangle *r = new Rectangle (rPointer->x, rPointer->y,
rPointer->width, rPointer->height ); rPointer->width, rPointer->height );
for (it = rectangleList->iterator (); it.hasNext (); ) { for( auto &ownRect: rectangleList )
Rectangle *ownRect = it.getNext (); {
int combinedHeight = int combinedHeight =
misc::max(r->y + r->height, ownRect->y + ownRect->height) - misc::max(r->y + r->height, ownRect->y + ownRect->height) -
misc::min(r->y, ownRect->y); 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::max(r->x + r->width, ownRect->x + ownRect->width) -
misc::min(r->x, ownRect->x); misc::min(r->x, ownRect->x);
if (rectangleList->size() >= 16 || if (rectangleList.size() >= 16 ||
combinedWidth * combinedHeight <= combinedWidth * combinedHeight <=
ownRect->width * ownRect->height + r->width * r->height) { ownRect->width * ownRect->height + r->width * r->height) {
@ -261,11 +249,11 @@ void Region::addRectangle (Rectangle *rPointer)
r->width = combinedWidth; r->width = combinedWidth;
r->height = combinedHeight; r->height = combinedHeight;
rectangleList->removeRef (ownRect); rectangleList.remove( ownRect );
} }
} }
rectangleList->append (r); rectangleList.push_back( std::move( r ) );
} }
Content::Type Content::maskForSelection (bool followReferences) Content::Type Content::maskForSelection (bool followReferences)

View File

@ -5,6 +5,9 @@
# error Do not include this file directly, use "core.hh" instead. # error Do not include this file directly, use "core.hh" instead.
#endif #endif
#include <memory>
#include <list>
namespace dw { namespace dw {
namespace core { namespace core {
@ -140,20 +143,22 @@ public:
class Region class Region
{ {
private: private:
lout::container::typed::List <Rectangle> *rectangleList; std::list< std::unique_ptr< Rectangle > > rectangleList;
public: public:
Region (); void clear () { rectangleList.clear(); }
~Region ();
void clear () { rectangleList->clear (); };
void addRectangle (Rectangle *r); void addRectangle (Rectangle *r);
lout::container::typed::Iterator <Rectangle> rectangles () auto begin()
{ {
return rectangleList->iterator (); return rectangleList.begin();
}; }
auto end()
{
return rectangleList.end();
}
}; };
/** /**