1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <canvas/debug.hxx>
22 #include <tools/diagnose_ex.h>
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>
30 #include <com/sun/star/animations/TransitionType.hpp>
31 #include <com/sun/star/animations/TransitionSubType.hpp>
33 #include "transitionfactory.hxx"
34 #include "transitionfactorytab.hxx"
35 #include "transitiontools.hxx"
36 #include "parametricpolypolygonfactory.hxx"
37 #include "animationfactory.hxx"
38 #include "clippingfunctor.hxx"
40 using namespace ::com::sun::star
;
45 /***************************************************
47 *** Shape Transition Effects ***
49 ***************************************************/
53 class ClippingAnimation
: public NumberAnimation
57 const ParametricPolyPolygonSharedPtr
& rPolygon
,
58 const ShapeManagerSharedPtr
& rShapeManager
,
59 const TransitionInfo
& rTransitionInfo
,
60 bool bDirectionForward
,
63 virtual ~ClippingAnimation();
65 // Animation interface
67 virtual void prefetch( const AnimatableShapeSharedPtr
& rShape
,
68 const ShapeAttributeLayerSharedPtr
& rAttrLayer
) SAL_OVERRIDE
;
69 virtual void start( const AnimatableShapeSharedPtr
& rShape
,
70 const ShapeAttributeLayerSharedPtr
& rAttrLayer
) SAL_OVERRIDE
;
71 virtual void end() SAL_OVERRIDE
;
73 // NumberAnimation interface
75 virtual bool operator()( double nValue
) SAL_OVERRIDE
;
76 virtual double getUnderlyingValue() const SAL_OVERRIDE
;
81 AnimatableShapeSharedPtr mpShape
;
82 ShapeAttributeLayerSharedPtr mpAttrLayer
;
83 ShapeManagerSharedPtr mpShapeManager
;
84 ClippingFunctor maClippingFunctor
;
88 ClippingAnimation::ClippingAnimation(
89 const ParametricPolyPolygonSharedPtr
& rPolygon
,
90 const ShapeManagerSharedPtr
& rShapeManager
,
91 const TransitionInfo
& rTransitionInfo
,
92 bool bDirectionForward
,
96 mpShapeManager( rShapeManager
),
97 maClippingFunctor( rPolygon
,
101 mbSpriteActive(false)
105 "ClippingAnimation::ClippingAnimation(): Invalid ShapeManager" );
108 ClippingAnimation::~ClippingAnimation()
114 catch (uno::Exception
&)
116 OSL_FAIL( OUStringToOString(
117 comphelper::anyToString(
118 cppu::getCaughtException() ),
119 RTL_TEXTENCODING_UTF8
).getStr() );
123 void ClippingAnimation::prefetch( const AnimatableShapeSharedPtr
&,
124 const ShapeAttributeLayerSharedPtr
& )
128 void ClippingAnimation::start( const AnimatableShapeSharedPtr
& rShape
,
129 const ShapeAttributeLayerSharedPtr
& rAttrLayer
)
131 OSL_ENSURE( !mpShape
,
132 "ClippingAnimation::start(): Shape already set" );
133 OSL_ENSURE( !mpAttrLayer
,
134 "ClippingAnimation::start(): Attribute layer already set" );
135 ENSURE_OR_THROW( rShape
,
136 "ClippingAnimation::start(): Invalid shape" );
137 ENSURE_OR_THROW( rAttrLayer
,
138 "ClippingAnimation::start(): Invalid attribute layer" );
141 mpAttrLayer
= rAttrLayer
;
143 if( !mbSpriteActive
)
145 mpShapeManager
->enterAnimationMode( mpShape
);
146 mbSpriteActive
= true;
150 void ClippingAnimation::end()
155 void ClippingAnimation::end_()
159 mbSpriteActive
= false;
160 mpShapeManager
->leaveAnimationMode( mpShape
);
162 if( mpShape
->isContentChanged() )
163 mpShapeManager
->notifyShapeUpdate( mpShape
);
167 bool ClippingAnimation::operator()( double nValue
)
169 ENSURE_OR_RETURN_FALSE(
170 mpAttrLayer
&& mpShape
,
171 "ClippingAnimation::operator(): Invalid ShapeAttributeLayer" );
174 mpAttrLayer
->setClip( maClippingFunctor( nValue
,
175 mpShape
->getDomBounds().getRange() ) );
177 if( mpShape
->isContentChanged() )
178 mpShapeManager
->notifyShapeUpdate( mpShape
);
183 double ClippingAnimation::getUnderlyingValue() const
187 "ClippingAnimation::getUnderlyingValue(): Invalid ShapeAttributeLayer" );
189 return 0.0; // though this should be used in concert with
190 // ActivitiesFactory::createSimpleActivity, better
191 // explicitly name our start value.
192 // Permissible range for operator() above is [0,1]
195 AnimationActivitySharedPtr
createShapeTransitionByType(
196 const ActivitiesFactory::CommonParameters
& rParms
,
197 const AnimatableShapeSharedPtr
& rShape
,
198 const ShapeManagerSharedPtr
& rShapeManager
,
199 const ::basegfx::B2DVector
& rSlideSize
,
200 ::com::sun::star::uno::Reference
<
201 ::com::sun::star::animations::XTransitionFilter
> const& xTransition
,
207 "createShapeTransitionByType(): Invalid XTransition" );
209 const TransitionInfo
* pTransitionInfo(
210 getTransitionInfo( nType
, nSubType
) );
212 AnimationActivitySharedPtr pGeneratedActivity
;
213 if( pTransitionInfo
!= NULL
)
215 switch( pTransitionInfo
->meTransitionClass
)
218 case TransitionInfo::TRANSITION_INVALID
:
219 OSL_FAIL( "createShapeTransitionByType(): Invalid transition type. "
220 "Don't ask me for a 0 TransitionType, have no XTransitionFilter node instead!" );
221 return AnimationActivitySharedPtr();
224 case TransitionInfo::TRANSITION_CLIP_POLYPOLYGON
:
226 // generate parametric poly-polygon
227 ParametricPolyPolygonSharedPtr
pPoly(
228 ParametricPolyPolygonFactory::createClipPolyPolygon(
231 // create a clip activity from that
232 pGeneratedActivity
= ActivitiesFactory::createSimpleActivity(
234 NumberAnimationSharedPtr(
235 new ClippingAnimation(
239 xTransition
->getDirection(),
240 xTransition
->getMode() ) ),
245 case TransitionInfo::TRANSITION_SPECIAL
:
249 case animations::TransitionType::RANDOM
:
251 // select randomly one of the effects from the
252 // TransitionFactoryTable
254 const TransitionInfo
* pRandomTransitionInfo( getRandomTransitionInfo() );
256 ENSURE_OR_THROW( pRandomTransitionInfo
!= NULL
,
257 "createShapeTransitionByType(): Got invalid random transition info" );
259 ENSURE_OR_THROW( pRandomTransitionInfo
->mnTransitionType
!= animations::TransitionType::RANDOM
,
260 "createShapeTransitionByType(): Got random again for random input!" );
263 pGeneratedActivity
= createShapeTransitionByType( rParms
,
268 pRandomTransitionInfo
->mnTransitionType
,
269 pRandomTransitionInfo
->mnTransitionSubType
);
273 // TODO(F3): Implement slidewipe for shape
274 case animations::TransitionType::SLIDEWIPE
:
276 sal_Int16
nBarWipeSubType(0);
277 bool bDirectionForward(true);
279 // map slidewipe to BARWIPE, for now
282 case animations::TransitionSubType::FROMLEFT
:
283 nBarWipeSubType
= animations::TransitionSubType::LEFTTORIGHT
;
284 bDirectionForward
= true;
287 case animations::TransitionSubType::FROMRIGHT
:
288 nBarWipeSubType
= animations::TransitionSubType::LEFTTORIGHT
;
289 bDirectionForward
= false;
292 case animations::TransitionSubType::FROMTOP
:
293 nBarWipeSubType
= animations::TransitionSubType::TOPTOBOTTOM
;
294 bDirectionForward
= true;
297 case animations::TransitionSubType::FROMBOTTOM
:
298 nBarWipeSubType
= animations::TransitionSubType::TOPTOBOTTOM
;
299 bDirectionForward
= false;
303 ENSURE_OR_THROW( false,
304 "createShapeTransitionByType(): Unexpected subtype for SLIDEWIPE" );
308 // generate parametric poly-polygon
309 ParametricPolyPolygonSharedPtr
pPoly(
310 ParametricPolyPolygonFactory::createClipPolyPolygon(
311 animations::TransitionType::BARWIPE
,
314 // create a clip activity from that
315 pGeneratedActivity
= ActivitiesFactory::createSimpleActivity(
317 NumberAnimationSharedPtr(
318 new ClippingAnimation(
321 *getTransitionInfo( animations::TransitionType::BARWIPE
,
324 xTransition
->getMode() ) ),
331 // TODO(F1): Check whether there's anything left, anyway,
332 // for _shape_ transitions. AFAIK, there are no special
333 // effects for shapes...
335 // for now, map all to fade effect
336 pGeneratedActivity
= ActivitiesFactory::createSimpleActivity(
338 AnimationFactory::createNumberPropertyAnimation(
343 xTransition
->getMode() );
352 if( !pGeneratedActivity
)
354 // No animation generated, maybe no table entry for given
357 "createShapeTransitionByType(): Unknown type/subtype (%d/%d) "
358 "combination encountered",
359 xTransition
->getTransition(),
360 xTransition
->getSubtype() );
362 "createShapeTransitionByType(): Unknown type/subtype "
363 "combination encountered" );
366 return pGeneratedActivity
;
371 AnimationActivitySharedPtr
TransitionFactory::createShapeTransition(
372 const ActivitiesFactory::CommonParameters
& rParms
,
373 const AnimatableShapeSharedPtr
& rShape
,
374 const ShapeManagerSharedPtr
& rShapeManager
,
375 const ::basegfx::B2DVector
& rSlideSize
,
376 uno::Reference
< animations::XTransitionFilter
> const& xTransition
)
378 return createShapeTransitionByType( rParms
,
383 xTransition
->getTransition(),
384 xTransition
->getSubtype() );
390 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */