1*dec99bbdSOliver-Rainer Wittmann /************************************************************** 2*dec99bbdSOliver-Rainer Wittmann * 3*dec99bbdSOliver-Rainer Wittmann * Licensed to the Apache Software Foundation (ASF) under one 4*dec99bbdSOliver-Rainer Wittmann * or more contributor license agreements. See the NOTICE file 5*dec99bbdSOliver-Rainer Wittmann * distributed with this work for additional information 6*dec99bbdSOliver-Rainer Wittmann * regarding copyright ownership. The ASF licenses this file 7*dec99bbdSOliver-Rainer Wittmann * to you under the Apache License, Version 2.0 (the 8*dec99bbdSOliver-Rainer Wittmann * "License"); you may not use this file except in compliance 9*dec99bbdSOliver-Rainer Wittmann * with the License. You may obtain a copy of the License at 10*dec99bbdSOliver-Rainer Wittmann * 11*dec99bbdSOliver-Rainer Wittmann * http://www.apache.org/licenses/LICENSE-2.0 12*dec99bbdSOliver-Rainer Wittmann * 13*dec99bbdSOliver-Rainer Wittmann * Unless required by applicable law or agreed to in writing, 14*dec99bbdSOliver-Rainer Wittmann * software distributed under the License is distributed on an 15*dec99bbdSOliver-Rainer Wittmann * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*dec99bbdSOliver-Rainer Wittmann * KIND, either express or implied. See the License for the 17*dec99bbdSOliver-Rainer Wittmann * specific language governing permissions and limitations 18*dec99bbdSOliver-Rainer Wittmann * under the License. 19*dec99bbdSOliver-Rainer Wittmann * 20*dec99bbdSOliver-Rainer Wittmann *************************************************************/ 21*dec99bbdSOliver-Rainer Wittmann 22*dec99bbdSOliver-Rainer Wittmann 23*dec99bbdSOliver-Rainer Wittmann // MARKER(update_precomp.py): autogen include statement, do not remove 24*dec99bbdSOliver-Rainer Wittmann #include "precompiled_sw.hxx" 25*dec99bbdSOliver-Rainer Wittmann 26*dec99bbdSOliver-Rainer Wittmann #include <OverlayRanges.hxx> 27*dec99bbdSOliver-Rainer Wittmann #include <view.hxx> 28*dec99bbdSOliver-Rainer Wittmann #include <svx/sdrpaintwindow.hxx> 29*dec99bbdSOliver-Rainer Wittmann #include <svx/svdview.hxx> 30*dec99bbdSOliver-Rainer Wittmann #include <svx/sdr/overlay/overlaymanager.hxx> 31*dec99bbdSOliver-Rainer Wittmann #include <basegfx/polygon/b2dpolygon.hxx> 32*dec99bbdSOliver-Rainer Wittmann #include <basegfx/polygon/b2dpolypolygon.hxx> 33*dec99bbdSOliver-Rainer Wittmann #include <basegfx/polygon/b2dpolygontools.hxx> 34*dec99bbdSOliver-Rainer Wittmann #include <basegfx/polygon/b2dpolypolygoncutter.hxx> 35*dec99bbdSOliver-Rainer Wittmann #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> 36*dec99bbdSOliver-Rainer Wittmann #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx> 37*dec99bbdSOliver-Rainer Wittmann 38*dec99bbdSOliver-Rainer Wittmann ////////////////////////////////////////////////////////////////////////////// 39*dec99bbdSOliver-Rainer Wittmann 40*dec99bbdSOliver-Rainer Wittmann namespace 41*dec99bbdSOliver-Rainer Wittmann { 42*dec99bbdSOliver-Rainer Wittmann // combine ranges geometrically to a single, ORed polygon impCombineRangesToPolyPolygon(const std::vector<basegfx::B2DRange> & rRanges)43*dec99bbdSOliver-Rainer Wittmann basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges) 44*dec99bbdSOliver-Rainer Wittmann { 45*dec99bbdSOliver-Rainer Wittmann const sal_uInt32 nCount(rRanges.size()); 46*dec99bbdSOliver-Rainer Wittmann basegfx::B2DPolyPolygon aRetval; 47*dec99bbdSOliver-Rainer Wittmann 48*dec99bbdSOliver-Rainer Wittmann for(sal_uInt32 a(0); a < nCount; a++) 49*dec99bbdSOliver-Rainer Wittmann { 50*dec99bbdSOliver-Rainer Wittmann const basegfx::B2DPolygon aDiscretePolygon(basegfx::tools::createPolygonFromRect(rRanges[a])); 51*dec99bbdSOliver-Rainer Wittmann 52*dec99bbdSOliver-Rainer Wittmann if(0 == a) 53*dec99bbdSOliver-Rainer Wittmann { 54*dec99bbdSOliver-Rainer Wittmann aRetval.append(aDiscretePolygon); 55*dec99bbdSOliver-Rainer Wittmann } 56*dec99bbdSOliver-Rainer Wittmann else 57*dec99bbdSOliver-Rainer Wittmann { 58*dec99bbdSOliver-Rainer Wittmann aRetval = basegfx::tools::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon)); 59*dec99bbdSOliver-Rainer Wittmann } 60*dec99bbdSOliver-Rainer Wittmann } 61*dec99bbdSOliver-Rainer Wittmann 62*dec99bbdSOliver-Rainer Wittmann return aRetval; 63*dec99bbdSOliver-Rainer Wittmann } 64*dec99bbdSOliver-Rainer Wittmann } 65*dec99bbdSOliver-Rainer Wittmann 66*dec99bbdSOliver-Rainer Wittmann namespace sw 67*dec99bbdSOliver-Rainer Wittmann { 68*dec99bbdSOliver-Rainer Wittmann namespace overlay 69*dec99bbdSOliver-Rainer Wittmann { createOverlayObjectPrimitive2DSequence()70*dec99bbdSOliver-Rainer Wittmann drawinglayer::primitive2d::Primitive2DSequence OverlayRanges::createOverlayObjectPrimitive2DSequence() 71*dec99bbdSOliver-Rainer Wittmann { 72*dec99bbdSOliver-Rainer Wittmann const sal_uInt32 nCount(getRanges().size()); 73*dec99bbdSOliver-Rainer Wittmann drawinglayer::primitive2d::Primitive2DSequence aRetval; 74*dec99bbdSOliver-Rainer Wittmann aRetval.realloc(nCount); 75*dec99bbdSOliver-Rainer Wittmann for ( sal_uInt32 a = 0; a < nCount; ++a ) 76*dec99bbdSOliver-Rainer Wittmann { 77*dec99bbdSOliver-Rainer Wittmann const basegfx::BColor aRGBColor(getBaseColor().getBColor()); 78*dec99bbdSOliver-Rainer Wittmann const basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(maRanges[a])); 79*dec99bbdSOliver-Rainer Wittmann aRetval[a] = drawinglayer::primitive2d::Primitive2DReference( 80*dec99bbdSOliver-Rainer Wittmann new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D( 81*dec99bbdSOliver-Rainer Wittmann basegfx::B2DPolyPolygon(aPolygon), 82*dec99bbdSOliver-Rainer Wittmann aRGBColor)); 83*dec99bbdSOliver-Rainer Wittmann } 84*dec99bbdSOliver-Rainer Wittmann // embed all rectangles in transparent paint 85*dec99bbdSOliver-Rainer Wittmann const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer; 86*dec99bbdSOliver-Rainer Wittmann const sal_uInt16 nTransparence( aSvtOptionsDrawinglayer.GetTransparentSelectionPercent() ); 87*dec99bbdSOliver-Rainer Wittmann const double fTransparence( nTransparence / 100.0 ); 88*dec99bbdSOliver-Rainer Wittmann const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence( 89*dec99bbdSOliver-Rainer Wittmann new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D( 90*dec99bbdSOliver-Rainer Wittmann aRetval, 91*dec99bbdSOliver-Rainer Wittmann fTransparence)); 92*dec99bbdSOliver-Rainer Wittmann 93*dec99bbdSOliver-Rainer Wittmann if ( mbShowSolidBorder ) 94*dec99bbdSOliver-Rainer Wittmann { 95*dec99bbdSOliver-Rainer Wittmann const basegfx::BColor aRGBColor(getBaseColor().getBColor()); 96*dec99bbdSOliver-Rainer Wittmann const basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges())); 97*dec99bbdSOliver-Rainer Wittmann const drawinglayer::primitive2d::Primitive2DReference aOutline( 98*dec99bbdSOliver-Rainer Wittmann new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D( 99*dec99bbdSOliver-Rainer Wittmann aPolyPolygon, 100*dec99bbdSOliver-Rainer Wittmann aRGBColor)); 101*dec99bbdSOliver-Rainer Wittmann 102*dec99bbdSOliver-Rainer Wittmann aRetval.realloc(2); 103*dec99bbdSOliver-Rainer Wittmann aRetval[0] = aUnifiedTransparence; 104*dec99bbdSOliver-Rainer Wittmann aRetval[1] = aOutline; 105*dec99bbdSOliver-Rainer Wittmann } 106*dec99bbdSOliver-Rainer Wittmann else 107*dec99bbdSOliver-Rainer Wittmann { 108*dec99bbdSOliver-Rainer Wittmann aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aUnifiedTransparence, 1); 109*dec99bbdSOliver-Rainer Wittmann } 110*dec99bbdSOliver-Rainer Wittmann 111*dec99bbdSOliver-Rainer Wittmann return aRetval; 112*dec99bbdSOliver-Rainer Wittmann } 113*dec99bbdSOliver-Rainer Wittmann CreateOverlayRange(SwView & rDocView,const Color & rColor,const std::vector<basegfx::B2DRange> & rRanges,const bool bShowSolidBorder)114*dec99bbdSOliver-Rainer Wittmann /*static*/ OverlayRanges* OverlayRanges::CreateOverlayRange( 115*dec99bbdSOliver-Rainer Wittmann SwView& rDocView, 116*dec99bbdSOliver-Rainer Wittmann const Color& rColor, 117*dec99bbdSOliver-Rainer Wittmann const std::vector< basegfx::B2DRange >& rRanges, 118*dec99bbdSOliver-Rainer Wittmann const bool bShowSolidBorder ) 119*dec99bbdSOliver-Rainer Wittmann { 120*dec99bbdSOliver-Rainer Wittmann OverlayRanges* pOverlayRanges = NULL; 121*dec99bbdSOliver-Rainer Wittmann 122*dec99bbdSOliver-Rainer Wittmann SdrView* pView = rDocView.GetDrawView(); 123*dec99bbdSOliver-Rainer Wittmann if ( pView != NULL ) 124*dec99bbdSOliver-Rainer Wittmann { 125*dec99bbdSOliver-Rainer Wittmann SdrPaintWindow* pCandidate = pView->GetPaintWindow(0); 126*dec99bbdSOliver-Rainer Wittmann sdr::overlay::OverlayManager* pTargetOverlay = pCandidate->GetOverlayManager(); 127*dec99bbdSOliver-Rainer Wittmann 128*dec99bbdSOliver-Rainer Wittmann if ( pTargetOverlay != NULL ) 129*dec99bbdSOliver-Rainer Wittmann { 130*dec99bbdSOliver-Rainer Wittmann pOverlayRanges = new sw::overlay::OverlayRanges( rColor, rRanges, bShowSolidBorder ); 131*dec99bbdSOliver-Rainer Wittmann pTargetOverlay->add( *pOverlayRanges ); 132*dec99bbdSOliver-Rainer Wittmann } 133*dec99bbdSOliver-Rainer Wittmann } 134*dec99bbdSOliver-Rainer Wittmann 135*dec99bbdSOliver-Rainer Wittmann return pOverlayRanges; 136*dec99bbdSOliver-Rainer Wittmann } 137*dec99bbdSOliver-Rainer Wittmann OverlayRanges(const Color & rColor,const std::vector<basegfx::B2DRange> & rRanges,const bool bShowSolidBorder)138*dec99bbdSOliver-Rainer Wittmann OverlayRanges::OverlayRanges( 139*dec99bbdSOliver-Rainer Wittmann const Color& rColor, 140*dec99bbdSOliver-Rainer Wittmann const std::vector< basegfx::B2DRange >& rRanges, 141*dec99bbdSOliver-Rainer Wittmann const bool bShowSolidBorder ) 142*dec99bbdSOliver-Rainer Wittmann : sdr::overlay::OverlayObject( rColor ) 143*dec99bbdSOliver-Rainer Wittmann , maRanges( rRanges ) 144*dec99bbdSOliver-Rainer Wittmann , mbShowSolidBorder( bShowSolidBorder ) 145*dec99bbdSOliver-Rainer Wittmann { 146*dec99bbdSOliver-Rainer Wittmann // no AA for highlight overlays 147*dec99bbdSOliver-Rainer Wittmann allowAntiAliase(false); 148*dec99bbdSOliver-Rainer Wittmann } 149*dec99bbdSOliver-Rainer Wittmann ~OverlayRanges()150*dec99bbdSOliver-Rainer Wittmann OverlayRanges::~OverlayRanges() 151*dec99bbdSOliver-Rainer Wittmann { 152*dec99bbdSOliver-Rainer Wittmann if( getOverlayManager() ) 153*dec99bbdSOliver-Rainer Wittmann { 154*dec99bbdSOliver-Rainer Wittmann getOverlayManager()->remove(*this); 155*dec99bbdSOliver-Rainer Wittmann } 156*dec99bbdSOliver-Rainer Wittmann } 157*dec99bbdSOliver-Rainer Wittmann setRanges(const std::vector<basegfx::B2DRange> & rNew)158*dec99bbdSOliver-Rainer Wittmann void OverlayRanges::setRanges(const std::vector< basegfx::B2DRange >& rNew) 159*dec99bbdSOliver-Rainer Wittmann { 160*dec99bbdSOliver-Rainer Wittmann if(rNew != maRanges) 161*dec99bbdSOliver-Rainer Wittmann { 162*dec99bbdSOliver-Rainer Wittmann maRanges = rNew; 163*dec99bbdSOliver-Rainer Wittmann objectChange(); 164*dec99bbdSOliver-Rainer Wittmann } 165*dec99bbdSOliver-Rainer Wittmann } 166*dec99bbdSOliver-Rainer Wittmann 167*dec99bbdSOliver-Rainer Wittmann ShowSolidBorder()168*dec99bbdSOliver-Rainer Wittmann void OverlayRanges::ShowSolidBorder() 169*dec99bbdSOliver-Rainer Wittmann { 170*dec99bbdSOliver-Rainer Wittmann if ( !mbShowSolidBorder ) 171*dec99bbdSOliver-Rainer Wittmann { 172*dec99bbdSOliver-Rainer Wittmann mbShowSolidBorder = true; 173*dec99bbdSOliver-Rainer Wittmann objectChange(); 174*dec99bbdSOliver-Rainer Wittmann } 175*dec99bbdSOliver-Rainer Wittmann } 176*dec99bbdSOliver-Rainer Wittmann HideSolidBorder()177*dec99bbdSOliver-Rainer Wittmann void OverlayRanges::HideSolidBorder() 178*dec99bbdSOliver-Rainer Wittmann { 179*dec99bbdSOliver-Rainer Wittmann if ( mbShowSolidBorder ) 180*dec99bbdSOliver-Rainer Wittmann { 181*dec99bbdSOliver-Rainer Wittmann mbShowSolidBorder = false; 182*dec99bbdSOliver-Rainer Wittmann objectChange(); 183*dec99bbdSOliver-Rainer Wittmann } 184*dec99bbdSOliver-Rainer Wittmann } 185*dec99bbdSOliver-Rainer Wittmann 186*dec99bbdSOliver-Rainer Wittmann } // end of namespace overlay 187*dec99bbdSOliver-Rainer Wittmann } // end of namespace sdr 188*dec99bbdSOliver-Rainer Wittmann 189*dec99bbdSOliver-Rainer Wittmann ////////////////////////////////////////////////////////////////////////////// 190*dec99bbdSOliver-Rainer Wittmann // eof 191