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