23#include <com/sun/star/animations/AnimationCalcMode.hpp>
53template<
typename ValueType>
struct FormulaTraits
56 const ValueType& rVal,
const std::shared_ptr<ExpressionNode>& )
63template<>
struct FormulaTraits<double>
65 static double getPresentationValue(
66 double const& rVal, std::shared_ptr<ExpressionNode>
const& rFormula )
68 return rFormula ? (*rFormula)(rVal) : rVal;
100template<
class BaseType,
typename AnimationType>
101class FromToByActivity :
public BaseType
104 typedef typename AnimationType::ValueType
ValueType;
105 typedef std::optional<ValueType> OptionalValueType;
112 return FormulaTraits<ValueType>::getPresentationValue( rVal,
mpFormula);
144 OptionalValueType aFrom,
145 const OptionalValueType& rTo,
146 const OptionalValueType& rBy,
147 const ActivityParameters& rParms,
148 ::std::shared_ptr< AnimationType > xAnim,
149 const Interpolator< ValueType >& rInterpolator,
151 : BaseType( rParms ),
170 "From and one of To or By, or To or By alone must be valid" );
173 virtual void startAnimation()
175 if (this->isDisposed() || !
mpAnim)
177 BaseType::startAnimation();
180 mpAnim->start( BaseType::getShape(),
181 BaseType::getShapeAttributeLayer() );
242 virtual void endAnimation()
250 void perform(
double nModifiedTime, sal_uInt32 nRepeatCount )
const
252 if (this->isDisposed() || !
mpAnim)
302 (*mpAnim)( getPresentationValue( aValue ) );
311 using BaseType::perform;
314 void perform( sal_uInt32 nFrame, sal_uInt32 nRepeatCount )
const
316 if (this->isDisposed() || !
mpAnim)
319 getPresentationValue(
323 ?
mpAnim->getUnderlyingValue()
327 BaseType::getNumberOfKeyTimes() ) ) ) );
330 using BaseType::isAutoReverse;
332 virtual void performEnd()
365 ::std::shared_ptr< AnimationType >
mpAnim;
380template<
class BaseType,
typename AnimationType>
385 const ActivityParameters& rParms,
386 const ::std::shared_ptr< AnimationType >& rAnim,
387 const Interpolator< typename AnimationType::ValueType >& rInterpolator,
390 const ::basegfx::B2DVector& rSlideBounds )
392 typedef typename AnimationType::ValueType
ValueType;
393 typedef std::optional<ValueType> OptionalValueType;
395 OptionalValueType
aFrom;
396 OptionalValueType
aTo;
397 OptionalValueType aBy;
404 extractValue( aTmpValue, rFromAny, rShape, rSlideBounds ),
405 "createFromToByActivity(): Could not extract from value" );
411 extractValue( aTmpValue, rToAny, rShape, rSlideBounds ),
412 "createFromToByActivity(): Could not extract to value" );
418 extractValue( aTmpValue, rByAny, rShape, rSlideBounds ),
419 "createFromToByActivity(): Could not extract by value" );
423 return std::make_shared<FromToByActivity<BaseType, AnimationType>>(
471template<
class BaseType,
typename AnimationType>
472class ValuesActivity :
public BaseType
475 typedef typename AnimationType::ValueType
ValueType;
476 typedef std::vector<ValueType> ValueVectorType;
483 return FormulaTraits<ValueType>::getPresentationValue(
510 const ValueVectorType& rValues,
511 const ActivityParameters& rParms,
512 std::shared_ptr<AnimationType> xAnim,
513 const Interpolator< ValueType >& rInterpolator,
515 : BaseType( rParms ),
526 virtual void startAnimation()
528 if (this->isDisposed() || !
mpAnim)
530 BaseType::startAnimation();
533 mpAnim->start( BaseType::getShape(),
534 BaseType::getShapeAttributeLayer() );
537 virtual void endAnimation()
545 void perform( sal_uInt32 nIndex,
546 double nFractionalIndex,
547 sal_uInt32 nRepeatCount )
const
549 if (this->isDisposed() || !
mpAnim)
552 "ValuesActivity::perform(): index out of range" );
556 getPresentationValue(
557 accumulate<ValueType>(
maValues.back(),
561 nFractionalIndex ) ) ) );
564 using BaseType::perform;
567 void perform( sal_uInt32 nFrame, sal_uInt32 nRepeatCount )
const
569 if (this->isDisposed() || !
mpAnim)
572 "ValuesActivity::perform(): index out of range" );
576 getPresentationValue(
577 slideshow::internal::accumulate<ValueType>(
maValues.back(),
582 virtual void performEnd()
586 (*mpAnim)( getPresentationValue(
maValues.back() ) );
592 std::shared_ptr<ExpressionNode>
mpFormula;
594 std::shared_ptr<AnimationType>
mpAnim;
607template<
class BaseType,
typename AnimationType>
609 const uno::Sequence<uno::Any>& rValues,
610 const ActivityParameters& rParms,
611 const std::shared_ptr<AnimationType>& rAnim,
612 const Interpolator<typename AnimationType::ValueType>& rInterpolator,
615 const ::basegfx::B2DVector& rSlideBounds )
617 typedef typename AnimationType::ValueType
ValueType;
618 typedef std::vector<ValueType> ValueVectorType;
620 ValueVectorType aValueVector;
621 aValueVector.reserve( rValues.getLength() );
623 for(
const auto& rValue : rValues )
628 "createValueListActivity(): Could not extract values" );
629 aValueVector.push_back( aValue );
632 return std::make_shared<ValuesActivity<BaseType, AnimationType>>(
661template<
typename AnimationType>
663 const ActivitiesFactory::CommonParameters& rParms,
664 const uno::Reference< animations::XAnimate >& xNode,
665 const ::std::shared_ptr< AnimationType >& rAnim,
666 const Interpolator< typename AnimationType::ValueType >& rInterpolator
667 = Interpolator< typename AnimationType::ValueType >() )
672 ActivityParameters aActivityParms( rParms.mpEndEvent,
674 rParms.mrActivitiesQueue,
675 rParms.mnMinDuration,
677 rParms.mnAcceleration,
678 rParms.mnDeceleration,
679 rParms.mnMinNumberOfFrames,
680 rParms.mbAutoReverse );
683 const OUString& rFormulaString( xNode->getFormula() );
684 if( !rFormulaString.isEmpty() )
689 aActivityParms.mpFormula =
693 rParms.maSlideBounds,
694 rParms.mpShape->getBounds() ) );
699 OSL_FAIL(
"createActivity(): Error parsing formula string" );
704 const uno::Sequence< double >& aKeyTimes( xNode->getKeyTimes() );
705 if( aKeyTimes.hasElements() )
708 aActivityParms.maDiscreteTimes.resize( aKeyTimes.getLength() );
710 aActivityParms.maDiscreteTimes.data(),
715 const sal_Int32 nValueLen( xNode->getValues().getLength() );
722 if( !aKeyTimes.hasElements() )
726 for( sal_Int32 i=0;
i<nValueLen; ++
i )
727 aActivityParms.maDiscreteTimes.push_back(
double(i)/nValueLen );
734 const sal_Int16 nCalcMode( xNode->getCalcMode() );
738 case animations::AnimationCalcMode::DISCRETE:
742 aActivityParms.mpWakeupEvent =
743 std::make_shared<WakeupEvent>(
744 rParms.mrEventQueue.getTimer(),
745 rParms.mrActivitiesQueue );
748 createValueListActivity< DiscreteActivityBase >(
753 xNode->getAccumulate(),
755 rParms.maSlideBounds ) );
759 aActivityParms.mpWakeupEvent->setActivity( pActivity );
765 OSL_FAIL(
"createActivity(): unexpected case" );
767 case animations::AnimationCalcMode::PACED:
768 case animations::AnimationCalcMode::SPLINE:
769 case animations::AnimationCalcMode::LINEAR:
770 return createValueListActivity< ContinuousKeyTimeActivityBase >(
775 xNode->getAccumulate(),
777 rParms.maSlideBounds );
789 const sal_Int16 nCalcMode( xNode->getCalcMode() );
793 case animations::AnimationCalcMode::DISCRETE:
796 if( !aKeyTimes.hasElements() )
799 const ::std::size_t nLen( 2 );
800 for( ::std::size_t i=0;
i<nLen; ++
i )
801 aActivityParms.maDiscreteTimes.push_back(
double(i)/nLen );
806 aActivityParms.mpWakeupEvent =
807 std::make_shared<WakeupEvent>(
808 rParms.mrEventQueue.getTimer(),
809 rParms.mrActivitiesQueue );
812 createFromToByActivity< DiscreteActivityBase >(
819 xNode->getAccumulate(),
821 rParms.maSlideBounds ) );
825 aActivityParms.mpWakeupEvent->setActivity( pActivity );
831 OSL_FAIL(
"createActivity(): unexpected case" );
833 case animations::AnimationCalcMode::PACED:
834 case animations::AnimationCalcMode::SPLINE:
835 case animations::AnimationCalcMode::LINEAR:
836 return createFromToByActivity< ContinuousActivityBase >(
843 xNode->getAccumulate(),
845 rParms.maSlideBounds );
858template<
int Direction>
859class SimpleActivity :
public ContinuousActivityBase
867 SimpleActivity(
const ActivityParameters& rParms,
869 ContinuousActivityBase( rParms ),
875 virtual void startAnimation()
override
877 if (this->isDisposed() || !
mpAnim)
882 mpAnim->start( getShape(),
883 getShapeAttributeLayer() );
886 virtual void endAnimation()
override
896 virtual void perform(
double nModifiedTime, sal_uInt32 )
const override
898 if (this->isDisposed() || !
mpAnim)
904 virtual void performEnd()
override
912 virtual void dispose()
override
926 const CommonParameters& rParms,
928 const uno::Reference< animations::XAnimate >& xNode )
931 return createActivity( rParms, xNode, rAnim );
935 const CommonParameters& rParms,
937 const uno::Reference< animations::XAnimate >& xNode )
940 return createActivity( rParms, xNode, rAnim );
944 const CommonParameters& rParms,
946 const uno::Reference< animations::XAnimate >& xNode )
949 return createActivity( rParms, xNode, rAnim );
953 const CommonParameters& rParms,
955 const uno::Reference< animations::XAnimateColor >& xNode )
958 return createActivity( rParms,
959 uno::Reference< animations::XAnimate >(
960 xNode, uno::UNO_QUERY_THROW ),
963 Interpolator< HSLColor >( !xNode->getDirection() ) );
967 const CommonParameters& rParms,
969 const uno::Reference< animations::XAnimate >& xNode )
972 return createActivity( rParms, xNode, rAnim );
976 const CommonParameters& rParms,
978 const uno::Reference< animations::XAnimate >& xNode )
981 return createActivity( rParms, xNode, rAnim );
985 const CommonParameters& rParms,
987 const uno::Reference< animations::XAnimate >& xNode )
990 return createActivity( rParms, xNode, rAnim );
996 bool bDirectionForward )
1008 if( bDirectionForward )
1009 return std::make_shared<SimpleActivity<1>>( aActivityParms, rAnim );
1011 return std::make_shared<SimpleActivity<0>>( aActivityParms, rAnim );
ValueType maPreviousValue
Interpolator< ValueType > maInterpolator
ValueType maStartInterpolationValue
std::shared_ptr< ExpressionNode > mpFormula
const OptionalValueType maBy
const OptionalValueType maFrom
::std::shared_ptr< AnimationType > mpAnim
const OptionalValueType maTo
virtual void dispose() override
From Disposable interface.
virtual void startAnimation() override
Hook for derived classes.
virtual bool perform() override
From Activity interface.
static std::shared_ptr< ExpressionNode > const & parseSmilFunction(const OUString &rSmilFunction, const ::basegfx::B2DRectangle &rRelativeShapeBounds)
Parse a string containing a SMIL function.
#define ENSURE_OR_THROW(c, m)
DstType * sequenceToArray(DstType *io_pArray, const css::uno::Sequence< SrcType > &i_Sequence)
AnimationActivitySharedPtr createAnimateActivity(const CommonParameters &rParms, const NumberAnimationSharedPtr &rAnimator, const css::uno::Reference< css::animations::XAnimate > &xNode)
Create an activity from an XAnimate node.
AnimationActivitySharedPtr createSimpleActivity(const CommonParameters &rParms, const NumberAnimationSharedPtr &rAnimator, bool bDirectionForward)
Create a simple activity for the given animator.
::std::shared_ptr< NumberAnimation > NumberAnimationSharedPtr
::std::shared_ptr< AnimationActivity > AnimationActivitySharedPtr
::std::shared_ptr< HSLColorAnimation > HSLColorAnimationSharedPtr
::std::shared_ptr< PairAnimation > PairAnimationSharedPtr
::std::shared_ptr< BoolAnimation > BoolAnimationSharedPtr
::std::shared_ptr< EnumAnimation > EnumAnimationSharedPtr
::std::shared_ptr< StringAnimation > StringAnimationSharedPtr
::std::shared_ptr< Shape > ShapeSharedPtr
::std::shared_ptr< ColorAnimation > ColorAnimationSharedPtr
bool extractValue(double &o_rValue, const uno::Any &rSourceAny, const ShapeSharedPtr &rShape, const ::basegfx::B2DVector &rSlideBounds)
extract unary double value from Any
ValueType accumulate(const ValueType &rEndValue, sal_uInt32 nRepeatCount, const ValueType &rCurrValue)
Generic accumulation.
basegfx::B2DRange calcRelativeShapeBounds(const basegfx::B2DVector &rPageSize, const basegfx::B2DRange &rShapeBounds)
ValueType lerp(const Interpolator< ValueType > &rInterpolator, const ValueType &rFrom, const ValueType &rTo, sal_uInt32 nFrame, ::std::size_t nTotalFrames)
Generic linear interpolator.
Collection of common factory parameters.
EventQueue & mrEventQueue
Event queue to insert the end event into.
bool mbAutoReverse
When true, activity is played reversed after mnDuration.
::std::optional< double > const maRepeats
Number of repeats for the simple duration.
sal_uInt32 mnMinNumberOfFrames
Minimal number of frames for this activity.
ActivitiesQueue & mrActivitiesQueue
Event queue to insert the end event into.
EventSharedPtr mpEndEvent
End event to fire when animation is over.
double mnDeceleration
Fraction of simple time to decelerate animation.
double mnAcceleration
Fraction of simple time to accelerate animation.
double mnMinDuration
Simple duration of the activity.
Parameter struct for animation activities.