1*06bcd5d2SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*06bcd5d2SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*06bcd5d2SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*06bcd5d2SAndrew Rist  * distributed with this work for additional information
6*06bcd5d2SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*06bcd5d2SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*06bcd5d2SAndrew Rist  * "License"); you may not use this file except in compliance
9*06bcd5d2SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*06bcd5d2SAndrew Rist  *
11*06bcd5d2SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*06bcd5d2SAndrew Rist  *
13*06bcd5d2SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*06bcd5d2SAndrew Rist  * software distributed under the License is distributed on an
15*06bcd5d2SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*06bcd5d2SAndrew Rist  * KIND, either express or implied.  See the License for the
17*06bcd5d2SAndrew Rist  * specific language governing permissions and limitations
18*06bcd5d2SAndrew Rist  * under the License.
19*06bcd5d2SAndrew Rist  *
20*06bcd5d2SAndrew Rist  *************************************************************/
21*06bcd5d2SAndrew Rist 
22*06bcd5d2SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SDEXT_PRESENTER_ANIMATION_HXX
25cdf0e10cSrcweir #define SDEXT_PRESENTER_ANIMATION_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <sal/types.h>
28cdf0e10cSrcweir #include <boost/function.hpp>
29cdf0e10cSrcweir #include <boost/noncopyable.hpp>
30cdf0e10cSrcweir #include <boost/scoped_ptr.hpp>
31cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
32cdf0e10cSrcweir #include <vector>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace sdext { namespace presenter {
35cdf0e10cSrcweir 
36cdf0e10cSrcweir /** Base class for animations handled by a PresenterAnimator object.
37cdf0e10cSrcweir     A PresenterAnimation objects basically states when it wants to be
38cdf0e10cSrcweir     started, how long it runs, and in what steps it wants to be called back
39cdf0e10cSrcweir     while running.
40cdf0e10cSrcweir     When a PresenterAnimation object is active/running its Run() method is
41cdf0e10cSrcweir     called back with increasing values between 0 and 1.
42cdf0e10cSrcweir */
43cdf0e10cSrcweir class PresenterAnimation
44cdf0e10cSrcweir     : private ::boost::noncopyable
45cdf0e10cSrcweir {
46cdf0e10cSrcweir public:
47cdf0e10cSrcweir     /** Create a new PresenterAnimation object.
48cdf0e10cSrcweir         @param nStartDelay
49cdf0e10cSrcweir             The delay in ms (milliseconds) from this call until the new
50cdf0e10cSrcweir             object is to be activated.
51cdf0e10cSrcweir         @param nTotalDuration
52cdf0e10cSrcweir             The duration in ms the Run() method is to be called with
53cdf0e10cSrcweir             increasing values between 0 and 1.
54cdf0e10cSrcweir         @param nStepDuration
55cdf0e10cSrcweir             The duration between calls to Run().  This leads to approximately
56cdf0e10cSrcweir             nTotalDuration/nStepDuration calls to Run().  The exact duration
57cdf0e10cSrcweir             of each step may vary depending on system load an other influences.
58cdf0e10cSrcweir     */
59cdf0e10cSrcweir     PresenterAnimation (
60cdf0e10cSrcweir         const sal_uInt64 nStartDelay,
61cdf0e10cSrcweir         const sal_uInt64 nTotalDuration,
62cdf0e10cSrcweir         const sal_uInt64 nStepDuration);
63cdf0e10cSrcweir     virtual ~PresenterAnimation (void);
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     /** Return the absolute start time in a system dependent format.
66cdf0e10cSrcweir         At about this time the Run() method will be called with a value of 0.
67cdf0e10cSrcweir     */
68cdf0e10cSrcweir     sal_uInt64 GetStartTime (void);
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     /** Return the absolute end time in a system dependent format.
71cdf0e10cSrcweir         At about this time the Run() method will be called with a value of 1.
72cdf0e10cSrcweir     */
73cdf0e10cSrcweir     sal_uInt64 GetEndTime (void);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     /** Return the duration of each step in ms.
76cdf0e10cSrcweir     */
77cdf0e10cSrcweir     sal_uInt64 GetStepDuration (void);
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     typedef ::boost::function<void(void)> Callback;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     /** Add a callback that is executed before Run() is called for the first
82cdf0e10cSrcweir         time.
83cdf0e10cSrcweir     */
84cdf0e10cSrcweir     void AddStartCallback (const Callback& rCallback);
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     /** Add a callback that is executed after Run() is called for the last
87cdf0e10cSrcweir         time.
88cdf0e10cSrcweir     */
89cdf0e10cSrcweir     void AddEndCallback (const Callback& rCallback);
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     /** Called with nProgress taking on values between 0 and 1.
92cdf0e10cSrcweir         @param nProgress
93cdf0e10cSrcweir             A value between 0 and 1.
94cdf0e10cSrcweir         @param nCurrentTime
95cdf0e10cSrcweir             Current time in a system dependent format.
96cdf0e10cSrcweir     */
97cdf0e10cSrcweir     virtual void Run (const double nProgress, const sal_uInt64 nCurrentTime) = 0;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     /** Called just before Run() is called for the first time to trigger the
100cdf0e10cSrcweir         callbacks registered via the <method>AddStartCallback()</method>.
101cdf0e10cSrcweir     */
102cdf0e10cSrcweir     void RunStartCallbacks (void);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     /** Called just after Run() is called for the last time to trigger the
105cdf0e10cSrcweir         callbacks registered via the <method>AddEndCallback()</method>.
106cdf0e10cSrcweir     */
107cdf0e10cSrcweir     void RunEndCallbacks (void);
108cdf0e10cSrcweir 
109cdf0e10cSrcweir private:
110cdf0e10cSrcweir     const sal_uInt64 mnStartTime;
111cdf0e10cSrcweir     const sal_uInt64 mnTotalDuration;
112cdf0e10cSrcweir     const sal_uInt64 mnStepDuration;
113cdf0e10cSrcweir     ::boost::scoped_ptr<std::vector<Callback> > mpStartCallbacks;
114cdf0e10cSrcweir     ::boost::scoped_ptr<std::vector<Callback> > mpEndCallbacks;
115cdf0e10cSrcweir };
116cdf0e10cSrcweir 
117cdf0e10cSrcweir sal_uInt64 GetCurrentTime (void);
GetSeconds(const sal_uInt64 nTime)118cdf0e10cSrcweir inline sal_uInt32 GetSeconds (const sal_uInt64 nTime) { return sal_uInt32(nTime / 1000); }
GetNanoSeconds(const sal_uInt64 nTime)119cdf0e10cSrcweir inline sal_uInt32 GetNanoSeconds (const sal_uInt64 nTime) { return sal_uInt32((nTime % 1000) * 1000000); }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir typedef ::boost::shared_ptr<PresenterAnimation> SharedPresenterAnimation;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 
124cdf0e10cSrcweir } } // end of namespace ::sdext::presenter
125cdf0e10cSrcweir 
126cdf0e10cSrcweir #endif
127