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
35namespace 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 {
67 {
68 // not possible when switched off by user
70 }
72 {
73
74 if(pOut->GetSettings().GetStyleSettings().GetHighContrastMode())
75 {
76 // not possible when in high contrast mode
78 }
79
80 if(!pOut->SupportsOperation(OutDevSupportType::TransparentRect))
81 {
82 // not possible when no fast transparence paint is supported on the system
84 }
85 }
86 }
87
88 return aOverlayType;
89 }
90
92 {
94 const sal_uInt32 nCount(getRanges().size());
95
96 if(nCount)
97 {
98 // create range primitives
99 const bool bInvert(OverlayType::Invert == maLastOverlayType);
100 basegfx::BColor aRGBColor(getBaseColor().getBColor());
101 aRetval.resize(nCount);
102
103 if(bInvert)
104 {
105 // force color to white for invert to get a full invert
106 aRGBColor = basegfx::BColor(1.0, 1.0, 1.0);
107 }
108
109 for(sal_uInt32 a(0);a < nCount; a++)
110 {
114 basegfx::B2DPolyPolygon(aPolygon),
115 aRGBColor));
116 }
117
118 if(bInvert)
119 {
120 // embed all in invert primitive
123 std::move(aRetval)));
125 }
127 {
128 // embed all rectangles in transparent paint
129 const double fTransparence(mnLastTransparence / 100.0);
130 const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence(
132 std::move(aRetval),
133 fTransparence));
134
135 if(mbBorder)
136 {
140 std::move(aPolyPolygon),
141 aRGBColor));
142
143 // add both to result
144 aRetval = drawinglayer::primitive2d::Primitive2DContainer { aUnifiedTransparence, aSelectionOutline };
145 }
146 else
147 {
148 // just add transparent part
149 aRetval = drawinglayer::primitive2d::Primitive2DContainer { aUnifiedTransparence };
150 }
151 }
152 }
153
154 return aRetval;
155 }
156
159 const Color& rColor,
160 std::vector< basegfx::B2DRange >&& rRanges,
161 bool bBorder)
162 : OverlayObject(rColor),
163 meOverlayType(eType),
164 maRanges(std::move(rRanges)),
165 maLastOverlayType(eType),
166 mnLastTransparence(0),
167 mbBorder(bBorder)
168 {
169 // no AA for selection overlays
170 allowAntiAliase(false);
171 }
172
174 {
176 {
177 getOverlayManager()->remove(*this);
178 }
179 }
180
182 {
183 // get current values
185 const sal_uInt16 nNewTransparence(SvtOptionsDrawinglayer::GetTransparentSelectionPercent());
186
187 if(!getPrimitive2DSequence().empty())
188 {
189 if(aNewOverlayType != maLastOverlayType
190 || nNewTransparence != mnLastTransparence)
191 {
192 // conditions of last local decomposition have changed, delete
193 const_cast< OverlaySelection* >(this)->resetPrimitive2DSequence();
194 }
195 }
196
197 if(getPrimitive2DSequence().empty())
198 {
199 // remember new values
200 const_cast< OverlaySelection* >(this)->maLastOverlayType = aNewOverlayType;
201 const_cast< OverlaySelection* >(this)->mnLastTransparence = nNewTransparence;
202 }
203
204 // call base implementation
206 }
207
208 void OverlaySelection::setRanges(std::vector< basegfx::B2DRange >&& rNew)
209 {
210 if(rNew != maRanges)
211 {
212 maRanges = std::move(rNew);
213 objectChange();
214 }
215 }
216} // end of namespace
217
218/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OutputDevice * GetDefaultDevice()
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
void remove(OverlayObject &rOverlayObject)
const Color & getBaseColor() const
void allowAntiAliase(bool bNew)
OverlayManager * getOverlayManager() const
const drawinglayer::primitive2d::Primitive2DContainer & getPrimitive2DSequence() const
virtual drawinglayer::primitive2d::Primitive2DContainer getOverlayObjectPrimitive2DSequence() const
std::vector< basegfx::B2DRange > maRanges
virtual drawinglayer::primitive2d::Primitive2DContainer getOverlayObjectPrimitive2DSequence() const override
override to check conditions for last createOverlayObjectPrimitive2DSequence
void setRanges(std::vector< basegfx::B2DRange > &&rNew)
OverlaySelection(OverlayType eType, const Color &rColor, std::vector< basegfx::B2DRange > &&rRanges, bool bBorder)
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
const std::vector< basegfx::B2DRange > & getRanges() const
int nCount
DocumentType eType
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
static OverlayType impCheckPossibleOverlayType(OverlayType aOverlayType)
static basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange > &rRanges)
oslFileHandle & pOut