bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / sdr / animation / animationstate.cxx
blobbc7b573fcc16a5d60b5258d12d376a4cf53b140f
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 <svx/sdr/contact/viewcontact.hxx>
25 #include <drawinglayer/primitive2d/animatedprimitive2d.hxx>
26 #include <drawinglayer/animation/animationtiming.hxx>
27 #include <comphelper/lok.hxx>
31 namespace sdr
33 namespace animation
35 double PrimitiveAnimation::getSmallestNextTime(double fCurrentTime)
37 double fRetval(0.0);
39 if(maAnimatedPrimitives.hasElements())
41 const sal_Int32 nCount(maAnimatedPrimitives.getLength());
43 for(sal_Int32 a(0L); a < nCount; a++)
45 const drawinglayer::primitive2d::Primitive2DReference xRef(maAnimatedPrimitives[a]);
46 const drawinglayer::primitive2d::AnimatedSwitchPrimitive2D* pCandidate = dynamic_cast< const drawinglayer::primitive2d::AnimatedSwitchPrimitive2D* >(xRef.get());
47 OSL_ENSURE(pCandidate, "PrimitiveAnimation::getSmallestNextTime: wrong primitive in animated list (!)");
49 if(pCandidate)
51 const drawinglayer::animation::AnimationEntry& rAnimEntry = pCandidate->getAnimationEntry();
52 const double fNextTime(rAnimEntry.getNextEventTime(fCurrentTime));
54 if(!::basegfx::fTools::equalZero(fNextTime))
56 if(::basegfx::fTools::equalZero(fRetval))
58 fRetval = fNextTime;
60 else if(::basegfx::fTools::less(fNextTime, fRetval))
62 fRetval = fNextTime;
69 return fRetval;
72 void PrimitiveAnimation::prepareNextEvent()
74 const double fCurrentTime(mrVOContact.GetObjectContact().getPrimitiveAnimator().GetTime());
75 const double fNextTime(getSmallestNextTime(fCurrentTime));
77 // getSmallestNextTime will be zero when animation ended. If not zero, a next step
78 // exists
79 if(!::basegfx::fTools::equalZero(fNextTime))
81 // next time point exists, use it
82 sal_uInt32 nNextTime;
84 if(fNextTime >= (double)0xffffff00)
86 // take care for very late points in time, e.g. when a text animation stops
87 // in a defined AnimationEntryFixed with endless (0xffffffff) duration
88 nNextTime = GetTime() + (1000 * 60 * 60); // one hour, works with vcl timers, 0xffffff00 was too much...
90 else
92 nNextTime = (sal_uInt32)fNextTime;
95 // ensure step forward in integer timing, the floating step difference maybe smaller than 1.0. Use
96 // at least 25ms for next step
97 const sal_uInt32 nMinimumStepTime((sal_uInt32)fCurrentTime + 25L);
99 if(nNextTime <= nMinimumStepTime)
101 nNextTime = nMinimumStepTime;
104 // set time and reactivate by re-adding to the scheduler
105 SetTime(nNextTime);
106 mrVOContact.GetObjectContact().getPrimitiveAnimator().InsertEvent(this);
110 PrimitiveAnimation::PrimitiveAnimation(sdr::contact::ViewObjectContact& rVOContact, const drawinglayer::primitive2d::Primitive2DSequence& rAnimatedPrimitives)
111 : Event(0L),
112 mrVOContact(rVOContact),
113 maAnimatedPrimitives(rAnimatedPrimitives)
115 if (!comphelper::LibreOfficeKit::isActive())
116 // setup initially
117 prepareNextEvent();
120 PrimitiveAnimation::~PrimitiveAnimation()
122 // ensure that Event member is removed from PrimitiveAnimator
123 mrVOContact.GetObjectContact().getPrimitiveAnimator().RemoveEvent(this);
126 // execute event, from base class Event
127 void PrimitiveAnimation::Trigger(sal_uInt32 /*nTime*/)
129 // schedule a repaint of associated object
130 mrVOContact.ActionChanged();
132 if (!comphelper::LibreOfficeKit::isActive())
133 // re-setup
134 prepareNextEvent();
136 } // end of namespace animation
137 } // end of namespace sdr
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */