diff options
Diffstat (limited to 'slideshow/source/engine/shapes/drawinglayeranimation.cxx')
-rw-r--r-- | slideshow/source/engine/shapes/drawinglayeranimation.cxx | 300 |
1 files changed, 150 insertions, 150 deletions
diff --git a/slideshow/source/engine/shapes/drawinglayeranimation.cxx b/slideshow/source/engine/shapes/drawinglayeranimation.cxx index 6c1cab84e0eb..9dc00c2ec81b 100644 --- a/slideshow/source/engine/shapes/drawinglayeranimation.cxx +++ b/slideshow/source/engine/shapes/drawinglayeranimation.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -82,7 +82,7 @@ class ScrollTextAnimNode sal_uInt32 mnFrequency; // in ms // forth and back change at mnRepeat%2: bool mbAlternate; - + public: ScrollTextAnimNode( sal_uInt32 nDuration, sal_uInt32 nRepeat, double fStart, double fStop, @@ -94,7 +94,7 @@ public: mnFrequency(nFrequency), mbAlternate(bAlternate) {} - + sal_uInt32 GetDuration() const { return mnDuration; } sal_uInt32 GetRepeat() const { return mnRepeat; } sal_uInt32 GetFullTime() const { return mnDuration * mnRepeat; } @@ -102,7 +102,7 @@ public: double GetStop() const { return mfStop; } sal_uInt32 GetFrequency() const { return mnFrequency; } bool DoAlternate() const { return mbAlternate; } - + double GetStateAtRelativeTime(sal_uInt32 nRelativeTime) const; }; @@ -113,31 +113,31 @@ double ScrollTextAnimNode::GetStateAtRelativeTime( if( mnDuration == 0 ) return mfStop; - if(mnRepeat) + if(mnRepeat) { // ending const sal_uInt32 nRepeatCount(nRelativeTime / mnDuration); sal_uInt32 nFrameTime(nRelativeTime - (nRepeatCount * mnDuration)); - - if(DoAlternate() && (nRepeatCount + 1L) % 2L) + + if(DoAlternate() && (nRepeatCount + 1L) % 2L) nFrameTime = mnDuration - nFrameTime; - + return mfStart + ((mfStop - mfStart) * (double(nFrameTime) / mnDuration)); } - else + else { // endless sal_uInt32 nFrameTime(nRelativeTime % mnDuration); - - if(DoAlternate()) + + if(DoAlternate()) { const sal_uInt32 nRepeatCount(nRelativeTime / mnDuration); - + if((nRepeatCount + 1L) % 2L) nFrameTime = mnDuration - nFrameTime; } - + return mfStart + ((mfStop - mfStart) * (double(nFrameTime) / mnDuration)); } } @@ -148,14 +148,14 @@ class ActivityImpl : public Activity, { public: virtual ~ActivityImpl(); - + ActivityImpl( SlideShowContext const& rContext, boost::shared_ptr<WakeupEvent> const& pWakeupEvent, boost::shared_ptr<DrawShape> const& pDrawShape ); bool enableAnimations(); - + // Disposable: virtual void dispose(); // Activity: @@ -165,23 +165,23 @@ public: virtual void dequeued(); virtual void end(); -private: +private: void updateShapeAttributes( double fTime, basegfx::B2DRectangle const& parentBounds ); - + // Access to VisibleWhenSTarted flags sal_Bool IsVisibleWhenStarted() const { return mbVisibleWhenStarted; } sal_Bool IsVisibleWhenStopped() const { return mbVisibleWhenStopped; } - + // scroll horizontal? if sal_False, scroll is vertical. bool ScrollHorizontal() const { return (drawing::TextAnimationDirection_LEFT == meDirection || drawing::TextAnimationDirection_RIGHT == meDirection); } - + // Access to StepWidth in logical units sal_uInt32 GetStepWidthLogic() const; - + // is the animation direction opposite? bool DoScrollForward() const { return (drawing::TextAnimationDirection_RIGHT == meDirection || @@ -190,10 +190,10 @@ private: // do alternate text directions? bool DoAlternate() const { return mbAlternate; } - + // do scroll in? bool DoScrollIn() const { return mbScrollIn; } - + // Scroll helper methods void ImpForceScrollTextAnimNodes(); ScrollTextAnimNode* ImpGetScrollTextAnimNode( @@ -205,7 +205,7 @@ private: double GetMixerState(sal_uInt32 nTime); //////////////////////////////////////////////////////////////////// - + SlideShowContext maContext; boost::shared_ptr<WakeupEvent> mpWakeupEvent; boost::weak_ptr<DrawShape> mpParentDrawShape; @@ -219,38 +219,38 @@ private: bool mbIsDisposed; bool mbIsActive; drawing::TextAnimationKind meAnimKind; - + // The blink frequency in ms sal_uInt32 mnFrequency; - + // The repeat count, init to 0L which means endless sal_uInt32 mnRepeat; - + // Flag to decide if text will be shown when animation has ended bool mbVisibleWhenStopped; bool mbVisibleWhenStarted; // Flag decides if TextScroll alternates. Default is sal_False. bool mbAlternate; - + // Flag to remember if this is a simple scrollin text bool mbScrollIn; - + // start time for this animation sal_uInt32 mnStartTime; - + // The AnimationDirection drawing::TextAnimationDirection meDirection; - + // Get width per Step. Negative means pixel, positive logical units sal_Int32 mnStepWidth; - + // The single anim steps std::vector< ScrollTextAnimNode > maVector; - + // the scroll rectangle Rectangle maScrollRectangleLogic; - + // the paint rectangle Rectangle maPaintRectangleLogic; }; @@ -277,60 +277,60 @@ private: double ActivityImpl::GetMixerState( sal_uInt32 nTime ) { - if( meAnimKind == drawing::TextAnimationKind_BLINK ) + if( meAnimKind == drawing::TextAnimationKind_BLINK ) { // from AInfoBlinkText: double fRetval(0.0); sal_Bool bDone(sal_False); const sal_uInt32 nLoopTime(2 * mnFrequency); - - if(mnRepeat) + + if(mnRepeat) { const sal_uInt32 nEndTime(mnRepeat * nLoopTime); - - if(nTime >= nEndTime) + + if(nTime >= nEndTime) { - if(mbVisibleWhenStopped) + if(mbVisibleWhenStopped) fRetval = 0.0; else fRetval = 1.0; - + bDone = sal_True; } } - - if(!bDone) + + if(!bDone) { sal_uInt32 nTimeInLoop(nTime % nLoopTime); fRetval = double(nTimeInLoop) / nLoopTime; } - + return fRetval; } - else + else { // from AInfoScrollText: double fRetval(0.0); ImpForceScrollTextAnimNodes(); - - if(!maVector.empty()) + + if(!maVector.empty()) { sal_uInt32 nRelativeTime; ScrollTextAnimNode* pNode = ImpGetScrollTextAnimNode(nTime, nRelativeTime); - - if(pNode) + + if(pNode) { // use node fRetval = pNode->GetStateAtRelativeTime(nRelativeTime); } - else + else { // end of animation, take last entry's end fRetval = maVector[maVector.size() - 1L].GetStop(); } } - + return fRetval; } } @@ -340,21 +340,21 @@ sal_uInt32 ActivityImpl::GetStepWidthLogic() const { // #i69847# Assuming higher DPI sal_uInt32 const PIXEL_TO_LOGIC = 30; - + sal_uInt32 nRetval(0L); - - if(mnStepWidth < 0L) + + if(mnStepWidth < 0L) { // is in pixels, convert to logical units nRetval = (-mnStepWidth * PIXEL_TO_LOGIC); } - else if(mnStepWidth > 0L) + else if(mnStepWidth > 0L) { // is in logical units nRetval = mnStepWidth; } - - if(0L == nRetval) + + if(0L == nRetval) { // step 1 pixel, canned value @@ -363,7 +363,7 @@ sal_uInt32 ActivityImpl::GetStepWidthLogic() const // from ainfoscrolltext.cxx) nRetval = 100L; } - + return nRetval; } @@ -376,7 +376,7 @@ void ActivityImpl::ImpForceScrollTextAnimNodes() double fZeroLogic, fOneLogic, fInitLogic, fDistanceLogic; double fZeroLogicAlternate = 0.0, fOneLogicAlternate = 0.0; double fZeroRelative, fOneRelative, fInitRelative,fDistanceRelative; - + if(ScrollHorizontal()) { if(DoAlternate()) @@ -387,18 +387,18 @@ void ActivityImpl::ImpForceScrollTextAnimNodes() fZeroLogicAlternate = maScrollRectangleLogic.Right() - maPaintRectangleLogic.GetWidth(); fOneLogicAlternate = maScrollRectangleLogic.Left(); } - else + else { fZeroLogicAlternate = maScrollRectangleLogic.Left(); fOneLogicAlternate = maScrollRectangleLogic.Right() - maPaintRectangleLogic.GetWidth(); } } - + fZeroLogic = maScrollRectangleLogic.Left() - maPaintRectangleLogic.GetWidth(); fOneLogic = maScrollRectangleLogic.Right(); fInitLogic = maPaintRectangleLogic.Left(); } - else + else { if(DoAlternate()) { @@ -407,22 +407,22 @@ void ActivityImpl::ImpForceScrollTextAnimNodes() fZeroLogicAlternate = maScrollRectangleLogic.Bottom() - maPaintRectangleLogic.GetHeight(); fOneLogicAlternate = maScrollRectangleLogic.Top(); } - else + else { fZeroLogicAlternate = maScrollRectangleLogic.Top(); fOneLogicAlternate = maScrollRectangleLogic.Bottom() - maPaintRectangleLogic.GetHeight(); } } - + fZeroLogic = maScrollRectangleLogic.Top() - maPaintRectangleLogic.GetHeight(); fOneLogic = maScrollRectangleLogic.Bottom(); fInitLogic = maPaintRectangleLogic.Top(); } - + fDistanceLogic = fOneLogic - fZeroLogic; fInitRelative = (fInitLogic - fZeroLogic) / fDistanceLogic; - - if(DoAlternate()) + + if(DoAlternate()) { fZeroRelative = (fZeroLogicAlternate - fZeroLogic) / fDistanceLogic; @@ -430,42 +430,42 @@ void ActivityImpl::ImpForceScrollTextAnimNodes() (fOneLogicAlternate - fZeroLogic) / fDistanceLogic; fDistanceRelative = fOneRelative - fZeroRelative; } - else + else { fZeroRelative = 0.0; fOneRelative = 1.0; fDistanceRelative = 1.0; } - - if(mnStartTime) + + if(mnStartTime) { // Start time loop ScrollTextAnimNode aStartNode( mnStartTime, 1L, 0.0, 0.0, mnStartTime, false); maVector.push_back(aStartNode); } - - if(IsVisibleWhenStarted()) + + if(IsVisibleWhenStarted()) { double fRelativeStartValue, fRelativeEndValue,fRelativeDistance; - - if(DoScrollForward()) + + if(DoScrollForward()) { fRelativeStartValue = fInitRelative; fRelativeEndValue = fOneRelative; fRelativeDistance = fRelativeEndValue - fRelativeStartValue; } - else + else { fRelativeStartValue = fInitRelative; fRelativeEndValue = fZeroRelative; fRelativeDistance = fRelativeStartValue - fRelativeEndValue; } - + const double fNumberSteps = (fRelativeDistance * fDistanceLogic) / GetStepWidthLogic(); nLoopTime = FRound(fNumberSteps * mnFrequency); - + // init loop ScrollTextAnimNode aInitNode( nLoopTime, 1L, @@ -473,31 +473,31 @@ void ActivityImpl::ImpForceScrollTextAnimNodes() mnFrequency, false); maVector.push_back(aInitNode); } - + // prepare main loop values { double fRelativeStartValue, fRelativeEndValue, fRelativeDistance; - - if(DoScrollForward()) + + if(DoScrollForward()) { fRelativeStartValue = fZeroRelative; fRelativeEndValue = fOneRelative; fRelativeDistance = fRelativeEndValue - fRelativeStartValue; } - else + else { fRelativeStartValue = fOneRelative; fRelativeEndValue = fZeroRelative; fRelativeDistance = fRelativeStartValue - fRelativeEndValue; } - + const double fNumberSteps = (fRelativeDistance * fDistanceLogic) / GetStepWidthLogic(); nLoopTime = FRound(fNumberSteps * mnFrequency); - - if(0L == mnRepeat) + + if(0L == mnRepeat) { - if(!DoScrollIn()) + if(!DoScrollIn()) { // endless main loop ScrollTextAnimNode aMainNode( @@ -507,13 +507,13 @@ void ActivityImpl::ImpForceScrollTextAnimNodes() maVector.push_back(aMainNode); } } - else + else { sal_uInt32 nNumRepeat(mnRepeat); - + if(DoAlternate() && (nNumRepeat + 1L) % 2L) nNumRepeat += 1L; - + // ending main loop ScrollTextAnimNode aMainNode( nLoopTime, nNumRepeat, @@ -522,28 +522,28 @@ void ActivityImpl::ImpForceScrollTextAnimNodes() maVector.push_back(aMainNode); } } - - if(IsVisibleWhenStopped()) + + if(IsVisibleWhenStopped()) { double fRelativeStartValue, fRelativeEndValue, fRelativeDistance; - - if(DoScrollForward()) + + if(DoScrollForward()) { fRelativeStartValue = fZeroRelative; fRelativeEndValue = fInitRelative; fRelativeDistance = fRelativeEndValue - fRelativeStartValue; } - else + else { fRelativeStartValue = fOneRelative; fRelativeEndValue = fInitRelative; fRelativeDistance = fRelativeStartValue - fRelativeEndValue; } - + const double fNumberSteps = (fRelativeDistance * fDistanceLogic) / GetStepWidthLogic(); nLoopTime = FRound(fNumberSteps * mnFrequency); - + // exit loop ScrollTextAnimNode aExitNode( nLoopTime, 1L, @@ -558,32 +558,32 @@ ScrollTextAnimNode* ActivityImpl::ImpGetScrollTextAnimNode( { ScrollTextAnimNode* pRetval = 0L; ImpForceScrollTextAnimNodes(); - + if(!maVector.empty()) { rRelativeTime = nTime; - + for(sal_uInt32 a(0L); !pRetval && a < maVector.size(); a++) { ScrollTextAnimNode & rNode = maVector[a]; - if(!rNode.GetRepeat()) + if(!rNode.GetRepeat()) { // endless loop, use it pRetval = &rNode; } - else if(rNode.GetFullTime() > rRelativeTime) + else if(rNode.GetFullTime() > rRelativeTime) { // ending node pRetval = &rNode; } - else + else { // look at next rRelativeTime -= rNode.GetFullTime(); } } } - + return pRetval; } @@ -591,38 +591,38 @@ sal_uInt32 ActivityImpl::ImpRegisterAgainScrollTextMixerState(sal_uInt32 nTime) { sal_uInt32 nRetval(0L); ImpForceScrollTextAnimNodes(); - + if(maVector.size()) { sal_uInt32 nRelativeTime; ScrollTextAnimNode* pNode = ImpGetScrollTextAnimNode(nTime, nRelativeTime); - + if(pNode) { - // take register time + // take register time nRetval = pNode->GetFrequency(); } } else { - // #i38135# not initialized, return default + // #i38135# not initialized, return default nRetval = mnFrequency; } - + return nRetval; } -void ActivityImpl::updateShapeAttributes( +void ActivityImpl::updateShapeAttributes( double fTime, basegfx::B2DRectangle const& parentBounds ) { OSL_ASSERT( meAnimKind != drawing::TextAnimationKind_NONE ); if( meAnimKind == drawing::TextAnimationKind_NONE ) return; - + double const fMixerState = GetMixerState( static_cast<sal_uInt32>(fTime * 1000.0) ); - - if( meAnimKind == drawing::TextAnimationKind_BLINK ) + + if( meAnimKind == drawing::TextAnimationKind_BLINK ) { // show/hide text: maShapeAttrLayer.get()->setVisibility( fMixerState < 0.5 ); @@ -632,23 +632,23 @@ void ActivityImpl::updateShapeAttributes( // // keep care: the below code is highly sensible to changes... // - + // rectangle of the pure text: double const fPaintWidth = maPaintRectangleLogic.GetWidth(); double const fPaintHeight = maPaintRectangleLogic.GetHeight(); // rectangle where the scrolling takes place (-> clipping): double const fScrollWidth = maScrollRectangleLogic.GetWidth(); double const fScrollHeight = maScrollRectangleLogic.GetHeight(); - + basegfx::B2DPoint pos, clipPos; - - if(ScrollHorizontal()) + + if(ScrollHorizontal()) { double const fOneEquiv( fScrollWidth ); double const fZeroEquiv( -fPaintWidth ); pos.setX( fZeroEquiv + (fMixerState * (fOneEquiv - fZeroEquiv)) ); - + clipPos.setX( -pos.getX() ); clipPos.setY( -pos.getY() ); @@ -657,7 +657,7 @@ void ActivityImpl::updateShapeAttributes( pos.setX( pos.getX() + (fPaintWidth-fScrollWidth) / 2.0 ); } else - { + { // scroll vertical: double const fOneEquiv( fScrollHeight ); double const fZeroEquiv( -fPaintHeight ); @@ -671,15 +671,15 @@ void ActivityImpl::updateShapeAttributes( if( fPaintHeight > fScrollHeight ) pos.setY( pos.getY() + (fPaintHeight-fScrollHeight) / 2.0 ); } - + basegfx::B2DPolygon clipPoly( basegfx::tools::createPolygonFromRect( basegfx::B2DRectangle( clipPos.getX(), clipPos.getY(), clipPos.getX() + fScrollWidth, clipPos.getY() + fScrollHeight ) ) ); - - if( !::basegfx::fTools::equalZero( mfRotationAngle )) + + if( !::basegfx::fTools::equalZero( mfRotationAngle )) { maShapeAttrLayer.get()->setRotationAngle( mfRotationAngle ); double const fRotate = (mfRotationAngle * M_PI / 180.0); @@ -688,7 +688,7 @@ void ActivityImpl::updateShapeAttributes( aTransform.rotate( fRotate ); pos *= aTransform; } - + pos += parentBounds.getCenter(); maShapeAttrLayer.get()->setPosition( pos ); maShapeAttrLayer.get()->setClip( basegfx::B2DPolyPolygon(clipPoly) ); @@ -699,15 +699,15 @@ bool ActivityImpl::perform() { if( !isActive() ) return false; - + ENSURE_OR_RETURN_FALSE( mpDrawShape, "ActivityImpl::perform(): still active, but NULL draw shape" ); - + DrawShapeSharedPtr const pParentDrawShape( mpParentDrawShape ); if( !pParentDrawShape ) return false; // parent has vanished - + if( pParentDrawShape->isVisible() ) { if( !mbIsShapeAnimated ) @@ -723,15 +723,15 @@ bool ActivityImpl::perform() const double nCurrTime( maTimer.getElapsedTime() ); updateShapeAttributes( nCurrTime, parentBounds ); - - const sal_uInt32 nFrequency( + + const sal_uInt32 nFrequency( ImpRegisterAgainScrollTextMixerState( static_cast<sal_uInt32>(nCurrTime * 1000.0)) ); if(nFrequency) { mpWakeupEvent->start(); - mpWakeupEvent->setNextTimeout( + mpWakeupEvent->setNextTimeout( std::max(0.1,nFrequency/1000.0) ); maContext.mrEventQueue.addEvent( mpWakeupEvent ); @@ -779,59 +779,59 @@ ActivityImpl::ActivityImpl( pParentDrawShape->getTreeNode( nNodes - 1, DocTreeNode::NODETYPE_LOGICAL_PARAGRAPH ).getEndIndex()); - + // TODO(Q3): Doing this manually, instead of using // ShapeSubset. This is because of lifetime issues (ShapeSubset // generates circular references to parent shape) mpDrawShape = boost::dynamic_pointer_cast<DrawShape>( - maContext.mpSubsettableShapeManager->getSubsetShape( - pParentDrawShape, + maContext.mpSubsettableShapeManager->getSubsetShape( + pParentDrawShape, scrollTextNode )); mpMetaFile = mpDrawShape->forceScrollTextMetaFile(); - + // make scroll text invisible for slide transition bitmaps - mpDrawShape->setVisibility(false); + mpDrawShape->setVisibility(false); basegfx::B2DRectangle aScrollRect, aPaintRect; - ENSURE_OR_THROW( getRectanglesFromScrollMtf( aScrollRect, + ENSURE_OR_THROW( getRectanglesFromScrollMtf( aScrollRect, aPaintRect, mpMetaFile ), "ActivityImpl::ActivityImpl(): Could not extract " "scroll anim rectangles from mtf" ); - + maScrollRectangleLogic = vcl::unotools::rectangleFromB2DRectangle( aScrollRect ); maPaintRectangleLogic = vcl::unotools::rectangleFromB2DRectangle( aPaintRect ); - + maShapeAttrLayer.createAttributeLayer(mpDrawShape); uno::Reference<drawing::XShape> const xShape( mpDrawShape->getXShape() ); uno::Reference<beans::XPropertySet> const xProps( xShape, uno::UNO_QUERY_THROW ); - + getPropertyValue( meAnimKind, xProps, OUSTR("TextAnimationKind") ); - OSL_ASSERT( meAnimKind != drawing::TextAnimationKind_NONE ); + OSL_ASSERT( meAnimKind != drawing::TextAnimationKind_NONE ); mbAlternate = (meAnimKind == drawing::TextAnimationKind_ALTERNATE); mbScrollIn = (meAnimKind == drawing::TextAnimationKind_SLIDE); - + // adopted from in AInfoBlinkText::ImplInit(): sal_Int16 nRepeat(0); getPropertyValue( nRepeat, xProps, OUSTR("TextAnimationCount") ); mnRepeat = nRepeat; - - if(mbAlternate) + + if(mbAlternate) { // force visible when started for scroll-forth-and-back, because // slide has been coming in with visible text in the middle: mbVisibleWhenStarted = true; } - else + else { getPropertyValue( mbVisibleWhenStarted, xProps, OUSTR("TextAnimationStartInside") ); } - + // set visible when stopped getPropertyValue( mbVisibleWhenStopped, xProps, OUSTR("TextAnimatiogonStopInside") ); @@ -839,7 +839,7 @@ ActivityImpl::ActivityImpl( getPropertyValue( mfRotationAngle, xProps, OUSTR("RotateAngle") ); mfRotationAngle /= -100.0; // (switching direction) - + // set frequency sal_Int16 nDelay(0); getPropertyValue( nDelay, xProps, OUSTR("TextAnimationDelay") ); @@ -848,11 +848,11 @@ ActivityImpl::ActivityImpl( // default: meAnimKind == drawing::TextAnimationKind_BLINK ? 250L : 50L ); - + // adopted from in AInfoScrollText::ImplInit(): - + // If it is a simple m_bScrollIn, reset some parameters - if( DoScrollIn() ) + if( DoScrollIn() ) { // most parameters are set correctly from the dialog logic, but // eg VisisbleWhenStopped is grayed out and needs to be corrected here. @@ -860,14 +860,14 @@ ActivityImpl::ActivityImpl( mbVisibleWhenStarted = false; mnRepeat = 0L; } - + // Get animation direction getPropertyValue( meDirection, xProps, OUSTR("TextAnimationDirection") ); - + // Get step width. Negative means pixel, positive logical units getPropertyValue( mnStepWidth, xProps, OUSTR("TextAnimationAmount") ); - maContext.mpSubsettableShapeManager->addIntrinsicAnimationHandler( + maContext.mpSubsettableShapeManager->addIntrinsicAnimationHandler( mpListener ); } @@ -900,7 +900,7 @@ void ActivityImpl::dispose() // shape) DrawShapeSharedPtr pParent( mpParentDrawShape.lock() ); if( pParent ) - maContext.mpSubsettableShapeManager->revokeSubset( + maContext.mpSubsettableShapeManager->revokeSubset( pParent, mpDrawShape ); } @@ -912,7 +912,7 @@ void ActivityImpl::dispose() maContext.dispose(); mbIsDisposed = true; - maContext.mpSubsettableShapeManager->removeIntrinsicAnimationHandler( + maContext.mpSubsettableShapeManager->removeIntrinsicAnimationHandler( mpListener ); } } @@ -973,7 +973,7 @@ boost::shared_ptr<Activity> createDrawingLayerAnimActivity( OSL_ENSURE( false, rtl::OUStringToOString( comphelper::anyToString( cppu::getCaughtException() ), - RTL_TEXTENCODING_UTF8 ).getStr() ); + RTL_TEXTENCODING_UTF8 ).getStr() ); } return pActivity; |