photosgallery/viewframework/views/zoomview/src/glxzoommathsengine.cpp
changeset 0 4e91876724a2
child 18 bcb43dc84c44
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    Implementation of Zoom Maths engine
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //includes 
       
    20 #include "glxzoomeventhandler.h"
       
    21 #include "glxzoommathsengine.h"
       
    22 #include "glxzoomcontrol.h"
       
    23 
       
    24 // Includes for Logs
       
    25 #include <glxtracer.h>                      //  For Tracer
       
    26 #include <glxlog.h>                         //  For Log
       
    27 
       
    28 #define BORDER_HEIGHT (iBorderWidth.iHeight*(100-((newZoomRatio-iMinZoomRatio)*100/(iMaxZoomRatio-iMinZoomRatio))))/100
       
    29 #define BORDER_WIDTH (iBorderWidth.iWidth*(100-((newZoomRatio-iMinZoomRatio)*100/(iMaxZoomRatio-iMinZoomRatio))))/100
       
    30 // LOCAL CONSTANTS AND MACROS
       
    31 const TInt KGlxLargeImageMaximumZoomRatio   =   100     ;
       
    32 const TInt KGlxSmallImageMaximumZoomRatio   =   150     ;
       
    33 
       
    34 const TInt KGlxMinPanFactor                 =   1       ; // The min multiple of pixles to pan 
       
    35 const TInt KGlxPanInertiaFactor             =   10      ; 
       
    36 const TInt KGlxPanFactorUpdateMultiple      =   5       ; // The number of pan operations after which panning speed is increased by an order of magnitude 
       
    37 const TInt KGlxMaxPanUpdateMultiple         =   6       ;
       
    38 const TInt KGlxOrigin                       =   0       ;
       
    39 
       
    40 const TInt KGlxMinRelativeZoomPercent       =   85       ;
       
    41 const TInt KGlxMaxRelativeZoomPercent       =   115      ;
       
    42 
       
    43 const TInt KGlxZoomPanInc                   =   10      ; // Min number of pixels panned in one keypress. This value is incremented exponentially by multiples of iPanFactor 
       
    44 
       
    45 // ============================ MEMBER FUNCTIONS ===============================
       
    46 
       
    47 void TGlxZoomAndPanMathsEngine::Initialize(TPoint& aCenter, 
       
    48         TSize& aScreenSize, 
       
    49         TSize& aImageSize,
       
    50         TSize& aOriginalZoomedDimensions,
       
    51         TUint8 aInitialZoomRatio)
       
    52     {
       
    53     TRACER("void TGlxZoomAndPanMathsEngine::Initialize()");
       
    54 
       
    55     iCenter             = aCenter;
       
    56     iScreenSize         = aScreenSize;
       
    57 
       
    58     // This will only be set at initialization/constructiron. Never afterwards.
       
    59     // [TODO] Is there a way to make this constant.
       
    60     iActualImageSize    = aImageSize;
       
    61     
       
    62     iMinZoomRatio   = aInitialZoomRatio;
       
    63     iZoomRatio          = aInitialZoomRatio;
       
    64     iMaxZoomRatio = ((aInitialZoomRatio == KGlxLargeImageMaximumZoomRatio) ? 
       
    65         KGlxSmallImageMaximumZoomRatio:KGlxLargeImageMaximumZoomRatio);
       
    66 
       
    67     iPanFactor          = KGlxMinPanFactor;
       
    68 
       
    69     iImageVirtualSize.iHeight   = aImageSize.iHeight * aInitialZoomRatio /100;
       
    70     iImageVirtualSize.iWidth    = aImageSize.iWidth  * aInitialZoomRatio /100;
       
    71     
       
    72     iCenter.iX = iImageVirtualSize.iWidth/2 ;
       
    73     iCenter.iY = iImageVirtualSize.iHeight/2;
       
    74     
       
    75     iBorderWidth.iWidth     = (iScreenSize.iWidth  - iImageVirtualSize.iWidth )/2  ; 
       
    76     iBorderWidth.iHeight    = (iScreenSize.iHeight - iImageVirtualSize.iHeight)/2 ;
       
    77     
       
    78     }
       
    79 
       
    80 TInt TGlxZoomAndPanMathsEngine::NewCenterCoordinate(TInt aCenter, 
       
    81                                 TInt aOffset, 
       
    82                                 TUint16 aHalfScreenDimension, 
       
    83                                 TInt aMinimumCoordinate, 
       
    84                                 TInt aMaximumCoordinate, 
       
    85                                 TBool *aThresholdReached)
       
    86     {
       
    87     TRACER("TGlxZoomAndPanMathsEngine::NewCenterCoordinate");
       
    88     if(aOffset)
       
    89         {
       
    90         //Add the No:of Pixels that has to be panned,the No:of pixels added will be more
       
    91         //if the pan key is held for long time,the PanFactor determines that
       
    92         aCenter = aCenter + (aOffset*iPanFactor);
       
    93         
       
    94         // For Checking the boundary condition
       
    95         if( (aCenter - aHalfScreenDimension)  < aMinimumCoordinate )
       
    96             {
       
    97             //This shows the black background on boundaries of the image and reset to the start of the image
       
    98             aCenter  = aHalfScreenDimension;
       
    99             // Set the variable as true, if the there EXISTS a Variable at that address 
       
   100             if (NULL != aThresholdReached)
       
   101                 {
       
   102                 *aThresholdReached = ETrue;
       
   103                 }
       
   104             }
       
   105         if(aCenter + aHalfScreenDimension > aMaximumCoordinate )
       
   106             {
       
   107             //This shows the black background on boundaries of the image and reset to the end of the image
       
   108             aCenter  = aMaximumCoordinate - aHalfScreenDimension;
       
   109             if (NULL != aThresholdReached)
       
   110                 {
       
   111                 *aThresholdReached = ETrue;
       
   112                 }
       
   113             }
       
   114         }
       
   115     return aCenter;
       
   116     }
       
   117 
       
   118     
       
   119 void TGlxZoomAndPanMathsEngine::Pan(TPoint aOffset, 
       
   120         TPoint& aViewPortTopLeft, 
       
   121         TGlxPanIncrementType aPanIncrement,
       
   122         TBool * aThresholdReached)
       
   123     {
       
   124     TRACER("TGlxZoomAndPanMathsEngine::Pan");
       
   125     
       
   126     GLX_LOG_INFO2("Pan: Center before PAN= [%d,%d]   ", iCenter.iX, iCenter.iY  );
       
   127     GLX_LOG_INFO2("Pan: Pan Offset = [%d,%d]   ", TInt(aOffset.iX), TInt(aOffset.iY));
       
   128     
       
   129     TPoint panOffset = aOffset; 
       
   130     TUint16 halfScreenWidth     = iScreenSize.iWidth>>1;
       
   131     TUint16 halfScreenHeight    = iScreenSize.iHeight>>1;
       
   132     
       
   133     // if we are dragging or something like that the caller might want a uniform increase in panning factor.
       
   134     if (EGlxPanIncrementUniform == aPanIncrement)
       
   135         {
       
   136         iPanFactor = KGlxMinPanFactor ; 
       
   137         }
       
   138     else if ( EGlxPanIncrementInertic == aPanIncrement)
       
   139         {
       
   140         if (panOffset.iX > 0 )
       
   141             {
       
   142             panOffset.iX = panOffset.iX - KGlxPanInertiaFactor ;
       
   143             }
       
   144         else
       
   145             {
       
   146             panOffset.iX = panOffset.iX + KGlxPanInertiaFactor ;
       
   147             }
       
   148 
       
   149         if (panOffset.iY > 0 )
       
   150             {
       
   151             panOffset.iY = panOffset.iY - KGlxPanInertiaFactor ;
       
   152             }
       
   153         else
       
   154             {
       
   155             panOffset.iY = panOffset.iY + KGlxPanInertiaFactor ;
       
   156             }
       
   157         }
       
   158 
       
   159     GLX_LOG_INFO1("Pan: Pan Factor = %d   ", iPanFactor  );
       
   160     
       
   161     // dont pan on a dimension if image is smaller on that dimension than the screen. 
       
   162     if (iImageVirtualSize.iWidth > iScreenSize.iWidth)
       
   163         {
       
   164         iCenter.iX = NewCenterCoordinate(   iCenter.iX, panOffset.iX, halfScreenWidth,KGlxOrigin, 
       
   165                 iImageVirtualSize.iWidth,   aThresholdReached)   ;
       
   166         }
       
   167     
       
   168     if (iImageVirtualSize.iHeight > iScreenSize.iHeight)
       
   169         {
       
   170         TBool thresholdReached = EFalse;
       
   171         iCenter.iY = NewCenterCoordinate(   iCenter.iY, panOffset.iY, halfScreenHeight,KGlxOrigin, 
       
   172                 iImageVirtualSize.iHeight,  &thresholdReached)   ;
       
   173 
       
   174         if (NULL != aThresholdReached)
       
   175             {
       
   176             *aThresholdReached = *aThresholdReached || thresholdReached ; // if we reach the threshold along either axis this means we have reached the threshold
       
   177             }
       
   178         }
       
   179     
       
   180     aViewPortTopLeft.iX = iCenter.iX - halfScreenWidth;
       
   181     aViewPortTopLeft.iY = iCenter.iY - halfScreenHeight;
       
   182     
       
   183     iLastPanOffset = panOffset; 
       
   184     
       
   185     GLX_LOG_INFO2("Pan: Center after PAN= [%d,%d]   ", 
       
   186             TInt(iCenter.iX), TInt(iCenter.iY)  );
       
   187     GLX_LOG_INFO2("Pan: aViewPortTopLeft after PAN= [%d,%d]   ", 
       
   188             TInt(aViewPortTopLeft.iX), TInt(aViewPortTopLeft.iY)  );
       
   189     }
       
   190 
       
   191 
       
   192 TInt TGlxZoomAndPanMathsEngine::Zoom(TZoomMode aZoomMode,
       
   193             TInt aExpectedZoomRatio,    // only for slider based zoom. = 0 for key based zoom
       
   194             TPoint& aViewPortTopLeft, 
       
   195             TSize& aViewPortDimension,
       
   196             TBool* aThresholdReached,
       
   197             TPoint* apZoomFocus, 
       
   198             TInt aRelativeZoomFactor)
       
   199     {
       
   200     TRACER("TGlxZoomAndPanMathsEngine::Zoom ");
       
   201     
       
   202     //[TODO] Unlike the above method this method is a very very very very very small method. 
       
   203     //[TODO] Consider making this larger. [:|]
       
   204     TUint16 halfScreenWidth     = iScreenSize.iWidth>>1;
       
   205     TUint16 halfScreenHeight    = iScreenSize.iHeight>>1;
       
   206     TPoint  centerTranslationfactor(0,0);
       
   207     
       
   208     //[TODO] try to make sure that this variable does not get used in calculations. it always should be the center and
       
   209     //existing and new screen and virtual image dimensions should be calculated using this one.
       
   210     TPoint viewPortTopLeft(TPoint(iCenter).iX - halfScreenWidth, 
       
   211             TPoint(iCenter).iY - halfScreenHeight) ;
       
   212     GLX_LOG_INFO2(" Zoom(): Center before Zoom= [%d,%d] ", iCenter.iX, iCenter.iY );
       
   213     GLX_LOG_INFO2(" Zoom(): viewPortTopLeft  Before Zoom  = [%d,%d] ", TInt(viewPortTopLeft.iX),
       
   214             TInt(viewPortTopLeft.iY)  );
       
   215     
       
   216     TInt oldZoomRatio = iZoomRatio ;  
       
   217     TInt newZoomRatio = NewZoomRatio(aExpectedZoomRatio, aRelativeZoomFactor, aZoomMode, aThresholdReached);
       
   218 
       
   219     // we have an offcenter focus for our zoom in certain cases ( e.g pinch operation) or a double tap at an offcenter point. 
       
   220     // In such a case the zoom happens around that point. So we need to translate (move) the 
       
   221     // center in such a way that the relative position of the zoom facus does not change. 
       
   222     // centerTranslationfactor is the vector representation of that amount. 
       
   223     if (NULL != apZoomFocus)
       
   224         {
       
   225 		// Offcenter Zooming will be enabled later on.
       
   226         centerTranslationfactor.iX = (((apZoomFocus->iX - halfScreenWidth) * newZoomRatio)/oldZoomRatio) + (halfScreenWidth - apZoomFocus->iX);         
       
   227         centerTranslationfactor.iY = (((apZoomFocus->iY - halfScreenHeight) * newZoomRatio)/oldZoomRatio) + (halfScreenHeight - apZoomFocus->iY);
       
   228         }
       
   229 
       
   230     GLX_LOG_INFO1(" Zoom: newZoomRatio = %d.   ", newZoomRatio );
       
   231     
       
   232     TSize imageDimension = TSize(iActualImageSize);
       
   233     imageDimension.iWidth =  (imageDimension.iWidth  * newZoomRatio)/100;
       
   234     imageDimension.iHeight = (imageDimension.iHeight * newZoomRatio)/100;
       
   235     
       
   236     // Is image size bigger than screen size AND image is panned to such an extent that 
       
   237     // the an edge of the image comes within the screen rectange? If so go ahead,   
       
   238     // for everything else there is mastercard. I mean the else condition below. 
       
   239     // [TODO] The master card however needs more simplification. 
       
   240     if(
       
   241             ((iImageVirtualSize.iHeight > iScreenSize.iHeight) 
       
   242                     && (iImageVirtualSize.iWidth > iScreenSize.iWidth)) 
       
   243             &&  ((iCenter.iX != iImageVirtualSize.iWidth/2) 
       
   244                     || (iCenter.iY != iImageVirtualSize.iHeight/2))
       
   245             )
       
   246         {
       
   247         //Calculate the new Center posistion accordingly to the new zoom factor
       
   248         // [TODO] Suggest the use of overloaded operators so that points can be operated upon by vectors. 
       
   249         // specifically in this case to enable a point to be multiplied by a dimension resulting from the ratio of two dimension  
       
   250         iCenter.iX = (iCenter.iX * imageDimension.iWidth )/iImageVirtualSize.iWidth  ;
       
   251         iCenter.iY = (iCenter.iY * imageDimension.iHeight)/iImageVirtualSize.iHeight ;
       
   252 
       
   253         
       
   254         //HEIGHT Calculation
       
   255         // TODO: Hive center corrections into an different function.
       
   256         // If the image might have become smaller than the screen DUE to or AFTER the above calculations
       
   257         if((imageDimension.iHeight < iScreenSize.iHeight - BORDER_HEIGHT))
       
   258             {
       
   259             iCenter.iY=(imageDimension.iHeight/2);
       
   260             }
       
   261         else
       
   262             {
       
   263             TInt weightedBorderHeight = (iBorderWidth.iHeight*(100-((newZoomRatio-iMinZoomRatio)*100/(iMaxZoomRatio-iMinZoomRatio))))/100 ;
       
   264             // Is Center positioned such that the top end of the image is inside the 
       
   265             // screen. 
       
   266             if( iCenter.iY < (halfScreenHeight - weightedBorderHeight )) 
       
   267                 {
       
   268                 iCenter.iY = halfScreenHeight - weightedBorderHeight ;
       
   269                 }
       
   270             // Is Center positioned such that the Bottom end of the image is inside the 
       
   271             // screen. 
       
   272             else if((iCenter.iY + (halfScreenHeight - weightedBorderHeight ))> imageDimension.iHeight)
       
   273                 {
       
   274                 // if so pan the image so that the edge of the image and screen coincide.
       
   275                 iCenter.iY = imageDimension.iHeight - (halfScreenHeight - weightedBorderHeight)  ;
       
   276                 }
       
   277             }
       
   278 
       
   279         //WIDTH Calculation
       
   280         if((imageDimension.iWidth < iScreenSize.iWidth - BORDER_WIDTH))
       
   281             {
       
   282             iCenter.iX=(imageDimension.iWidth/2);
       
   283             }
       
   284         else
       
   285             {
       
   286             TInt weightedBorderWidth = (iBorderWidth.iWidth*(100-((newZoomRatio-iMinZoomRatio)*100/(iMaxZoomRatio-iMinZoomRatio))))/100 ;
       
   287             if( iCenter.iX < (halfScreenWidth - weightedBorderWidth )) 
       
   288                 {
       
   289                 iCenter.iX = (halfScreenWidth - weightedBorderWidth );
       
   290                 }
       
   291             else if((iCenter.iX + (halfScreenWidth - weightedBorderWidth ))> imageDimension.iWidth)
       
   292                 {
       
   293                 iCenter.iX = imageDimension.iWidth - (halfScreenWidth - weightedBorderWidth ) ;
       
   294                 }
       
   295             }
       
   296         //Update the TopLeft corner and then re align to the center in the below code
       
   297         viewPortTopLeft.iY = iCenter.iY - halfScreenHeight ;
       
   298         viewPortTopLeft.iX = iCenter.iX - halfScreenWidth ;
       
   299 
       
   300         iImageVirtualSize = imageDimension;
       
   301         }
       
   302     else
       
   303         {
       
   304         //Conditions to Check.
       
   305         //1.Image Height is Smaller than screen Size and Width is Bigger than  screen Size.
       
   306         //2.Image Height is Bigger than screen Size and Width is Smaller than  screen Size.
       
   307         //3.Both Image Height and Width is  Smaller than screen Size 
       
   308         //4.Image Height is Bigger than screen Size and it is panned.
       
   309         //4.Image Height is Bigger than screen Size and it is not panned at all.
       
   310         //5.Image Width is Bigger than screen Size and it is panned.
       
   311         //6.Image Width is Bigger than screen Size and it is not panned at all.
       
   312         //7. First Time Zoom operation is performed.
       
   313         
       
   314         if( (imageDimension.iHeight <= iScreenSize.iHeight) ||
       
   315                 ( (imageDimension.iHeight > iScreenSize.iHeight) && 
       
   316                         (iCenter.iY == (iImageVirtualSize.iHeight/2)) ) ||
       
   317                 ( ((iCenter.iY + halfScreenHeight) > imageDimension.iHeight)&&
       
   318                         ((iCenter.iY - halfScreenHeight) < KGlxOrigin) ))
       
   319             {
       
   320             //The Image is not panned along Y axis, so the center of the image is the center co-ordinate on this axis.
       
   321             iCenter.iY=(imageDimension.iHeight/2);    
       
   322             }
       
   323         else
       
   324             {
       
   325             //The image is panned and shift the center posistion
       
   326             //Calculate the new Center posistion accordingly to the new zoom factor
       
   327             iCenter.iY = (iCenter.iY * imageDimension.iHeight)/iImageVirtualSize.iHeight;          
       
   328             if( (iCenter.iY + halfScreenHeight) > imageDimension.iHeight)   
       
   329                 {
       
   330                 //Stick the Image to bottom side and then re-posistion the center 
       
   331                 iCenter.iY = imageDimension.iHeight - halfScreenHeight;
       
   332                 }
       
   333             // New DIM is less than Old one. and all above conditions fail. 
       
   334             // This means that new DIM is smaller than VP DIM. So keep center 'centered'.
       
   335             // DIM = dimension
       
   336             else if(iImageVirtualSize.iHeight >  imageDimension.iHeight)      
       
   337                 {
       
   338                 //This is executed in the Zoom Out Case,In ZoomIn Case the Image is widened.
       
   339                 iCenter.iY=(imageDimension.iHeight/2);
       
   340                 }
       
   341             }
       
   342 
       
   343         if((imageDimension.iWidth <= iScreenSize.iWidth) ||
       
   344                 ( (imageDimension.iWidth > iScreenSize.iWidth) && (iCenter.iX == 
       
   345                 (iImageVirtualSize.iWidth/2)) ) || ( (iCenter.iX + halfScreenWidth) > 
       
   346                 imageDimension.iWidth )&&((iCenter.iX - halfScreenWidth) < KGlxOrigin) )
       
   347             {
       
   348             //The Image is not panned along X axis, ,so the center of the image is the center co-ordinate.
       
   349             iCenter.iX=(imageDimension.iWidth/2);
       
   350             }
       
   351         else
       
   352             {
       
   353             //The image is panned and shift the center posistion
       
   354             //Calculate the new Center posistion accordingly to the new zoom factor
       
   355             iCenter.iX = (iCenter.iX * imageDimension.iWidth )/iImageVirtualSize.iWidth ;
       
   356             if( (iCenter.iX + halfScreenWidth) > imageDimension.iWidth )
       
   357                 {
       
   358                 //Stick the Image to right side and then re-posistion the center 
       
   359                 iCenter.iX = imageDimension.iWidth - halfScreenWidth ;
       
   360                 }
       
   361             else if(iImageVirtualSize.iWidth >imageDimension.iWidth )
       
   362                 {
       
   363                 //The Image is panned and while zooming out ,the center has to be possistioned to center of the screen.
       
   364                 iCenter.iX =(imageDimension.iWidth/2);
       
   365                 }
       
   366             }
       
   367 
       
   368         viewPortTopLeft.iX = iCenter.iX - halfScreenWidth;
       
   369         viewPortTopLeft.iY = iCenter.iY - halfScreenHeight;
       
   370         iImageVirtualSize = imageDimension;
       
   371         
       
   372         }
       
   373 
       
   374     // if centerTranslationfactor exists that means we have an off center zoom, then 
       
   375     // pan that way to get the new center.
       
   376     Pan(centerTranslationfactor, viewPortTopLeft, EGlxPanIncrementUniform) ;
       
   377         
       
   378     aViewPortDimension  = imageDimension    ;
       
   379     aViewPortTopLeft    = viewPortTopLeft   ;
       
   380     
       
   381     GLX_LOG_INFO2("Zoom(): Center After Zoom = [%d,%d]   ", TInt(iCenter.iX), 
       
   382             TInt(iCenter.iY)  );
       
   383     GLX_LOG_INFO2("Zoom(): aViewPortDimension After Zoom  = [%d,%d]   ", 
       
   384             TInt(aViewPortDimension.iWidth), TInt(aViewPortDimension.iHeight)  );
       
   385     GLX_LOG_INFO2("Zoom(): viewPortTopLeft  After Zoom  = [%d,%d]   ", 
       
   386             TInt(viewPortTopLeft.iX), TInt(viewPortTopLeft.iY)  );
       
   387 
       
   388     return newZoomRatio;
       
   389     }
       
   390 
       
   391 //-------------------------------------------------------------------------------------
       
   392 // UpdatePanFactor: Calculates the Pan Factor based on time the key was pressed
       
   393 //-------------------------------------------------------------------------------------
       
   394 //
       
   395 void TGlxZoomAndPanMathsEngine::UpdatePanFactor(TTime& aPanTime)
       
   396     {
       
   397     TRACER("void TGlxZoomAndPanMathsEngine::UpdatePanFactor()");
       
   398     
       
   399     iContinuousPanOperations++;
       
   400     
       
   401     TInt  elapsedPanOperationSetCount = iContinuousPanOperations/KGlxPanFactorUpdateMultiple;
       
   402     
       
   403     // Double the pan factor for every multiple of KGlxPanFactorUpdateMultiple that the key was pressed till
       
   404     // we have crossed 'KGlxMaxTimeMultiple' orders of magnitude  
       
   405     if (KGlxMaxPanUpdateMultiple > elapsedPanOperationSetCount )
       
   406         {
       
   407         iPanFactor = KGlxMinPanFactor << elapsedPanOperationSetCount ;
       
   408         }
       
   409     GLX_LOG_INFO1("iPanFactor %d", iPanFactor);
       
   410     }
       
   411 
       
   412 
       
   413 //-------------------------------------------------------------------------------------
       
   414 // NewZoomRatio: Calculates the Zoom Ratio 
       
   415 //-------------------------------------------------------------------------------------
       
   416 //
       
   417 TInt TGlxZoomAndPanMathsEngine::NewZoomRatio( 
       
   418         TInt aExpectedZoomRatio,
       
   419         TInt aRelativeZoomFactor,
       
   420         TZoomMode aZoomMode,
       
   421         TBool *aThresholdReached)  
       
   422     {
       
   423     TRACER("TGlxZoomAndPanMathsEngine::NewZoomRatio ");
       
   424     GLX_LOG_INFO1("NewZoomRatio: Old Zoom Ratio = %d .   ",TInt(iZoomRatio)   );
       
   425     GLX_LOG_INFO1("NewZoomRatio: Expected Zoom Ratio  = %d .   ",aExpectedZoomRatio    );
       
   426     GLX_LOG_INFO1("NewZoomRatio: Relative Zoom Factor = %d .   ",aRelativeZoomFactor   );
       
   427     
       
   428     // We ignore zoommode and aRelativeZoomFactor if we have a aExpectedZoomRatio.
       
   429     // We ignore zoommode if we have a aRelativeZoomFactor.
       
   430     if (aExpectedZoomRatio > 0)
       
   431         {
       
   432         iZoomRatio = aExpectedZoomRatio    ;
       
   433         }
       
   434     else if (aRelativeZoomFactor > 0)
       
   435         {
       
   436         //Pruning extreme values. Not allowing more than 15% change in zoom ratio.
       
   437         TInt normalizedRelativeZoomFactor = aRelativeZoomFactor ;
       
   438         if (normalizedRelativeZoomFactor < KGlxMinRelativeZoomPercent)
       
   439             {
       
   440             normalizedRelativeZoomFactor = KGlxMinRelativeZoomPercent;
       
   441             }
       
   442         else if (normalizedRelativeZoomFactor > KGlxMaxRelativeZoomPercent)
       
   443             {
       
   444             normalizedRelativeZoomFactor = KGlxMaxRelativeZoomPercent;
       
   445             }
       
   446         
       
   447         iZoomRatio =  (iZoomRatio * normalizedRelativeZoomFactor)/100 ;
       
   448         }
       
   449     else
       
   450         {
       
   451         if(EZoomIn == aZoomMode)
       
   452             {
       
   453             iZoomRatio += KGlxZoomPanInc;
       
   454             }
       
   455         else  
       
   456             {
       
   457             iZoomRatio -= KGlxZoomPanInc;
       
   458             }
       
   459         }
       
   460 
       
   461     // if iZoomRatio crosses max or minimum limits, then peg them to those limits. 
       
   462     if (iZoomRatio >= iMaxZoomRatio) 
       
   463         {
       
   464         iZoomRatio = iMaxZoomRatio;
       
   465         if (NULL != aThresholdReached)
       
   466             {
       
   467             GLX_LOG_INFO1("NewZoomRatio: Max Threshold Reached iMaxZoomRatio = %d .",iMaxZoomRatio);
       
   468             *aThresholdReached = ETrue;
       
   469             }
       
   470         }
       
   471     else if( iZoomRatio <= iMinZoomRatio )
       
   472         {
       
   473         iZoomRatio = iMinZoomRatio;
       
   474         if (NULL != aThresholdReached)
       
   475             {
       
   476             GLX_LOG_INFO1("NewZoomRatio: Min Threshold Reached iInitialZoomRatio = %d .", iMinZoomRatio );
       
   477             *aThresholdReached = ETrue;
       
   478             }
       
   479         }
       
   480 
       
   481     GLX_LOG_INFO1("NewZoomRatio: New Zoom Ratio = %d.   ",TInt(iZoomRatio)   );
       
   482     return iZoomRatio;
       
   483     }
       
   484 
       
   485 
       
   486 //-------------------------------------------------------------------------------------
       
   487 // OrientationChanged:  
       
   488 //-------------------------------------------------------------------------------------
       
   489 //
       
   490 void TGlxZoomAndPanMathsEngine::OrientationChanged(const TRect& aNewScreenRect)
       
   491     {
       
   492     TRACER("void TGlxZoomAndPanMathsEngine::OrientationChanged()");
       
   493     iScreenSize.iWidth          = aNewScreenRect.Width();    
       
   494     iScreenSize.iHeight         = aNewScreenRect.Height();    
       
   495     }
       
   496 
       
   497 //-------------------------------------------------------------------------------------
       
   498 // ImageVirtualSize: retieves the virtual size of the image.    
       
   499 //-------------------------------------------------------------------------------------
       
   500 //
       
   501 TSize TGlxZoomAndPanMathsEngine::ImageVirtualSize()
       
   502     {
       
   503     TRACER("TGlxZoomAndPanMathsEngine::ImageVirtualSize()");
       
   504     return iImageVirtualSize;
       
   505     }
       
   506 
       
   507 
       
   508 //-------------------------------------------------------------------------------------
       
   509 // ScreenSize: retrieves the screen size .    
       
   510 //-------------------------------------------------------------------------------------
       
   511 //
       
   512 TSize TGlxZoomAndPanMathsEngine::ScreenSize()
       
   513     {
       
   514     TRACER("TGlxZoomAndPanMathsEngine::ScreenSize()");
       
   515     return iScreenSize;
       
   516     }
       
   517 
       
   518 //-------------------------------------------------------------------------------------
       
   519 // ImageVirtualSize: retrieves the screen size .    
       
   520 //-------------------------------------------------------------------------------------
       
   521 //
       
   522 void TGlxZoomAndPanMathsEngine::SetupPanOperation()
       
   523     {
       
   524     TRACER("TGlxZoomAndPanMathsEngine::SetupPanOperation()");
       
   525     iContinuousPanOperations = 0 ; 
       
   526     }
       
   527 
       
   528 TPoint TGlxZoomAndPanMathsEngine::LastPanOffset()
       
   529     {
       
   530     TRACER("TGlxZoomAndPanMathsEngine::LastPanOffset()");
       
   531     return iLastPanOffset;
       
   532     }