1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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::primitive2d
32 void AnimatedSwitchPrimitive2D::setAnimationEntry(const animation::AnimationEntry
& rNew
)
34 // clone given animation description
35 mpAnimationEntry
= rNew
.clone();
38 AnimatedSwitchPrimitive2D::AnimatedSwitchPrimitive2D(
39 const animation::AnimationEntry
& rAnimationEntry
,
40 Primitive2DContainer
&& aChildren
,
41 bool bIsTextAnimation
)
42 : GroupPrimitive2D(std::move(aChildren
)),
43 mbIsTextAnimation(bIsTextAnimation
)
45 // clone given animation description
46 mpAnimationEntry
= rAnimationEntry
.clone();
49 AnimatedSwitchPrimitive2D::~AnimatedSwitchPrimitive2D()
53 bool AnimatedSwitchPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
55 if(GroupPrimitive2D::operator==(rPrimitive
))
57 const AnimatedSwitchPrimitive2D
& rCompare
= static_cast< const AnimatedSwitchPrimitive2D
& >(rPrimitive
);
59 return (getAnimationEntry() == rCompare
.getAnimationEntry());
65 void AnimatedSwitchPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& rVisitor
, const geometry::ViewInformation2D
& rViewInformation
) const
67 if(getChildren().empty())
70 const double fState(getAnimationEntry().getStateAtTime(rViewInformation
.getViewTime()));
71 const sal_uInt32
nLen(getChildren().size());
72 sal_uInt32
nIndex(basegfx::fround(fState
* static_cast<double>(nLen
)));
79 const Primitive2DReference
xRef(getChildren()[nIndex
], uno::UNO_SET_THROW
);
84 sal_uInt32
AnimatedSwitchPrimitive2D::getPrimitive2DID() const
86 return PRIMITIVE2D_ID_ANIMATEDSWITCHPRIMITIVE2D
;
89 } // end of namespace drawinglayer::primitive2d
92 namespace drawinglayer::primitive2d
94 AnimatedBlinkPrimitive2D::AnimatedBlinkPrimitive2D(
95 const animation::AnimationEntry
& rAnimationEntry
,
96 Primitive2DContainer
&& aChildren
)
97 : AnimatedSwitchPrimitive2D(rAnimationEntry
, std::move(aChildren
), true/*bIsTextAnimation*/)
101 void AnimatedBlinkPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& rVisitor
, const geometry::ViewInformation2D
& rViewInformation
) const
103 if(!getChildren().empty())
105 const double fState(getAnimationEntry().getStateAtTime(rViewInformation
.getViewTime()));
109 getChildren(rVisitor
);
115 sal_uInt32
AnimatedBlinkPrimitive2D::getPrimitive2DID() const
117 return PRIMITIVE2D_ID_ANIMATEDBLINKPRIMITIVE2D
;
120 } // end of namespace drawinglayer::primitive2d
123 namespace drawinglayer::primitive2d
125 AnimatedInterpolatePrimitive2D::AnimatedInterpolatePrimitive2D(
126 const std::vector
< basegfx::B2DHomMatrix
>& rmMatrixStack
,
127 const animation::AnimationEntry
& rAnimationEntry
,
128 Primitive2DContainer
&& aChildren
)
129 : AnimatedSwitchPrimitive2D(rAnimationEntry
, std::move(aChildren
), true/*bIsTextAnimation*/)
131 // copy matrices to locally pre-decomposed matrix stack
132 const sal_uInt32
nCount(rmMatrixStack
.size());
133 maMatrixStack
.reserve(nCount
);
135 for(const auto& a
: rmMatrixStack
)
137 maMatrixStack
.emplace_back(a
);
141 void AnimatedInterpolatePrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& rVisitor
, const geometry::ViewInformation2D
& rViewInformation
) const
143 const sal_uInt32
nSize(maMatrixStack
.size());
147 double fState(getAnimationEntry().getStateAtTime(rViewInformation
.getViewTime()));
153 else if(fState
> 1.0)
158 const double fIndex(fState
* static_cast<double>(nSize
- 1));
159 const sal_uInt32
nIndA(sal_uInt32(floor(fIndex
)));
160 const double fOffset(fIndex
- static_cast<double>(nIndA
));
161 basegfx::B2DHomMatrix aTargetTransform
;
162 std::vector
< basegfx::utils::B2DHomMatrixBufferedDecompose
>::const_iterator
aMatA(maMatrixStack
.begin() + nIndA
);
164 if(basegfx::fTools::equalZero(fOffset
))
166 // use matrix from nIndA directly
167 aTargetTransform
= aMatA
->getB2DHomMatrix();
171 // interpolate. Get involved buffered decomposed matrices
172 const sal_uInt32
nIndB((nIndA
+ 1) % nSize
);
173 std::vector
< basegfx::utils::B2DHomMatrixBufferedDecompose
>::const_iterator
aMatB(maMatrixStack
.begin() + nIndB
);
175 // interpolate for fOffset [0.0 .. 1.0[
176 const basegfx::B2DVector
aScale(basegfx::interpolate(aMatA
->getScale(), aMatB
->getScale(), fOffset
));
177 const basegfx::B2DVector
aTranslate(basegfx::interpolate(aMatA
->getTranslate(), aMatB
->getTranslate(), fOffset
));
178 const double fRotate(((aMatB
->getRotate() - aMatA
->getRotate()) * fOffset
) + aMatA
->getRotate());
179 const double fShearX(((aMatB
->getShearX() - aMatA
->getShearX()) * fOffset
) + aMatA
->getShearX());
181 // build matrix for state
182 aTargetTransform
= basegfx::utils::createScaleShearXRotateTranslateB2DHomMatrix(
183 aScale
, fShearX
, fRotate
, aTranslate
);
186 // create new transform primitive reference, return new sequence
187 Primitive2DReference
xRef(new TransformPrimitive2D(aTargetTransform
, Primitive2DContainer(getChildren())));
188 rVisitor
.visit(xRef
);
192 getChildren(rVisitor
);
197 sal_uInt32
AnimatedInterpolatePrimitive2D::getPrimitive2DID() const
199 return PRIMITIVE2D_ID_ANIMATEDINTERPOLATEPRIMITIVE2D
;
201 } // end of namespace
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */