merge the formfield patch from ooo-build
[ooovba.git] / slideshow / source / engine / activities / continuouskeytimeactivitybase.cxx
blob4306967356ac70b20773e5aab3c916683e304141
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: continuouskeytimeactivitybase.cxx,v $
10 * $Revision: 1.9 $
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_slideshow.hxx"
34 // must be first
35 #include <canvas/debug.hxx>
36 #include <tools/diagnose_ex.h>
37 #include <canvas/verbosetrace.hxx>
39 #include <continuouskeytimeactivitybase.hxx>
41 #include <algorithm>
42 #include <iterator>
45 namespace slideshow
47 namespace internal
49 ContinuousKeyTimeActivityBase::ContinuousKeyTimeActivityBase( const ActivityParameters& rParms ) :
50 SimpleContinuousActivityBase( rParms ),
51 maKeyTimes( rParms.maDiscreteTimes ),
52 mnLastIndex( 0 )
54 ENSURE_OR_THROW( maKeyTimes.size() > 1,
55 "ContinuousKeyTimeActivityBase::ContinuousKeyTimeActivityBase(): key times vector must have two entries or more" );
57 #ifdef DBG_UTIL
58 // check parameters: rKeyTimes must be sorted in
59 // ascending order, and contain values only from the range
60 // [0,1]
61 for( ::std::size_t i=1, len=maKeyTimes.size(); i<len; ++i )
63 if( maKeyTimes[i] < 0.0 ||
64 maKeyTimes[i] > 1.0 ||
65 maKeyTimes[i-1] < 0.0 ||
66 maKeyTimes[i-1] > 1.0 )
68 ENSURE_OR_THROW( false, "ContinuousKeyTimeActivityBase::ContinuousKeyTimeActivityBase(): time values not within [0,1] range!" );
71 if( maKeyTimes[i-1] > maKeyTimes[i] )
73 ENSURE_OR_THROW( false, "ContinuousKeyTimeActivityBase::ContinuousKeyTimeActivityBase(): time vector is not sorted in ascending order!" );
77 // TODO(E2): check this also in production code?
78 #endif
81 void ContinuousKeyTimeActivityBase::simplePerform( double nSimpleTime,
82 sal_uInt32 nRepeatCount ) const
84 // calc simple time from global time - sweep through the
85 // array multiple times for repeated animations (according to
86 // SMIL spec).
87 const double nT( calcAcceleratedTime( nSimpleTime ) );
89 // determine position within key times vector from
90 // current simple time
92 // shortcut: cached value still okay?
93 if( maKeyTimes[ mnLastIndex ] < nT ||
94 maKeyTimes[ mnLastIndex+1 ] >= nT )
96 // nope, find new index
97 mnLastIndex = ::std::min< ::std::ptrdiff_t >(
98 maKeyTimes.size()-2,
99 // range is ensured by max below
100 ::std::max< ::std::ptrdiff_t >(
102 ::std::distance( maKeyTimes.begin(),
103 ::std::lower_bound( maKeyTimes.begin(),
104 maKeyTimes.end(),
105 nT ) ) - 1 ) );
108 OSL_ENSURE( mnLastIndex+1 < maKeyTimes.size(),
109 "ContinuousKeyTimeActivityBase::simplePerform(): index out of range" );
111 // mnLastIndex is now valid and up-to-date
113 // calc current simple time, as a fractional value ([0,1] range).
114 // I.e. the relative position between the two index times.
115 const double nCurrFractionalSimplTime( (nT - maKeyTimes[ mnLastIndex ]) /
116 (maKeyTimes[ mnLastIndex+1 ] - maKeyTimes[ mnLastIndex ]) );
118 perform(
119 mnLastIndex,
120 nCurrFractionalSimplTime,
121 nRepeatCount );