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