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 .
22 #include <view/SlideSorterView.hxx>
23 #include <canvas/elapsedtime.hxx>
24 #include <vcl/idle.hxx>
25 #include <sal/types.h>
26 #include <o3tl/deleter.hxx>
32 namespace sd::slidesorter
{ class SlideSorter
; }
34 namespace sd::slidesorter::controller
{
36 /** Experimental class for simple eye candy animations.
41 /** In some circumstances we have to avoid animation and jump to the
42 final animation state immediately. Use this enum instead of a bool
43 to be more expressive.
45 enum AnimationMode
{ AM_Animated
, AM_Immediate
};
47 explicit Animator (SlideSorter
& rSlideSorter
);
49 Animator(const Animator
&) = delete;
50 Animator
& operator=(const Animator
&) = delete;
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 ::std::function
<void (double)> AnimationFunctor
;
61 typedef ::std::function
<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 AnimationId
AddAnimation (
73 const AnimationFunctor
& rAnimation
,
74 const FinishFunctor
& rFinishFunctor
);
76 /** Abort and remove an animation. In order to reduce the bookkeeping
77 on the caller side, it is OK to call this method with an animation
78 function that is not currently being animated. Such a call is
81 void RemoveAnimation (const AnimationId nAnimationId
);
83 /** A typical use case for this method is the temporary shutdown of the
84 slidesorter when the slide sorter bar is put into a cache due to a
85 change of the edit mode.
87 void RemoveAllAnimations();
90 SlideSorter
& mrSlideSorter
;
94 typedef ::std::vector
<std::shared_ptr
<Animation
> > AnimationList
;
95 AnimationList maAnimations
;
96 ::canvas::tools::ElapsedTime maElapsedTime
;
98 std::unique_ptr
<view::SlideSorterView::DrawLock
, o3tl::default_delete
<view::SlideSorterView::DrawLock
>> mpDrawLock
;
100 AnimationId mnNextAnimationId
;
102 DECL_LINK(TimeoutHandler
, Timer
*, void);
104 /** Execute one step of every active animation.
106 Time measured in milliseconds with some arbitrary reference point.
108 When one or more animation has finished then <TRUE/> is
109 returned. Call CleanUpAnimationList() in this case.
111 bool ProcessAnimations (const double nTime
);
113 /** Remove animations that have expired.
115 void CleanUpAnimationList();
117 void RequestNextFrame();
120 } // end of namespace ::sd::slidesorter::controller
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */