1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef INCLUDED_SLIDESHOW_ACTIVITYBASE_HXX 25 #define INCLUDED_SLIDESHOW_ACTIVITYBASE_HXX 26 27 #include "animationactivity.hxx" 28 #include "activityparameters.hxx" 29 #include "animatableshape.hxx" 30 #include "shapeattributelayer.hxx" 31 32 namespace slideshow { 33 namespace internal { 34 35 /** Base class for animation activities. 36 37 This whole class hierarchy is only for code sharing 38 between the various specializations (with or without 39 key times, fully discrete, etc.). 40 */ 41 class ActivityBase : public AnimationActivity 42 { 43 public: 44 ActivityBase( const ActivityParameters& rParms ); 45 46 /// From Disposable interface 47 virtual void dispose(); 48 49 protected: 50 /** From Activity interface 51 52 Derived classes should override, call this first 53 and then perform their work. 54 */ 55 virtual bool perform(); 56 virtual double calcTimeLag() const; 57 virtual bool isActive() const; 58 59 private: 60 virtual void dequeued(); 61 62 // From AnimationActivity interface 63 virtual void setTargets( 64 const AnimatableShapeSharedPtr& rShape, 65 const ShapeAttributeLayerSharedPtr& rAttrLayer ); 66 67 private: 68 /** Hook for derived classes 69 70 This method will be called from the first 71 perform() invocation, to signal the start of the 72 activity. 73 */ 74 virtual void startAnimation() = 0; 75 76 /** Hook for derived classes 77 78 This method will be called after the last perform() 79 invocation, and after the potential changes of that 80 perform() call are committed to screen. That is, in 81 endAnimation(), the animation objects (sprites, 82 animation) can safely be destroyed, without causing 83 visible artifacts on screen. 84 */ 85 virtual void endAnimation() = 0; 86 87 protected: 88 89 /** End this activity, in a regular way. 90 91 This method is for derived classes needing to signal a 92 regular activity end (i.e. because the regular 93 duration is over) 94 */ 95 void endActivity(); 96 97 /** Modify fractional time. 98 99 This method modifies the fractional time (total 100 duration mapped to the [0,1] range) to the 101 effective simple time, but only according to 102 acceleration/deceleration. 103 */ 104 double calcAcceleratedTime( double nT ) const; 105 isDisposed() const106 bool isDisposed() const { 107 return (!mbIsActive && !mpEndEvent && !mpShape && 108 !mpAttributeLayer); 109 } 110 getEventQueue() const111 EventQueue& getEventQueue() const { return mrEventQueue; } 112 getShape() const113 AnimatableShapeSharedPtr getShape() const { return mpShape; } 114 getShapeAttributeLayer() const115 ShapeAttributeLayerSharedPtr getShapeAttributeLayer() const 116 { return mpAttributeLayer; } 117 isRepeatCountValid() const118 bool isRepeatCountValid() const { return maRepeats; } getRepeatCount() const119 double getRepeatCount() const { return *maRepeats; } isAutoReverse() const120 bool isAutoReverse() const { return mbAutoReverse; } 121 122 private: 123 /// Activity: 124 virtual void end(); 125 virtual void performEnd() = 0; 126 127 private: 128 EventSharedPtr mpEndEvent; 129 EventQueue& mrEventQueue; 130 AnimatableShapeSharedPtr mpShape; // only to pass on to animation 131 ShapeAttributeLayerSharedPtr mpAttributeLayer; // only to pass on to anim 132 133 ::boost::optional<double> const maRepeats; 134 const double mnAccelerationFraction; 135 const double mnDecelerationFraction; 136 137 const bool mbAutoReverse; 138 139 // true, if perform() has not yet been called: 140 mutable bool mbFirstPerformCall; 141 bool mbIsActive; 142 }; 143 144 } // namespace internal 145 } // namespace presentation 146 147 #endif /* INCLUDED_SLIDESHOW_ACTIVITYBASE_HXX */ 148 149