1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlsAnimator.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_sd.hxx"
33 #include "controller/SlsAnimator.hxx"
34 #include "view/SlideSorterView.hxx"
37 namespace sd
{ namespace slidesorter
{ namespace controller
{
40 static const sal_Int32 gnResolution
= 25;
42 /** Handle one animation function by using a timer for frequent calls to
43 the animations operator().
45 class Animator::Animation
49 const Animator::AnimationFunction
& rAnimation
,
53 bool IsExpired (void);
54 Animator::AnimationFunction maAnimation
;
62 class Animator::DrawLock
65 DrawLock (View
& rView
);
75 Animator::Animator (SlideSorter
& rSlideSorter
)
76 : mrSlideSorter(rSlideSorter
),
81 maTimer
.SetTimeout(gnResolution
);
82 maTimer
.SetTimeoutHdl(LINK(this,Animator
,TimeoutHandler
));
88 Animator::~Animator (void)
97 void Animator::AddAnimation (
98 const AnimationFunction
& rAnimation
,
99 const sal_Int32 nDuration
)
101 const double nDelta
= double(gnResolution
) / double(nDuration
);
102 maAnimations
.push_back(boost::shared_ptr
<Animation
>(new Animation(rAnimation
, nDelta
)));
104 // Prevent redraws except for the ones in TimeoutHandler.
105 // While the Animator is active it will schedule repaints regularly.
106 // Repaints in between would only lead to visual artifacts.
107 mpDrawLock
.reset(new DrawLock(mrSlideSorter
.GetView()));
114 bool Animator::ServeAnimations (void)
116 bool bExpired (false);
118 AnimationList
aCopy (maAnimations
);
119 AnimationList::const_iterator iAnimation
;
120 for (iAnimation
=aCopy
.begin(); iAnimation
!=aCopy
.end(); ++iAnimation
)
122 bExpired
|= (*iAnimation
)->Run();
131 void Animator::CleanUpAnimationList (void)
133 AnimationList aActiveAnimations
;
135 AnimationList::const_iterator iAnimation
;
136 for (iAnimation
=maAnimations
.begin(); iAnimation
!=maAnimations
.end(); ++iAnimation
)
138 if ( ! (*iAnimation
)->IsExpired())
139 aActiveAnimations
.push_back(*iAnimation
);
142 maAnimations
.swap(aActiveAnimations
);
148 IMPL_LINK(Animator
, TimeoutHandler
, Timer
*, EMPTYARG
)
150 if (ServeAnimations())
151 CleanUpAnimationList();
153 // Unlock the draw lock. This should lead to a repaint.
156 if (maAnimations
.size() > 0)
158 mpDrawLock
.reset(new DrawLock(mrSlideSorter
.GetView()));
168 //===== Animator::Animation ===================================================
170 Animator::Animation::Animation (
171 const Animator::AnimationFunction
& rAnimation
,
173 : maAnimation(rAnimation
),
178 maAnimation(mnValue
);
186 Animator::Animation::~Animation (void)
193 bool Animator::Animation::Run (void)
197 maAnimation(mnValue
);
211 bool Animator::Animation::IsExpired (void)
213 return mnValue
>= 1.0;
219 //===== Animator::DrawLock ====================================================
221 Animator::DrawLock::DrawLock (View
& rView
)
224 mrView
.LockRedraw(TRUE
);
230 Animator::DrawLock::~DrawLock (void)
232 mrView
.LockRedraw(FALSE
);
236 } } } // end of namespace ::sd::slidesorter::controller