1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <drawinglayer/primitive2d/backgroundcolorprimitive2d.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
23 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
24 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
25 #include <drawinglayer/geometry/viewinformation2d.hxx>
26 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
29 using namespace com::sun::star
;
32 namespace drawinglayer::primitive2d
34 void BackgroundColorPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& rViewInformation
) const
36 // transparency invalid or completely transparent, done
37 if(getTransparency() < 0.0 || getTransparency() >= 1.0)
40 // no viewport, not visible, done
41 if(rViewInformation
.getViewport().isEmpty())
44 // create decompose geometry
45 const basegfx::B2DPolygon
aOutline(basegfx::utils::createPolygonFromRect(rViewInformation
.getViewport()));
46 Primitive2DReference
aDecompose(new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aOutline
), getBColor()));
48 if(getTransparency() != 0.0)
50 // if used, embed decompose geometry to unified transparency
51 Primitive2DContainer aContent
{ aDecompose
};
52 aDecompose
= Primitive2DReference(
53 new UnifiedTransparencePrimitive2D(
58 rContainer
.push_back(aDecompose
);
61 BackgroundColorPrimitive2D::BackgroundColorPrimitive2D(
62 const basegfx::BColor
& rBColor
,
65 mfTransparency(fTransparency
)
69 bool BackgroundColorPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
71 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
73 const BackgroundColorPrimitive2D
& rCompare
= static_cast<const BackgroundColorPrimitive2D
&>(rPrimitive
);
75 return (getBColor() == rCompare
.getBColor() && getTransparency() == rCompare
.getTransparency());
81 basegfx::B2DRange
BackgroundColorPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& rViewInformation
) const
83 // always as big as the view
84 return rViewInformation
.getViewport();
87 void BackgroundColorPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& rVisitor
, const geometry::ViewInformation2D
& rViewInformation
) const
89 if(!getBuffered2DDecomposition().empty() && (maLastViewport
!= rViewInformation
.getViewport()))
91 // conditions of last local decomposition have changed, delete
92 const_cast< BackgroundColorPrimitive2D
* >(this)->setBuffered2DDecomposition(Primitive2DContainer());
95 if(getBuffered2DDecomposition().empty())
98 const_cast< BackgroundColorPrimitive2D
* >(this)->maLastViewport
= rViewInformation
.getViewport();
101 // use parent implementation
102 BufferedDecompositionPrimitive2D::get2DDecomposition(rVisitor
, rViewInformation
);
106 sal_uInt32
BackgroundColorPrimitive2D::getPrimitive2DID() const
108 return PRIMITIVE2D_ID_BACKGROUNDCOLORPRIMITIVE2D
;
111 } // end of namespace
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */