LibreOffice Module svx (master)  1
overlayselection.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 
26 #include <vcl/svapp.hxx>
27 #include <vcl/outdev.hxx>
28 #include <vcl/settings.hxx>
33 
34 
35 namespace sdr::overlay
36 {
37  // combine rages geometrically to a single, ORed polygon
38  static basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
39  {
40  const sal_uInt32 nCount(rRanges.size());
42 
43  for(sal_uInt32 a(0); a < nCount; a++)
44  {
45  const basegfx::B2DPolygon aDiscretePolygon(basegfx::utils::createPolygonFromRect(rRanges[a]));
46 
47  if(0 == a)
48  {
49  aRetval.append(aDiscretePolygon);
50  }
51  else
52  {
53  aRetval = basegfx::utils::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
54  }
55  }
56 
57  return aRetval;
58  }
59 
60  // check if wanted type OverlayType::Transparent or OverlayType::Solid
61  // is possible. If not, fallback to invert mode (classic mode)
63  {
64  if(OverlayType::Invert != aOverlayType)
65  {
66  const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
67 
68  if(!aSvtOptionsDrawinglayer.IsTransparentSelection())
69  {
70  // not possible when switched off by user
71  return OverlayType::Invert;
72  }
74  {
75 
76  if(pOut->GetSettings().GetStyleSettings().GetHighContrastMode())
77  {
78  // not possible when in high contrast mode
79  return OverlayType::Invert;
80  }
81 
82  if(!pOut->SupportsOperation(OutDevSupportType::TransparentRect))
83  {
84  // not possible when no fast transparence paint is supported on the system
85  return OverlayType::Invert;
86  }
87  }
88  }
89 
90  return aOverlayType;
91  }
92 
94  {
96  const sal_uInt32 nCount(getRanges().size());
97 
98  if(nCount)
99  {
100  // create range primitives
101  const bool bInvert(OverlayType::Invert == maLastOverlayType);
102  basegfx::BColor aRGBColor(getBaseColor().getBColor());
103  aRetval.resize(nCount);
104 
105  if(bInvert)
106  {
107  // force color to white for invert to get a full invert
108  aRGBColor = basegfx::BColor(1.0, 1.0, 1.0);
109  }
110 
111  for(sal_uInt32 a(0);a < nCount; a++)
112  {
116  basegfx::B2DPolyPolygon(aPolygon),
117  aRGBColor));
118  }
119 
120  if(bInvert)
121  {
122  // embed all in invert primitive
125  aRetval));
127  }
129  {
130  // embed all rectangles in transparent paint
131  const double fTransparence(mnLastTransparence / 100.0);
132  const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence(
134  aRetval,
135  fTransparence));
136 
137  if(mbBorder)
138  {
140  const drawinglayer::primitive2d::Primitive2DReference aSelectionOutline(
142  aPolyPolygon,
143  aRGBColor));
144 
145  // add both to result
146  aRetval.resize(2);
147  aRetval[0] = aUnifiedTransparence;
148  aRetval[1] = aSelectionOutline;
149  }
150  else
151  {
152  // just add transparent part
153  aRetval = drawinglayer::primitive2d::Primitive2DContainer { aUnifiedTransparence };
154  }
155  }
156  }
157 
158  return aRetval;
159  }
160 
163  const Color& rColor,
164  const std::vector< basegfx::B2DRange >& rRanges,
165  bool bBorder)
166  : OverlayObject(rColor),
167  meOverlayType(eType),
168  maRanges(rRanges),
169  maLastOverlayType(eType),
170  mnLastTransparence(0),
171  mbBorder(bBorder)
172  {
173  // no AA for selection overlays
174  allowAntiAliase(false);
175  }
176 
178  {
179  if(getOverlayManager())
180  {
181  getOverlayManager()->remove(*this);
182  }
183  }
184 
186  {
187  // get current values
188  const OverlayType aNewOverlayType(impCheckPossibleOverlayType(meOverlayType));
189  const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
190  const sal_uInt16 nNewTransparence(aSvtOptionsDrawinglayer.GetTransparentSelectionPercent());
191 
192  if(!getPrimitive2DSequence().empty())
193  {
194  if(aNewOverlayType != maLastOverlayType
195  || nNewTransparence != mnLastTransparence)
196  {
197  // conditions of last local decomposition have changed, delete
198  const_cast< OverlaySelection* >(this)->resetPrimitive2DSequence();
199  }
200  }
201 
202  if(getPrimitive2DSequence().empty())
203  {
204  // remember new values
205  const_cast< OverlaySelection* >(this)->maLastOverlayType = aNewOverlayType;
206  const_cast< OverlaySelection* >(this)->mnLastTransparence = nNewTransparence;
207  }
208 
209  // call base implementation
211  }
212 
213  void OverlaySelection::setRanges(const std::vector< basegfx::B2DRange >& rNew)
214  {
215  if(rNew != maRanges)
216  {
217  maRanges = rNew;
218  objectChange();
219  }
220  }
221 } // end of namespace
222 
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const drawinglayer::primitive2d::Primitive2DContainer & getPrimitive2DSequence() const
sal_uInt16 GetTransparentSelectionPercent() const
B2DPolyPolygon solvePolygonOperationOr(const B2DPolyPolygon &rCandidateA, const B2DPolyPolygon &rCandidateB)
void setRanges(const std::vector< basegfx::B2DRange > &rNew)
OverlayManager * getOverlayManager() const
const std::vector< basegfx::B2DRange > & getRanges() const
static OutputDevice * GetDefaultDevice()
void remove(OverlayObject &rOverlayObject)
int nCount
oslFileHandle & pOut
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
DocumentType eType
uno_Any a
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
size
virtual drawinglayer::primitive2d::Primitive2DContainer getOverlayObjectPrimitive2DSequence() const
OverlaySelection(OverlayType eType, const Color &rColor, const std::vector< basegfx::B2DRange > &rRanges, bool bBorder)
void allowAntiAliase(bool bNew)
const Color & getBaseColor() const
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
std::vector< basegfx::B2DRange > maRanges
static basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange > &rRanges)
bool IsTransparentSelection() const
static OverlayType impCheckPossibleOverlayType(OverlayType aOverlayType)
virtual drawinglayer::primitive2d::Primitive2DContainer getOverlayObjectPrimitive2DSequence() const override
override to check conditions for last createOverlayObjectPrimitive2DSequence