📄 scalablescreendrawingengine.cpp
字号:
{
// The vertical position is negative so we need to make sure that we don't draw
// before the valid memory area.
pDataLineDest = pDataLineDest + (bpp * aDestPoint.iX);
lines = Min(sizeSource.iHeight + aDestPoint.iY, sizeDest.iHeight);
pDataLineSource = pDataLineSource + (-aDestPoint.iY * strideSource);
pDataLineMask = pDataLineMask + (-aDestPoint.iY * strideMask);
}
if(aDestPoint.iX >= 0)
{
pixels = Min(sizeSource.iWidth, sizeDest.iWidth - aDestPoint.iX);
maskPixelXInit = 0;
}
else
{
// The horizontal line starts left from screen edge; we must adjust
// so that copying starts from the screen edge.
pDataLineDest = pDataLineDest - (bpp * aDestPoint.iX);
pixels = Min(sizeSource.iWidth, sizeSource.iWidth + aDestPoint.iX);
maskPixelXInit = -aDestPoint.iX;
pDataLineSource = pDataLineSource + (bpp * -aDestPoint.iX);
}
TUint8* pDestX;
TUint8* pSourceX;
TInt maskPixelX;
// Copy contents
if(pixels > 0)
{
for(TInt y = 0; y < lines; y++)
{
// Copy a line
pDestX = pDataLineDest;
pSourceX = pDataLineSource;
maskPixelX = maskPixelXInit;
for(TInt x = 0; x < pixels; x++)
{
if(aMask)
{
if( (( *(pDataLineMask + (maskPixelX >> 3))) >> (maskPixelX % 8)) & 1 != 0)
{
// Don't copy, just increase pointers
DoCopyPixel(pDestX, pSourceX, bpp, EFalse);
}
else
{
DoCopyPixel(pDestX, pSourceX, bpp);
}
maskPixelX++;
}
else
{
DoCopyPixel(pDestX, pSourceX, bpp);
}
}
// Advance to the next line
pDataLineDest = pDataLineDest + strideDest;
pDataLineSource = pDataLineSource + strideSource;
if(aMask)
{
pDataLineMask = pDataLineMask + strideMask;
}
}
}
#ifdef EKA2
aSource->UnlockHeap();
aDest->UnlockHeap();
#endif//EKA2
if(aMask)
{
aMask->UnlockHeap();
}
}
void CScalableScreenDrawingEngine::DoCopyPixel(TUint8*& aDest, TUint8*& aSource, TInt aBpp, TBool aCopy) const
{
switch(aBpp)
{
case 1:
{
*aDest++ = *aSource++;
break;
}
case 2:
{
TUint16* pDest = (TUint16*) aDest;
TUint16* pSource = (TUint16*) aSource;
if(aCopy)
{
*pDest = *pSource;
}
pDest++;
pSource++;
aDest = (TUint8*) pDest;
aSource = (TUint8*) pSource;
break;
}
default:
// If bitmap is not 1 byte per pixel or 2 bytes per pixel
// we don't draw anything.
break;
}
}
void CScalableScreenDrawingEngine::ScaleImage()
{
// Re-allocate back buffer because screen size has changed
TDisplayMode displayMode = iVirtualScreen->DisplayMode();
delete iVirtualScreen;
delete iBitmapDevice;
delete iBC;
iVirtualScreen = new (ELeave) CFbsBitmap;
iVirtualScreen->Create(iScreenDevice->SizeInPixels(), displayMode);
iBitmapDevice = CFbsBitmapDevice::NewL(iVirtualScreen);
iBitmapDevice->CreateBitmapContext(iBC);
iScreenDevice->GetDefaultScreenSizeAndRotation(iPixTwipsRot);
TSize size = iPixTwipsRot.iPixelSize;
RDebug::Print(_L("New display size: %dx%d"), size.iWidth, size.iHeight);
// Scale bitmaps. We use a synhcronous method since UI responsivity is of no concern
// in this case.
// AknIconUtils bitmaps keep their aspect ratio when changing between portrait and
// landscape modes.
// Backgound
AknIconUtils::SetSize(iBackground, TSize(size.iWidth, size.iHeight),EAspectRatioNotPreserved);
// Backgound (vector)
AknIconUtils::SetSize(iBackground2, TSize(size.iWidth, size.iHeight));
// Small snowflakes
// The target size of these flakes is 32x32 pixels on a 352x416 screen, and
// we use the calculation below to get a appropriately scaled flake regardless
// of the screen mode (the size of the bitmap is relative to the diagonal of
// the screen, so when the orientation changes but the resolution does not,
// the size of the bitmap does not change).
AknIconUtils::SetSize(iSnowflakeSmall,
TSize((size.iHeight + size.iWidth) / 24, (size.iHeight + size.iWidth) / 24));
// Big snowflakes
AknIconUtils::SetSize(iSnowflakeBig,
TSize((size.iHeight + size.iWidth) / 12, (size.iHeight + size.iWidth) / 12));
//TSize(46, 46));
// Menu selector
AknIconUtils::SetSize(iIconSelector,
//TSize(46, 46));
TSize((size.iHeight + size.iWidth) / 24, (size.iHeight + size.iWidth) / 24));
// Menu selector (vector)
AknIconUtils::SetSize(iIconSelector2,
TSize((size.iHeight + size.iWidth) / 24, (size.iHeight + size.iWidth) / 24));
RDebug::Print(_L("Scaling done. big flakes %dx%d"), (size.iHeight + size.iWidth) / 12, (size.iHeight + size.iWidth) / 12);
}
// Arrow up was pressed
void CScalableScreenDrawingEngine::ArrowUp()
{
if(iIxSelection > 0)
iIxSelection--;
}
// Arrow down was pressed
void CScalableScreenDrawingEngine::ArrowDown()
{
if(iIxSelection < 6)
iIxSelection++;
}
// Enter key press
void CScalableScreenDrawingEngine::EnterPress()
{
switch(iIxSelection)
{
case EDoubleBuffer:
{
// When double buffer is disabled the snowflakes will not show.
// This is because the custom blit routine cannot blit
// directly on the screen.
iUseDoubleBuffer = !iUseDoubleBuffer;
if(iUseDoubleBuffer)
{
RDebug::Print(_L("Double buffer enabled"));
}
else
{
RDebug::Print(_L("Double buffer disabled"));
}
break;
}
case EIcons:
{
iUseBitmapIcons = !iUseBitmapIcons;
if(iUseBitmapIcons)
{
RDebug::Print(_L("Bitmap icons enabled"));
}
else
{
RDebug::Print(_L("Bitmap icons disabled"));
}
break;
}
case EAnchor:
{
iUseAnchors = !iUseAnchors;
if(iUseAnchors)
{
RDebug::Print(_L("Anchors enabled"));
}
else
{
RDebug::Print(_L("Anchors disabled"));
}
break;
}
case EBackground:
{
iUseVectorBackground = !iUseVectorBackground;
if(iUseVectorBackground)
{
RDebug::Print(_L("Vector bg enabled"));
}
else
{
RDebug::Print(_L("Vector bg disabled"));
}
break;
}
case EScroll:
{
iUseScrolling = !iUseScrolling;
if(iUseScrolling)
{
RDebug::Print(_L("Scrolling enabled"));
}
else
{
RDebug::Print(_L("Scrolling disabled"));
}
break;
}
case EOrienation:
{
if(iAppUi->Orientation() == CAknViewAppUi::EAppUiOrientationLandscape)
{
RDebug::Print(_L("Portrait mode"));
iAppUi->SetOrientationL(CAknViewAppUi::EAppUiOrientationPortrait);
ScaleImage();
}
else
{
RDebug::Print(_L("Landscape mode"));
iAppUi->SetOrientationL(CAknViewAppUi::EAppUiOrientationLandscape);
ScaleImage();
}
break;
}
case ESnow:
{
iHideSnow = !iHideSnow;
if(!iHideSnow)
{
RDebug::Print(_L("Snow enabled"));
}
else
{
RDebug::Print(_L("Snow disabled"));
}
break;
}
}
}
// Toggle on/off menu, stars, and indicators (except FPS)
void CScalableScreenDrawingEngine::ToggleDecorators()
{
iHideMenu = !iHideMenu;
iHideStars = !iHideStars;
iHideCBA = !iHideCBA;
}
#ifdef EKA2
// Since the AknIconUtils cannot access the private directory of application,
// mix-in class MAknIconFileProvider is implemented to provide handle of the
// icon files (ScalableScreenDrawingIcons.mbm in this case) to AknIconUtils.
CIconFileProvider::CIconFileProvider(RFs aSession) : iSession(aSession)
{
}
// Destructor
CIconFileProvider:: ~CIconFileProvider()
{
delete iFilename;
iFilename = NULL;
}
CIconFileProvider* CIconFileProvider::NewL(RFs aSession, const TDesC& aFilename)
{
CIconFileProvider* self = new (ELeave) CIconFileProvider(aSession);
CleanupStack::PushL(self);
self->ConstructL(aFilename);
CleanupStack::Pop(); // self
return self;
}
// Second-phase constructor
void CIconFileProvider::ConstructL(const TDesC& aFilename)
{
iFilename = aFilename.AllocL();
}
void CIconFileProvider::RetrieveIconFileHandleL( RFile& aFile, const TIconFileType aType )
{
// MAknIconFileProvider will by default try to open files that
// have .mif extension first. If in case of this application, only the
// file handle of ScalableScreenDrawingIcons.mbm is passed to framework,
// MAknIconFileProvider result will be KErrArgument. This is solved by
// giving the correct file extension determined by function parameter
// aType.
//
TFileName filename;
filename = iFilename->Left(iFilename->Length()-3);
if (aType == EMifFile)
{
filename.Append(_L("mif"));
}
else // mbm
{
filename.Append(_L("mbm"));
}
User::LeaveIfError(aFile.Open(iSession, filename, EFileShareAny));
}
void CIconFileProvider::Finished()
{
}
#endif //EKA2
// End of file.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -