Update ooo320-m1
[ooovba.git] / slideshow / source / engine / transitions / shapetransitionfactory.cxx
blob33b085011b21b9d18d4aa89d8fa07860c5ea7f73
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: shapetransitionfactory.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_slideshow.hxx"
34 #include <canvas/debug.hxx>
35 #include <tools/diagnose_ex.h>
37 #include <comphelper/anytostring.hxx>
38 #include <cppuhelper/exc_hlp.hxx>
39 #include <basegfx/numeric/ftools.hxx>
40 #include <basegfx/matrix/b2dhommatrix.hxx>
41 #include <basegfx/polygon/b2dpolypolygontools.hxx>
43 #include <com/sun/star/animations/TransitionType.hpp>
44 #include <com/sun/star/animations/TransitionSubType.hpp>
46 #include "transitionfactory.hxx"
47 #include "transitiontools.hxx"
48 #include "parametricpolypolygonfactory.hxx"
49 #include "animationfactory.hxx"
50 #include "clippingfunctor.hxx"
52 #include <boost/bind.hpp>
55 using namespace ::com::sun::star;
57 namespace slideshow {
58 namespace internal {
60 /***************************************************
61 *** ***
62 *** Shape Transition Effects ***
63 *** ***
64 ***************************************************/
66 namespace {
68 class ClippingAnimation : public NumberAnimation
70 public:
71 ClippingAnimation(
72 const ParametricPolyPolygonSharedPtr& rPolygon,
73 const ShapeManagerSharedPtr& rShapeManager,
74 const TransitionInfo& rTransitionInfo,
75 bool bDirectionForward,
76 bool bModeIn );
78 ~ClippingAnimation();
80 // Animation interface
81 // -------------------
82 virtual void prefetch( const AnimatableShapeSharedPtr& rShape,
83 const ShapeAttributeLayerSharedPtr& rAttrLayer );
84 virtual void start( const AnimatableShapeSharedPtr& rShape,
85 const ShapeAttributeLayerSharedPtr& rAttrLayer );
86 virtual void end();
88 // NumberAnimation interface
89 // -----------------------
90 virtual bool operator()( double nValue );
91 virtual double getUnderlyingValue() const;
93 private:
94 void end_();
96 AnimatableShapeSharedPtr mpShape;
97 ShapeAttributeLayerSharedPtr mpAttrLayer;
98 ShapeManagerSharedPtr mpShapeManager;
99 ClippingFunctor maClippingFunctor;
100 bool mbSpriteActive;
103 ClippingAnimation::ClippingAnimation(
104 const ParametricPolyPolygonSharedPtr& rPolygon,
105 const ShapeManagerSharedPtr& rShapeManager,
106 const TransitionInfo& rTransitionInfo,
107 bool bDirectionForward,
108 bool bModeIn ) :
109 mpShape(),
110 mpAttrLayer(),
111 mpShapeManager( rShapeManager ),
112 maClippingFunctor( rPolygon,
113 rTransitionInfo,
114 bDirectionForward,
115 bModeIn ),
116 mbSpriteActive(false)
118 ENSURE_OR_THROW(
119 rShapeManager,
120 "ClippingAnimation::ClippingAnimation(): Invalid ShapeManager" );
123 ClippingAnimation::~ClippingAnimation()
127 end_();
129 catch (uno::Exception &)
131 OSL_ENSURE( false, rtl::OUStringToOString(
132 comphelper::anyToString(
133 cppu::getCaughtException() ),
134 RTL_TEXTENCODING_UTF8 ).getStr() );
138 void ClippingAnimation::prefetch( const AnimatableShapeSharedPtr&,
139 const ShapeAttributeLayerSharedPtr& )
143 void ClippingAnimation::start( const AnimatableShapeSharedPtr& rShape,
144 const ShapeAttributeLayerSharedPtr& rAttrLayer )
146 OSL_ENSURE( !mpShape,
147 "ClippingAnimation::start(): Shape already set" );
148 OSL_ENSURE( !mpAttrLayer,
149 "ClippingAnimation::start(): Attribute layer already set" );
151 mpShape = rShape;
152 mpAttrLayer = rAttrLayer;
154 ENSURE_OR_THROW( rShape,
155 "ClippingAnimation::start(): Invalid shape" );
156 ENSURE_OR_THROW( rAttrLayer,
157 "ClippingAnimation::start(): Invalid attribute layer" );
159 mpShape = rShape;
160 mpAttrLayer = rAttrLayer;
162 if( !mbSpriteActive )
164 mpShapeManager->enterAnimationMode( mpShape );
165 mbSpriteActive = true;
169 void ClippingAnimation::end()
171 end_();
174 void ClippingAnimation::end_()
176 if( mbSpriteActive )
178 mbSpriteActive = false;
179 mpShapeManager->leaveAnimationMode( mpShape );
181 if( mpShape->isContentChanged() )
182 mpShapeManager->notifyShapeUpdate( mpShape );
186 bool ClippingAnimation::operator()( double nValue )
188 ENSURE_OR_RETURN(
189 mpAttrLayer && mpShape,
190 "ClippingAnimation::operator(): Invalid ShapeAttributeLayer" );
192 // set new clip
193 mpAttrLayer->setClip( maClippingFunctor( nValue,
194 mpShape->getDomBounds().getRange() ) );
196 if( mpShape->isContentChanged() )
197 mpShapeManager->notifyShapeUpdate( mpShape );
199 return true;
202 double ClippingAnimation::getUnderlyingValue() const
204 ENSURE_OR_THROW(
205 mpAttrLayer,
206 "ClippingAnimation::getUnderlyingValue(): Invalid ShapeAttributeLayer" );
208 return 0.0; // though this should be used in concert with
209 // ActivitiesFactory::createSimpleActivity, better
210 // explicitely name our start value.
211 // Permissible range for operator() above is [0,1]
214 } // anon namespace
217 AnimationActivitySharedPtr TransitionFactory::createShapeTransition(
218 const ActivitiesFactory::CommonParameters& rParms,
219 const AnimatableShapeSharedPtr& rShape,
220 const ShapeManagerSharedPtr& rShapeManager,
221 const ::basegfx::B2DVector& rSlideSize,
222 uno::Reference< animations::XTransitionFilter > const& xTransition )
224 return createShapeTransition( rParms,
225 rShape,
226 rShapeManager,
227 rSlideSize,
228 xTransition,
229 xTransition->getTransition(),
230 xTransition->getSubtype() );
233 AnimationActivitySharedPtr TransitionFactory::createShapeTransition(
234 const ActivitiesFactory::CommonParameters& rParms,
235 const AnimatableShapeSharedPtr& rShape,
236 const ShapeManagerSharedPtr& rShapeManager,
237 const ::basegfx::B2DVector& rSlideSize,
238 ::com::sun::star::uno::Reference<
239 ::com::sun::star::animations::XTransitionFilter > const& xTransition,
240 sal_Int16 nType,
241 sal_Int16 nSubType )
243 ENSURE_OR_THROW(
244 xTransition.is(),
245 "TransitionFactory::createShapeTransition(): Invalid XTransition" );
247 const TransitionInfo* pTransitionInfo(
248 getTransitionInfo( nType, nSubType ) );
250 AnimationActivitySharedPtr pGeneratedActivity;
251 if( pTransitionInfo != NULL )
253 switch( pTransitionInfo->meTransitionClass )
255 default:
256 case TransitionInfo::TRANSITION_INVALID:
257 OSL_ENSURE( false,
258 "TransitionFactory::createShapeTransition(): Invalid transition type. "
259 "Don't ask me for a 0 TransitionType, have no XTransitionFilter node instead!" );
260 return AnimationActivitySharedPtr();
263 case TransitionInfo::TRANSITION_CLIP_POLYPOLYGON:
265 // generate parametric poly-polygon
266 ParametricPolyPolygonSharedPtr pPoly(
267 ParametricPolyPolygonFactory::createClipPolyPolygon(
268 nType, nSubType ) );
270 // create a clip activity from that
271 pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
272 rParms,
273 NumberAnimationSharedPtr(
274 new ClippingAnimation(
275 pPoly,
276 rShapeManager,
277 *pTransitionInfo,
278 xTransition->getDirection(),
279 xTransition->getMode() ) ),
280 true );
282 break;
284 case TransitionInfo::TRANSITION_SPECIAL:
286 switch( nType )
288 case animations::TransitionType::RANDOM:
290 // select randomly one of the effects from the
291 // TransitionFactoryTable
293 const TransitionInfo* pRandomTransitionInfo( getRandomTransitionInfo() );
295 ENSURE_OR_THROW( pRandomTransitionInfo != NULL,
296 "TransitionFactory::createShapeTransition(): Got invalid random transition info" );
298 ENSURE_OR_THROW( pRandomTransitionInfo->mnTransitionType != animations::TransitionType::RANDOM,
299 "TransitionFactory::createShapeTransition(): Got random again for random input!" );
301 // and recurse
302 pGeneratedActivity = createShapeTransition( rParms,
303 rShape,
304 rShapeManager,
305 rSlideSize,
306 xTransition,
307 pRandomTransitionInfo->mnTransitionType,
308 pRandomTransitionInfo->mnTransitionSubType );
310 break;
312 // TODO(F3): Implement slidewipe for shape
313 case animations::TransitionType::SLIDEWIPE:
315 sal_Int16 nBarWipeSubType(0);
316 bool bDirectionForward(true);
318 // map slidewipe to BARWIPE, for now
319 switch( nSubType )
321 case animations::TransitionSubType::FROMLEFT:
322 nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT;
323 bDirectionForward = true;
324 break;
326 case animations::TransitionSubType::FROMRIGHT:
327 nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT;
328 bDirectionForward = false;
329 break;
331 case animations::TransitionSubType::FROMTOP:
332 nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM;
333 bDirectionForward = true;
334 break;
336 case animations::TransitionSubType::FROMBOTTOM:
337 nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM;
338 bDirectionForward = false;
339 break;
341 default:
342 ENSURE_OR_THROW( false,
343 "TransitionFactory::createShapeTransition(): Unexpected subtype for SLIDEWIPE" );
344 break;
347 // generate parametric poly-polygon
348 ParametricPolyPolygonSharedPtr pPoly(
349 ParametricPolyPolygonFactory::createClipPolyPolygon(
350 animations::TransitionType::BARWIPE,
351 nBarWipeSubType ) );
353 // create a clip activity from that
354 pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
355 rParms,
356 NumberAnimationSharedPtr(
357 new ClippingAnimation(
358 pPoly,
359 rShapeManager,
360 *getTransitionInfo( animations::TransitionType::BARWIPE,
361 nBarWipeSubType ),
362 bDirectionForward,
363 xTransition->getMode() ) ),
364 true );
366 break;
368 default:
370 // TODO(F1): Check whether there's anything left, anyway,
371 // for _shape_ transitions. AFAIK, there are no special
372 // effects for shapes...
374 // for now, map all to fade effect
375 pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
376 rParms,
377 AnimationFactory::createNumberPropertyAnimation(
378 ::rtl::OUString(
379 RTL_CONSTASCII_USTRINGPARAM("Opacity") ),
380 rShape,
381 rShapeManager,
382 rSlideSize ),
383 xTransition->getMode() );
385 break;
388 break;
392 if( !pGeneratedActivity )
394 // No animation generated, maybe no table entry for given
395 // transition?
396 OSL_TRACE(
397 "TransitionFactory::createShapeTransition(): Unknown type/subtype (%d/%d) "
398 "combination encountered",
399 xTransition->getTransition(),
400 xTransition->getSubtype() );
401 OSL_ENSURE(
402 false,
403 "TransitionFactory::createShapeTransition(): Unknown type/subtype "
404 "combination encountered" );
407 return pGeneratedActivity;