Kaydet (Commit) 71eea07e authored tarafından Noel Grandin's avatar Noel Grandin

handle empty tools::Rectangle in svtoools

Change-Id: Ia6c4d56e8019fd92ac69499b9902f8bd8ca27fec
Reviewed-on: https://gerrit.libreoffice.org/72187
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst a361231b
...@@ -45,8 +45,10 @@ SvResizeHelper::SvResizeHelper() ...@@ -45,8 +45,10 @@ SvResizeHelper::SvResizeHelper()
|* |*
|* Description: the eight handles to magnify |* Description: the eight handles to magnify
*************************************************************************/ *************************************************************************/
void SvResizeHelper::FillHandleRectsPixel( tools::Rectangle aRects[ 8 ] ) const std::array<tools::Rectangle,8> SvResizeHelper::FillHandleRectsPixel() const
{ {
std::array<tools::Rectangle,8> aRects;
// only because of EMPTY_RECT // only because of EMPTY_RECT
Point aBottomRight = aOuter.BottomRight(); Point aBottomRight = aOuter.BottomRight();
...@@ -80,6 +82,7 @@ void SvResizeHelper::FillHandleRectsPixel( tools::Rectangle aRects[ 8 ] ) const ...@@ -80,6 +82,7 @@ void SvResizeHelper::FillHandleRectsPixel( tools::Rectangle aRects[ 8 ] ) const
aRects[ 7 ] = tools::Rectangle( Point( aOuter.Left(), aRects[ 7 ] = tools::Rectangle( Point( aOuter.Left(),
aOuter.Center().Y() - aBorder.Height() / 2 ), aOuter.Center().Y() - aBorder.Height() / 2 ),
aBorder ); aBorder );
return aRects;
} }
/************************************************************************* /*************************************************************************
...@@ -87,20 +90,26 @@ void SvResizeHelper::FillHandleRectsPixel( tools::Rectangle aRects[ 8 ] ) const ...@@ -87,20 +90,26 @@ void SvResizeHelper::FillHandleRectsPixel( tools::Rectangle aRects[ 8 ] ) const
|* |*
|* Description: the four edges are calculated |* Description: the four edges are calculated
*************************************************************************/ *************************************************************************/
void SvResizeHelper::FillMoveRectsPixel( tools::Rectangle aRects[ 4 ] ) const std::array<tools::Rectangle,4> SvResizeHelper::FillMoveRectsPixel() const
{ {
std::array<tools::Rectangle,4> aRects;
// upper // upper
aRects[ 0 ] = aOuter; aRects[ 0 ] = aOuter;
aRects[ 0 ].SetBottom( aRects[ 0 ].Top() + aBorder.Height() -1 ); aRects[ 0 ].SetBottom( aRects[ 0 ].Top() + aBorder.Height() -1 );
// right // right
aRects[ 1 ] = aOuter; aRects[ 1 ] = aOuter;
aRects[ 1 ].SetLeft( aRects[ 1 ].Right() - aBorder.Width() -1 ); if (!aOuter.IsWidthEmpty())
aRects[ 1 ].SetLeft( aRects[ 1 ].Right() - aBorder.Width() -1 );
// lower // lower
aRects[ 2 ] = aOuter; aRects[ 2 ] = aOuter;
aRects[ 2 ].SetTop( aRects[ 2 ].Bottom() - aBorder.Height() -1 ); if (!aOuter.IsHeightEmpty())
aRects[ 2 ].SetTop( aRects[ 2 ].Bottom() - aBorder.Height() -1 );
// left // left
aRects[ 3 ] = aOuter; aRects[ 3 ] = aOuter;
aRects[ 3 ].SetRight( aRects[ 3 ].Left() + aBorder.Width() -1 ); aRects[ 3 ].SetRight( aRects[ 3 ].Left() + aBorder.Width() -1 );
return aRects;
} }
/************************************************************************* /*************************************************************************
...@@ -116,15 +125,13 @@ void SvResizeHelper::Draw(vcl::RenderContext& rRenderContext) ...@@ -116,15 +125,13 @@ void SvResizeHelper::Draw(vcl::RenderContext& rRenderContext)
rRenderContext.SetFillColor( COL_LIGHTGRAY ); rRenderContext.SetFillColor( COL_LIGHTGRAY );
rRenderContext.SetLineColor(); rRenderContext.SetLineColor();
tools::Rectangle aMoveRects[ 4 ]; std::array<tools::Rectangle,4> aMoveRects = FillMoveRectsPixel();
FillMoveRectsPixel( aMoveRects );
sal_uInt16 i; sal_uInt16 i;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
rRenderContext.DrawRect(aMoveRects[i]); rRenderContext.DrawRect(aMoveRects[i]);
// draw handles // draw handles
rRenderContext.SetFillColor(Color()); // black rRenderContext.SetFillColor(Color()); // black
tools::Rectangle aRects[ 8 ]; std::array<tools::Rectangle,8> aRects = FillHandleRectsPixel();
FillHandleRectsPixel(aRects);
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
rRenderContext.DrawRect( aRects[ i ] ); rRenderContext.DrawRect( aRects[ i ] );
rRenderContext.Pop(); rRenderContext.Pop();
...@@ -137,8 +144,7 @@ void SvResizeHelper::Draw(vcl::RenderContext& rRenderContext) ...@@ -137,8 +144,7 @@ void SvResizeHelper::Draw(vcl::RenderContext& rRenderContext)
*************************************************************************/ *************************************************************************/
void SvResizeHelper::InvalidateBorder( vcl::Window * pWin ) void SvResizeHelper::InvalidateBorder( vcl::Window * pWin )
{ {
tools::Rectangle aMoveRects[ 4 ]; std::array<tools::Rectangle,4> aMoveRects = FillMoveRectsPixel();
FillMoveRectsPixel( aMoveRects );
for(const auto & rMoveRect : aMoveRects) for(const auto & rMoveRect : aMoveRects)
pWin->Invalidate( rMoveRect ); pWin->Invalidate( rMoveRect );
} }
...@@ -172,14 +178,12 @@ short SvResizeHelper::SelectMove( vcl::Window * pWin, const Point & rPos ) ...@@ -172,14 +178,12 @@ short SvResizeHelper::SelectMove( vcl::Window * pWin, const Point & rPos )
{ {
if( -1 == nGrab ) if( -1 == nGrab )
{ {
tools::Rectangle aRects[ 8 ]; std::array<tools::Rectangle,8> aRects = FillHandleRectsPixel();
FillHandleRectsPixel( aRects );
for( sal_uInt16 i = 0; i < 8; i++ ) for( sal_uInt16 i = 0; i < 8; i++ )
if( aRects[ i ].IsInside( rPos ) ) if( aRects[ i ].IsInside( rPos ) )
return i; return i;
// Move-Rect overlaps Handles // Move-Rect overlaps Handles
tools::Rectangle aMoveRects[ 4 ]; std::array<tools::Rectangle,4> aMoveRects = FillMoveRectsPixel();
FillMoveRectsPixel( aMoveRects );
for(const auto & rMoveRect : aMoveRects) for(const auto & rMoveRect : aMoveRects)
if( rMoveRect.IsInside( rPos ) ) if( rMoveRect.IsInside( rPos ) )
return 8; return 8;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <tools/gen.hxx> #include <tools/gen.hxx>
#include <vcl/window.hxx> #include <vcl/window.hxx>
#include <array>
/********************** SvResizeHelper *********************************** /********************** SvResizeHelper ***********************************
*************************************************************************/ *************************************************************************/
...@@ -48,8 +49,8 @@ public: ...@@ -48,8 +49,8 @@ public:
} }
// Clockwise, start at upper left // Clockwise, start at upper left
void FillHandleRectsPixel( tools::Rectangle aRects[ 8 ] ) const; std::array<tools::Rectangle,8> FillHandleRectsPixel() const;
void FillMoveRectsPixel( tools::Rectangle aRects[ 4 ] ) const; std::array<tools::Rectangle,4> FillMoveRectsPixel() const;
void Draw(vcl::RenderContext& rRenderContext); void Draw(vcl::RenderContext& rRenderContext);
void InvalidateBorder( vcl::Window * ); void InvalidateBorder( vcl::Window * );
bool SelectBegin( vcl::Window *, const Point & rPos ); bool SelectBegin( vcl::Window *, const Point & rPos );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment