1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: animatedprimitive2d.cxx,v $
9 * last change: $Author: aw $ $Date: 2008-05-27 14:11:20 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/primitive2d/animatedprimitive2d.hxx>
40 #include <drawinglayer/animation/animationtiming.hxx>
41 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
42 #include <drawinglayer/geometry/viewinformation2d.hxx>
43 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
45 //////////////////////////////////////////////////////////////////////////////
47 using namespace com::sun::star
;
49 //////////////////////////////////////////////////////////////////////////////
51 namespace drawinglayer
55 Primitive2DSequence
AnimatedSwitchPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const
57 if(getChildren().hasElements())
59 const double fState(getAnimationEntry().getStateAtTime(rViewInformation
.getViewTime()));
60 const sal_uInt32
nLen(getChildren().getLength());
61 sal_uInt32
nIndex(basegfx::fround(fState
* (double)nLen
));
68 const Primitive2DReference
xRef(getChildren()[nIndex
], uno::UNO_QUERY_THROW
);
69 return Primitive2DSequence(&xRef
, 1L);
72 return Primitive2DSequence();
75 AnimatedSwitchPrimitive2D::AnimatedSwitchPrimitive2D(
76 const animation::AnimationEntry
& rAnimationEntry
,
77 const Primitive2DSequence
& rChildren
,
78 bool bIsTextAnimation
)
79 : GroupPrimitive2D(rChildren
),
81 mfDecomposeViewTime(0.0),
82 mbIsTextAnimation(bIsTextAnimation
)
84 // clone given animation description
85 mpAnimationEntry
= rAnimationEntry
.clone();
88 AnimatedSwitchPrimitive2D::~AnimatedSwitchPrimitive2D()
90 // delete cloned animation description
91 delete mpAnimationEntry
;
94 bool AnimatedSwitchPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
96 if(GroupPrimitive2D::operator==(rPrimitive
))
98 const AnimatedSwitchPrimitive2D
& rCompare
= static_cast< const AnimatedSwitchPrimitive2D
& >(rPrimitive
);
100 return (getAnimationEntry() == rCompare
.getAnimationEntry());
106 Primitive2DSequence
AnimatedSwitchPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const
108 ::osl::MutexGuard
aGuard( m_aMutex
);
110 if(getLocalDecomposition().hasElements() && mfDecomposeViewTime
!= rViewInformation
.getViewTime())
112 // conditions of last local decomposition have changed, delete
113 const_cast< AnimatedSwitchPrimitive2D
* >(this)->setLocalDecomposition(Primitive2DSequence());
116 if(!getLocalDecomposition().hasElements())
119 const_cast< AnimatedSwitchPrimitive2D
* >(this)->mfDecomposeViewTime
= rViewInformation
.getViewTime();
122 // use parent implementation
123 return GroupPrimitive2D::get2DDecomposition(rViewInformation
);
126 basegfx::B2DRange
AnimatedSwitchPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& rViewInformation
) const
128 // to get range from decomposition and not from group content, call implementation from
129 // BasePrimitive2D here
130 return BasePrimitive2D::getB2DRange(rViewInformation
);
134 ImplPrimitrive2DIDBlock(AnimatedSwitchPrimitive2D
, PRIMITIVE2D_ID_ANIMATEDSWITCHPRIMITIVE2D
)
136 } // end of namespace primitive2d
137 } // end of namespace drawinglayer
139 //////////////////////////////////////////////////////////////////////////////
141 namespace drawinglayer
143 namespace primitive2d
145 Primitive2DSequence
AnimatedBlinkPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const
147 if(getChildren().hasElements())
149 const double fState(getAnimationEntry().getStateAtTime(rViewInformation
.getViewTime()));
153 return getChildren();
157 return Primitive2DSequence();
160 AnimatedBlinkPrimitive2D::AnimatedBlinkPrimitive2D(
161 const animation::AnimationEntry
& rAnimationEntry
,
162 const Primitive2DSequence
& rChildren
,
163 bool bIsTextAnimation
)
164 : AnimatedSwitchPrimitive2D(rAnimationEntry
, rChildren
, bIsTextAnimation
)
169 ImplPrimitrive2DIDBlock(AnimatedBlinkPrimitive2D
, PRIMITIVE2D_ID_ANIMATEDBLINKPRIMITIVE2D
)
171 } // end of namespace primitive2d
172 } // end of namespace drawinglayer
174 //////////////////////////////////////////////////////////////////////////////
175 // helper class for AnimatedInterpolatePrimitive2D
177 namespace drawinglayer
179 namespace primitive2d
181 BufferedMatrixDecompose::BufferedMatrixDecompose(const basegfx::B2DHomMatrix
& rMatrix
)
182 : maB2DHomMatrix(rMatrix
),
184 maTranslate(0.0, 0.0),
191 void BufferedMatrixDecompose::ensureDecompose() const
195 BufferedMatrixDecompose
* pThis
= const_cast< BufferedMatrixDecompose
* >(this);
196 maB2DHomMatrix
.decompose(pThis
->maScale
, pThis
->maTranslate
, pThis
->mfRotate
, pThis
->mfShearX
);
197 pThis
->mbDecomposed
= true;
200 } // end of anonymous namespace
201 } // end of namespace drawinglayer
203 //////////////////////////////////////////////////////////////////////////////
205 namespace drawinglayer
207 namespace primitive2d
209 Primitive2DSequence
AnimatedInterpolatePrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const
211 const sal_uInt32
nSize(maMatrixStack
.size());
215 double fState(getAnimationEntry().getStateAtTime(rViewInformation
.getViewTime()));
221 else if(fState
> 1.0)
226 const double fIndex(fState
* (double)(nSize
- 1L));
227 const sal_uInt32
nIndA(sal_uInt32(floor(fIndex
)));
228 const double fOffset(fIndex
- (double)nIndA
);
229 basegfx::B2DHomMatrix aTargetTransform
;
231 if(basegfx::fTools::equalZero(fOffset
))
233 // use matrix from nIndA directly
234 aTargetTransform
= maMatrixStack
[nIndA
].getB2DHomMatrix();
238 // interpolate. Get involved matrices and ensure they are decomposed
239 const sal_uInt32
nIndB((nIndA
+ 1L) % nSize
);
240 std::vector
< BufferedMatrixDecompose
>::const_iterator
aMatA(maMatrixStack
.begin() + nIndA
);
241 std::vector
< BufferedMatrixDecompose
>::const_iterator
aMatB(maMatrixStack
.begin() + nIndB
);
243 aMatA
->ensureDecompose();
244 aMatB
->ensureDecompose();
246 // interpolate for fOffset [0.0 .. 1.0[
247 const basegfx::B2DVector
aScale(basegfx::interpolate(aMatA
->getScale(), aMatB
->getScale(), fOffset
));
248 const basegfx::B2DVector
aTranslate(basegfx::interpolate(aMatA
->getTranslate(), aMatB
->getTranslate(), fOffset
));
249 const double fRotate(((aMatB
->getRotate() - aMatA
->getRotate()) * fOffset
) + aMatA
->getRotate());
250 const double fShearX(((aMatB
->getShearX() - aMatA
->getShearX()) * fOffset
) + aMatA
->getShearX());
252 // build matrix for state
253 aTargetTransform
.scale(aScale
.getX(), aScale
.getY());
254 aTargetTransform
.shearX(fShearX
);
255 aTargetTransform
.rotate(fRotate
);
256 aTargetTransform
.translate(aTranslate
.getX(), aTranslate
.getY());
259 // create new transform primitive reference, return new sequence
260 const Primitive2DReference
xRef(new TransformPrimitive2D(aTargetTransform
, getChildren()));
261 return Primitive2DSequence(&xRef
, 1L);
265 return getChildren();
269 AnimatedInterpolatePrimitive2D::AnimatedInterpolatePrimitive2D(
270 const std::vector
< basegfx::B2DHomMatrix
>& rmMatrixStack
,
271 const animation::AnimationEntry
& rAnimationEntry
,
272 const Primitive2DSequence
& rChildren
,
273 bool bIsTextAnimation
)
274 : AnimatedSwitchPrimitive2D(rAnimationEntry
, rChildren
, bIsTextAnimation
),
278 const sal_uInt32
nCount(rmMatrixStack
.size());
280 for(sal_uInt32
a(0L); a
< nCount
; a
++)
282 maMatrixStack
.push_back(BufferedMatrixDecompose(rmMatrixStack
[a
]));
287 ImplPrimitrive2DIDBlock(AnimatedInterpolatePrimitive2D
, PRIMITIVE2D_ID_ANIMATEDINTERPOLATEPRIMITIVE2D
)
289 } // end of namespace primitive2d
290 } // end of namespace drawinglayer
292 //////////////////////////////////////////////////////////////////////////////