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 .
20 #include "animationphysicsnode.hxx"
21 #include <animationfactory.hxx>
23 constexpr double fDefaultStartVelocityX(0.0);
24 constexpr double fDefaultStartVelocityY(0.0);
25 constexpr double fDefaultDensity(1.0);
26 constexpr double fDefaultBounciness(0.1);
28 namespace slideshow::internal
30 void AnimationPhysicsNode::dispose()
32 mxPhysicsMotionNode
.clear();
33 AnimationBaseNode::dispose();
36 AnimationActivitySharedPtr
AnimationPhysicsNode::createActivity() const
38 double fDuration(0.0);
39 ENSURE_OR_THROW((mxPhysicsMotionNode
->getDuration() >>= fDuration
),
40 "Couldn't get the animation duration.");
42 ::css::uno::Any aTemp
;
43 double fStartVelocityX
= fDefaultStartVelocityX
;
44 aTemp
= mxPhysicsMotionNode
->getStartVelocityX();
46 aTemp
>>= fStartVelocityX
;
48 double fStartVelocityY
= fDefaultStartVelocityY
;
49 aTemp
= mxPhysicsMotionNode
->getStartVelocityY();
51 aTemp
>>= fStartVelocityY
;
53 double fDensity
= fDefaultDensity
;
54 aTemp
= mxPhysicsMotionNode
->getDensity();
58 fDensity
= (fDensity
< 0.0) ? 0.0 : fDensity
;
61 double fBounciness
= fDefaultBounciness
;
62 aTemp
= mxPhysicsMotionNode
->getBounciness();
65 aTemp
>>= fBounciness
;
66 fBounciness
= std::clamp(fBounciness
, 0.0, 1.0);
69 ActivitiesFactory::CommonParameters
const aParms(fillCommonParameters());
70 return ActivitiesFactory::createSimpleActivity(
72 AnimationFactory::createPhysicsAnimation(
73 getContext().mpBox2DWorld
, fDuration
, getContext().mpSubsettableShapeManager
,
74 getSlideSize(), { fStartVelocityX
, fStartVelocityY
}, fDensity
, fBounciness
, 0),
78 bool AnimationPhysicsNode::enqueueActivity() const
80 return getContext().mrActivitiesQueue
.addTailActivity(mpActivity
);
83 } // namespace slideshow::internal
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */