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 <comphelper/diagnose_ex.hxx>
23 #include <sal/log.hxx>
25 #include <com/sun/star/animations/TransitionType.hpp>
26 #include <com/sun/star/animations/TransitionSubType.hpp>
28 #include <transitionfactory.hxx>
29 #include "transitionfactorytab.hxx"
30 #include "parametricpolypolygonfactory.hxx"
31 #include <animationfactory.hxx>
32 #include "clippingfunctor.hxx"
34 using namespace ::com::sun::star
;
36 namespace slideshow::internal
{
38 /***************************************************
40 *** Shape Transition Effects ***
42 ***************************************************/
46 class ClippingAnimation
: public NumberAnimation
50 const ParametricPolyPolygonSharedPtr
& rPolygon
,
51 const ShapeManagerSharedPtr
& rShapeManager
,
52 const TransitionInfo
& rTransitionInfo
,
53 bool bDirectionForward
,
56 virtual ~ClippingAnimation() override
;
58 // Animation interface
60 virtual void prefetch() override
;
61 virtual void start( const AnimatableShapeSharedPtr
& rShape
,
62 const ShapeAttributeLayerSharedPtr
& rAttrLayer
) override
;
63 virtual void end() override
;
65 // NumberAnimation interface
67 virtual bool operator()( double nValue
) override
;
68 virtual double getUnderlyingValue() const override
;
73 AnimatableShapeSharedPtr mpShape
;
74 ShapeAttributeLayerSharedPtr mpAttrLayer
;
75 ShapeManagerSharedPtr mpShapeManager
;
76 ClippingFunctor maClippingFunctor
;
80 ClippingAnimation::ClippingAnimation(
81 const ParametricPolyPolygonSharedPtr
& rPolygon
,
82 const ShapeManagerSharedPtr
& rShapeManager
,
83 const TransitionInfo
& rTransitionInfo
,
84 bool bDirectionForward
,
88 mpShapeManager( rShapeManager
),
89 maClippingFunctor( rPolygon
,
97 "ClippingAnimation::ClippingAnimation(): Invalid ShapeManager" );
100 ClippingAnimation::~ClippingAnimation()
106 catch (const uno::Exception
&)
108 TOOLS_WARN_EXCEPTION("slideshow", "");
112 void ClippingAnimation::prefetch()
116 void ClippingAnimation::start( const AnimatableShapeSharedPtr
& rShape
,
117 const ShapeAttributeLayerSharedPtr
& rAttrLayer
)
119 OSL_ENSURE( !mpShape
,
120 "ClippingAnimation::start(): Shape already set" );
121 OSL_ENSURE( !mpAttrLayer
,
122 "ClippingAnimation::start(): Attribute layer already set" );
123 ENSURE_OR_THROW( rShape
,
124 "ClippingAnimation::start(): Invalid shape" );
125 ENSURE_OR_THROW( rAttrLayer
,
126 "ClippingAnimation::start(): Invalid attribute layer" );
129 mpAttrLayer
= rAttrLayer
;
131 if( !mbSpriteActive
)
133 mpShapeManager
->enterAnimationMode( mpShape
);
134 mbSpriteActive
= true;
138 void ClippingAnimation::end()
143 void ClippingAnimation::end_()
147 mbSpriteActive
= false;
148 mpShapeManager
->leaveAnimationMode( mpShape
);
150 if( mpShape
->isContentChanged() )
151 mpShapeManager
->notifyShapeUpdate( mpShape
);
155 bool ClippingAnimation::operator()( double nValue
)
157 ENSURE_OR_RETURN_FALSE(
158 mpAttrLayer
&& mpShape
,
159 "ClippingAnimation::operator(): Invalid ShapeAttributeLayer" );
162 auto aBounds
= mpShape
->getDomBounds().getRange();
163 mpAttrLayer
->setClip( maClippingFunctor(nValue
, basegfx::B2DSize(aBounds
.getX(), aBounds
.getY())) );
165 if( mpShape
->isContentChanged() )
166 mpShapeManager
->notifyShapeUpdate( mpShape
);
171 double ClippingAnimation::getUnderlyingValue() const
175 "ClippingAnimation::getUnderlyingValue(): Invalid ShapeAttributeLayer" );
177 return 0.0; // though this should be used in concert with
178 // ActivitiesFactory::createSimpleActivity, better
179 // explicitly name our start value.
180 // Permissible range for operator() above is [0,1]
183 AnimationActivitySharedPtr
createShapeTransitionByType(
184 const ActivitiesFactory::CommonParameters
& rParms
,
185 const AnimatableShapeSharedPtr
& rShape
,
186 const ShapeManagerSharedPtr
& rShapeManager
,
187 const ::basegfx::B2DVector
& rSlideSize
,
188 css::uno::Reference
< css::animations::XTransitionFilter
> const& xTransition
,
194 "createShapeTransitionByType(): Invalid XTransition" );
196 const TransitionInfo
* pTransitionInfo(
197 getTransitionInfo( nType
, nSubType
) );
199 AnimationActivitySharedPtr pGeneratedActivity
;
200 if( pTransitionInfo
!= nullptr )
202 switch( pTransitionInfo
->meTransitionClass
)
205 case TransitionInfo::TRANSITION_INVALID
:
206 OSL_FAIL( "createShapeTransitionByType(): Invalid transition type. "
207 "Don't ask me for a 0 TransitionType, have no XTransitionFilter node instead!" );
208 return AnimationActivitySharedPtr();
211 case TransitionInfo::TRANSITION_CLIP_POLYPOLYGON
:
213 // generate parametric poly-polygon
214 ParametricPolyPolygonSharedPtr
pPoly(
215 ParametricPolyPolygonFactory::createClipPolyPolygon(
218 // create a clip activity from that
219 pGeneratedActivity
= ActivitiesFactory::createSimpleActivity(
221 std::make_shared
<ClippingAnimation
>(
225 xTransition
->getDirection(),
226 xTransition
->getMode() ),
231 case TransitionInfo::TRANSITION_SPECIAL
:
235 case animations::TransitionType::RANDOM
:
237 // select randomly one of the effects from the
238 // TransitionFactoryTable
240 const TransitionInfo
* pRandomTransitionInfo( getRandomTransitionInfo() );
242 ENSURE_OR_THROW( pRandomTransitionInfo
!= nullptr,
243 "createShapeTransitionByType(): Got invalid random transition info" );
245 ENSURE_OR_THROW( pRandomTransitionInfo
->mnTransitionType
!= animations::TransitionType::RANDOM
,
246 "createShapeTransitionByType(): Got random again for random input!" );
249 pGeneratedActivity
= createShapeTransitionByType( rParms
,
254 pRandomTransitionInfo
->mnTransitionType
,
255 pRandomTransitionInfo
->mnTransitionSubType
);
259 // TODO(F3): Implement slidewipe for shape
260 case animations::TransitionType::SLIDEWIPE
:
262 sal_Int16
nBarWipeSubType(0);
263 bool bDirectionForward(true);
265 // map slidewipe to BARWIPE, for now
268 case animations::TransitionSubType::FROMLEFT
:
269 nBarWipeSubType
= animations::TransitionSubType::LEFTTORIGHT
;
270 bDirectionForward
= true;
273 case animations::TransitionSubType::FROMRIGHT
:
274 nBarWipeSubType
= animations::TransitionSubType::LEFTTORIGHT
;
275 bDirectionForward
= false;
278 case animations::TransitionSubType::FROMTOP
:
279 nBarWipeSubType
= animations::TransitionSubType::TOPTOBOTTOM
;
280 bDirectionForward
= true;
283 case animations::TransitionSubType::FROMBOTTOM
:
284 nBarWipeSubType
= animations::TransitionSubType::TOPTOBOTTOM
;
285 bDirectionForward
= false;
289 ENSURE_OR_THROW( false,
290 "createShapeTransitionByType(): Unexpected subtype for SLIDEWIPE" );
294 // generate parametric poly-polygon
295 ParametricPolyPolygonSharedPtr
pPoly(
296 ParametricPolyPolygonFactory::createClipPolyPolygon(
297 animations::TransitionType::BARWIPE
,
300 // create a clip activity from that
301 pGeneratedActivity
= ActivitiesFactory::createSimpleActivity(
303 std::make_shared
<ClippingAnimation
>(
306 *getTransitionInfo( animations::TransitionType::BARWIPE
,
309 xTransition
->getMode() ),
316 // TODO(F1): Check whether there's anything left, anyway,
317 // for _shape_ transitions. AFAIK, there are no special
318 // effects for shapes...
320 // for now, map all to fade effect
321 pGeneratedActivity
= ActivitiesFactory::createSimpleActivity(
323 AnimationFactory::createNumberPropertyAnimation(
329 xTransition
->getMode() );
338 if( !pGeneratedActivity
)
340 // No animation generated, maybe no table entry for given
342 SAL_WARN("slideshow",
343 "createShapeTransitionByType(): Unknown type/subtype combination encountered: "
344 << xTransition
->getTransition() << " " << xTransition
->getSubtype() );
347 return pGeneratedActivity
;
352 AnimationActivitySharedPtr
TransitionFactory::createShapeTransition(
353 const ActivitiesFactory::CommonParameters
& rParms
,
354 const AnimatableShapeSharedPtr
& rShape
,
355 const ShapeManagerSharedPtr
& rShapeManager
,
356 const ::basegfx::B2DVector
& rSlideSize
,
357 uno::Reference
< animations::XTransitionFilter
> const& xTransition
)
359 return createShapeTransitionByType( rParms
,
364 xTransition
->getTransition(),
365 xTransition
->getSubtype() );
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */