drawinglayer: refactor GeoTexSvxTiled::iterateTiles
to provide a more generic callback interface and expose it as public to allow other usage. Change-Id: I6bc62a05fee750586f7281d8c24f2133884e77ba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92134 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include <basegfx/color/bcolor.hxx>
|
||||
#include <basegfx/utils/gradienttools.hxx>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace drawinglayer
|
||||
@@ -317,8 +318,6 @@ namespace drawinglayer
|
||||
double mfOffsetX;
|
||||
double mfOffsetY;
|
||||
|
||||
sal_Int32 iterateTiles(::std::vector< basegfx::B2DHomMatrix >* pMatrices) const;
|
||||
|
||||
public:
|
||||
GeoTexSvxTiled(
|
||||
const basegfx::B2DRange& rRange,
|
||||
@@ -329,6 +328,9 @@ namespace drawinglayer
|
||||
// compare operator
|
||||
virtual bool operator==(const GeoTexSvx& rGeoTexSvx) const override;
|
||||
|
||||
// Iterate over created tiles with callback provided.
|
||||
void iterateTiles(std::function<void(double fPosX, double fPosY)> aFunc) const;
|
||||
|
||||
void appendTransformations(::std::vector< basegfx::B2DHomMatrix >& rMatrices) const;
|
||||
sal_uInt32 getNumberOfTiles() const;
|
||||
};
|
||||
|
||||
@@ -677,18 +677,27 @@ namespace drawinglayer::texture
|
||||
|
||||
sal_uInt32 GeoTexSvxTiled::getNumberOfTiles() const
|
||||
{
|
||||
return iterateTiles(nullptr);
|
||||
sal_Int32 nTiles = 0;
|
||||
iterateTiles([&](double, double) { ++nTiles; });
|
||||
return nTiles;
|
||||
}
|
||||
|
||||
void GeoTexSvxTiled::appendTransformations(std::vector< basegfx::B2DHomMatrix >& rMatrices) const
|
||||
{
|
||||
iterateTiles(&rMatrices);
|
||||
const double fWidth(maRange.getWidth());
|
||||
const double fHeight(maRange.getHeight());
|
||||
iterateTiles([&](double fPosX, double fPosY) {
|
||||
rMatrices.push_back(basegfx::utils::createScaleTranslateB2DHomMatrix(
|
||||
fWidth,
|
||||
fHeight,
|
||||
fPosX,
|
||||
fPosY));
|
||||
});
|
||||
}
|
||||
|
||||
sal_Int32 GeoTexSvxTiled::iterateTiles(std::vector< basegfx::B2DHomMatrix >* pMatrices) const
|
||||
void GeoTexSvxTiled::iterateTiles(std::function<void(double fPosX, double fPosY)> aFunc) const
|
||||
{
|
||||
const double fWidth(maRange.getWidth());
|
||||
sal_Int32 nTiles = 0;
|
||||
|
||||
if(!basegfx::fTools::equalZero(fWidth))
|
||||
{
|
||||
@@ -739,21 +748,7 @@ namespace drawinglayer::texture
|
||||
{
|
||||
for(double fPosY((nPosX % 2) ? fStartY - fHeight + (mfOffsetY * fHeight) : fStartY);
|
||||
basegfx::fTools::less(fPosY, 1.0); fPosY += fHeight)
|
||||
{
|
||||
if(pMatrices)
|
||||
{
|
||||
pMatrices->push_back(
|
||||
basegfx::utils::createScaleTranslateB2DHomMatrix(
|
||||
fWidth,
|
||||
fHeight,
|
||||
fPosX,
|
||||
fPosY));
|
||||
}
|
||||
else
|
||||
{
|
||||
nTiles++;
|
||||
}
|
||||
}
|
||||
aFunc(fPosX, fPosY);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -762,27 +757,12 @@ namespace drawinglayer::texture
|
||||
{
|
||||
for(double fPosX((nPosY % 2) ? fStartX - fWidth + (mfOffsetX * fWidth) : fStartX);
|
||||
basegfx::fTools::less(fPosX, 1.0); fPosX += fWidth)
|
||||
{
|
||||
if(pMatrices)
|
||||
{
|
||||
pMatrices->push_back(
|
||||
basegfx::utils::createScaleTranslateB2DHomMatrix(
|
||||
fWidth,
|
||||
fHeight,
|
||||
fPosX,
|
||||
fPosY));
|
||||
}
|
||||
else
|
||||
{
|
||||
nTiles++;
|
||||
}
|
||||
}
|
||||
aFunc(fPosX, fPosY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nTiles;
|
||||
}
|
||||
|
||||
} // end of namespace
|
||||
|
||||
Reference in New Issue
Block a user