examples/ForumNokia/ImageConverter/src/ImageConverterContainer.cpp

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

Generated by  doxygen 1.6.2