bump product version to 5.0.4.1
[LibreOffice.git] / slideshow / source / engine / transitions / shapetransitionfactory.cxx
blob33fb7477fa122dedf59c771d1239d79efb3260fa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <canvas/debug.hxx>
22 #include <tools/diagnose_ex.h>
24 #include <comphelper/anytostring.hxx>
25 #include <cppuhelper/exc_hlp.hxx>
26 #include <basegfx/numeric/ftools.hxx>
27 #include <basegfx/matrix/b2dhommatrix.hxx>
28 #include <basegfx/polygon/b2dpolypolygontools.hxx>
30 #include <com/sun/star/animations/TransitionType.hpp>
31 #include <com/sun/star/animations/TransitionSubType.hpp>
33 #include "transitionfactory.hxx"
34 #include "transitionfactorytab.hxx"
35 #include "transitiontools.hxx"
36 #include "parametricpolypolygonfactory.hxx"
37 #include "animationfactory.hxx"
38 #include "clippingfunctor.hxx"
40 using namespace ::com::sun::star;
42 namespace slideshow {
43 namespace internal {
45 /***************************************************
46 *** ***
47 *** Shape Transition Effects ***
48 *** ***
49 ***************************************************/
51 namespace {
53 class ClippingAnimation : public NumberAnimation
55 public:
56 ClippingAnimation(
57 const ParametricPolyPolygonSharedPtr& rPolygon,
58 const ShapeManagerSharedPtr& rShapeManager,
59 const TransitionInfo& rTransitionInfo,
60 bool bDirectionForward,
61 bool bModeIn );
63 virtual ~ClippingAnimation();
65 // Animation interface
67 virtual void prefetch( const AnimatableShapeSharedPtr& rShape,
68 const ShapeAttributeLayerSharedPtr& rAttrLayer ) SAL_OVERRIDE;
69 virtual void start( const AnimatableShapeSharedPtr& rShape,
70 const ShapeAttributeLayerSharedPtr& rAttrLayer ) SAL_OVERRIDE;
71 virtual void end() SAL_OVERRIDE;
73 // NumberAnimation interface
75 virtual bool operator()( double nValue ) SAL_OVERRIDE;
76 virtual double getUnderlyingValue() const SAL_OVERRIDE;
78 private:
79 void end_();
81 AnimatableShapeSharedPtr mpShape;
82 ShapeAttributeLayerSharedPtr mpAttrLayer;
83 ShapeManagerSharedPtr mpShapeManager;
84 ClippingFunctor maClippingFunctor;
85 bool mbSpriteActive;
88 ClippingAnimation::ClippingAnimation(
89 const ParametricPolyPolygonSharedPtr& rPolygon,
90 const ShapeManagerSharedPtr& rShapeManager,
91 const TransitionInfo& rTransitionInfo,
92 bool bDirectionForward,
93 bool bModeIn ) :
94 mpShape(),
95 mpAttrLayer(),
96 mpShapeManager( rShapeManager ),
97 maClippingFunctor( rPolygon,
98 rTransitionInfo,
99 bDirectionForward,
100 bModeIn ),
101 mbSpriteActive(false)
103 ENSURE_OR_THROW(
104 rShapeManager,
105 "ClippingAnimation::ClippingAnimation(): Invalid ShapeManager" );
108 ClippingAnimation::~ClippingAnimation()
112 end_();
114 catch (uno::Exception &)
116 OSL_FAIL( OUStringToOString(
117 comphelper::anyToString(
118 cppu::getCaughtException() ),
119 RTL_TEXTENCODING_UTF8 ).getStr() );
123 void ClippingAnimation::prefetch( const AnimatableShapeSharedPtr&,
124 const ShapeAttributeLayerSharedPtr& )
128 void ClippingAnimation::start( const AnimatableShapeSharedPtr& rShape,
129 const ShapeAttributeLayerSharedPtr& rAttrLayer )
131 OSL_ENSURE( !mpShape,
132 "ClippingAnimation::start(): Shape already set" );
133 OSL_ENSURE( !mpAttrLayer,
134 "ClippingAnimation::start(): Attribute layer already set" );
135 ENSURE_OR_THROW( rShape,
136 "ClippingAnimation::start(): Invalid shape" );
137 ENSURE_OR_THROW( rAttrLayer,
138 "ClippingAnimation::start(): Invalid attribute layer" );
140 mpShape = rShape;
141 mpAttrLayer = rAttrLayer;
143 if( !mbSpriteActive )
145 mpShapeManager->enterAnimationMode( mpShape );
146 mbSpriteActive = true;
150 void ClippingAnimation::end()
152 end_();
155 void ClippingAnimation::end_()
157 if( mbSpriteActive )
159 mbSpriteActive = false;
160 mpShapeManager->leaveAnimationMode( mpShape );
162 if( mpShape->isContentChanged() )
163 mpShapeManager->notifyShapeUpdate( mpShape );
167 bool ClippingAnimation::operator()( double nValue )
169 ENSURE_OR_RETURN_FALSE(
170 mpAttrLayer && mpShape,
171 "ClippingAnimation::operator(): Invalid ShapeAttributeLayer" );
173 // set new clip
174 mpAttrLayer->setClip( maClippingFunctor( nValue,
175 mpShape->getDomBounds().getRange() ) );
177 if( mpShape->isContentChanged() )
178 mpShapeManager->notifyShapeUpdate( mpShape );
180 return true;
183 double ClippingAnimation::getUnderlyingValue() const
185 ENSURE_OR_THROW(
186 mpAttrLayer,
187 "ClippingAnimation::getUnderlyingValue(): Invalid ShapeAttributeLayer" );
189 return 0.0; // though this should be used in concert with
190 // ActivitiesFactory::createSimpleActivity, better
191 // explicitly name our start value.
192 // Permissible range for operator() above is [0,1]
195 AnimationActivitySharedPtr createShapeTransitionByType(
196 const ActivitiesFactory::CommonParameters& rParms,
197 const AnimatableShapeSharedPtr& rShape,
198 const ShapeManagerSharedPtr& rShapeManager,
199 const ::basegfx::B2DVector& rSlideSize,
200 ::com::sun::star::uno::Reference<
201 ::com::sun::star::animations::XTransitionFilter > const& xTransition,
202 sal_Int16 nType,
203 sal_Int16 nSubType )
205 ENSURE_OR_THROW(
206 xTransition.is(),
207 "createShapeTransitionByType(): Invalid XTransition" );
209 const TransitionInfo* pTransitionInfo(
210 getTransitionInfo( nType, nSubType ) );
212 AnimationActivitySharedPtr pGeneratedActivity;
213 if( pTransitionInfo != NULL )
215 switch( pTransitionInfo->meTransitionClass )
217 default:
218 case TransitionInfo::TRANSITION_INVALID:
219 OSL_FAIL( "createShapeTransitionByType(): Invalid transition type. "
220 "Don't ask me for a 0 TransitionType, have no XTransitionFilter node instead!" );
221 return AnimationActivitySharedPtr();
224 case TransitionInfo::TRANSITION_CLIP_POLYPOLYGON:
226 // generate parametric poly-polygon
227 ParametricPolyPolygonSharedPtr pPoly(
228 ParametricPolyPolygonFactory::createClipPolyPolygon(
229 nType, nSubType ) );
231 // create a clip activity from that
232 pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
233 rParms,
234 NumberAnimationSharedPtr(
235 new ClippingAnimation(
236 pPoly,
237 rShapeManager,
238 *pTransitionInfo,
239 xTransition->getDirection(),
240 xTransition->getMode() ) ),
241 true );
243 break;
245 case TransitionInfo::TRANSITION_SPECIAL:
247 switch( nType )
249 case animations::TransitionType::RANDOM:
251 // select randomly one of the effects from the
252 // TransitionFactoryTable
254 const TransitionInfo* pRandomTransitionInfo( getRandomTransitionInfo() );
256 ENSURE_OR_THROW( pRandomTransitionInfo != NULL,
257 "createShapeTransitionByType(): Got invalid random transition info" );
259 ENSURE_OR_THROW( pRandomTransitionInfo->mnTransitionType != animations::TransitionType::RANDOM,
260 "createShapeTransitionByType(): Got random again for random input!" );
262 // and recurse
263 pGeneratedActivity = createShapeTransitionByType( rParms,
264 rShape,
265 rShapeManager,
266 rSlideSize,
267 xTransition,
268 pRandomTransitionInfo->mnTransitionType,
269 pRandomTransitionInfo->mnTransitionSubType );
271 break;
273 // TODO(F3): Implement slidewipe for shape
274 case animations::TransitionType::SLIDEWIPE:
276 sal_Int16 nBarWipeSubType(0);
277 bool bDirectionForward(true);
279 // map slidewipe to BARWIPE, for now
280 switch( nSubType )
282 case animations::TransitionSubType::FROMLEFT:
283 nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT;
284 bDirectionForward = true;
285 break;
287 case animations::TransitionSubType::FROMRIGHT:
288 nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT;
289 bDirectionForward = false;
290 break;
292 case animations::TransitionSubType::FROMTOP:
293 nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM;
294 bDirectionForward = true;
295 break;
297 case animations::TransitionSubType::FROMBOTTOM:
298 nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM;
299 bDirectionForward = false;
300 break;
302 default:
303 ENSURE_OR_THROW( false,
304 "createShapeTransitionByType(): Unexpected subtype for SLIDEWIPE" );
305 break;
308 // generate parametric poly-polygon
309 ParametricPolyPolygonSharedPtr pPoly(
310 ParametricPolyPolygonFactory::createClipPolyPolygon(
311 animations::TransitionType::BARWIPE,
312 nBarWipeSubType ) );
314 // create a clip activity from that
315 pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
316 rParms,
317 NumberAnimationSharedPtr(
318 new ClippingAnimation(
319 pPoly,
320 rShapeManager,
321 *getTransitionInfo( animations::TransitionType::BARWIPE,
322 nBarWipeSubType ),
323 bDirectionForward,
324 xTransition->getMode() ) ),
325 true );
327 break;
329 default:
331 // TODO(F1): Check whether there's anything left, anyway,
332 // for _shape_ transitions. AFAIK, there are no special
333 // effects for shapes...
335 // for now, map all to fade effect
336 pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
337 rParms,
338 AnimationFactory::createNumberPropertyAnimation(
339 OUString("Opacity"),
340 rShape,
341 rShapeManager,
342 rSlideSize ),
343 xTransition->getMode() );
345 break;
348 break;
352 if( !pGeneratedActivity )
354 // No animation generated, maybe no table entry for given
355 // transition?
356 OSL_TRACE(
357 "createShapeTransitionByType(): Unknown type/subtype (%d/%d) "
358 "combination encountered",
359 xTransition->getTransition(),
360 xTransition->getSubtype() );
361 OSL_FAIL(
362 "createShapeTransitionByType(): Unknown type/subtype "
363 "combination encountered" );
366 return pGeneratedActivity;
369 } // anon namespace
371 AnimationActivitySharedPtr TransitionFactory::createShapeTransition(
372 const ActivitiesFactory::CommonParameters& rParms,
373 const AnimatableShapeSharedPtr& rShape,
374 const ShapeManagerSharedPtr& rShapeManager,
375 const ::basegfx::B2DVector& rSlideSize,
376 uno::Reference< animations::XTransitionFilter > const& xTransition )
378 return createShapeTransitionByType( rParms,
379 rShape,
380 rShapeManager,
381 rSlideSize,
382 xTransition,
383 xTransition->getTransition(),
384 xTransition->getSubtype() );
390 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */