1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: activitybase.cxx,v $
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"
35 #include <canvas/debug.hxx>
36 #include <tools/diagnose_ex.h>
37 #include <canvas/verbosetrace.hxx>
38 #include <canvas/canvastools.hxx>
40 #include <activitybase.hxx>
47 // TODO(P1): Elide some virtual function calls, by templifying this
50 ActivityBase::ActivityBase( const ActivityParameters
& rParms
) :
51 mpEndEvent( rParms
.mrEndEvent
),
52 mrEventQueue( rParms
.mrEventQueue
),
55 maRepeats( rParms
.mrRepeats
),
56 mnAccelerationFraction( rParms
.mnAccelerationFraction
),
57 mnDecelerationFraction( rParms
.mnDecelerationFraction
),
58 mbAutoReverse( rParms
.mbAutoReverse
),
59 mbFirstPerformCall( true ),
62 void ActivityBase::dispose()
69 mpEndEvent
->dispose();
74 mpAttributeLayer
.reset();
77 double ActivityBase::calcTimeLag() const
79 // TODO(Q1): implement different init process!
80 if (isActive() && mbFirstPerformCall
)
82 mbFirstPerformCall
= false;
84 // notify derived classes that we're
86 const_cast<ActivityBase
*>(this)->startAnimation();
91 bool ActivityBase::perform()
95 return false; // no, early exit.
97 OSL_ASSERT( ! mbFirstPerformCall
);
102 bool ActivityBase::isActive() const
107 void ActivityBase::setTargets( const AnimatableShapeSharedPtr
& rShape
,
108 const ShapeAttributeLayerSharedPtr
& rAttrLayer
)
110 ENSURE_OR_THROW( rShape
,
111 "ActivityBase::setTargets(): Invalid shape" );
112 ENSURE_OR_THROW( rAttrLayer
,
113 "ActivityBase::setTargets(): Invalid attribute layer" );
116 mpAttributeLayer
= rAttrLayer
;
119 void ActivityBase::endActivity()
121 // this is a regular activity end
124 // Activity is ending, queue event, then
126 mrEventQueue
.addEvent( mpEndEvent
);
128 // release references
132 void ActivityBase::dequeued()
135 // // ignored here, if we're still active. Discrete
136 // // activities are dequeued after every perform() call,
137 // // thus, the call is only significant when isActive() ==
143 void ActivityBase::end()
145 if (!isActive() || isDisposed())
147 // assure animation is started:
148 if (mbFirstPerformCall
) {
149 mbFirstPerformCall
= false;
150 // notify derived classes that we're starting now
151 this->startAnimation();
154 performEnd(); // calling private virtual
159 double ActivityBase::calcAcceleratedTime( double nT
) const
161 // Handle acceleration/deceleration
162 // ================================
164 // clamp nT to permissible [0,1] range
165 nT
= ::canvas::tools::clamp( nT
, 0.0, 1.0 );
167 // take acceleration/deceleration into account. if the sum
168 // of mnAccelerationFraction and mnDecelerationFraction
169 // exceeds 1.0, ignore both (that's according to SMIL spec)
170 if( (mnAccelerationFraction
> 0.0 ||
171 mnDecelerationFraction
> 0.0) &&
172 mnAccelerationFraction
+ mnDecelerationFraction
<= 1.0 )
175 // calc accelerated/decelerated time.
177 // We have three intervals:
180 // 3 [d,1] (with a and d being acceleration/deceleration
183 // The change rate during interval 1 is constantly
184 // increasing, reaching 1 at a. It then stays at 1,
185 // starting a linear decrease at d, ending with 0 at
186 // time 1. The integral of this function is the
187 // required new time nT'.
189 // As we arbitrarily assumed 1 as the upper value of
190 // the change rate, the integral must be normalized to
191 // reach nT'=1 at the end of the interval. This
192 // normalization constant is:
194 // c = 1 - 0.5a - 0.5d
196 // The integral itself then amounts to:
198 // 0.5 nT^2 / a + (nT-a) + (nT - 0.5 nT^2 / d)
200 // (where each of the three summands correspond to the
201 // three intervals above, and are applied only if nT
202 // has reached the corresponding interval)
204 // The graph of the change rate is a trapezoid:
207 // 1| /--------------\
211 // -----------------------------
215 const double nC( 1.0 - 0.5*mnAccelerationFraction
- 0.5*mnDecelerationFraction
);
217 // this variable accumulates the new time value
220 if( nT
< mnAccelerationFraction
)
222 nTPrime
+= 0.5*nT
*nT
/mnAccelerationFraction
; // partial first interval
226 nTPrime
+= 0.5*mnAccelerationFraction
; // full first interval
228 if( nT
<= 1.0-mnDecelerationFraction
)
230 nTPrime
+= nT
-mnAccelerationFraction
; // partial second interval
234 nTPrime
+= 1.0 - mnAccelerationFraction
- mnDecelerationFraction
; // full second interval
236 const double nTRelative( nT
- 1.0 + mnDecelerationFraction
);
238 nTPrime
+= nTRelative
- 0.5*nTRelative
*nTRelative
/ mnDecelerationFraction
;
242 // normalize, and assign to work variable