1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_CONTROLLER_SLSANIMATOR_HXX
21 #define INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_CONTROLLER_SLSANIMATOR_HXX
23 #include "SlideSorter.hxx"
24 #include "view/SlideSorterView.hxx"
25 #include <canvas/elapsedtime.hxx>
26 #include <vcl/timer.hxx>
27 #include <vcl/idle.hxx>
28 #include <sal/types.h>
30 #include <boost/function.hpp>
31 #include <boost/noncopyable.hpp>
32 #include <boost/scoped_ptr.hpp>
33 #include <boost/shared_ptr.hpp>
35 namespace sd
{ namespace slidesorter
{ namespace controller
{
37 /** Experimental class for simple eye candy animations.
40 : private ::boost::noncopyable
43 /** In some circumstances we have to avoid animation and jump to the
44 final animation state immediately. Use this enum instead of a bool
45 to be more expressive.
47 enum AnimationMode
{ AM_Animated
, AM_Immediate
};
49 Animator (SlideSorter
& rSlideSorter
);
52 /** When disposed the animator will stop its work immediately and not
53 process any timer events anymore.
57 /** An animation object is called with values between 0 and 1 as single
58 argument to its operator() method.
60 typedef ::boost::function1
<void, double> AnimationFunctor
;
61 typedef ::boost::function0
<void> FinishFunctor
;
63 typedef sal_Int32 AnimationId
;
64 static const AnimationId NotAnAnimationId
= -1;
66 /** Schedule a new animation for execution. The () operator of that
67 animation will be called with increasing values between 0 and 1 for
68 the specified duration.
70 The animation operation.
72 Time in milli seconds before the animation is started.
74 The duration in milli seconds.
76 AnimationId
AddAnimation (
77 const AnimationFunctor
& rAnimation
,
78 const sal_Int32 nStartOffset
,
79 const sal_Int32 nDuration
,
80 const FinishFunctor
& rFinishFunctor
= FinishFunctor());
82 /** Abort and remove an animation. In order to reduce the bookkeeping
83 on the caller side, it is OK to call this method with an animation
84 function that is not currently being animated. Such a call is
87 void RemoveAnimation (const AnimationId nAnimationId
);
89 /** A typical use case for this method is the temporary shutdown of the
90 slidesorter when the slide sorter bar is put into a cache due to a
91 change of the edit mode.
93 void RemoveAllAnimations();
96 SlideSorter
& mrSlideSorter
;
100 typedef ::std::vector
<boost::shared_ptr
<Animation
> > AnimationList
;
101 AnimationList maAnimations
;
102 ::canvas::tools::ElapsedTime maElapsedTime
;
104 ::boost::scoped_ptr
<view::SlideSorterView::DrawLock
> mpDrawLock
;
106 AnimationId mnNextAnimationId
;
108 DECL_LINK_TYPED(TimeoutHandler
, Idle
*, void);
110 /** Execute one step of every active animation.
112 Time measured in milli seconds with some arbitrary reference point.
114 When one or more animation has finished then <TRUE/> is
115 returned. Call CleanUpAnimationList() in this case.
117 bool ProcessAnimations (const double nTime
);
119 /** Remove animations that have expired.
121 void CleanUpAnimationList();
123 void RequestNextFrame (const double nFrameStart
= 0);
126 } } } // end of namespace ::sd::slidesorter::controller
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */