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: shapetransitionfactory.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"
34 #include <canvas/debug.hxx>
35 #include <tools/diagnose_ex.h>
37 #include <comphelper/anytostring.hxx>
38 #include <cppuhelper/exc_hlp.hxx>
39 #include <basegfx/numeric/ftools.hxx>
40 #include <basegfx/matrix/b2dhommatrix.hxx>
41 #include <basegfx/polygon/b2dpolypolygontools.hxx>
43 #include <com/sun/star/animations/TransitionType.hpp>
44 #include <com/sun/star/animations/TransitionSubType.hpp>
46 #include "transitionfactory.hxx"
47 #include "transitiontools.hxx"
48 #include "parametricpolypolygonfactory.hxx"
49 #include "animationfactory.hxx"
50 #include "clippingfunctor.hxx"
52 #include <boost/bind.hpp>
55 using namespace ::com::sun::star
;
60 /***************************************************
62 *** Shape Transition Effects ***
64 ***************************************************/
68 class ClippingAnimation
: public NumberAnimation
72 const ParametricPolyPolygonSharedPtr
& rPolygon
,
73 const ShapeManagerSharedPtr
& rShapeManager
,
74 const TransitionInfo
& rTransitionInfo
,
75 bool bDirectionForward
,
80 // Animation interface
81 // -------------------
82 virtual void prefetch( const AnimatableShapeSharedPtr
& rShape
,
83 const ShapeAttributeLayerSharedPtr
& rAttrLayer
);
84 virtual void start( const AnimatableShapeSharedPtr
& rShape
,
85 const ShapeAttributeLayerSharedPtr
& rAttrLayer
);
88 // NumberAnimation interface
89 // -----------------------
90 virtual bool operator()( double nValue
);
91 virtual double getUnderlyingValue() const;
96 AnimatableShapeSharedPtr mpShape
;
97 ShapeAttributeLayerSharedPtr mpAttrLayer
;
98 ShapeManagerSharedPtr mpShapeManager
;
99 ClippingFunctor maClippingFunctor
;
103 ClippingAnimation::ClippingAnimation(
104 const ParametricPolyPolygonSharedPtr
& rPolygon
,
105 const ShapeManagerSharedPtr
& rShapeManager
,
106 const TransitionInfo
& rTransitionInfo
,
107 bool bDirectionForward
,
111 mpShapeManager( rShapeManager
),
112 maClippingFunctor( rPolygon
,
116 mbSpriteActive(false)
120 "ClippingAnimation::ClippingAnimation(): Invalid ShapeManager" );
123 ClippingAnimation::~ClippingAnimation()
129 catch (uno::Exception
&)
131 OSL_ENSURE( false, rtl::OUStringToOString(
132 comphelper::anyToString(
133 cppu::getCaughtException() ),
134 RTL_TEXTENCODING_UTF8
).getStr() );
138 void ClippingAnimation::prefetch( const AnimatableShapeSharedPtr
&,
139 const ShapeAttributeLayerSharedPtr
& )
143 void ClippingAnimation::start( const AnimatableShapeSharedPtr
& rShape
,
144 const ShapeAttributeLayerSharedPtr
& rAttrLayer
)
146 OSL_ENSURE( !mpShape
,
147 "ClippingAnimation::start(): Shape already set" );
148 OSL_ENSURE( !mpAttrLayer
,
149 "ClippingAnimation::start(): Attribute layer already set" );
152 mpAttrLayer
= rAttrLayer
;
154 ENSURE_OR_THROW( rShape
,
155 "ClippingAnimation::start(): Invalid shape" );
156 ENSURE_OR_THROW( rAttrLayer
,
157 "ClippingAnimation::start(): Invalid attribute layer" );
160 mpAttrLayer
= rAttrLayer
;
162 if( !mbSpriteActive
)
164 mpShapeManager
->enterAnimationMode( mpShape
);
165 mbSpriteActive
= true;
169 void ClippingAnimation::end()
174 void ClippingAnimation::end_()
178 mbSpriteActive
= false;
179 mpShapeManager
->leaveAnimationMode( mpShape
);
181 if( mpShape
->isContentChanged() )
182 mpShapeManager
->notifyShapeUpdate( mpShape
);
186 bool ClippingAnimation::operator()( double nValue
)
189 mpAttrLayer
&& mpShape
,
190 "ClippingAnimation::operator(): Invalid ShapeAttributeLayer" );
193 mpAttrLayer
->setClip( maClippingFunctor( nValue
,
194 mpShape
->getDomBounds().getRange() ) );
196 if( mpShape
->isContentChanged() )
197 mpShapeManager
->notifyShapeUpdate( mpShape
);
202 double ClippingAnimation::getUnderlyingValue() const
206 "ClippingAnimation::getUnderlyingValue(): Invalid ShapeAttributeLayer" );
208 return 0.0; // though this should be used in concert with
209 // ActivitiesFactory::createSimpleActivity, better
210 // explicitely name our start value.
211 // Permissible range for operator() above is [0,1]
217 AnimationActivitySharedPtr
TransitionFactory::createShapeTransition(
218 const ActivitiesFactory::CommonParameters
& rParms
,
219 const AnimatableShapeSharedPtr
& rShape
,
220 const ShapeManagerSharedPtr
& rShapeManager
,
221 const ::basegfx::B2DVector
& rSlideSize
,
222 uno::Reference
< animations::XTransitionFilter
> const& xTransition
)
224 return createShapeTransition( rParms
,
229 xTransition
->getTransition(),
230 xTransition
->getSubtype() );
233 AnimationActivitySharedPtr
TransitionFactory::createShapeTransition(
234 const ActivitiesFactory::CommonParameters
& rParms
,
235 const AnimatableShapeSharedPtr
& rShape
,
236 const ShapeManagerSharedPtr
& rShapeManager
,
237 const ::basegfx::B2DVector
& rSlideSize
,
238 ::com::sun::star::uno::Reference
<
239 ::com::sun::star::animations::XTransitionFilter
> const& xTransition
,
245 "TransitionFactory::createShapeTransition(): Invalid XTransition" );
247 const TransitionInfo
* pTransitionInfo(
248 getTransitionInfo( nType
, nSubType
) );
250 AnimationActivitySharedPtr pGeneratedActivity
;
251 if( pTransitionInfo
!= NULL
)
253 switch( pTransitionInfo
->meTransitionClass
)
256 case TransitionInfo::TRANSITION_INVALID
:
258 "TransitionFactory::createShapeTransition(): Invalid transition type. "
259 "Don't ask me for a 0 TransitionType, have no XTransitionFilter node instead!" );
260 return AnimationActivitySharedPtr();
263 case TransitionInfo::TRANSITION_CLIP_POLYPOLYGON
:
265 // generate parametric poly-polygon
266 ParametricPolyPolygonSharedPtr
pPoly(
267 ParametricPolyPolygonFactory::createClipPolyPolygon(
270 // create a clip activity from that
271 pGeneratedActivity
= ActivitiesFactory::createSimpleActivity(
273 NumberAnimationSharedPtr(
274 new ClippingAnimation(
278 xTransition
->getDirection(),
279 xTransition
->getMode() ) ),
284 case TransitionInfo::TRANSITION_SPECIAL
:
288 case animations::TransitionType::RANDOM
:
290 // select randomly one of the effects from the
291 // TransitionFactoryTable
293 const TransitionInfo
* pRandomTransitionInfo( getRandomTransitionInfo() );
295 ENSURE_OR_THROW( pRandomTransitionInfo
!= NULL
,
296 "TransitionFactory::createShapeTransition(): Got invalid random transition info" );
298 ENSURE_OR_THROW( pRandomTransitionInfo
->mnTransitionType
!= animations::TransitionType::RANDOM
,
299 "TransitionFactory::createShapeTransition(): Got random again for random input!" );
302 pGeneratedActivity
= createShapeTransition( rParms
,
307 pRandomTransitionInfo
->mnTransitionType
,
308 pRandomTransitionInfo
->mnTransitionSubType
);
312 // TODO(F3): Implement slidewipe for shape
313 case animations::TransitionType::SLIDEWIPE
:
315 sal_Int16
nBarWipeSubType(0);
316 bool bDirectionForward(true);
318 // map slidewipe to BARWIPE, for now
321 case animations::TransitionSubType::FROMLEFT
:
322 nBarWipeSubType
= animations::TransitionSubType::LEFTTORIGHT
;
323 bDirectionForward
= true;
326 case animations::TransitionSubType::FROMRIGHT
:
327 nBarWipeSubType
= animations::TransitionSubType::LEFTTORIGHT
;
328 bDirectionForward
= false;
331 case animations::TransitionSubType::FROMTOP
:
332 nBarWipeSubType
= animations::TransitionSubType::TOPTOBOTTOM
;
333 bDirectionForward
= true;
336 case animations::TransitionSubType::FROMBOTTOM
:
337 nBarWipeSubType
= animations::TransitionSubType::TOPTOBOTTOM
;
338 bDirectionForward
= false;
342 ENSURE_OR_THROW( false,
343 "TransitionFactory::createShapeTransition(): Unexpected subtype for SLIDEWIPE" );
347 // generate parametric poly-polygon
348 ParametricPolyPolygonSharedPtr
pPoly(
349 ParametricPolyPolygonFactory::createClipPolyPolygon(
350 animations::TransitionType::BARWIPE
,
353 // create a clip activity from that
354 pGeneratedActivity
= ActivitiesFactory::createSimpleActivity(
356 NumberAnimationSharedPtr(
357 new ClippingAnimation(
360 *getTransitionInfo( animations::TransitionType::BARWIPE
,
363 xTransition
->getMode() ) ),
370 // TODO(F1): Check whether there's anything left, anyway,
371 // for _shape_ transitions. AFAIK, there are no special
372 // effects for shapes...
374 // for now, map all to fade effect
375 pGeneratedActivity
= ActivitiesFactory::createSimpleActivity(
377 AnimationFactory::createNumberPropertyAnimation(
379 RTL_CONSTASCII_USTRINGPARAM("Opacity") ),
383 xTransition
->getMode() );
392 if( !pGeneratedActivity
)
394 // No animation generated, maybe no table entry for given
397 "TransitionFactory::createShapeTransition(): Unknown type/subtype (%d/%d) "
398 "combination encountered",
399 xTransition
->getTransition(),
400 xTransition
->getSubtype() );
403 "TransitionFactory::createShapeTransition(): Unknown type/subtype "
404 "combination encountered" );
407 return pGeneratedActivity
;