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 #include <svx/sdr/animation/animationstate.hxx>
21 #include <svx/sdr/contact/viewobjectcontact.hxx>
22 #include <svx/sdr/animation/objectanimator.hxx>
23 #include <svx/sdr/contact/objectcontact.hxx>
24 #include <drawinglayer/primitive2d/animatedprimitive2d.hxx>
25 #include <drawinglayer/animation/animationtiming.hxx>
26 #include <comphelper/lok.hxx>
29 namespace sdr::animation
31 double PrimitiveAnimation::getSmallestNextTime(double fCurrentTime
)
35 if(!maAnimatedPrimitives
.empty())
37 const sal_Int32
nCount(maAnimatedPrimitives
.size());
39 for(sal_Int32
a(0); a
< nCount
; a
++)
41 const drawinglayer::primitive2d::Primitive2DReference
xRef(maAnimatedPrimitives
[a
]);
42 const drawinglayer::primitive2d::AnimatedSwitchPrimitive2D
* pCandidate
= dynamic_cast< const drawinglayer::primitive2d::AnimatedSwitchPrimitive2D
* >(xRef
.get());
43 OSL_ENSURE(pCandidate
, "PrimitiveAnimation::getSmallestNextTime: wrong primitive in animated list (!)");
47 const drawinglayer::animation::AnimationEntry
& rAnimEntry
= pCandidate
->getAnimationEntry();
48 const double fNextTime(rAnimEntry
.getNextEventTime(fCurrentTime
));
50 if(!::basegfx::fTools::equalZero(fNextTime
))
52 if(::basegfx::fTools::equalZero(fRetval
))
56 else if(::basegfx::fTools::less(fNextTime
, fRetval
))
68 void PrimitiveAnimation::prepareNextEvent()
70 const double fCurrentTime(mrVOContact
.GetObjectContact().getPrimitiveAnimator().GetTime());
71 const double fNextTime(getSmallestNextTime(fCurrentTime
));
73 // getSmallestNextTime will be zero when animation ended. If not zero, a next step
75 if(::basegfx::fTools::equalZero(fNextTime
))
78 // next time point exists, use it
81 if(fNextTime
>= double(0xffffff00))
83 // take care for very late points in time, e.g. when a text animation stops
84 // in a defined AnimationEntryFixed with endless (0xffffffff) duration
85 nNextTime
= GetTime() + (1000 * 60 * 60); // one hour, works with vcl timers, 0xffffff00 was too much...
89 nNextTime
= static_cast<sal_uInt32
>(fNextTime
);
92 // ensure step forward in integer timing, the floating step difference maybe smaller than 1.0. Use
93 // at least 25ms for next step
94 const sal_uInt32
nMinimumStepTime(static_cast<sal_uInt32
>(fCurrentTime
) + 25);
96 if(nNextTime
<= nMinimumStepTime
)
98 nNextTime
= nMinimumStepTime
;
101 // set time and reactivate by re-adding to the scheduler
103 mrVOContact
.GetObjectContact().getPrimitiveAnimator().InsertEvent(*this);
106 PrimitiveAnimation::PrimitiveAnimation(sdr::contact::ViewObjectContact
& rVOContact
, const drawinglayer::primitive2d::Primitive2DContainer
& rAnimatedPrimitives
)
108 mrVOContact(rVOContact
),
109 maAnimatedPrimitives(rAnimatedPrimitives
)
111 if (!comphelper::LibreOfficeKit::isActive())
116 PrimitiveAnimation::~PrimitiveAnimation()
118 // ensure that Event member is removed from PrimitiveAnimator
119 mrVOContact
.GetObjectContact().getPrimitiveAnimator().RemoveEvent(this);
122 // execute event, from base class Event
123 void PrimitiveAnimation::Trigger(sal_uInt32
/*nTime*/)
125 // schedule a repaint of associated object
126 mrVOContact
.ActionChanged();
128 if (!comphelper::LibreOfficeKit::isActive())
133 } // end of namespace
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */