Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef INCLUDED_SLIDESHOW_SETACTIVITY_HXX
20 : #define INCLUDED_SLIDESHOW_SETACTIVITY_HXX
21 :
22 : // must be first
23 : #include <canvas/debug.hxx>
24 : #include <tools/diagnose_ex.h>
25 : #include <canvas/verbosetrace.hxx>
26 :
27 : #include "animationactivity.hxx"
28 : #include "animation.hxx"
29 : #include "animatableshape.hxx"
30 : #include "shapeattributelayer.hxx"
31 : #include "activitiesfactory.hxx"
32 :
33 : namespace slideshow {
34 : namespace internal {
35 :
36 : /** Templated setter for animation values
37 :
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.
41 :
42 : @see AnimationSetNode.
43 : */
44 : template <class AnimationT>
45 0 : class SetActivity : public AnimationActivity
46 : {
47 : public:
48 : typedef ::boost::shared_ptr< AnimationT > AnimationSharedPtrT;
49 : typedef typename AnimationT::ValueType ValueT;
50 :
51 0 : 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 0 : mbIsActive(true)
61 : {
62 0 : ENSURE_OR_THROW( mpAnimation, "Invalid animation" );
63 0 : }
64 :
65 0 : virtual void dispose()
66 : {
67 0 : mbIsActive = false;
68 0 : mpAnimation.reset();
69 0 : mpShape.reset();
70 0 : mpAttributeLayer.reset();
71 : // discharge end event:
72 0 : if (mpEndEvent && mpEndEvent->isCharged())
73 0 : mpEndEvent->dispose();
74 0 : mpEndEvent.reset();
75 0 : }
76 :
77 0 : virtual double calcTimeLag() const
78 : {
79 0 : return 0.0;
80 : }
81 :
82 0 : virtual bool perform()
83 : {
84 0 : if (! isActive())
85 0 : return false;
86 : // we're going inactive immediately:
87 0 : mbIsActive = false;
88 :
89 0 : if (mpAnimation && mpAttributeLayer && mpShape) {
90 0 : mpAnimation->start( mpShape, mpAttributeLayer );
91 0 : (*mpAnimation)(maToValue);
92 0 : mpAnimation->end();
93 : }
94 : // fire end event, if any
95 0 : if (mpEndEvent)
96 0 : mrEventQueue.addEvent( mpEndEvent );
97 :
98 0 : return false; // don't reinsert
99 : }
100 :
101 0 : virtual bool isActive() const
102 : {
103 0 : return mbIsActive;
104 : }
105 :
106 0 : virtual void dequeued()
107 : {
108 0 : }
109 :
110 0 : virtual void end()
111 : {
112 0 : perform();
113 0 : }
114 :
115 0 : virtual void setTargets( const AnimatableShapeSharedPtr& rShape,
116 : const ShapeAttributeLayerSharedPtr& rAttrLayer )
117 : {
118 0 : ENSURE_OR_THROW( rShape, "Invalid shape" );
119 0 : ENSURE_OR_THROW( rAttrLayer, "Invalid attribute layer" );
120 :
121 0 : mpShape = rShape;
122 0 : mpAttributeLayer = rAttrLayer;
123 0 : }
124 :
125 : private:
126 : AnimationSharedPtrT mpAnimation;
127 : AnimatableShapeSharedPtr mpShape;
128 : ShapeAttributeLayerSharedPtr mpAttributeLayer;
129 : EventSharedPtr mpEndEvent;
130 : EventQueue& mrEventQueue;
131 : ValueT maToValue;
132 : bool mbIsActive;
133 : };
134 :
135 0 : template <class AnimationT> AnimationActivitySharedPtr makeSetActivity(
136 : const ActivitiesFactory::CommonParameters& rParms,
137 : const ::boost::shared_ptr< AnimationT >& rAnimation,
138 : const typename AnimationT::ValueType& rToValue )
139 : {
140 : return AnimationActivitySharedPtr(
141 0 : new SetActivity<AnimationT>(rParms,rAnimation,rToValue) );
142 : }
143 :
144 : } // namespace internal
145 : } // namespace presentation
146 :
147 : #endif /* INCLUDED_SLIDESHOW_SETACTIVITY_HXX */
148 :
149 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|