📄 camerawrapperexampleappview.cpp
字号:
/*
* Copyright (c) 2009 Nokia Corporation.
*/
// INCLUDE FILES
#include <coemain.h>
#include <eikon.hrh>
#include <aknutils.h>
#include <pathinfo.h>
#include <f32file.h>
#include <BAUTILS.H>
#include "CameraWrapperExampleAppView.h"
#include "CameraWrapperExampleAppUi.h"
// ============================ MEMBER FUNCTIONS ===============================
CCameraWrapperExampleAppView* CCameraWrapperExampleAppView::NewL (const TRect& aRect )
{
CCameraWrapperExampleAppView* self = CCameraWrapperExampleAppView::NewLC (aRect );
CleanupStack::Pop (self );
return self;
}
CCameraWrapperExampleAppView* CCameraWrapperExampleAppView::NewLC (const TRect& aRect )
{
CCameraWrapperExampleAppView* self = new (ELeave) CCameraWrapperExampleAppView;
CleanupStack::PushL (self );
self->ConstructL (aRect );
return self;
}
void CCameraWrapperExampleAppView::ConstructL (const TRect& aRect )
{
// Create a window for this application view
CreateWindowL ();
iTitleFont = AknLayoutUtils::FontFromId(EAknLogicalFontPrimarySmallFont);
iAppUi = static_cast<CCameraWrapperExampleAppUi*>(iEikonEnv->EikAppUi());
// Set the windows size
SetRect (aRect );
// Activate the window, which makes it ready to be drawn
ActivateL ();
}
CCameraWrapperExampleAppView::CCameraWrapperExampleAppView ()
{
}
CCameraWrapperExampleAppView::~CCameraWrapperExampleAppView ()
{
if (iCameraWrapper)
{
iCameraWrapper->ReleaseAndPowerOff();
}
delete iCameraWrapper;
delete iData;
ReleaseBackBuffer();
}
TKeyResponse CCameraWrapperExampleAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
switch ( aKeyEvent.iCode )
{
case EKeyOK:
case EStdKeyDevice3:
{
// Capture picture
iCameraShutterFocusing = EFalse;
StartFocusing();
return EKeyWasConsumed;
}
case EKeyUpArrow:
{
if (iCameraWrapper->State() == CCameraEngine::EEngineViewFinding)
{
iCameraWrapper->AdjustDigitalZoom(ETrue);
}
return EKeyWasConsumed;
}
case EKeyDownArrow:
{
if (iCameraWrapper->State() == CCameraEngine::EEngineViewFinding)
{
iCameraWrapper->AdjustDigitalZoom(EFalse);
}
return EKeyWasConsumed;
}
default:
{
break;
}
};
#ifdef ENABLE_CAMERA_SHUTTER
// Camera shutter autofocus
switch ( aKeyEvent.iScanCode )
{
case KStdKeyCameraFocus:
case KStdKeyCameraFocus2:
{
// Camera shutter autofocus
if (aType == EEventKeyDown)
{
if (!iAppUi->IsBackCBA())
{
iCameraShutterFocusing = ETrue;
StartFocusing();
}
return EKeyWasConsumed;
}
else if (aType == EEventKeyUp)
{
// Camera state can be EEngineIdle or EEngineFocusing
if (!iAppUi->IsBackCBA() && (iCameraWrapper->State() == CCameraEngine::EEngineFocusing ||
iCameraWrapper->State() == CCameraEngine::EEngineIdle))
{
iCameraWrapper->FocusCancel();
CancelCapturedPicture();
iAppUi->UseOptionsExitCbaL();
}
return EKeyWasConsumed;
}
}
default:
{
break;
}
};
#endif
return EKeyWasNotConsumed;
}
void CCameraWrapperExampleAppView::CancelCapturedPicture(TBool aCleanTexts)
{
if (iCameraWrapper && iCameraWrapper->State() == CCameraEngine::EEngineIdle)
{
TRAPD(err,iCameraWrapper->StartViewFinderL(iViewFinderSize));
if (aCleanTexts)
{
if (err)
{
SetError(_L("Camera viewfinder error %d"), err);
}
else
{
SetTitle(_L("Camera viewfinder"));
}
}
}
}
void CCameraWrapperExampleAppView::Draw(const TRect& /*aRect*/) const
{
CWindowGc& gc = SystemGc ();
// Draw backbuffer that has camera picture
gc.BitBlt(TPoint(0, 0), iBackBuffer);
// Draw texts
DrawTexts(gc);
// Focus rect
if (iCameraWrapper && iCameraWrapper->State() == CCameraEngine::EEngineFocusing)
{
gc.SetPenColor(KRgbWhite);
gc.DrawRect(iFocusRect);
}
}
void CCameraWrapperExampleAppView::DrawTexts(CWindowGc& gc) const
{
if (iTitle.Length()>0)
{
TRect rect(Rect());
gc.SetPenColor(KRgbWhite);
gc.UseFont(iTitleFont);
gc.DrawText(iTitle, rect, rect.Height()/10, CGraphicsContext::ECenter );
gc.DiscardFont();
}
}
void CCameraWrapperExampleAppView::SizeChanged()
{
// Create camera wrapper class here because
// whole camera wrapper and all handles have to reset
// while orientatio of the application changes.
if (iCameraWrapper)
{
// Power off camera if it is on
iCameraWrapper->StopViewFinder();
iCameraWrapper->ReleaseAndPowerOff();
delete iCameraWrapper; iCameraWrapper = NULL;
}
TInt camErr(KErrNotSupported);
if(CCameraEngine::CamerasAvailable() > 0)
{
TRAP(camErr, iCameraWrapper = CCameraEngine::NewL(0,0,this));
}
// iViewFinderSize is picture size for viewfinder.
// iCaptureSize is picture size for capturing picture.
// We want fill whole screen
if (Rect().Size().iWidth > Rect().Size().iHeight)
{
iViewFinderSize = TSize(Rect().Size().iWidth,Rect().Size().iWidth);
iCaptureSize = TSize(1280,960); // Captured picture size
}
else
{
iViewFinderSize = TSize(Rect().Size().iHeight,Rect().Size().iHeight);
iCaptureSize = TSize(1280,960); // Captured picture size
}
// Focus rectangle
iFocusRect = Rect();
iFocusRect.Shrink(Rect().Size().iWidth/4, Rect().Size().iHeight/4);
// Create back buffer where recieved camera pictures are copied
ReleaseBackBuffer();
CreateBackBufferL();
// Power on camera, start viewfinder when MceoCameraReady() received
if(camErr == KErrNone)
{
iCameraWrapper->ReserveAndPowerOn();
SetTitle(_L("Camera power on"));
}
else
{
SetTitle(_L("no camera found"));
}
}
void CCameraWrapperExampleAppView::HandlePointerEventL (
const TPointerEvent& aPointerEvent )
{
if (aPointerEvent.iType == TPointerEvent::EButton1Down)
{
// When pointing to screen camera capture picture
if (!iAppUi->IsBackCBA() &&
iCameraWrapper && iCameraWrapper->State() == CCameraEngine::EEngineViewFinding)
{
iCameraShutterFocusing = EFalse;
StartFocusing();
}
// After captureing, when pointing again to screen camera
// start viewfinder again
else if (!iAppUi->IsBackCBA() &&
iCameraWrapper && iCameraWrapper->State() == CCameraEngine::EEngineIdle)
{
CancelCapturedPicture();
iAppUi->UseOptionsExitCbaL();
}
}
}
void CCameraWrapperExampleAppView::SetTitle(const TDesC& aTitle)
{
iTitle.Copy(aTitle);
DrawNow();
}
void CCameraWrapperExampleAppView::SetError( const TDesC& aMsg, TInt aVal )
{
iTitle.Format(aMsg, aVal);
DrawNow();
}
void CCameraWrapperExampleAppView::SetError( const TDesC& aMsg, TInt aVal1, TInt aVal2 )
{
iTitle.Format(aMsg, aVal1, aVal2);
DrawNow();
}
void CCameraWrapperExampleAppView::CreateBackBufferL()
{
// create back buffer bitmap
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -