📄 pizizhappview.cpp
字号:
/*
============================================================================
Name : pizizhAppView.cpp
Author : pizi
Copyright : Your copyright notice
Description : Application view implementation
============================================================================
*/
// INCLUDE FILES
#include <coemain.h>
#include "pizizhAppView.h"
#include <e32math.h>
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CpizizhAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CpizizhAppView* CpizizhAppView::NewL( const TRect& aRect )
{
CpizizhAppView* self = CpizizhAppView::NewLC( aRect );
CleanupStack::Pop( self );
return self;
}
// -----------------------------------------------------------------------------
// CpizizhAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CpizizhAppView* CpizizhAppView::NewLC( const TRect& aRect )
{
CpizizhAppView* self = new ( ELeave ) CpizizhAppView;
CleanupStack::PushL( self );
self->ConstructL( aRect );
return self;
}
// -----------------------------------------------------------------------------
// CpizizhAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CpizizhAppView::ConstructL( const TRect& aRect )
{
// Create a window for this application view
CreateWindowL();
// Set the windows size
SetRect( aRect );
SetExtentToWholeScreen();
// Activate the window, which makes it ready to be drawn
ActivateL();
itime = 1;
_LIT(KMbmFile, "z:\\resource\\apps\\pizizh1.mbm");
map[0] = new (ELeave)CFbsBitmap();
User::LeaveIfError(map[0]->Load(KMbmFile, EMbmPizizh1140));
map[1] = new (ELeave)CFbsBitmap();
User::LeaveIfError(map[1]->Load(KMbmFile, EMbmPizizh1150));
bitmap = new (ELeave) CFbsBitmap();
bitmap->Create(CEikonEnv::Static()->ScreenDevice()->SizeInPixels(), CEikonEnv::Static()->DefaultDisplayMode());
CFbsBitmapDevice *bitDev = CFbsBitmapDevice::NewL(bitmap);
CleanupStack::PushL(bitDev);
CFbsBitGc *bitGc;
User::LeaveIfError( bitDev->CreateContext(bitGc));
TPoint zero(0,0);
TInt wi=map[itime]->SizeInPixels().iWidth;
TInt he=map[itime]->SizeInPixels().iHeight;
//bitGc->BitBlt(zero, map[itime]);
bitGc->DrawBitmap(TRect(TPoint(100,100),TSize(wi,he)),map[itime]);
CleanupStack::PopAndDestroy();//bitGc
delete bitGc;
}
// -----------------------------------------------------------------------------
// CpizizhAppView::CpizizhAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CpizizhAppView::CpizizhAppView()
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CpizizhAppView::~CpizizhAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CpizizhAppView::~CpizizhAppView()
{
// No implementation required
if(map[0])
{
delete map[0];
}
if(map[1])
{
delete map[1];
}
if(bitmap)
{
delete bitmap;
}
}
// -----------------------------------------------------------------------------
// CpizizhAppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CpizizhAppView::Draw( const TRect& /*aRect*/ ) const
{
// Get the standard graphics context
CWindowGc& gc = SystemGc();
// Gets the control's extent
TRect drawRect( Rect());
// Clears the screen
gc.Clear( drawRect );
TPoint top(0, 0);
//gc.BitBlt(top, bitmap);
gc.BitBlt(top, bitmap);
//TPoint top1(50, 50);
//gc.BitBlt(top1, map[1]);
}
// -----------------------------------------------------------------------------
// CpizizhAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CpizizhAppView::SizeChanged()
{
DrawNow();
}
// End of File
TKeyResponse CpizizhAppView::OfferKeyEventL(const TKeyEvent &aEvent, TEventCode aType)
{
if (aType == EEventKey)
{
if (aEvent.iCode == EKeyLeftArrow)
{
/*CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
informationNote->ExecuteLD(_L("left pressed!"));*/
//itime = (itime+1) % 2;
DrawNow();
CFbsBitmapDevice *bitDev = CFbsBitmapDevice::NewL(bitmap);
CleanupStack::PushL(bitDev);
CFbsBitGc *bitGc;
User::LeaveIfError( bitDev->CreateContext(bitGc));
itime = (itime+1)%2;
TInt i;
TInt j;
for(i=0; i <= 320; i+=2)
{
j = i;
while(j > 0)
{
bitGc->BitBlt(TPoint(0, j-1), map[itime],
TRect(TPoint(0,320-(i-j-1)),TSize(120,1)));
bitGc->BitBlt(TPoint(0, 320-j), map[itime],
TRect(TPoint(0,i-j),TSize(120,1)));
/*bitGc->DrawBitmap(TRect(TPoint(0, j-1), TSize(240,1)),
map[itime],
TRect(TPoint(0,320-(i-j-1)),TSize(240,1)));
bitGc->DrawBitmap(TRect(TPoint(0, 320-j), TSize(240,1)),
map[itime],
TRect(TPoint(0,i-j),TSize(240,1)));*/
j-=2;
if(j % 200 == 0)
{
iEikonEnv->WsSession().Flush();
DrawNow();
}
}
}
//雨滴效果
/*TInt i;
TInt j;
for(i=0; i<=320; ++i )
{
for(j=0; j<=320-i; ++j )
{
bitGc->DrawBitmap(TRect(TPoint(0, j), TSize(240,1)),
map[itime],
TRect(TPoint(0,320-i),TSize(240,1)));
if(j % 160 == 0)
{
DrawNow();
}
}
}*/
//积木效果
/*TInt i;
TInt j;
TInt stepx;
TInt stepy;
TInt dispnum;
TInt x;
TInt y;
TBool pxy[20][20];
for ( i=0; i<20; ++i )
{
for ( j=0; j<20; ++j )
{
pxy[i][j] = EFalse;
}
}
stepx = 240 / 20;
stepy = 320 / 20;
TTime time;
time.HomeTime();
TInt64 aSeed=time.Int64();
//srand( (unsigned)time( NULL ) );
dispnum = 0;
while(1)
{
x= Math::Rand(aSeed) % 20;
y= Math::Rand(aSeed) % 20;
if ( pxy[x][y] )
//本组x,y所代表的数据组是否已显示过?
continue;
pxy[x][y] = ETrue;
//表明本组x,y所代表的数据组已显示过
bitGc->BitBlt(TPoint(x*stepx, y*stepy), map[itime],
TRect(TPoint(x*stepx, y*stepy),TSize(stepx, stepy)));
//bitGc->DrawBitmap(TRect(TPoint(x*stepx, y*stepy), TSize(stepx,stepy)),
//map[itime],
//TRect(TPoint(x*stepx, y*stepy),TSize(stepx, stepy)));
if(dispnum%4 == 0)
{
iEikonEnv->WsSession().Flush();
DrawNow();
}
dispnum++;
if ( dispnum >=400 )
break;
}*/
//百叶窗效果
/*TInt i;
TInt j;
TInt stepi;
stepi=32;
for ( i=0; i<=stepi; ++i )
{
for ( j=0; j<10; ++j )
{
bitGc->DrawBitmap(TRect(TPoint(0, j*stepi+i), TSize(240,1)),
map[itime],
TRect(TPoint(0,j*stepi+i),TSize(240,1)));
if(j % 2 == 0)
{
DrawNow();
}
}
}*/
CleanupStack::PopAndDestroy();
if(bitGc)
{
delete bitGc;
}
}
if (aEvent.iCode == EKeyUpArrow)
{
TInt iImageHeight = 320;
TInt iImageWidth = 240;
TSize aImageSize = bitmap->SizeInPixels();
TReal aHeight = aImageSize.iHeight;
TReal aWidth = aImageSize.iWidth;
if(aHeight>iImageHeight||aWidth>iImageWidth)
{
if(aWidth/aHeight>((TReal)iImageWidth)/((TReal)iImageHeight))
{
aHeight = iImageWidth*aHeight/aWidth;
aWidth = iImageWidth;
}
else
{
aWidth = aWidth*iImageHeight/aHeight;
aHeight = iImageHeight;
}
}
//iScaler->Scale( &iStatus, *bitmap, TSize(aWidth,aHeight) );
/*CMyBitmapScaler* iScaler;
iScaler = CMyBitmapScaler::NewL(map[0], this);
CleanupStack::PushL(iScaler);
iScaler->Scale(50);
CleanupStack::PopAndDestroy();
DrawNow();*/
}
return EKeyWasConsumed;
}
return EKeyWasNotConsumed;
}
void CpizizhAppView::Completed(TInt)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -