1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_slideshow.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir // must be first 32*cdf0e10cSrcweir #include <canvas/debug.hxx> 33*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 34*cdf0e10cSrcweir #include <canvas/verbosetrace.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <com/sun/star/animations/AnimationCalcMode.hpp> 37*cdf0e10cSrcweir #include <comphelper/sequence.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include "activitiesfactory.hxx" 40*cdf0e10cSrcweir #include "smilfunctionparser.hxx" 41*cdf0e10cSrcweir #include "accumulation.hxx" 42*cdf0e10cSrcweir #include "activityparameters.hxx" 43*cdf0e10cSrcweir #include "interpolation.hxx" 44*cdf0e10cSrcweir #include "tools.hxx" 45*cdf0e10cSrcweir #include "simplecontinuousactivitybase.hxx" 46*cdf0e10cSrcweir #include "discreteactivitybase.hxx" 47*cdf0e10cSrcweir #include "continuousactivitybase.hxx" 48*cdf0e10cSrcweir #include "continuouskeytimeactivitybase.hxx" 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir #include <boost/bind.hpp> 51*cdf0e10cSrcweir #include <boost/optional.hpp> 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir #include <cmath> // for modf 54*cdf0e10cSrcweir #include <vector> 55*cdf0e10cSrcweir #include <algorithm> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir using namespace com::sun::star; 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir namespace slideshow { 60*cdf0e10cSrcweir namespace internal { 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir namespace { 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir /** Traits template, to take formula application only for ValueType = double 65*cdf0e10cSrcweir */ 66*cdf0e10cSrcweir template<typename ValueType> struct FormulaTraits 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir static ValueType getPresentationValue( 69*cdf0e10cSrcweir const ValueType& rVal, const ExpressionNodeSharedPtr& ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir return rVal; 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir }; 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir /// Specialization for ValueType = double 76*cdf0e10cSrcweir template<> struct FormulaTraits<double> 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir static double getPresentationValue( 79*cdf0e10cSrcweir double const& rVal, ExpressionNodeSharedPtr const& rFormula ) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir return rFormula ? (*rFormula)(rVal) : rVal; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir }; 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir // Various ActivityBase specializations for different animator types 86*cdf0e10cSrcweir // ================================================================= 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir /** FromToBy handler 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir Provides the Activity specializations for FromToBy 91*cdf0e10cSrcweir animations (e.g. those without a values list). 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir This template makes heavy use of SFINAE, only one of 94*cdf0e10cSrcweir the perform*() methods will compile for each of the 95*cdf0e10cSrcweir base classes. 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir Note that we omit the virtual keyword on the perform() 98*cdf0e10cSrcweir overrides on purpose; those that actually do override 99*cdf0e10cSrcweir baseclass virtual methods inherit the property, and 100*cdf0e10cSrcweir the others won't increase our vtable. What's more, 101*cdf0e10cSrcweir having all perform() method in the vtable actually 102*cdf0e10cSrcweir creates POIs for them, which breaks the whole SFINAE 103*cdf0e10cSrcweir concept (IOW, this template won't compile any longer). 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir @tpl BaseType 106*cdf0e10cSrcweir Base class to use for this activity. Only 107*cdf0e10cSrcweir ContinuousActivityBase and DiscreteActivityBase are 108*cdf0e10cSrcweir supported here. 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir @tpl AnimationType 111*cdf0e10cSrcweir Type of the Animation to call. 112*cdf0e10cSrcweir */ 113*cdf0e10cSrcweir template<class BaseType, typename AnimationType> 114*cdf0e10cSrcweir class FromToByActivity : public BaseType 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir public: 117*cdf0e10cSrcweir typedef typename AnimationType::ValueType ValueType; 118*cdf0e10cSrcweir typedef boost::optional<ValueType> OptionalValueType; 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir private: 121*cdf0e10cSrcweir // some compilers don't inline whose definition they haven't 122*cdf0e10cSrcweir // seen before the call site... 123*cdf0e10cSrcweir ValueType getPresentationValue( const ValueType& rVal ) const 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir return FormulaTraits<ValueType>::getPresentationValue( rVal, mpFormula); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir public: 129*cdf0e10cSrcweir /** Create FromToByActivity. 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir @param rFrom 132*cdf0e10cSrcweir From this value, the animation starts 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir @param rTo 135*cdf0e10cSrcweir With this value, the animation ends 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir @param rBy 138*cdf0e10cSrcweir With this value, the animation increments the start value 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir @param rParms 141*cdf0e10cSrcweir Standard Activity parameter struct 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir @param rAnim 144*cdf0e10cSrcweir Shared ptr to AnimationType 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir @param rInterpolator 147*cdf0e10cSrcweir Interpolator object to be used for lerping between 148*cdf0e10cSrcweir start and end value (need to be passed, since it 149*cdf0e10cSrcweir might contain state, e.g. interpolation direction 150*cdf0e10cSrcweir for HSL color space). 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir @param bCumulative 153*cdf0e10cSrcweir Whether repeated animations should cumulate the 154*cdf0e10cSrcweir value, or start fresh each time. 155*cdf0e10cSrcweir */ 156*cdf0e10cSrcweir FromToByActivity( 157*cdf0e10cSrcweir const OptionalValueType& rFrom, 158*cdf0e10cSrcweir const OptionalValueType& rTo, 159*cdf0e10cSrcweir const OptionalValueType& rBy, 160*cdf0e10cSrcweir const ActivityParameters& rParms, 161*cdf0e10cSrcweir const ::boost::shared_ptr< AnimationType >& rAnim, 162*cdf0e10cSrcweir const Interpolator< ValueType >& rInterpolator, 163*cdf0e10cSrcweir bool bCumulative ) 164*cdf0e10cSrcweir : BaseType( rParms ), 165*cdf0e10cSrcweir maFrom( rFrom ), 166*cdf0e10cSrcweir maTo( rTo ), 167*cdf0e10cSrcweir maBy( rBy ), 168*cdf0e10cSrcweir mpFormula( rParms.mpFormula ), 169*cdf0e10cSrcweir maStartValue(), 170*cdf0e10cSrcweir maEndValue(), 171*cdf0e10cSrcweir mpAnim( rAnim ), 172*cdf0e10cSrcweir maInterpolator( rInterpolator ), 173*cdf0e10cSrcweir mbDynamicStartValue( false ), 174*cdf0e10cSrcweir mbCumulative( bCumulative ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir ENSURE_OR_THROW( mpAnim, "Invalid animation object" ); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir ENSURE_OR_THROW( 179*cdf0e10cSrcweir rTo || rBy, 180*cdf0e10cSrcweir "From and one of To or By, or To or By alone must be valid" ); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir virtual void startAnimation() 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir if (this->isDisposed() || !mpAnim) 186*cdf0e10cSrcweir return; 187*cdf0e10cSrcweir BaseType::startAnimation(); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir // start animation 190*cdf0e10cSrcweir mpAnim->start( BaseType::getShape(), 191*cdf0e10cSrcweir BaseType::getShapeAttributeLayer() ); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir // setup start and end value. Determine animation 194*cdf0e10cSrcweir // start value only when animation actually 195*cdf0e10cSrcweir // started up (this order is part of the Animation 196*cdf0e10cSrcweir // interface contract) 197*cdf0e10cSrcweir const ValueType aAnimationStartValue( mpAnim->getUnderlyingValue() ); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir // first of all, determine general type of 200*cdf0e10cSrcweir // animation, by inspecting which of the FromToBy values 201*cdf0e10cSrcweir // are actually valid. 202*cdf0e10cSrcweir // See http://www.w3.org/TR/smil20/animation.html#AnimationNS-FromToBy 203*cdf0e10cSrcweir // for a definition 204*cdf0e10cSrcweir if( maFrom ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir // From-to or From-by animation. According to 207*cdf0e10cSrcweir // SMIL spec, the To value takes precedence 208*cdf0e10cSrcweir // over the By value, if both are specified 209*cdf0e10cSrcweir if( maTo ) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir // From-To animation 212*cdf0e10cSrcweir maStartValue = *maFrom; 213*cdf0e10cSrcweir maEndValue = *maTo; 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir else if( maBy ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir // From-By animation 218*cdf0e10cSrcweir maStartValue = *maFrom; 219*cdf0e10cSrcweir maEndValue = maStartValue + *maBy; 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir else 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir // By or To animation. According to SMIL spec, 225*cdf0e10cSrcweir // the To value takes precedence over the By 226*cdf0e10cSrcweir // value, if both are specified 227*cdf0e10cSrcweir if( maTo ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir // To animation 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir // According to the SMIL spec 232*cdf0e10cSrcweir // (http://www.w3.org/TR/smil20/animation.html#animationNS-ToAnimation), 233*cdf0e10cSrcweir // the to animation interpolates between 234*cdf0e10cSrcweir // the _running_ underlying value and the to value (as the end value) 235*cdf0e10cSrcweir mbDynamicStartValue = true; 236*cdf0e10cSrcweir maEndValue = *maTo; 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir else if( maBy ) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir // By animation 241*cdf0e10cSrcweir maStartValue = aAnimationStartValue; 242*cdf0e10cSrcweir maEndValue = maStartValue + *maBy; 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir virtual void endAnimation() 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir // end animation 250*cdf0e10cSrcweir if (mpAnim) 251*cdf0e10cSrcweir mpAnim->end(); 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir /// perform override for ContinuousActivityBase 255*cdf0e10cSrcweir void perform( double nModifiedTime, sal_uInt32 nRepeatCount ) const 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir if (this->isDisposed() || !mpAnim) 258*cdf0e10cSrcweir return; 259*cdf0e10cSrcweir (*mpAnim)( 260*cdf0e10cSrcweir getPresentationValue( 261*cdf0e10cSrcweir accumulate( maEndValue, 262*cdf0e10cSrcweir mbCumulative * nRepeatCount, // means: mbCumulative ? nRepeatCount : 0, 263*cdf0e10cSrcweir maInterpolator( (mbDynamicStartValue 264*cdf0e10cSrcweir ? mpAnim->getUnderlyingValue() 265*cdf0e10cSrcweir : maStartValue), 266*cdf0e10cSrcweir maEndValue, 267*cdf0e10cSrcweir nModifiedTime ) ) ) ); 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir using BaseType::perform; 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir /// perform override for DiscreteActivityBase base 273*cdf0e10cSrcweir void perform( sal_uInt32 nFrame, sal_uInt32 nRepeatCount ) const 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir if (this->isDisposed() || !mpAnim) 276*cdf0e10cSrcweir return; 277*cdf0e10cSrcweir (*mpAnim)( 278*cdf0e10cSrcweir getPresentationValue( 279*cdf0e10cSrcweir accumulate( maEndValue, mbCumulative ? nRepeatCount : 0, 280*cdf0e10cSrcweir lerp( maInterpolator, 281*cdf0e10cSrcweir (mbDynamicStartValue 282*cdf0e10cSrcweir ? mpAnim->getUnderlyingValue() 283*cdf0e10cSrcweir : maStartValue), 284*cdf0e10cSrcweir maEndValue, 285*cdf0e10cSrcweir nFrame, 286*cdf0e10cSrcweir BaseType::getNumberOfKeyTimes() ) ) ) ); 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir using BaseType::isAutoReverse; 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir virtual void performEnd() 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir // xxx todo: good guess 294*cdf0e10cSrcweir if (mpAnim) 295*cdf0e10cSrcweir { 296*cdf0e10cSrcweir if (isAutoReverse()) 297*cdf0e10cSrcweir (*mpAnim)( getPresentationValue( maStartValue ) ); 298*cdf0e10cSrcweir else 299*cdf0e10cSrcweir (*mpAnim)( getPresentationValue( maEndValue ) ); 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir /// Disposable: 304*cdf0e10cSrcweir virtual void dispose() 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir mpAnim.reset(); 307*cdf0e10cSrcweir BaseType::dispose(); 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir private: 311*cdf0e10cSrcweir const OptionalValueType maFrom; 312*cdf0e10cSrcweir const OptionalValueType maTo; 313*cdf0e10cSrcweir const OptionalValueType maBy; 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir ExpressionNodeSharedPtr mpFormula; 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir ValueType maStartValue; 318*cdf0e10cSrcweir ValueType maEndValue; 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir ::boost::shared_ptr< AnimationType > mpAnim; 321*cdf0e10cSrcweir Interpolator< ValueType > maInterpolator; 322*cdf0e10cSrcweir bool mbDynamicStartValue; 323*cdf0e10cSrcweir bool mbCumulative; 324*cdf0e10cSrcweir }; 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir /** Generate Activity corresponding to given FromToBy values 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir @tpl BaseType 330*cdf0e10cSrcweir BaseType to use for deriving the Activity from 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir @tpl AnimationType 333*cdf0e10cSrcweir Subtype of the Animation object (e.g. NumberAnimation) 334*cdf0e10cSrcweir */ 335*cdf0e10cSrcweir template<class BaseType, typename AnimationType> 336*cdf0e10cSrcweir AnimationActivitySharedPtr createFromToByActivity( 337*cdf0e10cSrcweir const uno::Any& rFromAny, 338*cdf0e10cSrcweir const uno::Any& rToAny, 339*cdf0e10cSrcweir const uno::Any& rByAny, 340*cdf0e10cSrcweir const ActivityParameters& rParms, 341*cdf0e10cSrcweir const ::boost::shared_ptr< AnimationType >& rAnim, 342*cdf0e10cSrcweir const Interpolator< typename AnimationType::ValueType >& rInterpolator, 343*cdf0e10cSrcweir bool bCumulative, 344*cdf0e10cSrcweir const ShapeSharedPtr& rShape, 345*cdf0e10cSrcweir const ::basegfx::B2DVector& rSlideBounds ) 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir typedef typename AnimationType::ValueType ValueType; 348*cdf0e10cSrcweir typedef boost::optional<ValueType> OptionalValueType; 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir OptionalValueType aFrom; 351*cdf0e10cSrcweir OptionalValueType aTo; 352*cdf0e10cSrcweir OptionalValueType aBy; 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir ValueType aTmpValue; 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir if( rFromAny.hasValue() ) 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir ENSURE_OR_THROW( 359*cdf0e10cSrcweir extractValue( aTmpValue, rFromAny, rShape, rSlideBounds ), 360*cdf0e10cSrcweir "createFromToByActivity(): Could not extract from value" ); 361*cdf0e10cSrcweir aFrom.reset(aTmpValue); 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir if( rToAny.hasValue() ) 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir ENSURE_OR_THROW( 366*cdf0e10cSrcweir extractValue( aTmpValue, rToAny, rShape, rSlideBounds ), 367*cdf0e10cSrcweir "createFromToByActivity(): Could not extract to value" ); 368*cdf0e10cSrcweir aTo.reset(aTmpValue); 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir if( rByAny.hasValue() ) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir ENSURE_OR_THROW( 373*cdf0e10cSrcweir extractValue( aTmpValue, rByAny, rShape, rSlideBounds ), 374*cdf0e10cSrcweir "createFromToByActivity(): Could not extract by value" ); 375*cdf0e10cSrcweir aBy.reset(aTmpValue); 376*cdf0e10cSrcweir } 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir return AnimationActivitySharedPtr( 379*cdf0e10cSrcweir new FromToByActivity<BaseType, AnimationType>( 380*cdf0e10cSrcweir aFrom, 381*cdf0e10cSrcweir aTo, 382*cdf0e10cSrcweir aBy, 383*cdf0e10cSrcweir rParms, 384*cdf0e10cSrcweir rAnim, 385*cdf0e10cSrcweir rInterpolator, 386*cdf0e10cSrcweir bCumulative ) ); 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir /* The following table shows which animator combines with 390*cdf0e10cSrcweir which Activity type: 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir NumberAnimator: all 393*cdf0e10cSrcweir PairAnimation: all 394*cdf0e10cSrcweir ColorAnimation: all 395*cdf0e10cSrcweir StringAnimation: DiscreteActivityBase 396*cdf0e10cSrcweir BoolAnimation: DiscreteActivityBase 397*cdf0e10cSrcweir */ 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir /** Values handler 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir Provides the Activity specializations for value lists 402*cdf0e10cSrcweir animations. 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir This template makes heavy use of SFINAE, only one of 405*cdf0e10cSrcweir the perform*() methods will compile for each of the 406*cdf0e10cSrcweir base classes. 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir Note that we omit the virtual keyword on the perform() 409*cdf0e10cSrcweir overrides on purpose; those that actually do override 410*cdf0e10cSrcweir baseclass virtual methods inherit the property, and 411*cdf0e10cSrcweir the others won't increase our vtable. What's more, 412*cdf0e10cSrcweir having all perform() method in the vtable actually 413*cdf0e10cSrcweir creates POIs for them, which breaks the whole SFINAE 414*cdf0e10cSrcweir concept (IOW, this template won't compile any longer). 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir @tpl BaseType 417*cdf0e10cSrcweir Base class to use for this activity. Only 418*cdf0e10cSrcweir ContinuousKeyTimeActivityBase and DiscreteActivityBase 419*cdf0e10cSrcweir are supported here. For values animation without key 420*cdf0e10cSrcweir times, the client must emulate key times by providing 421*cdf0e10cSrcweir a vector of equally spaced values between 0 and 1, 422*cdf0e10cSrcweir with the same number of entries as the values vector. 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir @tpl AnimationType 425*cdf0e10cSrcweir Type of the Animation to call. 426*cdf0e10cSrcweir */ 427*cdf0e10cSrcweir template<class BaseType, typename AnimationType> 428*cdf0e10cSrcweir class ValuesActivity : public BaseType 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir public: 431*cdf0e10cSrcweir typedef typename AnimationType::ValueType ValueType; 432*cdf0e10cSrcweir typedef std::vector<ValueType> ValueVectorType; 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir private: 435*cdf0e10cSrcweir // some compilers don't inline methods whose definition they haven't 436*cdf0e10cSrcweir // seen before the call site... 437*cdf0e10cSrcweir ValueType getPresentationValue( const ValueType& rVal ) const 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir return FormulaTraits<ValueType>::getPresentationValue( 440*cdf0e10cSrcweir rVal, mpFormula ); 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir public: 444*cdf0e10cSrcweir /** Create ValuesActivity. 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir @param rValues 447*cdf0e10cSrcweir Value vector to cycle animation through 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir @param rParms 450*cdf0e10cSrcweir Standard Activity parameter struct 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir @param rAnim 453*cdf0e10cSrcweir Shared ptr to AnimationType 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir @param rInterpolator 456*cdf0e10cSrcweir Interpolator object to be used for lerping between 457*cdf0e10cSrcweir start and end value (need to be passed, since it 458*cdf0e10cSrcweir might contain state, e.g. interpolation direction 459*cdf0e10cSrcweir for HSL color space). 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir @param bCumulative 462*cdf0e10cSrcweir Whether repeated animations should cumulate the 463*cdf0e10cSrcweir value, or start afresh each time. 464*cdf0e10cSrcweir */ 465*cdf0e10cSrcweir ValuesActivity( 466*cdf0e10cSrcweir const ValueVectorType& rValues, 467*cdf0e10cSrcweir const ActivityParameters& rParms, 468*cdf0e10cSrcweir const boost::shared_ptr<AnimationType>& rAnim, 469*cdf0e10cSrcweir const Interpolator< ValueType >& rInterpolator, 470*cdf0e10cSrcweir bool bCumulative ) 471*cdf0e10cSrcweir : BaseType( rParms ), 472*cdf0e10cSrcweir maValues( rValues ), 473*cdf0e10cSrcweir mpFormula( rParms.mpFormula ), 474*cdf0e10cSrcweir mpAnim( rAnim ), 475*cdf0e10cSrcweir maInterpolator( rInterpolator ), 476*cdf0e10cSrcweir mbCumulative( bCumulative ) 477*cdf0e10cSrcweir { 478*cdf0e10cSrcweir ENSURE_OR_THROW( mpAnim, "Invalid animation object" ); 479*cdf0e10cSrcweir ENSURE_OR_THROW( !rValues.empty(), "Empty value vector" ); 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir virtual void startAnimation() 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir if (this->isDisposed() || !mpAnim) 485*cdf0e10cSrcweir return; 486*cdf0e10cSrcweir BaseType::startAnimation(); 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir // start animation 489*cdf0e10cSrcweir mpAnim->start( BaseType::getShape(), 490*cdf0e10cSrcweir BaseType::getShapeAttributeLayer() ); 491*cdf0e10cSrcweir } 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir virtual void endAnimation() 494*cdf0e10cSrcweir { 495*cdf0e10cSrcweir // end animation 496*cdf0e10cSrcweir if (mpAnim) 497*cdf0e10cSrcweir mpAnim->end(); 498*cdf0e10cSrcweir } 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir /// perform override for ContinuousKeyTimeActivityBase base 501*cdf0e10cSrcweir void perform( sal_uInt32 nIndex, 502*cdf0e10cSrcweir double nFractionalIndex, 503*cdf0e10cSrcweir sal_uInt32 nRepeatCount ) const 504*cdf0e10cSrcweir { 505*cdf0e10cSrcweir if (this->isDisposed() || !mpAnim) 506*cdf0e10cSrcweir return; 507*cdf0e10cSrcweir ENSURE_OR_THROW( nIndex+1 < maValues.size(), 508*cdf0e10cSrcweir "ValuesActivity::perform(): index out of range" ); 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir // interpolate between nIndex and nIndex+1 values 511*cdf0e10cSrcweir (*mpAnim)( 512*cdf0e10cSrcweir getPresentationValue( 513*cdf0e10cSrcweir accumulate( maValues.back(), 514*cdf0e10cSrcweir mbCumulative ? nRepeatCount : 0, 515*cdf0e10cSrcweir maInterpolator( maValues[ nIndex ], 516*cdf0e10cSrcweir maValues[ nIndex+1 ], 517*cdf0e10cSrcweir nFractionalIndex ) ) ) ); 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir 520*cdf0e10cSrcweir using BaseType::perform; 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir /// perform override for DiscreteActivityBase base 523*cdf0e10cSrcweir void perform( sal_uInt32 nFrame, sal_uInt32 nRepeatCount ) const 524*cdf0e10cSrcweir { 525*cdf0e10cSrcweir if (this->isDisposed() || !mpAnim) 526*cdf0e10cSrcweir return; 527*cdf0e10cSrcweir ENSURE_OR_THROW( nFrame < maValues.size(), 528*cdf0e10cSrcweir "ValuesActivity::perform(): index out of range" ); 529*cdf0e10cSrcweir 530*cdf0e10cSrcweir // this is discrete, thus no lerp here. 531*cdf0e10cSrcweir (*mpAnim)( 532*cdf0e10cSrcweir getPresentationValue( 533*cdf0e10cSrcweir accumulate( maValues.back(), 534*cdf0e10cSrcweir mbCumulative ? nRepeatCount : 0, 535*cdf0e10cSrcweir maValues[ nFrame ] ) ) ); 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir virtual void performEnd() 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir // xxx todo: good guess 541*cdf0e10cSrcweir if (mpAnim) 542*cdf0e10cSrcweir (*mpAnim)( getPresentationValue( maValues.back() ) ); 543*cdf0e10cSrcweir } 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir /// Disposable: 546*cdf0e10cSrcweir virtual void dispose() 547*cdf0e10cSrcweir { 548*cdf0e10cSrcweir mpAnim.reset(); 549*cdf0e10cSrcweir BaseType::dispose(); 550*cdf0e10cSrcweir } 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir private: 553*cdf0e10cSrcweir ValueVectorType maValues; 554*cdf0e10cSrcweir 555*cdf0e10cSrcweir ExpressionNodeSharedPtr mpFormula; 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir boost::shared_ptr<AnimationType> mpAnim; 558*cdf0e10cSrcweir Interpolator< ValueType > maInterpolator; 559*cdf0e10cSrcweir bool mbCumulative; 560*cdf0e10cSrcweir }; 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir /** Generate Activity corresponding to given Value vector 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir @tpl BaseType 565*cdf0e10cSrcweir BaseType to use for deriving the Activity from 566*cdf0e10cSrcweir 567*cdf0e10cSrcweir @tpl AnimationType 568*cdf0e10cSrcweir Subtype of the Animation object (e.g. NumberAnimation) 569*cdf0e10cSrcweir */ 570*cdf0e10cSrcweir template<class BaseType, typename AnimationType> 571*cdf0e10cSrcweir AnimationActivitySharedPtr createValueListActivity( 572*cdf0e10cSrcweir const uno::Sequence<uno::Any>& rValues, 573*cdf0e10cSrcweir const ActivityParameters& rParms, 574*cdf0e10cSrcweir const boost::shared_ptr<AnimationType>& rAnim, 575*cdf0e10cSrcweir const Interpolator<typename AnimationType::ValueType>& rInterpolator, 576*cdf0e10cSrcweir bool bCumulative, 577*cdf0e10cSrcweir const ShapeSharedPtr& rShape, 578*cdf0e10cSrcweir const ::basegfx::B2DVector& rSlideBounds ) 579*cdf0e10cSrcweir { 580*cdf0e10cSrcweir typedef typename AnimationType::ValueType ValueType; 581*cdf0e10cSrcweir typedef std::vector<ValueType> ValueVectorType; 582*cdf0e10cSrcweir 583*cdf0e10cSrcweir ValueVectorType aValueVector; 584*cdf0e10cSrcweir aValueVector.reserve( rValues.getLength() ); 585*cdf0e10cSrcweir 586*cdf0e10cSrcweir for( ::std::size_t i=0, nLen=rValues.getLength(); i<nLen; ++i ) 587*cdf0e10cSrcweir { 588*cdf0e10cSrcweir ValueType aValue; 589*cdf0e10cSrcweir ENSURE_OR_THROW( 590*cdf0e10cSrcweir extractValue( aValue, rValues[i], rShape, rSlideBounds ), 591*cdf0e10cSrcweir "createValueListActivity(): Could not extract values" ); 592*cdf0e10cSrcweir aValueVector.push_back( aValue ); 593*cdf0e10cSrcweir } 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir return AnimationActivitySharedPtr( 596*cdf0e10cSrcweir new ValuesActivity<BaseType, AnimationType>( 597*cdf0e10cSrcweir aValueVector, 598*cdf0e10cSrcweir rParms, 599*cdf0e10cSrcweir rAnim, 600*cdf0e10cSrcweir rInterpolator, 601*cdf0e10cSrcweir bCumulative ) ); 602*cdf0e10cSrcweir } 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir /** Generate Activity for given XAnimate, corresponding to given Value vector 605*cdf0e10cSrcweir 606*cdf0e10cSrcweir @tpl AnimationType 607*cdf0e10cSrcweir Subtype of the Animation object (e.g. NumberAnimation) 608*cdf0e10cSrcweir 609*cdf0e10cSrcweir @param rParms 610*cdf0e10cSrcweir Common activity parameters 611*cdf0e10cSrcweir 612*cdf0e10cSrcweir @param xNode 613*cdf0e10cSrcweir XAnimate node, to retrieve animation values from 614*cdf0e10cSrcweir 615*cdf0e10cSrcweir @param rAnim 616*cdf0e10cSrcweir Actual animation to operate with (gets called with the 617*cdf0e10cSrcweir time-dependent values) 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir @param rInterpolator 620*cdf0e10cSrcweir Interpolator object to be used for lerping between 621*cdf0e10cSrcweir start and end values (need to be passed, since it 622*cdf0e10cSrcweir might contain state, e.g. interpolation direction 623*cdf0e10cSrcweir for HSL color space). 624*cdf0e10cSrcweir */ 625*cdf0e10cSrcweir template<typename AnimationType> 626*cdf0e10cSrcweir AnimationActivitySharedPtr createActivity( 627*cdf0e10cSrcweir const ActivitiesFactory::CommonParameters& rParms, 628*cdf0e10cSrcweir const uno::Reference< animations::XAnimate >& xNode, 629*cdf0e10cSrcweir const ::boost::shared_ptr< AnimationType >& rAnim, 630*cdf0e10cSrcweir const Interpolator< typename AnimationType::ValueType >& rInterpolator 631*cdf0e10cSrcweir = Interpolator< typename AnimationType::ValueType >() ) 632*cdf0e10cSrcweir { 633*cdf0e10cSrcweir // setup common parameters 634*cdf0e10cSrcweir // ======================= 635*cdf0e10cSrcweir 636*cdf0e10cSrcweir ActivityParameters aActivityParms( rParms.mpEndEvent, 637*cdf0e10cSrcweir rParms.mrEventQueue, 638*cdf0e10cSrcweir rParms.mrActivitiesQueue, 639*cdf0e10cSrcweir rParms.mnMinDuration, 640*cdf0e10cSrcweir rParms.maRepeats, 641*cdf0e10cSrcweir rParms.mnAcceleration, 642*cdf0e10cSrcweir rParms.mnDeceleration, 643*cdf0e10cSrcweir rParms.mnMinNumberOfFrames, 644*cdf0e10cSrcweir rParms.mbAutoReverse ); 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir // is a formula given? 647*cdf0e10cSrcweir const ::rtl::OUString& rFormulaString( xNode->getFormula() ); 648*cdf0e10cSrcweir if( rFormulaString.getLength() ) 649*cdf0e10cSrcweir { 650*cdf0e10cSrcweir // yep, parse and pass to ActivityParameters 651*cdf0e10cSrcweir try 652*cdf0e10cSrcweir { 653*cdf0e10cSrcweir aActivityParms.mpFormula = 654*cdf0e10cSrcweir SmilFunctionParser::parseSmilFunction( 655*cdf0e10cSrcweir rFormulaString, 656*cdf0e10cSrcweir calcRelativeShapeBounds( 657*cdf0e10cSrcweir rParms.maSlideBounds, 658*cdf0e10cSrcweir rParms.mpShape->getBounds() ) ); 659*cdf0e10cSrcweir } 660*cdf0e10cSrcweir catch( ParseError& ) 661*cdf0e10cSrcweir { 662*cdf0e10cSrcweir // parse error, thus no formula 663*cdf0e10cSrcweir OSL_ENSURE( false, 664*cdf0e10cSrcweir "createActivity(): Error parsing formula string" ); 665*cdf0e10cSrcweir } 666*cdf0e10cSrcweir } 667*cdf0e10cSrcweir 668*cdf0e10cSrcweir // are key times given? 669*cdf0e10cSrcweir const uno::Sequence< double >& aKeyTimes( xNode->getKeyTimes() ); 670*cdf0e10cSrcweir if( aKeyTimes.hasElements() ) 671*cdf0e10cSrcweir { 672*cdf0e10cSrcweir // yes, convert them from Sequence< double > 673*cdf0e10cSrcweir aActivityParms.maDiscreteTimes.resize( aKeyTimes.getLength() ); 674*cdf0e10cSrcweir comphelper::sequenceToArray( 675*cdf0e10cSrcweir &aActivityParms.maDiscreteTimes[0], 676*cdf0e10cSrcweir aKeyTimes ); // saves us some temporary vectors 677*cdf0e10cSrcweir } 678*cdf0e10cSrcweir 679*cdf0e10cSrcweir // values sequence given? 680*cdf0e10cSrcweir const sal_Int32 nValueLen( xNode->getValues().getLength() ); 681*cdf0e10cSrcweir if( nValueLen ) 682*cdf0e10cSrcweir { 683*cdf0e10cSrcweir // Value list activity 684*cdf0e10cSrcweir // =================== 685*cdf0e10cSrcweir 686*cdf0e10cSrcweir // fake keytimes, if necessary 687*cdf0e10cSrcweir if( !aKeyTimes.hasElements() ) 688*cdf0e10cSrcweir { 689*cdf0e10cSrcweir // create a dummy vector of key times, 690*cdf0e10cSrcweir // with aValues.getLength equally spaced entries. 691*cdf0e10cSrcweir for( sal_Int32 i=0; i<nValueLen; ++i ) 692*cdf0e10cSrcweir aActivityParms.maDiscreteTimes.push_back( double(i)/nValueLen ); 693*cdf0e10cSrcweir } 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir // determine type of animation needed here: 696*cdf0e10cSrcweir // Value list activities are possible with 697*cdf0e10cSrcweir // ContinuousKeyTimeActivityBase and DiscreteActivityBase 698*cdf0e10cSrcweir // specializations 699*cdf0e10cSrcweir const sal_Int16 nCalcMode( xNode->getCalcMode() ); 700*cdf0e10cSrcweir 701*cdf0e10cSrcweir switch( nCalcMode ) 702*cdf0e10cSrcweir { 703*cdf0e10cSrcweir case animations::AnimationCalcMode::DISCRETE: 704*cdf0e10cSrcweir { 705*cdf0e10cSrcweir // since DiscreteActivityBase suspends itself 706*cdf0e10cSrcweir // between the frames, create a WakeupEvent for it. 707*cdf0e10cSrcweir aActivityParms.mpWakeupEvent.reset( 708*cdf0e10cSrcweir new WakeupEvent( 709*cdf0e10cSrcweir rParms.mrEventQueue.getTimer(), 710*cdf0e10cSrcweir rParms.mrActivitiesQueue ) ); 711*cdf0e10cSrcweir 712*cdf0e10cSrcweir AnimationActivitySharedPtr pActivity( 713*cdf0e10cSrcweir createValueListActivity< DiscreteActivityBase >( 714*cdf0e10cSrcweir xNode->getValues(), 715*cdf0e10cSrcweir aActivityParms, 716*cdf0e10cSrcweir rAnim, 717*cdf0e10cSrcweir rInterpolator, 718*cdf0e10cSrcweir xNode->getAccumulate(), 719*cdf0e10cSrcweir rParms.mpShape, 720*cdf0e10cSrcweir rParms.maSlideBounds ) ); 721*cdf0e10cSrcweir 722*cdf0e10cSrcweir // WakeupEvent and DiscreteActivityBase need circular 723*cdf0e10cSrcweir // references to the corresponding other object. 724*cdf0e10cSrcweir aActivityParms.mpWakeupEvent->setActivity( pActivity ); 725*cdf0e10cSrcweir 726*cdf0e10cSrcweir return pActivity; 727*cdf0e10cSrcweir } 728*cdf0e10cSrcweir 729*cdf0e10cSrcweir default: 730*cdf0e10cSrcweir OSL_ENSURE( false, "createActivity(): unexpected case" ); 731*cdf0e10cSrcweir // FALLTHROUGH intended 732*cdf0e10cSrcweir case animations::AnimationCalcMode::PACED: 733*cdf0e10cSrcweir // FALLTHROUGH intended 734*cdf0e10cSrcweir case animations::AnimationCalcMode::SPLINE: 735*cdf0e10cSrcweir // FALLTHROUGH intended 736*cdf0e10cSrcweir case animations::AnimationCalcMode::LINEAR: 737*cdf0e10cSrcweir return createValueListActivity< ContinuousKeyTimeActivityBase >( 738*cdf0e10cSrcweir xNode->getValues(), 739*cdf0e10cSrcweir aActivityParms, 740*cdf0e10cSrcweir rAnim, 741*cdf0e10cSrcweir rInterpolator, 742*cdf0e10cSrcweir xNode->getAccumulate(), 743*cdf0e10cSrcweir rParms.mpShape, 744*cdf0e10cSrcweir rParms.maSlideBounds ); 745*cdf0e10cSrcweir } 746*cdf0e10cSrcweir } 747*cdf0e10cSrcweir else 748*cdf0e10cSrcweir { 749*cdf0e10cSrcweir // FromToBy activity 750*cdf0e10cSrcweir // ================= 751*cdf0e10cSrcweir 752*cdf0e10cSrcweir // determine type of animation needed here: 753*cdf0e10cSrcweir // FromToBy activities are possible with 754*cdf0e10cSrcweir // ContinuousActivityBase and DiscreteActivityBase 755*cdf0e10cSrcweir // specializations 756*cdf0e10cSrcweir const sal_Int16 nCalcMode( xNode->getCalcMode() ); 757*cdf0e10cSrcweir 758*cdf0e10cSrcweir switch( nCalcMode ) 759*cdf0e10cSrcweir { 760*cdf0e10cSrcweir case animations::AnimationCalcMode::DISCRETE: 761*cdf0e10cSrcweir { 762*cdf0e10cSrcweir // fake keytimes, if necessary 763*cdf0e10cSrcweir if( !aKeyTimes.hasElements() ) 764*cdf0e10cSrcweir { 765*cdf0e10cSrcweir // create a dummy vector of 2 key times 766*cdf0e10cSrcweir const ::std::size_t nLen( 2 ); 767*cdf0e10cSrcweir for( ::std::size_t i=0; i<nLen; ++i ) 768*cdf0e10cSrcweir aActivityParms.maDiscreteTimes.push_back( double(i)/nLen ); 769*cdf0e10cSrcweir } 770*cdf0e10cSrcweir 771*cdf0e10cSrcweir // since DiscreteActivityBase suspends itself 772*cdf0e10cSrcweir // between the frames, create a WakeupEvent for it. 773*cdf0e10cSrcweir aActivityParms.mpWakeupEvent.reset( 774*cdf0e10cSrcweir new WakeupEvent( 775*cdf0e10cSrcweir rParms.mrEventQueue.getTimer(), 776*cdf0e10cSrcweir rParms.mrActivitiesQueue ) ); 777*cdf0e10cSrcweir 778*cdf0e10cSrcweir AnimationActivitySharedPtr pActivity( 779*cdf0e10cSrcweir createFromToByActivity< DiscreteActivityBase >( 780*cdf0e10cSrcweir xNode->getFrom(), 781*cdf0e10cSrcweir xNode->getTo(), 782*cdf0e10cSrcweir xNode->getBy(), 783*cdf0e10cSrcweir aActivityParms, 784*cdf0e10cSrcweir rAnim, 785*cdf0e10cSrcweir rInterpolator, 786*cdf0e10cSrcweir xNode->getAccumulate(), 787*cdf0e10cSrcweir rParms.mpShape, 788*cdf0e10cSrcweir rParms.maSlideBounds ) ); 789*cdf0e10cSrcweir 790*cdf0e10cSrcweir // WakeupEvent and DiscreteActivityBase need circular 791*cdf0e10cSrcweir // references to the corresponding other object. 792*cdf0e10cSrcweir aActivityParms.mpWakeupEvent->setActivity( pActivity ); 793*cdf0e10cSrcweir 794*cdf0e10cSrcweir return pActivity; 795*cdf0e10cSrcweir } 796*cdf0e10cSrcweir 797*cdf0e10cSrcweir default: 798*cdf0e10cSrcweir OSL_ENSURE( false, "createActivity(): unexpected case" ); 799*cdf0e10cSrcweir // FALLTHROUGH intended 800*cdf0e10cSrcweir case animations::AnimationCalcMode::PACED: 801*cdf0e10cSrcweir // FALLTHROUGH intended 802*cdf0e10cSrcweir case animations::AnimationCalcMode::SPLINE: 803*cdf0e10cSrcweir // FALLTHROUGH intended 804*cdf0e10cSrcweir case animations::AnimationCalcMode::LINEAR: 805*cdf0e10cSrcweir return createFromToByActivity< ContinuousActivityBase >( 806*cdf0e10cSrcweir xNode->getFrom(), 807*cdf0e10cSrcweir xNode->getTo(), 808*cdf0e10cSrcweir xNode->getBy(), 809*cdf0e10cSrcweir aActivityParms, 810*cdf0e10cSrcweir rAnim, 811*cdf0e10cSrcweir rInterpolator, 812*cdf0e10cSrcweir xNode->getAccumulate(), 813*cdf0e10cSrcweir rParms.mpShape, 814*cdf0e10cSrcweir rParms.maSlideBounds ); 815*cdf0e10cSrcweir } 816*cdf0e10cSrcweir } 817*cdf0e10cSrcweir } 818*cdf0e10cSrcweir 819*cdf0e10cSrcweir /** Simple activity for ActivitiesFactory::createSimpleActivity 820*cdf0e10cSrcweir 821*cdf0e10cSrcweir @tpl Direction 822*cdf0e10cSrcweir Determines direction of value generator. A 1 yields a 823*cdf0e10cSrcweir forward direction, starting with 0.0 and ending with 824*cdf0e10cSrcweir 1.0. A 0 yields a backward direction, starting with 825*cdf0e10cSrcweir 1.0 and ending with 0.0 826*cdf0e10cSrcweir */ 827*cdf0e10cSrcweir template<int Direction> 828*cdf0e10cSrcweir class SimpleActivity : public ContinuousActivityBase 829*cdf0e10cSrcweir { 830*cdf0e10cSrcweir public: 831*cdf0e10cSrcweir /** Create SimpleActivity. 832*cdf0e10cSrcweir 833*cdf0e10cSrcweir @param rParms 834*cdf0e10cSrcweir Standard Activity parameter struct 835*cdf0e10cSrcweir */ 836*cdf0e10cSrcweir SimpleActivity( const ActivityParameters& rParms, 837*cdf0e10cSrcweir const NumberAnimationSharedPtr& rAnim ) : 838*cdf0e10cSrcweir ContinuousActivityBase( rParms ), 839*cdf0e10cSrcweir mpAnim( rAnim ) 840*cdf0e10cSrcweir { 841*cdf0e10cSrcweir ENSURE_OR_THROW( mpAnim, "Invalid animation object" ); 842*cdf0e10cSrcweir } 843*cdf0e10cSrcweir 844*cdf0e10cSrcweir virtual void startAnimation() 845*cdf0e10cSrcweir { 846*cdf0e10cSrcweir if (this->isDisposed() || !mpAnim) 847*cdf0e10cSrcweir return; 848*cdf0e10cSrcweir ContinuousActivityBase::startAnimation(); 849*cdf0e10cSrcweir 850*cdf0e10cSrcweir // start animation 851*cdf0e10cSrcweir mpAnim->start( getShape(), 852*cdf0e10cSrcweir getShapeAttributeLayer() ); 853*cdf0e10cSrcweir } 854*cdf0e10cSrcweir 855*cdf0e10cSrcweir virtual void endAnimation() 856*cdf0e10cSrcweir { 857*cdf0e10cSrcweir // end animation 858*cdf0e10cSrcweir if (mpAnim) 859*cdf0e10cSrcweir mpAnim->end(); 860*cdf0e10cSrcweir } 861*cdf0e10cSrcweir 862*cdf0e10cSrcweir using SimpleContinuousActivityBase::perform; 863*cdf0e10cSrcweir 864*cdf0e10cSrcweir /// perform override for ContinuousActivityBase 865*cdf0e10cSrcweir virtual void perform( double nModifiedTime, sal_uInt32 ) const 866*cdf0e10cSrcweir { 867*cdf0e10cSrcweir if (this->isDisposed() || !mpAnim) 868*cdf0e10cSrcweir return; 869*cdf0e10cSrcweir // no cumulation, simple [0,1] range 870*cdf0e10cSrcweir (*mpAnim)( 1.0 - Direction + nModifiedTime*(2.0*Direction - 1.0) ); 871*cdf0e10cSrcweir } 872*cdf0e10cSrcweir 873*cdf0e10cSrcweir virtual void performEnd() 874*cdf0e10cSrcweir { 875*cdf0e10cSrcweir // xxx todo: review 876*cdf0e10cSrcweir if (mpAnim) 877*cdf0e10cSrcweir (*mpAnim)( 1.0*Direction ); 878*cdf0e10cSrcweir } 879*cdf0e10cSrcweir 880*cdf0e10cSrcweir /// Disposable: 881*cdf0e10cSrcweir virtual void dispose() 882*cdf0e10cSrcweir { 883*cdf0e10cSrcweir mpAnim.reset(); 884*cdf0e10cSrcweir ContinuousActivityBase::dispose(); 885*cdf0e10cSrcweir } 886*cdf0e10cSrcweir 887*cdf0e10cSrcweir private: 888*cdf0e10cSrcweir NumberAnimationSharedPtr mpAnim; 889*cdf0e10cSrcweir }; 890*cdf0e10cSrcweir 891*cdf0e10cSrcweir } // anon namespace 892*cdf0e10cSrcweir 893*cdf0e10cSrcweir 894*cdf0e10cSrcweir AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( 895*cdf0e10cSrcweir const CommonParameters& rParms, 896*cdf0e10cSrcweir const NumberAnimationSharedPtr& rAnim, 897*cdf0e10cSrcweir const uno::Reference< animations::XAnimate >& xNode ) 898*cdf0e10cSrcweir { 899*cdf0e10cSrcweir // forward to appropriate template instantiation 900*cdf0e10cSrcweir return createActivity( rParms, xNode, rAnim ); 901*cdf0e10cSrcweir } 902*cdf0e10cSrcweir 903*cdf0e10cSrcweir AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( 904*cdf0e10cSrcweir const CommonParameters& rParms, 905*cdf0e10cSrcweir const EnumAnimationSharedPtr& rAnim, 906*cdf0e10cSrcweir const uno::Reference< animations::XAnimate >& xNode ) 907*cdf0e10cSrcweir { 908*cdf0e10cSrcweir // forward to appropriate template instantiation 909*cdf0e10cSrcweir return createActivity( rParms, xNode, rAnim ); 910*cdf0e10cSrcweir } 911*cdf0e10cSrcweir 912*cdf0e10cSrcweir AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( 913*cdf0e10cSrcweir const CommonParameters& rParms, 914*cdf0e10cSrcweir const ColorAnimationSharedPtr& rAnim, 915*cdf0e10cSrcweir const uno::Reference< animations::XAnimate >& xNode ) 916*cdf0e10cSrcweir { 917*cdf0e10cSrcweir // forward to appropriate template instantiation 918*cdf0e10cSrcweir return createActivity( rParms, xNode, rAnim ); 919*cdf0e10cSrcweir } 920*cdf0e10cSrcweir 921*cdf0e10cSrcweir AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( 922*cdf0e10cSrcweir const CommonParameters& rParms, 923*cdf0e10cSrcweir const HSLColorAnimationSharedPtr& rAnim, 924*cdf0e10cSrcweir const uno::Reference< animations::XAnimateColor >& xNode ) 925*cdf0e10cSrcweir { 926*cdf0e10cSrcweir // forward to appropriate template instantiation 927*cdf0e10cSrcweir return createActivity( rParms, 928*cdf0e10cSrcweir uno::Reference< animations::XAnimate >( 929*cdf0e10cSrcweir xNode, uno::UNO_QUERY_THROW ), 930*cdf0e10cSrcweir rAnim, 931*cdf0e10cSrcweir // Direction==true means clockwise in SMIL API 932*cdf0e10cSrcweir Interpolator< HSLColor >( !xNode->getDirection() ) ); 933*cdf0e10cSrcweir } 934*cdf0e10cSrcweir 935*cdf0e10cSrcweir AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( 936*cdf0e10cSrcweir const CommonParameters& rParms, 937*cdf0e10cSrcweir const PairAnimationSharedPtr& rAnim, 938*cdf0e10cSrcweir const uno::Reference< animations::XAnimate >& xNode ) 939*cdf0e10cSrcweir { 940*cdf0e10cSrcweir // forward to appropriate template instantiation 941*cdf0e10cSrcweir return createActivity( rParms, xNode, rAnim ); 942*cdf0e10cSrcweir } 943*cdf0e10cSrcweir 944*cdf0e10cSrcweir AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( 945*cdf0e10cSrcweir const CommonParameters& rParms, 946*cdf0e10cSrcweir const StringAnimationSharedPtr& rAnim, 947*cdf0e10cSrcweir const uno::Reference< animations::XAnimate >& xNode ) 948*cdf0e10cSrcweir { 949*cdf0e10cSrcweir // forward to appropriate template instantiation 950*cdf0e10cSrcweir return createActivity( rParms, xNode, rAnim ); 951*cdf0e10cSrcweir } 952*cdf0e10cSrcweir 953*cdf0e10cSrcweir AnimationActivitySharedPtr ActivitiesFactory::createAnimateActivity( 954*cdf0e10cSrcweir const CommonParameters& rParms, 955*cdf0e10cSrcweir const BoolAnimationSharedPtr& rAnim, 956*cdf0e10cSrcweir const uno::Reference< animations::XAnimate >& xNode ) 957*cdf0e10cSrcweir { 958*cdf0e10cSrcweir // forward to appropriate template instantiation 959*cdf0e10cSrcweir return createActivity( rParms, xNode, rAnim ); 960*cdf0e10cSrcweir } 961*cdf0e10cSrcweir 962*cdf0e10cSrcweir AnimationActivitySharedPtr ActivitiesFactory::createSimpleActivity( 963*cdf0e10cSrcweir const CommonParameters& rParms, 964*cdf0e10cSrcweir const NumberAnimationSharedPtr& rAnim, 965*cdf0e10cSrcweir bool bDirectionForward ) 966*cdf0e10cSrcweir { 967*cdf0e10cSrcweir ActivityParameters aActivityParms( rParms.mpEndEvent, 968*cdf0e10cSrcweir rParms.mrEventQueue, 969*cdf0e10cSrcweir rParms.mrActivitiesQueue, 970*cdf0e10cSrcweir rParms.mnMinDuration, 971*cdf0e10cSrcweir rParms.maRepeats, 972*cdf0e10cSrcweir rParms.mnAcceleration, 973*cdf0e10cSrcweir rParms.mnDeceleration, 974*cdf0e10cSrcweir rParms.mnMinNumberOfFrames, 975*cdf0e10cSrcweir rParms.mbAutoReverse ); 976*cdf0e10cSrcweir 977*cdf0e10cSrcweir if( bDirectionForward ) 978*cdf0e10cSrcweir return AnimationActivitySharedPtr( 979*cdf0e10cSrcweir new SimpleActivity<1>( aActivityParms, rAnim ) ); 980*cdf0e10cSrcweir else 981*cdf0e10cSrcweir return AnimationActivitySharedPtr( 982*cdf0e10cSrcweir new SimpleActivity<0>( aActivityParms, rAnim ) ); 983*cdf0e10cSrcweir } 984*cdf0e10cSrcweir 985*cdf0e10cSrcweir } // namespace internal 986*cdf0e10cSrcweir } // namespace presentation 987*cdf0e10cSrcweir 988