LibreOffice Module drawinglayer (master) 1
animatedprimitive2d.cxx
Go to the documentation of this file.
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
25
26
27using namespace com::sun::star;
28
29
31{
33 {
34 // clone given animation description
35 mpAnimationEntry = rNew.clone();
36 }
37
39 const animation::AnimationEntry& rAnimationEntry,
40 Primitive2DContainer&& aChildren,
41 bool bIsTextAnimation)
42 : GroupPrimitive2D(std::move(aChildren)),
43 mbIsTextAnimation(bIsTextAnimation)
44 {
45 // clone given animation description
46 mpAnimationEntry = rAnimationEntry.clone();
47 }
48
50 {
51 }
52
54 {
55 if(GroupPrimitive2D::operator==(rPrimitive))
56 {
57 const AnimatedSwitchPrimitive2D& rCompare = static_cast< const AnimatedSwitchPrimitive2D& >(rPrimitive);
58
59 return (getAnimationEntry() == rCompare.getAnimationEntry());
60 }
61
62 return false;
63 }
64
66 {
67 if(getChildren().empty())
68 return;
69
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)));
73
74 if(nIndex >= nLen)
75 {
76 nIndex = nLen - 1;
77 }
78
79 const Primitive2DReference xRef(getChildren()[nIndex], uno::UNO_SET_THROW);
80 rVisitor.visit(xRef);
81 }
82
83 // provide unique ID
85 {
87 }
88
89} // end of namespace drawinglayer::primitive2d
90
91
93{
95 const animation::AnimationEntry& rAnimationEntry,
96 Primitive2DContainer&& aChildren)
97 : AnimatedSwitchPrimitive2D(rAnimationEntry, std::move(aChildren), true/*bIsTextAnimation*/)
98 {
99 }
100
102 {
103 if(!getChildren().empty())
104 {
105 const double fState(getAnimationEntry().getStateAtTime(rViewInformation.getViewTime()));
106
107 if(fState < 0.5)
108 {
109 getChildren(rVisitor);
110 }
111 }
112 }
113
114 // provide unique ID
116 {
118 }
119
120} // end of namespace drawinglayer::primitive2d
121
122
124{
126 const std::vector< basegfx::B2DHomMatrix >& rmMatrixStack,
127 const animation::AnimationEntry& rAnimationEntry,
128 Primitive2DContainer&& aChildren)
129 : AnimatedSwitchPrimitive2D(rAnimationEntry, std::move(aChildren), true/*bIsTextAnimation*/)
130 {
131 // copy matrices to locally pre-decomposed matrix stack
132 const sal_uInt32 nCount(rmMatrixStack.size());
133 maMatrixStack.reserve(nCount);
134
135 for(const auto& a : rmMatrixStack)
136 {
137 maMatrixStack.emplace_back(a);
138 }
139 }
140
142 {
143 const sal_uInt32 nSize(maMatrixStack.size());
144
145 if(nSize)
146 {
147 double fState(getAnimationEntry().getStateAtTime(rViewInformation.getViewTime()));
148
149 if(fState < 0.0)
150 {
151 fState = 0.0;
152 }
153 else if(fState > 1.0)
154 {
155 fState = 1.0;
156 }
157
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);
163
164 if(basegfx::fTools::equalZero(fOffset))
165 {
166 // use matrix from nIndA directly
167 aTargetTransform = aMatA->getB2DHomMatrix();
168 }
169 else
170 {
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);
174
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());
180
181 // build matrix for state
183 aScale, fShearX, fRotate, aTranslate);
184 }
185
186 // create new transform primitive reference, return new sequence
188 rVisitor.visit(xRef);
189 }
190 else
191 {
192 getChildren(rVisitor);
193 }
194 }
195
196 // provide unique ID
198 {
200 }
201} // end of namespace
202
203/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual std::unique_ptr< AnimationEntry > clone() const =0
virtual void get2DDecomposition(Primitive2DDecompositionVisitor &rVisitor, const geometry::ViewInformation2D &rViewInformation) const override
create local decomposition
virtual sal_uInt32 getPrimitive2DID() const override
provide unique ID
AnimatedBlinkPrimitive2D(const animation::AnimationEntry &rAnimationEntry, Primitive2DContainer &&aChildren)
constructor
virtual sal_uInt32 getPrimitive2DID() const override
provide unique ID
AnimatedInterpolatePrimitive2D(const std::vector< basegfx::B2DHomMatrix > &rmMatrixStack, const animation::AnimationEntry &rAnimationEntry, Primitive2DContainer &&aChildren)
constructor
virtual void get2DDecomposition(Primitive2DDecompositionVisitor &rVisitor, const geometry::ViewInformation2D &rViewInformation) const override
create local decomposition
std::vector< basegfx::utils::B2DHomMatrixBufferedDecompose > maMatrixStack
the transformations
const animation::AnimationEntry & getAnimationEntry() const
data read access
void setAnimationEntry(const animation::AnimationEntry &rNew)
write access right for classes deriving from this who want to do special things (e....
std::unique_ptr< animation::AnimationEntry > mpAnimationEntry
The animation definition which allows translation of a point in time to an animation state [0....
AnimatedSwitchPrimitive2D(const animation::AnimationEntry &rAnimationEntry, Primitive2DContainer &&aChildren, bool bIsTextAnimation)
constructor
virtual void get2DDecomposition(Primitive2DDecompositionVisitor &rVisitor, const geometry::ViewInformation2D &rViewInformation) const override
Override getDecomposition() here since the decompose depends on the point in time,...
virtual sal_uInt32 getPrimitive2DID() const override
provide unique ID
virtual ~AnimatedSwitchPrimitive2D() override
destructor - needed due to mpAnimationEntry
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
compare operator
const Primitive2DContainer & getChildren() const
data read access
virtual void visit(const Primitive2DReference &)=0
int nCount
#define PRIMITIVE2D_ID_ANIMATEDINTERPOLATEPRIMITIVE2D
#define PRIMITIVE2D_ID_ANIMATEDSWITCHPRIMITIVE2D
#define PRIMITIVE2D_ID_ANIMATEDBLINKPRIMITIVE2D
sal_Int32 nIndex
uno_Any a
bool equalZero(const T &rfVal)
B2DHomMatrix createScaleShearXRotateTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fShearX, double fRadiant, double fTranslateX, double fTranslateY)
B2DTuple interpolate(const B2DTuple &rOld1, const B2DTuple &rOld2, double t)
B2IRange fround(const B2DRange &rRange)
size