LibreOffice Module slideshow (master) 1
discreteactivitybase.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
22
24
25
26namespace slideshow::internal
27{
29 ActivityBase( rParms ),
31 maDiscreteTimes( rParms.maDiscreteTimes ),
32 mnSimpleDuration( rParms.mnMinDuration ),
33 mnCurrPerformCalls( 0 )
34 {
36 "DiscreteActivityBase::DiscreteActivityBase(): Invalid wakeup event" );
37
39 "DiscreteActivityBase::DiscreteActivityBase(): time vector is empty, why do you create me?" );
40
41#ifdef DBG_UTIL
42 // check parameters: rDiscreteTimes must be sorted in
43 // ascending order, and contain values only from the range
44 // [0,1]
45 for( ::std::size_t i=1, len=maDiscreteTimes.size(); i<len; ++i )
46 {
47 if( maDiscreteTimes[i] < 0.0 ||
48 maDiscreteTimes[i] > 1.0 ||
49 maDiscreteTimes[i-1] < 0.0 ||
50 maDiscreteTimes[i-1] > 1.0 )
51 {
52 ENSURE_OR_THROW( false, "DiscreteActivityBase::DiscreteActivityBase(): time values not within [0,1] range!" );
53 }
54
56 ENSURE_OR_THROW( false, "DiscreteActivityBase::DiscreteActivityBase(): time vector is not sorted in ascending order!" );
57 }
58
59 // TODO(E2): check this also in production code?
60#endif
61 }
62
64 {
65 // start timer on wakeup event
66 mpWakeupEvent->start();
67 }
68
69 sal_uInt32 DiscreteActivityBase::calcFrameIndex( sal_uInt32 nCurrCalls,
70 ::std::size_t nVectorSize ) const
71 {
72 if( isAutoReverse() )
73 {
74 // every full repeat run consists of one
75 // forward and one backward traversal.
76 sal_uInt32 nFrameIndex( nCurrCalls % (2*nVectorSize) );
77
78 // nFrameIndex values >= nVectorSize belong to
79 // the backward traversal
80 if( nFrameIndex >= nVectorSize )
81 nFrameIndex = 2*nVectorSize - nFrameIndex; // invert sweep
82
83 return nFrameIndex;
84 }
85 else
86 {
87 return nCurrCalls % nVectorSize ;
88 }
89 }
90
91 sal_uInt32 DiscreteActivityBase::calcRepeatCount( sal_uInt32 nCurrCalls,
92 ::std::size_t nVectorSize ) const
93 {
94 if( isAutoReverse() )
95 return nCurrCalls / (2*nVectorSize); // we've got 2 cycles per repeat
96 else
97 return nCurrCalls / nVectorSize;
98 }
99
101 {
102 // call base class, for start() calls and end handling
103 if( !ActivityBase::perform() )
104 return false; // done, we're ended
105
106 const ::std::size_t nVectorSize( maDiscreteTimes.size() );
107
108 // actually perform something
109 // ==========================
110
111 // TODO(Q3): Refactor this mess
112
113 // call derived class with current frame index (modulo
114 // vector size, to cope with repeats)
116 calcRepeatCount( mnCurrPerformCalls, nVectorSize ) );
117
118 // calc next index
120
121 // calc currently reached repeat count
122 double nCurrRepeat( double(mnCurrPerformCalls) / nVectorSize );
123
124 // if auto-reverse is specified, halve the
125 // effective repeat count, since we pass every
126 // repeat run twice: once forward, once backward.
127 if( isAutoReverse() )
128 nCurrRepeat /= 2.0;
129
130 // schedule next frame, if either repeat is indefinite
131 // (repeat forever), or we've not yet reached the requested
132 // repeat count
133 if( !isRepeatCountValid() ||
134 nCurrRepeat < getRepeatCount() )
135 {
136 // add wake-up event to queue (modulo
137 // vector size, to cope with repeats).
138
139 // repeat is handled locally, only apply acceleration/deceleration.
140 // Scale time vector with simple duration, offset with full repeat
141 // times.
142
143 // Somewhat condensed, the argument for setNextTimeout below could
144 // be written as
145
146 // mnSimpleDuration*(nFullRepeats + calcAcceleratedTime( currentRepeatTime )),
147
148 // with currentRepeatTime = maDiscreteTimes[ currentRepeatIndex ]
149
150 // Note that calcAcceleratedTime() is only applied to the current repeat's value,
151 // not to the total resulting time. This is in accordance with the SMIL spec.
152
153 mpWakeupEvent->setNextTimeout(
157 nVectorSize ) +
162 nVectorSize ) ] ) ) );
163
165 }
166 else
167 {
168 // release event reference (relation to wakeup event
169 // is circular!)
170 mpWakeupEvent.reset();
171
172 // done with this activity
173 endActivity();
174 }
175
176 return false; // remove from queue, will be added back by the wakeup event.
177 }
178
180 {
181 // dispose event
182 if( mpWakeupEvent )
183 mpWakeupEvent->dispose();
184
185 // release references
186 mpWakeupEvent.reset();
187
189 }
190}
191
192/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class for animation activities.
virtual bool perform() override
From Activity interface.
EventQueue & getEventQueue() const
virtual void dispose() override
From Disposable interface.
void endActivity()
End this activity, in a regular way.
double calcAcceleratedTime(double nT) const
Modify fractional time.
sal_uInt32 calcFrameIndex(sal_uInt32 nCurrCalls, ::std::size_t nVectorSize) const
virtual void dispose() override
From Disposable interface.
virtual void startAnimation() override
Hook for derived classes.
const ::std::vector< double > maDiscreteTimes
DiscreteActivityBase(const ActivityParameters &rParms)
virtual bool perform() override
From Activity interface.
sal_uInt32 calcRepeatCount(sal_uInt32 nCurrCalls, ::std::size_t nVectorSize) const
bool addEvent(const EventSharedPtr &event)
Add the given event to the queue.
Definition: eventqueue.cxx:79
#define ENSURE_OR_THROW(c, m)
WakeupEventSharedPtr mpWakeupEvent
int i
Parameter struct for animation activities.