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 <OverlayRanges.hxx>
21 : #include <view.hxx>
22 : #include <svx/sdrpaintwindow.hxx>
23 : #include <svx/svdview.hxx>
24 : #include <svx/sdr/overlay/overlaymanager.hxx>
25 : #include <basegfx/polygon/b2dpolygon.hxx>
26 : #include <basegfx/polygon/b2dpolypolygon.hxx>
27 : #include <basegfx/polygon/b2dpolygontools.hxx>
28 : #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
29 : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
30 : #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
31 :
32 : namespace
33 : {
34 : // combine ranges geometrically to a single, ORed polygon
35 0 : basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
36 : {
37 0 : const sal_uInt32 nCount(rRanges.size());
38 0 : basegfx::B2DPolyPolygon aRetval;
39 :
40 0 : for(sal_uInt32 a(0); a < nCount; a++)
41 : {
42 0 : const basegfx::B2DPolygon aDiscretePolygon(basegfx::tools::createPolygonFromRect(rRanges[a]));
43 :
44 0 : if(0 == a)
45 : {
46 0 : aRetval.append(aDiscretePolygon);
47 : }
48 : else
49 : {
50 0 : aRetval = basegfx::tools::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
51 : }
52 0 : }
53 :
54 0 : return aRetval;
55 : }
56 : }
57 :
58 : namespace sw
59 : {
60 : namespace overlay
61 : {
62 150 : drawinglayer::primitive2d::Primitive2DSequence OverlayRanges::createOverlayObjectPrimitive2DSequence()
63 : {
64 150 : const sal_uInt32 nCount(getRanges().size());
65 150 : drawinglayer::primitive2d::Primitive2DSequence aRetval;
66 150 : aRetval.realloc(nCount);
67 372 : for ( sal_uInt32 a = 0; a < nCount; ++a )
68 : {
69 222 : const basegfx::BColor aRGBColor(getBaseColor().getBColor());
70 444 : const basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(maRanges[a]));
71 444 : aRetval[a] = drawinglayer::primitive2d::Primitive2DReference(
72 : new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
73 : basegfx::B2DPolyPolygon(aPolygon),
74 666 : aRGBColor));
75 222 : }
76 : // embed all rectangles in transparent paint
77 300 : const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
78 150 : const sal_uInt16 nTransparence( aSvtOptionsDrawinglayer.GetTransparentSelectionPercent() );
79 150 : const double fTransparence( nTransparence / 100.0 );
80 : const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence(
81 : new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
82 : aRetval,
83 300 : fTransparence));
84 :
85 150 : if ( mbShowSolidBorder )
86 : {
87 0 : const basegfx::BColor aRGBColor(getBaseColor().getBColor());
88 0 : const basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
89 : const drawinglayer::primitive2d::Primitive2DReference aOutline(
90 : new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
91 : aPolyPolygon,
92 0 : aRGBColor));
93 :
94 0 : aRetval.realloc(2);
95 0 : aRetval[0] = aUnifiedTransparence;
96 0 : aRetval[1] = aOutline;
97 : }
98 : else
99 : {
100 150 : aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aUnifiedTransparence, 1);
101 : }
102 :
103 300 : return aRetval;
104 : }
105 :
106 84 : /*static*/ OverlayRanges* OverlayRanges::CreateOverlayRange(
107 : SwView& rDocView,
108 : const Color& rColor,
109 : const std::vector< basegfx::B2DRange >& rRanges,
110 : const bool bShowSolidBorder )
111 : {
112 84 : OverlayRanges* pOverlayRanges = NULL;
113 :
114 84 : SdrView* pView = rDocView.GetDrawView();
115 84 : if ( pView != NULL )
116 : {
117 84 : SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
118 84 : rtl::Reference<sdr::overlay::OverlayManager> xTargetOverlay = pCandidate->GetOverlayManager();
119 :
120 84 : if ( xTargetOverlay.is() )
121 : {
122 84 : pOverlayRanges = new sw::overlay::OverlayRanges( rColor, rRanges, bShowSolidBorder );
123 84 : xTargetOverlay->add( *pOverlayRanges );
124 84 : }
125 : }
126 :
127 84 : return pOverlayRanges;
128 : }
129 :
130 84 : OverlayRanges::OverlayRanges(
131 : const Color& rColor,
132 : const std::vector< basegfx::B2DRange >& rRanges,
133 : const bool bShowSolidBorder )
134 : : sdr::overlay::OverlayObject( rColor )
135 : , maRanges( rRanges )
136 84 : , mbShowSolidBorder( bShowSolidBorder )
137 : {
138 : // no AA for highlight overlays
139 84 : allowAntiAliase(false);
140 84 : }
141 :
142 252 : OverlayRanges::~OverlayRanges()
143 : {
144 84 : if( getOverlayManager() )
145 : {
146 84 : getOverlayManager()->remove(*this);
147 : }
148 168 : }
149 :
150 806 : void OverlayRanges::setRanges(const std::vector< basegfx::B2DRange >& rNew)
151 : {
152 806 : if(rNew != maRanges)
153 : {
154 66 : maRanges = rNew;
155 66 : objectChange();
156 : }
157 806 : }
158 :
159 0 : void OverlayRanges::ShowSolidBorder()
160 : {
161 0 : if ( !mbShowSolidBorder )
162 : {
163 0 : mbShowSolidBorder = true;
164 0 : objectChange();
165 : }
166 0 : }
167 :
168 806 : void OverlayRanges::HideSolidBorder()
169 : {
170 806 : if ( mbShowSolidBorder )
171 : {
172 0 : mbShowSolidBorder = false;
173 0 : objectChange();
174 : }
175 806 : }
176 :
177 : } // end of namespace overlay
178 270 : } // end of namespace sdr
179 :
180 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|