Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / drawinglayer / source / primitive2d / animatedprimitive2d.cxx
blobabac6d5fbbbaf6b3c4e12b092fea920bd5386940
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 <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>
27 using namespace com::sun::star;
30 namespace drawinglayer
32 namespace primitive2d
34 void AnimatedSwitchPrimitive2D::setAnimationEntry(const animation::AnimationEntry& rNew)
36 // clone given animation description
37 mpAnimationEntry = rNew.clone();
40 AnimatedSwitchPrimitive2D::AnimatedSwitchPrimitive2D(
41 const animation::AnimationEntry& rAnimationEntry,
42 const Primitive2DContainer& rChildren,
43 bool bIsTextAnimation)
44 : GroupPrimitive2D(rChildren),
45 mbIsTextAnimation(bIsTextAnimation)
47 // clone given animation description
48 mpAnimationEntry = rAnimationEntry.clone();
51 AnimatedSwitchPrimitive2D::~AnimatedSwitchPrimitive2D()
55 bool AnimatedSwitchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
57 if(GroupPrimitive2D::operator==(rPrimitive))
59 const AnimatedSwitchPrimitive2D& rCompare = static_cast< const AnimatedSwitchPrimitive2D& >(rPrimitive);
61 return (getAnimationEntry() == rCompare.getAnimationEntry());
64 return false;
67 void AnimatedSwitchPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const
69 if(!getChildren().empty())
71 const double fState(getAnimationEntry().getStateAtTime(rViewInformation.getViewTime()));
72 const sal_uInt32 nLen(getChildren().size());
73 sal_uInt32 nIndex(basegfx::fround(fState * static_cast<double>(nLen)));
75 if(nIndex >= nLen)
77 nIndex = nLen - 1;
80 const Primitive2DReference xRef(getChildren()[nIndex], uno::UNO_SET_THROW);
81 rVisitor.append(xRef);
85 // provide unique ID
86 ImplPrimitive2DIDBlock(AnimatedSwitchPrimitive2D, PRIMITIVE2D_ID_ANIMATEDSWITCHPRIMITIVE2D)
88 } // end of namespace primitive2d
89 } // end of namespace drawinglayer
92 namespace drawinglayer
94 namespace primitive2d
96 AnimatedBlinkPrimitive2D::AnimatedBlinkPrimitive2D(
97 const animation::AnimationEntry& rAnimationEntry,
98 const Primitive2DContainer& rChildren)
99 : AnimatedSwitchPrimitive2D(rAnimationEntry, rChildren, true/*bIsTextAnimation*/)
103 void AnimatedBlinkPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const
105 if(!getChildren().empty())
107 const double fState(getAnimationEntry().getStateAtTime(rViewInformation.getViewTime()));
109 if(fState < 0.5)
111 getChildren(rVisitor);
116 // provide unique ID
117 ImplPrimitive2DIDBlock(AnimatedBlinkPrimitive2D, PRIMITIVE2D_ID_ANIMATEDBLINKPRIMITIVE2D)
119 } // end of namespace primitive2d
120 } // end of namespace drawinglayer
123 namespace drawinglayer
125 namespace primitive2d
127 AnimatedInterpolatePrimitive2D::AnimatedInterpolatePrimitive2D(
128 const std::vector< basegfx::B2DHomMatrix >& rmMatrixStack,
129 const animation::AnimationEntry& rAnimationEntry,
130 const Primitive2DContainer& rChildren)
131 : AnimatedSwitchPrimitive2D(rAnimationEntry, rChildren, true/*bIsTextAnimation*/),
132 maMatrixStack()
134 // copy matrices to locally pre-decomposed matrix stack
135 const sal_uInt32 nCount(rmMatrixStack.size());
136 maMatrixStack.reserve(nCount);
138 for(sal_uInt32 a(0); a < nCount; a++)
140 maMatrixStack.emplace_back(rmMatrixStack[a]);
144 void AnimatedInterpolatePrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const
146 const sal_uInt32 nSize(maMatrixStack.size());
148 if(nSize)
150 double fState(getAnimationEntry().getStateAtTime(rViewInformation.getViewTime()));
152 if(fState < 0.0)
154 fState = 0.0;
156 else if(fState > 1.0)
158 fState = 1.0;
161 const double fIndex(fState * static_cast<double>(nSize - 1));
162 const sal_uInt32 nIndA(sal_uInt32(floor(fIndex)));
163 const double fOffset(fIndex - static_cast<double>(nIndA));
164 basegfx::B2DHomMatrix aTargetTransform;
165 std::vector< basegfx::utils::B2DHomMatrixBufferedDecompose >::const_iterator aMatA(maMatrixStack.begin() + nIndA);
167 if(basegfx::fTools::equalZero(fOffset))
169 // use matrix from nIndA directly
170 aTargetTransform = aMatA->getB2DHomMatrix();
172 else
174 // interpolate. Get involved buffered decomposed matrices
175 const sal_uInt32 nIndB((nIndA + 1) % nSize);
176 std::vector< basegfx::utils::B2DHomMatrixBufferedDecompose >::const_iterator aMatB(maMatrixStack.begin() + nIndB);
178 // interpolate for fOffset [0.0 .. 1.0[
179 const basegfx::B2DVector aScale(basegfx::interpolate(aMatA->getScale(), aMatB->getScale(), fOffset));
180 const basegfx::B2DVector aTranslate(basegfx::interpolate(aMatA->getTranslate(), aMatB->getTranslate(), fOffset));
181 const double fRotate(((aMatB->getRotate() - aMatA->getRotate()) * fOffset) + aMatA->getRotate());
182 const double fShearX(((aMatB->getShearX() - aMatA->getShearX()) * fOffset) + aMatA->getShearX());
184 // build matrix for state
185 aTargetTransform = basegfx::utils::createScaleShearXRotateTranslateB2DHomMatrix(
186 aScale, fShearX, fRotate, aTranslate);
189 // create new transform primitive reference, return new sequence
190 const Primitive2DReference xRef(new TransformPrimitive2D(aTargetTransform, getChildren()));
191 rVisitor.append(xRef);
193 else
195 getChildren(rVisitor);
199 // provide unique ID
200 ImplPrimitive2DIDBlock(AnimatedInterpolatePrimitive2D, PRIMITIVE2D_ID_ANIMATEDINTERPOLATEPRIMITIVE2D)
202 } // end of namespace primitive2d
203 } // end of namespace drawinglayer
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */