1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_drawinglayer.hxx" 30 31 #include <drawinglayer/primitive2d/animatedprimitive2d.hxx> 32 #include <drawinglayer/animation/animationtiming.hxx> 33 #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 34 #include <drawinglayer/geometry/viewinformation2d.hxx> 35 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 36 37 ////////////////////////////////////////////////////////////////////////////// 38 39 using namespace com::sun::star; 40 41 ////////////////////////////////////////////////////////////////////////////// 42 43 namespace drawinglayer 44 { 45 namespace primitive2d 46 { 47 AnimatedSwitchPrimitive2D::AnimatedSwitchPrimitive2D( 48 const animation::AnimationEntry& rAnimationEntry, 49 const Primitive2DSequence& rChildren, 50 bool bIsTextAnimation) 51 : GroupPrimitive2D(rChildren), 52 mpAnimationEntry(0), 53 mbIsTextAnimation(bIsTextAnimation) 54 { 55 // clone given animation description 56 mpAnimationEntry = rAnimationEntry.clone(); 57 } 58 59 AnimatedSwitchPrimitive2D::~AnimatedSwitchPrimitive2D() 60 { 61 // delete cloned animation description 62 delete mpAnimationEntry; 63 } 64 65 bool AnimatedSwitchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 66 { 67 if(GroupPrimitive2D::operator==(rPrimitive)) 68 { 69 const AnimatedSwitchPrimitive2D& rCompare = static_cast< const AnimatedSwitchPrimitive2D& >(rPrimitive); 70 71 return (getAnimationEntry() == rCompare.getAnimationEntry()); 72 } 73 74 return false; 75 } 76 77 Primitive2DSequence AnimatedSwitchPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 78 { 79 if(getChildren().hasElements()) 80 { 81 const double fState(getAnimationEntry().getStateAtTime(rViewInformation.getViewTime())); 82 const sal_uInt32 nLen(getChildren().getLength()); 83 sal_uInt32 nIndex(basegfx::fround(fState * (double)nLen)); 84 85 if(nIndex >= nLen) 86 { 87 nIndex = nLen - 1L; 88 } 89 90 const Primitive2DReference xRef(getChildren()[nIndex], uno::UNO_QUERY_THROW); 91 return Primitive2DSequence(&xRef, 1L); 92 } 93 94 return Primitive2DSequence(); 95 } 96 97 // provide unique ID 98 ImplPrimitrive2DIDBlock(AnimatedSwitchPrimitive2D, PRIMITIVE2D_ID_ANIMATEDSWITCHPRIMITIVE2D) 99 100 } // end of namespace primitive2d 101 } // end of namespace drawinglayer 102 103 ////////////////////////////////////////////////////////////////////////////// 104 105 namespace drawinglayer 106 { 107 namespace primitive2d 108 { 109 AnimatedBlinkPrimitive2D::AnimatedBlinkPrimitive2D( 110 const animation::AnimationEntry& rAnimationEntry, 111 const Primitive2DSequence& rChildren, 112 bool bIsTextAnimation) 113 : AnimatedSwitchPrimitive2D(rAnimationEntry, rChildren, bIsTextAnimation) 114 { 115 } 116 117 Primitive2DSequence AnimatedBlinkPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 118 { 119 if(getChildren().hasElements()) 120 { 121 const double fState(getAnimationEntry().getStateAtTime(rViewInformation.getViewTime())); 122 123 if(fState < 0.5) 124 { 125 return getChildren(); 126 } 127 } 128 129 return Primitive2DSequence(); 130 } 131 132 // provide unique ID 133 ImplPrimitrive2DIDBlock(AnimatedBlinkPrimitive2D, PRIMITIVE2D_ID_ANIMATEDBLINKPRIMITIVE2D) 134 135 } // end of namespace primitive2d 136 } // end of namespace drawinglayer 137 138 ////////////////////////////////////////////////////////////////////////////// 139 140 namespace drawinglayer 141 { 142 namespace primitive2d 143 { 144 AnimatedInterpolatePrimitive2D::AnimatedInterpolatePrimitive2D( 145 const std::vector< basegfx::B2DHomMatrix >& rmMatrixStack, 146 const animation::AnimationEntry& rAnimationEntry, 147 const Primitive2DSequence& rChildren, 148 bool bIsTextAnimation) 149 : AnimatedSwitchPrimitive2D(rAnimationEntry, rChildren, bIsTextAnimation), 150 maMatrixStack() 151 { 152 // copy matrices to locally pre-decomposed matrix stack 153 const sal_uInt32 nCount(rmMatrixStack.size()); 154 maMatrixStack.reserve(nCount); 155 156 for(sal_uInt32 a(0L); a < nCount; a++) 157 { 158 maMatrixStack.push_back(basegfx::tools::B2DHomMatrixBufferedDecompose(rmMatrixStack[a])); 159 } 160 } 161 162 Primitive2DSequence AnimatedInterpolatePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 163 { 164 const sal_uInt32 nSize(maMatrixStack.size()); 165 166 if(nSize) 167 { 168 double fState(getAnimationEntry().getStateAtTime(rViewInformation.getViewTime())); 169 170 if(fState < 0.0) 171 { 172 fState = 0.0; 173 } 174 else if(fState > 1.0) 175 { 176 fState = 1.0; 177 } 178 179 const double fIndex(fState * (double)(nSize - 1L)); 180 const sal_uInt32 nIndA(sal_uInt32(floor(fIndex))); 181 const double fOffset(fIndex - (double)nIndA); 182 basegfx::B2DHomMatrix aTargetTransform; 183 std::vector< basegfx::tools::B2DHomMatrixBufferedDecompose >::const_iterator aMatA(maMatrixStack.begin() + nIndA); 184 185 if(basegfx::fTools::equalZero(fOffset)) 186 { 187 // use matrix from nIndA directly 188 aTargetTransform = aMatA->getB2DHomMatrix(); 189 } 190 else 191 { 192 // interpolate. Get involved buffered decomposed matrices 193 const sal_uInt32 nIndB((nIndA + 1L) % nSize); 194 std::vector< basegfx::tools::B2DHomMatrixBufferedDecompose >::const_iterator aMatB(maMatrixStack.begin() + nIndB); 195 196 // interpolate for fOffset [0.0 .. 1.0[ 197 const basegfx::B2DVector aScale(basegfx::interpolate(aMatA->getScale(), aMatB->getScale(), fOffset)); 198 const basegfx::B2DVector aTranslate(basegfx::interpolate(aMatA->getTranslate(), aMatB->getTranslate(), fOffset)); 199 const double fRotate(((aMatB->getRotate() - aMatA->getRotate()) * fOffset) + aMatA->getRotate()); 200 const double fShearX(((aMatB->getShearX() - aMatA->getShearX()) * fOffset) + aMatA->getShearX()); 201 202 // build matrix for state 203 aTargetTransform = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix( 204 aScale, fShearX, fRotate, aTranslate); 205 } 206 207 // create new transform primitive reference, return new sequence 208 const Primitive2DReference xRef(new TransformPrimitive2D(aTargetTransform, getChildren())); 209 return Primitive2DSequence(&xRef, 1L); 210 } 211 else 212 { 213 return getChildren(); 214 } 215 } 216 217 // provide unique ID 218 ImplPrimitrive2DIDBlock(AnimatedInterpolatePrimitive2D, PRIMITIVE2D_ID_ANIMATEDINTERPOLATEPRIMITIVE2D) 219 220 } // end of namespace primitive2d 221 } // end of namespace drawinglayer 222 223 ////////////////////////////////////////////////////////////////////////////// 224 // eof 225