LibreOffice Module sw (master) 1
OverlayRanges.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "OverlayRanges.hxx"
21#include <view.hxx>
23#include <svx/svdview.hxx>
33
34namespace
35{
36 // combine ranges geometrically to a single, ORed polygon
37 basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
38 {
39 const sal_uInt32 nCount(rRanges.size());
41
42 for(sal_uInt32 a(0); a < nCount; a++)
43 {
44 const basegfx::B2DPolygon aDiscretePolygon(basegfx::utils::createPolygonFromRect(rRanges[a]));
45
46 if(0 == a)
47 {
48 aRetval.append(aDiscretePolygon);
49 }
50 else
51 {
52 aRetval = basegfx::utils::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
53 }
54 }
55
56 return aRetval;
57 }
58}
59
60namespace sw::overlay
61{
63 {
64 const sal_uInt32 nCount(getRanges().size());
66 aRetval.resize(nCount);
67 for ( sal_uInt32 a = 0; a < nCount; ++a )
68 {
69 const basegfx::BColor aRGBColor(getBaseColor().getBColor());
74 aRGBColor));
75 }
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(
81 std::move(aRetval),
82 fTransparence));
83
85 {
86 const basegfx::BColor aRGBColor(getBaseColor().getBColor());
87 basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
90 std::move(aPolyPolygon),
91 aRGBColor));
92
93 aRetval = drawinglayer::primitive2d::Primitive2DContainer { aUnifiedTransparence, aOutline };
94 }
95 else
96 {
97 aRetval = drawinglayer::primitive2d::Primitive2DContainer { aUnifiedTransparence };
98 }
99
100 return aRetval;
101 }
102
103 /*static*/ std::unique_ptr<OverlayRanges> OverlayRanges::CreateOverlayRange(
104 SwView const & rDocView,
105 const Color& rColor,
106 std::vector< basegfx::B2DRange >&& rRanges,
107 const bool bShowSolidBorder )
108 {
109 std::unique_ptr<OverlayRanges> pOverlayRanges;
110
111 SdrView* pView = rDocView.GetDrawView();
112 if ( pView != nullptr )
113 {
114 SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
115 const rtl::Reference<sdr::overlay::OverlayManager>& xTargetOverlay = pCandidate->GetOverlayManager();
116
117 if ( xTargetOverlay.is() )
118 {
119 pOverlayRanges.reset(new sw::overlay::OverlayRanges( rColor, std::move(rRanges), bShowSolidBorder ));
120 xTargetOverlay->add( *pOverlayRanges );
121 }
122 }
123
124 return pOverlayRanges;
125 }
126
128 const Color& rColor,
129 std::vector< basegfx::B2DRange >&& rRanges,
130 const bool bShowSolidBorder )
131 : sdr::overlay::OverlayObject( rColor )
132 , maRanges( std::move(rRanges) )
133 , mbShowSolidBorder( bShowSolidBorder )
134 {
135 // no AA for highlight overlays
136 allowAntiAliase(false);
137 }
138
140 {
141 if( getOverlayManager() )
142 {
143 getOverlayManager()->remove(*this);
144 }
145 }
146
147 void OverlayRanges::setRanges(std::vector< basegfx::B2DRange >&& rNew)
148 {
149 if(rNew != maRanges)
150 {
151 maRanges = std::move(rNew);
152 objectChange();
153 }
154 }
155
157 {
158 if ( !mbShowSolidBorder )
159 {
160 mbShowSolidBorder = true;
161 objectChange();
162 }
163 }
164
166 {
167 if ( mbShowSolidBorder )
168 {
169 mbShowSolidBorder = false;
170 objectChange();
171 }
172 }
173
174} // end of namespace sw::overlay
175
176/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SdrPaintWindow * GetPaintWindow(sal_uInt32 nIndex) const
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
Definition: view.hxx:146
virtual SdrView * GetDrawView() const override
Definition: viewdraw.cxx:621
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
void remove(OverlayObject &rOverlayObject)
const Color & getBaseColor() const
void allowAntiAliase(bool bNew)
OverlayManager * getOverlayManager() const
static std::unique_ptr< OverlayRanges > CreateOverlayRange(SwView const &rDocView, const Color &rColor, std::vector< basegfx::B2DRange > &&rRanges, const bool bShowSolidBorder)
virtual ~OverlayRanges() override
std::vector< basegfx::B2DRange > maRanges
void setRanges(std::vector< basegfx::B2DRange > &&rNew)
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
const std::vector< basegfx::B2DRange > & getRanges() const
OverlayRanges(const Color &rColor, std::vector< basegfx::B2DRange > &&rRanges, const bool bShowSolidBorder)
int nCount
uno_Any a
sal_uInt16 GetTransparentSelectionPercent()
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
B2DPolyPolygon solvePolygonOperationOr(const B2DPolyPolygon &rCandidateA, const B2DPolyPolygon &rCandidateB)
size
rtl::Reference< BasePrimitive2D > Primitive2DReference