1*aaef562fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*aaef562fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*aaef562fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*aaef562fSAndrew Rist  * distributed with this work for additional information
6*aaef562fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*aaef562fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*aaef562fSAndrew Rist  * "License"); you may not use this file except in compliance
9*aaef562fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*aaef562fSAndrew Rist  *
11*aaef562fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*aaef562fSAndrew Rist  *
13*aaef562fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*aaef562fSAndrew Rist  * software distributed under the License is distributed on an
15*aaef562fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*aaef562fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*aaef562fSAndrew Rist  * specific language governing permissions and limitations
18*aaef562fSAndrew Rist  * under the License.
19*aaef562fSAndrew Rist  *
20*aaef562fSAndrew Rist  *************************************************************/
21*aaef562fSAndrew Rist 
22*aaef562fSAndrew Rist 
23cdf0e10cSrcweir #ifndef INCLUDED_SLIDESHOW_SETACTIVITY_HXX
24cdf0e10cSrcweir #define INCLUDED_SLIDESHOW_SETACTIVITY_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir // must be first
27cdf0e10cSrcweir #include <canvas/debug.hxx>
28cdf0e10cSrcweir #include <tools/diagnose_ex.h>
29cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "animationactivity.hxx"
32cdf0e10cSrcweir #include "animation.hxx"
33cdf0e10cSrcweir #include "animatableshape.hxx"
34cdf0e10cSrcweir #include "shapeattributelayer.hxx"
35cdf0e10cSrcweir #include "activitiesfactory.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace slideshow {
38cdf0e10cSrcweir namespace internal {
39cdf0e10cSrcweir 
40cdf0e10cSrcweir /** Templated setter for animation values
41cdf0e10cSrcweir 
42cdf0e10cSrcweir     This template class implements the AnimationActivity
43cdf0e10cSrcweir     interface, but only the perform() and
44cdf0e10cSrcweir     setAttributeLayer() methods are functional. To be used for set animations.
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     @see AnimationSetNode.
47cdf0e10cSrcweir */
48cdf0e10cSrcweir template <class AnimationT>
49cdf0e10cSrcweir class SetActivity : public AnimationActivity
50cdf0e10cSrcweir {
51cdf0e10cSrcweir public:
52cdf0e10cSrcweir     typedef ::boost::shared_ptr< AnimationT >   AnimationSharedPtrT;
53cdf0e10cSrcweir     typedef typename AnimationT::ValueType      ValueT;
54cdf0e10cSrcweir 
SetActivity(const ActivitiesFactory::CommonParameters & rParms,const AnimationSharedPtrT & rAnimation,const ValueT & rToValue)55cdf0e10cSrcweir     SetActivity( const ActivitiesFactory::CommonParameters& rParms,
56cdf0e10cSrcweir                  const AnimationSharedPtrT&                 rAnimation,
57cdf0e10cSrcweir                  const ValueT&                              rToValue )
58cdf0e10cSrcweir         : mpAnimation( rAnimation ),
59cdf0e10cSrcweir           mpShape(),
60cdf0e10cSrcweir           mpAttributeLayer(),
61cdf0e10cSrcweir           mpEndEvent( rParms.mpEndEvent ),
62cdf0e10cSrcweir           mrEventQueue( rParms.mrEventQueue ),
63cdf0e10cSrcweir           maToValue( rToValue ),
64cdf0e10cSrcweir           mbIsActive(true)
65cdf0e10cSrcweir     {
66cdf0e10cSrcweir         ENSURE_OR_THROW( mpAnimation, "Invalid animation" );
67cdf0e10cSrcweir     }
68cdf0e10cSrcweir 
dispose()69cdf0e10cSrcweir     virtual void dispose()
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir         mbIsActive = false;
72cdf0e10cSrcweir         mpAnimation.reset();
73cdf0e10cSrcweir         mpShape.reset();
74cdf0e10cSrcweir         mpAttributeLayer.reset();
75cdf0e10cSrcweir         // discharge end event:
76cdf0e10cSrcweir         if (mpEndEvent && mpEndEvent->isCharged())
77cdf0e10cSrcweir             mpEndEvent->dispose();
78cdf0e10cSrcweir         mpEndEvent.reset();
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir 
calcTimeLag() const81cdf0e10cSrcweir     virtual double calcTimeLag() const
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir         return 0.0;
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir 
perform()86cdf0e10cSrcweir     virtual bool perform()
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         if (! isActive())
89cdf0e10cSrcweir             return false;
90cdf0e10cSrcweir         // we're going inactive immediately:
91cdf0e10cSrcweir         mbIsActive = false;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         if (mpAnimation && mpAttributeLayer && mpShape) {
94cdf0e10cSrcweir             mpAnimation->start( mpShape, mpAttributeLayer );
95cdf0e10cSrcweir             (*mpAnimation)(maToValue);
96cdf0e10cSrcweir             mpAnimation->end();
97cdf0e10cSrcweir         }
98cdf0e10cSrcweir         // fire end event, if any
99cdf0e10cSrcweir         if (mpEndEvent)
100cdf0e10cSrcweir             mrEventQueue.addEvent( mpEndEvent );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         return false; // don't reinsert
103cdf0e10cSrcweir     }
104cdf0e10cSrcweir 
isActive() const105cdf0e10cSrcweir     virtual bool isActive() const
106cdf0e10cSrcweir     {
107cdf0e10cSrcweir         return mbIsActive;
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir 
dequeued()110cdf0e10cSrcweir     virtual void dequeued()
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir     }
113cdf0e10cSrcweir 
end()114cdf0e10cSrcweir     virtual void end()
115cdf0e10cSrcweir     {
116cdf0e10cSrcweir         perform();
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir 
setTargets(const AnimatableShapeSharedPtr & rShape,const ShapeAttributeLayerSharedPtr & rAttrLayer)119cdf0e10cSrcweir     virtual void setTargets( const AnimatableShapeSharedPtr&        rShape,
120cdf0e10cSrcweir                              const ShapeAttributeLayerSharedPtr&    rAttrLayer )
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         ENSURE_OR_THROW( rShape, "Invalid shape" );
123cdf0e10cSrcweir         ENSURE_OR_THROW( rAttrLayer, "Invalid attribute layer" );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         mpShape = rShape;
126cdf0e10cSrcweir         mpAttributeLayer = rAttrLayer;
127cdf0e10cSrcweir     }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir private:
130cdf0e10cSrcweir     AnimationSharedPtrT             mpAnimation;
131cdf0e10cSrcweir     AnimatableShapeSharedPtr        mpShape;
132cdf0e10cSrcweir     ShapeAttributeLayerSharedPtr    mpAttributeLayer;
133cdf0e10cSrcweir     EventSharedPtr                  mpEndEvent;
134cdf0e10cSrcweir     EventQueue&                     mrEventQueue;
135cdf0e10cSrcweir     ValueT                          maToValue;
136cdf0e10cSrcweir     bool                            mbIsActive;
137cdf0e10cSrcweir };
138cdf0e10cSrcweir 
makeSetActivity(const ActivitiesFactory::CommonParameters & rParms,const::boost::shared_ptr<AnimationT> & rAnimation,const typename AnimationT::ValueType & rToValue)139cdf0e10cSrcweir template <class AnimationT> AnimationActivitySharedPtr makeSetActivity(
140cdf0e10cSrcweir     const ActivitiesFactory::CommonParameters& rParms,
141cdf0e10cSrcweir     const ::boost::shared_ptr< AnimationT >&   rAnimation,
142cdf0e10cSrcweir     const typename AnimationT::ValueType&      rToValue )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir     return AnimationActivitySharedPtr(
145cdf0e10cSrcweir         new SetActivity<AnimationT>(rParms,rAnimation,rToValue) );
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir } // namespace internal
149cdf0e10cSrcweir } // namespace presentation
150cdf0e10cSrcweir 
151cdf0e10cSrcweir #endif /* INCLUDED_SLIDESHOW_SETACTIVITY_HXX */
152