LibreOffice Module slideshow (master) 1
shapetransitionfactory.cxx
Go to the documentation of this file.
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
22
23#include <sal/log.hxx>
24
25#include <com/sun/star/animations/TransitionType.hpp>
26#include <com/sun/star/animations/TransitionSubType.hpp>
27
28#include <transitionfactory.hxx>
31#include <animationfactory.hxx>
32#include "clippingfunctor.hxx"
33
34using namespace ::com::sun::star;
35
36namespace slideshow::internal {
37
38/***************************************************
39 *** ***
40 *** Shape Transition Effects ***
41 *** ***
42 ***************************************************/
43
44namespace {
45
46class ClippingAnimation : public NumberAnimation
47{
48public:
49 ClippingAnimation(
50 const ParametricPolyPolygonSharedPtr& rPolygon,
51 const ShapeManagerSharedPtr& rShapeManager,
52 const TransitionInfo& rTransitionInfo,
53 bool bDirectionForward,
54 bool bModeIn );
55
56 virtual ~ClippingAnimation() override;
57
58 // Animation interface
59
60 virtual void prefetch() override;
61 virtual void start( const AnimatableShapeSharedPtr& rShape,
62 const ShapeAttributeLayerSharedPtr& rAttrLayer ) override;
63 virtual void end() override;
64
65 // NumberAnimation interface
66
67 virtual bool operator()( double nValue ) override;
68 virtual double getUnderlyingValue() const override;
69
70private:
71 void end_();
72
76 ClippingFunctor maClippingFunctor;
78};
79
80ClippingAnimation::ClippingAnimation(
81 const ParametricPolyPolygonSharedPtr& rPolygon,
82 const ShapeManagerSharedPtr& rShapeManager,
83 const TransitionInfo& rTransitionInfo,
84 bool bDirectionForward,
85 bool bModeIn ) :
86 mpShape(),
88 mpShapeManager( rShapeManager ),
89 maClippingFunctor( rPolygon,
90 rTransitionInfo,
91 bDirectionForward,
92 bModeIn ),
93 mbSpriteActive(false)
94{
96 rShapeManager,
97 "ClippingAnimation::ClippingAnimation(): Invalid ShapeManager" );
98}
99
100ClippingAnimation::~ClippingAnimation()
101{
102 try
103 {
104 end_();
105 }
106 catch (const uno::Exception&)
107 {
108 TOOLS_WARN_EXCEPTION("slideshow", "");
109 }
110}
111
112void ClippingAnimation::prefetch()
113{
114}
115
116void ClippingAnimation::start( const AnimatableShapeSharedPtr& rShape,
117 const ShapeAttributeLayerSharedPtr& rAttrLayer )
118{
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" );
127
128 mpShape = rShape;
129 mpAttrLayer = rAttrLayer;
130
131 if( !mbSpriteActive )
132 {
133 mpShapeManager->enterAnimationMode( mpShape );
134 mbSpriteActive = true;
135 }
136}
137
138void ClippingAnimation::end()
139{
140 end_();
141}
142
143void ClippingAnimation::end_()
144{
145 if( mbSpriteActive )
146 {
147 mbSpriteActive = false;
148 mpShapeManager->leaveAnimationMode( mpShape );
149
150 if( mpShape->isContentChanged() )
151 mpShapeManager->notifyShapeUpdate( mpShape );
152 }
153}
154
155bool ClippingAnimation::operator()( double nValue )
156{
159 "ClippingAnimation::operator(): Invalid ShapeAttributeLayer" );
160
161 // set new clip
162 auto aBounds = mpShape->getDomBounds().getRange();
163 mpAttrLayer->setClip( maClippingFunctor(nValue, basegfx::B2DSize(aBounds.getX(), aBounds.getY())) );
164
165 if( mpShape->isContentChanged() )
166 mpShapeManager->notifyShapeUpdate( mpShape );
167
168 return true;
169}
170
171double ClippingAnimation::getUnderlyingValue() const
172{
175 "ClippingAnimation::getUnderlyingValue(): Invalid ShapeAttributeLayer" );
176
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]
181}
182
183AnimationActivitySharedPtr 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 )
191{
193 xTransition.is(),
194 "createShapeTransitionByType(): Invalid XTransition" );
195
196 const TransitionInfo* pTransitionInfo(
197 getTransitionInfo( nType, nSubType ) );
198
199 AnimationActivitySharedPtr pGeneratedActivity;
200 if( pTransitionInfo != nullptr )
201 {
202 switch( pTransitionInfo->meTransitionClass )
203 {
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!" );
209
210
211 case TransitionInfo::TRANSITION_CLIP_POLYPOLYGON:
212 {
213 // generate parametric poly-polygon
216 nType, nSubType ) );
217
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 );
228 }
229 break;
230
231 case TransitionInfo::TRANSITION_SPECIAL:
232 {
233 switch( nType )
234 {
235 case animations::TransitionType::RANDOM:
236 {
237 // select randomly one of the effects from the
238 // TransitionFactoryTable
239
240 const TransitionInfo* pRandomTransitionInfo( getRandomTransitionInfo() );
241
242 ENSURE_OR_THROW( pRandomTransitionInfo != nullptr,
243 "createShapeTransitionByType(): Got invalid random transition info" );
244
245 ENSURE_OR_THROW( pRandomTransitionInfo->mnTransitionType != animations::TransitionType::RANDOM,
246 "createShapeTransitionByType(): Got random again for random input!" );
247
248 // and recurse
249 pGeneratedActivity = createShapeTransitionByType( rParms,
250 rShape,
251 rShapeManager,
252 rSlideSize,
253 xTransition,
254 pRandomTransitionInfo->mnTransitionType,
255 pRandomTransitionInfo->mnTransitionSubType );
256 }
257 break;
258
259 // TODO(F3): Implement slidewipe for shape
260 case animations::TransitionType::SLIDEWIPE:
261 {
262 sal_Int16 nBarWipeSubType(0);
263 bool bDirectionForward(true);
264
265 // map slidewipe to BARWIPE, for now
266 switch( nSubType )
267 {
268 case animations::TransitionSubType::FROMLEFT:
269 nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT;
270 bDirectionForward = true;
271 break;
272
273 case animations::TransitionSubType::FROMRIGHT:
274 nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT;
275 bDirectionForward = false;
276 break;
277
278 case animations::TransitionSubType::FROMTOP:
279 nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM;
280 bDirectionForward = true;
281 break;
282
283 case animations::TransitionSubType::FROMBOTTOM:
284 nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM;
285 bDirectionForward = false;
286 break;
287
288 default:
289 ENSURE_OR_THROW( false,
290 "createShapeTransitionByType(): Unexpected subtype for SLIDEWIPE" );
291 break;
292 }
293
294 // generate parametric poly-polygon
297 animations::TransitionType::BARWIPE,
298 nBarWipeSubType ) );
299
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 );
311 }
312 break;
313
314 default:
315 {
316 // TODO(F1): Check whether there's anything left, anyway,
317 // for _shape_ transitions. AFAIK, there are no special
318 // effects for shapes...
319
320 // for now, map all to fade effect
321 pGeneratedActivity = ActivitiesFactory::createSimpleActivity(
322 rParms,
324 "Opacity",
325 rShape,
326 rShapeManager,
327 rSlideSize,
328 nullptr ),
329 xTransition->getMode() );
330 }
331 break;
332 }
333 }
334 break;
335 }
336 }
337
338 if( !pGeneratedActivity )
339 {
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() );
345 }
346
347 return pGeneratedActivity;
348}
349
350} // anon namespace
351
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 )
358{
359 return createShapeTransitionByType( rParms,
360 rShape,
361 rShapeManager,
362 rSlideSize,
363 xTransition,
364 xTransition->getTransition(),
365 xTransition->getSubtype() );
366}
367
368}
369
370/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define TOOLS_WARN_EXCEPTION(area, stream)
#define ENSURE_OR_RETURN_FALSE(c, m)
#define ENSURE_OR_THROW(c, m)
#define SAL_WARN(area, stream)
end
AnimationActivitySharedPtr createSimpleActivity(const CommonParameters &rParms, const NumberAnimationSharedPtr &rAnimator, bool bDirectionForward)
Create a simple activity for the given animator.
NumberAnimationSharedPtr createNumberPropertyAnimation(const OUString &rAttrName, const AnimatableShapeSharedPtr &rShape, const ShapeManagerSharedPtr &rShapeManager, const ::basegfx::B2DVector &rSlideSize, const box2d::utils::Box2DWorldSharedPtr &pBox2DWorld, int nFlags=0)
ParametricPolyPolygonSharedPtr createClipPolyPolygon(sal_Int16 nTransitionType, sal_Int16 nTransitionSubType)
AnimationActivitySharedPtr createShapeTransition(const ActivitiesFactory::CommonParameters &rParms, const AnimatableShapeSharedPtr &rShape, const ShapeManagerSharedPtr &rShapeManager, const ::basegfx::B2DVector &rSlideSize, css::uno::Reference< css::animations::XTransitionFilter > const &xTransition)
Create a transition effect for shapes.
::std::shared_ptr< AnimatableShape > AnimatableShapeSharedPtr
const TransitionInfo * getRandomTransitionInfo()
::std::shared_ptr< AnimationActivity > AnimationActivitySharedPtr
::std::shared_ptr< ShapeAttributeLayer > ShapeAttributeLayerSharedPtr
const TransitionInfo * getTransitionInfo(sal_Int16 nTransitionType, sal_Int16 nTransitionSubType)
std::shared_ptr< ShapeManager > ShapeManagerSharedPtr
Definition: box2dtools.hxx:23
::std::shared_ptr< ParametricPolyPolygon > ParametricPolyPolygonSharedPtr
ClippingFunctor maClippingFunctor
ShapeManagerSharedPtr mpShapeManager
AnimatableShapeSharedPtr mpShape
ShapeAttributeLayerSharedPtr mpAttrLayer
bool mbSpriteActive