merge the formfield patch from ooo-build
[ooovba.git] / slideshow / source / engine / activities / activitiesfactory.cxx
blob21a98940d458609cb59e317be82a565a83cc016d
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: activitiesfactory.cxx,v $
10 * $Revision: 1.12 $
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 // must be first
35 #include <canvas/debug.hxx>
36 #include <tools/diagnose_ex.h>
37 #include <canvas/verbosetrace.hxx>
39 #include <com/sun/star/animations/AnimationCalcMode.hpp>
40 #include <comphelper/sequence.hxx>
42 #include "activitiesfactory.hxx"
43 #include "smilfunctionparser.hxx"
44 #include "accumulation.hxx"
45 #include "activityparameters.hxx"
46 #include "interpolation.hxx"
47 #include "tools.hxx"
48 #include "simplecontinuousactivitybase.hxx"
49 #include "discreteactivitybase.hxx"
50 #include "continuousactivitybase.hxx"
51 #include "continuouskeytimeactivitybase.hxx"
53 #include <boost/bind.hpp>
54 #include <boost/optional.hpp>
56 #include <cmath> // for modf
57 #include <vector>
58 #include <algorithm>
60 using namespace com::sun::star;
62 namespace slideshow {
63 namespace internal {
65 namespace {
67 /** Traits template, to take formula application only for ValueType = double
69 template<typename ValueType> struct FormulaTraits
71 static ValueType getPresentationValue(
72 const ValueType& rVal, const ExpressionNodeSharedPtr& )
74 return rVal;
78 /// Specialization for ValueType = double
79 template<> struct FormulaTraits<double>
81 static double getPresentationValue(
82 double const& rVal, ExpressionNodeSharedPtr const& rFormula )
84 return rFormula ? (*rFormula)(rVal) : rVal;
88 // Various ActivityBase specializations for different animator types
89 // =================================================================
91 /** FromToBy handler
93 Provides the Activity specializations for FromToBy
94 animations (e.g. those without a values list).
96 This template makes heavy use of SFINAE, only one of
97 the perform*() methods will compile for each of the
98 base classes.
100 Note that we omit the virtual keyword on the perform()
101 overrides on purpose; those that actually do override
102 baseclass virtual methods inherit the property, and
103 the others won't increase our vtable. What's more,
104 having all perform() method in the vtable actually
105 creates POIs for them, which breaks the whole SFINAE
106 concept (IOW, this template won't compile any longer).
108 @tpl BaseType
109 Base class to use for this activity. Only
110 ContinuousActivityBase and DiscreteActivityBase are
111 supported here.
113 @tpl AnimationType
114 Type of the Animation to call.
116 template<class BaseType, typename AnimationType>
117 class FromToByActivity : public BaseType
119 public:
120 typedef typename AnimationType::ValueType ValueType;
121 typedef boost::optional<ValueType> OptionalValueType;
123 private:
124 // some compilers don't inline whose definition they haven't
125 // seen before the call site...
126 ValueType getPresentationValue( const ValueType& rVal ) const
128 return FormulaTraits<ValueType>::getPresentationValue( rVal, mpFormula);
131 public:
132 /** Create FromToByActivity.
134 @param rFrom
135 From this value, the animation starts
137 @param rTo
138 With this value, the animation ends
140 @param rBy
141 With this value, the animation increments the start value
143 @param rParms
144 Standard Activity parameter struct
146 @param rAnim
147 Shared ptr to AnimationType
149 @param rInterpolator
150 Interpolator object to be used for lerping between
151 start and end value (need to be passed, since it
152 might contain state, e.g. interpolation direction
153 for HSL color space).
155 @param bCumulative
156 Whether repeated animations should cumulate the
157 value, or start fresh each time.
159 FromToByActivity(
160 const OptionalValueType& rFrom,
161 const OptionalValueType& rTo,
162 const OptionalValueType& rBy,
163 const ActivityParameters& rParms,
164 const ::boost::shared_ptr< AnimationType >& rAnim,
165 const Interpolator< ValueType >& rInterpolator,
166 bool bCumulative )
167 : BaseType( rParms ),
168 maFrom( rFrom ),
169 maTo( rTo ),
170 maBy( rBy ),
171 mpFormula( rParms.mpFormula ),
172 maStartValue(),
173 maEndValue(),
174 mpAnim( rAnim ),
175 maInterpolator( rInterpolator ),
176 mbDynamicStartValue( false ),
177 mbCumulative( bCumulative )
179 ENSURE_OR_THROW( mpAnim, "Invalid animation object" );
181 ENSURE_OR_THROW(
182 rTo || rBy,
183 "From and one of To or By, or To or By alone must be valid" );
186 virtual void startAnimation()
188 if (this->isDisposed() || !mpAnim)
189 return;
190 BaseType::startAnimation();
192 // start animation
193 mpAnim->start( BaseType::getShape(),
194 BaseType::getShapeAttributeLayer() );
196 // setup start and end value. Determine animation
197 // start value only when animation actually
198 // started up (this order is part of the Animation
199 // interface contract)
200 const ValueType aAnimationStartValue( mpAnim->getUnderlyingValue() );
202 // first of all, determine general type of
203 // animation, by inspecting which of the FromToBy values
204 // are actually valid.
205 // See http://www.w3.org/TR/smil20/animation.html#AnimationNS-FromToBy
206 // for a definition
207 if( maFrom )
209 // From-to or From-by animation. According to
210 // SMIL spec, the To value takes precedence
211 // over the By value, if both are specified
212 if( maTo )
214 // From-To animation
215 maStartValue = *maFrom;
216 maEndValue = *maTo;
218 else if( maBy )
220 // From-By animation
221 maStartValue = *maFrom;
222 maEndValue = maStartValue + *maBy;
225 else
227 // By or To animation. According to SMIL spec,
228 // the To value takes precedence over the By
229 // value, if both are specified
230 if( maTo )
232 // To animation
234 // According to the SMIL spec
235 // (http://www.w3.org/TR/smil20/animation.html#animationNS-ToAnimation),
236 // the to animation interpolates between
237 // the _running_ underlying value and the to value (as the end value)
238 mbDynamicStartValue = true;
239 maEndValue = *maTo;
241 else if( maBy )
243 // By animation
244 maStartValue = aAnimationStartValue;
245 maEndValue = maStartValue + *maBy;
250 virtual void endAnimation()
252 // end animation
253 if (mpAnim)
254 mpAnim->end();
257 /// perform override for ContinuousActivityBase
258 void perform( double nModifiedTime, sal_uInt32 nRepeatCount ) const
260 if (this->isDisposed() || !mpAnim)
261 return;
262 (*mpAnim)(
263 getPresentationValue(
264 accumulate( maEndValue,
265 mbCumulative * nRepeatCount, // means: mbCumulative ? nRepeatCount : 0,
266 maInterpolator( (mbDynamicStartValue
267 ? mpAnim->getUnderlyingValue()
268 : maStartValue),
269 maEndValue,
270 nModifiedTime ) ) ) );
273 using BaseType::perform;
275 /// perform override for DiscreteActivityBase base
276 void perform( sal_uInt32 nFrame, sal_uInt32 nRepeatCount ) const
278 if (this->isDisposed() || !mpAnim)
279 return;
280 (*mpAnim)(
281 getPresentationValue(
282 accumulate( maEndValue, mbCumulative ? nRepeatCount : 0,
283 lerp( maInterpolator,
284 (mbDynamicStartValue
285 ? mpAnim->getUnderlyingValue()
286 : maStartValue),
287 maEndValue,
288 nFrame,
289 BaseType::getNumberOfKeyTimes() ) ) ) );
292 virtual void performEnd()
294 // xxx todo: good guess
295 if (mpAnim)
296 (*mpAnim)( getPresentationValue( maEndValue ) );
299 /// Disposable:
300 virtual void dispose()
302 mpAnim.reset();
303 BaseType::dispose();
306 private:
307 const OptionalValueType maFrom;
308 const OptionalValueType maTo;
309 const OptionalValueType maBy;
311 ExpressionNodeSharedPtr mpFormula;
313 ValueType maStartValue;
314 ValueType maEndValue;
316 ::boost::shared_ptr< AnimationType > mpAnim;
317 Interpolator< ValueType > maInterpolator;
318 bool mbDynamicStartValue;
319 bool mbCumulative;
323 /** Generate Activity corresponding to given FromToBy values
325 @tpl BaseType
326 BaseType to use for deriving the Activity from
328 @tpl AnimationType
329 Subtype of the Animation object (e.g. NumberAnimation)
331 template<class BaseType, typename AnimationType>
332 AnimationActivitySharedPtr createFromToByActivity(
333 const uno::Any& rFromAny,
334 const uno::Any& rToAny,
335 const uno::Any& rByAny,
336 const ActivityParameters& rParms,
337 const ::boost::shared_ptr< AnimationType >& rAnim,
338 const Interpolator< typename AnimationType::ValueType >& rInterpolator,
339 bool bCumulative,
340 const ShapeSharedPtr& rShape,
341 const ::basegfx::B2DVector& rSlideBounds )
343 typedef typename AnimationType::ValueType ValueType;
344 typedef boost::optional<ValueType> OptionalValueType;
346 OptionalValueType aFrom;
347 OptionalValueType aTo;
348 OptionalValueType aBy;
350 ValueType aTmpValue;
352 if( rFromAny.hasValue() )
354 ENSURE_OR_THROW(
355 extractValue( aTmpValue, rFromAny, rShape, rSlideBounds ),
356 "createFromToByActivity(): Could not extract from value" );
357 aFrom.reset(aTmpValue);
359 if( rToAny.hasValue() )
361 ENSURE_OR_THROW(
362 extractValue( aTmpValue, rToAny, rShape, rSlideBounds ),
363 "createFromToByActivity(): Could not extract to value" );
364 aTo.reset(aTmpValue);
366 if( rByAny.hasValue() )
368 ENSURE_OR_THROW(
369 extractValue( aTmpValue, rByAny, rShape, rSlideBounds ),
370 "createFromToByActivity(): Could not extract by value" );
371 aBy.reset(aTmpValue);
374 return AnimationActivitySharedPtr(
375 new FromToByActivity<BaseType, AnimationType>(
376 aFrom,
377 aTo,
378 aBy,
379 rParms,
380 rAnim,
381 rInterpolator,
382 bCumulative ) );
385 /* The following table shows which animator combines with
386 which Activity type:
388 NumberAnimator: all
389 PairAnimation: all
390 ColorAnimation: all
391 StringAnimation: DiscreteActivityBase
392 BoolAnimation: DiscreteActivityBase
395 /** Values handler
397 Provides the Activity specializations for value lists
398 animations.
400 This template makes heavy use of SFINAE, only one of
401 the perform*() methods will compile for each of the
402 base classes.
404 Note that we omit the virtual keyword on the perform()
405 overrides on purpose; those that actually do override
406 baseclass virtual methods inherit the property, and
407 the others won't increase our vtable. What's more,
408 having all perform() method in the vtable actually
409 creates POIs for them, which breaks the whole SFINAE
410 concept (IOW, this template won't compile any longer).
412 @tpl BaseType
413 Base class to use for this activity. Only
414 ContinuousKeyTimeActivityBase and DiscreteActivityBase
415 are supported here. For values animation without key
416 times, the client must emulate key times by providing
417 a vector of equally spaced values between 0 and 1,
418 with the same number of entries as the values vector.
420 @tpl AnimationType
421 Type of the Animation to call.
423 template<class BaseType, typename AnimationType>
424 class ValuesActivity : public BaseType
426 public:
427 typedef typename AnimationType::ValueType ValueType;
428 typedef std::vector<ValueType> ValueVectorType;
430 private:
431 // some compilers don't inline methods whose definition they haven't
432 // seen before the call site...
433 ValueType getPresentationValue( const ValueType& rVal ) const
435 return FormulaTraits<ValueType>::getPresentationValue(
436 rVal, mpFormula );
439 public:
440 /** Create ValuesActivity.
442 @param rValues
443 Value vector to cycle animation through
445 @param rParms
446 Standard Activity parameter struct
448 @param rAnim
449 Shared ptr to AnimationType
451 @param rInterpolator
452 Interpolator object to be used for lerping between
453 start and end value (need to be passed, since it
454 might contain state, e.g. interpolation direction
455 for HSL color space).
457 @param bCumulative
458 Whether repeated animations should cumulate the
459 value, or start afresh each time.
461 ValuesActivity(
462 const ValueVectorType& rValues,
463 const ActivityParameters& rParms,
464 const boost::shared_ptr<AnimationType>& rAnim,
465 const Interpolator< ValueType >& rInterpolator,
466 bool bCumulative )
467 : BaseType( rParms ),
468 maValues( rValues ),
469 mpFormula( rParms.mpFormula ),
470 mpAnim( rAnim ),
471 maInterpolator( rInterpolator ),
472 mbCumulative( bCumulative )
474 ENSURE_OR_THROW( mpAnim, "Invalid animation object" );
475 ENSURE_OR_THROW( !rValues.empty(), "Empty value vector" );
478 virtual void startAnimation()
480 if (this->isDisposed() || !mpAnim)
481 return;
482 BaseType::startAnimation();
484 // start animation
485 mpAnim->start( BaseType::getShape(),
486 BaseType::getShapeAttributeLayer() );
489 virtual void endAnimation()
491 // end animation
492 if (mpAnim)
493 mpAnim->end();
496 /// perform override for ContinuousKeyTimeActivityBase base
497 void perform( sal_uInt32 nIndex,
498 double nFractionalIndex,
499 sal_uInt32 nRepeatCount ) const
501 if (this->isDisposed() || !mpAnim)
502 return;
503 ENSURE_OR_THROW( nIndex+1 < maValues.size(),
504 "ValuesActivity::perform(): index out of range" );
506 // interpolate between nIndex and nIndex+1 values
507 (*mpAnim)(
508 getPresentationValue(
509 accumulate( maValues.back(),
510 mbCumulative ? nRepeatCount : 0,
511 maInterpolator( maValues[ nIndex ],
512 maValues[ nIndex+1 ],
513 nFractionalIndex ) ) ) );
516 using BaseType::perform;
518 /// perform override for DiscreteActivityBase base
519 void perform( sal_uInt32 nFrame, sal_uInt32 nRepeatCount ) const
521 if (this->isDisposed() || !mpAnim)
522 return;
523 ENSURE_OR_THROW( nFrame < maValues.size(),
524 "ValuesActivity::perform(): index out of range" );
526 // this is discrete, thus no lerp here.
527 (*mpAnim)(
528 getPresentationValue(
529 accumulate( maValues.back(),
530 mbCumulative ? nRepeatCount : 0,
531 maValues[ nFrame ] ) ) );
534 virtual void performEnd()
536 // xxx todo: good guess
537 if (mpAnim)
538 (*mpAnim)( getPresentationValue( maValues.back() ) );
541 /// Disposable:
542 virtual void dispose()
544 mpAnim.reset();
545 BaseType::dispose();
548 private:
549 ValueVectorType maValues;
551 ExpressionNodeSharedPtr mpFormula;
553 boost::shared_ptr<AnimationType> mpAnim;
554 Interpolator< ValueType > maInterpolator;
555 bool mbCumulative;
558 /** Generate Activity corresponding to given Value vector
560 @tpl BaseType
561 BaseType to use for deriving the Activity from
563 @tpl AnimationType
564 Subtype of the Animation object (e.g. NumberAnimation)
566 template<class BaseType, typename AnimationType>
567 AnimationActivitySharedPtr createValueListActivity(
568 const uno::Sequence<uno::Any>& rValues,
569 const ActivityParameters& rParms,
570 const boost::shared_ptr<AnimationType>& rAnim,
571 const Interpolator<typename AnimationType::ValueType>& rInterpolator,
572 bool bCumulative,
573 const ShapeSharedPtr& rShape,
574 const ::basegfx::B2DVector& rSlideBounds )
576 typedef typename AnimationType::ValueType ValueType;
577 typedef std::vector<ValueType> ValueVectorType;
579 ValueVectorType aValueVector;
580 aValueVector.reserve( rValues.getLength() );
582 for( ::std::size_t i=0, nLen=rValues.getLength(); i<nLen; ++i )
584 ValueType aValue;
585 ENSURE_OR_THROW(
586 extractValue( aValue, rValues[i], rShape, rSlideBounds ),
587 "createValueListActivity(): Could not extract values" );
588 aValueVector.push_back( aValue );
591 return AnimationActivitySharedPtr(
592 new ValuesActivity<BaseType, AnimationType>(
593 aValueVector,
594 rParms,
595 rAnim,
596 rInterpolator,
597 bCumulative ) );
600 /** Generate Activity for given XAnimate, corresponding to given Value vector
602 @tpl AnimationType
603 Subtype of the Animation object (e.g. NumberAnimation)
605 @param rParms
606 Common activity parameters
608 @param xNode
609 XAnimate node, to retrieve animation values from
611 @param rAnim
612 Actual animation to operate with (gets called with the
613 time-dependent values)
615 @param rInterpolator
616 Interpolator object to be used for lerping between
617 start and end values (need to be passed, since it
618 might contain state, e.g. interpolation direction
619 for HSL color space).
621 template<typename AnimationType>
622 AnimationActivitySharedPtr createActivity(
623 const ActivitiesFactory::CommonParameters& rParms,
624 const uno::Reference< animations::XAnimate >& xNode,
625 const ::boost::shared_ptr< AnimationType >& rAnim,
626 const Interpolator< typename AnimationType::ValueType >& rInterpolator
627 = Interpolator< typename AnimationType::ValueType >() )
629 // setup common parameters
630 // =======================
632 ActivityParameters aActivityParms( rParms.mpEndEvent,
633 rParms.mrEventQueue,
634 rParms.mrActivitiesQueue,
635 rParms.mnMinDuration,
636 rParms.maRepeats,
637 rParms.mnAcceleration,
638 rParms.mnDeceleration,
639 rParms.mnMinNumberOfFrames,
640 rParms.mbAutoReverse );
642 // is a formula given?
643 const ::rtl::OUString& rFormulaString( xNode->getFormula() );
644 if( rFormulaString.getLength() )
646 // yep, parse and pass to ActivityParameters
647 try
649 aActivityParms.mpFormula =
650 SmilFunctionParser::parseSmilFunction(
651 rFormulaString,
652 calcRelativeShapeBounds(
653 rParms.maSlideBounds,
654 rParms.mpShape->getBounds() ) );
656 catch( ParseError& )
658 // parse error, thus no formula
659 OSL_ENSURE( false,
660 "createActivity(): Error parsing formula string" );
664 // are key times given?
665 const uno::Sequence< double >& aKeyTimes( xNode->getKeyTimes() );
666 if( aKeyTimes.hasElements() )
668 // yes, convert them from Sequence< double >
669 aActivityParms.maDiscreteTimes.resize( aKeyTimes.getLength() );
670 comphelper::sequenceToArray(
671 &aActivityParms.maDiscreteTimes[0],
672 aKeyTimes ); // saves us some temporary vectors
675 // values sequence given?
676 const sal_Int32 nValueLen( xNode->getValues().getLength() );
677 if( nValueLen )
679 // Value list activity
680 // ===================
682 // fake keytimes, if necessary
683 if( !aKeyTimes.hasElements() )
685 // create a dummy vector of key times,
686 // with aValues.getLength equally spaced entries.
687 for( sal_Int32 i=0; i<nValueLen; ++i )
688 aActivityParms.maDiscreteTimes.push_back( double(i)/nValueLen );
691 // determine type of animation needed here:
692 // Value list activities are possible with
693 // ContinuousKeyTimeActivityBase and DiscreteActivityBase
694 // specializations
695 const sal_Int16 nCalcMode( xNode->getCalcMode() );
697 switch( nCalcMode )
699 case animations::AnimationCalcMode::DISCRETE:
701 // since DiscreteActivityBase suspends itself
702 // between the frames, create a WakeupEvent for it.
703 aActivityParms.mpWakeupEvent.reset(
704 new WakeupEvent(
705 rParms.mrEventQueue.getTimer(),
706 rParms.mrActivitiesQueue ) );
708 AnimationActivitySharedPtr pActivity(
709 createValueListActivity< DiscreteActivityBase >(
710 xNode->getValues(),
711 aActivityParms,
712 rAnim,
713 rInterpolator,
714 xNode->getAccumulate(),
715 rParms.mpShape,
716 rParms.maSlideBounds ) );
718 // WakeupEvent and DiscreteActivityBase need circular
719 // references to the corresponding other object.
720 aActivityParms.mpWakeupEvent->setActivity( pActivity );
722 return pActivity;
725 default:
726 OSL_ENSURE( false, "createActivity(): unexpected case" );
727 // FALLTHROUGH intended
728 case animations::AnimationCalcMode::PACED:
729 // FALLTHROUGH intended
730 case animations::AnimationCalcMode::SPLINE:
731 // FALLTHROUGH intended
732 case animations::AnimationCalcMode::LINEAR:
733 return createValueListActivity< ContinuousKeyTimeActivityBase >(
734 xNode->getValues(),
735 aActivityParms,
736 rAnim,
737 rInterpolator,
738 xNode->getAccumulate(),
739 rParms.mpShape,
740 rParms.maSlideBounds );
743 else
745 // FromToBy activity
746 // =================
748 // determine type of animation needed here:
749 // FromToBy activities are possible with
750 // ContinuousActivityBase and DiscreteActivityBase
751 // specializations
752 const sal_Int16 nCalcMode( xNode->getCalcMode() );
754 switch( nCalcMode )
756 case animations::AnimationCalcMode::DISCRETE:
758 // fake keytimes, if necessary
759 if( !aKeyTimes.hasElements() )
761 // create a dummy vector of 2 key times
762 const ::std::size_t nLen( 2 );
763 for( ::std::size_t i=0; i<nLen; ++i )
764 aActivityParms.maDiscreteTimes.push_back( double(i)/nLen );
767 // since DiscreteActivityBase suspends itself
768 // between the frames, create a WakeupEvent for it.
769 aActivityParms.mpWakeupEvent.reset(
770 new WakeupEvent(
771 rParms.mrEventQueue.getTimer(),
772 rParms.mrActivitiesQueue ) );
774 AnimationActivitySharedPtr pActivity(
775 createFromToByActivity< DiscreteActivityBase >(
776 xNode->getFrom(),
777 xNode->getTo(),
778 xNode->getBy(),
779 aActivityParms,
780 rAnim,
781 rInterpolator,
782 xNode->getAccumulate(),
783 rParms.mpShape,
784 rParms.maSlideBounds ) );
786 // WakeupEvent and DiscreteActivityBase need circular
787 // references to the corresponding other object.
788 aActivityParms.mpWakeupEvent->setActivity( pActivity );
790 return pActivity;
793 default:
794 OSL_ENSURE( false, "createActivity(): unexpected case" );
795 // FALLTHROUGH intended
796 case animations::AnimationCalcMode::PACED:
797 // FALLTHROUGH intended
798 case animations::AnimationCalcMode::SPLINE:
799 // FALLTHROUGH intended
800 case animations::AnimationCalcMode::LINEAR:
801 return createFromToByActivity< ContinuousActivityBase >(
802 xNode->getFrom(),
803 xNode->getTo(),
804 xNode->getBy(),
805 aActivityParms,
806 rAnim,
807 rInterpolator,
808 xNode->getAccumulate(),
809 rParms.mpShape,
810 rParms.maSlideBounds );
815 /** Simple activity for ActivitiesFactory::createSimpleActivity
817 @tpl Direction
818 Determines direction of value generator. A 1 yields a
819 forward direction, starting with 0.0 and ending with
820 1.0. A 0 yields a backward direction, starting with
821 1.0 and ending with 0.0
823 template<int Direction>
824 class SimpleActivity : public ContinuousActivityBase
826 public:
827 /** Create SimpleActivity.
829 @param rParms
830 Standard Activity parameter struct
832 SimpleActivity( const ActivityParameters& rParms,
833 const NumberAnimationSharedPtr& rAnim ) :
834 ContinuousActivityBase( rParms ),
835 mpAnim( rAnim )
837 ENSURE_OR_THROW( mpAnim, "Invalid animation object" );
840 virtual void startAnimation()
842 if (this->isDisposed() || !mpAnim)
843 return;
844 ContinuousActivityBase::startAnimation();
846 // start animation
847 mpAnim->start( getShape(),
848 getShapeAttributeLayer() );
851 virtual void endAnimation()
853 // end animation
854 if (mpAnim)
855 mpAnim->end();
858 using SimpleContinuousActivityBase::perform;
860 /// perform override for ContinuousActivityBase
861 virtual void perform( double nModifiedTime, sal_uInt32 ) const
863 if (this->isDisposed() || !mpAnim)
864 return;
865 // no cumulation, simple [0,1] range
866 (*mpAnim)( 1.0 - Direction + nModifiedTime*(2.0*Direction - 1.0) );
869 virtual void performEnd()
871 // xxx todo: review
872 if (mpAnim)
873 (*mpAnim)( 1.0*Direction );
876 /// Disposable:
877 virtual void dispose()
879 mpAnim.reset();
880 ContinuousActivityBase::dispose();
883 private:
884 NumberAnimationSharedPtr mpAnim;
887 } // anon namespace
890 AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity(
891 const CommonParameters& rParms,
892 const NumberAnimationSharedPtr& rAnim,
893 const uno::Reference< animations::XAnimate >& xNode )
895 // forward to appropriate template instantiation
896 return createActivity( rParms, xNode, rAnim );
899 AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity(
900 const CommonParameters& rParms,
901 const EnumAnimationSharedPtr& rAnim,
902 const uno::Reference< animations::XAnimate >& xNode )
904 // forward to appropriate template instantiation
905 return createActivity( rParms, xNode, rAnim );
908 AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity(
909 const CommonParameters& rParms,
910 const ColorAnimationSharedPtr& rAnim,
911 const uno::Reference< animations::XAnimate >& xNode )
913 // forward to appropriate template instantiation
914 return createActivity( rParms, xNode, rAnim );
917 AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity(
918 const CommonParameters& rParms,
919 const HSLColorAnimationSharedPtr& rAnim,
920 const uno::Reference< animations::XAnimateColor >& xNode )
922 // forward to appropriate template instantiation
923 return createActivity( rParms,
924 uno::Reference< animations::XAnimate >(
925 xNode, uno::UNO_QUERY_THROW ),
926 rAnim,
927 // Direction==true means clockwise in SMIL API
928 Interpolator< HSLColor >( !xNode->getDirection() ) );
931 AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity(
932 const CommonParameters& rParms,
933 const PairAnimationSharedPtr& rAnim,
934 const uno::Reference< animations::XAnimate >& xNode )
936 // forward to appropriate template instantiation
937 return createActivity( rParms, xNode, rAnim );
940 AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity(
941 const CommonParameters& rParms,
942 const StringAnimationSharedPtr& 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 BoolAnimationSharedPtr& rAnim,
952 const uno::Reference< animations::XAnimate >& xNode )
954 // forward to appropriate template instantiation
955 return createActivity( rParms, xNode, rAnim );
958 AnimationActivitySharedPtr ActivitiesFactory::createSimpleActivity(
959 const CommonParameters& rParms,
960 const NumberAnimationSharedPtr& rAnim,
961 bool bDirectionForward )
963 ActivityParameters aActivityParms( rParms.mpEndEvent,
964 rParms.mrEventQueue,
965 rParms.mrActivitiesQueue,
966 rParms.mnMinDuration,
967 rParms.maRepeats,
968 rParms.mnAcceleration,
969 rParms.mnDeceleration,
970 rParms.mnMinNumberOfFrames,
971 rParms.mbAutoReverse );
973 if( bDirectionForward )
974 return AnimationActivitySharedPtr(
975 new SimpleActivity<1>( aActivityParms, rAnim ) );
976 else
977 return AnimationActivitySharedPtr(
978 new SimpleActivity<0>( aActivityParms, rAnim ) );
981 } // namespace internal
982 } // namespace presentation