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 SDEXT_PRESENTER_ANIMATION_HXX
25 #define SDEXT_PRESENTER_ANIMATION_HXX
26 
27 #include <sal/types.h>
28 #include <boost/function.hpp>
29 #include <boost/noncopyable.hpp>
30 #include <boost/scoped_ptr.hpp>
31 #include <boost/shared_ptr.hpp>
32 #include <vector>
33 
34 namespace sdext { namespace presenter {
35 
36 /** Base class for animations handled by a PresenterAnimator object.
37     A PresenterAnimation objects basically states when it wants to be
38     started, how long it runs, and in what steps it wants to be called back
39     while running.
40     When a PresenterAnimation object is active/running its Run() method is
41     called back with increasing values between 0 and 1.
42 */
43 class PresenterAnimation
44     : private ::boost::noncopyable
45 {
46 public:
47     /** Create a new PresenterAnimation object.
48         @param nStartDelay
49             The delay in ms (milliseconds) from this call until the new
50             object is to be activated.
51         @param nTotalDuration
52             The duration in ms the Run() method is to be called with
53             increasing values between 0 and 1.
54         @param nStepDuration
55             The duration between calls to Run().  This leads to approximately
56             nTotalDuration/nStepDuration calls to Run().  The exact duration
57             of each step may vary depending on system load an other influences.
58     */
59     PresenterAnimation (
60         const sal_uInt64 nStartDelay,
61         const sal_uInt64 nTotalDuration,
62         const sal_uInt64 nStepDuration);
63     virtual ~PresenterAnimation (void);
64 
65     /** Return the absolute start time in a system dependent format.
66         At about this time the Run() method will be called with a value of 0.
67     */
68     sal_uInt64 GetStartTime (void);
69 
70     /** Return the absolute end time in a system dependent format.
71         At about this time the Run() method will be called with a value of 1.
72     */
73     sal_uInt64 GetEndTime (void);
74 
75     /** Return the duration of each step in ms.
76     */
77     sal_uInt64 GetStepDuration (void);
78 
79     typedef ::boost::function<void(void)> Callback;
80 
81     /** Add a callback that is executed before Run() is called for the first
82         time.
83     */
84     void AddStartCallback (const Callback& rCallback);
85 
86     /** Add a callback that is executed after Run() is called for the last
87         time.
88     */
89     void AddEndCallback (const Callback& rCallback);
90 
91     /** Called with nProgress taking on values between 0 and 1.
92         @param nProgress
93             A value between 0 and 1.
94         @param nCurrentTime
95             Current time in a system dependent format.
96     */
97     virtual void Run (const double nProgress, const sal_uInt64 nCurrentTime) = 0;
98 
99     /** Called just before Run() is called for the first time to trigger the
100         callbacks registered via the <method>AddStartCallback()</method>.
101     */
102     void RunStartCallbacks (void);
103 
104     /** Called just after Run() is called for the last time to trigger the
105         callbacks registered via the <method>AddEndCallback()</method>.
106     */
107     void RunEndCallbacks (void);
108 
109 private:
110     const sal_uInt64 mnStartTime;
111     const sal_uInt64 mnTotalDuration;
112     const sal_uInt64 mnStepDuration;
113     ::boost::scoped_ptr<std::vector<Callback> > mpStartCallbacks;
114     ::boost::scoped_ptr<std::vector<Callback> > mpEndCallbacks;
115 };
116 
117 sal_uInt64 GetCurrentTime (void);
GetSeconds(const sal_uInt64 nTime)118 inline sal_uInt32 GetSeconds (const sal_uInt64 nTime) { return sal_uInt32(nTime / 1000); }
GetNanoSeconds(const sal_uInt64 nTime)119 inline sal_uInt32 GetNanoSeconds (const sal_uInt64 nTime) { return sal_uInt32((nTime % 1000) * 1000000); }
120 
121 typedef ::boost::shared_ptr<PresenterAnimation> SharedPresenterAnimation;
122 
123 
124 } } // end of namespace ::sdext::presenter
125 
126 #endif
127