xref: /AOO41X/main/cppcanvas/source/wrapper/implspritecanvas.cxx (revision 25b1114295101a2e8c55dab9e4c2ddcafdffc2eb)
1*25b11142SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*25b11142SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*25b11142SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*25b11142SAndrew Rist  * distributed with this work for additional information
6*25b11142SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*25b11142SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*25b11142SAndrew Rist  * "License"); you may not use this file except in compliance
9*25b11142SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*25b11142SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*25b11142SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*25b11142SAndrew Rist  * software distributed under the License is distributed on an
15*25b11142SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*25b11142SAndrew Rist  * KIND, either express or implied.  See the License for the
17*25b11142SAndrew Rist  * specific language governing permissions and limitations
18*25b11142SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*25b11142SAndrew Rist  *************************************************************/
21*25b11142SAndrew Rist 
22*25b11142SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_cppcanvas.hxx"
26cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
27cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
28cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
29cdf0e10cSrcweir #include <com/sun/star/rendering/InterpolationMode.hpp>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <implspritecanvas.hxx>
32cdf0e10cSrcweir #include <implcustomsprite.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace ::com::sun::star;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace cppcanvas
38cdf0e10cSrcweir {
39cdf0e10cSrcweir     namespace internal
40cdf0e10cSrcweir     {
TransformationArbiter()41cdf0e10cSrcweir         ImplSpriteCanvas::TransformationArbiter::TransformationArbiter() :
42cdf0e10cSrcweir             maTransformation()
43cdf0e10cSrcweir         {
44cdf0e10cSrcweir         }
45cdf0e10cSrcweir 
setTransformation(const::basegfx::B2DHomMatrix & rViewTransform)46cdf0e10cSrcweir         void ImplSpriteCanvas::TransformationArbiter::setTransformation( const ::basegfx::B2DHomMatrix& rViewTransform )
47cdf0e10cSrcweir         {
48cdf0e10cSrcweir             maTransformation = rViewTransform;
49cdf0e10cSrcweir         }
50cdf0e10cSrcweir 
getTransformation() const51cdf0e10cSrcweir         ::basegfx::B2DHomMatrix ImplSpriteCanvas::TransformationArbiter::getTransformation() const
52cdf0e10cSrcweir         {
53cdf0e10cSrcweir             return maTransformation;
54cdf0e10cSrcweir         }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 
ImplSpriteCanvas(const uno::Reference<rendering::XSpriteCanvas> & rCanvas)57cdf0e10cSrcweir         ImplSpriteCanvas::ImplSpriteCanvas( const uno::Reference< rendering::XSpriteCanvas >& rCanvas ) :
58cdf0e10cSrcweir             ImplCanvas( uno::Reference< rendering::XCanvas >(rCanvas,
59cdf0e10cSrcweir                                                              uno::UNO_QUERY) ),
60cdf0e10cSrcweir             ImplBitmapCanvas( uno::Reference< rendering::XBitmapCanvas >(rCanvas,
61cdf0e10cSrcweir                                                                          uno::UNO_QUERY) ),
62cdf0e10cSrcweir             mxSpriteCanvas( rCanvas ),
63cdf0e10cSrcweir             mpTransformArbiter( new TransformationArbiter() )
64cdf0e10cSrcweir         {
65cdf0e10cSrcweir             OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::ImplSpriteCanvas(): Invalid canvas" );
66cdf0e10cSrcweir         }
67cdf0e10cSrcweir 
ImplSpriteCanvas(const ImplSpriteCanvas & rOrig)68cdf0e10cSrcweir         ImplSpriteCanvas::ImplSpriteCanvas(const ImplSpriteCanvas& rOrig) :
69cdf0e10cSrcweir             Canvas(),
70cdf0e10cSrcweir             BitmapCanvas(),
71cdf0e10cSrcweir             SpriteCanvas(),
72cdf0e10cSrcweir             ImplCanvas( rOrig ),
73cdf0e10cSrcweir             ImplBitmapCanvas( rOrig ),
74cdf0e10cSrcweir             mxSpriteCanvas( rOrig.getUNOSpriteCanvas() ),
75cdf0e10cSrcweir             mpTransformArbiter( new TransformationArbiter() )
76cdf0e10cSrcweir         {
77cdf0e10cSrcweir             OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::ImplSpriteCanvas( const ImplSpriteCanvas& ): Invalid canvas" );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir             mpTransformArbiter->setTransformation( getTransformation() );
80cdf0e10cSrcweir         }
81cdf0e10cSrcweir 
~ImplSpriteCanvas()82cdf0e10cSrcweir         ImplSpriteCanvas::~ImplSpriteCanvas()
83cdf0e10cSrcweir         {
84cdf0e10cSrcweir         }
85cdf0e10cSrcweir 
setTransformation(const::basegfx::B2DHomMatrix & rMatrix)86cdf0e10cSrcweir         void ImplSpriteCanvas::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix )
87cdf0e10cSrcweir         {
88cdf0e10cSrcweir             mpTransformArbiter->setTransformation( rMatrix );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir             ImplCanvas::setTransformation( rMatrix );
91cdf0e10cSrcweir         }
92cdf0e10cSrcweir 
updateScreen(bool bUpdateAll) const93cdf0e10cSrcweir         bool ImplSpriteCanvas::updateScreen( bool bUpdateAll ) const
94cdf0e10cSrcweir         {
95cdf0e10cSrcweir             OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::updateScreen(): Invalid canvas" );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir             if( !mxSpriteCanvas.is() )
98cdf0e10cSrcweir                 return false;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir             return mxSpriteCanvas->updateScreen( bUpdateAll );
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir 
createCustomSprite(const::basegfx::B2DSize & rSize) const103cdf0e10cSrcweir         CustomSpriteSharedPtr ImplSpriteCanvas::createCustomSprite( const ::basegfx::B2DSize& rSize ) const
104cdf0e10cSrcweir         {
105cdf0e10cSrcweir             OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::createCustomSprite(): Invalid canvas" );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir             if( !mxSpriteCanvas.is() )
108cdf0e10cSrcweir                 return CustomSpriteSharedPtr();
109cdf0e10cSrcweir 
110cdf0e10cSrcweir             return CustomSpriteSharedPtr(
111cdf0e10cSrcweir                 new ImplCustomSprite( mxSpriteCanvas,
112cdf0e10cSrcweir                                       mxSpriteCanvas->createCustomSprite( ::basegfx::unotools::size2DFromB2DSize(rSize) ),
113cdf0e10cSrcweir                                       mpTransformArbiter ) );
114cdf0e10cSrcweir         }
115cdf0e10cSrcweir 
createClonedSprite(const SpriteSharedPtr & rSprite) const116cdf0e10cSrcweir         SpriteSharedPtr ImplSpriteCanvas::createClonedSprite( const SpriteSharedPtr& rSprite ) const
117cdf0e10cSrcweir         {
118cdf0e10cSrcweir             OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::createCustomSprite(): Invalid canvas" );
119cdf0e10cSrcweir             OSL_ENSURE( rSprite.get() != NULL && rSprite->getUNOSprite().is(),
120cdf0e10cSrcweir                         "ImplSpriteCanvas::createCustomSprite(): Invalid sprite" );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir             if( !mxSpriteCanvas.is() ||
123cdf0e10cSrcweir                 rSprite.get() == NULL ||
124cdf0e10cSrcweir                 !rSprite->getUNOSprite().is() )
125cdf0e10cSrcweir             {
126cdf0e10cSrcweir                 return SpriteSharedPtr();
127cdf0e10cSrcweir             }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir             return SpriteSharedPtr(
130cdf0e10cSrcweir                 new ImplSprite( mxSpriteCanvas,
131cdf0e10cSrcweir                                 mxSpriteCanvas->createClonedSprite( rSprite->getUNOSprite() ),
132cdf0e10cSrcweir                                 mpTransformArbiter ) );
133cdf0e10cSrcweir         }
134cdf0e10cSrcweir 
createSpriteFromBitmaps(const uno::Sequence<uno::Reference<rendering::XBitmap>> & rAnimationBitmaps,sal_Int8 nInterpolationMode)135cdf0e10cSrcweir         SpriteSharedPtr ImplSpriteCanvas::createSpriteFromBitmaps( const uno::Sequence< uno::Reference< rendering::XBitmap > >& rAnimationBitmaps,
136cdf0e10cSrcweir                                                                    sal_Int8 													nInterpolationMode )
137cdf0e10cSrcweir         {
138cdf0e10cSrcweir             return SpriteSharedPtr( new internal::ImplSprite( mxSpriteCanvas,
139cdf0e10cSrcweir                                                               mxSpriteCanvas->createSpriteFromBitmaps( rAnimationBitmaps,
140cdf0e10cSrcweir                                                                                                        nInterpolationMode ),
141cdf0e10cSrcweir                                                               mpTransformArbiter ) );
142cdf0e10cSrcweir         }
143cdf0e10cSrcweir 
clone() const144cdf0e10cSrcweir         CanvasSharedPtr ImplSpriteCanvas::clone() const
145cdf0e10cSrcweir         {
146cdf0e10cSrcweir             return SpriteCanvasSharedPtr( new ImplSpriteCanvas( *this ) );
147cdf0e10cSrcweir         }
148cdf0e10cSrcweir 
getUNOSpriteCanvas() const149cdf0e10cSrcweir         uno::Reference< rendering::XSpriteCanvas > ImplSpriteCanvas::getUNOSpriteCanvas() const
150cdf0e10cSrcweir         {
151cdf0e10cSrcweir             return mxSpriteCanvas;
152cdf0e10cSrcweir         }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir }
156