Line data Source code
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 <svx/sdr/overlay/overlayselection.hxx>
21 : #include <basegfx/polygon/b2dpolygontools.hxx>
22 : #include <basegfx/polygon/b2dpolygon.hxx>
23 : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
24 : #include <svtools/optionsdrawinglayer.hxx>
25 : #include <vcl/svapp.hxx>
26 : #include <vcl/outdev.hxx>
27 : #include <vcl/settings.hxx>
28 : #include <drawinglayer/primitive2d/invertprimitive2d.hxx>
29 : #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
30 : #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
31 : #include <svx/sdr/overlay/overlaymanager.hxx>
32 :
33 :
34 :
35 : namespace sdr
36 : {
37 : namespace overlay
38 : {
39 : // combine rages geometrically to a single, ORed polygon
40 0 : basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
41 : {
42 0 : const sal_uInt32 nCount(rRanges.size());
43 0 : basegfx::B2DPolyPolygon aRetval;
44 :
45 0 : for(sal_uInt32 a(0); a < nCount; a++)
46 : {
47 0 : const basegfx::B2DPolygon aDiscretePolygon(basegfx::tools::createPolygonFromRect(rRanges[a]));
48 :
49 0 : if(0 == a)
50 : {
51 0 : aRetval.append(aDiscretePolygon);
52 : }
53 : else
54 : {
55 0 : aRetval = basegfx::tools::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
56 : }
57 0 : }
58 :
59 0 : return aRetval;
60 : }
61 :
62 : // check if wanted type OVERLAY_TRANSPARENT or OVERLAY_SOLID
63 : // is possible. If not, fallback to invert mode (classic mode)
64 13026 : OverlayType impCheckPossibleOverlayType(OverlayType aOverlayType)
65 : {
66 13026 : if(OVERLAY_INVERT != aOverlayType)
67 : {
68 13026 : const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
69 :
70 13026 : if(!aSvtOptionsDrawinglayer.IsTransparentSelection())
71 : {
72 : // not possible when switched off by user
73 0 : return OVERLAY_INVERT;
74 : }
75 13026 : else if (const OutputDevice* pOut = Application::GetDefaultDevice())
76 : {
77 :
78 13026 : if(pOut->GetSettings().GetStyleSettings().GetHighContrastMode())
79 : {
80 : // not possible when in high contrast mode
81 0 : return OVERLAY_INVERT;
82 : }
83 :
84 13026 : if(!pOut->SupportsOperation(OutDevSupport_TransparentRect))
85 : {
86 : // not possible when no fast transparence paint is supported on the system
87 13026 : return OVERLAY_INVERT;
88 : }
89 0 : }
90 : }
91 :
92 0 : return aOverlayType;
93 : }
94 :
95 5773 : drawinglayer::primitive2d::Primitive2DSequence OverlaySelection::createOverlayObjectPrimitive2DSequence()
96 : {
97 5773 : drawinglayer::primitive2d::Primitive2DSequence aRetval;
98 5773 : const sal_uInt32 nCount(getRanges().size());
99 :
100 5773 : if(nCount)
101 : {
102 : // create range primitives
103 5773 : const bool bInvert(OVERLAY_INVERT == maLastOverlayType);
104 5773 : basegfx::BColor aRGBColor(getBaseColor().getBColor());
105 5773 : aRetval.realloc(nCount);
106 :
107 5773 : if(bInvert)
108 : {
109 : // force color to white for invert to get a full invert
110 5773 : aRGBColor = basegfx::BColor(1.0, 1.0, 1.0);
111 : }
112 :
113 20633 : for(sal_uInt32 a(0);a < nCount; a++)
114 : {
115 14860 : const basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(maRanges[a]));
116 29720 : aRetval[a] = drawinglayer::primitive2d::Primitive2DReference(
117 : new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
118 : basegfx::B2DPolyPolygon(aPolygon),
119 44580 : aRGBColor));
120 14860 : }
121 :
122 5773 : if(bInvert)
123 : {
124 : // embed all in invert primitive
125 : const drawinglayer::primitive2d::Primitive2DReference aInvert(
126 : new drawinglayer::primitive2d::InvertPrimitive2D(
127 5773 : aRetval));
128 5773 : aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aInvert, 1);
129 : }
130 0 : else if(OVERLAY_TRANSPARENT == maLastOverlayType)
131 : {
132 : // embed all rectangles in transparent paint
133 0 : const double fTransparence(mnLastTransparence / 100.0);
134 : const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence(
135 : new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
136 : aRetval,
137 0 : fTransparence));
138 :
139 0 : if(getBorder())
140 : {
141 0 : const basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
142 : const drawinglayer::primitive2d::Primitive2DReference aSelectionOutline(
143 : new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
144 : aPolyPolygon,
145 0 : aRGBColor));
146 :
147 : // add both to result
148 0 : aRetval.realloc(2);
149 0 : aRetval[0] = aUnifiedTransparence;
150 0 : aRetval[1] = aSelectionOutline;
151 : }
152 : else
153 : {
154 : // just add transparent part
155 0 : aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aUnifiedTransparence, 1);
156 0 : }
157 5773 : }
158 : }
159 :
160 5773 : return aRetval;
161 : }
162 :
163 5760 : OverlaySelection::OverlaySelection(
164 : OverlayType eType,
165 : const Color& rColor,
166 : const std::vector< basegfx::B2DRange >& rRanges,
167 : bool bBorder)
168 : : OverlayObject(rColor),
169 : meOverlayType(eType),
170 : maRanges(rRanges),
171 : maLastOverlayType(eType),
172 : mnLastTransparence(0),
173 5760 : mbBorder(bBorder)
174 : {
175 : // no AA for selection overlays
176 5760 : allowAntiAliase(false);
177 5760 : }
178 :
179 17274 : OverlaySelection::~OverlaySelection()
180 : {
181 5758 : if(getOverlayManager())
182 : {
183 116 : getOverlayManager()->remove(*this);
184 : }
185 11516 : }
186 :
187 13026 : drawinglayer::primitive2d::Primitive2DSequence OverlaySelection::getOverlayObjectPrimitive2DSequence() const
188 : {
189 : // get current values
190 13026 : const OverlayType aNewOverlayType(impCheckPossibleOverlayType(meOverlayType));
191 13026 : const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
192 13026 : const sal_uInt16 nNewTransparence(aSvtOptionsDrawinglayer.GetTransparentSelectionPercent());
193 :
194 13026 : if(getPrimitive2DSequence().hasElements())
195 : {
196 7253 : if(aNewOverlayType != maLastOverlayType
197 7253 : || nNewTransparence != mnLastTransparence)
198 : {
199 : // conditions of last local decomposition have changed, delete
200 0 : const_cast< OverlaySelection* >(this)->setPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DSequence());
201 : }
202 : }
203 :
204 13026 : if(!getPrimitive2DSequence().hasElements())
205 : {
206 : // remember new values
207 5773 : const_cast< OverlaySelection* >(this)->maLastOverlayType = aNewOverlayType;
208 5773 : const_cast< OverlaySelection* >(this)->mnLastTransparence = nNewTransparence;
209 : }
210 :
211 : // call base implementation
212 13026 : return OverlayObject::getOverlayObjectPrimitive2DSequence();
213 : }
214 :
215 266 : void OverlaySelection::setRanges(const std::vector< basegfx::B2DRange >& rNew)
216 : {
217 266 : if(rNew != maRanges)
218 : {
219 13 : maRanges = rNew;
220 13 : objectChange();
221 : }
222 266 : }
223 : } // end of namespace overlay
224 : } // end of namespace sdr
225 :
226 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|