bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / sdr / overlay / overlayselection.cxx
blob4abcd2bd7182055c7039bf590a7609686956c0d2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <svx/sdr/overlay/overlayselection.hxx>
21 #include <basegfx/polygon/b2dpolygontools.hxx>
22 #include <basegfx/polygon/b2dpolygon.hxx>
23 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
24 #include <drawinglayer/primitive2d/PolyPolygonHairlinePrimitive2D.hxx>
25 #include <svtools/optionsdrawinglayer.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/outdev.hxx>
28 #include <vcl/settings.hxx>
29 #include <drawinglayer/primitive2d/invertprimitive2d.hxx>
30 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
31 #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
32 #include <svx/sdr/overlay/overlaymanager.hxx>
35 namespace sdr::overlay
37 // combine rages geometrically to a single, ORed polygon
38 static basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
40 const sal_uInt32 nCount(rRanges.size());
41 basegfx::B2DPolyPolygon aRetval;
43 for(sal_uInt32 a(0); a < nCount; a++)
45 const basegfx::B2DPolygon aDiscretePolygon(basegfx::utils::createPolygonFromRect(rRanges[a]));
47 if(0 == a)
49 aRetval.append(aDiscretePolygon);
51 else
53 aRetval = basegfx::utils::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
57 return aRetval;
60 // check if wanted type OverlayType::Transparent or OverlayType::Solid
61 // is possible. If not, fallback to invert mode (classic mode)
62 static OverlayType impCheckPossibleOverlayType(OverlayType aOverlayType)
64 if(OverlayType::Invert != aOverlayType)
66 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
68 if(!aSvtOptionsDrawinglayer.IsTransparentSelection())
70 // not possible when switched off by user
71 return OverlayType::Invert;
73 else if (const OutputDevice* pOut = Application::GetDefaultDevice())
76 if(pOut->GetSettings().GetStyleSettings().GetHighContrastMode())
78 // not possible when in high contrast mode
79 return OverlayType::Invert;
82 if(!pOut->SupportsOperation(OutDevSupportType::TransparentRect))
84 // not possible when no fast transparence paint is supported on the system
85 return OverlayType::Invert;
90 return aOverlayType;
93 drawinglayer::primitive2d::Primitive2DContainer OverlaySelection::createOverlayObjectPrimitive2DSequence()
95 drawinglayer::primitive2d::Primitive2DContainer aRetval;
96 const sal_uInt32 nCount(getRanges().size());
98 if(nCount)
100 // create range primitives
101 const bool bInvert(OverlayType::Invert == maLastOverlayType);
102 basegfx::BColor aRGBColor(getBaseColor().getBColor());
103 aRetval.resize(nCount);
105 if(bInvert)
107 // force color to white for invert to get a full invert
108 aRGBColor = basegfx::BColor(1.0, 1.0, 1.0);
111 for(sal_uInt32 a(0);a < nCount; a++)
113 const basegfx::B2DPolygon aPolygon(basegfx::utils::createPolygonFromRect(maRanges[a]));
114 aRetval[a] = drawinglayer::primitive2d::Primitive2DReference(
115 new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
116 basegfx::B2DPolyPolygon(aPolygon),
117 aRGBColor));
120 if(bInvert)
122 // embed all in invert primitive
123 const drawinglayer::primitive2d::Primitive2DReference aInvert(
124 new drawinglayer::primitive2d::InvertPrimitive2D(
125 aRetval));
126 aRetval = drawinglayer::primitive2d::Primitive2DContainer { aInvert };
128 else if(OverlayType::Transparent == maLastOverlayType)
130 // embed all rectangles in transparent paint
131 const double fTransparence(mnLastTransparence / 100.0);
132 const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence(
133 new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
134 aRetval,
135 fTransparence));
137 if(mbBorder)
139 const basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
140 const drawinglayer::primitive2d::Primitive2DReference aSelectionOutline(
141 new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
142 aPolyPolygon,
143 aRGBColor));
145 // add both to result
146 aRetval.resize(2);
147 aRetval[0] = aUnifiedTransparence;
148 aRetval[1] = aSelectionOutline;
150 else
152 // just add transparent part
153 aRetval = drawinglayer::primitive2d::Primitive2DContainer { aUnifiedTransparence };
158 return aRetval;
161 OverlaySelection::OverlaySelection(
162 OverlayType eType,
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)
173 // no AA for selection overlays
174 allowAntiAliase(false);
177 OverlaySelection::~OverlaySelection()
179 if(getOverlayManager())
181 getOverlayManager()->remove(*this);
185 drawinglayer::primitive2d::Primitive2DContainer OverlaySelection::getOverlayObjectPrimitive2DSequence() const
187 // get current values
188 const OverlayType aNewOverlayType(impCheckPossibleOverlayType(meOverlayType));
189 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
190 const sal_uInt16 nNewTransparence(aSvtOptionsDrawinglayer.GetTransparentSelectionPercent());
192 if(!getPrimitive2DSequence().empty())
194 if(aNewOverlayType != maLastOverlayType
195 || nNewTransparence != mnLastTransparence)
197 // conditions of last local decomposition have changed, delete
198 const_cast< OverlaySelection* >(this)->resetPrimitive2DSequence();
202 if(getPrimitive2DSequence().empty())
204 // remember new values
205 const_cast< OverlaySelection* >(this)->maLastOverlayType = aNewOverlayType;
206 const_cast< OverlaySelection* >(this)->mnLastTransparence = nNewTransparence;
209 // call base implementation
210 return OverlayObject::getOverlayObjectPrimitive2DSequence();
213 void OverlaySelection::setRanges(const std::vector< basegfx::B2DRange >& rNew)
215 if(rNew != maRanges)
217 maRanges = rNew;
218 objectChange();
221 } // end of namespace
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */