diff options
-rw-r--r-- | chart2/source/controller/main/ChartWindow.cxx | 10 | ||||
-rw-r--r-- | include/tools/gen.hxx | 59 | ||||
-rw-r--r-- | sfx2/source/view/lokcharthelper.cxx | 8 |
3 files changed, 49 insertions, 28 deletions
diff --git a/chart2/source/controller/main/ChartWindow.cxx b/chart2/source/controller/main/ChartWindow.cxx index 7c114d5fff72..9f1ff9342c98 100644 --- a/chart2/source/controller/main/ChartWindow.cxx +++ b/chart2/source/controller/main/ChartWindow.cxx @@ -315,15 +315,11 @@ void ChartWindow::LogicInvalidate(const tools::Rectangle* pRectangle) if (!IsMapModeEnabled()) { - aRectangle.SetLeft( o3tl::convert(aRectangle.Left(), scaleX.GetDenominator(), scaleX.GetNumerator()) ); - aRectangle.SetRight( o3tl::convert(aRectangle.Right(), scaleX.GetDenominator(), scaleX.GetNumerator()) ); - aRectangle.SetTop( o3tl::convert(aRectangle.Top(), scaleY.GetDenominator(), scaleY.GetNumerator()) ); - aRectangle.SetBottom( o3tl::convert(aRectangle.Bottom(), scaleY.GetDenominator(), scaleY.GetNumerator()) ); + aRectangle = aRectangle.scale(scaleX.GetDenominator(), scaleX.GetNumerator(), + scaleY.GetDenominator(), scaleY.GetNumerator()); } - Point aOffset = this->GetOffsetPixelFrom(*pEditWin); - aOffset.setX( o3tl::convert(aOffset.X(), nXNum, nXDen) ); - aOffset.setY( o3tl::convert(aOffset.Y(), nYNum, nYDen) ); + Point aOffset = this->GetOffsetPixelFrom(*pEditWin).scale(nXNum, nXDen, nYNum, nYDen); aRectangle = tools::Rectangle(aRectangle.TopLeft() + aOffset, aRectangle.GetSize()); } diff --git a/include/tools/gen.hxx b/include/tools/gen.hxx index d016546724e2..01e3b45e456d 100644 --- a/include/tools/gen.hxx +++ b/include/tools/gen.hxx @@ -106,6 +106,10 @@ public: Pair const & toPair() const { return *this; } Pair & toPair() { return *this; } + // Scales relative to 0,0 + constexpr inline Point scale(sal_Int64 nMulX, sal_Int64 nDivX, + sal_Int64 nMulY, sal_Int64 nDivY) const; + using Pair::toString; }; @@ -173,14 +177,19 @@ inline bool operator !=(Point const & p1, Point const & p2) return !(p1 == p2); } +constexpr inline Point Point::scale(sal_Int64 nMulX, sal_Int64 nDivX, sal_Int64 nMulY, sal_Int64 nDivY) const +{ + return Point(o3tl::convert(getX(), nMulX, nDivX), + o3tl::convert(getY(), nMulY, nDivY)); +} + namespace o3tl { constexpr Point convert(const Point& rPoint, o3tl::Length eFrom, o3tl::Length eTo) { - return Point( - o3tl::convert(rPoint.getX(), eFrom, eTo), - o3tl::convert(rPoint.getY(), eFrom, eTo)); + const auto [num, den] = o3tl::getConversionMulDiv(eFrom, eTo); + return rPoint.scale(num, den, num, den); } } // end o3tl @@ -234,6 +243,9 @@ public: friend inline Size operator*( const Size &rVal1, const tools::Long nVal2 ); friend inline Size operator/( const Size &rVal1, const tools::Long nVal2 ); + constexpr inline Size scale(sal_Int64 nMulX, sal_Int64 nDivX, + sal_Int64 nMulY, sal_Int64 nDivY) const; + }; inline bool operator ==(Size const & s1, Size const & s2) @@ -294,14 +306,20 @@ inline Size operator/( const Size &rVal1, const tools::Long nVal2 ) return Size( rVal1.nA/nVal2, rVal1.nB/nVal2 ); } +constexpr inline Size Size::scale(sal_Int64 nMulX, sal_Int64 nDivX, + sal_Int64 nMulY, sal_Int64 nDivY) const +{ + return Size(o3tl::convert(Width(), nMulX, nDivX), + o3tl::convert(Height(), nMulY, nDivY)); +} + namespace o3tl { constexpr Size convert(const Size& rSize, o3tl::Length eFrom, o3tl::Length eTo) { - return Size( - o3tl::convert(rSize.Width(), eFrom, eTo), - o3tl::convert(rSize.Height(), eFrom, eTo)); + const auto [num, den] = o3tl::getConversionMulDiv(eFrom, eTo); + return rSize.scale(num, den, num, den); } } // end o3tl @@ -595,6 +613,10 @@ public: void SaturatingSetPosX(tools::Long x); void SaturatingSetPosY(tools::Long y); + // Scales relative to 0,0 + constexpr inline tools::Rectangle scale(sal_Int64 nMulX, sal_Int64 nDivX, + sal_Int64 nMulY, sal_Int64 nDivY) const; + private: tools::Long nLeft = 0; tools::Long nTop = 0; @@ -718,20 +740,27 @@ inline Rectangle operator - ( const Rectangle& rRect, const Point& rPt ) } +constexpr inline tools::Rectangle tools::Rectangle::scale(sal_Int64 nMulX, sal_Int64 nDivX, + sal_Int64 nMulY, sal_Int64 nDivY) const +{ + // 1. Create an empty rectangle with correct left and top + tools::Rectangle aRect(o3tl::convert(Left(), nMulX, nDivX), + o3tl::convert(Top(), nMulY, nDivY)); + // 2. If source has width/height, set respective right and bottom + if (!IsWidthEmpty()) + aRect.SetRight(o3tl::convert(Right(), nMulX, nDivX)); + if (!IsHeightEmpty()) + aRect.SetBottom(o3tl::convert(Bottom(), nMulY, nDivY)); + return aRect; +} + namespace o3tl { constexpr tools::Rectangle convert(const tools::Rectangle& rRectangle, o3tl::Length eFrom, o3tl::Length eTo) { - // 1. Create an empty rectangle with correct left and top - tools::Rectangle aRect(o3tl::convert(rRectangle.Left(), eFrom, eTo), - o3tl::convert(rRectangle.Top(), eFrom, eTo)); - // 2. If source has width/height, set respective right and bottom - if (!rRectangle.IsWidthEmpty()) - aRect.SetRight(o3tl::convert(rRectangle.Right(), eFrom, eTo)); - if (!rRectangle.IsHeightEmpty()) - aRect.SetBottom(o3tl::convert(rRectangle.Bottom(), eFrom, eTo)); - return aRect; + const auto [num, den] = o3tl::getConversionMulDiv(eFrom, eTo); + return rRectangle.scale(num, den, num, den); } } // end o3tl diff --git a/sfx2/source/view/lokcharthelper.cxx b/sfx2/source/view/lokcharthelper.cxx index 7220621a566c..1016f90135c1 100644 --- a/sfx2/source/view/lokcharthelper.cxx +++ b/sfx2/source/view/lokcharthelper.cxx @@ -141,12 +141,8 @@ tools::Rectangle LokChartHelper::GetChartBoundingBox() const auto nYNum = p.first * scaleY.GetDenominator(); const auto nYDen = p.second * scaleY.GetNumerator(); - Point aOffset = pWindow->GetOffsetPixelFrom(*pRootWin); - aOffset.setX( o3tl::convert(aOffset.X(), nXNum, nXDen) ); - aOffset.setY( o3tl::convert(aOffset.Y(), nYNum, nYDen) ); - Size aSize = pWindow->GetSizePixel(); - aSize.setWidth( o3tl::convert(aSize.Width(), nXNum, nXDen) ); - aSize.setHeight( o3tl::convert(aSize.Height(), nYNum, nYDen) ); + Point aOffset = pWindow->GetOffsetPixelFrom(*pRootWin).scale(nXNum, nXDen, nYNum, nYDen); + Size aSize = pWindow->GetSizePixel().scale(nXNum, nXDen, nYNum, nYDen); aBBox = tools::Rectangle(aOffset, aSize); } } |