Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef INCLUDED_CANVAS_SPRITECANVASBASE_HXX
30 : : #define INCLUDED_CANVAS_SPRITECANVASBASE_HXX
31 : :
32 : : #include <rtl/ref.hxx>
33 : : #include <com/sun/star/rendering/XSpriteCanvas.hpp>
34 : : #include <com/sun/star/rendering/InterpolationMode.hpp>
35 : : #include <canvas/base/integerbitmapbase.hxx>
36 : : #include <canvas/spriteredrawmanager.hxx>
37 : :
38 : :
39 : : namespace canvas
40 : : {
41 : : /** Helper template to handle XIntegerBitmap method forwarding to
42 : : BitmapCanvasHelper
43 : :
44 : : Use this helper to handle the XIntegerBitmap part of your
45 : : implementation.
46 : :
47 : : @tpl Base
48 : : Base class to use, most probably one of the
49 : : WeakComponentImplHelperN templates with the appropriate
50 : : interfaces. At least XSpriteCanvas and SpriteSurface should be
51 : : among them (why else would you use this template, then?). Base
52 : : class must have an Base( const Mutex& ) constructor (like the
53 : : WeakComponentImplHelperN templates have).
54 : :
55 : : @tpl CanvasHelper
56 : : Canvas helper implementation for the backend in question
57 : :
58 : : @tpl Mutex
59 : : Lock strategy to use. Defaults to using the
60 : : OBaseMutex-provided lock. Everytime one of the methods is
61 : : entered, an object of type Mutex is created with m_aMutex as
62 : : the sole parameter, and destroyed again when the method scope
63 : : is left.
64 : :
65 : : @tpl UnambiguousBase
66 : : Optional unambiguous base class for XInterface of Base. It's
67 : : sometimes necessary to specify this parameter, e.g. if Base
68 : : derives from multiple UNO interface (were each provides its
69 : : own version of XInterface, making the conversion ambiguous)
70 : :
71 : : @see CanvasBase for further contractual requirements towards
72 : : the CanvasHelper type, and some examples.
73 : : */
74 : : template< class Base,
75 : : class CanvasHelper,
76 : : class Mutex=::osl::MutexGuard,
77 : 0 : class UnambiguousBase=::com::sun::star::uno::XInterface > class SpriteCanvasBase :
78 : : public IntegerBitmapBase< Base, CanvasHelper, Mutex, UnambiguousBase >
79 : : {
80 : : public:
81 : : typedef IntegerBitmapBase< Base, CanvasHelper, Mutex, UnambiguousBase > BaseType;
82 : : typedef ::rtl::Reference< SpriteCanvasBase > Reference;
83 : :
84 : 0 : SpriteCanvasBase() :
85 : 0 : maRedrawManager()
86 : : {
87 : 0 : }
88 : :
89 : 0 : virtual void disposeThis()
90 : : {
91 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
92 : :
93 : 0 : maRedrawManager.disposing();
94 : :
95 : : // pass on to base class
96 : 0 : BaseType::disposeThis();
97 : 0 : }
98 : :
99 : : // XSpriteCanvas
100 : 0 : 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,
101 : : ::com::sun::star::uno::RuntimeException)
102 : : {
103 : 0 : tools::verifyArgs(animation,
104 : : BOOST_CURRENT_FUNCTION,
105 : : static_cast< typename BaseType::UnambiguousBaseType* >(this));
106 : :
107 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
108 : :
109 : 0 : return BaseType::maCanvasHelper.createSpriteFromAnimation(animation);
110 : : }
111 : :
112 : 0 : 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,
113 : : sal_Int8 interpolationMode ) throw (::com::sun::star::lang::IllegalArgumentException,
114 : : ::com::sun::star::rendering::VolatileContentDestroyedException,
115 : : ::com::sun::star::uno::RuntimeException)
116 : : {
117 : 0 : tools::verifyArgs(animationBitmaps,
118 : : BOOST_CURRENT_FUNCTION,
119 : : static_cast< typename BaseType::UnambiguousBaseType* >(this));
120 : : tools::verifyRange( interpolationMode,
121 : : ::com::sun::star::rendering::InterpolationMode::NEAREST_NEIGHBOR,
122 : 0 : ::com::sun::star::rendering::InterpolationMode::BEZIERSPLINE4 );
123 : :
124 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
125 : :
126 : 0 : return BaseType::maCanvasHelper.createSpriteFromBitmaps(animationBitmaps, interpolationMode);
127 : : }
128 : :
129 : 0 : 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,
130 : : ::com::sun::star::uno::RuntimeException)
131 : : {
132 : 0 : tools::verifySpriteSize(spriteSize,
133 : : BOOST_CURRENT_FUNCTION,
134 : : static_cast< typename BaseType::UnambiguousBaseType* >(this));
135 : :
136 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
137 : :
138 : 0 : return BaseType::maCanvasHelper.createCustomSprite(spriteSize);
139 : : }
140 : :
141 : 0 : 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,
142 : : ::com::sun::star::uno::RuntimeException)
143 : : {
144 : 0 : tools::verifyArgs(original,
145 : : BOOST_CURRENT_FUNCTION,
146 : : static_cast< typename BaseType::UnambiguousBaseType* >(this));
147 : :
148 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
149 : :
150 : 0 : return BaseType::maCanvasHelper.createClonedSprite(original);
151 : : }
152 : :
153 : : // SpriteSurface
154 : 0 : virtual void showSprite( const Sprite::Reference& rSprite )
155 : : {
156 : : OSL_ASSERT( rSprite.is() );
157 : :
158 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
159 : :
160 : 0 : maRedrawManager.showSprite( rSprite );
161 : 0 : }
162 : :
163 : 0 : virtual void hideSprite( const Sprite::Reference& rSprite )
164 : : {
165 : : OSL_ASSERT( rSprite.is() );
166 : :
167 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
168 : :
169 : 0 : maRedrawManager.hideSprite( rSprite );
170 : 0 : }
171 : :
172 : 0 : virtual void moveSprite( const Sprite::Reference& rSprite,
173 : : const ::basegfx::B2DPoint& rOldPos,
174 : : const ::basegfx::B2DPoint& rNewPos,
175 : : const ::basegfx::B2DVector& rSpriteSize )
176 : : {
177 : : OSL_ASSERT( rSprite.is() );
178 : :
179 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
180 : :
181 : 0 : maRedrawManager.moveSprite( rSprite, rOldPos, rNewPos, rSpriteSize );
182 : 0 : }
183 : :
184 : 0 : virtual void updateSprite( const Sprite::Reference& rSprite,
185 : : const ::basegfx::B2DPoint& rPos,
186 : : const ::basegfx::B2DRange& rUpdateArea )
187 : : {
188 : : OSL_ASSERT( rSprite.is() );
189 : :
190 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
191 : :
192 : 0 : maRedrawManager.updateSprite( rSprite, rPos, rUpdateArea );
193 : 0 : }
194 : :
195 : : protected:
196 : : SpriteRedrawManager maRedrawManager;
197 : : };
198 : : }
199 : :
200 : : #endif /* INCLUDED_CANVAS_SPRITECANVASBASE_HXX */
201 : :
202 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|