📄 clientanimationcontainer.cpp
字号:
/**
*
* @brief Definition of CClientAnimationContainer
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDES
// Class include
#include "ClientAnimationContainer.h"
// System includes
#include <ClientAnimation.rsg>
#include <barsread.h>
#include <eikenv.h>
#include <w32std.h>
// User include
#include "DoubleBufferedArea.h"
#include "ExplosionArray.h"
#include "ExplosionCreator.h"
// CONSTANTS
const TInt KAnimFrameTime = 50000;
const TInt KColorBlack = 215;
// ================= MEMBER FUNCTIONS =======================
/**
* Symbian OS 2 phase constructor.
* Constructs the CClientAnimationContainer using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
*
* @param aRect The rectangle for this window
* @return The newly constructed CClientAnimationContainer
*/
CClientAnimationContainer* CClientAnimationContainer::NewL(const TRect& aRect)
{
CClientAnimationContainer* self = CClientAnimationContainer::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CClientAnimationContainer using the constructor and ConstructL
* method, leaving the constructed object on the CleanupStack before returning it.
*
* @param aRect The rectangle for this window
* @return The newly constructed CClientAnimationContainer
*/
CClientAnimationContainer* CClientAnimationContainer::NewLC(const TRect& aRect)
{
CClientAnimationContainer* self = new (ELeave) CClientAnimationContainer;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
/**
* Symbian OS 2nd phase constructor. Creates a Window for the control to draw to in order to animate
* Sets up Periodic timer, which, will repeatedly call the call back function thereby animating
* Creates Doublebufferedarea which animation function draws to, to avoid flickery redraw
* Starts animation
*
* @param aRect The rectangle for this window
*/
void CClientAnimationContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
SetRect(aRect);
iTimer = CPeriodic::NewL(CActive::EPriorityStandard);
iDoubleBufferedArea = CDoubleBufferedArea::NewL(aRect.Size(), EColor4K);
iExplosions = CExplosionArray::NewL(aRect);
iExplosionCreator = CExplosionCreator::NewL(*iExplosions);
ActivateL();
StartAnimationL();
}
/**
* Destructor.
*/
CClientAnimationContainer::~CClientAnimationContainer()
{
delete iTimer;
delete iExplosionCreator;
delete iExplosions;
delete iDoubleBufferedArea;
}
/**
* Starts animation by calling the CPeriodic::Start() function passing in CClientAnimationContainer::AnimationCallback
* as the callback function
* Also sets off mechansim that creates the explosions
**/
void CClientAnimationContainer::StartAnimationL()
{
if (!iTimer->IsActive())
{
iTimer->Start(0, KAnimFrameTime,TCallBack(CClientAnimationContainer::AnimationCallback,this));
}
iExplosionCreator->StartExplosionCreator();
}
/**
* Stops the animation by calling the CPeriodic::Cancel()
* Also stops the explosions being generated
*/
void CClientAnimationContainer::StopAnimation()
{
iExplosionCreator->Cancel();
iTimer->Cancel();
}
/**
* Callback function which calls the CClientAnimcationContainer::DrawFrame() function to
* actually perform the drawing
*
* @param aPtr Pointer to CClientAnimationContainer class
*/
TInt CClientAnimationContainer::AnimationCallback(TAny* aPtr)
{
((CClientAnimationContainer*)aPtr)->DrawFrame();
return 1;
}
/**
* Function which draws animation to offscreen bitmap before blitting the offscreen bitmap
* to the system graphics context
* Invalidates area of window to be drawn to and informs window server of impending draw
* Calls DrawToDoubleBufferedArea() function
* Draws offscreen bitmap to system graphics context
* Informs window of conclusion of draw
*/
void CClientAnimationContainer::DrawFrame()
{
Window().Invalidate(Rect());
ActivateGc();
Window().BeginRedraw(Rect());
DrawToDoubleBufferedArea();
CWindowGc& gc = SystemGc();
gc.BitBlt(TPoint(0,0), &(iDoubleBufferedArea->GetDoubleBufferedAreaBitmap()));
Window().EndRedraw();
DeactivateGc();
}
/**
* Draws animation to offscreen bitmap
*/
void CClientAnimationContainer::DrawToDoubleBufferedArea()
{
iDoubleBufferedArea->GetDoubleBufferedAreaContext().Clear();
TRgb colorBlack= AKN_LAF_COLOR(KColorBlack);
iDoubleBufferedArea->GetDoubleBufferedAreaContext().SetBrushColor(colorBlack);
iDoubleBufferedArea->GetDoubleBufferedAreaContext().DrawRect(Rect());
iExplosions->DrawExplosions(iDoubleBufferedArea->GetDoubleBufferedAreaContext());
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -