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/overlaypolypolygon.hxx> 21 #include <svx/sdr/overlay/overlaymanager.hxx> 22 #include <drawinglayer/primitive2d/PolyPolygonMarkerPrimitive2D.hxx> 23 #include <drawinglayer/primitive2d/PolyPolygonSelectionPrimitive2D.hxx> 24 #include <drawinglayer/primitive2d/PolyPolygonStrokePrimitive2D.hxx> 25 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx> 26 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx> 27 28 29 namespace sdr::overlay 30 { OverlayPolyPolygon(const basegfx::B2DPolyPolygon & rLinePolyPolygon,Color const & rLineColor,double fLineWidth,Color const & rFillColor)31 OverlayPolyPolygon::OverlayPolyPolygon( 32 const basegfx::B2DPolyPolygon& rLinePolyPolygon, 33 Color const & rLineColor, 34 double fLineWidth, 35 Color const & rFillColor) 36 : OverlayObject(rLineColor) 37 , maLinePolyPolygon(rLinePolyPolygon) 38 , mfLineWidth(fLineWidth) 39 , maFillColor(rFillColor) 40 { 41 } 42 43 OverlayPolyPolygon::~OverlayPolyPolygon() = default; 44 createOverlayObjectPrimitive2DSequence()45 drawinglayer::primitive2d::Primitive2DContainer OverlayPolyPolygon::createOverlayObjectPrimitive2DSequence() 46 { 47 drawinglayer::primitive2d::Primitive2DContainer aReturnContainer; 48 49 if (getOverlayManager()) 50 { 51 const drawinglayer::attribute::LineAttribute aLineAttribute(getBaseColor().getBColor(), mfLineWidth); 52 53 aReturnContainer = drawinglayer::primitive2d::Primitive2DContainer { 54 new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D(maLinePolyPolygon, aLineAttribute) }; 55 56 if (maFillColor.GetAlpha() != 0) 57 { 58 aReturnContainer.push_back(new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(maLinePolyPolygon, maFillColor.getBColor())); 59 } 60 61 sal_uInt8 nTransparency = 255 - getBaseColor().GetAlpha(); 62 if (nTransparency > 0) 63 { 64 const drawinglayer::primitive2d::Primitive2DReference aTransparencePrimitive( 65 new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(aReturnContainer, nTransparency / 255.0)); 66 aReturnContainer = drawinglayer::primitive2d::Primitive2DContainer{ aTransparencePrimitive }; 67 } 68 } 69 70 return aReturnContainer; 71 } 72 createOverlayObjectPrimitive2DSequence()73 drawinglayer::primitive2d::Primitive2DContainer OverlayPolyPolygonStripedAndFilled::createOverlayObjectPrimitive2DSequence() 74 { 75 drawinglayer::primitive2d::Primitive2DContainer aRetval; 76 77 if(getOverlayManager()) 78 { 79 const basegfx::BColor aRGBColorA(getOverlayManager()->getStripeColorA().getBColor()); 80 const basegfx::BColor aRGBColorB(getOverlayManager()->getStripeColorB().getBColor()); 81 const double fStripeLengthPixel(getOverlayManager()->getStripeLengthPixel()); 82 const drawinglayer::primitive2d::Primitive2DReference aStriped( 83 new drawinglayer::primitive2d::PolyPolygonMarkerPrimitive2D( 84 getLinePolyPolygon(), 85 aRGBColorA, 86 aRGBColorB, 87 fStripeLengthPixel)); 88 89 aRetval = drawinglayer::primitive2d::Primitive2DContainer { aStriped }; 90 91 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer; 92 const basegfx::BColor aHilightColor(aSvtOptionsDrawinglayer.getHilightColor().getBColor()); 93 const double fTransparence(aSvtOptionsDrawinglayer.GetTransparentSelectionPercent() * 0.01); 94 95 const drawinglayer::primitive2d::Primitive2DReference aFilled( 96 new drawinglayer::primitive2d::PolyPolygonSelectionPrimitive2D( 97 getLinePolyPolygon(), 98 aHilightColor, 99 fTransparence, 100 3.0, 101 false)); 102 103 aRetval.push_back(aFilled); 104 } 105 106 return aRetval; 107 } 108 stripeDefinitionHasChanged()109 void OverlayPolyPolygonStripedAndFilled::stripeDefinitionHasChanged() 110 { 111 // react on OverlayManager's stripe definition change 112 objectChange(); 113 } 114 OverlayPolyPolygonStripedAndFilled(const basegfx::B2DPolyPolygon & rLinePolyPolygon)115 OverlayPolyPolygonStripedAndFilled::OverlayPolyPolygonStripedAndFilled( 116 const basegfx::B2DPolyPolygon& rLinePolyPolygon) 117 : OverlayObject(COL_BLACK), 118 maLinePolyPolygon(rLinePolyPolygon) 119 { 120 } 121 ~OverlayPolyPolygonStripedAndFilled()122 OverlayPolyPolygonStripedAndFilled::~OverlayPolyPolygonStripedAndFilled() 123 { 124 } 125 126 } // end of namespace 127 128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 129