191c99ff4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
391c99ff4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
491c99ff4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
591c99ff4SAndrew Rist  * distributed with this work for additional information
691c99ff4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
791c99ff4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
891c99ff4SAndrew Rist  * "License"); you may not use this file except in compliance
991c99ff4SAndrew Rist  * with the License.  You may obtain a copy of the License at
1091c99ff4SAndrew Rist  *
1191c99ff4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1291c99ff4SAndrew Rist  *
1391c99ff4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1491c99ff4SAndrew Rist  * software distributed under the License is distributed on an
1591c99ff4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1691c99ff4SAndrew Rist  * KIND, either express or implied.  See the License for the
1791c99ff4SAndrew Rist  * specific language governing permissions and limitations
1891c99ff4SAndrew Rist  * under the License.
1991c99ff4SAndrew Rist  *
2091c99ff4SAndrew Rist  *************************************************************/
2191c99ff4SAndrew Rist 
2291c99ff4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_CANVAS_SPRITECANVASBASE_HXX
25cdf0e10cSrcweir #define INCLUDED_CANVAS_SPRITECANVASBASE_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <rtl/ref.hxx>
28cdf0e10cSrcweir #include <com/sun/star/rendering/XSpriteCanvas.hpp>
29cdf0e10cSrcweir #include <com/sun/star/rendering/InterpolationMode.hpp>
30cdf0e10cSrcweir #include <canvas/base/integerbitmapbase.hxx>
31cdf0e10cSrcweir #include <canvas/spriteredrawmanager.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace canvas
35cdf0e10cSrcweir {
36cdf0e10cSrcweir     /** Helper template to handle XIntegerBitmap method forwarding to
37cdf0e10cSrcweir         BitmapCanvasHelper
38cdf0e10cSrcweir 
39cdf0e10cSrcweir     	Use this helper to handle the XIntegerBitmap part of your
40cdf0e10cSrcweir     	implementation.
41cdf0e10cSrcweir 
42cdf0e10cSrcweir         @tpl Base
43cdf0e10cSrcweir         Base class to use, most probably one of the
44cdf0e10cSrcweir         WeakComponentImplHelperN templates with the appropriate
45cdf0e10cSrcweir         interfaces. At least XSpriteCanvas and SpriteSurface should be
46cdf0e10cSrcweir         among them (why else would you use this template, then?). Base
47cdf0e10cSrcweir         class must have an Base( const Mutex& ) constructor (like the
48cdf0e10cSrcweir         WeakComponentImplHelperN templates have).
49cdf0e10cSrcweir 
50cdf0e10cSrcweir         @tpl CanvasHelper
51cdf0e10cSrcweir         Canvas helper implementation for the backend in question
52cdf0e10cSrcweir 
53cdf0e10cSrcweir         @tpl Mutex
54cdf0e10cSrcweir         Lock strategy to use. Defaults to using the
55*07a3d7f1SPedro Giffuni         OBaseMutex-provided lock.  Every time one of the methods is
56cdf0e10cSrcweir         entered, an object of type Mutex is created with m_aMutex as
57cdf0e10cSrcweir         the sole parameter, and destroyed again when the method scope
58cdf0e10cSrcweir         is left.
59cdf0e10cSrcweir 
60cdf0e10cSrcweir         @tpl UnambiguousBase
61cdf0e10cSrcweir         Optional unambiguous base class for XInterface of Base. It's
62cdf0e10cSrcweir         sometimes necessary to specify this parameter, e.g. if Base
63cdf0e10cSrcweir         derives from multiple UNO interface (were each provides its
64cdf0e10cSrcweir         own version of XInterface, making the conversion ambiguous)
65cdf0e10cSrcweir 
66cdf0e10cSrcweir         @see CanvasBase for further contractual requirements towards
67cdf0e10cSrcweir         the CanvasHelper type, and some examples.
68cdf0e10cSrcweir      */
69cdf0e10cSrcweir     template< class Base,
70cdf0e10cSrcweir               class CanvasHelper,
71cdf0e10cSrcweir               class Mutex=::osl::MutexGuard,
72cdf0e10cSrcweir               class UnambiguousBase=::com::sun::star::uno::XInterface > class SpriteCanvasBase :
73cdf0e10cSrcweir         public IntegerBitmapBase< Base, CanvasHelper, Mutex, UnambiguousBase >
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir     public:
76cdf0e10cSrcweir         typedef IntegerBitmapBase< Base, CanvasHelper, Mutex, UnambiguousBase >	BaseType;
77cdf0e10cSrcweir         typedef ::rtl::Reference< SpriteCanvasBase > 							Reference;
78cdf0e10cSrcweir 
SpriteCanvasBase()79cdf0e10cSrcweir         SpriteCanvasBase() :
80cdf0e10cSrcweir             maRedrawManager()
81cdf0e10cSrcweir         {
82cdf0e10cSrcweir         }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir #if defined __SUNPRO_CC
85cdf0e10cSrcweir         using Base::disposing;
86cdf0e10cSrcweir #endif
disposing()87cdf0e10cSrcweir         virtual void SAL_CALL disposing()
88cdf0e10cSrcweir         {
89cdf0e10cSrcweir             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
90cdf0e10cSrcweir 
91cdf0e10cSrcweir             maRedrawManager.disposing();
92cdf0e10cSrcweir 
93cdf0e10cSrcweir             // pass on to base class
94cdf0e10cSrcweir             BaseType::disposing();
95cdf0e10cSrcweir         }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         // XSpriteCanvas
createSpriteFromAnimation(const::com::sun::star::uno::Reference<::com::sun::star::rendering::XAnimation> & animation)98cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XAnimatedSprite > SAL_CALL createSpriteFromAnimation( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XAnimation >& animation ) throw (::com::sun::star::lang::IllegalArgumentException,
99cdf0e10cSrcweir                                                                                                                                                                                                                                            ::com::sun::star::uno::RuntimeException)
100cdf0e10cSrcweir         {
101cdf0e10cSrcweir             tools::verifyArgs(animation,
102cdf0e10cSrcweir                               BOOST_CURRENT_FUNCTION,
103cdf0e10cSrcweir                               static_cast< typename BaseType::UnambiguousBaseType* >(this));
104cdf0e10cSrcweir 
105cdf0e10cSrcweir             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir             return BaseType::maCanvasHelper.createSpriteFromAnimation(animation);
108cdf0e10cSrcweir         }
109cdf0e10cSrcweir 
createSpriteFromBitmaps(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Reference<::com::sun::star::rendering::XBitmap>> & animationBitmaps,sal_Int8 interpolationMode)110cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XAnimatedSprite > SAL_CALL createSpriteFromBitmaps( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > >& animationBitmaps,
111cdf0e10cSrcweir                                                                                                                                    sal_Int8                                                                                                           interpolationMode ) throw (::com::sun::star::lang::IllegalArgumentException,
112cdf0e10cSrcweir                                                                                                                                                                                                                                                                                  ::com::sun::star::rendering::VolatileContentDestroyedException,
113cdf0e10cSrcweir                                                                                                                                                                                                                                                                                  ::com::sun::star::uno::RuntimeException)
114cdf0e10cSrcweir         {
115cdf0e10cSrcweir             tools::verifyArgs(animationBitmaps,
116cdf0e10cSrcweir                               BOOST_CURRENT_FUNCTION,
117cdf0e10cSrcweir                               static_cast< typename BaseType::UnambiguousBaseType* >(this));
118cdf0e10cSrcweir             tools::verifyRange( interpolationMode,
119cdf0e10cSrcweir                                 ::com::sun::star::rendering::InterpolationMode::NEAREST_NEIGHBOR,
120cdf0e10cSrcweir                                 ::com::sun::star::rendering::InterpolationMode::BEZIERSPLINE4 );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir             return BaseType::maCanvasHelper.createSpriteFromBitmaps(animationBitmaps, interpolationMode);
125cdf0e10cSrcweir         }
126cdf0e10cSrcweir 
createCustomSprite(const::com::sun::star::geometry::RealSize2D & spriteSize)127cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCustomSprite > SAL_CALL createCustomSprite( const ::com::sun::star::geometry::RealSize2D& spriteSize ) throw (::com::sun::star::lang::IllegalArgumentException,
128cdf0e10cSrcweir                                                                                                                                                                                               ::com::sun::star::uno::RuntimeException)
129cdf0e10cSrcweir         {
130cdf0e10cSrcweir             tools::verifySpriteSize(spriteSize,
131cdf0e10cSrcweir                                     BOOST_CURRENT_FUNCTION,
132cdf0e10cSrcweir                                     static_cast< typename BaseType::UnambiguousBaseType* >(this));
133cdf0e10cSrcweir 
134cdf0e10cSrcweir             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
135cdf0e10cSrcweir 
136cdf0e10cSrcweir             return BaseType::maCanvasHelper.createCustomSprite(spriteSize);
137cdf0e10cSrcweir         }
138cdf0e10cSrcweir 
createClonedSprite(const::com::sun::star::uno::Reference<::com::sun::star::rendering::XSprite> & original)139cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XSprite > SAL_CALL createClonedSprite( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XSprite >& original ) throw (::com::sun::star::lang::IllegalArgumentException,
140cdf0e10cSrcweir                                                                                                                                                                                                                         ::com::sun::star::uno::RuntimeException)
141cdf0e10cSrcweir         {
142cdf0e10cSrcweir             tools::verifyArgs(original,
143cdf0e10cSrcweir                               BOOST_CURRENT_FUNCTION,
144cdf0e10cSrcweir                               static_cast< typename BaseType::UnambiguousBaseType* >(this));
145cdf0e10cSrcweir 
146cdf0e10cSrcweir             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir             return BaseType::maCanvasHelper.createClonedSprite(original);
149cdf0e10cSrcweir         }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir         // SpriteSurface
showSprite(const Sprite::Reference & rSprite)152cdf0e10cSrcweir         virtual void showSprite( const Sprite::Reference& rSprite )
153cdf0e10cSrcweir         {
154cdf0e10cSrcweir             OSL_ASSERT( rSprite.is() );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir             maRedrawManager.showSprite( rSprite );
159cdf0e10cSrcweir         }
160cdf0e10cSrcweir 
hideSprite(const Sprite::Reference & rSprite)161cdf0e10cSrcweir         virtual void hideSprite( const Sprite::Reference& rSprite )
162cdf0e10cSrcweir         {
163cdf0e10cSrcweir             OSL_ASSERT( rSprite.is() );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
166cdf0e10cSrcweir 
167cdf0e10cSrcweir             maRedrawManager.hideSprite( rSprite );
168cdf0e10cSrcweir         }
169cdf0e10cSrcweir 
moveSprite(const Sprite::Reference & rSprite,const::basegfx::B2DPoint & rOldPos,const::basegfx::B2DPoint & rNewPos,const::basegfx::B2DVector & rSpriteSize)170cdf0e10cSrcweir         virtual void moveSprite( const Sprite::Reference&		rSprite,
171cdf0e10cSrcweir                                  const ::basegfx::B2DPoint& 	rOldPos,
172cdf0e10cSrcweir                                  const ::basegfx::B2DPoint&		rNewPos,
173cdf0e10cSrcweir                                  const ::basegfx::B2DVector& 	rSpriteSize )
174cdf0e10cSrcweir         {
175cdf0e10cSrcweir             OSL_ASSERT( rSprite.is() );
176cdf0e10cSrcweir 
177cdf0e10cSrcweir             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir             maRedrawManager.moveSprite( rSprite, rOldPos, rNewPos, rSpriteSize );
180cdf0e10cSrcweir         }
181cdf0e10cSrcweir 
updateSprite(const Sprite::Reference & rSprite,const::basegfx::B2DPoint & rPos,const::basegfx::B2DRange & rUpdateArea)182cdf0e10cSrcweir         virtual void updateSprite( const Sprite::Reference& 	rSprite,
183cdf0e10cSrcweir                                    const ::basegfx::B2DPoint& 	rPos,
184cdf0e10cSrcweir                                    const ::basegfx::B2DRange&	rUpdateArea )
185cdf0e10cSrcweir         {
186cdf0e10cSrcweir             OSL_ASSERT( rSprite.is() );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
189cdf0e10cSrcweir 
190cdf0e10cSrcweir             maRedrawManager.updateSprite( rSprite, rPos, rUpdateArea );
191cdf0e10cSrcweir         }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     protected:
194cdf0e10cSrcweir         SpriteRedrawManager maRedrawManager;
195cdf0e10cSrcweir     };
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir #endif /* INCLUDED_CANVAS_SPRITECANVASBASE_HXX */
199