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 <view/SlideSorterView.hxx>
24 #include <canvas/elapsedtime.hxx>
25 #include <vcl/idle.hxx>
26 #include <sal/types.h>
27 #include <o3tl/deleter.hxx>
33 namespace sd
{ namespace slidesorter
{ class SlideSorter
; } }
35 namespace sd
{ namespace slidesorter
{ namespace controller
{
37 /** Experimental class for simple eye candy animations.
42 /** In some circumstances we have to avoid animation and jump to the
43 final animation state immediately. Use this enum instead of a bool
44 to be more expressive.
46 enum AnimationMode
{ AM_Animated
, AM_Immediate
};
48 explicit Animator (SlideSorter
& rSlideSorter
);
50 Animator(const Animator
&) = delete;
51 Animator
& operator=(const Animator
&) = delete;
53 /** When disposed the animator will stop its work immediately and not
54 process any timer events anymore.
58 /** An animation object is called with values between 0 and 1 as single
59 argument to its operator() method.
61 typedef ::std::function
<void (double)> AnimationFunctor
;
62 typedef ::std::function
<void ()> FinishFunctor
;
64 typedef sal_Int32 AnimationId
;
65 static const AnimationId NotAnAnimationId
= -1;
67 /** Schedule a new animation for execution. The () operator of that
68 animation will be called with increasing values between 0 and 1 for
69 the specified duration.
71 The animation operation.
73 AnimationId
AddAnimation (
74 const AnimationFunctor
& rAnimation
,
75 const FinishFunctor
& rFinishFunctor
);
77 /** Abort and remove an animation. In order to reduce the bookkeeping
78 on the caller side, it is OK to call this method with an animation
79 function that is not currently being animated. Such a call is
82 void RemoveAnimation (const AnimationId nAnimationId
);
84 /** A typical use case for this method is the temporary shutdown of the
85 slidesorter when the slide sorter bar is put into a cache due to a
86 change of the edit mode.
88 void RemoveAllAnimations();
91 SlideSorter
& mrSlideSorter
;
95 typedef ::std::vector
<std::shared_ptr
<Animation
> > AnimationList
;
96 AnimationList maAnimations
;
97 ::canvas::tools::ElapsedTime
const maElapsedTime
;
99 std::unique_ptr
<view::SlideSorterView::DrawLock
, o3tl::default_delete
<view::SlideSorterView::DrawLock
>> mpDrawLock
;
101 AnimationId mnNextAnimationId
;
103 DECL_LINK(TimeoutHandler
, Timer
*, void);
105 /** Execute one step of every active animation.
107 Time measured in milli seconds with some arbitrary reference point.
109 When one or more animation has finished then <TRUE/> is
110 returned. Call CleanUpAnimationList() in this case.
112 bool ProcessAnimations (const double nTime
);
114 /** Remove animations that have expired.
116 void CleanUpAnimationList();
118 void RequestNextFrame();
121 } } } // end of namespace ::sd::slidesorter::controller
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */