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>
22 #include <svx/sdrpaintwindow.hxx>
23 #include <svx/svdview.hxx>
32 
33 namespace
34 {
35  // combine ranges geometrically to a single, ORed polygon
36  basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
37  {
38  const sal_uInt32 nCount(rRanges.size());
40 
41  for(sal_uInt32 a(0); a < nCount; a++)
42  {
43  const basegfx::B2DPolygon aDiscretePolygon(basegfx::utils::createPolygonFromRect(rRanges[a]));
44 
45  if(0 == a)
46  {
47  aRetval.append(aDiscretePolygon);
48  }
49  else
50  {
51  aRetval = basegfx::utils::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
52  }
53  }
54 
55  return aRetval;
56  }
57 }
58 
59 namespace sw::overlay
60 {
62  {
63  const sal_uInt32 nCount(getRanges().size());
65  aRetval.resize(nCount);
66  for ( sal_uInt32 a = 0; a < nCount; ++a )
67  {
68  const basegfx::BColor aRGBColor(getBaseColor().getBColor());
72  basegfx::B2DPolyPolygon(aPolygon),
73  aRGBColor));
74  }
75  // embed all rectangles in transparent paint
76  const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
77  const sal_uInt16 nTransparence( aSvtOptionsDrawinglayer.GetTransparentSelectionPercent() );
78  const double fTransparence( nTransparence / 100.0 );
79  const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence(
81  aRetval,
82  fTransparence));
83 
84  if ( mbShowSolidBorder )
85  {
86  const basegfx::BColor aRGBColor(getBaseColor().getBColor());
87  const basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
90  aPolyPolygon,
91  aRGBColor));
92 
93  aRetval.resize(2);
94  aRetval[0] = aUnifiedTransparence;
95  aRetval[1] = aOutline;
96  }
97  else
98  {
99  aRetval = drawinglayer::primitive2d::Primitive2DContainer { aUnifiedTransparence };
100  }
101 
102  return aRetval;
103  }
104 
105  /*static*/ std::unique_ptr<OverlayRanges> OverlayRanges::CreateOverlayRange(
106  SwView const & rDocView,
107  const Color& rColor,
108  const std::vector< basegfx::B2DRange >& rRanges,
109  const bool bShowSolidBorder )
110  {
111  std::unique_ptr<OverlayRanges> pOverlayRanges;
112 
113  SdrView* pView = rDocView.GetDrawView();
114  if ( pView != nullptr )
115  {
116  SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
117  const rtl::Reference<sdr::overlay::OverlayManager>& xTargetOverlay = pCandidate->GetOverlayManager();
118 
119  if ( xTargetOverlay.is() )
120  {
121  pOverlayRanges.reset(new sw::overlay::OverlayRanges( rColor, rRanges, bShowSolidBorder ));
122  xTargetOverlay->add( *pOverlayRanges );
123  }
124  }
125 
126  return pOverlayRanges;
127  }
128 
130  const Color& rColor,
131  const std::vector< basegfx::B2DRange >& rRanges,
132  const bool bShowSolidBorder )
133  : sdr::overlay::OverlayObject( rColor )
134  , maRanges( rRanges )
135  , mbShowSolidBorder( bShowSolidBorder )
136  {
137  // no AA for highlight overlays
138  allowAntiAliase(false);
139  }
140 
142  {
143  if( getOverlayManager() )
144  {
145  getOverlayManager()->remove(*this);
146  }
147  }
148 
149  void OverlayRanges::setRanges(const std::vector< basegfx::B2DRange >& rNew)
150  {
151  if(rNew != maRanges)
152  {
153  maRanges = rNew;
154  objectChange();
155  }
156  }
157 
159  {
160  if ( !mbShowSolidBorder )
161  {
162  mbShowSolidBorder = true;
163  objectChange();
164  }
165  }
166 
168  {
169  if ( mbShowSolidBorder )
170  {
171  mbShowSolidBorder = false;
172  objectChange();
173  }
174  }
175 
176 } // end of namespace sw::overlay
177 
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetTransparentSelectionPercent() const
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
B2DPolyPolygon solvePolygonOperationOr(const B2DPolyPolygon &rCandidateA, const B2DPolyPolygon &rCandidateB)
virtual ~OverlayRanges() override
OverlayManager * getOverlayManager() const
const std::vector< basegfx::B2DRange > & getRanges() const
void remove(OverlayObject &rOverlayObject)
int nCount
uno_Any a
static std::unique_ptr< OverlayRanges > CreateOverlayRange(SwView const &rDocView, const Color &rColor, const std::vector< basegfx::B2DRange > &rRanges, const bool bShowSolidBorder)
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
size
void allowAntiAliase(bool bNew)
std::vector< basegfx::B2DRange > maRanges
const Color & getBaseColor() const
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
OverlayRanges(const Color &rColor, const std::vector< basegfx::B2DRange > &rRanges, const bool bShowSolidBorder)
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
virtual SdrView * GetDrawView() const override
Definition: viewdraw.cxx:612
SdrPaintWindow * GetPaintWindow(sal_uInt32 nIndex) const
void setRanges(const std::vector< basegfx::B2DRange > &rNew)
Definition: view.hxx:144