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_cppcanvas.hxx" 26 #include <basegfx/matrix/b2dhommatrix.hxx> 27 #include <basegfx/tools/canvastools.hxx> 28 #include <basegfx/polygon/b2dpolypolygon.hxx> 29 #include <com/sun/star/rendering/InterpolationMode.hpp> 30 31 #include <implspritecanvas.hxx> 32 #include <implcustomsprite.hxx> 33 34 35 using namespace ::com::sun::star; 36 37 namespace cppcanvas 38 { 39 namespace internal 40 { TransformationArbiter()41 ImplSpriteCanvas::TransformationArbiter::TransformationArbiter() : 42 maTransformation() 43 { 44 } 45 setTransformation(const::basegfx::B2DHomMatrix & rViewTransform)46 void ImplSpriteCanvas::TransformationArbiter::setTransformation( const ::basegfx::B2DHomMatrix& rViewTransform ) 47 { 48 maTransformation = rViewTransform; 49 } 50 getTransformation() const51 ::basegfx::B2DHomMatrix ImplSpriteCanvas::TransformationArbiter::getTransformation() const 52 { 53 return maTransformation; 54 } 55 56 ImplSpriteCanvas(const uno::Reference<rendering::XSpriteCanvas> & rCanvas)57 ImplSpriteCanvas::ImplSpriteCanvas( const uno::Reference< rendering::XSpriteCanvas >& rCanvas ) : 58 ImplCanvas( uno::Reference< rendering::XCanvas >(rCanvas, 59 uno::UNO_QUERY) ), 60 ImplBitmapCanvas( uno::Reference< rendering::XBitmapCanvas >(rCanvas, 61 uno::UNO_QUERY) ), 62 mxSpriteCanvas( rCanvas ), 63 mpTransformArbiter( new TransformationArbiter() ) 64 { 65 OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::ImplSpriteCanvas(): Invalid canvas" ); 66 } 67 ImplSpriteCanvas(const ImplSpriteCanvas & rOrig)68 ImplSpriteCanvas::ImplSpriteCanvas(const ImplSpriteCanvas& rOrig) : 69 Canvas(), 70 BitmapCanvas(), 71 SpriteCanvas(), 72 ImplCanvas( rOrig ), 73 ImplBitmapCanvas( rOrig ), 74 mxSpriteCanvas( rOrig.getUNOSpriteCanvas() ), 75 mpTransformArbiter( new TransformationArbiter() ) 76 { 77 OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::ImplSpriteCanvas( const ImplSpriteCanvas& ): Invalid canvas" ); 78 79 mpTransformArbiter->setTransformation( getTransformation() ); 80 } 81 ~ImplSpriteCanvas()82 ImplSpriteCanvas::~ImplSpriteCanvas() 83 { 84 } 85 setTransformation(const::basegfx::B2DHomMatrix & rMatrix)86 void ImplSpriteCanvas::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix ) 87 { 88 mpTransformArbiter->setTransformation( rMatrix ); 89 90 ImplCanvas::setTransformation( rMatrix ); 91 } 92 updateScreen(bool bUpdateAll) const93 bool ImplSpriteCanvas::updateScreen( bool bUpdateAll ) const 94 { 95 OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::updateScreen(): Invalid canvas" ); 96 97 if( !mxSpriteCanvas.is() ) 98 return false; 99 100 return mxSpriteCanvas->updateScreen( bUpdateAll ); 101 } 102 createCustomSprite(const::basegfx::B2DSize & rSize) const103 CustomSpriteSharedPtr ImplSpriteCanvas::createCustomSprite( const ::basegfx::B2DSize& rSize ) const 104 { 105 OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::createCustomSprite(): Invalid canvas" ); 106 107 if( !mxSpriteCanvas.is() ) 108 return CustomSpriteSharedPtr(); 109 110 return CustomSpriteSharedPtr( 111 new ImplCustomSprite( mxSpriteCanvas, 112 mxSpriteCanvas->createCustomSprite( ::basegfx::unotools::size2DFromB2DSize(rSize) ), 113 mpTransformArbiter ) ); 114 } 115 createClonedSprite(const SpriteSharedPtr & rSprite) const116 SpriteSharedPtr ImplSpriteCanvas::createClonedSprite( const SpriteSharedPtr& rSprite ) const 117 { 118 OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::createCustomSprite(): Invalid canvas" ); 119 OSL_ENSURE( rSprite.get() != NULL && rSprite->getUNOSprite().is(), 120 "ImplSpriteCanvas::createCustomSprite(): Invalid sprite" ); 121 122 if( !mxSpriteCanvas.is() || 123 rSprite.get() == NULL || 124 !rSprite->getUNOSprite().is() ) 125 { 126 return SpriteSharedPtr(); 127 } 128 129 return SpriteSharedPtr( 130 new ImplSprite( mxSpriteCanvas, 131 mxSpriteCanvas->createClonedSprite( rSprite->getUNOSprite() ), 132 mpTransformArbiter ) ); 133 } 134 createSpriteFromBitmaps(const uno::Sequence<uno::Reference<rendering::XBitmap>> & rAnimationBitmaps,sal_Int8 nInterpolationMode)135 SpriteSharedPtr ImplSpriteCanvas::createSpriteFromBitmaps( const uno::Sequence< uno::Reference< rendering::XBitmap > >& rAnimationBitmaps, 136 sal_Int8 nInterpolationMode ) 137 { 138 return SpriteSharedPtr( new internal::ImplSprite( mxSpriteCanvas, 139 mxSpriteCanvas->createSpriteFromBitmaps( rAnimationBitmaps, 140 nInterpolationMode ), 141 mpTransformArbiter ) ); 142 } 143 clone() const144 CanvasSharedPtr ImplSpriteCanvas::clone() const 145 { 146 return SpriteCanvasSharedPtr( new ImplSpriteCanvas( *this ) ); 147 } 148 getUNOSpriteCanvas() const149 uno::Reference< rendering::XSpriteCanvas > ImplSpriteCanvas::getUNOSpriteCanvas() const 150 { 151 return mxSpriteCanvas; 152 } 153 154 } 155 } 156