os/mm/imagingandcamerafws/camerafw/testapps/testcameraapp/TestCameraApp.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <eikenv.h>
    17 #include <testcameraapp.rsg>
    18 #include "TestCameraApp.h"
    19 #include "TestCameraApp.hrh"
    20 #include "TestCamera.h"
    21 
    22 const TInt KMaxErrLength=50;
    23 _LIT(KErrorFormat,"Error - %d (%S)");
    24 
    25 //
    26 //  CTCamAppUi
    27 //
    28 
    29 void CTCamAppUi::ConstructL()
    30 	{
    31 	CEikAppUi::ConstructL();
    32 	iAppView = new(ELeave) CTCamAppView;
    33 	iAppView->ConstructL(ClientRect());
    34 	AddToStackL(iAppView);
    35 	
    36 	// The plugin relies on a specific file existing
    37 	// hence this has to be created.
    38 	CreateDependencyFileL();
    39 
    40 	iCamera = CCamera::NewL(*this,0,0);
    41 	
    42 	iCameraAdvSet = CCamera::CCameraAdvancedSettings::NewL(*iCamera);
    43 	iCameraPresets = CCamera::CCameraPresets::NewL(*iCamera);
    44 	iCameraImgProc = CCamera::CCameraImageProcessing::NewL(*iCamera);
    45 	iCameraSnapshot = CCamera::CCameraSnapshot::NewL(*iCamera);
    46 	
    47 	iCamera->Reserve();
    48 	}
    49 
    50 CTCamAppUi::~CTCamAppUi()
    51 	{
    52 	if (iCamera!=NULL)
    53 		iCamera->Release();
    54 	
    55 	delete iCameraSnapshot;
    56 	delete iCameraImgProc;	
    57 	delete iCameraPresets;
    58 	delete iCameraAdvSet;
    59 	delete iCamera;
    60 
    61 	// as the application is being closed, delete the file
    62 	// so that the plugin will not be reactivated accidentaly
    63 	RemoveDependencyFile();
    64 	
    65 	if (iAppView)
    66 		{
    67 		RemoveFromStack(iAppView);
    68 		delete iAppView;
    69 		}
    70 	}
    71 
    72 void CTCamAppUi::HandleCommandL(TInt aCommand)
    73 	{
    74 	switch (aCommand)
    75 		{
    76 	case ETCamCmdPowerOn:
    77 		iCamera->PowerOn();
    78 		break;
    79 	case ETCamCmdPowerOff:
    80 		iCamera->PowerOff();
    81 		break;
    82 	case ETCamCmdViewFinder:
    83 		ViewFinderL();
    84 		break;
    85 	case ETCamCmdCaptureImage:
    86 		SingleShotL();
    87 		break;
    88 	case ETCamCmdBurstMode:
    89 		BurstModeL();
    90 		break;
    91 	case ETCamCmdCaptureVideo:
    92 		CaptureVideoL();
    93 		break;
    94 	case ETCamCmdIncBrightness:
    95 		iCamera->SetBrightnessL(iCamera->Brightness() + 10);
    96 		break;
    97 	case ETCamCmdIncContrast:
    98 		iCamera->SetContrastL(iCamera->Contrast() + 10);
    99 		break;
   100 	case ETCamCmdDecBrightness:
   101 		iCamera->SetBrightnessL(iCamera->Brightness() - 10);
   102 		break;
   103 	case ETCamCmdDecContrast:
   104 		iCamera->SetContrastL(iCamera->Contrast() - 10);
   105 		break;
   106 	case ETCamCmdResetBrightness:
   107 		iCamera->SetBrightnessL(0);
   108 		break;
   109 	case ETCamCmdResetContrast:
   110 		iCamera->SetContrastL(0);
   111 		break;
   112 	case ETCamCmdIncNumBurstImages:
   113 		iCameraAdvSet->SetBurstImages(iCameraAdvSet->BurstImages() + 1);
   114 		break;
   115 	case ETCamCmdDecNumBurstImages:
   116 		iCameraAdvSet->SetBurstImages(iCameraAdvSet->BurstImages() - 1);
   117 		break;
   118 	case ETCamCmdResetNumBurstImages:
   119 		iCameraAdvSet->SetBurstImages(4);
   120 		break;
   121 		
   122 	case ETCamCmdFactoryPreset:
   123 		iCameraPresets->SetPreset(KUidECamPresetFactoryDefault);
   124 		break;
   125 	
   126 	case ETCamCmdOutdoorPreset:
   127 		iCameraPresets->SetPreset(KUidECamPresetOutdoor);
   128 		break;	
   129 		
   130 	case ETCamCmdOutdoorSportPreset:
   131 		iCameraPresets->SetPreset(KUidECamPresetOutdoorSport);
   132 		break;
   133 	
   134 	case ETCamCmdFogPreset:
   135 		iCameraPresets->SetPreset(KUidECamPresetFog);
   136 		break;	
   137 
   138 	case ETCamCmdNightPartyIndoorPreset:
   139 		iCameraPresets->SetPreset(KUidECamPresetNightPartyIndoor);
   140 		break;
   141 	
   142 	case ETCamCmdTextDocumentPreset:
   143 		iCameraPresets->SetPreset(KUidECamPresetTextDocument);
   144 		break;	
   145 		
   146 	case ETCamCmdImgProcIncBrightness:
   147 		IncImgProcAdjustmentL(KUidECamEventImageProcessingAdjustBrightness);
   148 		break;
   149 		
   150 	case ETCamCmdImgProcDecBrightness:
   151 		DecImgProcAdjustmentL(KUidECamEventImageProcessingAdjustBrightness);
   152 		break;
   153 		
   154 	case ETCamCmdImgProcIncContrast:
   155 		IncImgProcAdjustmentL(KUidECamEventImageProcessingAdjustContrast);
   156 		break;
   157 		
   158 	case ETCamCmdImgProcDecContrast:
   159 		DecImgProcAdjustmentL(KUidECamEventImageProcessingAdjustContrast);
   160 		break;
   161 		
   162 	case ETCamCmdEnableSnapshot:
   163 		EnableSnapshotL();
   164 		break;
   165 		
   166 	case ETCamCmdDisableSnapshot:
   167 		DisableSnapshot();
   168 		break;
   169 	
   170 	case EEikCmdExit:
   171 		Exit();
   172 		break;
   173 		}
   174 	}
   175 
   176 void CTCamAppUi::ViewFinderL()
   177 	{
   178 	TSize imageSize;
   179 	iCamera->EnumerateCaptureSizes(imageSize,1,CCamera::EFormatFbsBitmapColor16M);
   180 	const TPoint pos = iAppView->DrawBorders(imageSize);
   181 	TRect screenRect(pos,imageSize);
   182 	TRect clipRect;
   183 
   184 	if (!iCamera->ViewFinderActive())
   185 		{
   186 		iCamera->StartViewFinderDirectL(iCoeEnv->WsSession(),*iCoeEnv->ScreenDevice(),*iAppView->DrawableWindow(),screenRect,clipRect);		
   187 		}
   188 	else
   189 		{
   190 		iCamera->StopViewFinder();
   191 		}
   192 	}
   193 
   194 void CTCamAppUi::BurstModeL()
   195 	{
   196 	if (!iCameraAdvSet)
   197 		{
   198 		User::Leave(KErrNotSupported);
   199 		}
   200 	
   201 	if(CCamera::CCameraAdvancedSettings::EDriveModeBurst & iCameraAdvSet->SupportedDriveModes() )
   202 		{
   203 		iCameraAdvSet->SetDriveMode(CCamera::CCameraAdvancedSettings::EDriveModeBurst);
   204 		}
   205 	else
   206 		{
   207 		User::Leave(KErrNotSupported);	
   208 		}
   209 	}
   210 	
   211 void CTCamAppUi::EnableSnapshotL()
   212 	{
   213 	if(!iCameraSnapshot->IsSnapshotActive())
   214 		{
   215 		TSize size;
   216 		iCamera->EnumerateCaptureSizes(size,1,CCamera::EFormatFbsBitmapColor16M);
   217 		if(iCameraSnapshot->SupportedFormats() & CCamera::EFormatFbsBitmapColor4K)
   218 			{
   219 			iCameraSnapshot->PrepareSnapshotL(CCamera::EFormatFbsBitmapColor4K, TPoint(0,0), size, KRgbWhite, EFalse);
   220 			iCameraSnapshot->StartSnapshot();
   221 			}
   222 		}
   223 	}
   224 	
   225 void CTCamAppUi::DisableSnapshot()
   226 	{
   227 	if(iCameraSnapshot->IsSnapshotActive())
   228 		{
   229 		iCameraSnapshot->StopSnapshot();
   230 		}
   231 	}
   232 	
   233 void CTCamAppUi::SingleShotL()
   234 	{
   235 	if (!iCameraAdvSet)
   236 		{
   237 		User::Leave(KErrNotSupported);
   238 		}
   239 	
   240 	if(CCamera::CCameraAdvancedSettings::EDriveModeSingleShot & iCameraAdvSet->SupportedDriveModes() )
   241 		{
   242 		iCameraAdvSet->SetDriveMode(CCamera::CCameraAdvancedSettings::EDriveModeSingleShot);
   243 		}
   244 	else
   245 		{
   246 		User::Leave(KErrNotSupported);	
   247 		}
   248 	}
   249 
   250 void CTCamAppUi::CaptureImageL()
   251 	{
   252 	TSize size;
   253 	iCamera->EnumerateCaptureSizes(size,1,CCamera::EFormatFbsBitmapColor16M);
   254 	iCamera->PrepareImageCaptureL(CCamera::EFormatFbsBitmapColor16M,1);
   255 	iCamera->CaptureImage();
   256 	}
   257 
   258 void CTCamAppUi::CaptureVideoL()
   259 	{
   260 	if (!iCamera->VideoCaptureActive())
   261 		{
   262 		iCameraSnapshot->StopSnapshot();
   263 		
   264 		TSize size;
   265 		TReal32 rate = 0;
   266 		iCamera->EnumerateVideoFrameSizes(size,0,CCamera::EFormatFbsBitmapColor16M);
   267 		iCamera->EnumerateVideoFrameRates(rate,0,CCamera::EFormatFbsBitmapColor16M,0);
   268 		iCamera->PrepareVideoCaptureL(CCamera::EFormatFbsBitmapColor16M,0,0,2,1);
   269 		iCamera->StartVideoCapture();
   270 		}
   271 	else
   272 		{
   273 		iCamera->StopVideoCapture();
   274 		}	
   275 	}
   276 	
   277 void CTCamAppUi::IncImgProcAdjustmentL(TUid aTransformation)
   278 	{
   279 	if(!iCameraImgProc)	
   280 		{
   281 		User::Leave(KErrNotSupported);
   282 		}
   283 	
   284 	RArray<TUid> supportedTransformations;
   285 	CleanupClosePushL(supportedTransformations);
   286 	iCameraImgProc->GetSupportedTransformationsL(supportedTransformations);
   287 	
   288 	TInt error = supportedTransformations.Find(aTransformation);
   289 	CleanupStack::PopAndDestroy(); 
   290 
   291 	if(error == KErrNotFound)
   292 		{
   293 		User::Leave(error);
   294 		}
   295 		
   296 	TInt valuetx;
   297 	User::LeaveIfError(iCameraImgProc->GetTransformationValue(aTransformation, valuetx));
   298 	
   299 	iCameraImgProc->SetTransformationValue(aTransformation, valuetx + 10);
   300 	}
   301 	
   302 void CTCamAppUi::DecImgProcAdjustmentL(TUid aTransformation)
   303 	{
   304 	if(!iCameraImgProc)	
   305 		{
   306 		User::Leave(KErrNotSupported);
   307 		}
   308 	
   309 	RArray<TUid> supportedTransformations;
   310 	CleanupClosePushL(supportedTransformations);
   311 	iCameraImgProc->GetSupportedTransformationsL(supportedTransformations);
   312 	
   313 	TInt error = supportedTransformations.Find(aTransformation);
   314 	CleanupStack::PopAndDestroy(); 
   315 
   316 	if(error == KErrNotFound)
   317 		{
   318 		User::Leave(error);
   319 		}
   320 		
   321 	TInt valuetx;
   322 	User::LeaveIfError(iCameraImgProc->GetTransformationValue(aTransformation, valuetx));
   323 	
   324 	iCameraImgProc->SetTransformationValue(aTransformation, valuetx - 10);
   325 	}
   326 	
   327 void CTCamAppUi::ReserveComplete(TInt /*aError*/)
   328 	{
   329 	}
   330 
   331 void CTCamAppUi::PowerOnComplete(TInt /*aError*/)
   332 	{
   333 	}
   334 
   335 void CTCamAppUi::ViewFinderFrameReady(CFbsBitmap& /*aFrame*/)
   336 	{
   337 	}
   338 
   339 void CTCamAppUi::ImageReady(CFbsBitmap* aBitmap,HBufC8* /*aData*/,TInt aError)
   340 	{
   341 	TBuf<KMaxErrLength> msgBuffer;
   342 	_LIT(KErrMessage,"CTCamAppUi::ImageReady");
   343 	if (aBitmap)
   344 		{
   345 		iAppView->DrawImage(aBitmap);
   346 		delete aBitmap;
   347 		}
   348 	if (aError)
   349 		{
   350 		msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
   351 		iEikonEnv->InfoMsg(msgBuffer);
   352 		}
   353 	}
   354 
   355 void CTCamAppUi::FrameBufferReady(MFrameBuffer* aFrameBuffer,TInt aError)
   356 	{
   357 	TBuf<KMaxErrLength> msgBuffer;
   358 	_LIT(KErrMessage,"CTCamAppUi::FrameBufferReady");
   359 	if (aError)
   360 		{
   361 		msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
   362 		iEikonEnv->InfoMsg(msgBuffer);
   363 		return;
   364 		}
   365 	TRAPD(error,iAppView->DrawImage(aFrameBuffer->FrameL(0)));
   366 	aFrameBuffer->Release();
   367 	if (error)
   368 		{
   369 		msgBuffer.Format(KErrorFormat,error,&KErrMessage);
   370 		iEikonEnv->InfoMsg(msgBuffer);
   371 		}
   372 	}
   373 	
   374 void CTCamAppUi::HandleEvent(const TECAMEvent& aEvent)
   375 	{
   376 	if(!TECAMEvent2::IsEventEncapsulationValid(aEvent))
   377 		{
   378 		HandleEvent1(aEvent);
   379 		}
   380 	else
   381 		{
   382 		HandleEvent2(static_cast<const TECAMEvent2&>(aEvent));
   383 		}
   384 	}
   385 	
   386 void CTCamAppUi::HandleEvent2(const TECAMEvent2& /*aEvent2*/)
   387 	{
   388 	
   389 	}
   390 	
   391 void CTCamAppUi::HandleEvent1(const TECAMEvent& aEvent)
   392 	{
   393 	TBuf<KMaxErrLength> msgBuffer;
   394 	
   395 	switch(aEvent.iEventType.iUid)
   396 		{
   397 		case KUidECamEventCameraSettingDriveModeUidValue:
   398 			{
   399 			if(!aEvent.iErrorCode)
   400 				{
   401 				TRAPD(error,CaptureImageL());	
   402 				if(error)
   403 					{
   404 					_LIT(KErrMessage,"CaptureImage");
   405 					msgBuffer.Format(KErrorFormat,error,&KErrMessage);
   406 					iEikonEnv->InfoMsg(msgBuffer);
   407 					}
   408 				}
   409 			else
   410 				{
   411 				_LIT(KErrMessage,"SettingDriveMode");
   412 				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
   413 				iEikonEnv->InfoMsg(msgBuffer);
   414 				}
   415 			break;
   416 			}
   417 		case KUidECamEventBurstImagesUidValue:
   418 			{
   419 			if(aEvent.iErrorCode)
   420 				{
   421 				_LIT(KErrMessage,"SettingNumOfBurstImage");
   422 				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
   423 				iEikonEnv->InfoMsg(msgBuffer);
   424 				}	
   425 			break;	
   426 			}
   427 		case KUidECamEventSnapshotUidValue:
   428 			{
   429 			if(aEvent.iErrorCode)
   430 				{
   431 				_LIT(KErrMessage,"SnapshotDataNotification");
   432 				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
   433 				iEikonEnv->InfoMsg(msgBuffer);
   434 				}
   435 			else
   436 				{
   437 				if(iCamera->ViewFinderActive())
   438 					{	
   439 					iCamera->StopViewFinder();
   440 					}
   441 			
   442 				TRAPD(error, SnapshotDataDisplayL());
   443 
   444 				if(error != KErrNone)
   445 					{
   446 					_LIT(KErrMessage,"SnapshotDataDisplay");
   447 					msgBuffer.Format(KErrorFormat,error,&KErrMessage);
   448 					iEikonEnv->InfoMsg(msgBuffer);
   449 					}
   450 				}
   451 			break;
   452 			}
   453 			
   454 		case KUidECamPresetFactoryDefaultUidValue:
   455 			{
   456 			if(aEvent.iErrorCode)
   457 				{
   458 				_LIT(KErrMessage,"FactoryPreset");
   459 				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
   460 				iEikonEnv->InfoMsg(msgBuffer);
   461 				}
   462 			break;
   463 			}
   464 			
   465 		case KUidECamPresetOutdoorUidValue:
   466 			{
   467 			if(aEvent.iErrorCode)
   468 				{
   469 				_LIT(KErrMessage,"OutdoorPreset");
   470 				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
   471 				iEikonEnv->InfoMsg(msgBuffer);
   472 				}
   473 			break;
   474 			}
   475 			
   476 		case KUidECamPresetOutdoorSportUidValue:
   477 			{
   478 			if(aEvent.iErrorCode)
   479 				{
   480 				_LIT(KErrMessage,"OutdoorSportPreset");
   481 				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
   482 				iEikonEnv->InfoMsg(msgBuffer);
   483 				}
   484 			break;
   485 			}
   486 			
   487 		case KUidECamPresetFogUidValue:
   488 			{
   489 			if(aEvent.iErrorCode)
   490 				{
   491 				_LIT(KErrMessage,"FogPreset");
   492 				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
   493 				iEikonEnv->InfoMsg(msgBuffer);
   494 				}
   495 			break;
   496 			}
   497 			
   498 		case KUidECamPresetNightPartyIndoorUidValue:
   499 			{
   500 			if(aEvent.iErrorCode)
   501 				{
   502 				_LIT(KErrMessage,"NightPartyIndoorPreset");
   503 				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
   504 				iEikonEnv->InfoMsg(msgBuffer);
   505 				}
   506 			break;
   507 			}
   508 			
   509 		case KUidECamPresetTextDocumentUidValue:
   510 			{
   511 			if(aEvent.iErrorCode)
   512 				{
   513 				_LIT(KErrMessage,"TextDocumentPreset");
   514 				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
   515 				iEikonEnv->InfoMsg(msgBuffer);
   516 				}
   517 			break;
   518 			}
   519 		
   520 		case KUidECamEventImageProcessingAdjustBrightnessUidValue:
   521 			{
   522 			if(aEvent.iErrorCode)
   523 				{
   524 				_LIT(KErrMessage,"ImageProcessingAdjustBrightness");
   525 				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
   526 				iEikonEnv->InfoMsg(msgBuffer);
   527 				}
   528 			break;
   529 			}
   530 			
   531 		case KUidECamEventImageProcessingAdjustContrastUidValue:
   532 			{
   533 			if(aEvent.iErrorCode)
   534 				{
   535 				_LIT(KErrMessage,"ImageProcessingAdjustContrast");
   536 				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
   537 				iEikonEnv->InfoMsg(msgBuffer);
   538 				}
   539 			break;
   540 			}
   541 					
   542 		default:
   543 			break;
   544 		}
   545 	}
   546 	
   547 void CTCamAppUi::ViewFinderReady(MCameraBuffer& /*aCameraBuffer*/,TInt /*aError*/)
   548 	{
   549 	
   550 	}
   551 	
   552 void CTCamAppUi::ImageBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
   553 	{
   554 	TBuf<KMaxErrLength> msgBuffer;
   555 	_LIT(KErrMessage,"CTCamAppUi::ImageBufferReady");
   556 	if(aError)
   557 		{
   558 		msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
   559 		iEikonEnv->InfoMsg(msgBuffer);
   560 		return;
   561 		}
   562 	if(!iCameraSnapshot->IsSnapshotActive())
   563 		{
   564 		if (iCamera->ViewFinderActive())
   565 			{	
   566 			iCamera->StopViewFinder();
   567 			}
   568 		TRAP(aError,iAppView->DrawImage(&aCameraBuffer.BitmapL(0)));		
   569 		}
   570 
   571 	aCameraBuffer.Release();
   572 	
   573 	if (aError)
   574 		{
   575 		msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
   576 		iEikonEnv->InfoMsg(msgBuffer);
   577 		}
   578 		
   579 	}
   580 	
   581 void CTCamAppUi::VideoBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
   582 	{
   583 	TBuf<KMaxErrLength> msgBuffer;
   584 	_LIT(KErrMessage,"CTCamAppUi::FrameBufferReady");
   585 	if (aError)
   586 		{
   587 		msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
   588 		iEikonEnv->InfoMsg(msgBuffer);
   589 		return;
   590 		}
   591 	TRAPD(error,iAppView->DrawImage(&aCameraBuffer.BitmapL(0)));
   592 	aCameraBuffer.Release();
   593 	if (error)
   594 		{
   595 		msgBuffer.Format(KErrorFormat,error,&KErrMessage);
   596 		iEikonEnv->InfoMsg(msgBuffer);
   597 		}		
   598 	}
   599 	
   600 void CTCamAppUi::SnapshotDataDisplayL()
   601 	{
   602 	RArray<TInt> array;
   603 	array.Reset();
   604 	RTestCameraFrameBuffer& buffer = static_cast<RTestCameraFrameBuffer&>(iCameraSnapshot->SnapshotDataL(array));
   605 	iAppView->DrawImage(&buffer.BitmapL(0));
   606 	array.Close();
   607 	buffer.Release();
   608 	}	
   609 
   610 void CTCamAppUi::CreateDependencyFileL()
   611 	{
   612 	// enforce dependency
   613 	// create the file the plugin depends on.
   614 	User::LeaveIfError(ifsSession.Connect());
   615 	RFile file;
   616 	TInt err = file.Replace(ifsSession, KTestCameraPluginName, EFileShareAny);
   617   	file.Close();
   618   	if(err != KErrNone)
   619   		{
   620 	    User::LeaveIfError(KErrNotSupported);
   621   		}
   622 	}
   623 	
   624 void CTCamAppUi::RemoveDependencyFile()
   625 	{
   626 	ifsSession.Delete(KTestCameraPluginName);
   627 	ifsSession.Close();
   628 	}
   629 
   630 //
   631 // CTCamAppView
   632 //
   633 
   634 CTCamAppView::CTCamAppView():
   635 	CCoeControl()
   636 	{
   637 	}
   638 
   639 void CTCamAppView::ConstructL(const TRect& /*aRect*/)
   640 	{
   641 	CreateWindowL();
   642 	EnableDragEvents();
   643 	SetExtentToWholeScreen();
   644 	ActivateL();
   645 	}
   646 
   647 CTCamAppView::~CTCamAppView()
   648 	{
   649 	}
   650 
   651 void CTCamAppView::DrawImage(CFbsBitmap* aImage) const
   652 	{
   653 	CWindowGc& gc = SystemGc();
   654 	gc.Activate(Window());
   655 	TRect drawRect=Rect();
   656 	TPoint pos;
   657 	pos.iX = (3 * drawRect.iBr.iX / 4) - (aImage->SizeInPixels().iWidth / 2);
   658 	pos.iY = (drawRect.iBr.iY - aImage->SizeInPixels().iWidth) / 2;
   659 	gc.BitBlt(pos,aImage);
   660 	TRect border(pos,aImage->SizeInPixels());
   661 	border.Grow(1,1);
   662 	gc.DrawRect(border);
   663 	gc.Deactivate();
   664 	iCoeEnv->WsSession().Flush();
   665 	}
   666 
   667 void CTCamAppView::Draw(const TRect& /*aRect*/) const
   668 	{
   669 	CWindowGc& gc = SystemGc();
   670 	TRect drawRect(Rect());
   671 	drawRect.Shrink(1,1);
   672 	gc.DrawRect(drawRect);
   673 	gc.Clear();
   674 	}
   675 
   676 TPoint CTCamAppView::DrawBorders(const TSize& aSize) const
   677 	{
   678 	CWindowGc& gc = SystemGc();
   679 	gc.Activate(Window());
   680 	TRect drawRect(Rect());
   681 	TPoint pos;
   682 	pos.iX = (drawRect.iBr.iX / 4) - (aSize.iWidth / 2);
   683 	pos.iY = (drawRect.iBr.iY - aSize.iWidth) / 2;
   684 	TRect border(pos,aSize);
   685 	border.Grow(1,1);
   686 	gc.SetPenColor(KRgbBlack);
   687 	gc.DrawRect(border);
   688 	gc.Deactivate();
   689 	iCoeEnv->WsSession().Flush();
   690 	return pos;
   691 	}
   692 
   693 //
   694 // CTCamDocument
   695 //
   696 
   697 CTCamDocument::CTCamDocument(CEikApplication& aApp)
   698 		: CEikDocument(aApp)
   699 	{
   700 	}
   701 
   702 CEikAppUi* CTCamDocument::CreateAppUiL()
   703 	{
   704     return new(ELeave) CTCamAppUi;
   705 	}
   706 
   707 //
   708 // CTCamApp
   709 //
   710 
   711 TUid CTCamApp::AppDllUid() const
   712 	{
   713 	return KUidTestCameraApp;
   714 	}
   715 
   716 CApaDocument* CTCamApp::CreateDocumentL()
   717 	{
   718 	return new(ELeave) CTCamDocument(*this);
   719 	}
   720 
   721 
   722 
   723 //
   724 // Base factory function
   725 //
   726 
   727 #include <eikstart.h>
   728 LOCAL_C CApaApplication* NewApplication()
   729 	{
   730 	return new CTCamApp;
   731 	}
   732 
   733 //
   734 // EXE Entry point
   735 //
   736 
   737 GLDEF_C TInt E32Main()
   738 	{
   739 	return EikStart::RunApplication(NewApplication);
   740 	}
   741 
   742 
   743 
   744