vcl/source/animate/Animation.cxx |  275 ++++++++++++++++++---------------------
 1 file changed, 129 insertions(+), 146 deletions(-)

New commits:
commit 77aa9c210ad79af443191860ee1a7233d2d007cf
Author:     Chris Sherlock <chris.sherloc...@gmail.com>
AuthorDate: Sat Aug 31 14:13:36 2024 +1000
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Sun Sep 1 22:18:50 2024 +0200

    vcl: flatten Animation.cxx functions
    
    Change-Id: I613c630bdbd9eefa4c9196e4647fb0f26f5efcd5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172691
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/vcl/source/animate/Animation.cxx b/vcl/source/animate/Animation.cxx
index daa9e1f1be4e..0233288e77fd 100644
--- a/vcl/source/animate/Animation.cxx
+++ b/vcl/source/animate/Animation.cxx
@@ -165,59 +165,57 @@ BitmapChecksum Animation::GetChecksum() const
 bool Animation::Start(OutputDevice& rOut, const Point& rDestPt, const Size& 
rDestSz,
                       tools::Long nRendererId, OutputDevice* pFirstFrameOutDev)
 {
-    bool bRet = false;
+    if (maFrames.empty())
+        return false;
 
-    if (!maFrames.empty())
+    if ((rOut.GetOutDevType() == OUTDEV_WINDOW) && !mbLoopTerminated
+        && (ANIMATION_TIMEOUT_ON_CLICK != maFrames[mnFrameIndex]->mnWait))
     {
-        if ((rOut.GetOutDevType() == OUTDEV_WINDOW) && !mbLoopTerminated
-            && (ANIMATION_TIMEOUT_ON_CLICK != maFrames[mnFrameIndex]->mnWait))
-        {
-            bool differs = true;
+        bool differs = true;
 
-            auto itAnimView = std::find_if(
-                maRenderers.begin(), maRenderers.end(),
-                [&rOut, nRendererId](const std::unique_ptr<AnimationRenderer>& 
pRenderer) -> bool {
-                    return pRenderer->matches(&rOut, nRendererId);
-                });
+        auto itAnimView = std::find_if(
+            maRenderers.begin(), maRenderers.end(),
+            [&rOut, nRendererId](const std::unique_ptr<AnimationRenderer>& 
pRenderer) -> bool {
+                return pRenderer->matches(&rOut, nRendererId);
+            });
 
-            if (itAnimView != maRenderers.end())
+        if (itAnimView != maRenderers.end())
+        {
+            if ((*itAnimView)->getOriginPosition() == rDestPt
+                && (*itAnimView)->getOutSizePix() == 
rOut.LogicToPixel(rDestSz))
             {
-                if ((*itAnimView)->getOriginPosition() == rDestPt
-                    && (*itAnimView)->getOutSizePix() == 
rOut.LogicToPixel(rDestSz))
-                {
-                    (*itAnimView)->repaint();
-                    differs = false;
-                }
-                else
-                {
-                    maRenderers.erase(itAnimView);
-                }
+                (*itAnimView)->repaint();
+                differs = false;
             }
-
-            if (maRenderers.empty())
+            else
             {
-                maTimer.Stop();
-                mbIsInAnimation = false;
-                mnFrameIndex = 0;
+                maRenderers.erase(itAnimView);
             }
+        }
 
-            if (differs)
-                maRenderers.emplace_back(new AnimationRenderer(this, &rOut, 
rDestPt, rDestSz,
-                                                               nRendererId, 
pFirstFrameOutDev));
-
-            if (!mbIsInAnimation)
-            {
-                ImplRestartTimer(maFrames[mnFrameIndex]->mnWait);
-                mbIsInAnimation = true;
-            }
+        if (maRenderers.empty())
+        {
+            maTimer.Stop();
+            mbIsInAnimation = false;
+            mnFrameIndex = 0;
         }
-        else
-            Draw(rOut, rDestPt, rDestSz);
 
-        bRet = true;
+        if (differs)
+            maRenderers.emplace_back(new AnimationRenderer(this, &rOut, 
rDestPt, rDestSz,
+                                                           nRendererId, 
pFirstFrameOutDev));
+
+        if (!mbIsInAnimation)
+        {
+            ImplRestartTimer(maFrames[mnFrameIndex]->mnWait);
+            mbIsInAnimation = true;
+        }
+    }
+    else
+    {
+        Draw(rOut, rDestPt, rDestSz);
     }
 
-    return bRet;
+    return true;
 }
 
 void Animation::Stop(const OutputDevice* pOut, tools::Long nRendererId)
@@ -377,52 +375,47 @@ IMPL_LINK_NOARG(Animation, ImplTimeoutHdl, Timer*, void)
 {
     const size_t nAnimCount = maFrames.size();
 
-    if (nAnimCount)
+    if (!nAnimCount)
     {
-        bool bIsAnyRendererActive = true;
+        Stop();
+        return;
+    }
 
-        if (maNotifyLink.IsSet())
-        {
-            maNotifyLink.Call(this);
-            PopulateRenderers();
-            PruneMarkedRenderers();
-            bIsAnyRendererActive = IsAnyRendererActive();
-        }
+    bool bIsAnyRendererActive = true;
 
-        if (maRenderers.empty())
-            Stop();
-        else if (!bIsAnyRendererActive)
-            ImplRestartTimer(10);
-        else
-            RenderNextFrameInAllRenderers();
-    }
-    else
+    if (maNotifyLink.IsSet())
     {
-        Stop();
+        maNotifyLink.Call(this);
+        PopulateRenderers();
+        PruneMarkedRenderers();
+        bIsAnyRendererActive = IsAnyRendererActive();
     }
+
+    if (maRenderers.empty())
+        Stop();
+    else if (!bIsAnyRendererActive)
+        ImplRestartTimer(10);
+    else
+        RenderNextFrameInAllRenderers();
 }
 
 bool Animation::Insert(const AnimationFrame& rStepBmp)
 {
-    bool bRet = false;
+    if (IsInAnimation())
+        return false;
 
-    if (!IsInAnimation())
-    {
-        tools::Rectangle aGlobalRect(Point(), maGlobalSize);
-
-        maGlobalSize
-            = aGlobalRect.Union(tools::Rectangle(rStepBmp.maPositionPixel, 
rStepBmp.maSizePixel))
-                  .GetSize();
-        maFrames.emplace_back(new AnimationFrame(rStepBmp));
+    tools::Rectangle aGlobalRect(Point(), maGlobalSize);
 
-        // As a start, we make the first BitmapEx the replacement BitmapEx
-        if (maFrames.size() == 1)
-            maBitmapEx = rStepBmp.maBitmapEx;
+    maGlobalSize
+        = aGlobalRect.Union(tools::Rectangle(rStepBmp.maPositionPixel, 
rStepBmp.maSizePixel))
+              .GetSize();
+    maFrames.emplace_back(new AnimationFrame(rStepBmp));
 
-        bRet = true;
-    }
+    // As a start, we make the first BitmapEx the replacement BitmapEx
+    if (maFrames.size() == 1)
+        maBitmapEx = rStepBmp.maBitmapEx;
 
-    return bRet;
+    return true;
 }
 
 const AnimationFrame& Animation::Get(sal_uInt16 nAnimation) const
@@ -462,42 +455,36 @@ void Animation::Convert(BmpConversion eConversion)
 {
     SAL_WARN_IF(IsInAnimation(), "vcl", "Animation modified while it is 
animated");
 
-    bool bRet;
-
-    if (!IsInAnimation() && !maFrames.empty())
-    {
-        bRet = true;
+    if (IsInAnimation() || maFrames.empty())
+        return;
 
-        for (size_t i = 0, n = maFrames.size(); (i < n) && bRet; ++i)
-            bRet = maFrames[i]->maBitmapEx.Convert(eConversion);
+    bool bRet = true;
 
-        maBitmapEx.Convert(eConversion);
+    for (size_t i = 0, n = maFrames.size(); (i < n) && bRet; ++i)
+    {
+        bRet = maFrames[i]->maBitmapEx.Convert(eConversion);
     }
+
+    maBitmapEx.Convert(eConversion);
 }
 
 bool Animation::ReduceColors(sal_uInt16 nNewColorCount)
 {
     SAL_WARN_IF(IsInAnimation(), "vcl", "Animation modified while it is 
animated");
 
-    bool bRet;
+    if (IsInAnimation() || maFrames.empty())
+        return false;
 
-    if (!IsInAnimation() && !maFrames.empty())
-    {
-        bRet = true;
+    bool bRet = true;
 
-        for (size_t i = 0, n = maFrames.size(); (i < n) && bRet; ++i)
-        {
-            bRet = BitmapFilter::Filter(maFrames[i]->maBitmapEx,
-                                        
BitmapColorQuantizationFilter(nNewColorCount));
-        }
-
-        BitmapFilter::Filter(maBitmapEx, 
BitmapColorQuantizationFilter(nNewColorCount));
-    }
-    else
+    for (size_t i = 0, n = maFrames.size(); (i < n) && bRet; ++i)
     {
-        bRet = false;
+        bRet = BitmapFilter::Filter(maFrames[i]->maBitmapEx,
+                                    
BitmapColorQuantizationFilter(nNewColorCount));
     }
 
+    BitmapFilter::Filter(maBitmapEx, 
BitmapColorQuantizationFilter(nNewColorCount));
+
     return bRet;
 }
 
@@ -505,19 +492,17 @@ bool Animation::Invert()
 {
     SAL_WARN_IF(IsInAnimation(), "vcl", "Animation modified while it is 
animated");
 
-    bool bRet;
-
-    if (!IsInAnimation() && !maFrames.empty())
-    {
-        bRet = true;
+    if (IsInAnimation() || maFrames.empty())
+        return false;
 
-        for (size_t i = 0, n = maFrames.size(); (i < n) && bRet; ++i)
-            bRet = maFrames[i]->maBitmapEx.Invert();
+    bool bRet = true;
 
-        maBitmapEx.Invert();
+    for (size_t i = 0, n = maFrames.size(); (i < n) && bRet; ++i)
+    {
+        bRet = maFrames[i]->maBitmapEx.Invert();
     }
-    else
-        bRet = false;
+
+    maBitmapEx.Invert();
 
     return bRet;
 }
@@ -526,16 +511,14 @@ void Animation::Mirror(BmpMirrorFlags nMirrorFlags)
 {
     SAL_WARN_IF(IsInAnimation(), "vcl", "Animation modified while it is 
animated");
 
-    bool bRet;
-
     if (IsInAnimation() || maFrames.empty())
         return;
 
-    bRet = true;
-
     if (nMirrorFlags == BmpMirrorFlags::NONE)
         return;
 
+    bool bRet = true;
+
     for (size_t i = 0, n = maFrames.size(); (i < n) && bRet; ++i)
     {
         AnimationFrame* pCurrentFrameBmp = maFrames[i].get();
@@ -562,12 +545,10 @@ void Animation::Adjust(short nLuminancePercent, short 
nContrastPercent, short nC
 {
     SAL_WARN_IF(IsInAnimation(), "vcl", "Animation modified while it is 
animated");
 
-    bool bRet;
-
     if (IsInAnimation() || maFrames.empty())
         return;
 
-    bRet = true;
+    bool bRet = true;
 
     for (size_t i = 0, n = maFrames.size(); (i < n) && bRet; ++i)
     {
@@ -583,43 +564,43 @@ SvStream& WriteAnimation(SvStream& rOStm, const 
Animation& rAnimation)
 {
     const sal_uInt16 nCount = rAnimation.Count();
 
-    if (nCount)
-    {
-        const sal_uInt32 nDummy32 = 0;
+    if (!nCount)
+        return rOStm;
 
-        // If no BitmapEx was set we write the first Bitmap of
-        // the Animation
-        if (rAnimation.GetBitmapEx().GetBitmap().IsEmpty())
-            WriteDIBBitmapEx(rAnimation.Get(0).maBitmapEx, rOStm);
-        else
-            WriteDIBBitmapEx(rAnimation.GetBitmapEx(), rOStm);
+    const sal_uInt32 nDummy32 = 0;
 
-        // Write identifier ( SDANIMA1 )
-        rOStm.WriteUInt32(0x5344414e).WriteUInt32(0x494d4931);
+    // If no BitmapEx was set we write the first Bitmap of
+    // the Animation
+    if (rAnimation.GetBitmapEx().GetBitmap().IsEmpty())
+        WriteDIBBitmapEx(rAnimation.Get(0).maBitmapEx, rOStm);
+    else
+        WriteDIBBitmapEx(rAnimation.GetBitmapEx(), rOStm);
 
-        for (sal_uInt16 i = 0; i < nCount; i++)
-        {
-            const AnimationFrame& rAnimationFrame = rAnimation.Get(i);
-            const sal_uInt16 nRest = nCount - i - 1;
-
-            // Write AnimationFrame
-            WriteDIBBitmapEx(rAnimationFrame.maBitmapEx, rOStm);
-            tools::GenericTypeSerializer aSerializer(rOStm);
-            aSerializer.writePoint(rAnimationFrame.maPositionPixel);
-            aSerializer.writeSize(rAnimationFrame.maSizePixel);
-            aSerializer.writeSize(rAnimation.maGlobalSize);
-            rOStm.WriteUInt16((ANIMATION_TIMEOUT_ON_CLICK == 
rAnimationFrame.mnWait)
-                                  ? 65535
-                                  : rAnimationFrame.mnWait);
-            
rOStm.WriteUInt16(static_cast<sal_uInt16>(rAnimationFrame.meDisposal));
-            rOStm.WriteBool(rAnimationFrame.mbUserInput);
-            rOStm.WriteUInt32(rAnimation.mnLoopCount);
-            rOStm.WriteUInt32(nDummy32); // Unused
-            rOStm.WriteUInt32(nDummy32); // Unused
-            rOStm.WriteUInt32(nDummy32); // Unused
-            write_uInt16_lenPrefixed_uInt8s_FromOString(rOStm, ""); // dummy
-            rOStm.WriteUInt16(nRest); // Count of remaining structures
-        }
+    // Write identifier ( SDANIMA1 )
+    rOStm.WriteUInt32(0x5344414e).WriteUInt32(0x494d4931);
+
+    for (sal_uInt16 i = 0; i < nCount; i++)
+    {
+        const AnimationFrame& rAnimationFrame = rAnimation.Get(i);
+        const sal_uInt16 nRest = nCount - i - 1;
+
+        // Write AnimationFrame
+        WriteDIBBitmapEx(rAnimationFrame.maBitmapEx, rOStm);
+        tools::GenericTypeSerializer aSerializer(rOStm);
+        aSerializer.writePoint(rAnimationFrame.maPositionPixel);
+        aSerializer.writeSize(rAnimationFrame.maSizePixel);
+        aSerializer.writeSize(rAnimation.maGlobalSize);
+        rOStm.WriteUInt16((ANIMATION_TIMEOUT_ON_CLICK == 
rAnimationFrame.mnWait)
+                              ? 65535
+                              : rAnimationFrame.mnWait);
+        rOStm.WriteUInt16(static_cast<sal_uInt16>(rAnimationFrame.meDisposal));
+        rOStm.WriteBool(rAnimationFrame.mbUserInput);
+        rOStm.WriteUInt32(rAnimation.mnLoopCount);
+        rOStm.WriteUInt32(nDummy32); // Unused
+        rOStm.WriteUInt32(nDummy32); // Unused
+        rOStm.WriteUInt32(nDummy32); // Unused
+        write_uInt16_lenPrefixed_uInt8s_FromOString(rOStm, ""); // dummy
+        rOStm.WriteUInt16(nRest); // Count of remaining structures
     }
 
     return rOStm;
@@ -641,7 +622,9 @@ SvStream& ReadAnimation(SvStream& rIStm, Animation& 
rAnimation)
     // If the BitmapEx at the beginning have already been read (by Graphic)
     // we can start reading the AnimationFrames right away
     if ((nAnimMagic1 == 0x5344414e) && (nAnimMagic2 == 0x494d4931) && 
!rIStm.GetError())
+    {
         bReadAnimations = true;
+    }
     // Else, we try reading the Bitmap(-Ex)
     else
     {

Reply via email to