1*70f497fbSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*70f497fbSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*70f497fbSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*70f497fbSAndrew Rist * distributed with this work for additional information 6*70f497fbSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*70f497fbSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*70f497fbSAndrew Rist * "License"); you may not use this file except in compliance 9*70f497fbSAndrew Rist * with the License. You may obtain a copy of the License at 10*70f497fbSAndrew Rist * 11*70f497fbSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*70f497fbSAndrew Rist * 13*70f497fbSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*70f497fbSAndrew Rist * software distributed under the License is distributed on an 15*70f497fbSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*70f497fbSAndrew Rist * KIND, either express or implied. See the License for the 17*70f497fbSAndrew Rist * specific language governing permissions and limitations 18*70f497fbSAndrew Rist * under the License. 19*70f497fbSAndrew Rist * 20*70f497fbSAndrew Rist *************************************************************/ 21*70f497fbSAndrew Rist 22*70f497fbSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_slideshow.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <canvas/debug.hxx> 28cdf0e10cSrcweir #include <tools/diagnose_ex.h> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <comphelper/anytostring.hxx> 31cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx> 32cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 33cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 34cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <com/sun/star/animations/TransitionType.hpp> 37cdf0e10cSrcweir #include <com/sun/star/animations/TransitionSubType.hpp> 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include "transitionfactory.hxx" 40cdf0e10cSrcweir #include "transitiontools.hxx" 41cdf0e10cSrcweir #include "parametricpolypolygonfactory.hxx" 42cdf0e10cSrcweir #include "animationfactory.hxx" 43cdf0e10cSrcweir #include "clippingfunctor.hxx" 44cdf0e10cSrcweir 45cdf0e10cSrcweir #include <boost/bind.hpp> 46cdf0e10cSrcweir 47cdf0e10cSrcweir 48cdf0e10cSrcweir using namespace ::com::sun::star; 49cdf0e10cSrcweir 50cdf0e10cSrcweir namespace slideshow { 51cdf0e10cSrcweir namespace internal { 52cdf0e10cSrcweir 53cdf0e10cSrcweir /*************************************************** 54cdf0e10cSrcweir *** *** 55cdf0e10cSrcweir *** Shape Transition Effects *** 56cdf0e10cSrcweir *** *** 57cdf0e10cSrcweir ***************************************************/ 58cdf0e10cSrcweir 59cdf0e10cSrcweir namespace { 60cdf0e10cSrcweir 61cdf0e10cSrcweir class ClippingAnimation : public NumberAnimation 62cdf0e10cSrcweir { 63cdf0e10cSrcweir public: 64cdf0e10cSrcweir ClippingAnimation( 65cdf0e10cSrcweir const ParametricPolyPolygonSharedPtr& rPolygon, 66cdf0e10cSrcweir const ShapeManagerSharedPtr& rShapeManager, 67cdf0e10cSrcweir const TransitionInfo& rTransitionInfo, 68cdf0e10cSrcweir bool bDirectionForward, 69cdf0e10cSrcweir bool bModeIn ); 70cdf0e10cSrcweir 71cdf0e10cSrcweir ~ClippingAnimation(); 72cdf0e10cSrcweir 73cdf0e10cSrcweir // Animation interface 74cdf0e10cSrcweir // ------------------- 75cdf0e10cSrcweir virtual void prefetch( const AnimatableShapeSharedPtr& rShape, 76cdf0e10cSrcweir const ShapeAttributeLayerSharedPtr& rAttrLayer ); 77cdf0e10cSrcweir virtual void start( const AnimatableShapeSharedPtr& rShape, 78cdf0e10cSrcweir const ShapeAttributeLayerSharedPtr& rAttrLayer ); 79cdf0e10cSrcweir virtual void end(); 80cdf0e10cSrcweir 81cdf0e10cSrcweir // NumberAnimation interface 82cdf0e10cSrcweir // ----------------------- 83cdf0e10cSrcweir virtual bool operator()( double nValue ); 84cdf0e10cSrcweir virtual double getUnderlyingValue() const; 85cdf0e10cSrcweir 86cdf0e10cSrcweir private: 87cdf0e10cSrcweir void end_(); 88cdf0e10cSrcweir 89cdf0e10cSrcweir AnimatableShapeSharedPtr mpShape; 90cdf0e10cSrcweir ShapeAttributeLayerSharedPtr mpAttrLayer; 91cdf0e10cSrcweir ShapeManagerSharedPtr mpShapeManager; 92cdf0e10cSrcweir ClippingFunctor maClippingFunctor; 93cdf0e10cSrcweir bool mbSpriteActive; 94cdf0e10cSrcweir }; 95cdf0e10cSrcweir 96cdf0e10cSrcweir ClippingAnimation::ClippingAnimation( 97cdf0e10cSrcweir const ParametricPolyPolygonSharedPtr& rPolygon, 98cdf0e10cSrcweir const ShapeManagerSharedPtr& rShapeManager, 99cdf0e10cSrcweir const TransitionInfo& rTransitionInfo, 100cdf0e10cSrcweir bool bDirectionForward, 101cdf0e10cSrcweir bool bModeIn ) : 102cdf0e10cSrcweir mpShape(), 103cdf0e10cSrcweir mpAttrLayer(), 104cdf0e10cSrcweir mpShapeManager( rShapeManager ), 105cdf0e10cSrcweir maClippingFunctor( rPolygon, 106cdf0e10cSrcweir rTransitionInfo, 107cdf0e10cSrcweir bDirectionForward, 108cdf0e10cSrcweir bModeIn ), 109cdf0e10cSrcweir mbSpriteActive(false) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir ENSURE_OR_THROW( 112cdf0e10cSrcweir rShapeManager, 113cdf0e10cSrcweir "ClippingAnimation::ClippingAnimation(): Invalid ShapeManager" ); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir ClippingAnimation::~ClippingAnimation() 117cdf0e10cSrcweir { 118cdf0e10cSrcweir try 119cdf0e10cSrcweir { 120cdf0e10cSrcweir end_(); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir catch (uno::Exception &) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir OSL_ENSURE( false, rtl::OUStringToOString( 125cdf0e10cSrcweir comphelper::anyToString( 126cdf0e10cSrcweir cppu::getCaughtException() ), 127cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 ).getStr() ); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir void ClippingAnimation::prefetch( const AnimatableShapeSharedPtr&, 132cdf0e10cSrcweir const ShapeAttributeLayerSharedPtr& ) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir void ClippingAnimation::start( const AnimatableShapeSharedPtr& rShape, 137cdf0e10cSrcweir const ShapeAttributeLayerSharedPtr& rAttrLayer ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir OSL_ENSURE( !mpShape, 140cdf0e10cSrcweir "ClippingAnimation::start(): Shape already set" ); 141cdf0e10cSrcweir OSL_ENSURE( !mpAttrLayer, 142cdf0e10cSrcweir "ClippingAnimation::start(): Attribute layer already set" ); 143cdf0e10cSrcweir 144cdf0e10cSrcweir mpShape = rShape; 145cdf0e10cSrcweir mpAttrLayer = rAttrLayer; 146cdf0e10cSrcweir 147cdf0e10cSrcweir ENSURE_OR_THROW( rShape, 148cdf0e10cSrcweir "ClippingAnimation::start(): Invalid shape" ); 149cdf0e10cSrcweir ENSURE_OR_THROW( rAttrLayer, 150cdf0e10cSrcweir "ClippingAnimation::start(): Invalid attribute layer" ); 151cdf0e10cSrcweir 152cdf0e10cSrcweir mpShape = rShape; 153cdf0e10cSrcweir mpAttrLayer = rAttrLayer; 154cdf0e10cSrcweir 155cdf0e10cSrcweir if( !mbSpriteActive ) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir mpShapeManager->enterAnimationMode( mpShape ); 158cdf0e10cSrcweir mbSpriteActive = true; 159cdf0e10cSrcweir } 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir void ClippingAnimation::end() 163cdf0e10cSrcweir { 164cdf0e10cSrcweir end_(); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir void ClippingAnimation::end_() 168cdf0e10cSrcweir { 169cdf0e10cSrcweir if( mbSpriteActive ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir mbSpriteActive = false; 172cdf0e10cSrcweir mpShapeManager->leaveAnimationMode( mpShape ); 173cdf0e10cSrcweir 174cdf0e10cSrcweir if( mpShape->isContentChanged() ) 175cdf0e10cSrcweir mpShapeManager->notifyShapeUpdate( mpShape ); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir bool ClippingAnimation::operator()( double nValue ) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir ENSURE_OR_RETURN_FALSE( 182cdf0e10cSrcweir mpAttrLayer && mpShape, 183cdf0e10cSrcweir "ClippingAnimation::operator(): Invalid ShapeAttributeLayer" ); 184cdf0e10cSrcweir 185cdf0e10cSrcweir // set new clip 186cdf0e10cSrcweir mpAttrLayer->setClip( maClippingFunctor( nValue, 187cdf0e10cSrcweir mpShape->getDomBounds().getRange() ) ); 188cdf0e10cSrcweir 189cdf0e10cSrcweir if( mpShape->isContentChanged() ) 190cdf0e10cSrcweir mpShapeManager->notifyShapeUpdate( mpShape ); 191cdf0e10cSrcweir 192cdf0e10cSrcweir return true; 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir double ClippingAnimation::getUnderlyingValue() const 196cdf0e10cSrcweir { 197cdf0e10cSrcweir ENSURE_OR_THROW( 198cdf0e10cSrcweir mpAttrLayer, 199cdf0e10cSrcweir "ClippingAnimation::getUnderlyingValue(): Invalid ShapeAttributeLayer" ); 200cdf0e10cSrcweir 201cdf0e10cSrcweir return 0.0; // though this should be used in concert with 202cdf0e10cSrcweir // ActivitiesFactory::createSimpleActivity, better 203cdf0e10cSrcweir // explicitely name our start value. 204cdf0e10cSrcweir // Permissible range for operator() above is [0,1] 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir } // anon namespace 208cdf0e10cSrcweir 209cdf0e10cSrcweir 210cdf0e10cSrcweir AnimationActivitySharedPtr TransitionFactory::createShapeTransition( 211cdf0e10cSrcweir const ActivitiesFactory::CommonParameters& rParms, 212cdf0e10cSrcweir const AnimatableShapeSharedPtr& rShape, 213cdf0e10cSrcweir const ShapeManagerSharedPtr& rShapeManager, 214cdf0e10cSrcweir const ::basegfx::B2DVector& rSlideSize, 215cdf0e10cSrcweir uno::Reference< animations::XTransitionFilter > const& xTransition ) 216cdf0e10cSrcweir { 217cdf0e10cSrcweir return createShapeTransition( rParms, 218cdf0e10cSrcweir rShape, 219cdf0e10cSrcweir rShapeManager, 220cdf0e10cSrcweir rSlideSize, 221cdf0e10cSrcweir xTransition, 222cdf0e10cSrcweir xTransition->getTransition(), 223cdf0e10cSrcweir xTransition->getSubtype() ); 224cdf0e10cSrcweir } 225cdf0e10cSrcweir 226cdf0e10cSrcweir AnimationActivitySharedPtr TransitionFactory::createShapeTransition( 227cdf0e10cSrcweir const ActivitiesFactory::CommonParameters& rParms, 228cdf0e10cSrcweir const AnimatableShapeSharedPtr& rShape, 229cdf0e10cSrcweir const ShapeManagerSharedPtr& rShapeManager, 230cdf0e10cSrcweir const ::basegfx::B2DVector& rSlideSize, 231cdf0e10cSrcweir ::com::sun::star::uno::Reference< 232cdf0e10cSrcweir ::com::sun::star::animations::XTransitionFilter > const& xTransition, 233cdf0e10cSrcweir sal_Int16 nType, 234cdf0e10cSrcweir sal_Int16 nSubType ) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir ENSURE_OR_THROW( 237cdf0e10cSrcweir xTransition.is(), 238cdf0e10cSrcweir "TransitionFactory::createShapeTransition(): Invalid XTransition" ); 239cdf0e10cSrcweir 240cdf0e10cSrcweir const TransitionInfo* pTransitionInfo( 241cdf0e10cSrcweir getTransitionInfo( nType, nSubType ) ); 242cdf0e10cSrcweir 243cdf0e10cSrcweir AnimationActivitySharedPtr pGeneratedActivity; 244cdf0e10cSrcweir if( pTransitionInfo != NULL ) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir switch( pTransitionInfo->meTransitionClass ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir default: 249cdf0e10cSrcweir case TransitionInfo::TRANSITION_INVALID: 250cdf0e10cSrcweir OSL_ENSURE( false, 251cdf0e10cSrcweir "TransitionFactory::createShapeTransition(): Invalid transition type. " 252cdf0e10cSrcweir "Don't ask me for a 0 TransitionType, have no XTransitionFilter node instead!" ); 253cdf0e10cSrcweir return AnimationActivitySharedPtr(); 254cdf0e10cSrcweir 255cdf0e10cSrcweir 256cdf0e10cSrcweir case TransitionInfo::TRANSITION_CLIP_POLYPOLYGON: 257cdf0e10cSrcweir { 258cdf0e10cSrcweir // generate parametric poly-polygon 259cdf0e10cSrcweir ParametricPolyPolygonSharedPtr pPoly( 260cdf0e10cSrcweir ParametricPolyPolygonFactory::createClipPolyPolygon( 261cdf0e10cSrcweir nType, nSubType ) ); 262cdf0e10cSrcweir 263cdf0e10cSrcweir // create a clip activity from that 264cdf0e10cSrcweir pGeneratedActivity = ActivitiesFactory::createSimpleActivity( 265cdf0e10cSrcweir rParms, 266cdf0e10cSrcweir NumberAnimationSharedPtr( 267cdf0e10cSrcweir new ClippingAnimation( 268cdf0e10cSrcweir pPoly, 269cdf0e10cSrcweir rShapeManager, 270cdf0e10cSrcweir *pTransitionInfo, 271cdf0e10cSrcweir xTransition->getDirection(), 272cdf0e10cSrcweir xTransition->getMode() ) ), 273cdf0e10cSrcweir true ); 274cdf0e10cSrcweir } 275cdf0e10cSrcweir break; 276cdf0e10cSrcweir 277cdf0e10cSrcweir case TransitionInfo::TRANSITION_SPECIAL: 278cdf0e10cSrcweir { 279cdf0e10cSrcweir switch( nType ) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir case animations::TransitionType::RANDOM: 282cdf0e10cSrcweir { 283cdf0e10cSrcweir // select randomly one of the effects from the 284cdf0e10cSrcweir // TransitionFactoryTable 285cdf0e10cSrcweir 286cdf0e10cSrcweir const TransitionInfo* pRandomTransitionInfo( getRandomTransitionInfo() ); 287cdf0e10cSrcweir 288cdf0e10cSrcweir ENSURE_OR_THROW( pRandomTransitionInfo != NULL, 289cdf0e10cSrcweir "TransitionFactory::createShapeTransition(): Got invalid random transition info" ); 290cdf0e10cSrcweir 291cdf0e10cSrcweir ENSURE_OR_THROW( pRandomTransitionInfo->mnTransitionType != animations::TransitionType::RANDOM, 292cdf0e10cSrcweir "TransitionFactory::createShapeTransition(): Got random again for random input!" ); 293cdf0e10cSrcweir 294cdf0e10cSrcweir // and recurse 295cdf0e10cSrcweir pGeneratedActivity = createShapeTransition( rParms, 296cdf0e10cSrcweir rShape, 297cdf0e10cSrcweir rShapeManager, 298cdf0e10cSrcweir rSlideSize, 299cdf0e10cSrcweir xTransition, 300cdf0e10cSrcweir pRandomTransitionInfo->mnTransitionType, 301cdf0e10cSrcweir pRandomTransitionInfo->mnTransitionSubType ); 302cdf0e10cSrcweir } 303cdf0e10cSrcweir break; 304cdf0e10cSrcweir 305cdf0e10cSrcweir // TODO(F3): Implement slidewipe for shape 306cdf0e10cSrcweir case animations::TransitionType::SLIDEWIPE: 307cdf0e10cSrcweir { 308cdf0e10cSrcweir sal_Int16 nBarWipeSubType(0); 309cdf0e10cSrcweir bool bDirectionForward(true); 310cdf0e10cSrcweir 311cdf0e10cSrcweir // map slidewipe to BARWIPE, for now 312cdf0e10cSrcweir switch( nSubType ) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir case animations::TransitionSubType::FROMLEFT: 315cdf0e10cSrcweir nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT; 316cdf0e10cSrcweir bDirectionForward = true; 317cdf0e10cSrcweir break; 318cdf0e10cSrcweir 319cdf0e10cSrcweir case animations::TransitionSubType::FROMRIGHT: 320cdf0e10cSrcweir nBarWipeSubType = animations::TransitionSubType::LEFTTORIGHT; 321cdf0e10cSrcweir bDirectionForward = false; 322cdf0e10cSrcweir break; 323cdf0e10cSrcweir 324cdf0e10cSrcweir case animations::TransitionSubType::FROMTOP: 325cdf0e10cSrcweir nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM; 326cdf0e10cSrcweir bDirectionForward = true; 327cdf0e10cSrcweir break; 328cdf0e10cSrcweir 329cdf0e10cSrcweir case animations::TransitionSubType::FROMBOTTOM: 330cdf0e10cSrcweir nBarWipeSubType = animations::TransitionSubType::TOPTOBOTTOM; 331cdf0e10cSrcweir bDirectionForward = false; 332cdf0e10cSrcweir break; 333cdf0e10cSrcweir 334cdf0e10cSrcweir default: 335cdf0e10cSrcweir ENSURE_OR_THROW( false, 336cdf0e10cSrcweir "TransitionFactory::createShapeTransition(): Unexpected subtype for SLIDEWIPE" ); 337cdf0e10cSrcweir break; 338cdf0e10cSrcweir } 339cdf0e10cSrcweir 340cdf0e10cSrcweir // generate parametric poly-polygon 341cdf0e10cSrcweir ParametricPolyPolygonSharedPtr pPoly( 342cdf0e10cSrcweir ParametricPolyPolygonFactory::createClipPolyPolygon( 343cdf0e10cSrcweir animations::TransitionType::BARWIPE, 344cdf0e10cSrcweir nBarWipeSubType ) ); 345cdf0e10cSrcweir 346cdf0e10cSrcweir // create a clip activity from that 347cdf0e10cSrcweir pGeneratedActivity = ActivitiesFactory::createSimpleActivity( 348cdf0e10cSrcweir rParms, 349cdf0e10cSrcweir NumberAnimationSharedPtr( 350cdf0e10cSrcweir new ClippingAnimation( 351cdf0e10cSrcweir pPoly, 352cdf0e10cSrcweir rShapeManager, 353cdf0e10cSrcweir *getTransitionInfo( animations::TransitionType::BARWIPE, 354cdf0e10cSrcweir nBarWipeSubType ), 355cdf0e10cSrcweir bDirectionForward, 356cdf0e10cSrcweir xTransition->getMode() ) ), 357cdf0e10cSrcweir true ); 358cdf0e10cSrcweir } 359cdf0e10cSrcweir break; 360cdf0e10cSrcweir 361cdf0e10cSrcweir default: 362cdf0e10cSrcweir { 363cdf0e10cSrcweir // TODO(F1): Check whether there's anything left, anyway, 364cdf0e10cSrcweir // for _shape_ transitions. AFAIK, there are no special 365cdf0e10cSrcweir // effects for shapes... 366cdf0e10cSrcweir 367cdf0e10cSrcweir // for now, map all to fade effect 368cdf0e10cSrcweir pGeneratedActivity = ActivitiesFactory::createSimpleActivity( 369cdf0e10cSrcweir rParms, 370cdf0e10cSrcweir AnimationFactory::createNumberPropertyAnimation( 371cdf0e10cSrcweir ::rtl::OUString( 372cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("Opacity") ), 373cdf0e10cSrcweir rShape, 374cdf0e10cSrcweir rShapeManager, 375cdf0e10cSrcweir rSlideSize ), 376cdf0e10cSrcweir xTransition->getMode() ); 377cdf0e10cSrcweir } 378cdf0e10cSrcweir break; 379cdf0e10cSrcweir } 380cdf0e10cSrcweir } 381cdf0e10cSrcweir break; 382cdf0e10cSrcweir } 383cdf0e10cSrcweir } 384cdf0e10cSrcweir 385cdf0e10cSrcweir if( !pGeneratedActivity ) 386cdf0e10cSrcweir { 387cdf0e10cSrcweir // No animation generated, maybe no table entry for given 388cdf0e10cSrcweir // transition? 389cdf0e10cSrcweir OSL_TRACE( 390cdf0e10cSrcweir "TransitionFactory::createShapeTransition(): Unknown type/subtype (%d/%d) " 391cdf0e10cSrcweir "combination encountered", 392cdf0e10cSrcweir xTransition->getTransition(), 393cdf0e10cSrcweir xTransition->getSubtype() ); 394cdf0e10cSrcweir OSL_ENSURE( 395cdf0e10cSrcweir false, 396cdf0e10cSrcweir "TransitionFactory::createShapeTransition(): Unknown type/subtype " 397cdf0e10cSrcweir "combination encountered" ); 398cdf0e10cSrcweir } 399cdf0e10cSrcweir 400cdf0e10cSrcweir return pGeneratedActivity; 401cdf0e10cSrcweir } 402cdf0e10cSrcweir 403cdf0e10cSrcweir } 404cdf0e10cSrcweir } 405