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 const Primitive2DContainer
& rChildren
,
41 bool bIsTextAnimation
)
42 : GroupPrimitive2D(rChildren
),
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
);
80 rVisitor
.append(xRef
);
84 ImplPrimitive2DIDBlock(AnimatedSwitchPrimitive2D
, PRIMITIVE2D_ID_ANIMATEDSWITCHPRIMITIVE2D
)
86 } // end of namespace drawinglayer::primitive2d
89 namespace drawinglayer::primitive2d
91 AnimatedBlinkPrimitive2D::AnimatedBlinkPrimitive2D(
92 const animation::AnimationEntry
& rAnimationEntry
,
93 const Primitive2DContainer
& rChildren
)
94 : AnimatedSwitchPrimitive2D(rAnimationEntry
, rChildren
, true/*bIsTextAnimation*/)
98 void AnimatedBlinkPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& rVisitor
, const geometry::ViewInformation2D
& rViewInformation
) const
100 if(!getChildren().empty())
102 const double fState(getAnimationEntry().getStateAtTime(rViewInformation
.getViewTime()));
106 getChildren(rVisitor
);
112 ImplPrimitive2DIDBlock(AnimatedBlinkPrimitive2D
, PRIMITIVE2D_ID_ANIMATEDBLINKPRIMITIVE2D
)
114 } // end of namespace drawinglayer::primitive2d
117 namespace drawinglayer::primitive2d
119 AnimatedInterpolatePrimitive2D::AnimatedInterpolatePrimitive2D(
120 const std::vector
< basegfx::B2DHomMatrix
>& rmMatrixStack
,
121 const animation::AnimationEntry
& rAnimationEntry
,
122 const Primitive2DContainer
& rChildren
)
123 : AnimatedSwitchPrimitive2D(rAnimationEntry
, rChildren
, true/*bIsTextAnimation*/),
126 // copy matrices to locally pre-decomposed matrix stack
127 const sal_uInt32
nCount(rmMatrixStack
.size());
128 maMatrixStack
.reserve(nCount
);
130 for(sal_uInt32
a(0); a
< nCount
; a
++)
132 maMatrixStack
.emplace_back(rmMatrixStack
[a
]);
136 void AnimatedInterpolatePrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& rVisitor
, const geometry::ViewInformation2D
& rViewInformation
) const
138 const sal_uInt32
nSize(maMatrixStack
.size());
142 double fState(getAnimationEntry().getStateAtTime(rViewInformation
.getViewTime()));
148 else if(fState
> 1.0)
153 const double fIndex(fState
* static_cast<double>(nSize
- 1));
154 const sal_uInt32
nIndA(sal_uInt32(floor(fIndex
)));
155 const double fOffset(fIndex
- static_cast<double>(nIndA
));
156 basegfx::B2DHomMatrix aTargetTransform
;
157 std::vector
< basegfx::utils::B2DHomMatrixBufferedDecompose
>::const_iterator
aMatA(maMatrixStack
.begin() + nIndA
);
159 if(basegfx::fTools::equalZero(fOffset
))
161 // use matrix from nIndA directly
162 aTargetTransform
= aMatA
->getB2DHomMatrix();
166 // interpolate. Get involved buffered decomposed matrices
167 const sal_uInt32
nIndB((nIndA
+ 1) % nSize
);
168 std::vector
< basegfx::utils::B2DHomMatrixBufferedDecompose
>::const_iterator
aMatB(maMatrixStack
.begin() + nIndB
);
170 // interpolate for fOffset [0.0 .. 1.0[
171 const basegfx::B2DVector
aScale(basegfx::interpolate(aMatA
->getScale(), aMatB
->getScale(), fOffset
));
172 const basegfx::B2DVector
aTranslate(basegfx::interpolate(aMatA
->getTranslate(), aMatB
->getTranslate(), fOffset
));
173 const double fRotate(((aMatB
->getRotate() - aMatA
->getRotate()) * fOffset
) + aMatA
->getRotate());
174 const double fShearX(((aMatB
->getShearX() - aMatA
->getShearX()) * fOffset
) + aMatA
->getShearX());
176 // build matrix for state
177 aTargetTransform
= basegfx::utils::createScaleShearXRotateTranslateB2DHomMatrix(
178 aScale
, fShearX
, fRotate
, aTranslate
);
181 // create new transform primitive reference, return new sequence
182 const Primitive2DReference
xRef(new TransformPrimitive2D(aTargetTransform
, getChildren()));
183 rVisitor
.append(xRef
);
187 getChildren(rVisitor
);
192 ImplPrimitive2DIDBlock(AnimatedInterpolatePrimitive2D
, PRIMITIVE2D_ID_ANIMATEDINTERPOLATEPRIMITIVE2D
)
194 } // end of namespace
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */