1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_SLIDESHOW_ACTIVITIESFACTORY_HXX
25 #define INCLUDED_SLIDESHOW_ACTIVITIESFACTORY_HXX
26 
27 #include <com/sun/star/animations/XAnimate.hpp>
28 #include <com/sun/star/animations/XAnimateColor.hpp>
29 
30 #include "animationactivity.hxx"
31 #include "activitiesqueue.hxx"
32 #include "event.hxx"
33 #include "eventqueue.hxx"
34 #include "shape.hxx"
35 #include "numberanimation.hxx"
36 #include "enumanimation.hxx"
37 #include "coloranimation.hxx"
38 #include "hslcoloranimation.hxx"
39 #include "stringanimation.hxx"
40 #include "boolanimation.hxx"
41 #include "pairanimation.hxx"
42 
43 #include <boost/optional.hpp>
44 #include <boost/utility.hpp>
45 
46 /* Definition of ActivitiesFactory class */
47 
48 namespace slideshow {
49 namespace internal {
50 
51 class ActivitiesFactory : private ::boost::noncopyable
52 {
53 public:
54     /// Collection of common factory parameters
55     struct CommonParameters
56     {
CommonParametersslideshow::internal::ActivitiesFactory::CommonParameters57         CommonParameters(
58             const EventSharedPtr&                 rEndEvent,
59             EventQueue&                           rEventQueue,
60             ActivitiesQueue&                      rActivitiesQueue,
61             double                                nMinDuration,
62             sal_uInt32                            nMinNumberOfFrames,
63             bool                                  bAutoReverse,
64             ::boost::optional<double> const&      aRepeats,
65             double                                nAcceleration,
66             double                                nDeceleration,
67             const ShapeSharedPtr&                 rShape,
68             const ::basegfx::B2DVector&           rSlideBounds )
69             : mpEndEvent( rEndEvent ),
70               mrEventQueue( rEventQueue ),
71               mrActivitiesQueue( rActivitiesQueue ),
72               mnMinDuration( nMinDuration ),
73               mnMinNumberOfFrames( nMinNumberOfFrames ),
74               maRepeats( aRepeats ),
75               mnAcceleration( nAcceleration ),
76               mnDeceleration( nDeceleration ),
77               mpShape( rShape ),
78               maSlideBounds( rSlideBounds ),
79               mbAutoReverse( bAutoReverse ) {}
80 
81         /// End event to fire when animation is over
82         EventSharedPtr                                  mpEndEvent;
83 
84         /// Event queue to insert the end event into.
85         EventQueue&                                     mrEventQueue;
86         /// Event queue to insert the end event into.
87         ActivitiesQueue&                                mrActivitiesQueue;
88 
89         /** Simple duration of the activity
90 
91             Specifies the minimal simple duration of the
92             activity (minimal, because mnMinNumberOfFrames
93             might prolongue the activity). According to SMIL,
94             this might also be indefinite, which for our
95             framework does not make much sense, though
96             (wouldn't have a clue, then, how to scale the
97             animation over time).
98         */
99         double                                          mnMinDuration;
100 
101         /** Minimal number of frames for this activity.
102 
103             This specifies the minimal number of frames this
104             activity will display per simple duration. If less
105             than this number are displayed until mnMinDuration
106             is over, the activity will be prolongued until
107             mnMinNumberOfFrames are rendered.
108         */
109         sal_uInt32                                      mnMinNumberOfFrames;
110 
111         /** Number of repeats for the simple duration
112 
113             This specified the number of repeats. The
114             mnMinDuration times maRepeats yields the total
115             duration of this activity. If this value is
116             unspecified, the activity will repeat
117             indefinitely.
118         */
119         ::boost::optional<double> const                 maRepeats;
120 
121         /// Fraction of simple time to accelerate animation
122         double                                          mnAcceleration;
123 
124         /// Fraction of simple time to decelerate animation
125         double                                          mnDeceleration;
126 
127         /// Shape, to get bounds from
128         ShapeSharedPtr                                  mpShape;
129 
130         /// LayerManager, to get page size from
131         ::basegfx::B2DVector                            maSlideBounds;
132 
133         /// When true, activity is played reversed after mnDuration.
134         bool                                            mbAutoReverse;
135     };
136 
137     /** Create an activity from an XAnimate node.
138 
139         This method creates an animated activity from the
140         given XAnimate node, extracting all necessary
141         animation parameters from that. Note that due to the
142         animator parameter, the animation values must be
143         convertible to a double value.
144 
145         @param rParms
146         Factory parameter structure
147 
148         @param rAnimator
149         Animator sub-object
150 
151         @param xNode
152         The SMIL animation node to animate
153     */
154     static AnimationActivitySharedPtr createAnimateActivity(
155         const CommonParameters&                        rParms,
156         const NumberAnimationSharedPtr&                rAnimator,
157         const ::com::sun::star::uno::Reference<
158         ::com::sun::star::animations::XAnimate >&   xNode );
159 
160     /** Create an activity from an XAnimate node.
161 
162         This method creates an animated activity from the
163         given XAnimate node, extracting all necessary
164         animation parameters from that. Note that due to the
165         animator parameter, the animation values must be
166         convertible to a double value.
167 
168         @param rParms
169         Factory parameter structure
170 
171         @param rAnimator
172         Animator sub-object
173 
174         @param xNode
175         The SMIL animation node to animate
176     */
177     static AnimationActivitySharedPtr createAnimateActivity(
178         const CommonParameters&                        rParms,
179         const EnumAnimationSharedPtr&                  rAnimator,
180         const ::com::sun::star::uno::Reference<
181         ::com::sun::star::animations::XAnimate >&      xNode );
182 
183     /** Create an activity from an XAnimate node.
184 
185         This method creates an animated activity from the
186         given XAnimate node, extracting all necessary
187         animation parameters from that. Note that due to the
188         animator parameter, the animation values must be
189         convertible to a color value.
190 
191         @param rParms
192         Factory parameter structure
193 
194         @param rAnimator
195         Animator sub-object
196 
197         @param xNode
198         The SMIL animation node to animate
199     */
200     static AnimationActivitySharedPtr createAnimateActivity(
201         const CommonParameters&                        rParms,
202         const ColorAnimationSharedPtr&                 rAnimator,
203         const ::com::sun::star::uno::Reference<
204         ::com::sun::star::animations::XAnimate >&      xNode );
205 
206     /** Create an activity from an XAnimate node.
207 
208         This method creates an animated activity from the
209         given XAnimate node, extracting all necessary
210         animation parameters from that. Note that due to the
211         animator parameter, the animation values must be
212         convertible to a color value.
213 
214         @param rParms
215         Factory parameter structure
216 
217         @param rAnimator
218         Animator sub-object
219 
220         @param xNode
221         The SMIL animation node to animate
222     */
223     static AnimationActivitySharedPtr createAnimateActivity(
224         const CommonParameters&                            rParms,
225         const HSLColorAnimationSharedPtr&                  rAnimator,
226         const ::com::sun::star::uno::Reference<
227         ::com::sun::star::animations::XAnimateColor >&     xNode );
228 
229     /** Create an activity from an XAnimate node.
230 
231         This method creates an animated activity from the
232         given XAnimate node, extracting all necessary
233         animation parameters from that. Note that due to the
234         animator parameter, the animation values must be
235         convertible to a pair of double values.
236 
237         @param rParms
238         Factory parameter structure
239 
240         @param rAnimator
241         Animator sub-object
242 
243         @param xNode
244         The SMIL animation node to animate
245     */
246     static AnimationActivitySharedPtr createAnimateActivity(
247         const CommonParameters&                        rParms,
248         const PairAnimationSharedPtr&                  rAnimator,
249         const ::com::sun::star::uno::Reference<
250         ::com::sun::star::animations::XAnimate >&   xNode );
251 
252     /** Create an activity from an XAnimate node.
253 
254         This method creates an animated activity from the
255         given XAnimate node, extracting all necessary
256         animation parameters from that. Note that due to the
257         animator parameter, the animation values must be
258         convertible to a string.
259 
260         @param rParms
261         Factory parameter structure
262 
263         @param rAnimator
264         Animator sub-object
265 
266         @param xNode
267         The SMIL animation node to animate
268     */
269     static AnimationActivitySharedPtr createAnimateActivity(
270         const CommonParameters&                        rParms,
271         const StringAnimationSharedPtr&                rAnimator,
272         const ::com::sun::star::uno::Reference<
273         ::com::sun::star::animations::XAnimate >&      xNode );
274 
275     /** Create an activity from an XAnimate node.
276 
277         This method creates an animated activity from the
278         given XAnimate node, extracting all necessary
279         animation parameters from that. Note that due to the
280         animator parameter, the animation values must be
281         convertible to a bool value.
282 
283         @param rParms
284         Factory parameter structure
285 
286         @param rAnimator
287         Animator sub-object
288 
289         @param xNode
290         The SMIL animation node to animate
291     */
292     static AnimationActivitySharedPtr createAnimateActivity(
293         const CommonParameters&                        rParms,
294         const BoolAnimationSharedPtr&                  rAnimator,
295         const ::com::sun::star::uno::Reference<
296         ::com::sun::star::animations::XAnimate >&      xNode );
297 
298     /** Create a simple activity for the given animator
299 
300         This method is suited to create activities for custom
301         animations, which need a simple double value and lasts
302         a given timespan. This activity always generates values
303         from the [0,1] range.
304 
305         @param rParms
306         Factory parameter structure
307 
308         @param rAnimator
309         Animator sub-object
310 
311         @param bDirectionForward
312         If true, the activity goes 'forward', i.e. from 0 to
313         1. With false, the direction is reversed.
314     */
315     static AnimationActivitySharedPtr createSimpleActivity(
316         const CommonParameters&         rParms,
317         const NumberAnimationSharedPtr& rAnimator,
318         bool                            bDirectionForward );
319 
320 private:
321     // default: constructor/destructor disabed
322     ActivitiesFactory();
323     ~ActivitiesFactory();
324 };
325 
326 } // namespace internal
327 } // namespace presentation
328 
329 #endif /* INCLUDED_SLIDESHOW_ACTIVITIESFACTORY_HXX */
330 
331