[Libreoffice-commits] core.git: Branch 'private/quwex/gsoc-box2d-experimental' - 2 commits - offapi/com slideshow/Library_slideshow.mk slideshow/source

Sarper Akdemir (via logerrit) logerrit at kemper.freedesktop.org
Thu Jun 18 09:43:34 UTC 2020


Rebased ref, commits from common ancestor:
commit e15e548fa61193955a8e114ec707c76a30b76d56
Author:     Sarper Akdemir <q.sarperakdemir at gmail.com>
AuthorDate: Wed Jun 17 13:08:03 2020 +0300
Commit:     Sarper Akdemir <q.sarperakdemir at gmail.com>
CommitDate: Thu Jun 18 12:42:06 2020 +0300

    override creation of PathMotionNode for testing
    
    Change-Id: Iaa1c28f00c090dda4734675e549911c711003758

diff --git a/slideshow/source/engine/animationnodes/animationnodefactory.cxx b/slideshow/source/engine/animationnodes/animationnodefactory.cxx
index a88c3a8ab7e0..f07dfd2f3572 100644
--- a/slideshow/source/engine/animationnodes/animationnodefactory.cxx
+++ b/slideshow/source/engine/animationnodes/animationnodefactory.cxx
@@ -480,7 +480,8 @@ BaseNodeSharedPtr implCreateAnimationNode(
         break;
 
     case animations::AnimationNodeType::ANIMATEMOTION:
-        pCreatedNode = std::make_shared<AnimationPathMotionNode>(
+//        pCreatedNode = std::make_shared<AnimationPathMotionNode>(
+        pCreatedNode = std::make_shared<AnimationSimulatedNode>(
                                 xNode, rParent, rContext );
         break;
 
commit 8873dcf4179764b496344303f82c8b9446233acd
Author:     Sarper Akdemir <q.sarperakdemir at gmail.com>
AuthorDate: Thu Jun 11 19:29:38 2020 +0300
Commit:     Sarper Akdemir <q.sarperakdemir at gmail.com>
CommitDate: Thu Jun 18 12:42:06 2020 +0300

    make simulated animations part of the animation engine
    
    Wiring up and creating required classes for simulated
    animations to be part of the animation engine.
    
    Creating a new animation node AnimationSimulationNode
    for simulated animations and SimulatedAnimation class
    that inherits from NumberAnimation in the animation
    factory.
    
    Change-Id: I1f125df5324673e9937b8164c0fc267c9683afa0

diff --git a/offapi/com/sun/star/animations/AnimationNodeType.idl b/offapi/com/sun/star/animations/AnimationNodeType.idl
index 31bed11ff728..770f148356ae 100644
--- a/offapi/com/sun/star/animations/AnimationNodeType.idl
+++ b/offapi/com/sun/star/animations/AnimationNodeType.idl
@@ -68,6 +68,9 @@ constants AnimationNodeType
     /** Defines a command effect. */
     const short COMMAND = 11;
 
+    /** Defines a simulated animation */
+    const short ANIMATESIMULATED = 12;
+
 };
 
 
diff --git a/slideshow/Library_slideshow.mk b/slideshow/Library_slideshow.mk
index 53324ea25dcc..398f82bd1f51 100644
--- a/slideshow/Library_slideshow.mk
+++ b/slideshow/Library_slideshow.mk
@@ -75,6 +75,7 @@ $(eval $(call gb_Library_add_exception_objects,slideshow,\
     slideshow/source/engine/animationnodes/animationnodefactory \
     slideshow/source/engine/animationnodes/animationpathmotionnode \
     slideshow/source/engine/animationnodes/animationsetnode \
+    slideshow/source/engine/animationnodes/animationsimulatednode \
     slideshow/source/engine/animationnodes/animationtransformnode \
     slideshow/source/engine/animationnodes/animationtransitionfilternode \
     slideshow/source/engine/animationnodes/basecontainernode \
diff --git a/slideshow/source/engine/animationfactory.cxx b/slideshow/source/engine/animationfactory.cxx
index f81c37b77df3..85263c35edcb 100644
--- a/slideshow/source/engine/animationfactory.cxx
+++ b/slideshow/source/engine/animationfactory.cxx
@@ -35,6 +35,7 @@
 #include <basegfx/polygon/b2dpolygontools.hxx>
 #include <basegfx/polygon/b2dpolypolygontools.hxx>
 
+#include <box2dtools.hxx>
 
 using namespace ::com::sun::star;
 
@@ -341,6 +342,166 @@ namespace slideshow::internal
                 sal_Int16                          mnAdditive;
             };
 
+            class SimulatedAnimation : public NumberAnimation
+            {
+            public:
+                SimulatedAnimation( const double                 fDuration,
+                                    sal_Int16                    nAdditive,
+                                    const ShapeManagerSharedPtr& rShapeManager,
+                                    const ::basegfx::B2DVector&  rSlideSize,
+                                    int                          nFlags ) :
+                    mfDuration(fDuration),
+                    mpShape(),
+                    mpAttrLayer(),
+                    mpShapeManager( rShapeManager ),
+                    maPageSize( rSlideSize ),
+                    maShapeOrig(),
+                    mnFlags( nFlags ),
+                    mbAnimationStarted( false ),
+                    mnAdditive( nAdditive ),
+                    mpBox2DBody(),
+                    mpBox2DWorld(),
+                    mfPreviousElapsedTime(0.00f)
+                {
+                    ENSURE_OR_THROW( rShapeManager,
+                                     "SimulatedAnimation::SimulatedAnimation(): Invalid ShapeManager" );
+                }
+
+                virtual ~SimulatedAnimation() override
+                {
+                    end_();
+                }
+
+                // Animation interface
+
+                virtual void prefetch() override
+                {}
+
+                virtual void start( const AnimatableShapeSharedPtr&     rShape,
+                                    const ShapeAttributeLayerSharedPtr& rAttrLayer ) override
+                {
+                    OSL_ENSURE( !mpShape,
+                                "PathAnimation::start(): Shape already set" );
+                    OSL_ENSURE( !mpAttrLayer,
+                                "PathAnimation::start(): Attribute layer already set" );
+
+                    mpShape = rShape;
+                    mpAttrLayer = rAttrLayer;
+
+                    mpBox2DWorld = std::make_shared<box2d::utils::box2DWorld>( maPageSize );
+                    mpBox2DBody = std::make_shared<box2d::utils::box2DBody>( mpBox2DWorld->createDynamicBodyFromBoundingBox(
+                                                                            rShape, rAttrLayer) );
+
+                    auto pXShapeHash = mpShapeManager->getXShapeToShapeMapPtr();
+
+                    // iterate over shapes in the current slide
+                    for( auto aIt = pXShapeHash->begin(); aIt != pXShapeHash->end(); aIt++ )
+                    {
+                        ShapeSharedPtr pShape = aIt->second;
+
+                        if( pShape->isVisible()
+                         && pShape->getPriority() != rShape->getPriority() // checking against our main animation shape
+                         && pShape->isForeground() )
+                        {
+                            mpBox2DWorld->createStaticBodyFromBoundingBox( pShape );
+                        }
+                    }
+
+                    ENSURE_OR_THROW( rShape,
+                                      "SimulatedAnimation::start(): Invalid shape" );
+                    ENSURE_OR_THROW( rAttrLayer,
+                                      "SimulatedAnimation::(): Invalid attribute layer" );
+
+                    // TODO(F1): Check whether _shape_ bounds are correct here.
+                    // Theoretically, our AttrLayer is way down the stack, and
+                    // we only have to consider _that_ value, not the one from
+                    // the top of the stack as returned by Shape::getBounds()
+                    if( mnAdditive == animations::AnimationAdditiveMode::SUM )
+                        maShapeOrig = mpShape->getBounds().getCenter();
+                    else
+                        maShapeOrig = mpShape->getDomBounds().getCenter();
+
+                    if( !mbAnimationStarted )
+                    {
+                        mbAnimationStarted = true;
+
+                        if( !(mnFlags & AnimationFactory::FLAG_NO_SPRITE) )
+                            mpShapeManager->enterAnimationMode( mpShape );
+                    }
+                }
+
+                virtual void end() override { end_(); }
+                void end_()
+                {
+                    if( mbAnimationStarted )
+                    {
+                        mbAnimationStarted = false;
+
+                        if( !(mnFlags & AnimationFactory::FLAG_NO_SPRITE) )
+                            mpShapeManager->leaveAnimationMode( mpShape );
+
+                        if( mpShape->isContentChanged() )
+                            mpShapeManager->notifyShapeUpdate( mpShape );
+                    }
+                }
+
+                // NumberAnimation interface
+
+
+                virtual bool operator()( double nValue ) override
+                {
+                    ENSURE_OR_RETURN_FALSE( mpAttrLayer && mpShape,
+                                       "SimulatedAnimation::operator(): Invalid ShapeAttributeLayer" );
+
+                    double fPassedTime = (mfDuration * nValue) - mfPreviousElapsedTime;
+                    double fTimeStep = 1.0f/60.0f;
+
+                    for( ; fPassedTime - fTimeStep >= 0; fPassedTime -= fTimeStep )
+                    {
+                        mpBox2DWorld->step( fTimeStep );
+                        mfPreviousElapsedTime += fTimeStep;
+                    }
+
+                    if( (nValue * mfDuration) < mfDuration )
+                    {
+                        ::basegfx::B2DPoint rOutPos = mpBox2DBody->getPosition( maPageSize );
+                        mpAttrLayer->setPosition( rOutPos );
+
+                        double fAngle = mpBox2DBody->getAngle();
+                        mpAttrLayer->setRotationAngle( fAngle );
+                    }
+
+                    if( mpShape->isContentChanged() )
+                        mpShapeManager->notifyShapeUpdate( mpShape );
+
+                    return true;
+                }
+
+                virtual double getUnderlyingValue() const override
+                {
+                    ENSURE_OR_THROW( mpAttrLayer,
+                                      "SimulatedAnimation::getUnderlyingValue(): Invalid ShapeAttributeLayer" );
+
+                    return 0.0; // though this should be used in concert with
+                                // ActivitiesFactory::createSimpleActivity, better
+                                // explicitly name our start value.
+                                // Permissible range for operator() above is [0,1]
+                }
+
+            private:
+                double                             mfDuration;
+                AnimatableShapeSharedPtr           mpShape;
+                ShapeAttributeLayerSharedPtr       mpAttrLayer;
+                ShapeManagerSharedPtr              mpShapeManager;
+                const ::basegfx::B2DSize           maPageSize;
+                ::basegfx::B2DPoint                maShapeOrig;
+                const int                          mnFlags;
+                bool                               mbAnimationStarted;
+                sal_Int16                          mnAdditive;
+                box2d::utils::Box2DBodySharedPtr   mpBox2DBody;
+                box2d::utils::Box2DWorldSharedPtr  mpBox2DWorld;
+                double                             mfPreviousElapsedTime;
+            };
 
             /** GenericAnimation template
 
@@ -1228,6 +1389,19 @@ namespace slideshow::internal
                                    nFlags );
         }
 
+        NumberAnimationSharedPtr AnimationFactory::createSimulatedAnimation(  const double                      fDuration,
+                                                                              sal_Int16                         nAdditive,
+                                                                              const AnimatableShapeSharedPtr&   /*rShape*/,
+                                                                              const ShapeManagerSharedPtr&      rShapeManager,
+                                                                              const ::basegfx::B2DVector&       rSlideSize,
+                                                                              int                               nFlags )
+        {
+            return std::make_shared<SimulatedAnimation>( fDuration, nAdditive,
+                                   rShapeManager,
+                                   rSlideSize,
+                                   nFlags );
+        }
+
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/slideshow/source/engine/animationnodes/animationnodefactory.cxx b/slideshow/source/engine/animationnodes/animationnodefactory.cxx
index f9fa01b2f1fd..a88c3a8ab7e0 100644
--- a/slideshow/source/engine/animationnodes/animationnodefactory.cxx
+++ b/slideshow/source/engine/animationnodes/animationnodefactory.cxx
@@ -33,6 +33,7 @@
 #include "propertyanimationnode.hxx"
 #include "animationsetnode.hxx"
 #include "animationpathmotionnode.hxx"
+#include "animationsimulatednode.hxx"
 #include "animationcolornode.hxx"
 #include "animationtransformnode.hxx"
 #include "animationtransitionfilternode.hxx"
@@ -493,6 +494,11 @@ BaseNodeSharedPtr implCreateAnimationNode(
                                 xNode, rParent, rContext );
         break;
 
+    case animations::AnimationNodeType::ANIMATESIMULATED:
+        pCreatedNode = std::make_shared<AnimationSimulatedNode>(
+                                xNode, rParent, rContext );
+        break;
+
     case animations::AnimationNodeType::TRANSITIONFILTER:
         pCreatedNode = std::make_shared<AnimationTransitionFilterNode>(
                                 xNode, rParent, rContext );
diff --git a/slideshow/source/engine/animationnodes/animationsimulatednode.cxx b/slideshow/source/engine/animationnodes/animationsimulatednode.cxx
new file mode 100644
index 000000000000..7655a7461088
--- /dev/null
+++ b/slideshow/source/engine/animationnodes/animationsimulatednode.cxx
@@ -0,0 +1,48 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "animationsimulatednode.hxx"
+#include <animationfactory.hxx>
+
+namespace slideshow::internal
+{
+void AnimationSimulatedNode::dispose()
+{
+    mxSimulatedMotionNode.clear();
+    AnimationBaseNode::dispose();
+}
+
+AnimationActivitySharedPtr AnimationSimulatedNode::createActivity() const
+{
+    double fDuration;
+    ENSURE_OR_THROW((mxSimulatedMotionNode->getDuration() >>= fDuration),
+                    "Couldn't get the animation duration.");
+
+    ActivitiesFactory::CommonParameters const aParms(fillCommonParameters());
+    return ActivitiesFactory::createSimpleActivity(
+        aParms,
+        AnimationFactory::createSimulatedAnimation(
+            fDuration, mxSimulatedMotionNode->getAdditive(), getShape(),
+            getContext().mpSubsettableShapeManager, getSlideSize(), 0),
+        true);
+}
+
+} // namespace slideshow::internal
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/slideshow/source/engine/animationnodes/animationsimulatednode.hxx b/slideshow/source/engine/animationnodes/animationsimulatednode.hxx
new file mode 100644
index 000000000000..82fa764c805d
--- /dev/null
+++ b/slideshow/source/engine/animationnodes/animationsimulatednode.hxx
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#pragma once
+
+#include "animationbasenode.hxx"
+#include <com/sun/star/animations/XAnimateMotion.hpp>
+
+namespace slideshow
+{
+namespace internal
+{
+class AnimationSimulatedNode : public AnimationBaseNode
+{
+public:
+    AnimationSimulatedNode(const css::uno::Reference<css::animations::XAnimationNode>& xNode,
+                           const BaseContainerNodeSharedPtr& rParent, const NodeContext& rContext)
+        : AnimationBaseNode(xNode, rParent, rContext)
+        , mxSimulatedMotionNode(xNode, css::uno::UNO_QUERY_THROW)
+    {
+    }
+
+#if defined(DBG_UTIL)
+    virtual const char* getDescription() const override { return "AnimationSimulationNode"; }
+#endif
+
+protected:
+    virtual void dispose() override;
+
+private:
+    virtual AnimationActivitySharedPtr createActivity() const override;
+
+    css::uno::Reference<css::animations::XAnimateMotion> mxSimulatedMotionNode;
+};
+
+} // namespace internal
+} // namespace slideshow
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/slideshow/source/inc/animationfactory.hxx b/slideshow/source/inc/animationfactory.hxx
index 7d2f205c63a5..690ed1e697ea 100644
--- a/slideshow/source/inc/animationfactory.hxx
+++ b/slideshow/source/inc/animationfactory.hxx
@@ -126,6 +126,13 @@ namespace slideshow
                                                                        const ShapeManagerSharedPtr&             rShapeManager,
                                                                        const ::basegfx::B2DVector&              rSlideSize,
                                                                        int                                      nFlags);
+
+            NumberAnimationSharedPtr createSimulatedAnimation( const double                      fDuration,
+                                                               sal_Int16                         nAdditive,
+                                                               const AnimatableShapeSharedPtr&   /*rShape*/,
+                                                               const ShapeManagerSharedPtr&      rShapeManager,
+                                                               const ::basegfx::B2DVector&       rSlideSize,
+                                                               int                               nFlags );
         }
     }
 }


More information about the Libreoffice-commits mailing list