1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "OverlayRanges.hxx"
22 #include <svx/sdrpaintwindow.hxx>
23 #include <svx/svdview.hxx>
24 #include <svx/sdr/overlay/overlaymanager.hxx>
25 #include <basegfx/polygon/b2dpolygon.hxx>
26 #include <basegfx/polygon/b2dpolypolygon.hxx>
27 #include <basegfx/polygon/b2dpolygontools.hxx>
28 #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
29 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
30 #include <drawinglayer/primitive2d/PolyPolygonHairlinePrimitive2D.hxx>
31 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
32 #include <svtools/optionsdrawinglayer.hxx>
36 // combine ranges geometrically to a single, ORed polygon
37 basegfx::B2DPolyPolygon
impCombineRangesToPolyPolygon(const std::vector
< basegfx::B2DRange
>& rRanges
)
39 const sal_uInt32
nCount(rRanges
.size());
40 basegfx::B2DPolyPolygon aRetval
;
42 for(sal_uInt32
a(0); a
< nCount
; a
++)
44 const basegfx::B2DPolygon
aDiscretePolygon(basegfx::utils::createPolygonFromRect(rRanges
[a
]));
48 aRetval
.append(aDiscretePolygon
);
52 aRetval
= basegfx::utils::solvePolygonOperationOr(aRetval
, basegfx::B2DPolyPolygon(aDiscretePolygon
));
62 drawinglayer::primitive2d::Primitive2DContainer
OverlayRanges::createOverlayObjectPrimitive2DSequence()
64 const sal_uInt32
nCount(getRanges().size());
65 drawinglayer::primitive2d::Primitive2DContainer aRetval
;
66 aRetval
.resize(nCount
);
67 for ( sal_uInt32 a
= 0; a
< nCount
; ++a
)
69 const basegfx::BColor
aRGBColor(getBaseColor().getBColor());
70 const basegfx::B2DPolygon
aPolygon(basegfx::utils::createPolygonFromRect(maRanges
[a
]));
71 aRetval
[a
] = drawinglayer::primitive2d::Primitive2DReference(
72 new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
73 basegfx::B2DPolyPolygon(aPolygon
),
76 // embed all rectangles in transparent paint
77 const sal_uInt16
nTransparence( SvtOptionsDrawinglayer::GetTransparentSelectionPercent() );
78 const double fTransparence( nTransparence
/ 100.0 );
79 const drawinglayer::primitive2d::Primitive2DReference
aUnifiedTransparence(
80 new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
84 if ( mbShowSolidBorder
)
86 const basegfx::BColor
aRGBColor(getBaseColor().getBColor());
87 basegfx::B2DPolyPolygon
aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
88 const drawinglayer::primitive2d::Primitive2DReference
aOutline(
89 new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
90 std::move(aPolyPolygon
),
93 aRetval
= drawinglayer::primitive2d::Primitive2DContainer
{ aUnifiedTransparence
, aOutline
};
97 aRetval
= drawinglayer::primitive2d::Primitive2DContainer
{ aUnifiedTransparence
};
103 /*static*/ std::unique_ptr
<OverlayRanges
> OverlayRanges::CreateOverlayRange(
104 SwView
const & rDocView
,
106 std::vector
< basegfx::B2DRange
>&& rRanges
,
107 const bool bShowSolidBorder
)
109 std::unique_ptr
<OverlayRanges
> pOverlayRanges
;
111 SdrView
* pView
= rDocView
.GetDrawView();
112 if ( pView
!= nullptr )
114 SdrPaintWindow
* pCandidate
= pView
->GetPaintWindow(0);
115 const rtl::Reference
<sdr::overlay::OverlayManager
>& xTargetOverlay
= pCandidate
->GetOverlayManager();
117 if ( xTargetOverlay
.is() )
119 pOverlayRanges
.reset(new sw::overlay::OverlayRanges( rColor
, std::move(rRanges
), bShowSolidBorder
));
120 xTargetOverlay
->add( *pOverlayRanges
);
124 return pOverlayRanges
;
127 OverlayRanges::OverlayRanges(
129 std::vector
< basegfx::B2DRange
>&& rRanges
,
130 const bool bShowSolidBorder
)
131 : sdr::overlay::OverlayObject( rColor
)
132 , maRanges( std::move(rRanges
) )
133 , mbShowSolidBorder( bShowSolidBorder
)
135 // no AA for highlight overlays
136 allowAntiAliase(false);
139 OverlayRanges::~OverlayRanges()
141 if( getOverlayManager() )
143 getOverlayManager()->remove(*this);
147 void OverlayRanges::setRanges(std::vector
< basegfx::B2DRange
>&& rNew
)
151 maRanges
= std::move(rNew
);
156 void OverlayRanges::ShowSolidBorder()
158 if ( !mbShowSolidBorder
)
160 mbShowSolidBorder
= true;
165 void OverlayRanges::HideSolidBorder()
167 if ( mbShowSolidBorder
)
169 mbShowSolidBorder
= false;
174 } // end of namespace sw::overlay
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */