fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / source / engine / activities / activitiesfactory.cxx
blob3a4cf8cf03ca45909c98d6cfbb83d7f16edc5508
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 // must be first
22 #include <canvas/debug.hxx>
23 #include <tools/diagnose_ex.h>
24 #include <canvas/verbosetrace.hxx>
26 #include <com/sun/star/animations/AnimationCalcMode.hpp>
27 #include <comphelper/sequence.hxx>
29 #include "activitiesfactory.hxx"
30 #include "smilfunctionparser.hxx"
31 #include "accumulation.hxx"
32 #include "activityparameters.hxx"
33 #include "interpolation.hxx"
34 #include "tools.hxx"
35 #include "simplecontinuousactivitybase.hxx"
36 #include "discreteactivitybase.hxx"
37 #include "continuousactivitybase.hxx"
38 #include "continuouskeytimeactivitybase.hxx"
40 #include <boost/optional.hpp>
41 #include <boost/shared_ptr.hpp>
43 #include <cmath>
44 #include <vector>
45 #include <algorithm>
47 using namespace com::sun::star;
49 namespace slideshow {
50 namespace internal {
52 namespace {
54 /** Traits template, to take formula application only for ValueType = double
56 template<typename ValueType> struct FormulaTraits
58 static ValueType getPresentationValue(
59 const ValueType& rVal, const ExpressionNodeSharedPtr& )
61 return rVal;
65 /// Specialization for ValueType = double
66 template<> struct FormulaTraits<double>
68 static double getPresentationValue(
69 double const& rVal, ExpressionNodeSharedPtr const& rFormula )
71 return rFormula ? (*rFormula)(rVal) : rVal;
75 // Various ActivityBase specializations for different animator types
76 // =================================================================
78 /** FromToBy handler
80 Provides the Activity specializations for FromToBy
81 animations (e.g. those without a values list).
83 This template makes heavy use of SFINAE, only one of
84 the perform*() methods will compile for each of the
85 base classes.
87 Note that we omit the virtual keyword on the perform()
88 overrides on purpose; those that actually do override
89 baseclass virtual methods inherit the property, and
90 the others won't increase our vtable. What's more,
91 having all perform() method in the vtable actually
92 creates POIs for them, which breaks the whole SFINAE
93 concept (IOW, this template won't compile any longer).
95 @tpl BaseType
96 Base class to use for this activity. Only
97 ContinuousActivityBase and DiscreteActivityBase are
98 supported here.
100 @tpl AnimationType
101 Type of the Animation to call.
103 template<class BaseType, typename AnimationType>
104 class FromToByActivity : public BaseType
106 public:
107 typedef typename AnimationType::ValueType ValueType;
108 typedef boost::optional<ValueType> OptionalValueType;
110 private:
111 // some compilers don't inline whose definition they haven't
112 // seen before the call site...
113 ValueType getPresentationValue( const ValueType& rVal ) const
115 return FormulaTraits<ValueType>::getPresentationValue( rVal, mpFormula);
118 public:
119 /** Create FromToByActivity.
121 @param rFrom
122 From this value, the animation starts
124 @param rTo
125 With this value, the animation ends
127 @param rBy
128 With this value, the animation increments the start value
130 @param rParms
131 Standard Activity parameter struct
133 @param rAnim
134 Shared ptr to AnimationType
136 @param rInterpolator
137 Interpolator object to be used for lerping between
138 start and end value (need to be passed, since it
139 might contain state, e.g. interpolation direction
140 for HSL color space).
142 @param bCumulative
143 Whether repeated animations should cumulate the
144 value, or start fresh each time.
146 FromToByActivity(
147 const OptionalValueType& rFrom,
148 const OptionalValueType& rTo,
149 const OptionalValueType& rBy,
150 const ActivityParameters& rParms,
151 const ::boost::shared_ptr< AnimationType >& rAnim,
152 const Interpolator< ValueType >& rInterpolator,
153 bool bCumulative )
154 : BaseType( rParms ),
155 maFrom( rFrom ),
156 maTo( rTo ),
157 maBy( rBy ),
158 mpFormula( rParms.mpFormula ),
159 maStartValue(),
160 maEndValue(),
161 maPreviousValue(),
162 maStartInterpolationValue(),
163 mnIteration( 0 ),
164 mpAnim( rAnim ),
165 maInterpolator( rInterpolator ),
166 mbDynamicStartValue( false ),
167 mbCumulative( bCumulative )
169 ENSURE_OR_THROW( mpAnim, "Invalid animation object" );
171 ENSURE_OR_THROW(
172 rTo || rBy,
173 "From and one of To or By, or To or By alone must be valid" );
176 virtual void startAnimation()
178 if (this->isDisposed() || !mpAnim)
179 return;
180 BaseType::startAnimation();
182 // start animation
183 mpAnim->start( BaseType::getShape(),
184 BaseType::getShapeAttributeLayer() );
186 // setup start and end value. Determine animation
187 // start value only when animation actually
188 // started up (this order is part of the Animation
189 // interface contract)
190 const ValueType aAnimationStartValue( mpAnim->getUnderlyingValue() );
192 // first of all, determine general type of
193 // animation, by inspecting which of the FromToBy values
194 // are actually valid.
195 // See http://www.w3.org/TR/smil20/animation.html#AnimationNS-FromToBy
196 // for a definition
197 if( maFrom )
199 // From-to or From-by animation. According to
200 // SMIL spec, the To value takes precedence
201 // over the By value, if both are specified
202 if( maTo )
204 // From-To animation
205 maStartValue = *maFrom;
206 maEndValue = *maTo;
208 else if( maBy )
210 // From-By animation
211 maStartValue = *maFrom;
212 maEndValue = maStartValue + *maBy;
215 else
217 maStartValue = aAnimationStartValue;
218 maStartInterpolationValue = maStartValue;
220 // By or To animation. According to SMIL spec,
221 // the To value takes precedence over the By
222 // value, if both are specified
223 if( maTo )
225 // To animation
227 // According to the SMIL spec
228 // (http://www.w3.org/TR/smil20/animation.html#animationNS-ToAnimation),
229 // the to animation interpolates between
230 // the _running_ underlying value and the to value (as the end value)
231 mbDynamicStartValue = true;
232 maPreviousValue = maStartValue;
233 maEndValue = *maTo;
235 else if( maBy )
237 // By animation
238 maStartValue = aAnimationStartValue;
239 maEndValue = maStartValue + *maBy;
244 virtual void endAnimation()
246 // end animation
247 if (mpAnim)
248 mpAnim->end();
251 /// perform override for ContinuousActivityBase
252 void perform( double nModifiedTime, sal_uInt32 nRepeatCount ) const
254 if (this->isDisposed() || !mpAnim)
255 return;
257 // According to SMIL 3.0 spec 'to' animation if no other (lower priority)
258 // animations are active or frozen then a simple interpolation is performed.
259 // That is, the start interpolation value is constant while the animation
260 // is running, and is equal to the underlying value retrieved when
261 // the animation start.
262 // However if another animation is manipulating the underlying value,
263 // the 'to' animation will initially add to the effect of the lower priority
264 // animation, and increasingly dominate it as it nears the end of the
265 // simple duration, eventually overriding it completely.
266 // That is, each time the underlying value is changed between two
267 // computations of the animation function the new underlying value is used
268 // as start value for the interpolation.
269 // See:
270 // http://www.w3.org/TR/SMIL3/smil-animation.html#animationNS-ToAnimation
271 // (Figure 6 - Effect of Additive to animation example)
272 // Moreover when a 'to' animation is repeated, at each new iteration
273 // the start interpolation value is reset to the underlying value
274 // of the animated property when the animation started,
275 // as it is shown in the example provided by the SMIL 3.0 spec.
276 // This is exactly as Firefox performs SVG 'to' animations.
277 if( mbDynamicStartValue )
279 if( mnIteration != nRepeatCount )
281 mnIteration = nRepeatCount;
282 maStartInterpolationValue = maStartValue;
284 else
286 ValueType aActualValue = mpAnim->getUnderlyingValue();
287 if( aActualValue != maPreviousValue )
288 maStartInterpolationValue = aActualValue;
292 ValueType aValue = maInterpolator( maStartInterpolationValue,
293 maEndValue, nModifiedTime );
295 // According to the SMIL spec:
296 // Because 'to' animation is defined in terms of absolute values of
297 // the target attribute, cumulative animation is not defined.
298 if( mbCumulative && !mbDynamicStartValue )
300 // aValue = this.aEndValue * nRepeatCount + aValue;
301 aValue = accumulate( maEndValue, nRepeatCount, aValue );
304 (*mpAnim)( getPresentationValue( aValue ) );
306 if( mbDynamicStartValue )
308 maPreviousValue = mpAnim->getUnderlyingValue();
313 using BaseType::perform;
315 /// perform override for DiscreteActivityBase base
316 void perform( sal_uInt32 nFrame, sal_uInt32 nRepeatCount ) const
318 if (this->isDisposed() || !mpAnim)
319 return;
320 (*mpAnim)(
321 getPresentationValue(
322 accumulate( maEndValue, mbCumulative ? nRepeatCount : 0,
323 lerp( maInterpolator,
324 (mbDynamicStartValue
325 ? mpAnim->getUnderlyingValue()
326 : maStartValue),
327 maEndValue,
328 nFrame,
329 BaseType::getNumberOfKeyTimes() ) ) ) );
332 using BaseType::isAutoReverse;
334 virtual void performEnd()
336 // xxx todo: good guess
337 if (mpAnim)
339 if (isAutoReverse())
340 (*mpAnim)( getPresentationValue( maStartValue ) );
341 else
342 (*mpAnim)( getPresentationValue( maEndValue ) );
346 /// Disposable:
347 virtual void dispose()
349 mpAnim.reset();
350 BaseType::dispose();
353 private:
354 const OptionalValueType maFrom;
355 const OptionalValueType maTo;
356 const OptionalValueType maBy;
358 ExpressionNodeSharedPtr mpFormula;
360 ValueType maStartValue;
361 ValueType maEndValue;
363 mutable ValueType maPreviousValue;
364 mutable ValueType maStartInterpolationValue;
365 mutable sal_uInt32 mnIteration;
367 ::boost::shared_ptr< AnimationType > mpAnim;
368 Interpolator< ValueType > maInterpolator;
369 bool mbDynamicStartValue;
370 bool mbCumulative;
374 /** Generate Activity corresponding to given FromToBy values
376 @tpl BaseType
377 BaseType to use for deriving the Activity from
379 @tpl AnimationType
380 Subtype of the Animation object (e.g. NumberAnimation)
382 template<class BaseType, typename AnimationType>
383 AnimationActivitySharedPtr createFromToByActivity(
384 const uno::Any& rFromAny,
385 const uno::Any& rToAny,
386 const uno::Any& rByAny,
387 const ActivityParameters& rParms,
388 const ::boost::shared_ptr< AnimationType >& rAnim,
389 const Interpolator< typename AnimationType::ValueType >& rInterpolator,
390 bool bCumulative,
391 const ShapeSharedPtr& rShape,
392 const ::basegfx::B2DVector& rSlideBounds )
394 typedef typename AnimationType::ValueType ValueType;
395 typedef boost::optional<ValueType> OptionalValueType;
397 OptionalValueType aFrom;
398 OptionalValueType aTo;
399 OptionalValueType aBy;
401 ValueType aTmpValue;
403 if( rFromAny.hasValue() )
405 ENSURE_OR_THROW(
406 extractValue( aTmpValue, rFromAny, rShape, rSlideBounds ),
407 "createFromToByActivity(): Could not extract from value" );
408 aFrom.reset(aTmpValue);
410 if( rToAny.hasValue() )
412 ENSURE_OR_THROW(
413 extractValue( aTmpValue, rToAny, rShape, rSlideBounds ),
414 "createFromToByActivity(): Could not extract to value" );
415 aTo.reset(aTmpValue);
417 if( rByAny.hasValue() )
419 ENSURE_OR_THROW(
420 extractValue( aTmpValue, rByAny, rShape, rSlideBounds ),
421 "createFromToByActivity(): Could not extract by value" );
422 aBy.reset(aTmpValue);
425 return AnimationActivitySharedPtr(
426 new FromToByActivity<BaseType, AnimationType>(
427 aFrom,
428 aTo,
429 aBy,
430 rParms,
431 rAnim,
432 rInterpolator,
433 bCumulative ) );
436 /* The following table shows which animator combines with
437 which Activity type:
439 NumberAnimator: all
440 PairAnimation: all
441 ColorAnimation: all
442 StringAnimation: DiscreteActivityBase
443 BoolAnimation: DiscreteActivityBase
446 /** Values handler
448 Provides the Activity specializations for value lists
449 animations.
451 This template makes heavy use of SFINAE, only one of
452 the perform*() methods will compile for each of the
453 base classes.
455 Note that we omit the virtual keyword on the perform()
456 overrides on purpose; those that actually do override
457 baseclass virtual methods inherit the property, and
458 the others won't increase our vtable. What's more,
459 having all perform() method in the vtable actually
460 creates POIs for them, which breaks the whole SFINAE
461 concept (IOW, this template won't compile any longer).
463 @tpl BaseType
464 Base class to use for this activity. Only
465 ContinuousKeyTimeActivityBase and DiscreteActivityBase
466 are supported here. For values animation without key
467 times, the client must emulate key times by providing
468 a vector of equally spaced values between 0 and 1,
469 with the same number of entries as the values vector.
471 @tpl AnimationType
472 Type of the Animation to call.
474 template<class BaseType, typename AnimationType>
475 class ValuesActivity : public BaseType
477 public:
478 typedef typename AnimationType::ValueType ValueType;
479 typedef std::vector<ValueType> ValueVectorType;
481 private:
482 // some compilers don't inline methods whose definition they haven't
483 // seen before the call site...
484 ValueType getPresentationValue( const ValueType& rVal ) const
486 return FormulaTraits<ValueType>::getPresentationValue(
487 rVal, mpFormula );
490 public:
491 /** Create ValuesActivity.
493 @param rValues
494 Value vector to cycle animation through
496 @param rParms
497 Standard Activity parameter struct
499 @param rAnim
500 Shared ptr to AnimationType
502 @param rInterpolator
503 Interpolator object to be used for lerping between
504 start and end value (need to be passed, since it
505 might contain state, e.g. interpolation direction
506 for HSL color space).
508 @param bCumulative
509 Whether repeated animations should cumulate the
510 value, or start afresh each time.
512 ValuesActivity(
513 const ValueVectorType& rValues,
514 const ActivityParameters& rParms,
515 const boost::shared_ptr<AnimationType>& rAnim,
516 const Interpolator< ValueType >& rInterpolator,
517 bool bCumulative )
518 : BaseType( rParms ),
519 maValues( rValues ),
520 mpFormula( rParms.mpFormula ),
521 mpAnim( rAnim ),
522 maInterpolator( rInterpolator ),
523 mbCumulative( bCumulative )
525 ENSURE_OR_THROW( mpAnim, "Invalid animation object" );
526 ENSURE_OR_THROW( !rValues.empty(), "Empty value vector" );
529 virtual void startAnimation()
531 if (this->isDisposed() || !mpAnim)
532 return;
533 BaseType::startAnimation();
535 // start animation
536 mpAnim->start( BaseType::getShape(),
537 BaseType::getShapeAttributeLayer() );
540 virtual void endAnimation()
542 // end animation
543 if (mpAnim)
544 mpAnim->end();
547 /// perform override for ContinuousKeyTimeActivityBase base
548 void perform( sal_uInt32 nIndex,
549 double nFractionalIndex,
550 sal_uInt32 nRepeatCount ) const
552 if (this->isDisposed() || !mpAnim)
553 return;
554 ENSURE_OR_THROW( nIndex+1 < maValues.size(),
555 "ValuesActivity::perform(): index out of range" );
557 // interpolate between nIndex and nIndex+1 values
558 (*mpAnim)(
559 getPresentationValue(
560 accumulate<ValueType>( maValues.back(),
561 mbCumulative ? nRepeatCount : 0,
562 maInterpolator( maValues[ nIndex ],
563 maValues[ nIndex+1 ],
564 nFractionalIndex ) ) ) );
567 using BaseType::perform;
569 /// perform override for DiscreteActivityBase base
570 void perform( sal_uInt32 nFrame, sal_uInt32 nRepeatCount ) const
572 if (this->isDisposed() || !mpAnim)
573 return;
574 ENSURE_OR_THROW( nFrame < maValues.size(),
575 "ValuesActivity::perform(): index out of range" );
577 // this is discrete, thus no lerp here.
578 (*mpAnim)(
579 getPresentationValue(
580 accumulate<ValueType>( maValues.back(),
581 mbCumulative ? nRepeatCount : 0,
582 maValues[ nFrame ] ) ) );
585 virtual void performEnd()
587 // xxx todo: good guess
588 if (mpAnim)
589 (*mpAnim)( getPresentationValue( maValues.back() ) );
592 /// Disposable:
593 virtual void dispose()
595 mpAnim.reset();
596 BaseType::dispose();
599 private:
600 ValueVectorType maValues;
602 ExpressionNodeSharedPtr mpFormula;
604 boost::shared_ptr<AnimationType> mpAnim;
605 Interpolator< ValueType > maInterpolator;
606 bool mbCumulative;
609 /** Generate Activity corresponding to given Value vector
611 @tpl BaseType
612 BaseType to use for deriving the Activity from
614 @tpl AnimationType
615 Subtype of the Animation object (e.g. NumberAnimation)
617 template<class BaseType, typename AnimationType>
618 AnimationActivitySharedPtr createValueListActivity(
619 const uno::Sequence<uno::Any>& rValues,
620 const ActivityParameters& rParms,
621 const boost::shared_ptr<AnimationType>& rAnim,
622 const Interpolator<typename AnimationType::ValueType>& rInterpolator,
623 bool bCumulative,
624 const ShapeSharedPtr& rShape,
625 const ::basegfx::B2DVector& rSlideBounds )
627 typedef typename AnimationType::ValueType ValueType;
628 typedef std::vector<ValueType> ValueVectorType;
630 ValueVectorType aValueVector;
631 aValueVector.reserve( rValues.getLength() );
633 for( ::std::size_t i=0, nLen=rValues.getLength(); i<nLen; ++i )
635 ValueType aValue;
636 ENSURE_OR_THROW(
637 extractValue( aValue, rValues[i], rShape, rSlideBounds ),
638 "createValueListActivity(): Could not extract values" );
639 aValueVector.push_back( aValue );
642 return AnimationActivitySharedPtr(
643 new ValuesActivity<BaseType, AnimationType>(
644 aValueVector,
645 rParms,
646 rAnim,
647 rInterpolator,
648 bCumulative ) );
651 /** Generate Activity for given XAnimate, corresponding to given Value vector
653 @tpl AnimationType
654 Subtype of the Animation object (e.g. NumberAnimation)
656 @param rParms
657 Common activity parameters
659 @param xNode
660 XAnimate node, to retrieve animation values from
662 @param rAnim
663 Actual animation to operate with (gets called with the
664 time-dependent values)
666 @param rInterpolator
667 Interpolator object to be used for lerping between
668 start and end values (need to be passed, since it
669 might contain state, e.g. interpolation direction
670 for HSL color space).
672 template<typename AnimationType>
673 AnimationActivitySharedPtr createActivity(
674 const ActivitiesFactory::CommonParameters& rParms,
675 const uno::Reference< animations::XAnimate >& xNode,
676 const ::boost::shared_ptr< AnimationType >& rAnim,
677 const Interpolator< typename AnimationType::ValueType >& rInterpolator
678 = Interpolator< typename AnimationType::ValueType >() )
680 // setup common parameters
681 // =======================
683 ActivityParameters aActivityParms( rParms.mpEndEvent,
684 rParms.mrEventQueue,
685 rParms.mrActivitiesQueue,
686 rParms.mnMinDuration,
687 rParms.maRepeats,
688 rParms.mnAcceleration,
689 rParms.mnDeceleration,
690 rParms.mnMinNumberOfFrames,
691 rParms.mbAutoReverse );
693 // is a formula given?
694 const OUString& rFormulaString( xNode->getFormula() );
695 if( !rFormulaString.isEmpty() )
697 // yep, parse and pass to ActivityParameters
700 aActivityParms.mpFormula =
701 SmilFunctionParser::parseSmilFunction(
702 rFormulaString,
703 calcRelativeShapeBounds(
704 rParms.maSlideBounds,
705 rParms.mpShape->getBounds() ) );
707 catch( ParseError& )
709 // parse error, thus no formula
710 OSL_FAIL( "createActivity(): Error parsing formula string" );
714 // are key times given?
715 const uno::Sequence< double >& aKeyTimes( xNode->getKeyTimes() );
716 if( aKeyTimes.hasElements() )
718 // yes, convert them from Sequence< double >
719 aActivityParms.maDiscreteTimes.resize( aKeyTimes.getLength() );
720 comphelper::sequenceToArray(
721 &aActivityParms.maDiscreteTimes[0],
722 aKeyTimes ); // saves us some temporary vectors
725 // values sequence given?
726 const sal_Int32 nValueLen( xNode->getValues().getLength() );
727 if( nValueLen )
729 // Value list activity
730 // ===================
732 // fake keytimes, if necessary
733 if( !aKeyTimes.hasElements() )
735 // create a dummy vector of key times,
736 // with aValues.getLength equally spaced entries.
737 for( sal_Int32 i=0; i<nValueLen; ++i )
738 aActivityParms.maDiscreteTimes.push_back( double(i)/nValueLen );
741 // determine type of animation needed here:
742 // Value list activities are possible with
743 // ContinuousKeyTimeActivityBase and DiscreteActivityBase
744 // specializations
745 const sal_Int16 nCalcMode( xNode->getCalcMode() );
747 switch( nCalcMode )
749 case animations::AnimationCalcMode::DISCRETE:
751 // since DiscreteActivityBase suspends itself
752 // between the frames, create a WakeupEvent for it.
753 aActivityParms.mpWakeupEvent.reset(
754 new WakeupEvent(
755 rParms.mrEventQueue.getTimer(),
756 rParms.mrActivitiesQueue ) );
758 AnimationActivitySharedPtr pActivity(
759 createValueListActivity< DiscreteActivityBase >(
760 xNode->getValues(),
761 aActivityParms,
762 rAnim,
763 rInterpolator,
764 xNode->getAccumulate(),
765 rParms.mpShape,
766 rParms.maSlideBounds ) );
768 // WakeupEvent and DiscreteActivityBase need circular
769 // references to the corresponding other object.
770 aActivityParms.mpWakeupEvent->setActivity( pActivity );
772 return pActivity;
775 default:
776 OSL_FAIL( "createActivity(): unexpected case" );
777 // FALLTHROUGH intended
778 case animations::AnimationCalcMode::PACED:
779 // FALLTHROUGH intended
780 case animations::AnimationCalcMode::SPLINE:
781 // FALLTHROUGH intended
782 case animations::AnimationCalcMode::LINEAR:
783 return createValueListActivity< ContinuousKeyTimeActivityBase >(
784 xNode->getValues(),
785 aActivityParms,
786 rAnim,
787 rInterpolator,
788 xNode->getAccumulate(),
789 rParms.mpShape,
790 rParms.maSlideBounds );
793 else
795 // FromToBy activity
796 // =================
798 // determine type of animation needed here:
799 // FromToBy activities are possible with
800 // ContinuousActivityBase and DiscreteActivityBase
801 // specializations
802 const sal_Int16 nCalcMode( xNode->getCalcMode() );
804 switch( nCalcMode )
806 case animations::AnimationCalcMode::DISCRETE:
808 // fake keytimes, if necessary
809 if( !aKeyTimes.hasElements() )
811 // create a dummy vector of 2 key times
812 const ::std::size_t nLen( 2 );
813 for( ::std::size_t i=0; i<nLen; ++i )
814 aActivityParms.maDiscreteTimes.push_back( double(i)/nLen );
817 // since DiscreteActivityBase suspends itself
818 // between the frames, create a WakeupEvent for it.
819 aActivityParms.mpWakeupEvent.reset(
820 new WakeupEvent(
821 rParms.mrEventQueue.getTimer(),
822 rParms.mrActivitiesQueue ) );
824 AnimationActivitySharedPtr pActivity(
825 createFromToByActivity< DiscreteActivityBase >(
826 xNode->getFrom(),
827 xNode->getTo(),
828 xNode->getBy(),
829 aActivityParms,
830 rAnim,
831 rInterpolator,
832 xNode->getAccumulate(),
833 rParms.mpShape,
834 rParms.maSlideBounds ) );
836 // WakeupEvent and DiscreteActivityBase need circular
837 // references to the corresponding other object.
838 aActivityParms.mpWakeupEvent->setActivity( pActivity );
840 return pActivity;
843 default:
844 OSL_FAIL( "createActivity(): unexpected case" );
845 // FALLTHROUGH intended
846 case animations::AnimationCalcMode::PACED:
847 // FALLTHROUGH intended
848 case animations::AnimationCalcMode::SPLINE:
849 // FALLTHROUGH intended
850 case animations::AnimationCalcMode::LINEAR:
851 return createFromToByActivity< ContinuousActivityBase >(
852 xNode->getFrom(),
853 xNode->getTo(),
854 xNode->getBy(),
855 aActivityParms,
856 rAnim,
857 rInterpolator,
858 xNode->getAccumulate(),
859 rParms.mpShape,
860 rParms.maSlideBounds );
865 /** Simple activity for ActivitiesFactory::createSimpleActivity
867 @tpl Direction
868 Determines direction of value generator. A 1 yields a
869 forward direction, starting with 0.0 and ending with
870 1.0. A 0 yields a backward direction, starting with
871 1.0 and ending with 0.0
873 template<int Direction>
874 class SimpleActivity : public ContinuousActivityBase
876 public:
877 /** Create SimpleActivity.
879 @param rParms
880 Standard Activity parameter struct
882 SimpleActivity( const ActivityParameters& rParms,
883 const NumberAnimationSharedPtr& rAnim ) :
884 ContinuousActivityBase( rParms ),
885 mpAnim( rAnim )
887 ENSURE_OR_THROW( mpAnim, "Invalid animation object" );
890 virtual void startAnimation() SAL_OVERRIDE
892 if (this->isDisposed() || !mpAnim)
893 return;
894 ContinuousActivityBase::startAnimation();
896 // start animation
897 mpAnim->start( getShape(),
898 getShapeAttributeLayer() );
901 virtual void endAnimation() SAL_OVERRIDE
903 // end animation
904 if (mpAnim)
905 mpAnim->end();
908 using SimpleContinuousActivityBase::perform;
910 /// perform override for ContinuousActivityBase
911 virtual void perform( double nModifiedTime, sal_uInt32 ) const SAL_OVERRIDE
913 if (this->isDisposed() || !mpAnim)
914 return;
915 // no cumulation, simple [0,1] range
916 (*mpAnim)( 1.0 - Direction + nModifiedTime*(2.0*Direction - 1.0) );
919 virtual void performEnd() SAL_OVERRIDE
921 // xxx todo: review
922 if (mpAnim)
923 (*mpAnim)( 1.0*Direction );
926 /// Disposable:
927 virtual void dispose() SAL_OVERRIDE
929 mpAnim.reset();
930 ContinuousActivityBase::dispose();
933 private:
934 NumberAnimationSharedPtr mpAnim;
937 } // anon namespace
940 AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity(
941 const CommonParameters& rParms,
942 const NumberAnimationSharedPtr& rAnim,
943 const uno::Reference< animations::XAnimate >& xNode )
945 // forward to appropriate template instantiation
946 return createActivity( rParms, xNode, rAnim );
949 AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity(
950 const CommonParameters& rParms,
951 const EnumAnimationSharedPtr& rAnim,
952 const uno::Reference< animations::XAnimate >& xNode )
954 // forward to appropriate template instantiation
955 return createActivity( rParms, xNode, rAnim );
958 AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity(
959 const CommonParameters& rParms,
960 const ColorAnimationSharedPtr& rAnim,
961 const uno::Reference< animations::XAnimate >& xNode )
963 // forward to appropriate template instantiation
964 return createActivity( rParms, xNode, rAnim );
967 AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity(
968 const CommonParameters& rParms,
969 const HSLColorAnimationSharedPtr& rAnim,
970 const uno::Reference< animations::XAnimateColor >& xNode )
972 // forward to appropriate template instantiation
973 return createActivity( rParms,
974 uno::Reference< animations::XAnimate >(
975 xNode, uno::UNO_QUERY_THROW ),
976 rAnim,
977 // Direction==true means clockwise in SMIL API
978 Interpolator< HSLColor >( !xNode->getDirection() ) );
981 AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity(
982 const CommonParameters& rParms,
983 const PairAnimationSharedPtr& rAnim,
984 const uno::Reference< animations::XAnimate >& xNode )
986 // forward to appropriate template instantiation
987 return createActivity( rParms, xNode, rAnim );
990 AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity(
991 const CommonParameters& rParms,
992 const StringAnimationSharedPtr& rAnim,
993 const uno::Reference< animations::XAnimate >& xNode )
995 // forward to appropriate template instantiation
996 return createActivity( rParms, xNode, rAnim );
999 AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity(
1000 const CommonParameters& rParms,
1001 const BoolAnimationSharedPtr& rAnim,
1002 const uno::Reference< animations::XAnimate >& xNode )
1004 // forward to appropriate template instantiation
1005 return createActivity( rParms, xNode, rAnim );
1008 AnimationActivitySharedPtr ActivitiesFactory::createSimpleActivity(
1009 const CommonParameters& rParms,
1010 const NumberAnimationSharedPtr& rAnim,
1011 bool bDirectionForward )
1013 ActivityParameters aActivityParms( rParms.mpEndEvent,
1014 rParms.mrEventQueue,
1015 rParms.mrActivitiesQueue,
1016 rParms.mnMinDuration,
1017 rParms.maRepeats,
1018 rParms.mnAcceleration,
1019 rParms.mnDeceleration,
1020 rParms.mnMinNumberOfFrames,
1021 rParms.mbAutoReverse );
1023 if( bDirectionForward )
1024 return AnimationActivitySharedPtr(
1025 new SimpleActivity<1>( aActivityParms, rAnim ) );
1026 else
1027 return AnimationActivitySharedPtr(
1028 new SimpleActivity<0>( aActivityParms, rAnim ) );
1031 } // namespace internal
1032 } // namespace presentation
1034 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */