Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / sdr / animation / animationstate.cxx
blob074f2082e4605a6069fe1fb50f9520bfc5bcc286
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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)
33 double fRetval(0.0);
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 = static_cast< const drawinglayer::primitive2d::AnimatedSwitchPrimitive2D* >(xRef.get());
44 const drawinglayer::animation::AnimationEntry& rAnimEntry = pCandidate->getAnimationEntry();
45 const double fNextTime(rAnimEntry.getNextEventTime(fCurrentTime));
47 if(!::basegfx::fTools::equalZero(fNextTime))
49 if(::basegfx::fTools::equalZero(fRetval))
51 fRetval = fNextTime;
53 else if(::basegfx::fTools::less(fNextTime, fRetval))
55 fRetval = fNextTime;
61 return fRetval;
64 void PrimitiveAnimation::prepareNextEvent()
66 const double fCurrentTime(mrVOContact.GetObjectContact().getPrimitiveAnimator().GetTime());
67 const double fNextTime(getSmallestNextTime(fCurrentTime));
69 // getSmallestNextTime will be zero when animation ended. If not zero, a next step
70 // exists
71 if(::basegfx::fTools::equalZero(fNextTime))
72 return;
74 // next time point exists, use it
75 sal_uInt32 nNextTime;
77 if(fNextTime >= double(0xffffff00))
79 // take care for very late points in time, e.g. when a text animation stops
80 // in a defined AnimationEntryFixed with endless (0xffffffff) duration
81 nNextTime = GetTime() + (1000 * 60 * 60); // one hour, works with vcl timers, 0xffffff00 was too much...
83 else
85 nNextTime = static_cast<sal_uInt32>(fNextTime);
88 // ensure step forward in integer timing, the floating step difference maybe smaller than 1.0. Use
89 // at least 25ms for next step
90 const sal_uInt32 nMinimumStepTime(static_cast<sal_uInt32>(fCurrentTime) + 25);
92 if(nNextTime <= nMinimumStepTime)
94 nNextTime = nMinimumStepTime;
97 // set time and reactivate by re-adding to the scheduler
98 SetTime(nNextTime);
99 mrVOContact.GetObjectContact().getPrimitiveAnimator().InsertEvent(*this);
102 PrimitiveAnimation::PrimitiveAnimation(sdr::contact::ViewObjectContact& rVOContact, drawinglayer::primitive2d::Primitive2DContainer&& rAnimatedPrimitives)
103 : mrVOContact(rVOContact),
104 maAnimatedPrimitives(std::move(rAnimatedPrimitives))
106 if (!comphelper::LibreOfficeKit::isActive())
107 // setup initially
108 prepareNextEvent();
111 PrimitiveAnimation::~PrimitiveAnimation()
113 // ensure that Event member is removed from PrimitiveAnimator
114 mrVOContact.GetObjectContact().getPrimitiveAnimator().RemoveEvent(this);
117 // execute event, from base class Event
118 void PrimitiveAnimation::Trigger(sal_uInt32 /*nTime*/)
120 // schedule a repaint of associated object
121 mrVOContact.ActionChanged();
123 if (!comphelper::LibreOfficeKit::isActive())
124 // re-setup
125 prepareNextEvent();
128 } // end of namespace
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */