xref: /trunk/main/canvas/inc/canvas/base/spritecanvasbase.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 #ifndef INCLUDED_CANVAS_SPRITECANVASBASE_HXX
25 #define INCLUDED_CANVAS_SPRITECANVASBASE_HXX
26 
27 #include <rtl/ref.hxx>
28 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
29 #include <com/sun/star/rendering/InterpolationMode.hpp>
30 #include <canvas/base/integerbitmapbase.hxx>
31 #include <canvas/spriteredrawmanager.hxx>
32 
33 
34 namespace canvas
35 {
36     /** Helper template to handle XIntegerBitmap method forwarding to
37         BitmapCanvasHelper
38 
39         Use this helper to handle the XIntegerBitmap part of your
40         implementation.
41 
42         @tpl Base
43         Base class to use, most probably one of the
44         WeakComponentImplHelperN templates with the appropriate
45         interfaces. At least XSpriteCanvas and SpriteSurface should be
46         among them (why else would you use this template, then?). Base
47         class must have an Base( const Mutex& ) constructor (like the
48         WeakComponentImplHelperN templates have).
49 
50         @tpl CanvasHelper
51         Canvas helper implementation for the backend in question
52 
53         @tpl Mutex
54         Lock strategy to use. Defaults to using the
55         OBaseMutex-provided lock.  Every time one of the methods is
56         entered, an object of type Mutex is created with m_aMutex as
57         the sole parameter, and destroyed again when the method scope
58         is left.
59 
60         @tpl UnambiguousBase
61         Optional unambiguous base class for XInterface of Base. It's
62         sometimes necessary to specify this parameter, e.g. if Base
63         derives from multiple UNO interface (were each provides its
64         own version of XInterface, making the conversion ambiguous)
65 
66         @see CanvasBase for further contractual requirements towards
67         the CanvasHelper type, and some examples.
68      */
69     template< class Base,
70               class CanvasHelper,
71               class Mutex=::osl::MutexGuard,
72               class UnambiguousBase=::com::sun::star::uno::XInterface > class SpriteCanvasBase :
73         public IntegerBitmapBase< Base, CanvasHelper, Mutex, UnambiguousBase >
74     {
75     public:
76         typedef IntegerBitmapBase< Base, CanvasHelper, Mutex, UnambiguousBase > BaseType;
77         typedef ::rtl::Reference< SpriteCanvasBase >                            Reference;
78 
SpriteCanvasBase()79         SpriteCanvasBase() :
80             maRedrawManager()
81         {
82         }
83 
84 #if defined __SUNPRO_CC
85         using Base::disposing;
86 #endif
disposing()87         virtual void SAL_CALL disposing()
88         {
89             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
90 
91             maRedrawManager.disposing();
92 
93             // pass on to base class
94             BaseType::disposing();
95         }
96 
97         // XSpriteCanvas
createSpriteFromAnimation(const::com::sun::star::uno::Reference<::com::sun::star::rendering::XAnimation> & animation)98         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 )
99         {
100             tools::verifyArgs(animation,
101                               BOOST_CURRENT_FUNCTION,
102                               static_cast< typename BaseType::UnambiguousBaseType* >(this));
103 
104             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
105 
106             return BaseType::maCanvasHelper.createSpriteFromAnimation(animation);
107         }
108 
createSpriteFromBitmaps(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Reference<::com::sun::star::rendering::XBitmap>> & animationBitmaps,sal_Int8 interpolationMode)109         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,
110                                                                                                                                    sal_Int8                                                                                                           interpolationMode )
111         {
112             tools::verifyArgs(animationBitmaps,
113                               BOOST_CURRENT_FUNCTION,
114                               static_cast< typename BaseType::UnambiguousBaseType* >(this));
115             tools::verifyRange( interpolationMode,
116                                 ::com::sun::star::rendering::InterpolationMode::NEAREST_NEIGHBOR,
117                                 ::com::sun::star::rendering::InterpolationMode::BEZIERSPLINE4 );
118 
119             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
120 
121             return BaseType::maCanvasHelper.createSpriteFromBitmaps(animationBitmaps, interpolationMode);
122         }
123 
createCustomSprite(const::com::sun::star::geometry::RealSize2D & spriteSize)124         virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCustomSprite > SAL_CALL createCustomSprite( const ::com::sun::star::geometry::RealSize2D& spriteSize )
125         {
126             tools::verifySpriteSize(spriteSize,
127                                     BOOST_CURRENT_FUNCTION,
128                                     static_cast< typename BaseType::UnambiguousBaseType* >(this));
129 
130             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
131 
132             return BaseType::maCanvasHelper.createCustomSprite(spriteSize);
133         }
134 
createClonedSprite(const::com::sun::star::uno::Reference<::com::sun::star::rendering::XSprite> & original)135         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 )
136         {
137             tools::verifyArgs(original,
138                               BOOST_CURRENT_FUNCTION,
139                               static_cast< typename BaseType::UnambiguousBaseType* >(this));
140 
141             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
142 
143             return BaseType::maCanvasHelper.createClonedSprite(original);
144         }
145 
146         // SpriteSurface
showSprite(const Sprite::Reference & rSprite)147         virtual void showSprite( const Sprite::Reference& rSprite )
148         {
149             OSL_ASSERT( rSprite.is() );
150 
151             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
152 
153             maRedrawManager.showSprite( rSprite );
154         }
155 
hideSprite(const Sprite::Reference & rSprite)156         virtual void hideSprite( const Sprite::Reference& rSprite )
157         {
158             OSL_ASSERT( rSprite.is() );
159 
160             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
161 
162             maRedrawManager.hideSprite( rSprite );
163         }
164 
moveSprite(const Sprite::Reference & rSprite,const::basegfx::B2DPoint & rOldPos,const::basegfx::B2DPoint & rNewPos,const::basegfx::B2DVector & rSpriteSize)165         virtual void moveSprite( const Sprite::Reference&       rSprite,
166                                  const ::basegfx::B2DPoint&     rOldPos,
167                                  const ::basegfx::B2DPoint&     rNewPos,
168                                  const ::basegfx::B2DVector&    rSpriteSize )
169         {
170             OSL_ASSERT( rSprite.is() );
171 
172             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
173 
174             maRedrawManager.moveSprite( rSprite, rOldPos, rNewPos, rSpriteSize );
175         }
176 
updateSprite(const Sprite::Reference & rSprite,const::basegfx::B2DPoint & rPos,const::basegfx::B2DRange & rUpdateArea)177         virtual void updateSprite( const Sprite::Reference&     rSprite,
178                                    const ::basegfx::B2DPoint&   rPos,
179                                    const ::basegfx::B2DRange&   rUpdateArea )
180         {
181             OSL_ASSERT( rSprite.is() );
182 
183             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
184 
185             maRedrawManager.updateSprite( rSprite, rPos, rUpdateArea );
186         }
187 
188     protected:
189         SpriteRedrawManager maRedrawManager;
190     };
191 }
192 
193 #endif /* INCLUDED_CANVAS_SPRITECANVASBASE_HXX */
194