Use o3tl::convert in Math
[LibreOffice.git] / slideshow / source / engine / animationnodes / setactivity.hxx
blobb3585af2e9b800c34acaf8821c534bf4b013b2a6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_SLIDESHOW_SOURCE_ENGINE_ANIMATIONNODES_SETACTIVITY_HXX
20 #define INCLUDED_SLIDESHOW_SOURCE_ENGINE_ANIMATIONNODES_SETACTIVITY_HXX
22 #include <tools/diagnose_ex.h>
24 #include <animationactivity.hxx>
25 #include <animatableshape.hxx>
26 #include <shapeattributelayer.hxx>
27 #include <activitiesfactory.hxx>
29 namespace slideshow::internal {
31 /** Templated setter for animation values
33 This template class implements the AnimationActivity
34 interface, but only the perform() and
35 setAttributeLayer() methods are functional. To be used for set animations.
37 @see AnimationSetNode.
39 template <class AnimationT>
40 class SetActivity : public AnimationActivity
42 public:
43 typedef ::std::shared_ptr< AnimationT > AnimationSharedPtrT;
44 typedef typename AnimationT::ValueType ValueT;
46 SetActivity( const ActivitiesFactory::CommonParameters& rParms,
47 const AnimationSharedPtrT& rAnimation,
48 const ValueT& rToValue )
49 : mpAnimation( rAnimation ),
50 mpShape(),
51 mpAttributeLayer(),
52 mpEndEvent( rParms.mpEndEvent ),
53 mrEventQueue( rParms.mrEventQueue ),
54 maToValue( rToValue ),
55 mbIsActive(true)
57 ENSURE_OR_THROW( mpAnimation, "Invalid animation" );
60 virtual void dispose() override
62 mbIsActive = false;
63 mpAnimation.reset();
64 mpShape.reset();
65 mpAttributeLayer.reset();
66 // discharge end event:
67 if (mpEndEvent && mpEndEvent->isCharged())
68 mpEndEvent->dispose();
69 mpEndEvent.reset();
72 virtual double calcTimeLag() const override
74 return 0.0;
77 virtual bool perform() override
79 if (! isActive())
80 return false;
81 // we're going inactive immediately:
82 mbIsActive = false;
84 if (mpAnimation && mpAttributeLayer && mpShape) {
85 mpAnimation->start( mpShape, mpAttributeLayer );
86 (*mpAnimation)(maToValue);
87 mpAnimation->end();
89 // fire end event, if any
90 if (mpEndEvent)
91 mrEventQueue.addEvent( mpEndEvent );
93 return false; // don't reinsert
96 virtual bool isActive() const override
98 return mbIsActive;
101 virtual void dequeued() override
105 virtual void end() override
107 perform();
110 virtual void setTargets( const AnimatableShapeSharedPtr& rShape,
111 const ShapeAttributeLayerSharedPtr& rAttrLayer ) override
113 ENSURE_OR_THROW( rShape, "Invalid shape" );
114 ENSURE_OR_THROW( rAttrLayer, "Invalid attribute layer" );
116 mpShape = rShape;
117 mpAttributeLayer = rAttrLayer;
120 private:
121 AnimationSharedPtrT mpAnimation;
122 AnimatableShapeSharedPtr mpShape;
123 ShapeAttributeLayerSharedPtr mpAttributeLayer;
124 EventSharedPtr mpEndEvent;
125 EventQueue& mrEventQueue;
126 ValueT maToValue;
127 bool mbIsActive;
130 template <class AnimationT> AnimationActivitySharedPtr makeSetActivity(
131 const ActivitiesFactory::CommonParameters& rParms,
132 const ::std::shared_ptr< AnimationT >& rAnimation,
133 const typename AnimationT::ValueType& rToValue )
135 return std::make_shared<SetActivity<AnimationT>>(rParms,rAnimation,rToValue);
138 } // namespace presentation::internal
140 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_ANIMATIONNODES_SETACTIVITY_HXX
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */