diff options
Diffstat (limited to 'slideshow/source/engine/activities/activitiesfactory.cxx')
-rw-r--r-- | slideshow/source/engine/activities/activitiesfactory.cxx | 296 |
1 files changed, 148 insertions, 148 deletions
diff --git a/slideshow/source/engine/activities/activitiesfactory.cxx b/slideshow/source/engine/activities/activitiesfactory.cxx index 9308d0b80217..f42a6497f25b 100644 --- a/slideshow/source/engine/activities/activitiesfactory.cxx +++ b/slideshow/source/engine/activities/activitiesfactory.cxx @@ -2,7 +2,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -87,14 +87,14 @@ template<> struct FormulaTraits<double> // ================================================================= /** FromToBy handler - + Provides the Activity specializations for FromToBy animations (e.g. those without a values list). - + This template makes heavy use of SFINAE, only one of the perform*() methods will compile for each of the base classes. - + Note that we omit the virtual keyword on the perform() overrides on purpose; those that actually do override baseclass virtual methods inherit the property, and @@ -102,14 +102,14 @@ template<> struct FormulaTraits<double> having all perform() method in the vtable actually creates POIs for them, which breaks the whole SFINAE concept (IOW, this template won't compile any longer). - + @tpl BaseType Base class to use for this activity. Only ContinuousActivityBase and DiscreteActivityBase are supported here. - + @tpl AnimationType - Type of the Animation to call. + Type of the Animation to call. */ template<class BaseType, typename AnimationType> class FromToByActivity : public BaseType @@ -117,39 +117,39 @@ class FromToByActivity : public BaseType public: typedef typename AnimationType::ValueType ValueType; typedef boost::optional<ValueType> OptionalValueType; - + private: - // some compilers don't inline whose definition they haven't + // some compilers don't inline whose definition they haven't // seen before the call site... ValueType getPresentationValue( const ValueType& rVal ) const { return FormulaTraits<ValueType>::getPresentationValue( rVal, mpFormula); } - + public: /** Create FromToByActivity. - + @param rFrom From this value, the animation starts - + @param rTo With this value, the animation ends - + @param rBy With this value, the animation increments the start value - + @param rParms Standard Activity parameter struct - + @param rAnim Shared ptr to AnimationType - + @param rInterpolator Interpolator object to be used for lerping between start and end value (need to be passed, since it might contain state, e.g. interpolation direction for HSL color space). - + @param bCumulative Whether repeated animations should cumulate the value, or start fresh each time. @@ -175,60 +175,60 @@ public: mbCumulative( bCumulative ) { ENSURE_OR_THROW( mpAnim, "Invalid animation object" ); - + ENSURE_OR_THROW( rTo || rBy, "From and one of To or By, or To or By alone must be valid" ); } - - virtual void startAnimation() + + virtual void startAnimation() { if (this->isDisposed() || !mpAnim) return; BaseType::startAnimation(); - - // start animation + + // start animation mpAnim->start( BaseType::getShape(), BaseType::getShapeAttributeLayer() ); - + // setup start and end value. Determine animation // start value only when animation actually // started up (this order is part of the Animation // interface contract) const ValueType aAnimationStartValue( mpAnim->getUnderlyingValue() ); - + // first of all, determine general type of // animation, by inspecting which of the FromToBy values // are actually valid. // See http://www.w3.org/TR/smil20/animation.html#AnimationNS-FromToBy // for a definition - if( maFrom ) + if( maFrom ) { // From-to or From-by animation. According to // SMIL spec, the To value takes precedence // over the By value, if both are specified - if( maTo ) + if( maTo ) { // From-To animation maStartValue = *maFrom; maEndValue = *maTo; } - else if( maBy ) + else if( maBy ) { // From-By animation maStartValue = *maFrom; maEndValue = maStartValue + *maBy; } } - else + else { // By or To animation. According to SMIL spec, // the To value takes precedence over the By // value, if both are specified - if( maTo ) + if( maTo ) { // To animation - + // According to the SMIL spec // (http://www.w3.org/TR/smil20/animation.html#animationNS-ToAnimation), // the to animation interpolates between @@ -236,7 +236,7 @@ public: mbDynamicStartValue = true; maEndValue = *maTo; } - else if( maBy ) + else if( maBy ) { // By animation maStartValue = aAnimationStartValue; @@ -244,14 +244,14 @@ public: } } } - + virtual void endAnimation() { // end animation if (mpAnim) mpAnim->end(); } - + /// perform override for ContinuousActivityBase void perform( double nModifiedTime, sal_uInt32 nRepeatCount ) const { @@ -259,7 +259,7 @@ public: return; (*mpAnim)( getPresentationValue( - accumulate( maEndValue, + accumulate( maEndValue, mbCumulative * nRepeatCount, // means: mbCumulative ? nRepeatCount : 0, maInterpolator( (mbDynamicStartValue ? mpAnim->getUnderlyingValue() @@ -275,7 +275,7 @@ public: { if (this->isDisposed() || !mpAnim) return; - (*mpAnim)( + (*mpAnim)( getPresentationValue( accumulate( maEndValue, mbCumulative ? nRepeatCount : 0, lerp( maInterpolator, @@ -283,12 +283,12 @@ public: ? mpAnim->getUnderlyingValue() : maStartValue), maEndValue, - nFrame, + nFrame, BaseType::getNumberOfKeyTimes() ) ) ) ); } using BaseType::isAutoReverse; - + virtual void performEnd() { // xxx todo: good guess @@ -300,7 +300,7 @@ public: (*mpAnim)( getPresentationValue( maEndValue ) ); } } - + /// Disposable: virtual void dispose() { @@ -312,12 +312,12 @@ private: const OptionalValueType maFrom; const OptionalValueType maTo; const OptionalValueType maBy; - + ExpressionNodeSharedPtr mpFormula; - + ValueType maStartValue; ValueType maEndValue; - + ::boost::shared_ptr< AnimationType > mpAnim; Interpolator< ValueType > maInterpolator; bool mbDynamicStartValue; @@ -326,10 +326,10 @@ private: /** Generate Activity corresponding to given FromToBy values - + @tpl BaseType BaseType to use for deriving the Activity from - + @tpl AnimationType Subtype of the Animation object (e.g. NumberAnimation) */ @@ -347,35 +347,35 @@ AnimationActivitySharedPtr createFromToByActivity( { typedef typename AnimationType::ValueType ValueType; typedef boost::optional<ValueType> OptionalValueType; - + OptionalValueType aFrom; OptionalValueType aTo; OptionalValueType aBy; - + ValueType aTmpValue; - - if( rFromAny.hasValue() ) + + if( rFromAny.hasValue() ) { ENSURE_OR_THROW( extractValue( aTmpValue, rFromAny, rShape, rSlideBounds ), "createFromToByActivity(): Could not extract from value" ); aFrom.reset(aTmpValue); } - if( rToAny.hasValue() ) + if( rToAny.hasValue() ) { ENSURE_OR_THROW( extractValue( aTmpValue, rToAny, rShape, rSlideBounds ), "createFromToByActivity(): Could not extract to value" ); aTo.reset(aTmpValue); } - if( rByAny.hasValue() ) + if( rByAny.hasValue() ) { ENSURE_OR_THROW( extractValue( aTmpValue, rByAny, rShape, rSlideBounds ), "createFromToByActivity(): Could not extract by value" ); aBy.reset(aTmpValue); } - + return AnimationActivitySharedPtr( new FromToByActivity<BaseType, AnimationType>( aFrom, @@ -389,7 +389,7 @@ AnimationActivitySharedPtr createFromToByActivity( /* The following table shows which animator combines with which Activity type: - + NumberAnimator: all PairAnimation: all ColorAnimation: all @@ -398,14 +398,14 @@ AnimationActivitySharedPtr createFromToByActivity( */ /** Values handler - + Provides the Activity specializations for value lists animations. - + This template makes heavy use of SFINAE, only one of the perform*() methods will compile for each of the base classes. - + Note that we omit the virtual keyword on the perform() overrides on purpose; those that actually do override baseclass virtual methods inherit the property, and @@ -413,7 +413,7 @@ AnimationActivitySharedPtr createFromToByActivity( having all perform() method in the vtable actually creates POIs for them, which breaks the whole SFINAE concept (IOW, this template won't compile any longer). - + @tpl BaseType Base class to use for this activity. Only ContinuousKeyTimeActivityBase and DiscreteActivityBase @@ -421,9 +421,9 @@ AnimationActivitySharedPtr createFromToByActivity( times, the client must emulate key times by providing a vector of equally spaced values between 0 and 1, with the same number of entries as the values vector. - + @tpl AnimationType - Type of the Animation to call. + Type of the Animation to call. */ template<class BaseType, typename AnimationType> class ValuesActivity : public BaseType @@ -431,34 +431,34 @@ class ValuesActivity : public BaseType public: typedef typename AnimationType::ValueType ValueType; typedef std::vector<ValueType> ValueVectorType; - + private: - // some compilers don't inline methods whose definition they haven't + // some compilers don't inline methods whose definition they haven't // seen before the call site... ValueType getPresentationValue( const ValueType& rVal ) const { return FormulaTraits<ValueType>::getPresentationValue( rVal, mpFormula ); } - + public: /** Create ValuesActivity. - + @param rValues Value vector to cycle animation through - + @param rParms Standard Activity parameter struct - + @param rAnim Shared ptr to AnimationType - + @param rInterpolator Interpolator object to be used for lerping between start and end value (need to be passed, since it might contain state, e.g. interpolation direction for HSL color space). - + @param bCumulative Whether repeated animations should cumulate the value, or start afresh each time. @@ -479,25 +479,25 @@ public: ENSURE_OR_THROW( mpAnim, "Invalid animation object" ); ENSURE_OR_THROW( !rValues.empty(), "Empty value vector" ); } - + virtual void startAnimation() { if (this->isDisposed() || !mpAnim) return; BaseType::startAnimation(); - + // start animation mpAnim->start( BaseType::getShape(), BaseType::getShapeAttributeLayer() ); } - + virtual void endAnimation() { // end animation if (mpAnim) mpAnim->end(); } - + /// perform override for ContinuousKeyTimeActivityBase base void perform( sal_uInt32 nIndex, double nFractionalIndex, @@ -507,14 +507,14 @@ public: return; ENSURE_OR_THROW( nIndex+1 < maValues.size(), "ValuesActivity::perform(): index out of range" ); - + // interpolate between nIndex and nIndex+1 values - (*mpAnim)( + (*mpAnim)( getPresentationValue( accumulate( maValues.back(), mbCumulative ? nRepeatCount : 0, - maInterpolator( maValues[ nIndex ], - maValues[ nIndex+1 ], + maInterpolator( maValues[ nIndex ], + maValues[ nIndex+1 ], nFractionalIndex ) ) ) ); } @@ -527,44 +527,44 @@ public: return; ENSURE_OR_THROW( nFrame < maValues.size(), "ValuesActivity::perform(): index out of range" ); - + // this is discrete, thus no lerp here. - (*mpAnim)( + (*mpAnim)( getPresentationValue( accumulate( maValues.back(), mbCumulative ? nRepeatCount : 0, maValues[ nFrame ] ) ) ); } - + virtual void performEnd() { // xxx todo: good guess if (mpAnim) (*mpAnim)( getPresentationValue( maValues.back() ) ); } - + /// Disposable: virtual void dispose() { mpAnim.reset(); BaseType::dispose(); } - + private: ValueVectorType maValues; - + ExpressionNodeSharedPtr mpFormula; - + boost::shared_ptr<AnimationType> mpAnim; Interpolator< ValueType > maInterpolator; bool mbCumulative; }; /** Generate Activity corresponding to given Value vector - + @tpl BaseType BaseType to use for deriving the Activity from - + @tpl AnimationType Subtype of the Animation object (e.g. NumberAnimation) */ @@ -580,19 +580,19 @@ AnimationActivitySharedPtr createValueListActivity( { typedef typename AnimationType::ValueType ValueType; typedef std::vector<ValueType> ValueVectorType; - - ValueVectorType aValueVector; + + ValueVectorType aValueVector; aValueVector.reserve( rValues.getLength() ); - + for( ::std::size_t i=0, nLen=rValues.getLength(); i<nLen; ++i ) { - ValueType aValue; + ValueType aValue; ENSURE_OR_THROW( extractValue( aValue, rValues[i], rShape, rSlideBounds ), "createValueListActivity(): Could not extract values" ); aValueVector.push_back( aValue ); } - + return AnimationActivitySharedPtr( new ValuesActivity<BaseType, AnimationType>( aValueVector, @@ -603,20 +603,20 @@ AnimationActivitySharedPtr createValueListActivity( } /** Generate Activity for given XAnimate, corresponding to given Value vector - + @tpl AnimationType Subtype of the Animation object (e.g. NumberAnimation) - + @param rParms Common activity parameters - + @param xNode XAnimate node, to retrieve animation values from - + @param rAnim Actual animation to operate with (gets called with the time-dependent values) - + @param rInterpolator Interpolator object to be used for lerping between start and end values (need to be passed, since it @@ -633,7 +633,7 @@ AnimationActivitySharedPtr createActivity( { // setup common parameters // ======================= - + ActivityParameters aActivityParms( rParms.mpEndEvent, rParms.mrEventQueue, rParms.mrActivitiesQueue, @@ -643,75 +643,75 @@ AnimationActivitySharedPtr createActivity( rParms.mnDeceleration, rParms.mnMinNumberOfFrames, rParms.mbAutoReverse ); - - // is a formula given? + + // is a formula given? const ::rtl::OUString& rFormulaString( xNode->getFormula() ); if( rFormulaString.getLength() ) { // yep, parse and pass to ActivityParameters - try + try { - aActivityParms.mpFormula = + aActivityParms.mpFormula = SmilFunctionParser::parseSmilFunction( rFormulaString, calcRelativeShapeBounds( rParms.maSlideBounds, rParms.mpShape->getBounds() ) ); } - catch( ParseError& ) + catch( ParseError& ) { // parse error, thus no formula OSL_ENSURE( false, "createActivity(): Error parsing formula string" ); } } - + // are key times given? const uno::Sequence< double >& aKeyTimes( xNode->getKeyTimes() ); - if( aKeyTimes.hasElements() ) + if( aKeyTimes.hasElements() ) { // yes, convert them from Sequence< double > aActivityParms.maDiscreteTimes.resize( aKeyTimes.getLength() ); comphelper::sequenceToArray( - &aActivityParms.maDiscreteTimes[0], + &aActivityParms.maDiscreteTimes[0], aKeyTimes ); // saves us some temporary vectors } - + // values sequence given? const sal_Int32 nValueLen( xNode->getValues().getLength() ); - if( nValueLen ) + if( nValueLen ) { // Value list activity // =================== - + // fake keytimes, if necessary - if( !aKeyTimes.hasElements() ) + if( !aKeyTimes.hasElements() ) { // create a dummy vector of key times, // with aValues.getLength equally spaced entries. for( sal_Int32 i=0; i<nValueLen; ++i ) aActivityParms.maDiscreteTimes.push_back( double(i)/nValueLen ); } - + // determine type of animation needed here: // Value list activities are possible with // ContinuousKeyTimeActivityBase and DiscreteActivityBase // specializations const sal_Int16 nCalcMode( xNode->getCalcMode() ); - - switch( nCalcMode ) + + switch( nCalcMode ) { - case animations::AnimationCalcMode::DISCRETE: + case animations::AnimationCalcMode::DISCRETE: { // since DiscreteActivityBase suspends itself // between the frames, create a WakeupEvent for it. - aActivityParms.mpWakeupEvent.reset( + aActivityParms.mpWakeupEvent.reset( new WakeupEvent( rParms.mrEventQueue.getTimer(), rParms.mrActivitiesQueue ) ); - + AnimationActivitySharedPtr pActivity( - createValueListActivity< DiscreteActivityBase >( + createValueListActivity< DiscreteActivityBase >( xNode->getValues(), aActivityParms, rAnim, @@ -719,23 +719,23 @@ AnimationActivitySharedPtr createActivity( xNode->getAccumulate(), rParms.mpShape, rParms.maSlideBounds ) ); - + // WakeupEvent and DiscreteActivityBase need circular // references to the corresponding other object. aActivityParms.mpWakeupEvent->setActivity( pActivity ); - + return pActivity; } - + default: OSL_ENSURE( false, "createActivity(): unexpected case" ); - // FALLTHROUGH intended + // FALLTHROUGH intended case animations::AnimationCalcMode::PACED: // FALLTHROUGH intended case animations::AnimationCalcMode::SPLINE: // FALLTHROUGH intended case animations::AnimationCalcMode::LINEAR: - return createValueListActivity< ContinuousKeyTimeActivityBase >( + return createValueListActivity< ContinuousKeyTimeActivityBase >( xNode->getValues(), aActivityParms, rAnim, @@ -745,39 +745,39 @@ AnimationActivitySharedPtr createActivity( rParms.maSlideBounds ); } } - else + else { // FromToBy activity // ================= - + // determine type of animation needed here: // FromToBy activities are possible with // ContinuousActivityBase and DiscreteActivityBase // specializations const sal_Int16 nCalcMode( xNode->getCalcMode() ); - - switch( nCalcMode ) + + switch( nCalcMode ) { - case animations::AnimationCalcMode::DISCRETE: + case animations::AnimationCalcMode::DISCRETE: { // fake keytimes, if necessary - if( !aKeyTimes.hasElements() ) + if( !aKeyTimes.hasElements() ) { // create a dummy vector of 2 key times const ::std::size_t nLen( 2 ); for( ::std::size_t i=0; i<nLen; ++i ) aActivityParms.maDiscreteTimes.push_back( double(i)/nLen ); } - + // since DiscreteActivityBase suspends itself // between the frames, create a WakeupEvent for it. - aActivityParms.mpWakeupEvent.reset( + aActivityParms.mpWakeupEvent.reset( new WakeupEvent( rParms.mrEventQueue.getTimer(), rParms.mrActivitiesQueue ) ); - + AnimationActivitySharedPtr pActivity( - createFromToByActivity< DiscreteActivityBase >( + createFromToByActivity< DiscreteActivityBase >( xNode->getFrom(), xNode->getTo(), xNode->getBy(), @@ -787,23 +787,23 @@ AnimationActivitySharedPtr createActivity( xNode->getAccumulate(), rParms.mpShape, rParms.maSlideBounds ) ); - + // WakeupEvent and DiscreteActivityBase need circular // references to the corresponding other object. aActivityParms.mpWakeupEvent->setActivity( pActivity ); - + return pActivity; } - + default: OSL_ENSURE( false, "createActivity(): unexpected case" ); - // FALLTHROUGH intended + // FALLTHROUGH intended case animations::AnimationCalcMode::PACED: // FALLTHROUGH intended case animations::AnimationCalcMode::SPLINE: // FALLTHROUGH intended case animations::AnimationCalcMode::LINEAR: - return createFromToByActivity< ContinuousActivityBase >( + return createFromToByActivity< ContinuousActivityBase >( xNode->getFrom(), xNode->getTo(), xNode->getBy(), @@ -818,7 +818,7 @@ AnimationActivitySharedPtr createActivity( } /** Simple activity for ActivitiesFactory::createSimpleActivity - + @tpl Direction Determines direction of value generator. A 1 yields a forward direction, starting with 0.0 and ending with @@ -830,7 +830,7 @@ class SimpleActivity : public ContinuousActivityBase { public: /** Create SimpleActivity. - + @param rParms Standard Activity parameter struct */ @@ -841,18 +841,18 @@ public: { ENSURE_OR_THROW( mpAnim, "Invalid animation object" ); } - + virtual void startAnimation() { if (this->isDisposed() || !mpAnim) return; ContinuousActivityBase::startAnimation(); - + // start animation mpAnim->start( getShape(), getShapeAttributeLayer() ); } - + virtual void endAnimation() { // end animation @@ -870,21 +870,21 @@ public: // no cumulation, simple [0,1] range (*mpAnim)( 1.0 - Direction + nModifiedTime*(2.0*Direction - 1.0) ); } - + virtual void performEnd() { // xxx todo: review if (mpAnim) (*mpAnim)( 1.0*Direction ); } - + /// Disposable: virtual void dispose() { mpAnim.reset(); ContinuousActivityBase::dispose(); } - + private: NumberAnimationSharedPtr mpAnim; }; @@ -894,7 +894,7 @@ private: AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( const CommonParameters& rParms, - const NumberAnimationSharedPtr& rAnim, + const NumberAnimationSharedPtr& rAnim, const uno::Reference< animations::XAnimate >& xNode ) { // forward to appropriate template instantiation @@ -903,7 +903,7 @@ AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( const CommonParameters& rParms, - const EnumAnimationSharedPtr& rAnim, + const EnumAnimationSharedPtr& rAnim, const uno::Reference< animations::XAnimate >& xNode ) { // forward to appropriate template instantiation @@ -912,7 +912,7 @@ AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( const CommonParameters& rParms, - const ColorAnimationSharedPtr& rAnim, + const ColorAnimationSharedPtr& rAnim, const uno::Reference< animations::XAnimate >& xNode ) { // forward to appropriate template instantiation @@ -921,7 +921,7 @@ AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( const CommonParameters& rParms, - const HSLColorAnimationSharedPtr& rAnim, + const HSLColorAnimationSharedPtr& rAnim, const uno::Reference< animations::XAnimateColor >& xNode ) { // forward to appropriate template instantiation @@ -935,7 +935,7 @@ AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( const CommonParameters& rParms, - const PairAnimationSharedPtr& rAnim, + const PairAnimationSharedPtr& rAnim, const uno::Reference< animations::XAnimate >& xNode ) { // forward to appropriate template instantiation @@ -944,7 +944,7 @@ AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( const CommonParameters& rParms, - const StringAnimationSharedPtr& rAnim, + const StringAnimationSharedPtr& rAnim, const uno::Reference< animations::XAnimate >& xNode ) { // forward to appropriate template instantiation @@ -953,7 +953,7 @@ AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( const CommonParameters& rParms, - const BoolAnimationSharedPtr& rAnim, + const BoolAnimationSharedPtr& rAnim, const uno::Reference< animations::XAnimate >& xNode ) { // forward to appropriate template instantiation @@ -974,7 +974,7 @@ AnimationActivitySharedPtr ActivitiesFactory::createSimpleActivity( rParms.mnDeceleration, rParms.mnMinNumberOfFrames, rParms.mbAutoReverse ); - + if( bDirectionForward ) return AnimationActivitySharedPtr( new SimpleActivity<1>( aActivityParms, rAnim ) ); |