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

📄 bitmapscalercontainer.cpp

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

// INCLUDE FILES
#include <eikenv.h>
#include <eikappui.h>
#include <eikapp.h>
#include <BitmapScaler.mbg>

#include "BitmapScalerContainer.h"


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

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

    CEikonEnv* eikonEnv = CEikonEnv::Static();
    TFileName mbmFile = eikonEnv->EikAppUi()->Application()->BitmapStoreName();
    iBitmap = eikonEnv->CreateBitmapL(mbmFile, EMbmBitmapscalerFace);

    iBitmapScalerEngine = CBitmapScalerEngine::NewL(*this);

    SetRect(aRect);
    ActivateL();
    }

// Destructor
CBitmapScalerContainer::~CBitmapScalerContainer()
    {
    if(iBitmapScalerEngine!=NULL)
        {
        delete iBitmapScalerEngine;
        }
    delete iBitmap;
    delete iScaled;
    }

TKeyResponse CBitmapScalerContainer::OfferKeyEventL(
    const TKeyEvent& aKeyEvent,TEventCode aType)
    {
    TKeyResponse response = EKeyWasNotConsumed;
    if(aType==EEventKey)
        {
        const TSize KMinSize(16, 16);
        const TSize KMaxSize(80, 80);

        response = EKeyWasConsumed;
        switch(aKeyEvent.iScanCode)
            {
            case EStdKeyLeftArrow: // Zoom out
            case EStdKeyDownArrow:
                {
                if(iScaled==NULL)
                    {
                    TSize size = iBitmap->SizeInPixels() - KMinSize;
                    iScaled = new(ELeave) CFbsBitmap;
                    User::LeaveIfError(iScaled->Create(size, iBitmap->DisplayMode()));
                    iBitmapScalerEngine->Scale(*iBitmap, *iScaled);
                    }
                else
                    {
                    TSize size = iScaled->SizeInPixels() - KMinSize;
                    if(size==iBitmap->SizeInPixels())
                        {
                        delete iScaled;
                        iScaled = NULL;
                        DrawDeferred();
                        }
                    else if(size.iWidth>=KMinSize.iWidth)
                        {
                        User::LeaveIfError(iScaled->Resize(size));
                        iBitmapScalerEngine->Scale(*iBitmap, *iScaled);
                        }
                    }
                break;
                }
            case EStdKeyRightArrow: // Zoom in
            case EStdKeyUpArrow:
                {
                if(iScaled==NULL)
                    {
                    TSize size = iBitmap->SizeInPixels() + KMinSize;
                    iScaled = new(ELeave) CFbsBitmap;
                    User::LeaveIfError(iScaled->Create(size, iBitmap->DisplayMode()));
                    iBitmapScalerEngine->Scale(*iBitmap, *iScaled);
                    }
                else
                    {
                    TSize size = iScaled->SizeInPixels() + KMinSize;
                    if(size==iBitmap->SizeInPixels())
                        {
                        delete iScaled;
                        iScaled = NULL;
                        DrawDeferred();
                        }
                    else if(size.iWidth<=KMaxSize.iWidth)
                        {
                        User::LeaveIfError(iScaled->Resize(size));
                        iBitmapScalerEngine->Scale(*iBitmap, *iScaled);
                        }
                    }
                }
            default:
                {
                response = EKeyWasNotConsumed;
                break;
                }
            }
        }
    return response;
    }

void CBitmapScalerContainer::OnCompleteL(TInt/*aError*/)
    {
    DrawDeferred();
    }

// ---------------------------------------------------------
// CBitmapScalerContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CBitmapScalerContainer::Draw(const TRect&/* aRect*/) const
    {
    if(iBitmapScalerEngine->IsActive())
        {
        return;
        }

    CWindowGc& gc = SystemGc();
    gc.Clear();

    CFbsBitmap* bitmap = iScaled;
    if(bitmap==NULL)
        {
        bitmap = iBitmap;
        }
    TRect rect = Rect();
    TSize size = bitmap->SizeInPixels();
    TPoint pos((rect.Width()-size.iWidth)/2, (rect.Height()-size.iHeight)/2);
    gc.BitBlt(pos, bitmap);
    }

// End of File  

⌨️ 快捷键说明

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