[Libreoffice-commits] core.git: Branch 'private/quwex/gsoc-box2d-experimental' - 6 commits - external/box2d slideshow/Library_slideshow.mk slideshow/source slideshow/test

Sarper Akdemir (via logerrit) logerrit at kemper.freedesktop.org
Wed Jun 17 16:16:08 UTC 2020


Rebased ref, commits from common ancestor:
commit bff8798226248f0d0d2ea2613b183c355be26e51
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: Wed Jun 17 19:15:13 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 6c1f866bc97ab67e7e51c47be58a9da32fded7e1
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: Wed Jun 17 19:15:13 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/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 );
         }
     }
 }
commit e815a05930b5f2f0103f76a9d25c012d31cc4aca
Author:     Sarper Akdemir <q.sarperakdemir at gmail.com>
AuthorDate: Wed Jun 10 02:33:22 2020 +0300
Commit:     Sarper Akdemir <q.sarperakdemir at gmail.com>
CommitDate: Wed Jun 17 19:15:12 2020 +0300

    Add Shape mbIsForeground flag and getters and setters for it
    
    mbIsForeground is a flag that is set if a shape is known to not belong
    to the foreground.
    
    It is set to false while shapes are being imported and the shape
    belongs to the master slide or is a group shape, right now.
    
    Change-Id: I7f7d5cc8b5ca99961049ab7b1062fa20b77884ca

diff --git a/slideshow/source/engine/shapes/backgroundshape.cxx b/slideshow/source/engine/shapes/backgroundshape.cxx
index 88d48b7e72e9..a4e02ac7e0c1 100644
--- a/slideshow/source/engine/shapes/backgroundshape.cxx
+++ b/slideshow/source/engine/shapes/backgroundshape.cxx
@@ -83,6 +83,8 @@ namespace slideshow::internal
             virtual ::basegfx::B2DRectangle getUpdateArea() const override;
             virtual bool isVisible() const override;
             virtual double getPriority() const override;
+            virtual bool isForeground() const override;
+            virtual void setIsForeground( const bool bIsForeground) override;
             virtual bool isBackgroundDetached() const override;
 
 
@@ -98,6 +100,7 @@ namespace slideshow::internal
             GDIMetaFileSharedPtr        mpMtf;
 
             // The attributes of this Shape
+            bool                        mbIsForeground;
             ::basegfx::B2DRectangle     maBounds; // always needed for rendering
 
             /// the list of active view shapes (one for each registered view layer)
@@ -111,6 +114,7 @@ namespace slideshow::internal
                                           const uno::Reference< drawing::XDrawPage >& xMasterPage,
                                           const SlideShowContext&                     rContext ) :
             mpMtf(),
+            mbIsForeground(true),
             maBounds(),
             maViewShapes()
         {
@@ -235,6 +239,16 @@ namespace slideshow::internal
             return 0.0; // lowest prio, we're the background
         }
 
+        bool BackgroundShape::isForeground() const
+        {
+            return mbIsForeground;
+        }
+
+        void BackgroundShape::setIsForeground( const bool bIsForeground )
+        {
+            mbIsForeground = bIsForeground;
+        }
+
         bool BackgroundShape::update() const
         {
             return render();
diff --git a/slideshow/source/engine/shapes/drawshape.cxx b/slideshow/source/engine/shapes/drawshape.cxx
index e8fcd0299ab3..3b9df45dcc91 100644
--- a/slideshow/source/engine/shapes/drawshape.cxx
+++ b/slideshow/source/engine/shapes/drawshape.cxx
@@ -346,6 +346,7 @@ namespace slideshow::internal
                                 ? MTF_LOAD_FOREIGN_SOURCE : MTF_LOAD_NONE ),
             maCurrentShapeUnitBounds(),
             mnPriority( nPrio ), // TODO(F1): When ZOrder someday becomes usable: make this ( getAPIShapePrio( xShape ) ),
+            mbIsForeground(true),
             maBounds( getAPIShapeBounds( xShape ) ),
             mpAttributeLayer(),
             mpIntrinsicAnimationActivity(),
@@ -455,6 +456,7 @@ namespace slideshow::internal
             mnCurrMtfLoadFlags( rSrc.mnCurrMtfLoadFlags ),
             maCurrentShapeUnitBounds(),
             mnPriority( nPrio ),
+            mbIsForeground(true),
             maBounds( rSrc.maBounds ),
             mpAttributeLayer(),
             mpIntrinsicAnimationActivity(),
@@ -796,6 +798,16 @@ namespace slideshow::internal
             return mnPriority;
         }
 
+        bool DrawShape::isForeground() const
+        {
+            return mbIsForeground;
+        }
+
+        void DrawShape::setIsForeground(const bool bIsForeground)
+        {
+            mbIsForeground = bIsForeground;
+        }
+
         bool DrawShape::isBackgroundDetached() const
         {
             return mnIsAnimatedCount > 0;
diff --git a/slideshow/source/engine/shapes/drawshape.hxx b/slideshow/source/engine/shapes/drawshape.hxx
index e4def440fe3d..9e65472fd14a 100644
--- a/slideshow/source/engine/shapes/drawshape.hxx
+++ b/slideshow/source/engine/shapes/drawshape.hxx
@@ -137,6 +137,8 @@ namespace slideshow
             virtual ::basegfx::B2DRectangle getUpdateArea() const override;
             virtual bool isVisible() const override;
             virtual double getPriority() const override;
+            virtual bool isForeground() const override;
+            virtual void setIsForeground( const bool bIsForeground ) override;
 
 
             // animation methods
@@ -296,6 +298,7 @@ namespace slideshow
 
             // The attributes of this Shape
             const double                                                            mnPriority;
+            bool                                                                    mbIsForeground;
             ::basegfx::B2DRectangle                                                 maBounds; // always needed for rendering.
                                                                                               // for subset shapes, this member
                                                                                               // might change when views are
diff --git a/slideshow/source/engine/shapes/externalshapebase.cxx b/slideshow/source/engine/shapes/externalshapebase.cxx
index aeff0f412cc9..d2aee17170ed 100644
--- a/slideshow/source/engine/shapes/externalshapebase.cxx
+++ b/slideshow/source/engine/shapes/externalshapebase.cxx
@@ -85,6 +85,7 @@ namespace slideshow::internal
             mpShapeManager( rContext.mpSubsettableShapeManager ),
             mrEventMultiplexer( rContext.mrEventMultiplexer ),
             mnPriority( nPrio ), // TODO(F1): When ZOrder someday becomes usable: make this ( getAPIShapePrio( xShape ) ),
+            mbIsForeground(true),
             maBounds( getAPIShapeBounds( xShape ) )
         {
             ENSURE_OR_THROW( mxShape.is(), "ExternalShapeBase::ExternalShapeBase(): Invalid XShape" );
@@ -198,6 +199,15 @@ namespace slideshow::internal
             return mnPriority;
         }
 
+        bool ExternalShapeBase::isForeground() const
+        {
+            return mbIsForeground;
+        }
+
+        void ExternalShapeBase::setIsForeground( const bool bIsForeground )
+        {
+            mbIsForeground = bIsForeground;
+        }
 
         bool ExternalShapeBase::isBackgroundDetached() const
         {
diff --git a/slideshow/source/engine/shapes/externalshapebase.hxx b/slideshow/source/engine/shapes/externalshapebase.hxx
index 6b455e387f07..f3c5fa63e49f 100644
--- a/slideshow/source/engine/shapes/externalshapebase.hxx
+++ b/slideshow/source/engine/shapes/externalshapebase.hxx
@@ -84,6 +84,8 @@ namespace slideshow
             virtual ::basegfx::B2DRectangle getUpdateArea() const override;
             virtual bool   isVisible() const override;
             virtual double getPriority() const override;
+            virtual bool   isForeground() const override;
+            virtual void   setIsForeground( const bool bIsForeground ) override;
             virtual bool   isBackgroundDetached() const override;
 
         protected:
@@ -122,6 +124,7 @@ namespace slideshow
 
             // The attributes of this Shape
             const double                                                            mnPriority;
+            bool                                                                    mbIsForeground;
             ::basegfx::B2DRectangle                                                 maBounds;
         };
     }
diff --git a/slideshow/source/engine/shapes/shapeimporter.cxx b/slideshow/source/engine/shapes/shapeimporter.cxx
index b1b1b3417269..60e884ef6696 100644
--- a/slideshow/source/engine/shapes/shapeimporter.cxx
+++ b/slideshow/source/engine/shapes/shapeimporter.cxx
@@ -97,12 +97,15 @@ public:
     virtual basegfx::B2DRectangle getUpdateArea() const override;
     virtual bool isVisible() const override;
     virtual double getPriority() const override;
+    virtual bool isForeground() const override;
+    virtual void setIsForeground( const bool bIsForeground ) override;
     virtual bool isBackgroundDetached() const override;
 
 private:
     ShapeSharedPtr const                  mpGroupShape;
     uno::Reference<drawing::XShape> const mxShape;
     double const                          mnPrio;
+    bool                                  mbIsForeground;
     basegfx::B2DPoint                     maPosOffset;
     double                                mnWidth;
     double                                mnHeight;
@@ -114,7 +117,8 @@ ShapeOfGroup::ShapeOfGroup( ShapeSharedPtr const&                      pGroupSha
                             double                                     nPrio ) :
     mpGroupShape(pGroupShape),
     mxShape(xShape),
-    mnPrio(nPrio)
+    mnPrio(nPrio),
+    mbIsForeground(true)
 {
     // read bound rect
     uno::Any const aTmpRect_( xPropSet->getPropertyValue( "BoundRect" ));
@@ -188,6 +192,16 @@ double ShapeOfGroup::getPriority() const
     return mnPrio;
 }
 
+bool ShapeOfGroup::isForeground() const
+{
+    return mbIsForeground;
+}
+
+void ShapeOfGroup::setIsForeground(const bool bIsForeground)
+{
+    mbIsForeground = bIsForeground;
+}
+
 bool ShapeOfGroup::isBackgroundDetached() const
 {
     return false;
@@ -426,6 +440,7 @@ ShapeSharedPtr ShapeImporter::importBackgroundShape() // throw (ShapeLoadFailedE
                                   uno::UNO_QUERY_THROW),
                               mrContext) );
     mnAscendingPrio += 1.0;
+    pBgShape->setIsForeground(false);
 
     return pBgShape;
 }
@@ -495,6 +510,7 @@ ShapeSharedPtr ShapeImporter::importShape() // throw (ShapeLoadFailedException)
         }
         if( bIsGroupShape && pRet )
         {
+            pRet->setIsForeground(false);
             // push new group on the stack: group traversal
             maShapesStack.push( XShapesEntry( pRet ) );
         }
diff --git a/slideshow/source/engine/slide/slideimpl.cxx b/slideshow/source/engine/slide/slideimpl.cxx
index 0805d084e9fa..a9120c6da829 100644
--- a/slideshow/source/engine/slide/slideimpl.cxx
+++ b/slideshow/source/engine/slide/slideimpl.cxx
@@ -981,7 +981,10 @@ bool SlideImpl::loadShapes()
                     ShapeSharedPtr const& rShape(
                         aMPShapesFunctor.importShape() );
                     if( rShape )
+                    {
+                        rShape->setIsForeground(false);
                         mpLayerManager->addShape( rShape );
+                    }
                 }
                 addPolygons(aMPShapesFunctor.getPolygons());
 
diff --git a/slideshow/source/inc/shape.hxx b/slideshow/source/inc/shape.hxx
index 9b6099462ab6..a522a0f76766 100644
--- a/slideshow/source/inc/shape.hxx
+++ b/slideshow/source/inc/shape.hxx
@@ -204,6 +204,24 @@ namespace slideshow
              */
             virtual bool isBackgroundDetached() const = 0;
 
+            /** Check whether the shape belongs to the foreground
+
+                For instance, if the shape is part of the Master slide
+                it does not belong to the foreground.
+
+               @return true if the shape is on the foreground
+             */
+            virtual bool isForeground() const = 0;
+
+            /**
+               Set the flag that holds wheter the shape is
+               in the foreground or not
+
+               @param bIsForeground
+               Shape is on the foreground
+             */
+            virtual void setIsForeground( const bool bIsForeground ) = 0;
+
             // Misc
 
 
diff --git a/slideshow/test/testshape.cxx b/slideshow/test/testshape.cxx
index db7031070ba8..d13a05f2be1e 100644
--- a/slideshow/test/testshape.cxx
+++ b/slideshow/test/testshape.cxx
@@ -44,6 +44,7 @@ class ImplTestShape : public TestShape,
     ViewVector               maViewLayers;
     const basegfx::B2DRange  maRect;
     const double             mnPrio;
+    bool                     mbIsForeground;
     sal_Int32                mnAnimated;
     mutable sal_Int32        mnNumUpdates;
     mutable sal_Int32        mnNumRenders;
@@ -55,6 +56,7 @@ public:
         maViewLayers(),
         maRect( rRect ),
         mnPrio( nPrio ),
+        mbIsForeground(true),
         mnAnimated(0),
         mnNumUpdates(0),
         mnNumRenders(0)
@@ -175,6 +177,14 @@ private:
     {
         return mnPrio;
     }
+    virtual bool isForeground() const override
+    {
+        return mbIsForeground;
+    }
+    virtual void setIsForeground( const bool bIsForeground ) override
+    {
+        mbIsForeground = bIsForeground;
+    }
     virtual bool isBackgroundDetached() const override
     {
         return mnAnimated != 0;
commit e9a15cabf203f9e6677c41e7a4d7f2465171f1a1
Author:     Sarper Akdemir <q.sarperakdemir at gmail.com>
AuthorDate: Wed Jun 10 02:11:36 2020 +0300
Commit:     Sarper Akdemir <q.sarperakdemir at gmail.com>
CommitDate: Wed Jun 17 19:15:12 2020 +0300

    adding XShapeHashMapSharedPtr getter to ShapeManager
    
    Refactoring XShapeHash in layermanager as XShapeToShapeMap
    and XShapeHash in targetpropertiescreator as XShapeToNamedValuesMap.
    This refactoring describes what the types are more clearly and
    stops violating one define rule in the desired implementation.
    
    In layer manager getting XShapeToShapeMap ready to be passed around
    changing it to be a shared pointer.
    
    And adding getter getXShapeToShapeMap to ShapeManager to enable
    Animation::start() to access Shapes and XShapes of the current
    slide.
    
    Change-Id: Ida2554b6727861b9be13acc09e2356fdd1793b3e

diff --git a/slideshow/source/engine/slide/layermanager.cxx b/slideshow/source/engine/slide/layermanager.cxx
index 2ec37ee2c6ff..6d21682aee68 100644
--- a/slideshow/source/engine/slide/layermanager.cxx
+++ b/slideshow/source/engine/slide/layermanager.cxx
@@ -67,7 +67,7 @@ namespace slideshow::internal
                                     bool                       bDisableAnimationZOrder ) :
             mrViews(rViews),
             maLayers(),
-            maXShapeHash( 101 ),
+            mpXShapeHash( std::make_shared<XShapeToShapeMap>(101) ),
             maAllShapes(),
             maUpdateShapes(),
             mnActiveSprites(0),
@@ -210,7 +210,7 @@ namespace slideshow::internal
             ENSURE_OR_THROW( rShape, "LayerManager::addShape(): invalid Shape" );
 
             // add shape to XShape hash map
-            if( !maXShapeHash.emplace(rShape->getXShape(),
+            if( !mpXShapeHash->emplace(rShape->getXShape(),
                                       rShape).second )
             {
                 // entry already present, nothing to do
@@ -252,7 +252,7 @@ namespace slideshow::internal
         bool LayerManager::removeShape( const ShapeSharedPtr& rShape )
         {
             // remove shape from XShape hash map
-            if( maXShapeHash.erase( rShape->getXShape() ) == 0 )
+            if( mpXShapeHash->erase( rShape->getXShape() ) == 0 )
                 return false; // shape not in map
 
             OSL_ASSERT( maAllShapes.find(rShape) != maAllShapes.end() );
@@ -302,8 +302,8 @@ namespace slideshow::internal
         {
             ENSURE_OR_THROW( xShape.is(), "LayerManager::lookupShape(): invalid Shape" );
 
-            const XShapeHash::const_iterator aIter( maXShapeHash.find( xShape ));
-            if( aIter == maXShapeHash.end() )
+            const XShapeToShapeMap::const_iterator aIter( mpXShapeHash->find( xShape ));
+            if( aIter == mpXShapeHash->end() )
                 return ShapeSharedPtr(); // not found
 
             // found, return data part of entry pair.
@@ -341,6 +341,11 @@ namespace slideshow::internal
             return pSubset;
         }
 
+        std::shared_ptr<XShapeToShapeMap const> LayerManager::getXShapeToShapeMapPtr() const
+        {
+            return mpXShapeHash;
+        }
+
         void LayerManager::revokeSubset( const AttributableShapeSharedPtr& rOrigShape,
                                          const AttributableShapeSharedPtr& rSubsetShape )
         {
diff --git a/slideshow/source/engine/slide/layermanager.hxx b/slideshow/source/engine/slide/layermanager.hxx
index 0f2844ced967..aa70520089bb 100644
--- a/slideshow/source/engine/slide/layermanager.hxx
+++ b/slideshow/source/engine/slide/layermanager.hxx
@@ -38,6 +38,17 @@ namespace slideshow
 {
     namespace internal
     {
+        /** A hash map which maps the XShape to the corresponding Shape object.
+
+            Provides quicker lookup than ShapeSet for simple mappings
+         */
+        typedef std::unordered_map<
+              css::uno::Reference< css::drawing::XShape >,
+              ShapeSharedPtr,
+              hash< css::uno::Reference< css::drawing::XShape > >
+            > XShapeToShapeMap;
+
+        typedef std::shared_ptr<XShapeToShapeMap> XShapeToShapeMapSharedPtr;
         /* Definition of Layermanager class */
 
         /** This class manages all of a slide's layers (and shapes)
@@ -132,6 +143,13 @@ namespace slideshow
             AttributableShapeSharedPtr getSubsetShape( const AttributableShapeSharedPtr&    rOrigShape,
                                                        const DocTreeNode&                   rTreeNode );
 
+            /** Get a map that maps all Shapes with their XShape reference as the key
+             *
+             * @return an unordered map shared pointer that contains all shapes in the
+             * current page with their XShape reference as the key
+             */
+            std::shared_ptr<XShapeToShapeMap const> getXShapeToShapeMapPtr() const;
+
             /** Revoke a previously queried subset shape.
 
                 With this method, a previously requested subset shape
@@ -219,15 +237,7 @@ namespace slideshow
             bool renderTo( const ::cppcanvas::CanvasSharedPtr& rTargetCanvas ) const;
 
         private:
-            /** A hash map which maps the XShape to the corresponding Shape object.
 
-                Provides quicker lookup than ShapeSet for simple mappings
-             */
-            typedef std::unordered_map<
-                  css::uno::Reference< css::drawing::XShape >,
-                  ShapeSharedPtr,
-                  hash< css::uno::Reference< css::drawing::XShape > >
-                > XShapeHash;
 
             class ShapeComparator
             {
@@ -311,7 +321,7 @@ namespace slideshow
 
             /** Contains all shapes with their XShape reference as the key
              */
-            XShapeHash               maXShapeHash;
+            XShapeToShapeMapSharedPtr      mpXShapeHash;
 
             /** Set of shapes this LayerManager own
 
diff --git a/slideshow/source/engine/slide/shapemanagerimpl.cxx b/slideshow/source/engine/slide/shapemanagerimpl.cxx
index 7863f7e7412b..7553297ec439 100644
--- a/slideshow/source/engine/slide/shapemanagerimpl.cxx
+++ b/slideshow/source/engine/slide/shapemanagerimpl.cxx
@@ -267,6 +267,14 @@ ShapeSharedPtr ShapeManagerImpl::lookupShape( uno::Reference< drawing::XShape >
     return ShapeSharedPtr();
 }
 
+std::shared_ptr<XShapeToShapeMap const> ShapeManagerImpl::getXShapeToShapeMapPtr() const
+{
+    if( mpLayerManager )
+        return mpLayerManager->getXShapeToShapeMapPtr();
+
+    return XShapeToShapeMapSharedPtr();
+}
+
 void ShapeManagerImpl::addHyperlinkArea( const HyperlinkAreaSharedPtr& rArea )
 {
     maHyperlinkShapes.insert(rArea);
diff --git a/slideshow/source/engine/slide/shapemanagerimpl.hxx b/slideshow/source/engine/slide/shapemanagerimpl.hxx
index 9730975630b0..fdb37924ba2f 100644
--- a/slideshow/source/engine/slide/shapemanagerimpl.hxx
+++ b/slideshow/source/engine/slide/shapemanagerimpl.hxx
@@ -120,6 +120,7 @@ private:
     virtual void notifyShapeUpdate( const ShapeSharedPtr& rShape ) override;
     virtual ShapeSharedPtr lookupShape(
         css::uno::Reference< css::drawing::XShape > const & xShape ) const override;
+    virtual std::shared_ptr<XShapeToShapeMap const> getXShapeToShapeMapPtr() const override;
     virtual void addHyperlinkArea( const HyperlinkAreaSharedPtr& rArea ) override;
 
 
diff --git a/slideshow/source/engine/slide/targetpropertiescreator.cxx b/slideshow/source/engine/slide/targetpropertiescreator.cxx
index 7a70b8b63352..b159bc6c2778 100644
--- a/slideshow/source/engine/slide/targetpropertiescreator.cxx
+++ b/slideshow/source/engine/slide/targetpropertiescreator.cxx
@@ -85,14 +85,14 @@ namespace slideshow::internal
         };
 
         // A hash map which maps a XShape to the corresponding vector of initial properties
-        typedef std::unordered_map< ShapeHashKey, VectorOfNamedValues, ShapeKeyHasher > XShapeHash;
+        typedef std::unordered_map< ShapeHashKey, VectorOfNamedValues, ShapeKeyHasher > XShapeToNamedValuesMap;
 
 
         class NodeFunctor
         {
         public:
             explicit NodeFunctor(
-                XShapeHash& rShapeHash,
+                XShapeToNamedValuesMap& rShapeHash,
                 bool bInitial )
             :   mrShapeHash( rShapeHash ),
                 mxTargetShape(),
@@ -101,7 +101,7 @@ namespace slideshow::internal
             {
             }
 
-            NodeFunctor( XShapeHash&                                rShapeHash,
+            NodeFunctor( XShapeToNamedValuesMap&                    rShapeHash,
                          const uno::Reference< drawing::XShape >&   rTargetShape,
                          sal_Int16                                  nParagraphIndex,
                          bool                                       bInitial) :
@@ -307,7 +307,7 @@ namespace slideshow::internal
             }
 
         private:
-            XShapeHash&                         mrShapeHash;
+            XShapeToNamedValuesMap&             mrShapeHash;
             uno::Reference< drawing::XShape >   mxTargetShape;
             sal_Int16                           mnParagraphIndex;
 
@@ -324,7 +324,7 @@ namespace slideshow::internal
     {
         // scan all nodes for visibility changes, and record first
         // 'visibility=true' for each shape
-        XShapeHash aShapeHash( 101 );
+        XShapeToNamedValuesMap aShapeHash( 101 );
 
         NodeFunctor aFunctor(
             aShapeHash,
diff --git a/slideshow/source/inc/shapemanager.hxx b/slideshow/source/inc/shapemanager.hxx
index ef2e40de6466..1a504f86dfd1 100644
--- a/slideshow/source/inc/shapemanager.hxx
+++ b/slideshow/source/inc/shapemanager.hxx
@@ -23,6 +23,8 @@
 #include "disposable.hxx"
 #include <com/sun/star/uno/Reference.hxx>
 #include <memory>
+#include <unordered_map>
+#include "tools.hxx"
 
 namespace com::sun::star::drawing { class XShape; }
 
@@ -35,9 +37,15 @@ namespace slideshow
         class HyperlinkArea;
         class AnimatableShape;
         class Shape;
+        typedef std::unordered_map<
+              css::uno::Reference< css::drawing::XShape >,
+              ShapeSharedPtr,
+              hash< css::uno::Reference< css::drawing::XShape > >
+            > XShapeToShapeMap;
         typedef ::std::shared_ptr< AnimatableShape > AnimatableShapeSharedPtr;
         typedef ::std::shared_ptr< Shape > ShapeSharedPtr;
         typedef std::shared_ptr< HyperlinkArea > HyperlinkAreaSharedPtr;
+        typedef std::shared_ptr<XShapeToShapeMap> XShapeToShapeMapSharedPtr;
 
         /** ShapeManager interface
 
@@ -92,6 +100,13 @@ namespace slideshow
             virtual ShapeSharedPtr lookupShape(
                 css::uno::Reference< css::drawing::XShape > const & xShape ) const = 0;
 
+            /** Get a map that maps all Shapes with their XShape reference as the key
+             *
+             *  @return an unordered map shared pointer that contains all shapes in the
+             *  current page with their XShape reference as the key
+             */
+            virtual std::shared_ptr<XShapeToShapeMap const> getXShapeToShapeMapPtr() const = 0;
+
             /** Register given shape as a hyperlink target
 
                 @param rArea
commit 9c1dafb399e4e9760a503e43943509eff9036766
Author:     Sarper Akdemir <q.sarperakdemir at gmail.com>
AuthorDate: Fri Jun 5 20:23:21 2020 +0300
Commit:     Sarper Akdemir <q.sarperakdemir at gmail.com>
CommitDate: Wed Jun 17 19:15:12 2020 +0300

    box2d tools: initial work for physics based animation effects
    
    Two new classes for managing box2d bodies(b2Body) and box2d worlds(b2World)
    
    ::box2d::utils::Box2DBody :
    Since b2Body has a private constructor, it is forbidden to make a shared_ptr
    out of it.
    When there are multiple parallel physics based animation effects going on,
    it will be useful to share b2Body pointers around.
    This class will help with that and also has get methods that return LO types
    instead of box2d ones.
    
    ::box2d::utils::Box2DWorld :
    A class that manages b2World with convenient functions that will be needed
    during animation effects.
    
    Change-Id: Id02fefe937347029daddde043da2b8e8dba3acaf

diff --git a/slideshow/Library_slideshow.mk b/slideshow/Library_slideshow.mk
index 55c531a86f43..53324ea25dcc 100644
--- a/slideshow/Library_slideshow.mk
+++ b/slideshow/Library_slideshow.mk
@@ -24,6 +24,7 @@ $(eval $(call gb_Library_set_precompiled_header,slideshow,slideshow/inc/pch/prec
 
 $(eval $(call gb_Library_use_externals,slideshow,\
 	boost_headers \
+	box2d \
 ))
 ifeq ($(DISABLE_GUI),)
 $(eval $(call gb_Library_use_externals,slideshow,\
@@ -84,6 +85,7 @@ $(eval $(call gb_Library_add_exception_objects,slideshow,\
     slideshow/source/engine/animationnodes/propertyanimationnode \
     slideshow/source/engine/animationnodes/sequentialtimecontainer \
     slideshow/source/engine/attributemap \
+    slideshow/source/engine/box2dtools \
     slideshow/source/engine/color \
     slideshow/source/engine/delayevent \
     slideshow/source/engine/effectrewinder \
diff --git a/slideshow/source/engine/box2dtools.cxx b/slideshow/source/engine/box2dtools.cxx
new file mode 100644
index 000000000000..e10761804f0c
--- /dev/null
+++ b/slideshow/source/engine/box2dtools.cxx
@@ -0,0 +1,173 @@
+/* -*- 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 <box2dtools.hxx>
+#include <basegfx/numeric/ftools.hxx>
+#include <sal/log.hxx>
+
+namespace box2d::utils
+{
+double calculateScaleFactor(const ::basegfx::B2DVector& rSlideSize)
+{
+    double fWidth = rSlideSize.getX();
+    double fHeight = rSlideSize.getY();
+
+    if (fWidth > fHeight)
+        return BOX2D_SLIDE_SIZE_IN_METERS / fWidth;
+    else
+        return BOX2D_SLIDE_SIZE_IN_METERS / fHeight;
+}
+
+box2DWorld::box2DWorld(const ::basegfx::B2DVector& rSlideSize, const float fGravityX,
+                       const float fGravityY)
+    : maBox2DWorld(b2Vec2(fGravityX, fGravityY))
+    , mfScaleFactor(calculateScaleFactor(rSlideSize))
+{
+    createStaticFrameAroundSlide(rSlideSize);
+}
+
+b2Body* box2DWorld::createStaticFrameAroundSlide(const ::basegfx::B2DVector& rSlideSize)
+{
+    float fWidth = static_cast<float>(rSlideSize.getX() * mfScaleFactor);
+
+    // temporary solution that assumes slide is in 16 / 9
+    // since rSlide appears to give a square
+    float fHeight = BOX2D_SLIDE_SIZE_IN_METERS * 9 / 16;
+
+    // static body for creating the frame made out of four walls
+    b2BodyDef aBodyDef;
+    aBodyDef.type = b2_staticBody;
+    aBodyDef.position.Set(0, 0);
+    b2Body* pStaticBody = maBox2DWorld.CreateBody(&aBodyDef);
+
+    b2PolygonShape aPolygonShape;
+
+    b2FixtureDef aFixtureDef;
+    aFixtureDef.shape = &aPolygonShape;
+
+    //add four walls to the static body
+    aPolygonShape.SetAsBox(fWidth / 2.0f, 1.0f / 10.0f, // ground wall
+                           b2Vec2(fWidth / 2, -fHeight - 1.0f / 10.0f), 0);
+    pStaticBody->CreateFixture(&aFixtureDef);
+
+    aPolygonShape.SetAsBox(fWidth / 2.0f, 1.0f / 10.0f, // ceiling wall
+                           b2Vec2(fWidth / 2, 1.0f / 10.0f), 0);
+    pStaticBody->CreateFixture(&aFixtureDef);
+
+    aPolygonShape.SetAsBox(1.0f / 10.0f, fHeight / 2, // left wall
+                           b2Vec2(-1.0f / 10.0f, -fHeight / 2), 0);
+    pStaticBody->CreateFixture(&aFixtureDef);
+
+    aPolygonShape.SetAsBox(1.0f / 10.0f, fHeight / 2.0f, // right wall
+                           b2Vec2(fWidth + 1.0f / 10.0f, -fHeight / 2), 0);
+    pStaticBody->CreateFixture(&aFixtureDef);
+
+    return pStaticBody;
+}
+
+void box2DWorld::step(const float fTimeStep, const int nVelocityIterations,
+                      const int nPositionIterations)
+{
+    maBox2DWorld.Step(fTimeStep, nVelocityIterations, nPositionIterations);
+}
+
+b2Body* box2DWorld::createDynamicBodyFromBoundingBox(
+    const slideshow::internal::ShapeSharedPtr& rShape,
+    const slideshow::internal::ShapeAttributeLayerSharedPtr& rAttrLayer, const float fDensity,
+    const float fFriction)
+{
+    ::basegfx::B2DRectangle aShapeBounds = rShape->getBounds();
+    double fShapeWidth = aShapeBounds.getWidth() * mfScaleFactor;
+    double fShapeHeight = aShapeBounds.getHeight() * mfScaleFactor;
+
+    double fRotationAngle = ::basegfx::deg2rad(-rAttrLayer->getRotationAngle());
+
+    ::basegfx::B2DPoint aShapePosition = aShapeBounds.getCenter();
+    float fBodyPosX = aShapePosition.getX() * mfScaleFactor;
+    float fBodyPosY = aShapePosition.getY() * -mfScaleFactor;
+
+    b2BodyDef aBodyDef;
+    aBodyDef.type = b2_dynamicBody;
+    aBodyDef.position.Set(fBodyPosX, fBodyPosY);
+    aBodyDef.angle = static_cast<float>(fRotationAngle);
+
+    b2Body* pBody = maBox2DWorld.CreateBody(&aBodyDef);
+
+    b2PolygonShape aDynamicBox;
+    aDynamicBox.SetAsBox(static_cast<float>(fShapeWidth / 2), static_cast<float>(fShapeHeight / 2));
+
+    b2FixtureDef aFixtureDef;
+    aFixtureDef.shape = &aDynamicBox;
+    aFixtureDef.density = fDensity;
+    aFixtureDef.friction = fFriction;
+
+    pBody->CreateFixture(&aFixtureDef);
+    return pBody;
+}
+
+b2Body*
+box2DWorld::createStaticBodyFromBoundingBox(const slideshow::internal::ShapeSharedPtr& rShape,
+                                            const float fDensity, const float fFriction)
+{
+    ::basegfx::B2DRectangle aShapeBounds = rShape->getBounds();
+    double fShapeWidth = aShapeBounds.getWidth() * mfScaleFactor;
+    double fShapeHeight = aShapeBounds.getHeight() * mfScaleFactor;
+
+    ::basegfx::B2DPoint aShapePosition = aShapeBounds.getCenter();
+    float fBodyPosX = aShapePosition.getX() * mfScaleFactor;
+    float fBodyPosY = aShapePosition.getY() * -mfScaleFactor;
+
+    b2BodyDef aBodyDef;
+    aBodyDef.type = b2_staticBody;
+    aBodyDef.position.Set(fBodyPosX, fBodyPosY);
+
+    b2Body* pBody = maBox2DWorld.CreateBody(&aBodyDef);
+
+    b2PolygonShape aDynamicBox;
+    aDynamicBox.SetAsBox(static_cast<float>(fShapeWidth / 2), static_cast<float>(fShapeHeight / 2));
+
+    b2FixtureDef aFixtureDef;
+    aFixtureDef.shape = &aDynamicBox;
+    aFixtureDef.density = fDensity;
+    aFixtureDef.friction = fFriction;
+
+    pBody->CreateFixture(&aFixtureDef);
+    return pBody;
+}
+
+box2DBody::box2DBody(b2Body* pBox2DBody)
+    : mpBox2DBody(pBox2DBody){};
+
+::basegfx::B2DPoint box2DBody::getPosition(const ::basegfx::B2DVector& rSlideSize)
+{
+    double fScaleFactor = calculateScaleFactor(rSlideSize);
+    b2Vec2 aPosition = mpBox2DBody->GetPosition();
+    double fX = static_cast<double>(aPosition.x) / fScaleFactor;
+    double fY = static_cast<double>(aPosition.y) / -fScaleFactor;
+    return ::basegfx::B2DPoint(fX, fY);
+}
+
+double box2DBody::getAngle()
+{
+    double fAngle = static_cast<double>(mpBox2DBody->GetAngle());
+    return ::basegfx::rad2deg(-fAngle);
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/slideshow/source/inc/box2dtools.hxx b/slideshow/source/inc/box2dtools.hxx
new file mode 100644
index 000000000000..105556be879c
--- /dev/null
+++ b/slideshow/source/inc/box2dtools.hxx
@@ -0,0 +1,75 @@
+/* -*- 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 <Box2D/Box2D.h>
+#include "animatableshape.hxx"
+#include "shapeattributelayer.hxx"
+
+#define BOX2D_SLIDE_SIZE_IN_METERS 100.00f
+
+namespace box2d::utils
+{
+double calculateScaleFactor(const ::basegfx::B2DVector& rSlideSize);
+
+class box2DWorld
+{
+private:
+    b2World maBox2DWorld;
+    double mfScaleFactor;
+
+    b2Body* createStaticFrameAroundSlide(const ::basegfx::B2DVector& rSlideSize);
+
+public:
+    box2DWorld(const ::basegfx::B2DVector& rSlideSize, const float fGravityX = 0.0f,
+               const float fGravityY = -10.0f);
+
+    box2DWorld(box2DWorld&) = delete;
+
+    void step(const float fTimeStep = 1.0f / 60.0f, const int nVelocityIterations = 6,
+              const int nPositionIterations = 2);
+
+    b2Body* createDynamicBodyFromBoundingBox(
+        const slideshow::internal::ShapeSharedPtr& rShape,
+        const slideshow::internal::ShapeAttributeLayerSharedPtr& rAttrLayer,
+        const float fDensity = 1.0f, const float fFriction = 0.3f);
+
+    b2Body* createStaticBodyFromBoundingBox(const slideshow::internal::ShapeSharedPtr& rShape,
+                                            const float fDensity = 1.0f,
+                                            const float fFriction = 0.3f);
+};
+
+class box2DBody
+{
+private:
+    b2Body* mpBox2DBody;
+
+public:
+    box2DBody(b2Body* pBox2DBody);
+
+    ::basegfx::B2DPoint getPosition(const ::basegfx::B2DVector& rSlideSize);
+    double getAngle();
+};
+
+typedef std::shared_ptr<box2DWorld> Box2DWorldSharedPtr;
+typedef std::shared_ptr<box2DBody> Box2DBodySharedPtr;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit af2350ba50ff551e3dd53aebdeb654e342e34147
Author:     Sarper Akdemir <q.sarperakdemir at gmail.com>
AuthorDate: Tue Jun 16 09:33:14 2020 +0300
Commit:     Sarper Akdemir <q.sarperakdemir at gmail.com>
CommitDate: Wed Jun 17 19:15:12 2020 +0300

    box2d: remove type punning behaviour and ignore -Wshadow
    
    Adding two patches to static external library box2d
    getting rid of type punning behaviour and ignoring
    -Wshadow to get rid of errors while building.
    
    Change-Id: I5752eb484d6aafe057c9102b1ed87aaf31d6555c

diff --git a/external/box2d/UnpackedTarball_box2d.mk b/external/box2d/UnpackedTarball_box2d.mk
index 340a17511711..9aad109eeff8 100644
--- a/external/box2d/UnpackedTarball_box2d.mk
+++ b/external/box2d/UnpackedTarball_box2d.mk
@@ -11,4 +11,11 @@ $(eval $(call gb_UnpackedTarball_UnpackedTarball,box2d))
 
 $(eval $(call gb_UnpackedTarball_set_tarball,box2d,$(BOX2D_TARBALL)))
 
+$(eval $(call gb_UnpackedTarball_set_patchlevel,box2d,1))
+
+$(eval $(call gb_UnpackedTarball_add_patches,box2d, \
+	external/box2d/remove-type-punning.patch \
+	external/box2d/disable-shadow-warning-for-drawh.patch \
+))
+
 # vim: set noet sw=4 ts=4:
diff --git a/external/box2d/disable-shadow-warning-for-drawh.patch b/external/box2d/disable-shadow-warning-for-drawh.patch
new file mode 100644
index 000000000000..316a6ff9e284
--- /dev/null
+++ b/external/box2d/disable-shadow-warning-for-drawh.patch
@@ -0,0 +1,18 @@
+diff -ur box2d/Box2D/Box2D/Box2D.h box2d_patched/Box2D/Box2D/Box2D.h
+--- box2d/Box2D/Box2D/Box2D.h	2014-04-06 03:43:12.000000000 +0300
++++ box2d_patched/Box2D/Box2D/Box2D.h	2020-06-17 18:44:25.920658966 +0300
+@@ -32,7 +32,14 @@
+ // These include files constitute the main Box2D API
+ 
+ #include <Box2D/Common/b2Settings.h>
++#if defined __GNUC__
++#pragma GCC diagnostic push
++#pragma GCC diagnostic ignored "-Wshadow"
++#endif
+ #include <Box2D/Common/b2Draw.h>
++#if defined __GNUC__
++#pragma GCC diagnostic pop
++#endif
+ #include <Box2D/Common/b2Timer.h>
+ 
+ #include <Box2D/Collision/Shapes/b2CircleShape.h>
diff --git a/external/box2d/remove-type-punning.patch b/external/box2d/remove-type-punning.patch
new file mode 100644
index 000000000000..20b5e49eb936
--- /dev/null
+++ b/external/box2d/remove-type-punning.patch
@@ -0,0 +1,13 @@
+diff -ru box2d/Box2D/Box2D/Common/b2Math.h box2d_patched/Box2D/Box2D/Common/b2Math.h
+--- box2d/Box2D/Box2D/Common/b2Math.h	2014-04-06 03:43:12.000000000 +0300
++++ box2d_patched/Box2D/Box2D/Common/b2Math.h	2020-06-16 07:37:31.713248714 +0300
+@@ -25,8 +25,7 @@
+ /// This function is used to ensure that a floating point number is not a NaN or infinity.
+ inline bool b2IsValid(float32 x)
+ {
+-	int32 ix = *reinterpret_cast<int32*>(&x);
+-	return (ix & 0x7f800000) != 0x7f800000;
++	return isfinite(x);
+ }
+ 
+ /// This is a approximate yet fast inverse square-root.


More information about the Libreoffice-commits mailing list