xref: /AOO41X/main/drawinglayer/source/primitive2d/backgroundcolorprimitive2d.cxx (revision 464702f4578bd67db020a330afd07883930c5e07)
1*464702f4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*464702f4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*464702f4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*464702f4SAndrew Rist  * distributed with this work for additional information
6*464702f4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*464702f4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*464702f4SAndrew Rist  * "License"); you may not use this file except in compliance
9*464702f4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*464702f4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*464702f4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*464702f4SAndrew Rist  * software distributed under the License is distributed on an
15*464702f4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*464702f4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*464702f4SAndrew Rist  * specific language governing permissions and limitations
18*464702f4SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*464702f4SAndrew Rist  *************************************************************/
21*464702f4SAndrew Rist 
22*464702f4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <drawinglayer/primitive2d/backgroundcolorprimitive2d.hxx>
28cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
29cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
30cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
31cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
32cdf0e10cSrcweir #include <drawinglayer/geometry/viewinformation2d.hxx>
33cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace com::sun::star;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace drawinglayer
42cdf0e10cSrcweir {
43cdf0e10cSrcweir 	namespace primitive2d
44cdf0e10cSrcweir 	{
create2DDecomposition(const geometry::ViewInformation2D & rViewInformation) const45cdf0e10cSrcweir 		Primitive2DSequence BackgroundColorPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
46cdf0e10cSrcweir 		{
47cdf0e10cSrcweir 			if(!rViewInformation.getViewport().isEmpty())
48cdf0e10cSrcweir 			{
49cdf0e10cSrcweir 				const basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(rViewInformation.getViewport()));
50cdf0e10cSrcweir 				const Primitive2DReference xRef(new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aOutline), getBColor()));
51cdf0e10cSrcweir 				return Primitive2DSequence(&xRef, 1L);
52cdf0e10cSrcweir 			}
53cdf0e10cSrcweir 			else
54cdf0e10cSrcweir 			{
55cdf0e10cSrcweir 				return Primitive2DSequence();
56cdf0e10cSrcweir 			}
57cdf0e10cSrcweir 		}
58cdf0e10cSrcweir 
BackgroundColorPrimitive2D(const basegfx::BColor & rBColor)59cdf0e10cSrcweir 		BackgroundColorPrimitive2D::BackgroundColorPrimitive2D(
60cdf0e10cSrcweir 			const basegfx::BColor& rBColor)
61cdf0e10cSrcweir 		:	BufferedDecompositionPrimitive2D(),
62cdf0e10cSrcweir 			maBColor(rBColor),
63cdf0e10cSrcweir 			maLastViewport()
64cdf0e10cSrcweir 		{
65cdf0e10cSrcweir 		}
66cdf0e10cSrcweir 
operator ==(const BasePrimitive2D & rPrimitive) const67cdf0e10cSrcweir 		bool BackgroundColorPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
68cdf0e10cSrcweir 		{
69cdf0e10cSrcweir 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
70cdf0e10cSrcweir 			{
71cdf0e10cSrcweir 				const BackgroundColorPrimitive2D& rCompare = (BackgroundColorPrimitive2D&)rPrimitive;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 				return (getBColor() == rCompare.getBColor());
74cdf0e10cSrcweir 			}
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 			return false;
77cdf0e10cSrcweir 		}
78cdf0e10cSrcweir 
getB2DRange(const geometry::ViewInformation2D & rViewInformation) const79cdf0e10cSrcweir 		basegfx::B2DRange BackgroundColorPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
80cdf0e10cSrcweir 		{
81cdf0e10cSrcweir 			// always as big as the view
82cdf0e10cSrcweir 			return rViewInformation.getViewport();
83cdf0e10cSrcweir 		}
84cdf0e10cSrcweir 
get2DDecomposition(const geometry::ViewInformation2D & rViewInformation) const85cdf0e10cSrcweir 		Primitive2DSequence BackgroundColorPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
86cdf0e10cSrcweir 		{
87cdf0e10cSrcweir 			::osl::MutexGuard aGuard( m_aMutex );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 			if(getBuffered2DDecomposition().hasElements() && (maLastViewport != rViewInformation.getViewport()))
90cdf0e10cSrcweir 			{
91cdf0e10cSrcweir 				// conditions of last local decomposition have changed, delete
92cdf0e10cSrcweir 				const_cast< BackgroundColorPrimitive2D* >(this)->setBuffered2DDecomposition(Primitive2DSequence());
93cdf0e10cSrcweir 			}
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 			if(!getBuffered2DDecomposition().hasElements())
96cdf0e10cSrcweir 			{
97cdf0e10cSrcweir 				// remember ViewRange
98cdf0e10cSrcweir 				const_cast< BackgroundColorPrimitive2D* >(this)->maLastViewport = rViewInformation.getViewport();
99cdf0e10cSrcweir 			}
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 			// use parent implementation
102cdf0e10cSrcweir 			return BufferedDecompositionPrimitive2D::get2DDecomposition(rViewInformation);
103cdf0e10cSrcweir 		}
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 		// provide unique ID
106cdf0e10cSrcweir 		ImplPrimitrive2DIDBlock(BackgroundColorPrimitive2D, PRIMITIVE2D_ID_BACKGROUNDCOLORPRIMITIVE2D)
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	} // end of namespace primitive2d
109cdf0e10cSrcweir } // end of namespace drawinglayer
110cdf0e10cSrcweir 
111cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
112cdf0e10cSrcweir // eof
113