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