android: Update app-specific/MIME type icons
[LibreOffice.git] / slideshow / source / engine / animationnodes / animationphysicsnode.cxx
blob0502f35c18d7221d41cff8bd3001fd71a40b4591
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 .
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();
45 if (aTemp.hasValue())
46 aTemp >>= fStartVelocityX;
48 double fStartVelocityY = fDefaultStartVelocityY;
49 aTemp = mxPhysicsMotionNode->getStartVelocityY();
50 if (aTemp.hasValue())
51 aTemp >>= fStartVelocityY;
53 double fDensity = fDefaultDensity;
54 aTemp = mxPhysicsMotionNode->getDensity();
55 if (aTemp.hasValue())
57 aTemp >>= fDensity;
58 fDensity = (fDensity < 0.0) ? 0.0 : fDensity;
61 double fBounciness = fDefaultBounciness;
62 aTemp = mxPhysicsMotionNode->getBounciness();
63 if (aTemp.hasValue())
65 aTemp >>= fBounciness;
66 fBounciness = std::clamp(fBounciness, 0.0, 1.0);
69 ActivitiesFactory::CommonParameters const aParms(fillCommonParameters());
70 return ActivitiesFactory::createSimpleActivity(
71 aParms,
72 AnimationFactory::createPhysicsAnimation(
73 getContext().mpBox2DWorld, fDuration, getContext().mpSubsettableShapeManager,
74 getSlideSize(), { fStartVelocityX, fStartVelocityY }, fDensity, fBounciness, 0),
75 true);
78 bool AnimationPhysicsNode::enqueueActivity() const
80 return getContext().mrActivitiesQueue.addTailActivity(mpActivity);
83 } // namespace slideshow::internal
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */