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