Update ooo320-m1
[ooovba.git] / svx / source / sdr / animation / animationstate.cxx
blob9ca93a6854b7651fee682e6f90da33001fa8f0da
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: animationstate.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <svx/sdr/animation/animationstate.hxx>
34 #include <tools/debug.hxx>
35 #include <svx/sdr/contact/viewobjectcontact.hxx>
36 #include <svx/sdr/animation/objectanimator.hxx>
37 #include <svx/sdr/contact/objectcontact.hxx>
38 #include <svx/sdr/contact/viewcontact.hxx>
39 #include <drawinglayer/primitive2d/animatedprimitive2d.hxx>
40 #include <drawinglayer/animation/animationtiming.hxx>
42 //////////////////////////////////////////////////////////////////////////////
44 namespace sdr
46 namespace animation
48 double PrimitiveAnimation::getSmallestNextTime(double fCurrentTime)
50 double fRetval(0.0);
52 if(maAnimatedPrimitives.hasElements())
54 const sal_Int32 nCount(maAnimatedPrimitives.getLength());
56 for(sal_Int32 a(0L); a < nCount; a++)
58 const drawinglayer::primitive2d::Primitive2DReference xRef(maAnimatedPrimitives[a]);
59 const drawinglayer::primitive2d::AnimatedSwitchPrimitive2D* pCandidate = dynamic_cast< const drawinglayer::primitive2d::AnimatedSwitchPrimitive2D* >(xRef.get());
60 OSL_ENSURE(pCandidate, "PrimitiveAnimation::getSmallestNextTime: wrong primitive in animated list (!)");
62 if(pCandidate)
64 const drawinglayer::animation::AnimationEntry& rAnimEntry = pCandidate->getAnimationEntry();
65 const double fNextTime(rAnimEntry.getNextEventTime(fCurrentTime));
67 if(!::basegfx::fTools::equalZero(fNextTime))
69 if(::basegfx::fTools::equalZero(fRetval))
71 fRetval = fNextTime;
73 else if(::basegfx::fTools::less(fNextTime, fRetval))
75 fRetval = fNextTime;
82 return fRetval;
85 void PrimitiveAnimation::prepareNextEvent()
87 const double fCurrentTime(mrVOContact.GetObjectContact().getPrimitiveAnimator().GetTime());
88 const double fNextTime(getSmallestNextTime(fCurrentTime));
90 // getSmallestNextTime will be zero when animation ended. If not zero, a next step
91 // exists
92 if(!::basegfx::fTools::equalZero(fNextTime))
94 // next time point exists, use it
95 sal_uInt32 nNextTime;
97 if(fNextTime >= (double)0xffffff00)
99 // take care for very late points in time, e.g. when a text animation stops
100 // in a defined AnimationEntryFixed with endless (0xffffffff) duration
101 nNextTime = GetTime() + (1000 * 60 * 60); // one hour, works with vcl timers, 0xffffff00 was too much...
103 else
105 nNextTime = (sal_uInt32)fNextTime;
108 // ensure step forward in integer timing, the floating step difference maybe smaller than 1.0. Use
109 // at least 25ms for next step
110 const sal_uInt32 nMinimumStepTime((sal_uInt32)fCurrentTime + 25L);
112 if(nNextTime <= nMinimumStepTime)
114 nNextTime = nMinimumStepTime;
117 // set time and reactivate by re-adding to the scheduler
118 SetTime(nNextTime);
119 mrVOContact.GetObjectContact().getPrimitiveAnimator().InsertEvent(this);
123 PrimitiveAnimation::PrimitiveAnimation(sdr::contact::ViewObjectContact& rVOContact, const drawinglayer::primitive2d::Primitive2DSequence& rAnimatedPrimitives)
124 : Event(0L),
125 mrVOContact(rVOContact),
126 maAnimatedPrimitives(rAnimatedPrimitives)
128 // setup initially
129 prepareNextEvent();
132 PrimitiveAnimation::~PrimitiveAnimation()
134 // ensure that Event member is removed from PrimitiveAnimator
135 mrVOContact.GetObjectContact().getPrimitiveAnimator().RemoveEvent(this);
138 // execute event, from base class Event
139 void PrimitiveAnimation::Trigger(sal_uInt32 /*nTime*/)
141 // schedule a repaint of associated object
142 mrVOContact.ActionChanged();
144 // re-setup
145 prepareNextEvent();
147 } // end of namespace animation
148 } // end of namespace sdr
150 //////////////////////////////////////////////////////////////////////////////
151 // eof