📄 cameraappbasecontainer.cpp
字号:
/*
* Copyright ?2008 Nokia Corporation.
*/
#include <w32std.h>
#include <coemain.h>
#include <aknsutils.h>
#include <aknnavide.h>
#include <barsread.h>
#include <akntabgrp.h>
#include <CameraApp.rsg>
#include "CameraAppBaseContainer.h"
#include "CameraAppController.h"
#include "cameraappapp.h"
//#include "CameraApp_sc.hlp.hrh"
#include "cameraappappui.h"
// Constants
const TInt KErrorMsgXPos = 10;
const TInt KErrorMsgYPos = 50;
const TInt KErrorMaxWidth = 160;
const TInt KRedColor = 35;
/*
-------------------------------------------------------------------------------
Constructor. Initializes member variables.
-------------------------------------------------------------------------------
*/
CCameraAppBaseContainer::CCameraAppBaseContainer(
CCameraAppController*& aController )
: iController( aController ),
iBitmap( 0 ),
iOffScreenBitmap( 0 ),
iFbsBitGc( 0 ),
iBmpDevice( 0 )
{
iController->SetAppContainer( this );
}
void CCameraAppBaseContainer::SetController(CCameraAppController*& aController)
{
iController = aController;
if (iController)
{
iController->SetAppContainer( this );
}
}
/*
-------------------------------------------------------------------------------
Symbian OS 2nd phase constructor
-------------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
SetRect(aRect);
ActivateL();
// This should be called after the windows has been activated
CreateOffScreenBitmapL();
}
/*
-------------------------------------------------------------------------------
Destructor. Frees reserved resources.
-------------------------------------------------------------------------------
*/
CCameraAppBaseContainer::~CCameraAppBaseContainer()
{
delete iOffScreenBitmap;
delete iFbsBitGc;
delete iBmpDevice;
}
/*
-------------------------------------------------------------------------------
Renders a bitmap image onto a real screen
-------------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::DrawImage(CWindowGc& aGc,
const TRect& aRect) const
{
if( iController && iController->IsSkippingFrames() )
{
return;
}
TSize bmpSizeInPixels( iBitmap->SizeInPixels() );
TInt xDelta = (aRect.Width() - bmpSizeInPixels.iWidth) / 2;
TInt yDelta = (aRect.Height() - bmpSizeInPixels.iHeight) / 2;
TPoint pos( xDelta, yDelta ); // displacement vector
pos += aRect.iTl; // bitmap top left corner position
// Drawing viewfinder image to bitmap
iFbsBitGc->BitBlt( pos, iBitmap, TRect( TPoint( 0, 0 ), bmpSizeInPixels ));
// Draws bitmap with indicators on the screen
TSize size( iOffScreenBitmap->SizeInPixels() );
aGc.BitBlt( TPoint(0,0), iOffScreenBitmap, TRect( TPoint(0,0), size ) );
}
/*
-------------------------------------------------------------------------------
Gets the control's help context
-------------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::GetHelpContext(TCoeHelpContext& aContext) const
{
// Get the help context for the application
aContext.iMajor = KUidHelpFile;
_LIT(KContextApplication,"Just temp temp");
aContext.iContext = KContextApplication;
}
/*
-------------------------------------------------------------------------------
Creates the data member offscreen bitmap
-------------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::CreateOffScreenBitmapL()
{
iOffScreenBitmap = new (ELeave) CWsBitmap( iCoeEnv->WsSession() );
TSize size = Rect().Size();
TInt createError = iOffScreenBitmap->Create( size,
iController->DisplayMode());
User::LeaveIfError( createError );
iFbsBitGc = CFbsBitGc::NewL(); //graphic context
iBmpDevice = CFbsBitmapDevice::NewL(iOffScreenBitmap);
iFbsBitGc->Activate(iBmpDevice);
iFbsBitGc->SetBrushColor( KRgbBlack );
iFbsBitGc->Clear();
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
CFbsBitmap* bitmap = AknsUtils::GetCachedBitmap( skin,
KAknsIIDQsnBgAreaMain);
if ( bitmap )
{
iFbsBitGc->BitBlt( TPoint(0,0), bitmap );
}
iOffScreenBitmapCreated = ETrue;
}
/*
-------------------------------------------------------------------------------
Gets from Controller the image to draw and calls DrawNow()
-------------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::DrawImageNow(CFbsBitmap& aBitmap)
{
if (iOffScreenBitmapCreated && IsActivated() && IsReadyToDraw())
{
iBitmap = &aBitmap;
DrawNow();
}
}
/*
-------------------------------------------------------------------------------
Redraws offscreen bitmap with landscape focus indicators
-------------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::ReDrawOffScreenBitmap()
{
iOffScreenBitmapCreated = ETrue;
iFbsBitGc->SetBrushColor( KRgbBlack );
iFbsBitGc->Clear();
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
CFbsBitmap* bitmap = AknsUtils::GetCachedBitmap( skin,
KAknsIIDQsnBgAreaMain );
if ( bitmap )
{
iFbsBitGc->BitBlt( TPoint(0,0), bitmap );
}
DrawNow();
}
/*
-------------------------------------------------------------------------------
Shows an error message on the screen
-------------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::ShowErrorMessage(const TDesC &aMsg)
{
const CFont* font = LatinBold16();
iFbsBitGc->UseFont( font );
TInt ascent = font->AscentInPixels();
TInt height = font->HeightInPixels();
iFbsBitGc->SetPenColor( AKN_LAF_COLOR( KRedColor ) );
TPoint point( KErrorMsgXPos, KErrorMsgYPos );
iFbsBitGc->DrawText(
aMsg,
TRect( point, TSize( KErrorMaxWidth, height )),
ascent,
CGraphicsContext::ERight,
0 );
// Draw the offscreen bitmap now to show the message
DrawNow();
}
/*
-------------------------------------------------------------------------------
Called when this control's rect changes
-------------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::SizeChanged()
{
TRect rect = Rect();
if( iOffScreenBitmapCreated )
{
iOffScreenBitmap->Resize( rect.Size() );
iBmpDevice->Resize( rect.Size() );
iFbsBitGc->Resized();
}
if (iController)
{
TRAP_IGNORE( iController->ClientRectChangedL( rect ) );
}
}
/*
-------------------------------------------------------------------------------
Handles a change to the control's resources. Specifically, handles a layout
(orientation) change event.
-------------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::HandleResourceChange( TInt aType )
{
if( aType == KEikDynamicLayoutVariantSwitch )
{
if( iOffScreenBitmapCreated )
{
iFbsBitGc->Clear();
}
// skip a couple of vf frames, otherwise display can get messed up
// during layout switch
const TInt KNumOfFrames = 5;
if (iController)
{
iController->SkipFrames(KNumOfFrames);
}
}
// call base class implementation
CCoeControl::HandleResourceChange( aType );
}
/*
-------------------------------------------------------------------------------
Called by the framework to draw the screen
-------------------------------------------------------------------------------
*/
void CCameraAppBaseContainer::Draw(const TRect& /*aRect*/ ) const
{
TRect drawingRect = Rect();
CWindowGc& gc = SystemGc();
if ( iOffScreenBitmapCreated )
{
if ( iBitmap ) //Viewfinding ongoing
{
DrawImage(gc, drawingRect);
}
else
{
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
CFbsBitmap* bitmap = AknsUtils::GetCachedBitmap( skin,
KAknsIIDQsnBgAreaMain );
if ( bitmap )
{
gc.BitBlt( TPoint(0,0), bitmap);
}
else
{
// Draws bitmap with indicators on the screen
TSize size( iOffScreenBitmap->SizeInPixels() );
gc.BitBlt( TPoint(0,0), iOffScreenBitmap,
TRect( TPoint(0,0), size ) );
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -