photosgallery/viewframework/views/zoomview/src/glxzoommathsengine.cpp
branchRCL_3
changeset 23 b023a8d2866a
parent 21 f9e827349359
equal deleted inserted replaced
21:f9e827349359 23:b023a8d2866a
    23 
    23 
    24 // Includes for Logs
    24 // Includes for Logs
    25 #include <glxtracer.h>                      //  For Tracer
    25 #include <glxtracer.h>                      //  For Tracer
    26 #include <glxlog.h>                         //  For Log
    26 #include <glxlog.h>                         //  For Log
    27 
    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
    28 // LOCAL CONSTANTS AND MACROS
    31 const TInt KGlxLargeImageMaximumZoomRatio   =   100     ;
    29 const TInt KGlxLargeImageMaximumZoomRatio   =   100     ;
    32 const TInt KGlxSmallImageMaximumZoomRatio   =   150     ;
    30 const TInt KGlxSmallImageMaximumZoomRatio   =   150     ;
    33 
    31 
    34 const TInt KGlxMinPanFactor                 =   1       ; // The min multiple of pixles to pan 
    32 const TInt KGlxMinPanFactor                 =   1       ; // The min multiple of pixles to pan 
    35 const TInt KGlxPanInertiaFactor             =   10      ; 
    33 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 
    34 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       ;
    35 const TInt KGlxMaxPanUpdateMultiple         =   6       ;
    38 const TInt KGlxOrigin                       =   0       ;
    36 const TInt KGlxOrigin                       =   0       ;
    39 
    37 
    40 const TInt KGlxMinRelativeZoomPercent       =   70       ;
    38 const TInt KGlxMinRelativeZoomPercent       =   85       ;
    41 const TInt KGlxMaxRelativeZoomPercent       =   130      ;
    39 const TInt KGlxMaxRelativeZoomPercent       =   115      ;
    42 
    40 
    43 const TInt KGlxZoomPanInc                   =   10      ; // Min number of pixels panned in one keypress. This value is incremented exponentially by multiples of iPanFactor 
    41 const TInt KGlxZoomPanInc                   =   10      ; // Min number of pixels panned in one keypress. This value is incremented exponentially by multiples of iPanFactor 
    44 
    42 
    45 // ============================ MEMBER FUNCTIONS ===============================
    43 // ============================ MEMBER FUNCTIONS ===============================
    46 
    44 
    47 void TGlxZoomAndPanMathsEngine::Initialize(TPoint& aCenter, 
    45 void TGlxZoomAndPanMathsEngine::Initialize(TPoint& aCenter, 
    48         TSize& aScreenSize, 
    46         TSize& aScreenSize, 
    49         TSize& aImageSize,
    47         TSize& aImageSize,
    50         TSize& /*aOriginalZoomedDimensions*/,
    48         TUint8 aInitialZoomRatio,
    51         TUint8 aInitialZoomRatio)
    49         TUint8 aMinZoomRatio)
    52     {
    50     {
    53     TRACER("void TGlxZoomAndPanMathsEngine::Initialize()");
    51     TRACER("void TGlxZoomAndPanMathsEngine::Initialize()");
    54 
    52 
    55     iCenter             = aCenter;
    53     iCenter             = aCenter;
    56     iScreenSize         = aScreenSize;
    54     iScreenSize         = aScreenSize;
    57 
    55 
    58     // This will only be set at initialization/constructiron. Never afterwards.
    56     // This will only be set at initialization/constructiron. Never afterwards.
    59     // [TODO] Is there a way to make this constant.
    57     // [TODO] Is there a way to make this constant.
    60     iActualImageSize    = aImageSize;
    58     iActualImageSize    = aImageSize;
    61     
    59     
    62     iMinZoomRatio   = aInitialZoomRatio;
    60     iMinZoomRatio   = aMinZoomRatio;
    63     iZoomRatio          = aInitialZoomRatio;
    61     iZoomRatio      = aInitialZoomRatio;
    64     iMaxZoomRatio = ((aInitialZoomRatio == KGlxLargeImageMaximumZoomRatio) ? 
    62     iMaxZoomRatio   = ((aInitialZoomRatio >= KGlxLargeImageMaximumZoomRatio) ? 
    65         KGlxSmallImageMaximumZoomRatio:KGlxLargeImageMaximumZoomRatio);
    63         KGlxSmallImageMaximumZoomRatio:KGlxLargeImageMaximumZoomRatio);
       
    64     GLX_LOG_INFO1("TGlxZoomAndPanMathsEngine::Initialize: Minimum ZoomRatio = [%d]   ", iMinZoomRatio     );
       
    65     GLX_LOG_INFO1("TGlxZoomAndPanMathsEngine::Initialize: Maximum ZoomRatio = [%d]   ", iMaxZoomRatio     );
    66 
    66 
    67     iPanFactor          = KGlxMinPanFactor;
    67     iPanFactor          = KGlxMinPanFactor;
    68 
    68 
    69     iImageVirtualSize.iHeight   = aImageSize.iHeight * aInitialZoomRatio /100;
    69     iImageVirtualSize.iHeight   = aImageSize.iHeight * aInitialZoomRatio /100;
    70     iImageVirtualSize.iWidth    = aImageSize.iWidth  * aInitialZoomRatio /100;
    70     iImageVirtualSize.iWidth    = aImageSize.iWidth  * aInitialZoomRatio /100;
    72     iCenter.iX = iImageVirtualSize.iWidth/2 ;
    72     iCenter.iX = iImageVirtualSize.iWidth/2 ;
    73     iCenter.iY = iImageVirtualSize.iHeight/2;
    73     iCenter.iY = iImageVirtualSize.iHeight/2;
    74     
    74     
    75     iBorderWidth.iWidth     = (iScreenSize.iWidth  - iImageVirtualSize.iWidth )/2  ; 
    75     iBorderWidth.iWidth     = (iScreenSize.iWidth  - iImageVirtualSize.iWidth )/2  ; 
    76     iBorderWidth.iHeight    = (iScreenSize.iHeight - iImageVirtualSize.iHeight)/2 ;
    76     iBorderWidth.iHeight    = (iScreenSize.iHeight - iImageVirtualSize.iHeight)/2 ;
       
    77     
       
    78     GLX_LOG_INFO2("TGlxZoomAndPanMathsEngine::Initialize: Center at Initialization = [%f,%f]   ", iCenter.iX, iCenter.iY  );
    77     
    79     
    78     }
    80     }
    79 
    81 
    80 TInt TGlxZoomAndPanMathsEngine::NewCenterCoordinate(TInt aCenter, 
    82 TInt TGlxZoomAndPanMathsEngine::NewCenterCoordinate(TInt aCenter, 
    81                                 TInt aOffset, 
    83                                 TInt aOffset, 
   122         TBool * aThresholdReached)
   124         TBool * aThresholdReached)
   123     {
   125     {
   124     TRACER("TGlxZoomAndPanMathsEngine::Pan");
   126     TRACER("TGlxZoomAndPanMathsEngine::Pan");
   125     
   127     
   126     GLX_LOG_INFO2("Pan: Center before PAN= [%d,%d]   ", iCenter.iX, iCenter.iY  );
   128     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));
   129     GLX_LOG_INFO2("Pan: Pan Offset = [%d,%d]   ", aOffset.iX, aOffset.iY);
   128     
   130     
   129     TPoint panOffset = aOffset; 
   131     TPoint panOffset = aOffset; 
   130     TUint16 halfScreenWidth     = iScreenSize.iWidth>>1;
   132     TUint16 halfScreenWidth     = iScreenSize.iWidth>>1;
   131     TUint16 halfScreenHeight    = iScreenSize.iHeight>>1;
   133     TUint16 halfScreenHeight    = iScreenSize.iHeight>>1;
   132     
   134     
   250         iCenter.iY = (iCenter.iY * imageDimension.iHeight)/iImageVirtualSize.iHeight ;
   252         iCenter.iY = (iCenter.iY * imageDimension.iHeight)/iImageVirtualSize.iHeight ;
   251 
   253 
   252         //HEIGHT Calculation
   254         //HEIGHT Calculation
   253         // TODO: Hive center corrections into an different function.
   255         // TODO: Hive center corrections into an different function.
   254         // If the image might have become smaller than the screen DUE to or AFTER the above calculations
   256         // If the image might have become smaller than the screen DUE to or AFTER the above calculations
   255         if((imageDimension.iHeight < iScreenSize.iHeight - BORDER_HEIGHT))
   257         if((imageDimension.iHeight < iScreenSize.iHeight ))
   256             {
   258             {
   257             iCenter.iY=(imageDimension.iHeight/2);
   259             iCenter.iY=(imageDimension.iHeight/2);
   258             }
   260             }
   259         else
   261         else
   260             {
   262             {