⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gifanimationcontainer.cpp

📁 《基于Symbian OS的手机开发与应用实践》这本书的配套源码。
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CGifAnimationContainer from GifAnimationContainer.h
*  Part of  : GifAnimation
*  Created  : 31.01.2006 by ToBeReplacedByAuthor
*  Implementation notes:
*     Initial content was generated by Series 60 Application Wizard.
*  Version  :
*  Copyright: ToBeReplacedByCopyright
* ============================================================================
*/

// INCLUDE FILES
#include <aknutils.h>

#include "GifAnimationContainer.h"


// ================= MEMBER FUNCTIONS =======================

// ---------------------------------------------------------
// CGifAnimationContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CGifAnimationContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();

    iGifAnimationEngine = CGifAnimationEngine::NewL(*this);
    _LIT(KImageFile, "image.gif");
    TFileName imageFile(KImageFile);
    CompleteWithAppPath(imageFile);
    iGifAnimationEngine->LoadL(imageFile);

    iPeriodic=CPeriodic::NewL(0); // neutral priority

    SetRect(aRect);
    ActivateL();
    }

// Destructor
CGifAnimationContainer::~CGifAnimationContainer()
    {
    if(iPeriodic!=NULL)
        {
        iPeriodic->Cancel();
        delete iPeriodic;
        }

    delete iGifAnimationEngine;

    if(iBitmapPointerArray!=NULL)
        {
        iBitmapPointerArray->ResetAndDestroy();
        delete iBitmapPointerArray;
        }
    }
void CGifAnimationContainer::OnCompleteL(CBitmapPointerArray* aArray, TInt/* aError*/)
    {
    if(iBitmapPointerArray!=NULL)
        {
        iBitmapPointerArray->ResetAndDestroy();
        delete iBitmapPointerArray;
        }
    iBitmapPointerArray = aArray;
    StartL();
    }

void CGifAnimationContainer::StartL()
    {
    if((iBitmapPointerArray!=NULL))
        {
        iPeriodic->Cancel();
        iBitmapIndex = -1;
        // variable (actually 1 second) delay and interval
        iPeriodic->Start(1000,500000,TCallBack(Tick, this));
        }
    }

void CGifAnimationContainer::Stop()
    {
    iPeriodic->Cancel();
    DrawDeferred();
    }

// ---------------------------------------------------------
// CGifAnimationContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CGifAnimationContainer::Draw(const TRect&/* aRect*/) const
    {
    if(iBitmapPointerArray==NULL)
        {
        return;
        }
    if(iBitmapIndex<0 || iBitmapIndex>=iBitmapPointerArray->Count())
        {
        return;
        }

    CFbsBitmap* bitmap = (*iBitmapPointerArray)[iBitmapIndex];
    CWindowGc& gc = SystemGc();
    gc.Clear();
    if(bitmap!=NULL)
        {
        TRect rect = Rect();
        TSize size = bitmap->SizeInPixels();
        TPoint pos(0,0);
        if(size.iWidth<rect.Width())
            {
            pos.iX = (rect.Width()-size.iWidth)/2;
            }
        if(size.iHeight<rect.Height())
            {
            pos.iY = (rect.Height()-size.iHeight)/2;
            }
        gc.BitBlt(pos, bitmap);
        }
    }

TInt CGifAnimationContainer::Tick(TAny* aObject)
    {
    ((CGifAnimationContainer*)aObject)->DoTick(); // cast, and call non-static function
    return 1;
    }

void CGifAnimationContainer::DoTick()
    {
    if(iBitmapPointerArray==NULL)
        {
        return;
        }
    iBitmapIndex++;
    if(iBitmapIndex>=iBitmapPointerArray->Count())
        {
        iBitmapIndex=0;
        }
    DrawDeferred();
    }

// End of File  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -