android: Update app-specific/MIME type icons
[LibreOffice.git] / slideshow / source / engine / transitions / shapetransitionfactory.cxx
blob2df1b55a692a0f52a8c2827d83553a131d44014d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 /***************************************************
39 *** ***
40 *** Shape Transition Effects ***
41 *** ***
42 ***************************************************/
44 namespace {
46 class ClippingAnimation : public NumberAnimation
48 public:
49 ClippingAnimation(
50 const ParametricPolyPolygonSharedPtr& rPolygon,
51 const ShapeManagerSharedPtr& rShapeManager,
52 const TransitionInfo& rTransitionInfo,
53 bool bDirectionForward,
54 bool bModeIn );
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;
70 private:
71 void end_();
73 AnimatableShapeSharedPtr mpShape;
74 ShapeAttributeLayerSharedPtr mpAttrLayer;
75 ShapeManagerSharedPtr mpShapeManager;
76 ClippingFunctor maClippingFunctor;
77 bool mbSpriteActive;
80 ClippingAnimation::ClippingAnimation(
81 const ParametricPolyPolygonSharedPtr& rPolygon,
82 const ShapeManagerSharedPtr& rShapeManager,
83 const TransitionInfo& rTransitionInfo,
84 bool bDirectionForward,
85 bool bModeIn ) :
86 mpShape(),
87 mpAttrLayer(),
88 mpShapeManager( rShapeManager ),
89 maClippingFunctor( rPolygon,
90 rTransitionInfo,
91 bDirectionForward,
92 bModeIn ),
93 mbSpriteActive(false)
95 ENSURE_OR_THROW(
96 rShapeManager,
97 "ClippingAnimation::ClippingAnimation(): Invalid ShapeManager" );
100 ClippingAnimation::~ClippingAnimation()
104 end_();
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" );
128 mpShape = rShape;
129 mpAttrLayer = rAttrLayer;
131 if( !mbSpriteActive )
133 mpShapeManager->enterAnimationMode( mpShape );
134 mbSpriteActive = true;
138 void ClippingAnimation::end()
140 end_();
143 void ClippingAnimation::end_()
145 if( mbSpriteActive )
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" );
161 // set new clip
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 );
168 return true;
171 double ClippingAnimation::getUnderlyingValue() const
173 ENSURE_OR_THROW(
174 mpAttrLayer,
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,
189 sal_Int16 nType,
190 sal_Int16 nSubType )
192 ENSURE_OR_THROW(
193 xTransition.is(),
194 "createShapeTransitionByType(): Invalid XTransition" );
196 const TransitionInfo* pTransitionInfo(
197 getTransitionInfo( nType, nSubType ) );
199 AnimationActivitySharedPtr pGeneratedActivity;
200 if( pTransitionInfo != nullptr )
202 switch( pTransitionInfo->meTransitionClass )
204 default:
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(
216 nType, nSubType ) );
218 // create a clip activity from that
219 pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
220 rParms,
221 std::make_shared<ClippingAnimation>(
222 pPoly,
223 rShapeManager,
224 *pTransitionInfo,
225 xTransition->getDirection(),
226 xTransition->getMode() ),
227 true );
229 break;
231 case TransitionInfo::TRANSITION_SPECIAL:
233 switch( nType )
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!" );
248 // and recurse
249 pGeneratedActivity = createShapeTransitionByType( rParms,
250 rShape,
251 rShapeManager,
252 rSlideSize,
253 xTransition,
254 pRandomTransitionInfo->mnTransitionType,
255 pRandomTransitionInfo->mnTransitionSubType );
257 break;
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
266 switch( nSubType )
268 case animations::TransitionSubType::FROMLEFT:
269 nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT;
270 bDirectionForward = true;
271 break;
273 case animations::TransitionSubType::FROMRIGHT:
274 nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT;
275 bDirectionForward = false;
276 break;
278 case animations::TransitionSubType::FROMTOP:
279 nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM;
280 bDirectionForward = true;
281 break;
283 case animations::TransitionSubType::FROMBOTTOM:
284 nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM;
285 bDirectionForward = false;
286 break;
288 default:
289 ENSURE_OR_THROW( false,
290 "createShapeTransitionByType(): Unexpected subtype for SLIDEWIPE" );
291 break;
294 // generate parametric poly-polygon
295 ParametricPolyPolygonSharedPtr pPoly(
296 ParametricPolyPolygonFactory::createClipPolyPolygon(
297 animations::TransitionType::BARWIPE,
298 nBarWipeSubType ) );
300 // create a clip activity from that
301 pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
302 rParms,
303 std::make_shared<ClippingAnimation>(
304 pPoly,
305 rShapeManager,
306 *getTransitionInfo( animations::TransitionType::BARWIPE,
307 nBarWipeSubType ),
308 bDirectionForward,
309 xTransition->getMode() ),
310 true );
312 break;
314 default:
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(
322 rParms,
323 AnimationFactory::createNumberPropertyAnimation(
324 "Opacity",
325 rShape,
326 rShapeManager,
327 rSlideSize,
328 nullptr ),
329 xTransition->getMode() );
331 break;
334 break;
338 if( !pGeneratedActivity )
340 // No animation generated, maybe no table entry for given
341 // transition?
342 SAL_WARN("slideshow",
343 "createShapeTransitionByType(): Unknown type/subtype combination encountered: "
344 << xTransition->getTransition() << " " << xTransition->getSubtype() );
347 return pGeneratedActivity;
350 } // anon namespace
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,
360 rShape,
361 rShapeManager,
362 rSlideSize,
363 xTransition,
364 xTransition->getTransition(),
365 xTransition->getSubtype() );
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */