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