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 
24cdf0e10cSrcweir #ifndef INCLUDED_SLIDESHOW_ACTIVITYBASE_HXX
25cdf0e10cSrcweir #define INCLUDED_SLIDESHOW_ACTIVITYBASE_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "animationactivity.hxx"
28cdf0e10cSrcweir #include "activityparameters.hxx"
29cdf0e10cSrcweir #include "animatableshape.hxx"
30cdf0e10cSrcweir #include "shapeattributelayer.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir namespace slideshow {
33cdf0e10cSrcweir namespace internal {
34cdf0e10cSrcweir 
35cdf0e10cSrcweir /** Base class for animation activities.
36cdf0e10cSrcweir 
37cdf0e10cSrcweir     This whole class hierarchy is only for code sharing
38cdf0e10cSrcweir     between the various specializations (with or without
39cdf0e10cSrcweir     key times, fully discrete, etc.).
40cdf0e10cSrcweir */
41cdf0e10cSrcweir class ActivityBase : public AnimationActivity
42cdf0e10cSrcweir {
43cdf0e10cSrcweir public:
44cdf0e10cSrcweir     ActivityBase( const ActivityParameters& rParms );
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     /// From Disposable interface
47cdf0e10cSrcweir     virtual void dispose();
48cdf0e10cSrcweir 
49cdf0e10cSrcweir protected:
50cdf0e10cSrcweir     /** From Activity interface
51cdf0e10cSrcweir 
52cdf0e10cSrcweir         Derived classes should override, call this first
53cdf0e10cSrcweir         and then perform their work.
54cdf0e10cSrcweir     */
55cdf0e10cSrcweir     virtual bool perform();
56cdf0e10cSrcweir     virtual double calcTimeLag() const;
57cdf0e10cSrcweir     virtual bool isActive() const;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir private:
60cdf0e10cSrcweir     virtual void dequeued();
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     // From AnimationActivity interface
63cdf0e10cSrcweir     virtual void setTargets(
64cdf0e10cSrcweir         const AnimatableShapeSharedPtr&        rShape,
65cdf0e10cSrcweir         const ShapeAttributeLayerSharedPtr&    rAttrLayer );
66cdf0e10cSrcweir 
67cdf0e10cSrcweir private:
68cdf0e10cSrcweir     /** Hook for derived classes
69cdf0e10cSrcweir 
70cdf0e10cSrcweir         This method will be called from the first
71cdf0e10cSrcweir         perform() invocation, to signal the start of the
72cdf0e10cSrcweir         activity.
73cdf0e10cSrcweir     */
74cdf0e10cSrcweir     virtual void startAnimation() = 0;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     /** Hook for derived classes
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         This method will be called after the last perform()
79cdf0e10cSrcweir         invocation, and after the potential changes of that
80cdf0e10cSrcweir         perform() call are committed to screen. That is, in
81cdf0e10cSrcweir         endAnimation(), the animation objects (sprites,
82cdf0e10cSrcweir         animation) can safely be destroyed, without causing
83cdf0e10cSrcweir         visible artifacts on screen.
84cdf0e10cSrcweir     */
85cdf0e10cSrcweir     virtual void endAnimation() = 0;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir protected:
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     /** End this activity, in a regular way.
90cdf0e10cSrcweir 
91cdf0e10cSrcweir         This method is for derived classes needing to signal a
92cdf0e10cSrcweir         regular activity end (i.e. because the regular
93cdf0e10cSrcweir         duration is over)
94cdf0e10cSrcweir     */
95cdf0e10cSrcweir     void endActivity();
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     /** Modify fractional time.
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         This method modifies the fractional time (total
100cdf0e10cSrcweir         duration mapped to the [0,1] range) to the
101cdf0e10cSrcweir         effective simple time, but only according to
102cdf0e10cSrcweir         acceleration/deceleration.
103cdf0e10cSrcweir     */
104cdf0e10cSrcweir     double calcAcceleratedTime( double nT ) const;
105cdf0e10cSrcweir 
isDisposed() const106cdf0e10cSrcweir     bool isDisposed() const {
107cdf0e10cSrcweir         return (!mbIsActive && !mpEndEvent && !mpShape &&
108cdf0e10cSrcweir                 !mpAttributeLayer);
109cdf0e10cSrcweir     }
110cdf0e10cSrcweir 
getEventQueue() const111cdf0e10cSrcweir     EventQueue& getEventQueue() const { return mrEventQueue; }
112cdf0e10cSrcweir 
getShape() const113cdf0e10cSrcweir     AnimatableShapeSharedPtr getShape() const { return mpShape; }
114cdf0e10cSrcweir 
getShapeAttributeLayer() const115cdf0e10cSrcweir     ShapeAttributeLayerSharedPtr getShapeAttributeLayer() const
116cdf0e10cSrcweir         { return mpAttributeLayer; }
117cdf0e10cSrcweir 
isRepeatCountValid() const118cdf0e10cSrcweir     bool isRepeatCountValid() const { return maRepeats; }
getRepeatCount() const119cdf0e10cSrcweir     double getRepeatCount() const { return *maRepeats; }
isAutoReverse() const120cdf0e10cSrcweir     bool isAutoReverse() const { return mbAutoReverse; }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir private:
123cdf0e10cSrcweir     /// Activity:
124cdf0e10cSrcweir     virtual void end();
125cdf0e10cSrcweir     virtual void performEnd() = 0;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir private:
128cdf0e10cSrcweir     EventSharedPtr                  mpEndEvent;
129cdf0e10cSrcweir     EventQueue&                     mrEventQueue;
130cdf0e10cSrcweir     AnimatableShapeSharedPtr        mpShape; // only to pass on to animation
131cdf0e10cSrcweir     ShapeAttributeLayerSharedPtr    mpAttributeLayer; // only to pass on to anim
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     ::boost::optional<double> const maRepeats;
134cdf0e10cSrcweir     const double                    mnAccelerationFraction;
135cdf0e10cSrcweir     const double                    mnDecelerationFraction;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     const bool                      mbAutoReverse;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     // true, if perform() has not yet been called:
140cdf0e10cSrcweir     mutable bool                    mbFirstPerformCall;
141cdf0e10cSrcweir     bool                            mbIsActive;
142cdf0e10cSrcweir };
143cdf0e10cSrcweir 
144cdf0e10cSrcweir } // namespace internal
145cdf0e10cSrcweir } // namespace presentation
146cdf0e10cSrcweir 
147cdf0e10cSrcweir #endif /* INCLUDED_SLIDESHOW_ACTIVITYBASE_HXX */
148cdf0e10cSrcweir 
149