Branch data Line data Source code
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 : :
21 : : #include <canvas/debug.hxx>
22 : : #include <tools/diagnose_ex.h>
23 : :
24 : : #include <comphelper/anytostring.hxx>
25 : : #include <cppuhelper/exc_hlp.hxx>
26 : : #include <basegfx/numeric/ftools.hxx>
27 : : #include <basegfx/matrix/b2dhommatrix.hxx>
28 : : #include <basegfx/polygon/b2dpolypolygontools.hxx>
29 : :
30 : : #include <com/sun/star/animations/TransitionType.hpp>
31 : : #include <com/sun/star/animations/TransitionSubType.hpp>
32 : :
33 : : #include "transitionfactory.hxx"
34 : : #include "transitiontools.hxx"
35 : : #include "parametricpolypolygonfactory.hxx"
36 : : #include "animationfactory.hxx"
37 : : #include "clippingfunctor.hxx"
38 : :
39 : : using namespace ::com::sun::star;
40 : :
41 : : namespace slideshow {
42 : : namespace internal {
43 : :
44 : : /***************************************************
45 : : *** ***
46 : : *** Shape Transition Effects ***
47 : : *** ***
48 : : ***************************************************/
49 : :
50 : : namespace {
51 : :
52 : : class ClippingAnimation : public NumberAnimation
53 : : {
54 : : public:
55 : : ClippingAnimation(
56 : : const ParametricPolyPolygonSharedPtr& rPolygon,
57 : : const ShapeManagerSharedPtr& rShapeManager,
58 : : const TransitionInfo& rTransitionInfo,
59 : : bool bDirectionForward,
60 : : bool bModeIn );
61 : :
62 : : ~ClippingAnimation();
63 : :
64 : : // Animation interface
65 : : // -------------------
66 : : virtual void prefetch( const AnimatableShapeSharedPtr& rShape,
67 : : const ShapeAttributeLayerSharedPtr& rAttrLayer );
68 : : virtual void start( const AnimatableShapeSharedPtr& rShape,
69 : : const ShapeAttributeLayerSharedPtr& rAttrLayer );
70 : : virtual void end();
71 : :
72 : : // NumberAnimation interface
73 : : // -----------------------
74 : : virtual bool operator()( double nValue );
75 : : virtual double getUnderlyingValue() const;
76 : :
77 : : private:
78 : : void end_();
79 : :
80 : : AnimatableShapeSharedPtr mpShape;
81 : : ShapeAttributeLayerSharedPtr mpAttrLayer;
82 : : ShapeManagerSharedPtr mpShapeManager;
83 : : ClippingFunctor maClippingFunctor;
84 : : bool mbSpriteActive;
85 : : };
86 : :
87 : 0 : ClippingAnimation::ClippingAnimation(
88 : : const ParametricPolyPolygonSharedPtr& rPolygon,
89 : : const ShapeManagerSharedPtr& rShapeManager,
90 : : const TransitionInfo& rTransitionInfo,
91 : : bool bDirectionForward,
92 : : bool bModeIn ) :
93 : : mpShape(),
94 : : mpAttrLayer(),
95 : : mpShapeManager( rShapeManager ),
96 : : maClippingFunctor( rPolygon,
97 : : rTransitionInfo,
98 : : bDirectionForward,
99 : : bModeIn ),
100 : 0 : mbSpriteActive(false)
101 : : {
102 : 0 : ENSURE_OR_THROW(
103 : : rShapeManager,
104 : : "ClippingAnimation::ClippingAnimation(): Invalid ShapeManager" );
105 : 0 : }
106 : :
107 : 0 : ClippingAnimation::~ClippingAnimation()
108 : : {
109 : : try
110 : : {
111 : 0 : end_();
112 : : }
113 : 0 : catch (uno::Exception &)
114 : : {
115 : : OSL_FAIL( rtl::OUStringToOString(
116 : : comphelper::anyToString(
117 : : cppu::getCaughtException() ),
118 : : RTL_TEXTENCODING_UTF8 ).getStr() );
119 : : }
120 : 0 : }
121 : :
122 : 0 : void ClippingAnimation::prefetch( const AnimatableShapeSharedPtr&,
123 : : const ShapeAttributeLayerSharedPtr& )
124 : : {
125 : 0 : }
126 : :
127 : 0 : void ClippingAnimation::start( const AnimatableShapeSharedPtr& rShape,
128 : : const ShapeAttributeLayerSharedPtr& rAttrLayer )
129 : : {
130 : : OSL_ENSURE( !mpShape,
131 : : "ClippingAnimation::start(): Shape already set" );
132 : : OSL_ENSURE( !mpAttrLayer,
133 : : "ClippingAnimation::start(): Attribute layer already set" );
134 : 0 : ENSURE_OR_THROW( rShape,
135 : : "ClippingAnimation::start(): Invalid shape" );
136 : 0 : ENSURE_OR_THROW( rAttrLayer,
137 : : "ClippingAnimation::start(): Invalid attribute layer" );
138 : :
139 : 0 : mpShape = rShape;
140 : 0 : mpAttrLayer = rAttrLayer;
141 : :
142 : 0 : if( !mbSpriteActive )
143 : : {
144 : 0 : mpShapeManager->enterAnimationMode( mpShape );
145 : 0 : mbSpriteActive = true;
146 : : }
147 : 0 : }
148 : :
149 : 0 : void ClippingAnimation::end()
150 : : {
151 : 0 : end_();
152 : 0 : }
153 : :
154 : 0 : void ClippingAnimation::end_()
155 : : {
156 : 0 : if( mbSpriteActive )
157 : : {
158 : 0 : mbSpriteActive = false;
159 : 0 : mpShapeManager->leaveAnimationMode( mpShape );
160 : :
161 : 0 : if( mpShape->isContentChanged() )
162 : 0 : mpShapeManager->notifyShapeUpdate( mpShape );
163 : : }
164 : 0 : }
165 : :
166 : 0 : bool ClippingAnimation::operator()( double nValue )
167 : : {
168 : 0 : ENSURE_OR_RETURN_FALSE(
169 : : mpAttrLayer && mpShape,
170 : : "ClippingAnimation::operator(): Invalid ShapeAttributeLayer" );
171 : :
172 : : // set new clip
173 : : mpAttrLayer->setClip( maClippingFunctor( nValue,
174 : 0 : mpShape->getDomBounds().getRange() ) );
175 : :
176 : 0 : if( mpShape->isContentChanged() )
177 : 0 : mpShapeManager->notifyShapeUpdate( mpShape );
178 : :
179 : 0 : return true;
180 : : }
181 : :
182 : 0 : double ClippingAnimation::getUnderlyingValue() const
183 : : {
184 : 0 : ENSURE_OR_THROW(
185 : : mpAttrLayer,
186 : : "ClippingAnimation::getUnderlyingValue(): Invalid ShapeAttributeLayer" );
187 : :
188 : 0 : return 0.0; // though this should be used in concert with
189 : : // ActivitiesFactory::createSimpleActivity, better
190 : : // explicitly name our start value.
191 : : // Permissible range for operator() above is [0,1]
192 : : }
193 : :
194 : : } // anon namespace
195 : :
196 : :
197 : 0 : AnimationActivitySharedPtr TransitionFactory::createShapeTransition(
198 : : const ActivitiesFactory::CommonParameters& rParms,
199 : : const AnimatableShapeSharedPtr& rShape,
200 : : const ShapeManagerSharedPtr& rShapeManager,
201 : : const ::basegfx::B2DVector& rSlideSize,
202 : : uno::Reference< animations::XTransitionFilter > const& xTransition )
203 : : {
204 : : return createShapeTransition( rParms,
205 : : rShape,
206 : : rShapeManager,
207 : : rSlideSize,
208 : : xTransition,
209 : 0 : xTransition->getTransition(),
210 : 0 : xTransition->getSubtype() );
211 : : }
212 : :
213 : 0 : AnimationActivitySharedPtr TransitionFactory::createShapeTransition(
214 : : const ActivitiesFactory::CommonParameters& rParms,
215 : : const AnimatableShapeSharedPtr& rShape,
216 : : const ShapeManagerSharedPtr& rShapeManager,
217 : : const ::basegfx::B2DVector& rSlideSize,
218 : : ::com::sun::star::uno::Reference<
219 : : ::com::sun::star::animations::XTransitionFilter > const& xTransition,
220 : : sal_Int16 nType,
221 : : sal_Int16 nSubType )
222 : : {
223 : 0 : ENSURE_OR_THROW(
224 : : xTransition.is(),
225 : : "TransitionFactory::createShapeTransition(): Invalid XTransition" );
226 : :
227 : : const TransitionInfo* pTransitionInfo(
228 : 0 : getTransitionInfo( nType, nSubType ) );
229 : :
230 : 0 : AnimationActivitySharedPtr pGeneratedActivity;
231 : 0 : if( pTransitionInfo != NULL )
232 : : {
233 : 0 : switch( pTransitionInfo->meTransitionClass )
234 : : {
235 : : default:
236 : : case TransitionInfo::TRANSITION_INVALID:
237 : : OSL_FAIL( "TransitionFactory::createShapeTransition(): Invalid transition type. "
238 : : "Don't ask me for a 0 TransitionType, have no XTransitionFilter node instead!" );
239 : 0 : return AnimationActivitySharedPtr();
240 : :
241 : :
242 : : case TransitionInfo::TRANSITION_CLIP_POLYPOLYGON:
243 : : {
244 : : // generate parametric poly-polygon
245 : : ParametricPolyPolygonSharedPtr pPoly(
246 : : ParametricPolyPolygonFactory::createClipPolyPolygon(
247 : 0 : nType, nSubType ) );
248 : :
249 : : // create a clip activity from that
250 : : pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
251 : : rParms,
252 : : NumberAnimationSharedPtr(
253 : : new ClippingAnimation(
254 : : pPoly,
255 : : rShapeManager,
256 : : *pTransitionInfo,
257 : 0 : xTransition->getDirection(),
258 : 0 : xTransition->getMode() ) ),
259 : 0 : true );
260 : : }
261 : 0 : break;
262 : :
263 : : case TransitionInfo::TRANSITION_SPECIAL:
264 : : {
265 : 0 : switch( nType )
266 : : {
267 : : case animations::TransitionType::RANDOM:
268 : : {
269 : : // select randomly one of the effects from the
270 : : // TransitionFactoryTable
271 : :
272 : 0 : const TransitionInfo* pRandomTransitionInfo( getRandomTransitionInfo() );
273 : :
274 : 0 : ENSURE_OR_THROW( pRandomTransitionInfo != NULL,
275 : : "TransitionFactory::createShapeTransition(): Got invalid random transition info" );
276 : :
277 : 0 : ENSURE_OR_THROW( pRandomTransitionInfo->mnTransitionType != animations::TransitionType::RANDOM,
278 : : "TransitionFactory::createShapeTransition(): Got random again for random input!" );
279 : :
280 : : // and recurse
281 : : pGeneratedActivity = createShapeTransition( rParms,
282 : : rShape,
283 : : rShapeManager,
284 : : rSlideSize,
285 : : xTransition,
286 : : pRandomTransitionInfo->mnTransitionType,
287 : 0 : pRandomTransitionInfo->mnTransitionSubType );
288 : : }
289 : 0 : break;
290 : :
291 : : // TODO(F3): Implement slidewipe for shape
292 : : case animations::TransitionType::SLIDEWIPE:
293 : : {
294 : 0 : sal_Int16 nBarWipeSubType(0);
295 : 0 : bool bDirectionForward(true);
296 : :
297 : : // map slidewipe to BARWIPE, for now
298 : 0 : switch( nSubType )
299 : : {
300 : : case animations::TransitionSubType::FROMLEFT:
301 : 0 : nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT;
302 : 0 : bDirectionForward = true;
303 : 0 : break;
304 : :
305 : : case animations::TransitionSubType::FROMRIGHT:
306 : 0 : nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT;
307 : 0 : bDirectionForward = false;
308 : 0 : break;
309 : :
310 : : case animations::TransitionSubType::FROMTOP:
311 : 0 : nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM;
312 : 0 : bDirectionForward = true;
313 : 0 : break;
314 : :
315 : : case animations::TransitionSubType::FROMBOTTOM:
316 : 0 : nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM;
317 : 0 : bDirectionForward = false;
318 : 0 : break;
319 : :
320 : : default:
321 : 0 : ENSURE_OR_THROW( false,
322 : : "TransitionFactory::createShapeTransition(): Unexpected subtype for SLIDEWIPE" );
323 : : break;
324 : : }
325 : :
326 : : // generate parametric poly-polygon
327 : : ParametricPolyPolygonSharedPtr pPoly(
328 : : ParametricPolyPolygonFactory::createClipPolyPolygon(
329 : : animations::TransitionType::BARWIPE,
330 : 0 : nBarWipeSubType ) );
331 : :
332 : : // create a clip activity from that
333 : : pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
334 : : rParms,
335 : : NumberAnimationSharedPtr(
336 : : new ClippingAnimation(
337 : : pPoly,
338 : : rShapeManager,
339 : : *getTransitionInfo( animations::TransitionType::BARWIPE,
340 : 0 : nBarWipeSubType ),
341 : : bDirectionForward,
342 : 0 : xTransition->getMode() ) ),
343 : 0 : true );
344 : : }
345 : 0 : break;
346 : :
347 : : default:
348 : : {
349 : : // TODO(F1): Check whether there's anything left, anyway,
350 : : // for _shape_ transitions. AFAIK, there are no special
351 : : // effects for shapes...
352 : :
353 : : // for now, map all to fade effect
354 : : pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
355 : : rParms,
356 : : AnimationFactory::createNumberPropertyAnimation(
357 : : ::rtl::OUString(
358 : : RTL_CONSTASCII_USTRINGPARAM("Opacity") ),
359 : : rShape,
360 : : rShapeManager,
361 : : rSlideSize ),
362 : 0 : xTransition->getMode() );
363 : : }
364 : 0 : break;
365 : : }
366 : : }
367 : 0 : break;
368 : : }
369 : : }
370 : :
371 : 0 : if( !pGeneratedActivity )
372 : : {
373 : : // No animation generated, maybe no table entry for given
374 : : // transition?
375 : : OSL_TRACE(
376 : : "TransitionFactory::createShapeTransition(): Unknown type/subtype (%d/%d) "
377 : : "combination encountered",
378 : : xTransition->getTransition(),
379 : : xTransition->getSubtype() );
380 : : OSL_FAIL(
381 : : "TransitionFactory::createShapeTransition(): Unknown type/subtype "
382 : : "combination encountered" );
383 : : }
384 : :
385 : 0 : return pGeneratedActivity;
386 : : }
387 : :
388 : : }
389 : : }
390 : :
391 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|