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 SD_SLIDESORTER_CONTROLLER_ANIMATOR_HXX 25 #define SD_SLIDESORTER_CONTROLLER_ANIMATOR_HXX 26 27 #include "SlideSorter.hxx" 28 #include "view/SlideSorterView.hxx" 29 #include <canvas/elapsedtime.hxx> 30 #include <vcl/timer.hxx> 31 #include <sal/types.h> 32 #include <vector> 33 #include <boost/function.hpp> 34 #include <boost/noncopyable.hpp> 35 #include <boost/scoped_ptr.hpp> 36 #include <boost/shared_ptr.hpp> 37 38 39 namespace sd { namespace slidesorter { namespace controller { 40 41 /** Experimental class for simple eye candy animations. 42 */ 43 class Animator 44 : private ::boost::noncopyable 45 { 46 public: 47 /** In some circumstances we have to avoid animation and jump to the 48 final animation state immediately. Use this enum instead of a bool 49 to be more expressive. 50 */ 51 enum AnimationMode { AM_Animated, AM_Immediate }; 52 53 Animator (SlideSorter& rSlideSorter); 54 ~Animator (void); 55 56 /** When disposed the animator will stop its work immediately and not 57 process any timer events anymore. 58 */ 59 void Dispose (void); 60 61 /** An animation object is called with values between 0 and 1 as single 62 argument to its operator() method. 63 */ 64 typedef ::boost::function1<void, double> AnimationFunctor; 65 typedef ::boost::function0<void> FinishFunctor; 66 67 typedef sal_Int32 AnimationId; 68 static const AnimationId NotAnAnimationId = -1; 69 70 /** Schedule a new animation for execution. The () operator of that 71 animation will be called with increasing values between 0 and 1 for 72 the specified duration. 73 @param rAnimation 74 The animation operation. 75 @param nStartOffset 76 Time in milliseconds before the animation is started. 77 @param nDuration 78 The duration in milliseconds. 79 */ 80 AnimationId AddAnimation ( 81 const AnimationFunctor& rAnimation, 82 const sal_Int32 nStartOffset, 83 const sal_Int32 nDuration, 84 const FinishFunctor& rFinishFunctor = FinishFunctor()); 85 86 AnimationId AddInfiniteAnimation ( 87 const AnimationFunctor& rAnimation, 88 const double nDelta); 89 90 /** Abort and remove an animation. In order to reduce the bookkeeping 91 on the caller side, it is OK to call this method with an animation 92 function that is not currently being animated. Such a call is 93 silently ignored. 94 */ 95 void RemoveAnimation (const AnimationId nAnimationId); 96 97 /** A typical use case for this method is the temporary shutdown of the 98 slidesorter when the slide sorter bar is put into a cache due to a 99 change of the edit mode. 100 */ 101 void RemoveAllAnimations (void); 102 103 private: 104 SlideSorter& mrSlideSorter; 105 Timer maTimer; 106 bool mbIsDisposed; 107 class Animation; 108 typedef ::std::vector<boost::shared_ptr<Animation> > AnimationList; 109 AnimationList maAnimations; 110 ::canvas::tools::ElapsedTime maElapsedTime; 111 112 ::boost::scoped_ptr<view::SlideSorterView::DrawLock> mpDrawLock; 113 114 AnimationId mnNextAnimationId; 115 116 DECL_LINK(TimeoutHandler, Timer*); 117 118 /** Execute one step of every active animation. 119 @param nTime 120 Time measured in milliseconds with some arbitrary reference point. 121 @return 122 When one or more animation has finished then <TRUE/> is 123 returned. Call CleanUpAnimationList() in this case. 124 */ 125 bool ProcessAnimations (const double nTime); 126 127 /** Remove animations that have expired. 128 */ 129 void CleanUpAnimationList (void); 130 131 void RequestNextFrame (const double nFrameStart = 0); 132 }; 133 134 135 } } } // end of namespace ::sd::slidesorter::controller 136 137 #endif 138