examples/ForumNokia/ImageConverter/src/ImageConverterContainer.cpp

00001 /*
00002  * Copyright © 2008 Nokia Corporation.
00003  */
00004 
00005 
00006 // INCLUDE FILES
00007 #include "ImageConverterContainer.h"
00008 #include "ImageConverterAppUi.h"
00009 
00010 #include <eiklabel.h>  // for example label control
00011 #include <aknutils.h>  // for scalable UI
00012 #include <eikdef.h>
00013 #include <eikenv.h>
00014 #include <e32cmn.h>
00015 
00016 // ================= MEMBER FUNCTIONS =======================
00017 
00018 // ---------------------------------------------------------
00019 // CImageConverterContainer::ConstructL(const TRect& aRect)
00020 // EPOC two phased constructor
00021 // ---------------------------------------------------------
00022 //
00023 void CImageConverterContainer::ConstructL(const TRect& /*aRect*/)
00024     {
00025     iAppUi = (static_cast<CImageConverterAppUi*>(iEikonEnv->AppUi()));
00026 
00027     CreateWindowL();
00028 
00029     EnableDragEvents();
00030     
00031     #ifdef __TUI_SUPPORTED__    
00032     iTouchFeedBack = MTouchFeedback::Instance();
00033     iTouchFeedBack->SetFeedbackEnabledForThisApp(ETrue);
00034     iLongTapDetector = CAknLongTapDetector::NewL(this);
00035     #endif
00036     
00037     // Create font
00038     _LIT( KSeries60SansB, "Series 60 SansB" );
00039     TFontSpec fontSpec( KSeries60SansB, 90 );
00040     fontSpec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
00041     User::LeaveIfError(iEikonEnv->ScreenDevice()->GetNearestFontInTwips( iFont, fontSpec ));
00042 
00043     TFontSpec fontSpec2( KSeries60SansB, 120 );
00044     fontSpec2.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
00045     User::LeaveIfError(iEikonEnv->ScreenDevice()->GetNearestFontInTwips( iCbaFont, fontSpec2 ));
00046     
00047     SetExtentToWholeScreen();
00048     ActivateL();
00049     }
00050 
00051 // Destructor
00052 CImageConverterContainer::~CImageConverterContainer()
00053     {
00054     iDragPoints.Close();
00055     delete iPeriodic;
00056     
00057     ReleaseBackBuffer();
00058 
00059     #ifdef __TUI_SUPPORTED__
00060     delete iLongTapDetector;
00061     #endif
00062 
00063     // Release font
00064     iEikonEnv->ScreenDevice()->ReleaseFont(iFont);
00065     iEikonEnv->ScreenDevice()->ReleaseFont(iCbaFont);
00066     }
00067 
00068 // ---------------------------------------------------------
00069 // CImageConverterContainer::SizeChanged()
00070 // Called by framework when the view size is changed
00071 // ---------------------------------------------------------
00072 //
00073 void CImageConverterContainer::SizeChanged()
00074     {
00075     // Delete back buffer and create a new one with new size
00076     ReleaseBackBuffer();
00077     CreateBackBufferL();
00078     SetPictureScreenCenter(ETrue);
00079     }
00080 
00081 // ---------------------------------------------------------
00082 // CImageConverterContainer::HandleResourceChange()
00083 // Called by framework when resource is changed.
00084 // ---------------------------------------------------------
00085 //
00086 void CImageConverterContainer::HandleResourceChange(TInt aType)
00087     {
00088     CCoeControl::HandleResourceChange(aType);
00089     if ( aType==KEikDynamicLayoutVariantSwitch )
00090         {
00091         SetExtentToWholeScreen();
00092         }
00093     }
00094 
00095 // ---------------------------------------------------------
00096 // CImageConverterContainer::CountComponentControls() const
00097 // ---------------------------------------------------------
00098 //
00099 TInt CImageConverterContainer::CountComponentControls() const
00100     {
00101     return 0; // return nbr of controls inside this container
00102     }
00103 
00104 // ---------------------------------------------------------
00105 // CImageConverterContainer::ComponentControl(TInt aIndex) const
00106 // ---------------------------------------------------------
00107 //
00108 CCoeControl* CImageConverterContainer::ComponentControl(TInt /*aIndex*/) const
00109     {
00110     return NULL;
00111     }
00112 
00113 // ---------------------------------------------------------
00114 // CImageConverterContainer::Draw(const TRect& aRect) const
00115 // ---------------------------------------------------------
00116 //
00117 void CImageConverterContainer::Draw(const TRect& /*aRect*/) const
00118     {
00119     CWindowGc& gc = SystemGc();
00120     
00121     // Copy backbuffer into the screen
00122     gc.BitBlt(TPoint(0, 0), iBackBuffer);
00123     }
00124 
00125 // ---------------------------------------------------------
00126 // CImageConverterContainer::HandleControlEventL(
00127 //     CCoeControl* aControl,TCoeEvent aEventType)
00128 // ---------------------------------------------------------
00129 //
00130 void CImageConverterContainer::HandleControlEventL(
00131     CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
00132     {
00133     }
00134 
00135 
00136 // ---------------------------------------------------------
00137 // CImageConverterContainer::SetBitmap(CFbsBitmap* aBitmap)
00138 // ---------------------------------------------------------
00139 //
00140 void CImageConverterContainer::SetBitmap(CFbsBitmap* aBitmap)
00141     {
00142     iBitmap = aBitmap;
00143 
00144     if (iBitmap)
00145         {
00146         // Set picture first to screen center
00147         SetPictureScreenCenter(EFalse);
00148 
00149         // If this picture is animated and comes from right or left
00150         if (iAnimationEvent != ENoAnimation)
00151             {
00152             iNextAnimationWaiting = ETrue;
00153             StartNewPictureAnimate();
00154             }
00155         }
00156     }
00157 
00158 #ifdef __TUI_SUPPORTED__
00159 void CImageConverterContainer::HandlePointerEventL(const TPointerEvent& aPointerEvent)
00160     {
00161     iLongTapDetector->PointerEventL(aPointerEvent);
00162     
00163     if (aPointerEvent.iType == TPointerEvent::EButton1Down)
00164         {
00165         iDragPoints.Reset();
00166         // Start dragging
00167         iDragPoints.Append(aPointerEvent.iPosition);
00168         // Give feedback to user (vibration)
00169         iTouchFeedBack->InstantFeedback(ETouchFeedbackBasic);
00170         }
00171     else if (aPointerEvent.iType == TPointerEvent::EDrag)
00172         {
00173         // Dragging...
00174         // If long tap detection is running user is moving picture location then
00175         // we do not have to store pointer positions
00176         if (!iLongTapDetected)
00177             {
00178             iDragPoints.Append(aPointerEvent.iPosition);
00179             }
00180         else
00181             {
00182             // Long tap detection is activated so user is moving the picture
00183             MovePicture(aPointerEvent.iPosition);
00184             }
00185         }
00186     else if (aPointerEvent.iType == TPointerEvent::EButton1Up)
00187         {
00188         // Long tap detection ends when pen is released (EButton1Up)
00189         if (iLongTapDetected)
00190             {
00191             // If long tap detection is running user is moving picture location then
00192             // we do not have to handle pointer positions
00193             iLongTapDetected = EFalse;
00194             return;
00195             }
00196         
00197         // Check CBA buttons
00198         if (iOptionsRect.Contains(aPointerEvent.iPosition))
00199             {
00200             iEikonEnv->AppUiFactory()->MenuBar()->TryDisplayMenuBarL();
00201             return;
00202             }
00203         else if (iExitRect.Contains(aPointerEvent.iPosition))
00204             {
00205             iAppUi->HandleCommandL(EEikCmdExit);
00206             return;
00207             }
00208         
00209         // Dragging stops
00210         iDragPoints.Append(aPointerEvent.iPosition);
00211 
00212         // Clear pointer event
00213         iPointerEvent = ENoValidPointerEvent;
00214 
00215         // Check user pointer event, how user move pointer
00216         if (iDragPoints.Count() > KMIN_POINTER_COUNT)
00217             {
00218             if (!IsZooming())
00219                 {
00220                 if (!IsChangingPicture())
00221                     {
00222                     if (!IsRotate())
00223                         {
00224                         // Did not found anything
00225                         return;
00226                         }
00227                     }
00228                 }
00229             }
00230         // Do first animation and then event
00231         if (iAnimationEvent != ENoAnimation)
00232             {
00233             // Changing picture
00234             // appUI->DoEvent() is called when current picture animation ends
00235             }
00236         // Do event only (no animation)
00237         else if (iPointerEvent != ENoValidPointerEvent && iAnimationEvent == ENoAnimation)
00238             {
00239             DrawToBackBuffer();
00240             DrawNow();
00241             iAppUi->DoEvent(iPointerEvent);
00242             }
00243         }
00244     }
00245 #endif
00246 
00247 void CImageConverterContainer::ResetTitleText(TBool aDrawNow)
00248     {
00249     iStateInfo.Zero();
00250     if (aDrawNow)
00251         {
00252         DrawToBackBuffer();
00253         DrawNow();
00254         }
00255     }
00256 
00257 
00258 void CImageConverterContainer::SetTitleText(ETitleState aState, TBool aDrawNow)
00259     {
00260     iStateInfo.Zero();
00261 
00262     iTitleState = aState;
00263     
00264     switch (iTitleState)
00265         {
00266         case ETitleNextImage:
00267             {
00268             iStateInfo.Copy(_L("Next"));
00269             break;
00270             }
00271         case ETitlePrevImage:
00272             {
00273             iStateInfo.Copy(_L("Previous"));
00274             break;
00275             }
00276         case ETitleZoomIn:
00277         case ETitleZoomOut:
00278             {
00279             iStateInfo.Copy(_L("Scaled"));
00280             break;
00281             }
00282         case ETitleRotateRight:
00283         case ETitleRotateLeft:
00284             {
00285             iStateInfo.Copy(_L("Rotated"));
00286             break;
00287             }
00288         default:
00289             {
00290             break;
00291             }
00292         }
00293     if (aDrawNow)
00294         {
00295         DrawToBackBuffer();
00296         DrawNow();
00297         }
00298     }
00299 
00300 
00301 TBool CImageConverterContainer::IsZooming()
00302     {
00303     TPoint firstPoint;
00304     TPoint lastPoint;
00305     firstPoint = iDragPoints[0];
00306     lastPoint = iDragPoints[iDragPoints.Count()-1];
00307 
00308     // Max difference 33%
00309     TInt max_x_difference = Abs(firstPoint.iY - lastPoint.iY) / 3;
00310     
00311     // Is line straight?
00312     // Goes all points throught and finds is some over max_x_difference
00313     // if found this is not anymore vertical line
00314     for (TInt i=1;i<iDragPoints.Count();i++)
00315         {
00316         TPoint point = iDragPoints[i];
00317         TInt value = Abs(point.iX - firstPoint.iX);
00318         if (value > max_x_difference)
00319             {
00320             return EFalse;
00321             }
00322         }
00323 
00324     // Is direction up or down?
00325     lastPoint = iDragPoints[iDragPoints.Count()-1];
00326     if (firstPoint.iY > lastPoint.iY)
00327         {
00328         iPointerEvent = EZoomIn;
00329         }
00330     else
00331         {
00332         iPointerEvent = EZoomOut;
00333         }
00334     return ETrue;
00335     }
00336 
00337 
00338 
00339 TBool CImageConverterContainer::IsChangingPicture()
00340     {
00341     TPoint firstPoint;
00342     TPoint lastPoint;
00343     firstPoint = iDragPoints[0];
00344     lastPoint = iDragPoints[iDragPoints.Count()-1];
00345 
00346     // Max difference 33%
00347     TInt max_y_difference = Abs(firstPoint.iX - lastPoint.iX) / 3;
00348     
00349     // Is line straight?
00350     // Goes all points throught and finds is some over max_y_difference
00351     // if found this is not anymore horizontal line
00352     for (TInt i=1;i<iDragPoints.Count();i++)
00353         {
00354         TPoint point = iDragPoints[i];
00355         TInt value = Abs(point.iY - firstPoint.iY);
00356         if (value > max_y_difference)
00357             {
00358             return EFalse;
00359             }
00360         }
00361 
00362     // Is direction right or left?
00363     lastPoint = iDragPoints[iDragPoints.Count()-1];
00364     if (firstPoint.iX > lastPoint.iX)
00365         {
00366         iPointerEvent = ENextImage;
00367         iAnimationEvent = EAnimateToLeft;
00368         }
00369     else
00370         {
00371         iPointerEvent = EPrevImage;
00372         iAnimationEvent = EAnimateToRight;
00373         }
00374 
00375     StartAnimateL();
00376     return ETrue;
00377     }
00378 
00379 void CImageConverterContainer::ChangeNextPictureL()
00380     {
00381     iAnimationEvent = EAnimateToLeft;
00382     iPointerEvent = ENextImage;
00383     StartAnimateL();
00384     }
00385 
00386 void CImageConverterContainer::ChangePrevPictureL()
00387     {
00388     iAnimationEvent = EAnimateToRight;
00389     iPointerEvent = EPrevImage;
00390     StartAnimateL();
00391     }
00392 
00393 TPoint CImageConverterContainer::FindCenterPointInRotate(TPoint& aFirstPoint)
00394     {
00395     TPoint center;
00396     TInt  farist(0);
00397 
00398     for (TInt i=0;i<iDragPoints.Count();i++)
00399         {
00400         TPoint point = iDragPoints[i];
00401         TInt value = Abs(point.iX - aFirstPoint.iX);
00402         if (value > farist)
00403             {
00404             farist = value;
00405             center = point;
00406             }
00407         }
00408     
00409     return center;
00410     }
00411 
00412 void CImageConverterContainer::FindPointsForRotate(TPoint& aTopPoint, 
00413         TPoint& aCenterPoint, TPoint& aBottomPoint, TBool& aDrawDirectionIsFromTop)
00414     {
00415     aTopPoint = TPoint(Size().iWidth/2,Size().iHeight);
00416     aBottomPoint = TPoint(Size().iWidth/2,0);
00417     TInt topIndex=0;
00418     TInt bottomIndex=0;
00419 
00420     // Find top and bottom points
00421     for (TInt i=0;i<iDragPoints.Count();i++)
00422         {
00423         if (aTopPoint.iY > iDragPoints[i].iY)
00424             {
00425             aTopPoint = iDragPoints[i];
00426             topIndex = i;
00427             }
00428         if (aBottomPoint.iY < iDragPoints[i].iY)
00429             {
00430             aBottomPoint = iDragPoints[i];
00431             bottomIndex = i;
00432             }
00433         }
00434     
00435     // Find center point
00436     aCenterPoint = FindCenterPointInRotate(aTopPoint);
00437     
00438     // Is direction to left or right?
00439     if (topIndex < bottomIndex)
00440         {
00441         aDrawDirectionIsFromTop = ETrue;
00442         }
00443     else
00444         {
00445         aDrawDirectionIsFromTop = EFalse;
00446         }
00447     }
00448 
00449 
00450 TBool CImageConverterContainer::IsRotate()
00451     {
00452     TPoint firstPoint;
00453     TPoint centerPoint;
00454     TPoint lastPoint;
00455     TBool drawFromTop;
00456     
00457     // Find points locations (top, bottom, center(left/right))
00458     FindPointsForRotate(firstPoint,centerPoint,lastPoint,drawFromTop);
00459     
00460     // Max difference is height of the drawed thing
00461     TInt height = Abs(firstPoint.iY - lastPoint.iY);
00462     
00463     // Start and end point x difference can not be more than
00464     // height of the whole thing
00465     TInt xSE = Abs(firstPoint.iX - lastPoint.iX);
00466     if (xSE > height)
00467         {
00468         return EFalse;
00469         }
00470     
00471     // Check center point in x-axel
00472     TInt maxXcenterLine = Max(Abs(firstPoint.iX-centerPoint.iX),Abs(lastPoint.iX-centerPoint.iX));
00473     // Must draw to right or left at least 33% from height
00474     if (maxXcenterLine < height / 3) // 33%
00475         {
00476         return EFalse;
00477         }
00478     
00479     // Rotate to left or right?
00480     if (centerPoint.iX < firstPoint.iX)
00481         {
00482         // Left
00483         if (drawFromTop)
00484             {
00485             iPointerEvent = ERotateLeft;
00486             }
00487         else
00488             {
00489             iPointerEvent = ERotateRight;
00490             }
00491         }
00492     else
00493         {
00494         // Right
00495         if (drawFromTop)
00496             {
00497             iPointerEvent = ERotateRight;
00498             }
00499         else
00500             {
00501             iPointerEvent = ERotateLeft;
00502             }
00503         }
00504 
00505     return ETrue;
00506     }
00507 
00508 void CImageConverterContainer::StartAnimateL()
00509     {
00510     // Start animation timer, image is ready
00511     if (iAnimationEvent != ENoAnimation && iBitmap && !iAppUi->IsEngineBusy())
00512         {
00513         if (!iPeriodic)
00514             {
00515             iPeriodic = CPeriodic::NewL(CActive::EPriorityStandard);
00516             }
00517         if (iPeriodic)
00518             {
00519             iPeriodic->Cancel();
00520             }
00521 
00522         // Update title
00523         if (iAnimationEvent == EAnimateToLeft)
00524             {
00525             SetTitleText(ETitleNextImage,EFalse);
00526             }
00527         else if(iAnimationEvent == EAnimateToRight)
00528             {
00529             SetTitleText(ETitlePrevImage,EFalse);
00530             }
00531         
00532         
00533         if (iAnimationEvent == EAnimateToLeft  || iAnimationEvent == EAnimateToRight)
00534             {
00535             iAnimateX = 0;
00536             iPixelsToMove = 1;
00537             }
00538         else if (iAnimationEvent == EAnimateFromRight)
00539             {
00540             iAnimateX = 0;
00541             iPixelsToMove = (Size().iWidth - iBitmap->SizeInPixels().iWidth)/2 + iBitmap->SizeInPixels().iWidth;
00542             }
00543         else if (iAnimationEvent == EAnimateFromLeft)
00544             {
00545             iAnimateX = 0;
00546             iPixelsToMove = (Size().iWidth - iBitmap->SizeInPixels().iWidth)/2 + iBitmap->SizeInPixels().iWidth;
00547             }
00548         iPeriodic->Start(TTimeIntervalMicroSeconds32(0), DELAY, TCallBack(CImageConverterContainer::Animate, this));
00549         }
00550     // Engine is busy, there is image conversion or scaling ongoing, wait for these
00551     else if (iAppUi->IsEngineBusy())
00552         {
00553         if (!iPeriodic)
00554             {
00555             iPeriodic = CPeriodic::NewL(CActive::EPriorityStandard);
00556             }
00557         if (iPeriodic)
00558             {
00559             iPeriodic->Cancel();
00560             }
00561         iPeriodic->Start(SLEEP_DELAY, SLEEP_DELAY, TCallBack(CImageConverterContainer::Sleep, this));
00562         }
00563     // No image, no animation
00564     else if (!iAppUi->IsEngineBusy() && !iBitmap)
00565         {
00566         iAnimationEvent = ENoAnimation;
00567         StopAnimate();
00568         }
00569     }
00570 
00571 void CImageConverterContainer::StartNewPictureAnimate()
00572     {
00573     if (iNextAnimationWaiting)
00574         {
00575         iNextAnimationWaiting = EFalse;
00576         if (iAnimationEvent == EAnimateToLeft)
00577             {
00578             iAnimationEvent = EAnimateFromRight;
00579             }
00580         else if (iAnimationEvent == EAnimateToRight)
00581             {
00582             iAnimationEvent = EAnimateFromLeft;
00583             }
00584         
00585         if (iAnimationEvent == EAnimateFromRight)
00586             {
00587             iPicturePoint.iX = Size().iWidth;
00588             }
00589         else if (iAnimationEvent == EAnimateFromLeft)
00590             {
00591             iPicturePoint.iX = iBitmap->SizeInPixels().iWidth*-1;
00592             }
00593         
00594         StartAnimateL();
00595         }
00596     }
00597 
00598 TBool CImageConverterContainer::IsAnimating()
00599     {
00600     if (iPeriodic && iPeriodic->IsActive())
00601         {
00602         return ETrue;
00603         }
00604     else
00605         {
00606         return EFalse;
00607         }
00608     }
00609 
00610 void CImageConverterContainer::StopAnimate()
00611     {
00612     // Stop animation
00613     if (iPeriodic)
00614         {
00615         iPeriodic->Cancel();
00616         }
00617 
00618     // Call event now (animation is ended)
00619     iAppUi->DoEvent(iPointerEvent);
00620     // Clear pointer event
00621     iPointerEvent = ENoValidPointerEvent;
00622 
00623     // Set animation event to ENoAnimation after new picture is also animated
00624     if (iAnimationEvent == EAnimateFromRight || iAnimationEvent == EAnimateFromLeft)
00625         {
00626         iAnimationEvent = ENoAnimation;
00627         }
00628     
00629     if (iAnimationEvent==ENoAnimation)
00630         {
00631         ResetTitleText(EFalse);
00632         }
00633     }
00634 
00635 void CImageConverterContainer::SetNextAnimationWaiting(TBool aValue)
00636     {
00637     iNextAnimationWaiting = aValue;
00638     }
00639 
00640 TInt CImageConverterContainer::Animate(TAny* aObj)
00641     {
00642     static_cast<CImageConverterContainer*>(aObj)->DoFrame();
00643     return 1;
00644     }
00645 
00646 TInt CImageConverterContainer::Sleep(TAny* aObj)
00647     {
00648     static_cast<CImageConverterContainer*>(aObj)->SetNextAnimationWaiting(EFalse);
00649     static_cast<CImageConverterContainer*>(aObj)->StartAnimateL();
00650     return 0;
00651     }
00652 
00653 void CImageConverterContainer::SetPictureScreenCenter(TBool aDraw)
00654     {
00655     if (iBitmap)
00656         {
00657         iPicturePoint.SetXY((Size().iWidth - iBitmap->SizeInPixels().iWidth) / 2, (Size().iHeight - iBitmap->SizeInPixels().iHeight) / 2);
00658         if (aDraw)
00659             {
00660             DrawToBackBuffer();
00661             DrawNow();
00662             }
00663         }
00664     }
00665 
00666 void CImageConverterContainer::DoFrame()
00667     {
00668     if (iAnimationEvent == EAnimateToLeft)
00669         {
00670         if (iPicturePoint.iX < iBitmap->SizeInPixels().iWidth*-1)
00671             {
00672             StopAnimate();
00673             }
00674         else
00675             {
00676             iPixelsToMove = iPixelsToMove*2;
00677             iAnimateX = iAnimateX - iPixelsToMove;
00678             }
00679         }
00680     else if (iAnimationEvent == EAnimateToRight)
00681         {
00682         if (iPicturePoint.iX > Size().iWidth)
00683             {
00684             StopAnimate();
00685             }
00686         else
00687             {
00688             iPixelsToMove = iPixelsToMove*2;
00689             iAnimateX = iAnimateX + iPixelsToMove;
00690             }
00691         }
00692     else if (iAnimationEvent == EAnimateFromLeft)
00693         {
00694         // Stop animate if picture is about screen center
00695         iPixelsToMove = iPixelsToMove/2;
00696         iPixelsToMove++;
00697         TInt tmp = iPixelsToMove + iPicturePoint.iX;
00698         if (tmp >= (Size().iWidth - iBitmap->SizeInPixels().iWidth)/2)
00699             {
00700             StopAnimate();
00701             SetPictureScreenCenter(EFalse);
00702             }
00703         else
00704             {
00705             iAnimateX = iPixelsToMove;
00706             }
00707         }
00708     else if (iAnimationEvent == EAnimateFromRight)
00709         {
00710         // Stop animate if picture is about screen center
00711         iPixelsToMove = iPixelsToMove/2;
00712         iPixelsToMove++;
00713         TInt tmp = iPicturePoint.iX - iPixelsToMove;
00714         if (tmp <= (Size().iWidth - iBitmap->SizeInPixels().iWidth)/2)
00715             {
00716             StopAnimate();
00717             SetPictureScreenCenter(EFalse);
00718             }
00719         else
00720             {
00721             iAnimateX = iPixelsToMove*-1;
00722             }
00723         }
00724     else
00725         {
00726         StopAnimate();
00727         }
00728     
00729     DrawToBackBuffer();
00730     DrawNow();
00731     }
00732 
00733 #ifdef __TUI_SUPPORTED__
00734 void CImageConverterContainer::HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& /*aPenEventScreenLocation*/ )
00735     {
00736     iLongTapDetected = ETrue;
00737     iLongTapPoint.SetXY(-10,-10);
00738     MovePicture(aPenEventLocation);
00739     }
00740 
00741 void CImageConverterContainer::MovePicture(const TPoint& aPoint)
00742     {
00743     if (iLongTapPoint.iX == -10)
00744         {
00745         // First move received
00746         iLongTapPoint = aPoint;
00747         return;
00748         }
00749     TInt x = iLongTapPoint.iX - aPoint.iX;
00750     TInt y = iLongTapPoint.iY - aPoint.iY;
00751     iPicturePoint.iX = iPicturePoint.iX - x; 
00752     iPicturePoint.iY = iPicturePoint.iY - y; 
00753     iLongTapPoint = aPoint;
00754     DrawToBackBuffer();
00755     DrawNow();
00756     }
00757 #endif
00758 
00759 
00760 void CImageConverterContainer::CreateBackBufferL()
00761     {
00762     // create back buffer bitmap
00763     iBackBuffer = new (ELeave) CFbsBitmap;
00764     
00765     User::LeaveIfError( iBackBuffer->Create(Size(),
00766                         iEikonEnv->DefaultDisplayMode()));
00767     
00768     // create back buffer graphics context
00769     iBackBufferDevice = CFbsBitmapDevice::NewL(iBackBuffer);
00770     User::LeaveIfError(iBackBufferDevice->CreateContext(iBackBufferContext));
00771     iBackBufferContext->SetPenStyle(CGraphicsContext::ESolidPen);
00772     
00773     iBackBufferSize = iBackBuffer->SizeInPixels();
00774     }
00775 
00776 
00777 void CImageConverterContainer::ReleaseBackBuffer()
00778     {
00779     if (iBackBufferContext)
00780         {
00781         delete iBackBufferContext;
00782         iBackBufferContext = NULL;
00783         }
00784     if (iBackBufferDevice)
00785         {
00786         delete iBackBufferDevice;
00787         iBackBufferDevice = NULL;
00788         }
00789     if (iBackBuffer)
00790         {
00791         delete iBackBuffer;
00792         iBackBuffer = NULL;
00793         }
00794     iBackBufferSize = TSize(0, 0);
00795     }
00796 
00797 
00798 void CImageConverterContainer::DrawToBackBuffer()
00799     {
00800     if (!iBackBufferContext)
00801         {
00802         return;
00803         }
00804     iBackBufferContext->SetBrushColor(KRgbBlack);
00805     iBackBufferContext->Clear();
00806     
00807     TRgb color = KRgbWhite;
00808     color.SetAlpha(70);
00809     
00810     iBackBufferContext->SetPenColor(KRgbWhite);
00811     TInt textWidth = 0;
00812     
00813     TFileName filename;
00814 
00815     iBackBufferContext->UseFont(iFont);
00816 
00817     // Draw status text
00818     textWidth = iFont->TextWidthInPixels(iStateInfo);
00819     iBackBufferContext->DrawText(iStateInfo,TPoint((Size().iWidth-textWidth)/2,iFont->FontMaxHeight()+3));
00820     
00821     // Draw bitmap and picture counter and filename
00822     if (iBitmap)
00823         {
00824         if (iAnimationEvent != ENoAnimation)    
00825             {
00826             iPicturePoint.iX = iPicturePoint.iX + iAnimateX;
00827             iBackBufferContext->BitBlt(iPicturePoint, iBitmap);
00828             }
00829         else
00830             {
00831             iBackBufferContext->BitBlt(iPicturePoint, iBitmap);
00832             iBackBufferContext->SetPenColor(KRgbGray);
00833             iBackBufferContext->DrawRect(TRect(iPicturePoint.iX-3,
00834                                                iPicturePoint.iY-3,
00835                                                iPicturePoint.iX + iBitmap->SizeInPixels().iWidth + 3,
00836                                                iPicturePoint.iY + iBitmap->SizeInPixels().iHeight + 3));
00837 
00838             iBackBufferContext->SetPenColor(KRgbWhite);
00839 
00840             // Draw filename
00841             iAppUi->ImageName(filename);
00842             textWidth = iFont->TextWidthInPixels(filename);
00843             iBackBufferContext->DrawText(filename,TPoint(5,iFont->FontMaxHeight()+3));
00844 
00845             // Draw counter
00846             iPictureInfo.Zero();
00847             iPictureInfo.AppendNum(iAppUi->ImageIndex()+1);
00848             iPictureInfo.Append(_L(" of "));
00849             iPictureInfo.AppendNum(iAppUi->ImageCount());
00850             textWidth = iFont->TextWidthInPixels(iPictureInfo);
00851             iBackBufferContext->DrawText(iPictureInfo,TPoint(Size().iWidth-textWidth-5,iFont->FontMaxHeight()+3));
00852             }
00853         }
00854 
00855     // Draw round rect for filename and counter
00856     iBackBufferContext->SetBrushColor(color);
00857     iBackBufferContext->SetBrushStyle(CWindowGc::ESolidBrush);
00858     iBackBufferContext->DrawRoundRect(TRect(2,2,Size().iWidth-2,iFont->FontMaxHeight()+7),TSize(2,2));
00859     iBackBufferContext->SetBrushStyle(CWindowGc::ENullBrush);
00860 
00861 
00862     //Finding correct location for CBA and drawing them.
00863     //
00864     // Note that there is a known issue detected in the S60 5th Edition SDK v0.9. With an empty status pane,            
00865     // AknLayoutUtils::CbaLocation() does not return correct locations for CBA in 
00866     // the landscape orientation. This method has been tested to work fine on S60 3rd Edition and
00867     // 5th Edition devices.
00868 
00869     iBackBufferContext->UseFont(iCbaFont);
00870     iBackBufferContext->SetPenColor(KRgbGray);
00871     if (AknLayoutUtils::CbaLocation() == AknLayoutUtils::EAknCbaLocationRight)
00872         {
00873         // Landscape
00874         if (iAppUi->IsOptionsButtonOnTop())
00875             {
00876             // Options selection is on top (Nokia E90)
00877             // Draw menu item "Exit"
00878             iPictureInfo.Zero();
00879             iPictureInfo.Append(_L("Exit"));
00880             textWidth = iCbaFont->TextWidthInPixels(iPictureInfo);
00881             iBackBufferContext->DrawText(iPictureInfo,TPoint(Size().iWidth-textWidth-5,Size().iHeight-7));
00882             // Save exit rect for Touch
00883             iExitRect.SetRect(Size().iWidth-textWidth-30,Size().iHeight-30,Size().iWidth,Size().iHeight);
00884 
00885             // Draw menu item "Options"
00886             iPictureInfo.Zero();
00887             iPictureInfo.Append(_L("Options"));
00888             textWidth = iCbaFont->TextWidthInPixels(iPictureInfo);
00889             iBackBufferContext->DrawText(iPictureInfo,TPoint(Size().iWidth-textWidth-5,iCbaFont->FontMaxHeight()+30));
00890             // Save option rect for Touch
00891             iOptionsRect.SetRect(Size().iWidth-textWidth-30,iCbaFont->FontMaxHeight()+10,Size().iWidth,iCbaFont->FontMaxHeight()+40);
00892             }
00893         else
00894             {
00895             // Options selection is on bottom (Nokia N95)
00896             // Draw menu item "Options"
00897             iPictureInfo.Zero();
00898             iPictureInfo.Append(_L("Options"));
00899             textWidth = iCbaFont->TextWidthInPixels(iPictureInfo);
00900             iBackBufferContext->DrawText(iPictureInfo,TPoint(Size().iWidth-textWidth-5,Size().iHeight-7));
00901             // Save exit rect for Touch
00902             iOptionsRect.SetRect(Size().iWidth-textWidth-30,Size().iHeight-30,Size().iWidth,Size().iHeight);
00903 
00904             // Draw menu item "Exit"
00905             iPictureInfo.Zero();
00906             iPictureInfo.Append(_L("Exit"));
00907             textWidth = iCbaFont->TextWidthInPixels(iPictureInfo);
00908             iBackBufferContext->DrawText(iPictureInfo,TPoint(Size().iWidth-textWidth-5,iCbaFont->FontMaxHeight()+30));
00909             // Save option rect for Touch
00910             iExitRect.SetRect(Size().iWidth-textWidth-30,iCbaFont->FontMaxHeight()+10,Size().iWidth,iCbaFont->FontMaxHeight()+40);
00911             }
00912         }
00913     else if(AknLayoutUtils::CbaLocation() == AknLayoutUtils::EAknCbaLocationBottom)
00914         {
00915         // Portrait
00916         // Draw menu item "Options"
00917         iPictureInfo.Zero();
00918         iPictureInfo.Append(_L("Options"));
00919         textWidth = iCbaFont->TextWidthInPixels(iPictureInfo);
00920         iBackBufferContext->DrawText(iPictureInfo,TPoint(5,Size().iHeight-7));
00921         // Save option rect for Touch
00922         iOptionsRect.SetRect(0,Size().iHeight-30,textWidth+30,Size().iHeight);
00923         
00924         // Draw menu item "Exit"
00925         iPictureInfo.Zero();
00926         iPictureInfo.Append(_L("Exit"));
00927         textWidth = iCbaFont->TextWidthInPixels(iPictureInfo);
00928         iBackBufferContext->DrawText(iPictureInfo,TPoint(Size().iWidth-textWidth-5,Size().iHeight-7));
00929         // Save exit rect for Touch
00930         iExitRect.SetRect(Size().iWidth-textWidth-30,Size().iHeight-30,Size().iWidth,Size().iHeight);
00931         }
00932     
00933     }
00934 
00935 
00936 
00937 
00938 
00939 // End of File  

Generated by  doxygen 1.6.2