LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive2d - animatedprimitive2d.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 67 0.0 %
Date: 2014-11-03 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #include <drawinglayer/primitive2d/animatedprimitive2d.hxx>
      21             : #include <drawinglayer/animation/animationtiming.hxx>
      22             : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
      23             : #include <drawinglayer/geometry/viewinformation2d.hxx>
      24             : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
      25             : 
      26             : 
      27             : 
      28             : using namespace com::sun::star;
      29             : 
      30             : 
      31             : 
      32             : namespace drawinglayer
      33             : {
      34             :     namespace primitive2d
      35             :     {
      36           0 :         AnimatedSwitchPrimitive2D::AnimatedSwitchPrimitive2D(
      37             :             const animation::AnimationEntry& rAnimationEntry,
      38             :             const Primitive2DSequence& rChildren,
      39             :             bool bIsTextAnimation)
      40             :         :   GroupPrimitive2D(rChildren),
      41             :             mpAnimationEntry(0),
      42           0 :             mbIsTextAnimation(bIsTextAnimation)
      43             :         {
      44             :             // clone given animation description
      45           0 :             mpAnimationEntry = rAnimationEntry.clone();
      46           0 :         }
      47             : 
      48           0 :         AnimatedSwitchPrimitive2D::~AnimatedSwitchPrimitive2D()
      49             :         {
      50             :             // delete cloned animation description
      51           0 :             delete mpAnimationEntry;
      52           0 :         }
      53             : 
      54           0 :         bool AnimatedSwitchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
      55             :         {
      56           0 :             if(GroupPrimitive2D::operator==(rPrimitive))
      57             :             {
      58           0 :                 const AnimatedSwitchPrimitive2D& rCompare = static_cast< const AnimatedSwitchPrimitive2D& >(rPrimitive);
      59             : 
      60           0 :                 return (getAnimationEntry() == rCompare.getAnimationEntry());
      61             :             }
      62             : 
      63           0 :             return false;
      64             :         }
      65             : 
      66           0 :         Primitive2DSequence AnimatedSwitchPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
      67             :         {
      68           0 :             if(getChildren().hasElements())
      69             :             {
      70           0 :                 const double fState(getAnimationEntry().getStateAtTime(rViewInformation.getViewTime()));
      71           0 :                 const sal_uInt32 nLen(getChildren().getLength());
      72           0 :                 sal_uInt32 nIndex(basegfx::fround(fState * (double)nLen));
      73             : 
      74           0 :                 if(nIndex >= nLen)
      75             :                 {
      76           0 :                     nIndex = nLen - 1L;
      77             :                 }
      78             : 
      79           0 :                 const Primitive2DReference xRef(getChildren()[nIndex], uno::UNO_QUERY_THROW);
      80           0 :                 return Primitive2DSequence(&xRef, 1L);
      81             :             }
      82             : 
      83           0 :             return Primitive2DSequence();
      84             :         }
      85             : 
      86             :         // provide unique ID
      87           0 :         ImplPrimitive2DIDBlock(AnimatedSwitchPrimitive2D, PRIMITIVE2D_ID_ANIMATEDSWITCHPRIMITIVE2D)
      88             : 
      89             :     } // end of namespace primitive2d
      90             : } // end of namespace drawinglayer
      91             : 
      92             : 
      93             : 
      94             : namespace drawinglayer
      95             : {
      96             :     namespace primitive2d
      97             :     {
      98           0 :         AnimatedBlinkPrimitive2D::AnimatedBlinkPrimitive2D(
      99             :             const animation::AnimationEntry& rAnimationEntry,
     100             :             const Primitive2DSequence& rChildren,
     101             :             bool bIsTextAnimation)
     102           0 :         :   AnimatedSwitchPrimitive2D(rAnimationEntry, rChildren, bIsTextAnimation)
     103             :         {
     104           0 :         }
     105             : 
     106           0 :         Primitive2DSequence AnimatedBlinkPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
     107             :         {
     108           0 :             if(getChildren().hasElements())
     109             :             {
     110           0 :                 const double fState(getAnimationEntry().getStateAtTime(rViewInformation.getViewTime()));
     111             : 
     112           0 :                 if(fState < 0.5)
     113             :                 {
     114           0 :                     return getChildren();
     115             :                 }
     116             :             }
     117             : 
     118           0 :             return Primitive2DSequence();
     119             :         }
     120             : 
     121             :         // provide unique ID
     122           0 :         ImplPrimitive2DIDBlock(AnimatedBlinkPrimitive2D, PRIMITIVE2D_ID_ANIMATEDBLINKPRIMITIVE2D)
     123             : 
     124             :     } // end of namespace primitive2d
     125             : } // end of namespace drawinglayer
     126             : 
     127             : 
     128             : 
     129             : namespace drawinglayer
     130             : {
     131             :     namespace primitive2d
     132             :     {
     133           0 :         AnimatedInterpolatePrimitive2D::AnimatedInterpolatePrimitive2D(
     134             :             const std::vector< basegfx::B2DHomMatrix >& rmMatrixStack,
     135             :             const animation::AnimationEntry& rAnimationEntry,
     136             :             const Primitive2DSequence& rChildren,
     137             :             bool bIsTextAnimation)
     138             :         :   AnimatedSwitchPrimitive2D(rAnimationEntry, rChildren, bIsTextAnimation),
     139           0 :             maMatrixStack()
     140             :         {
     141             :             // copy matrices to locally pre-decomposed matrix stack
     142           0 :             const sal_uInt32 nCount(rmMatrixStack.size());
     143           0 :             maMatrixStack.reserve(nCount);
     144             : 
     145           0 :             for(sal_uInt32 a(0L); a < nCount; a++)
     146             :             {
     147           0 :                 maMatrixStack.push_back(basegfx::tools::B2DHomMatrixBufferedDecompose(rmMatrixStack[a]));
     148             :             }
     149           0 :         }
     150             : 
     151           0 :         Primitive2DSequence AnimatedInterpolatePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
     152             :         {
     153           0 :             const sal_uInt32 nSize(maMatrixStack.size());
     154             : 
     155           0 :             if(nSize)
     156             :             {
     157           0 :                 double fState(getAnimationEntry().getStateAtTime(rViewInformation.getViewTime()));
     158             : 
     159           0 :                 if(fState < 0.0)
     160             :                 {
     161           0 :                     fState = 0.0;
     162             :                 }
     163           0 :                 else if(fState > 1.0)
     164             :                 {
     165           0 :                     fState = 1.0;
     166             :                 }
     167             : 
     168           0 :                 const double fIndex(fState * (double)(nSize - 1L));
     169           0 :                 const sal_uInt32 nIndA(sal_uInt32(floor(fIndex)));
     170           0 :                 const double fOffset(fIndex - (double)nIndA);
     171           0 :                 basegfx::B2DHomMatrix aTargetTransform;
     172           0 :                 std::vector< basegfx::tools::B2DHomMatrixBufferedDecompose >::const_iterator aMatA(maMatrixStack.begin() + nIndA);
     173             : 
     174           0 :                 if(basegfx::fTools::equalZero(fOffset))
     175             :                 {
     176             :                     // use matrix from nIndA directly
     177           0 :                     aTargetTransform = aMatA->getB2DHomMatrix();
     178             :                 }
     179             :                 else
     180             :                 {
     181             :                     // interpolate. Get involved buffered decomposed matrices
     182           0 :                     const sal_uInt32 nIndB((nIndA + 1L) % nSize);
     183           0 :                     std::vector< basegfx::tools::B2DHomMatrixBufferedDecompose >::const_iterator aMatB(maMatrixStack.begin() + nIndB);
     184             : 
     185             :                     // interpolate for fOffset [0.0 .. 1.0[
     186           0 :                     const basegfx::B2DVector aScale(basegfx::interpolate(aMatA->getScale(), aMatB->getScale(), fOffset));
     187           0 :                     const basegfx::B2DVector aTranslate(basegfx::interpolate(aMatA->getTranslate(), aMatB->getTranslate(), fOffset));
     188           0 :                     const double fRotate(((aMatB->getRotate() - aMatA->getRotate()) * fOffset) + aMatA->getRotate());
     189           0 :                     const double fShearX(((aMatB->getShearX() - aMatA->getShearX()) * fOffset) + aMatA->getShearX());
     190             : 
     191             :                     // build matrix for state
     192           0 :                     aTargetTransform = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
     193           0 :                         aScale, fShearX, fRotate, aTranslate);
     194             :                 }
     195             : 
     196             :                 // create new transform primitive reference, return new sequence
     197           0 :                 const Primitive2DReference xRef(new TransformPrimitive2D(aTargetTransform, getChildren()));
     198           0 :                 return Primitive2DSequence(&xRef, 1L);
     199             :             }
     200             :             else
     201             :             {
     202           0 :                 return getChildren();
     203             :             }
     204             :         }
     205             : 
     206             :         // provide unique ID
     207           0 :         ImplPrimitive2DIDBlock(AnimatedInterpolatePrimitive2D, PRIMITIVE2D_ID_ANIMATEDINTERPOLATEPRIMITIVE2D)
     208             : 
     209             :     } // end of namespace primitive2d
     210             : } // end of namespace drawinglayer
     211             : 
     212             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10