bump product version to 5.0.4.1
[LibreOffice.git] / slideshow / source / engine / animationnodes / setactivity.hxx
blob2f94d62b38416a6545232b8d3b61b47d560879e6
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 // must be first
23 #include <canvas/debug.hxx>
24 #include <tools/diagnose_ex.h>
25 #include <canvas/verbosetrace.hxx>
27 #include "animationactivity.hxx"
28 #include "animation.hxx"
29 #include "animatableshape.hxx"
30 #include "shapeattributelayer.hxx"
31 #include "activitiesfactory.hxx"
33 namespace slideshow {
34 namespace internal {
36 /** Templated setter for animation values
38 This template class implements the AnimationActivity
39 interface, but only the perform() and
40 setAttributeLayer() methods are functional. To be used for set animations.
42 @see AnimationSetNode.
44 template <class AnimationT>
45 class SetActivity : public AnimationActivity
47 public:
48 typedef ::boost::shared_ptr< AnimationT > AnimationSharedPtrT;
49 typedef typename AnimationT::ValueType ValueT;
51 SetActivity( const ActivitiesFactory::CommonParameters& rParms,
52 const AnimationSharedPtrT& rAnimation,
53 const ValueT& rToValue )
54 : mpAnimation( rAnimation ),
55 mpShape(),
56 mpAttributeLayer(),
57 mpEndEvent( rParms.mpEndEvent ),
58 mrEventQueue( rParms.mrEventQueue ),
59 maToValue( rToValue ),
60 mbIsActive(true)
62 ENSURE_OR_THROW( mpAnimation, "Invalid animation" );
65 virtual void dispose() SAL_OVERRIDE
67 mbIsActive = false;
68 mpAnimation.reset();
69 mpShape.reset();
70 mpAttributeLayer.reset();
71 // discharge end event:
72 if (mpEndEvent && mpEndEvent->isCharged())
73 mpEndEvent->dispose();
74 mpEndEvent.reset();
77 virtual double calcTimeLag() const SAL_OVERRIDE
79 return 0.0;
82 virtual bool perform() SAL_OVERRIDE
84 if (! isActive())
85 return false;
86 // we're going inactive immediately:
87 mbIsActive = false;
89 if (mpAnimation && mpAttributeLayer && mpShape) {
90 mpAnimation->start( mpShape, mpAttributeLayer );
91 (*mpAnimation)(maToValue);
92 mpAnimation->end();
94 // fire end event, if any
95 if (mpEndEvent)
96 mrEventQueue.addEvent( mpEndEvent );
98 return false; // don't reinsert
101 virtual bool isActive() const SAL_OVERRIDE
103 return mbIsActive;
106 virtual void dequeued() SAL_OVERRIDE
110 virtual void end() SAL_OVERRIDE
112 perform();
115 virtual void setTargets( const AnimatableShapeSharedPtr& rShape,
116 const ShapeAttributeLayerSharedPtr& rAttrLayer ) SAL_OVERRIDE
118 ENSURE_OR_THROW( rShape, "Invalid shape" );
119 ENSURE_OR_THROW( rAttrLayer, "Invalid attribute layer" );
121 mpShape = rShape;
122 mpAttributeLayer = rAttrLayer;
125 private:
126 AnimationSharedPtrT mpAnimation;
127 AnimatableShapeSharedPtr mpShape;
128 ShapeAttributeLayerSharedPtr mpAttributeLayer;
129 EventSharedPtr mpEndEvent;
130 EventQueue& mrEventQueue;
131 ValueT maToValue;
132 bool mbIsActive;
135 template <class AnimationT> AnimationActivitySharedPtr makeSetActivity(
136 const ActivitiesFactory::CommonParameters& rParms,
137 const ::boost::shared_ptr< AnimationT >& rAnimation,
138 const typename AnimationT::ValueType& rToValue )
140 return AnimationActivitySharedPtr(
141 new SetActivity<AnimationT>(rParms,rAnimation,rToValue) );
144 } // namespace internal
145 } // namespace presentation
147 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_ANIMATIONNODES_SETACTIVITY_HXX
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */