|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * Crop plugin's control class. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include <fbs.h> |
|
23 #include <badesca.h> |
|
24 #include <eikenv.h> |
|
25 |
|
26 #include <ImageEditorUI.mbg> |
|
27 |
|
28 #include <aknview.h> |
|
29 #include <aknutils.h> |
|
30 #include <AknInfoPopupNoteController.h> |
|
31 #include <crop.rsg> |
|
32 #include <bautils.h> |
|
33 #include <ConeResLoader.h> |
|
34 #include <StringLoader.h> |
|
35 #include <AknIconUtils.h> |
|
36 |
|
37 #ifdef RD_TACTILE_FEEDBACK |
|
38 #include <touchfeedback.h> |
|
39 #endif /* RD_TACTILE_FEEDBACK */ |
|
40 |
|
41 #include "ImageEditorUI.hrh" |
|
42 #include "ImageEditorPluginBase.hrh" |
|
43 #include "PluginInfo.h" |
|
44 #include "DrawUtils.h" |
|
45 #include "SystemParameters.h" |
|
46 #include "JpTimer.h" |
|
47 #include "ImageEditorUIDefs.h" |
|
48 #include "iepb.h" |
|
49 |
|
50 #include "ImageEditorCropControl.h" |
|
51 #include "ImageEditorError.h" |
|
52 |
|
53 // debug log |
|
54 #include "imageeditordebugutils.h" |
|
55 _LIT(KCropPluginLogFile,"CropPlugin.log"); |
|
56 |
|
57 // Resource file name |
|
58 _LIT (KPgnResourceFile, "crop.rsc"); |
|
59 // Separator to navi pane text |
|
60 _LIT( KCropNaviTextSeparator, "x" ); |
|
61 |
|
62 // CONSTANTS |
|
63 const float KParamStep = 0.005F; |
|
64 const float KMinCropRelDistFrac = 0.01F; |
|
65 const float KCursorScalingFactor = 0.7F; |
|
66 |
|
67 const TInt KMaxCropAbsoluteMin = 75; |
|
68 const TInt KMinSourceSize = 75; |
|
69 |
|
70 //const TInt KStatusPaneTextMoveIndex = 1; |
|
71 const TInt KStatusPaneTextAreaIndex = 2; |
|
72 |
|
73 // Default value from CPreviewControlBase not used |
|
74 const TInt KCropFastKeyTimerDelayInMicroseconds = 1000; |
|
75 |
|
76 // Used fixed point resolution for scales |
|
77 //const TInt KScaleBits = 12; |
|
78 |
|
79 //============================================================================= |
|
80 CImageEditorCropControl * CImageEditorCropControl::NewL ( |
|
81 const TRect& aRect, |
|
82 CCoeControl* aParent |
|
83 ) |
|
84 { |
|
85 LOG(KCropPluginLogFile, "CImageEditorCropControl::NewL()"); |
|
86 |
|
87 CImageEditorCropControl * self = new (ELeave) CImageEditorCropControl; |
|
88 CleanupStack::PushL (self); |
|
89 self->ConstructL (aRect, aParent); |
|
90 CleanupStack::Pop (); // self |
|
91 return self; |
|
92 } |
|
93 |
|
94 //============================================================================= |
|
95 TInt CImageEditorCropControl::DancingAntsCallback (TAny * aPtr) |
|
96 { |
|
97 ((CImageEditorCropControl *)aPtr)->OnDancingAntsCallBack(); |
|
98 return KErrNone; |
|
99 } |
|
100 |
|
101 //============================================================================= |
|
102 TInt CImageEditorCropControl::FastKeyCallback (TAny * aPtr) |
|
103 { |
|
104 TRAPD( err, ((CImageEditorCropControl *)aPtr)->OnFastKeyCallBackL() ); |
|
105 return err; |
|
106 } |
|
107 |
|
108 //============================================================================= |
|
109 CImageEditorCropControl::CImageEditorCropControl () : |
|
110 iState (ECropStateFirst), |
|
111 iFastKeyTimerState (ETimerInactive), |
|
112 iHandleEventKeys (ETrue), |
|
113 iTickCount (0), |
|
114 iNaviStepMultiplier (KDefaultSmallNavigationStepMultiplier), |
|
115 iReadyToRender(EFalse) |
|
116 { |
|
117 |
|
118 } |
|
119 |
|
120 //============================================================================= |
|
121 CImageEditorCropControl::~CImageEditorCropControl () |
|
122 { |
|
123 iEditorView = NULL; |
|
124 iItem = NULL; |
|
125 iSysPars = NULL; |
|
126 |
|
127 delete iCrossHair; |
|
128 delete iCrossHairMask; |
|
129 |
|
130 delete iSecondaryCrossHair; |
|
131 delete iSecondaryCrossHairMask; |
|
132 if (iTimer) |
|
133 { |
|
134 iTimer->Cancel(); |
|
135 } |
|
136 delete iTimer; |
|
137 |
|
138 delete iPopupController; |
|
139 delete iTooltipResize; |
|
140 delete iTooltipMove; |
|
141 |
|
142 #ifdef DOUBLE_BUFFERED_CROP |
|
143 |
|
144 delete iBufBitmap; |
|
145 |
|
146 #endif // DOUBLE_BUFFERED_CROP |
|
147 |
|
148 } |
|
149 |
|
150 //============================================================================= |
|
151 void CImageEditorCropControl::ConstructL ( |
|
152 const TRect& /*aRect*/, |
|
153 CCoeControl* aParent |
|
154 ) |
|
155 { |
|
156 LOG(KCropPluginLogFile, "CImageEditorCropControl::ConstructL()"); |
|
157 |
|
158 // Set parent window |
|
159 SetContainerWindowL (*aParent); |
|
160 |
|
161 // Load MAIN CROSSHAIR image |
|
162 SDrawUtils::GetIndicatorBitmapL ( |
|
163 iCrossHair, |
|
164 iCrossHairMask, |
|
165 EMbmImageeditoruiQgn_indi_imed_cursor_super, |
|
166 EMbmImageeditoruiQgn_indi_imed_cursor_super_mask |
|
167 ); |
|
168 |
|
169 // Load SECOND CROSSHAIR image |
|
170 SDrawUtils::GetIndicatorBitmapL ( |
|
171 iSecondaryCrossHair, |
|
172 iSecondaryCrossHairMask, |
|
173 EMbmImageeditoruiQgn_indi_imed_cursor2_super, |
|
174 EMbmImageeditoruiQgn_indi_imed_cursor2_super_mask |
|
175 ); |
|
176 |
|
177 TSize chSize = iCrossHair->SizeInPixels(); |
|
178 TSize chNewSize = TSize( ( chSize.iWidth * KCursorScalingFactor ), |
|
179 ( chSize.iHeight * KCursorScalingFactor ) ); |
|
180 // Set secondary cursor size smaller than the main cursor |
|
181 AknIconUtils::SetSize( iSecondaryCrossHair, chNewSize ); |
|
182 AknIconUtils::SetSize( iSecondaryCrossHairMask, chNewSize ); |
|
183 |
|
184 // Create and start timer for dancing ants and fast key events |
|
185 iTimer = CPeriodic::NewL (CActive::EPriorityStandard); |
|
186 StartDancingAntsTimer(); |
|
187 |
|
188 iPopupController = CAknInfoPopupNoteController::NewL(); |
|
189 |
|
190 TFileName resourcefile; |
|
191 resourcefile.Append(KPgnResourcePath); |
|
192 resourcefile.Append(KPgnResourceFile); |
|
193 User::LeaveIfError( CompleteWithAppPath( resourcefile ) ); |
|
194 |
|
195 // Read tooltip resources |
|
196 // (RConeResourceLoader selects the language using BaflUtils::NearestLanguageFile) |
|
197 RConeResourceLoader resLoader ( *CEikonEnv::Static() ); |
|
198 CleanupClosePushL ( resLoader ); |
|
199 resLoader.OpenL ( resourcefile ); |
|
200 |
|
201 iTooltipResize = CEikonEnv::Static()->AllocReadResourceL(R_TOOLTIP_CROP_RESIZE_AREA); |
|
202 iTooltipMove = CEikonEnv::Static()->AllocReadResourceL(R_TOOLTIP_CROP_MOVE_AREA); |
|
203 |
|
204 |
|
205 #ifdef RD_TACTILE_FEEDBACK |
|
206 iTouchFeedBack = MTouchFeedback::Instance(); |
|
207 #endif /* RD_TACTILE_FEEDBACK */ |
|
208 |
|
209 CleanupStack::PopAndDestroy(); // resLoader |
|
210 |
|
211 EnableDragEvents(); |
|
212 |
|
213 // Activate control |
|
214 ActivateL(); |
|
215 } |
|
216 |
|
217 //============================================================================= |
|
218 void CImageEditorCropControl::Draw (const TRect & aRect) const |
|
219 { |
|
220 |
|
221 #ifndef DOUBLE_BUFFERED_CROP |
|
222 |
|
223 CPreviewControlBase::DrawPreviewImage (aRect); |
|
224 |
|
225 #endif // DOUBLE_BUFFERED_CROP |
|
226 |
|
227 if ( iState != ECropStateMin ) |
|
228 { |
|
229 // Get graphics context |
|
230 CWindowGc & gc = SystemGc(); |
|
231 |
|
232 #ifdef DOUBLE_BUFFERED_CROP |
|
233 |
|
234 if ( iBufBitmap && iBufBitmap->Handle() ) |
|
235 { |
|
236 gc.BitBlt(TPoint(0,0), iBufBitmap); |
|
237 } |
|
238 |
|
239 #endif // DOUBLE_BUFFERED_CROP |
|
240 |
|
241 // Compute crop rectangle inside the image area |
|
242 TRect rect = iSysPars->VisibleImageRectPrev(); |
|
243 TInt w = (rect.iBr.iX - rect.iTl.iX); |
|
244 TInt h = (rect.iBr.iY - rect.iTl.iY); |
|
245 TInt ulc = (TInt) (iULC * w + 0.5) + rect.iTl.iX; |
|
246 TInt ulr = (TInt) (iULR * h + 0.5) + rect.iTl.iY; |
|
247 TInt lrc = (TInt) (iLRC * w + 0.5) + rect.iTl.iX; |
|
248 TInt lrr = (TInt) (iLRR * h + 0.5) + rect.iTl.iY; |
|
249 |
|
250 #ifndef DOUBLE_BUFFERED_CROP |
|
251 |
|
252 // Darken areas in the image that are outside crop rectangle |
|
253 gc.SetDrawMode (CGraphicsContext::EDrawModeAND); |
|
254 gc.SetPenStyle (CGraphicsContext::ENullPen); |
|
255 gc.SetPenColor (KRgbBlack); |
|
256 gc.SetBrushStyle (CGraphicsContext::EDiamondCrossHatchBrush); |
|
257 gc.SetBrushColor (KRgbWhite); |
|
258 |
|
259 // Darken top |
|
260 gc.DrawRect ( TRect ( rect.iTl.iX, 0, rect.iBr.iX, ulr ) ); |
|
261 |
|
262 // Darken left side |
|
263 gc.DrawRect ( TRect( rect.iTl.iX, ulr, ulc, lrr ) ); |
|
264 |
|
265 // Darken right side |
|
266 gc.DrawRect ( TRect( lrc, ulr, rect.iBr.iX, lrr ) ); |
|
267 |
|
268 // Darken bottom |
|
269 gc.DrawRect ( TRect( rect.iTl.iX, lrr, rect.iBr.iX, Rect().iBr.iY ) ); |
|
270 |
|
271 #endif // DOUBLE_BUFFERED_CROP |
|
272 |
|
273 // Draw crop rectangle with dancing antz |
|
274 DrawDancingAnts (aRect); |
|
275 |
|
276 DrawCursors( TRect( ulc, ulr, lrc, lrr ) ); |
|
277 |
|
278 } |
|
279 } |
|
280 |
|
281 //============================================================================= |
|
282 void CImageEditorCropControl::DrawCursors (const TRect& aCropRect) const |
|
283 { |
|
284 CWindowGc & gc = SystemGc(); |
|
285 |
|
286 CFbsBitmap* mainCrossHair; |
|
287 CFbsBitmap* mainCrossHairMask; |
|
288 if ( iState == ECropStateMove ) |
|
289 { |
|
290 mainCrossHair = iSecondaryCrossHair; |
|
291 mainCrossHairMask = iSecondaryCrossHairMask; |
|
292 } |
|
293 else |
|
294 { |
|
295 mainCrossHair = iCrossHair; |
|
296 mainCrossHairMask = iCrossHairMask; |
|
297 } |
|
298 |
|
299 // Draw the main cross hair |
|
300 if ( mainCrossHair && mainCrossHair ) |
|
301 { |
|
302 TInt cx = 0; |
|
303 TInt cy = 0; |
|
304 if (iState == ECropStateFirst || iState == ECropStateMove) |
|
305 { |
|
306 cx = aCropRect.iTl.iX; |
|
307 cy = aCropRect.iTl.iY; |
|
308 } |
|
309 else if (iState == ECropStateSecond) |
|
310 { |
|
311 cx = aCropRect.iBr.iX - 1; |
|
312 cy = aCropRect.iBr.iY - 1; |
|
313 } |
|
314 |
|
315 TSize chSize = mainCrossHair->SizeInPixels(); |
|
316 gc.BitBltMasked ( |
|
317 TPoint(cx - (chSize.iWidth >> 1), cy - (chSize.iHeight >> 1)), |
|
318 mainCrossHair, |
|
319 TRect (chSize), |
|
320 mainCrossHairMask, |
|
321 EFalse |
|
322 ); |
|
323 } |
|
324 |
|
325 // Draw the secondary cross hair |
|
326 if ( iSecondaryCrossHair && iSecondaryCrossHairMask ) |
|
327 { |
|
328 |
|
329 TInt cx = 0; |
|
330 TInt cy = 0; |
|
331 if (iState == ECropStateFirst || iState == ECropStateMove) |
|
332 { |
|
333 cx = aCropRect.iBr.iX - 1; |
|
334 cy = aCropRect.iBr.iY - 1; |
|
335 } |
|
336 else if (iState == ECropStateSecond) |
|
337 { |
|
338 cx = aCropRect.iTl.iX; |
|
339 cy = aCropRect.iTl.iY; |
|
340 } |
|
341 |
|
342 TSize chSize = iSecondaryCrossHair->SizeInPixels(); |
|
343 gc.BitBltMasked ( |
|
344 TPoint(cx - (chSize.iWidth >> 1), cy - (chSize.iHeight >> 1)), |
|
345 iSecondaryCrossHair, |
|
346 TRect (chSize), |
|
347 iSecondaryCrossHairMask, |
|
348 EFalse |
|
349 ); |
|
350 } |
|
351 } |
|
352 |
|
353 //============================================================================= |
|
354 void CImageEditorCropControl::DrawDancingAnts (const TRect & /*aRect*/) const |
|
355 { |
|
356 // Get graphics context |
|
357 CWindowGc & gc = SystemGc(); |
|
358 |
|
359 // Compute crop rectangle inside the image area |
|
360 TRect rect = iSysPars->VisibleImageRectPrev(); |
|
361 TInt w = (rect.iBr.iX - rect.iTl.iX); |
|
362 TInt h = (rect.iBr.iY - rect.iTl.iY); |
|
363 TInt ulc = (TInt) (iULC * w) + rect.iTl.iX; |
|
364 TInt ulr = (TInt) (iULR * h) + rect.iTl.iY; |
|
365 TInt lrc = (TInt) (iLRC * w) + rect.iTl.iX; |
|
366 TInt lrr = (TInt) (iLRR * h) + rect.iTl.iY; |
|
367 |
|
368 // Crop needed rectangles |
|
369 TRect cr (ulc, ulr, lrc, lrr); |
|
370 |
|
371 // Draw the "dancing ants" rectangle |
|
372 gc.SetDrawMode (CGraphicsContext::EDrawModePEN); |
|
373 gc.SetBrushStyle (CGraphicsContext::ENullBrush); |
|
374 gc.SetBrushColor (KRgbBlack); |
|
375 |
|
376 // Draw |
|
377 gc.SetPenStyle (CGraphicsContext::ESolidPen); |
|
378 gc.SetPenColor ((iAntFlag) ? (KRgbBlack) : (KRgbWhite)); |
|
379 gc.DrawRect (cr); |
|
380 |
|
381 // Draw dashed line |
|
382 gc.SetPenStyle (CGraphicsContext::EDashedPen); |
|
383 gc.SetPenColor ((iAntFlag) ? (KRgbWhite) : (KRgbBlack)); |
|
384 gc.DrawRect (cr); |
|
385 |
|
386 } |
|
387 |
|
388 |
|
389 //============================================================================= |
|
390 void CImageEditorCropControl::SetView (CAknView * aView) |
|
391 { |
|
392 LOG(KCropPluginLogFile, "CImageEditorCropControl::SetView()"); |
|
393 |
|
394 iEditorView = aView; |
|
395 } |
|
396 |
|
397 //============================================================================= |
|
398 void CImageEditorCropControl::SetSelectedUiItemL (CPluginInfo * aItem) |
|
399 { |
|
400 LOG(KCropPluginLogFile, "CImageEditorCropControl::SetSelectedUiItemL()"); |
|
401 iItem = aItem; |
|
402 } |
|
403 |
|
404 #ifdef DOUBLE_BUFFERED_CROP |
|
405 |
|
406 //============================================================================= |
|
407 void CImageEditorCropControl::SetImageL (CFbsBitmap * aBitmap) |
|
408 { |
|
409 LOG(KCropPluginLogFile, "CImageEditorCropControl::SetImageL()"); |
|
410 |
|
411 // Create preview bitmap |
|
412 iPrevBitmap = aBitmap; |
|
413 TSize size = iPrevBitmap->SizeInPixels(); |
|
414 TDisplayMode dmode = iPrevBitmap->DisplayMode(); |
|
415 |
|
416 delete iBufBitmap; |
|
417 iBufBitmap = 0; |
|
418 iBufBitmap = new (ELeave) CFbsBitmap; |
|
419 User::LeaveIfError ( iBufBitmap->Create(size, dmode) ); |
|
420 |
|
421 // Copy bitmap data |
|
422 ClonePreviewBitmapL(); |
|
423 DarkenUnselectedAreaL(); |
|
424 DrawNow(); |
|
425 } |
|
426 |
|
427 #endif // DOUBLE_BUFFERED_CROP |
|
428 |
|
429 //============================================================================= |
|
430 TKeyResponse CImageEditorCropControl::OfferKeyEventL ( |
|
431 const TKeyEvent & aKeyEvent, |
|
432 TEventCode aType |
|
433 ) |
|
434 { |
|
435 LOG(KCropPluginLogFile, "CImageEditorCropControl::OfferKeyEventL()"); |
|
436 |
|
437 TKeyResponse response = EKeyWasNotConsumed; |
|
438 |
|
439 // If busy, do not handle anything |
|
440 if ( Busy() ) |
|
441 { |
|
442 response = EKeyWasConsumed; |
|
443 } |
|
444 |
|
445 // EVENTKEY |
|
446 else if (EEventKey == aType && iHandleEventKeys) |
|
447 { |
|
448 |
|
449 switch (aKeyEvent.iCode) |
|
450 { |
|
451 |
|
452 case EKeyDownArrow: |
|
453 { |
|
454 // Adjust crop point |
|
455 NaviDownL(); |
|
456 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
457 DrawNow(); |
|
458 response = EKeyWasConsumed; |
|
459 iPopupController->HideInfoPopupNote(); |
|
460 break; |
|
461 } |
|
462 |
|
463 case EKeyUpArrow: |
|
464 { |
|
465 // Adjust crop point |
|
466 NaviUpL(); |
|
467 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
468 DrawNow(); |
|
469 response = EKeyWasConsumed; |
|
470 iPopupController->HideInfoPopupNote(); |
|
471 break; |
|
472 } |
|
473 |
|
474 case EKeyRightArrow: |
|
475 { |
|
476 // Adjust crop point |
|
477 NaviRightL(); |
|
478 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
479 DrawNow(); |
|
480 response = EKeyWasConsumed; |
|
481 iPopupController->HideInfoPopupNote(); |
|
482 break; |
|
483 } |
|
484 |
|
485 case EKeyLeftArrow: |
|
486 { |
|
487 // Adjust crop point |
|
488 NaviLeftL(); |
|
489 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
490 DrawNow(); |
|
491 response = EKeyWasConsumed; |
|
492 iPopupController->HideInfoPopupNote(); |
|
493 break; |
|
494 } |
|
495 |
|
496 case EKeyOK: |
|
497 case EKeyEnter: |
|
498 { |
|
499 StartDancingAntsTimer(); |
|
500 |
|
501 if ( iIsCropModeManual ) |
|
502 { |
|
503 |
|
504 if (iState == ECropStateFirst) |
|
505 { |
|
506 iState = ECropStateSecond; |
|
507 iEditorView->HandleCommandL (EImageEditorUpdateSoftkeys); |
|
508 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
509 DrawNow(); |
|
510 } |
|
511 else if (iState == ECropStateSecond) |
|
512 { |
|
513 iState = ECropStateMove; |
|
514 iEditorView->HandleCommandL (EImageEditorUpdateSoftkeys); |
|
515 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
516 DrawNow(); |
|
517 } |
|
518 else |
|
519 { |
|
520 iState = ECropStateMin; |
|
521 iReadyToRender = ETrue; |
|
522 iEditorView->HandleCommandL (EImageEditorResetZoom); |
|
523 |
|
524 if ( iULC == 0.00 && iULR == 0.00 && iLRC == 1.00 && iLRR == 1.00) |
|
525 { |
|
526 iEditorView->HandleCommandL (EImageEditorCancelPlugin); |
|
527 } |
|
528 else |
|
529 { |
|
530 iEditorView->HandleCommandL (EImageEditorApplyPlugin); |
|
531 } |
|
532 |
|
533 } |
|
534 response = EKeyWasConsumed; |
|
535 } |
|
536 else |
|
537 { |
|
538 if (iState == ECropStateFirst) |
|
539 { |
|
540 iState = ECropStateSecond; |
|
541 iEditorView->HandleCommandL (EImageEditorUpdateSoftkeys); |
|
542 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
543 DrawNow(); |
|
544 } |
|
545 else if (iState == ECropStateSecond) |
|
546 { |
|
547 iState = ECropStateMove; |
|
548 iEditorView->HandleCommandL (EImageEditorUpdateSoftkeys); |
|
549 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
550 DrawNow(); |
|
551 } |
|
552 else |
|
553 { |
|
554 ComputeCropParams(); |
|
555 iState = ECropStateMin; |
|
556 iReadyToRender = ETrue; |
|
557 iEditorView->HandleCommandL (EImageEditorResetZoom); |
|
558 if ( iULC == 0.00 && iULR == 0.00 && iLRC == 1.00 && iLRR == 1.00) |
|
559 { |
|
560 iEditorView->HandleCommandL (EImageEditorCancelPlugin); |
|
561 } |
|
562 else |
|
563 { |
|
564 iEditorView->HandleCommandL (EImageEditorApplyPlugin); |
|
565 } |
|
566 |
|
567 } |
|
568 response = EKeyWasConsumed; |
|
569 } |
|
570 break; |
|
571 } |
|
572 |
|
573 case 0x2a: // * |
|
574 case EStdKeyIncVolume: // zoom in key |
|
575 { |
|
576 |
|
577 // Check for minimum crop size |
|
578 TRect virect = iSysPars->VisibleImageRect(); |
|
579 TInt width = (TInt)((iLRC - iULC) * (virect.iBr.iX - virect.iTl.iX) + 0.5F); |
|
580 width = (TInt)(width * iSysPars->Scale() + 0.5); |
|
581 TInt height = (TInt)((iLRR - iULR) * (virect.iBr.iY - virect.iTl.iY) + 0.5F); |
|
582 height = (TInt)(height * iSysPars->Scale() + 0.5); |
|
583 |
|
584 TReal relscale = iSysPars->RelScale(); |
|
585 TInt minCrop = (TInt)(KMaxCropAbsoluteMin * relscale + 0.5); |
|
586 |
|
587 if ( (width <= minCrop) || (height <= minCrop) ) |
|
588 { |
|
589 response = EKeyWasConsumed; |
|
590 } |
|
591 |
|
592 // Store crop rectangle relative to screen |
|
593 StoreCropRelScreen(); |
|
594 break; |
|
595 } |
|
596 |
|
597 case 0x23: // # |
|
598 case EStdKeyDecVolume: // zoom out key |
|
599 { |
|
600 // Store crop rectangle relative to screen |
|
601 StoreCropRelScreen(); |
|
602 break; |
|
603 } |
|
604 |
|
605 // Consume rotation keys to disable rotation |
|
606 #ifndef LANDSCAPE_ROTATE_HOTKEYS |
|
607 case 0x31: // 1 |
|
608 #else |
|
609 case 0x33: // 3 |
|
610 #endif |
|
611 #ifndef LANDSCAPE_ROTATE_HOTKEYS |
|
612 case 0x33: // 3 |
|
613 #else |
|
614 case 0x39: // 9 |
|
615 #endif |
|
616 { |
|
617 response = EKeyWasConsumed; |
|
618 break; |
|
619 } |
|
620 |
|
621 default: |
|
622 { |
|
623 break; |
|
624 } |
|
625 } |
|
626 |
|
627 // If the device is really slow, it may happen that the timer |
|
628 // does not get execution time and slows down or halts completely. |
|
629 // (Ideally, this should not happen.) |
|
630 // This block is just to make sure that the cursor keeps moving |
|
631 // even if the timer halts. |
|
632 if (ETimerStarted == iFastKeyTimerState) |
|
633 { |
|
634 if (iTickCount > KDefaultFastKeyTimerMultiplyThresholdInTicks) |
|
635 { |
|
636 iNaviStepMultiplier = KDefaultBigNavigationStepMultiplier; |
|
637 } |
|
638 else |
|
639 { |
|
640 iTickCount++; |
|
641 } |
|
642 } |
|
643 } |
|
644 |
|
645 else if (EEventKey == aType && !iHandleEventKeys) |
|
646 { |
|
647 response = EKeyWasConsumed; |
|
648 } |
|
649 |
|
650 // EVENTKEYDOWN |
|
651 else if (EEventKeyDown == aType) |
|
652 { |
|
653 |
|
654 switch (aKeyEvent.iScanCode) |
|
655 { |
|
656 |
|
657 case EStdKeyLeftArrow: |
|
658 case EStdKeyRightArrow: |
|
659 case EStdKeyUpArrow: |
|
660 case EStdKeyDownArrow: |
|
661 { |
|
662 iPressedKeyScanCode = aKeyEvent.iScanCode; |
|
663 StartFastKeyTimer(); |
|
664 response = EKeyWasConsumed; |
|
665 break; |
|
666 } |
|
667 default: |
|
668 break; |
|
669 } |
|
670 } |
|
671 |
|
672 // EVENTKEYUP |
|
673 else if (EEventKeyUp == aType) |
|
674 { |
|
675 if (aKeyEvent.iScanCode == iPressedKeyScanCode) |
|
676 { |
|
677 iHandleEventKeys = ETrue; |
|
678 iFastKeyTimerState = ETimerInactive; |
|
679 StartDancingAntsTimer(); |
|
680 response = EKeyWasConsumed; |
|
681 ShowTooltip(); |
|
682 } |
|
683 } |
|
684 |
|
685 return response; |
|
686 } |
|
687 |
|
688 //============================================================================= |
|
689 void CImageEditorCropControl::SizeChanged() |
|
690 { |
|
691 LOG(KCropPluginLogFile, "CImageEditorCropControl::SizeChanged()"); |
|
692 |
|
693 } |
|
694 |
|
695 //============================================================================= |
|
696 TDesC & CImageEditorCropControl::GetParam () |
|
697 { |
|
698 LOG(KCropPluginLogFile, "CImageEditorCropControl::GetParam()"); |
|
699 |
|
700 // Do not set crop paramater before valid area is selected, |
|
701 // otherwise preview image is cropped when zooming or panning |
|
702 if (iReadyToRender) |
|
703 { |
|
704 iParam.Copy (_L("x1 ")); |
|
705 iParam.AppendNum (iCropX); |
|
706 iParam.Append (_L(" y1 ")); |
|
707 iParam.AppendNum (iCropY); |
|
708 iParam.Append (_L(" x2 ")); |
|
709 iParam.AppendNum (iCropX + iCropW); |
|
710 iParam.Append (_L(" y2 ")); |
|
711 iParam.AppendNum (iCropY + iCropH); |
|
712 } |
|
713 return iParam; |
|
714 } |
|
715 |
|
716 //============================================================================= |
|
717 void CImageEditorCropControl::SetSystemParameters ( const CSystemParameters * aPars) |
|
718 { |
|
719 LOG(KCropPluginLogFile, "CImageEditorCropControl::SetSystemParameters()"); |
|
720 iSysPars = aPars; |
|
721 } |
|
722 |
|
723 //============================================================================= |
|
724 void CImageEditorCropControl::SetCropModeL ( |
|
725 const TInt aMode, |
|
726 const float aRatio |
|
727 ) |
|
728 { |
|
729 LOG(KCropPluginLogFile, "CImageEditorCropControl::SetCropModeL()"); |
|
730 |
|
731 // Store crop mode |
|
732 iIsCropModeManual = (aMode == 0); |
|
733 |
|
734 // Store wanted aspect ratio |
|
735 iCropRatio = aRatio; |
|
736 |
|
737 // Set initial points according to the cropping mode (aspect ratio) |
|
738 SetInitialPointsL (); |
|
739 // Shows the first tooltip when the plugin is entered |
|
740 ShowTooltip(); |
|
741 } |
|
742 |
|
743 //============================================================================= |
|
744 void CImageEditorCropControl::HandlePluginCommandL (const TInt aCommand) |
|
745 { |
|
746 LOGFMT(KCropPluginLogFile, "CImageEditorCropControl::HandlePluginCommandL(), aCommand = %d", aCommand); |
|
747 |
|
748 switch (aCommand) |
|
749 { |
|
750 |
|
751 // Control focus gained, start dancing ants timer |
|
752 case EImageEditorFocusGained: |
|
753 { |
|
754 StartDancingAntsTimer(); |
|
755 break; |
|
756 } |
|
757 |
|
758 // Control focus lost, stop dancing ants timer |
|
759 case EImageEditorFocusLost: |
|
760 { |
|
761 if (iTimer) |
|
762 { |
|
763 iTimer->Cancel(); |
|
764 } |
|
765 break; |
|
766 } |
|
767 |
|
768 // Visible image area changes => update crop parameters and |
|
769 // screen buffer |
|
770 case EImageEditorGlobalZoomChanged: |
|
771 case EImageEditorGlobalPanChanged: |
|
772 case EImageEditorGlobalRotationChanged: |
|
773 case EImageEditorPostScreenModeChange: |
|
774 { |
|
775 |
|
776 if ( aCommand == EImageEditorGlobalZoomChanged ) |
|
777 { |
|
778 RestoreCropRelScreen(); |
|
779 UpdateCropRectangle(); |
|
780 } |
|
781 else if ( aCommand == EImageEditorPostScreenModeChange ) |
|
782 { |
|
783 RestoreCropRelImage(); |
|
784 UpdateCropRectangle(); |
|
785 } |
|
786 |
|
787 #ifdef DOUBLE_BUFFERED_CROP |
|
788 |
|
789 ClonePreviewBitmapL(); |
|
790 DarkenUnselectedAreaL(); |
|
791 DrawNow(); |
|
792 |
|
793 #endif // DOUBLE_BUFFERED_CROP |
|
794 |
|
795 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
796 DrawNow(); |
|
797 break; |
|
798 } |
|
799 |
|
800 // Set softkey |
|
801 case EPgnSoftkeyIdSet: |
|
802 { |
|
803 if (iState == ECropStateFirst) |
|
804 { |
|
805 iState = ECropStateSecond; |
|
806 } |
|
807 else |
|
808 { |
|
809 iState = ECropStateMove; |
|
810 } |
|
811 iEditorView->HandleCommandL (EImageEditorUpdateSoftkeys); |
|
812 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
813 DrawNow(); |
|
814 ShowTooltip(); |
|
815 break; |
|
816 } |
|
817 |
|
818 // Done softkey |
|
819 case EPgnSoftkeyIdDone: |
|
820 { |
|
821 ComputeCropParams(); |
|
822 iState = ECropStateMin; |
|
823 iReadyToRender = ETrue; |
|
824 iEditorView->HandleCommandL (EImageEditorResetZoom); |
|
825 if ( iULC == 0.00 && iULR == 0.00 && iLRC == 1.00 && iLRR == 1.00) |
|
826 { |
|
827 iEditorView->HandleCommandL (EImageEditorCancelPlugin); |
|
828 } |
|
829 else |
|
830 { |
|
831 iEditorView->HandleCommandL (EImageEditorApplyPlugin); |
|
832 } |
|
833 |
|
834 break; |
|
835 } |
|
836 |
|
837 // Cancel softkey |
|
838 case EPgnSoftkeyIdCancel: |
|
839 { |
|
840 iEditorView->HandleCommandL (EImageEditorResetZoom); |
|
841 iEditorView->HandleCommandL (EImageEditorCancelPlugin); |
|
842 break; |
|
843 } |
|
844 |
|
845 // Back softkey |
|
846 case EPgnSoftkeyIdBack: |
|
847 { |
|
848 if (iState == ECropStateSecond) |
|
849 { |
|
850 iState = ECropStateFirst; |
|
851 } |
|
852 else |
|
853 { |
|
854 iState = ECropStateSecond; |
|
855 } |
|
856 iEditorView->HandleCommandL (EImageEditorUpdateSoftkeys); |
|
857 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
858 DrawNow(); |
|
859 ShowTooltip(); |
|
860 break; |
|
861 } |
|
862 |
|
863 // Screen mode changed (portrait, portrait full, landscape, landscape full) |
|
864 case EImageEditorPreScreenModeChange: |
|
865 { |
|
866 // Store crop rectangle relative to image |
|
867 StoreCropRelImage(); |
|
868 break; |
|
869 } |
|
870 |
|
871 default: |
|
872 { |
|
873 break; |
|
874 } |
|
875 } |
|
876 } |
|
877 |
|
878 //============================================================================= |
|
879 TInt CImageEditorCropControl::GetSoftkeyIndexL() |
|
880 { |
|
881 LOG(KCropPluginLogFile, "CImageEditorCropControl::GetSoftkeyIndexL()"); |
|
882 |
|
883 switch (iState) |
|
884 { |
|
885 case ECropStateFirst: |
|
886 { |
|
887 return 0; |
|
888 } |
|
889 case ECropStateSecond: |
|
890 { |
|
891 return 2; |
|
892 } |
|
893 case ECropStateMove: |
|
894 { |
|
895 return 1; |
|
896 } |
|
897 case ECropStateMinCrop: |
|
898 { |
|
899 return 3; // empty - cancel |
|
900 } |
|
901 default: |
|
902 { |
|
903 return -1; |
|
904 } |
|
905 } |
|
906 } |
|
907 |
|
908 //============================================================================= |
|
909 TPtrC CImageEditorCropControl::GetNaviPaneTextL ( |
|
910 TBool& aLeftNaviPaneScrollButtonVisibile, |
|
911 TBool& aRightNaviPaneScrollButtonVisible ) |
|
912 { |
|
913 LOG(KCropPluginLogFile, "CImageEditorCropControl::GetNaviPaneTextL()"); |
|
914 |
|
915 aLeftNaviPaneScrollButtonVisibile = EFalse; |
|
916 aRightNaviPaneScrollButtonVisible = EFalse; |
|
917 |
|
918 |
|
919 // Update parameters - needed for the zoom update |
|
920 ComputeCropParams(); |
|
921 |
|
922 // Getting string from resources |
|
923 TPtrC ptr = iItem->Parameters()[KStatusPaneTextAreaIndex]; |
|
924 |
|
925 // Compute scaled width and height |
|
926 TReal width = iSysPars->Scale() * iCropW; |
|
927 TReal height = iSysPars->Scale() * iCropH; |
|
928 |
|
929 // Convert the width and height relative to the |
|
930 TReal relscale = iSysPars->RelScale(); |
|
931 TInt scaledWidth = (TInt)((width / relscale) + 0.5); |
|
932 TInt scaledHeight = (TInt)((height / relscale) + 0.5); |
|
933 |
|
934 iNaviPaneText.Zero(); |
|
935 |
|
936 // Generate string to be added to %U |
|
937 TBuf< 20 > valueStr; |
|
938 |
|
939 valueStr.AppendNum( scaledWidth ); |
|
940 valueStr.Append( KCropNaviTextSeparator ); |
|
941 valueStr.AppendNum( scaledHeight ); |
|
942 AknTextUtils::LanguageSpecificNumberConversion ( valueStr ); |
|
943 |
|
944 StringLoader::Format( iNaviPaneText, ptr, -1, valueStr ); |
|
945 |
|
946 CalculateMinCrop(); |
|
947 return iNaviPaneText; |
|
948 } |
|
949 |
|
950 //============================================================================= |
|
951 void CImageEditorCropControl::ComputeCropParams() |
|
952 { |
|
953 |
|
954 LOG(KCropPluginLogFile, "CImageEditorCropControl::ComputeCropParams()"); |
|
955 |
|
956 TRect virect = iSysPars->VisibleImageRect(); |
|
957 |
|
958 TInt w = (virect.iBr.iX - virect.iTl.iX); |
|
959 TInt h = (virect.iBr.iY - virect.iTl.iY); |
|
960 |
|
961 TInt ulc = (TInt)(iULC * w + 0.5); |
|
962 TInt ulr = (TInt)(iULR * h + 0.5); |
|
963 TInt lrc = (TInt)(iLRC * w + 0.5); |
|
964 TInt lrr = (TInt)(iLRR * h + 0.5); |
|
965 |
|
966 // Set parameter struct |
|
967 w = lrc - ulc; |
|
968 h = lrr - ulr; |
|
969 iCropX = iSysPars->VisibleImageRect().iTl.iX + ulc; |
|
970 iCropY = iSysPars->VisibleImageRect().iTl.iY + ulr; |
|
971 iCropW = w; |
|
972 if (iCropX + w > virect.iBr.iX) |
|
973 { |
|
974 iCropW = virect.iBr.iX - iCropX; |
|
975 } |
|
976 iCropH = h; |
|
977 if (iCropY + h > virect.iBr.iY) |
|
978 { |
|
979 iCropH = virect.iBr.iY - iCropY; |
|
980 } |
|
981 } |
|
982 |
|
983 //============================================================================= |
|
984 void CImageEditorCropControl::NaviDownL() |
|
985 { |
|
986 |
|
987 LOG(KCropPluginLogFile, "CImageEditorCropControl::NaviDownL()"); |
|
988 |
|
989 // MANUAL MODE |
|
990 if (iIsCropModeManual) |
|
991 { |
|
992 |
|
993 // FIRST: UPPER LEFT CORNER |
|
994 if (iState == ECropStateFirst) |
|
995 { |
|
996 iULR += (KParamStep * iNaviStepMultiplier); |
|
997 if (iULR > iLRR - iMinY) |
|
998 { |
|
999 iULR = iLRR - iMinY; |
|
1000 } |
|
1001 } |
|
1002 |
|
1003 // SECOND: LOWER RIGHT CORNER |
|
1004 else if (iState == ECropStateSecond) |
|
1005 { |
|
1006 iLRR += (KParamStep * iNaviStepMultiplier); |
|
1007 if (iLRR > 1.0) |
|
1008 { |
|
1009 iLRR = 1.0; |
|
1010 } |
|
1011 } |
|
1012 // MOVE (ADDED FOR MANUAL) |
|
1013 else |
|
1014 { |
|
1015 float old = iLRR; |
|
1016 iLRR += (KParamStep * iNaviStepMultiplier); |
|
1017 if (iLRR > 1.0) |
|
1018 { |
|
1019 iLRR = 1.0; |
|
1020 } |
|
1021 iULR += (iLRR - old); |
|
1022 } |
|
1023 } |
|
1024 |
|
1025 // ASPECT RATIO PRESERVING MODE |
|
1026 else |
|
1027 { |
|
1028 |
|
1029 // FIRST: UPPER LEFT CORNER |
|
1030 if (iState == ECropStateFirst) |
|
1031 { |
|
1032 if ( ((iLRC - iULC) > iMinX) && ((iLRR - iULR) > iMinY) ) |
|
1033 { |
|
1034 iULR += (KParamStep * iNaviStepMultiplier); |
|
1035 if (iULR > iLRR - iMinY) |
|
1036 { |
|
1037 iULR = iLRR - iMinY; |
|
1038 } |
|
1039 ComputePreservedULC(); |
|
1040 if (iULC > iLRC - iMinX) |
|
1041 { |
|
1042 iULC = iLRC - iMinX; |
|
1043 } |
|
1044 } |
|
1045 } |
|
1046 |
|
1047 // SECOND: LOWER RIGHT CORNER |
|
1048 else if (iState == ECropStateSecond) |
|
1049 { |
|
1050 iLRR += (KParamStep * iNaviStepMultiplier); |
|
1051 if (iLRR > 1.0) |
|
1052 { |
|
1053 iLRR = 1.0; |
|
1054 } |
|
1055 ComputePreservedLRC(); |
|
1056 if (iLRC > 1.0) |
|
1057 { |
|
1058 iLRC = 1.0; |
|
1059 ComputePreservedLRR(); |
|
1060 } |
|
1061 } |
|
1062 |
|
1063 // MOVE (ONLY WITH ASPECT RATIO PRESERVING) |
|
1064 // NOWADAYS ALSO WITH MANUAL |
|
1065 else |
|
1066 { |
|
1067 float old = iLRR; |
|
1068 iLRR += (KParamStep * iNaviStepMultiplier); |
|
1069 if (iLRR > 1.0) |
|
1070 { |
|
1071 iLRR = 1.0; |
|
1072 } |
|
1073 iULR += (iLRR - old); |
|
1074 } |
|
1075 } |
|
1076 ComputeCropParams(); |
|
1077 |
|
1078 #ifdef DOUBLE_BUFFERED_CROP |
|
1079 |
|
1080 if (iState == ECropStateSecond || iState == ECropStateMove) |
|
1081 { |
|
1082 ClonePreviewBitmapL(); |
|
1083 } |
|
1084 |
|
1085 DarkenUnselectedAreaL(); |
|
1086 DrawNow(); |
|
1087 |
|
1088 #endif // DOUBLE_BUFFERED_CROP |
|
1089 |
|
1090 } |
|
1091 |
|
1092 //============================================================================= |
|
1093 void CImageEditorCropControl::NaviUpL() |
|
1094 { |
|
1095 |
|
1096 LOG(KCropPluginLogFile, "CImageEditorCropControl::NaviUpL()"); |
|
1097 |
|
1098 // MANUAL MODE |
|
1099 if (iIsCropModeManual) |
|
1100 { |
|
1101 |
|
1102 // FIRST: UPPER LEFT CORNER |
|
1103 if (iState == ECropStateFirst) |
|
1104 { |
|
1105 iULR -= (KParamStep * iNaviStepMultiplier); |
|
1106 if (iULR < 0.0) |
|
1107 { |
|
1108 iULR = 0.0; |
|
1109 } |
|
1110 } |
|
1111 |
|
1112 // SECOND: LOWER RIGHT CORNER |
|
1113 else if (iState == ECropStateSecond) |
|
1114 { |
|
1115 iLRR -= (KParamStep * iNaviStepMultiplier); |
|
1116 if (iLRR < iULR + iMinY) |
|
1117 { |
|
1118 iLRR = iULR + iMinY; |
|
1119 } |
|
1120 } |
|
1121 // MOVE (ADDED FOR MANUAL) |
|
1122 else |
|
1123 { |
|
1124 float old = iULR; |
|
1125 iULR -= (KParamStep * iNaviStepMultiplier); |
|
1126 if (iULR < 0.0) |
|
1127 { |
|
1128 iULR = 0.0; |
|
1129 } |
|
1130 iLRR -= (old - iULR); |
|
1131 } |
|
1132 } |
|
1133 |
|
1134 // ASPECT RATIO PRESERVING MODE |
|
1135 else |
|
1136 { |
|
1137 |
|
1138 // FIRST: UPPER LEFT CORNER |
|
1139 if (iState == ECropStateFirst) |
|
1140 { |
|
1141 iULR -= (KParamStep * iNaviStepMultiplier); |
|
1142 if (iULR < 0.0) |
|
1143 { |
|
1144 iULR = 0.0; |
|
1145 } |
|
1146 ComputePreservedULC(); |
|
1147 if (iULC < 0.0) |
|
1148 { |
|
1149 iULC = 0.0; |
|
1150 ComputePreservedULR(); |
|
1151 } |
|
1152 } |
|
1153 |
|
1154 // SECOND: LOWER RIGHT CORNER |
|
1155 else if (iState == ECropStateSecond) |
|
1156 { |
|
1157 if ( ((iLRC - iULC) > iMinX) && ((iLRR - iULR) > iMinY) ) |
|
1158 { |
|
1159 iLRR -= (KParamStep * iNaviStepMultiplier); |
|
1160 if ((iLRR - iULR) < iMinY) |
|
1161 { |
|
1162 iLRR = iULR + iMinY; |
|
1163 } |
|
1164 ComputePreservedLRC(); |
|
1165 if ((iLRC - iULC) < iMinX) |
|
1166 { |
|
1167 iLRC = iULC + iMinX; |
|
1168 } |
|
1169 } |
|
1170 } |
|
1171 |
|
1172 // MOVE (ONLY WITH ASPECT RATIO PRESERVING) |
|
1173 // NOWADAYS ALSO WITH MANUAL |
|
1174 else |
|
1175 { |
|
1176 float old = iULR; |
|
1177 iULR -= (KParamStep * iNaviStepMultiplier); |
|
1178 if (iULR < 0.0) |
|
1179 { |
|
1180 iULR = 0.0; |
|
1181 } |
|
1182 iLRR -= (old - iULR); |
|
1183 } |
|
1184 } |
|
1185 ComputeCropParams(); |
|
1186 |
|
1187 #ifdef DOUBLE_BUFFERED_CROP |
|
1188 |
|
1189 if (iState == ECropStateFirst || iState == ECropStateMove) |
|
1190 { |
|
1191 ClonePreviewBitmapL(); |
|
1192 } |
|
1193 |
|
1194 DarkenUnselectedAreaL(); |
|
1195 DrawNow(); |
|
1196 |
|
1197 #endif // DOUBLE_BUFFERED_CROP |
|
1198 |
|
1199 } |
|
1200 |
|
1201 //============================================================================= |
|
1202 void CImageEditorCropControl::NaviRightL() |
|
1203 { |
|
1204 |
|
1205 LOG(KCropPluginLogFile, "CImageEditorCropControl::NaviRightL()"); |
|
1206 |
|
1207 // MANUAL MODE |
|
1208 if (iIsCropModeManual) |
|
1209 { |
|
1210 |
|
1211 // FIRST: UPPER LEFT CORNER |
|
1212 if (iState == ECropStateFirst) |
|
1213 { |
|
1214 iULC += (KParamStep * iNaviStepMultiplier); |
|
1215 if (iULC > iLRC - iMinX) |
|
1216 { |
|
1217 iULC = iLRC - iMinX; |
|
1218 } |
|
1219 } |
|
1220 |
|
1221 // SECOND: LOWER RIGHT CORNER |
|
1222 else if (iState == ECropStateSecond) |
|
1223 { |
|
1224 iLRC += (KParamStep * iNaviStepMultiplier); |
|
1225 if (iLRC > 1.0) |
|
1226 { |
|
1227 iLRC = 1.0; |
|
1228 } |
|
1229 } |
|
1230 // MOVE (ADDED FOR MANUAL) |
|
1231 else if (iState == ECropStateMove) |
|
1232 { |
|
1233 float old = iLRC; |
|
1234 iLRC += (KParamStep * iNaviStepMultiplier); |
|
1235 if (iLRC > 1.0) |
|
1236 { |
|
1237 iLRC = 1.0; |
|
1238 } |
|
1239 iULC += (iLRC - old); |
|
1240 } |
|
1241 } |
|
1242 |
|
1243 // ASPECT RATIO PRESERVING MODE |
|
1244 else |
|
1245 { |
|
1246 |
|
1247 // MOVE (ONLY WITH ASPECT RATIO PRESERVING) |
|
1248 // NOWADAYS ALSO WITH MANUAL |
|
1249 if (iState == ECropStateMove) |
|
1250 { |
|
1251 float old = iLRC; |
|
1252 iLRC += (KParamStep * iNaviStepMultiplier); |
|
1253 if (iLRC > 1.0) |
|
1254 { |
|
1255 iLRC = 1.0; |
|
1256 } |
|
1257 iULC += (iLRC - old); |
|
1258 } |
|
1259 } |
|
1260 ComputeCropParams(); |
|
1261 |
|
1262 #ifdef DOUBLE_BUFFERED_CROP |
|
1263 |
|
1264 if (iState == ECropStateSecond || iState == ECropStateMove) |
|
1265 { |
|
1266 ClonePreviewBitmapL(); |
|
1267 } |
|
1268 |
|
1269 DarkenUnselectedAreaL(); |
|
1270 DrawNow(); |
|
1271 |
|
1272 #endif // DOUBLE_BUFFERED_CROP |
|
1273 |
|
1274 } |
|
1275 |
|
1276 //============================================================================= |
|
1277 void CImageEditorCropControl::NaviLeftL() |
|
1278 { |
|
1279 |
|
1280 LOG(KCropPluginLogFile, "CImageEditorCropControl::NaviLeftL()"); |
|
1281 |
|
1282 // MANUAL MODE |
|
1283 if (iIsCropModeManual) |
|
1284 { |
|
1285 |
|
1286 // FIRST: UPPER LEFT CORNER |
|
1287 if (iState == ECropStateFirst) |
|
1288 { |
|
1289 iULC -= (KParamStep * iNaviStepMultiplier); |
|
1290 if (iULC < 0.0) |
|
1291 { |
|
1292 iULC = 0.0; |
|
1293 } |
|
1294 } |
|
1295 |
|
1296 // SECOND: LOWER RIGHT CORNER |
|
1297 else if (iState == ECropStateSecond) |
|
1298 { |
|
1299 iLRC -= (KParamStep * iNaviStepMultiplier); |
|
1300 if (iLRC < iULC + iMinX) |
|
1301 { |
|
1302 iLRC = iULC + iMinX; |
|
1303 } |
|
1304 } |
|
1305 // MOVE (ADDED FOR MANUAL) |
|
1306 else if (iState == ECropStateMove) |
|
1307 { |
|
1308 float old = iULC; |
|
1309 iULC -= (KParamStep * iNaviStepMultiplier); |
|
1310 if (iULC < 0.0) |
|
1311 { |
|
1312 iULC = 0.0; |
|
1313 } |
|
1314 iLRC -= (old - iULC); |
|
1315 } |
|
1316 } |
|
1317 |
|
1318 // ASPECT RATIO PRESERVING MODE |
|
1319 else |
|
1320 { |
|
1321 |
|
1322 // MOVE (ONLY WITH ASPECT RATIO PRESERVING) |
|
1323 // NOWADAYS ALSO WITH MANUAL |
|
1324 if (iState == ECropStateMove) |
|
1325 { |
|
1326 float old = iULC; |
|
1327 iULC -= (KParamStep * iNaviStepMultiplier); |
|
1328 if (iULC < 0.0) |
|
1329 { |
|
1330 iULC = 0.0; |
|
1331 } |
|
1332 iLRC -= (old - iULC); |
|
1333 } |
|
1334 } |
|
1335 ComputeCropParams(); |
|
1336 |
|
1337 #ifdef DOUBLE_BUFFERED_CROP |
|
1338 |
|
1339 if (iState == ECropStateFirst || iState == ECropStateMove) |
|
1340 { |
|
1341 ClonePreviewBitmapL(); |
|
1342 } |
|
1343 |
|
1344 DarkenUnselectedAreaL(); |
|
1345 DrawNow(); |
|
1346 |
|
1347 #endif // DOUBLE_BUFFERED_CROP |
|
1348 |
|
1349 } |
|
1350 |
|
1351 //============================================================================= |
|
1352 void CImageEditorCropControl::SetInitialPointsL () |
|
1353 { |
|
1354 |
|
1355 LOG(KCropPluginLogFile, "CImageEditorCropControl::SetInitialPointsL()"); |
|
1356 |
|
1357 const TSize vps = iSysPars->ViewPortRect().Size(); |
|
1358 if (vps.iWidth <= KMinSourceSize || vps.iHeight <= KMinSourceSize) |
|
1359 { |
|
1360 iULC = 0.00F; |
|
1361 iULR = 0.00F; |
|
1362 iLRC = 1.00F; |
|
1363 iLRR = 1.00F; |
|
1364 iState = ECropStateMinCrop; |
|
1365 } |
|
1366 |
|
1367 // MANUAL |
|
1368 else if (iIsCropModeManual) |
|
1369 { |
|
1370 iULC = 0.02F; |
|
1371 iULR = 0.02F; |
|
1372 iLRC = 0.98F; |
|
1373 iLRR = 0.98F; |
|
1374 } |
|
1375 |
|
1376 // ASPECT RATIO PRESERVED |
|
1377 else |
|
1378 { |
|
1379 |
|
1380 TRect virect = iSysPars->VisibleImageRect(); |
|
1381 TInt width = (virect.iBr.iX - virect.iTl.iX); |
|
1382 TInt height = (virect.iBr.iY - virect.iTl.iY); |
|
1383 |
|
1384 float current = (float)width / (float)height; |
|
1385 |
|
1386 if (iCropRatio > current) |
|
1387 { |
|
1388 float tmp = 0.5F * (current / iCropRatio); |
|
1389 iULC = 0.0F; |
|
1390 iULR = 0.5F - tmp; |
|
1391 iLRC = 1.0F; |
|
1392 iLRR = 0.5F + tmp; |
|
1393 } |
|
1394 else |
|
1395 { |
|
1396 float tmp = 0.5F * (iCropRatio / current); |
|
1397 iULC = 0.5F - tmp; |
|
1398 iULR = 0.0F; |
|
1399 iLRC = 0.5F + tmp; |
|
1400 iLRR = 1.0F; |
|
1401 } |
|
1402 } |
|
1403 |
|
1404 ComputeCropParams(); |
|
1405 StoreCropRelScreen(); |
|
1406 |
|
1407 #ifdef DOUBLE_BUFFERED_CROP |
|
1408 |
|
1409 DarkenUnselectedAreaL(); |
|
1410 DrawNow(); |
|
1411 |
|
1412 #endif // DOUBLE_BUFFERED_CROP |
|
1413 |
|
1414 } |
|
1415 |
|
1416 //============================================================================= |
|
1417 void CImageEditorCropControl::StartDancingAntsTimer() |
|
1418 { |
|
1419 |
|
1420 LOG(KCropPluginLogFile, "CImageEditorCropControl::StartDancingAntsTimer()"); |
|
1421 |
|
1422 if (iTimer) |
|
1423 { |
|
1424 iTimer->Cancel(); |
|
1425 iTimer->Start( |
|
1426 TTimeIntervalMicroSeconds32 (KDancingAntzTimerDelayInMicroseconds), |
|
1427 TTimeIntervalMicroSeconds32 (KDancingAntzTimerIntervalInMicroseconds), |
|
1428 TCallBack (DancingAntsCallback, this) |
|
1429 ); |
|
1430 } |
|
1431 } |
|
1432 |
|
1433 //============================================================================= |
|
1434 void CImageEditorCropControl::StartFastKeyTimer() |
|
1435 { |
|
1436 |
|
1437 LOG(KCropPluginLogFile, "CImageEditorCropControl::StartFastKeyTimer()"); |
|
1438 |
|
1439 iNaviStepMultiplier = KDefaultSmallNavigationStepMultiplier; |
|
1440 iTickCount = 0; |
|
1441 iFastKeyTimerState = ETimerStarted; |
|
1442 |
|
1443 if (iTimer) |
|
1444 { |
|
1445 iTimer->Cancel(); |
|
1446 iTimer->Start( |
|
1447 TTimeIntervalMicroSeconds32 (KCropFastKeyTimerDelayInMicroseconds), |
|
1448 TTimeIntervalMicroSeconds32 (KDefaultFastKeyTimerIntervalInMicroseconds), |
|
1449 TCallBack (FastKeyCallback, this) |
|
1450 ); |
|
1451 } |
|
1452 } |
|
1453 |
|
1454 //============================================================================= |
|
1455 void CImageEditorCropControl::OnDancingAntsCallBack() |
|
1456 { |
|
1457 iAntFlag = !iAntFlag; |
|
1458 ActivateGc(); |
|
1459 DrawDancingAnts (Rect()); |
|
1460 DeactivateGc(); |
|
1461 } |
|
1462 |
|
1463 //============================================================================= |
|
1464 void CImageEditorCropControl::OnFastKeyCallBackL() |
|
1465 { |
|
1466 if (iTickCount > KDefaultFastKeyTimerMultiplyThresholdInTicks) |
|
1467 { |
|
1468 iNaviStepMultiplier = KDefaultBigNavigationStepMultiplier; |
|
1469 } |
|
1470 else |
|
1471 { |
|
1472 iTickCount++; |
|
1473 } |
|
1474 |
|
1475 // If first time here, reset the tick counter. |
|
1476 if (ETimerStarted == iFastKeyTimerState) |
|
1477 { |
|
1478 iFastKeyTimerState = ETimerRunning; |
|
1479 iTickCount = 0; |
|
1480 } |
|
1481 |
|
1482 iHandleEventKeys = EFalse; |
|
1483 |
|
1484 switch (iPressedKeyScanCode) |
|
1485 { |
|
1486 case EStdKeyDownArrow: |
|
1487 { |
|
1488 NaviDownL(); |
|
1489 break; |
|
1490 } |
|
1491 case EStdKeyUpArrow: |
|
1492 { |
|
1493 NaviUpL(); |
|
1494 break; |
|
1495 } |
|
1496 case EStdKeyLeftArrow: |
|
1497 { |
|
1498 NaviLeftL(); |
|
1499 break; |
|
1500 } |
|
1501 case EStdKeyRightArrow: |
|
1502 { |
|
1503 NaviRightL(); |
|
1504 break; |
|
1505 } |
|
1506 default: |
|
1507 break; |
|
1508 } |
|
1509 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
1510 DrawNow(); |
|
1511 } |
|
1512 |
|
1513 //============================================================================= |
|
1514 TBool CImageEditorCropControl::IsReadyToRender() const |
|
1515 { |
|
1516 LOG(KCropPluginLogFile, "CImageEditorCropControl::IsReadyToRender()"); |
|
1517 |
|
1518 // Always ready to render. However selected crop are is not set in GetParam()¨ |
|
1519 // until closing the plug-in. |
|
1520 return ETrue; |
|
1521 } |
|
1522 |
|
1523 //============================================================================= |
|
1524 void CImageEditorCropControl::CalculateMinCrop() |
|
1525 { |
|
1526 LOG(KCropPluginLogFile, "CImageEditorCropControl::CalculateMinCrop()"); |
|
1527 |
|
1528 TInt im_width = (iSysPars->VisibleImageRect().iBr.iX - iSysPars->VisibleImageRect().iTl.iX); |
|
1529 im_width = (TInt)(im_width * iSysPars->Scale() + 0.5); |
|
1530 TInt im_height = (iSysPars->VisibleImageRect().iBr.iY - iSysPars->VisibleImageRect().iTl.iY); |
|
1531 im_height = (TInt)(im_height * iSysPars->Scale() + 0.5); |
|
1532 TInt im_maxdim = (im_width < im_height) ? (im_height) : (im_width); |
|
1533 |
|
1534 TInt im_min_crop_rel = (TInt)(KMinCropRelDistFrac * im_maxdim + 0.5F); |
|
1535 TInt im_min_crop_abs = KMaxCropAbsoluteMin; |
|
1536 TInt im_maxcrop = (im_min_crop_rel > im_min_crop_abs) ? |
|
1537 (im_min_crop_rel) : (im_min_crop_abs); |
|
1538 |
|
1539 TReal relscale = iSysPars->RelScale(); |
|
1540 TInt image_maxcrop_prev = (TInt)(im_maxcrop * relscale + 0.5); |
|
1541 |
|
1542 iMinX = (float)image_maxcrop_prev / (float)im_width; |
|
1543 iMinY = (float)image_maxcrop_prev / (float)im_height; |
|
1544 } |
|
1545 |
|
1546 //============================================================================= |
|
1547 void CImageEditorCropControl::ComputePreservedULC() |
|
1548 { |
|
1549 LOG(KCropPluginLogFile, "CImageEditorCropControl::ComputePreservedULC()"); |
|
1550 |
|
1551 TRect virect = iSysPars->VisibleImageRect(); |
|
1552 TInt viwidth = (virect.iBr.iX - virect.iTl.iX); |
|
1553 TInt viheight = (virect.iBr.iY - virect.iTl.iY); |
|
1554 iULC = (iLRC * viwidth - iCropRatio * ((iLRR - iULR) * viheight)) / viwidth; |
|
1555 } |
|
1556 |
|
1557 //============================================================================= |
|
1558 void CImageEditorCropControl::ComputePreservedLRC() |
|
1559 { |
|
1560 LOG(KCropPluginLogFile, "CImageEditorCropControl::ComputePreservedLRC()"); |
|
1561 |
|
1562 TRect virect = iSysPars->VisibleImageRect(); |
|
1563 TInt viwidth = (virect.iBr.iX - virect.iTl.iX); |
|
1564 TInt viheight =(virect.iBr.iY - virect.iTl.iY); |
|
1565 iLRC = (iULC * viwidth + iCropRatio * ((iLRR - iULR) * viheight)) / viwidth; |
|
1566 } |
|
1567 |
|
1568 //============================================================================= |
|
1569 void CImageEditorCropControl::ComputePreservedULR() |
|
1570 { |
|
1571 LOG(KCropPluginLogFile, "CImageEditorCropControl::ComputePreservedULR()"); |
|
1572 |
|
1573 TRect virect = iSysPars->VisibleImageRect(); |
|
1574 TInt viwidth = (virect.iBr.iX - virect.iTl.iX); |
|
1575 TInt viheight =(virect.iBr.iY - virect.iTl.iY); |
|
1576 iULR = (iLRR * viheight - (((iLRC - iULC) * viwidth) / iCropRatio)) / viheight; |
|
1577 } |
|
1578 |
|
1579 //============================================================================= |
|
1580 void CImageEditorCropControl::ComputePreservedLRR() |
|
1581 { |
|
1582 LOG(KCropPluginLogFile, "CImageEditorCropControl::ComputePreservedLRR()"); |
|
1583 |
|
1584 TRect virect = iSysPars->VisibleImageRect(); |
|
1585 TInt viwidth = (virect.iBr.iX - virect.iTl.iX); |
|
1586 TInt viheight =(virect.iBr.iY - virect.iTl.iY); |
|
1587 iLRR = (iULR * viheight + (((iLRC - iULC) * viwidth) / iCropRatio)) / viheight; |
|
1588 } |
|
1589 |
|
1590 #ifdef DOUBLE_BUFFERED_CROP |
|
1591 |
|
1592 //============================================================================= |
|
1593 void CImageEditorCropControl::ClonePreviewBitmapL() |
|
1594 { |
|
1595 |
|
1596 LOG(KCropPluginLogFile, "CImageEditorCropControl::ClonePreviewBitmapL()"); |
|
1597 |
|
1598 TBitmapUtil bmptls (iPrevBitmap); |
|
1599 bmptls.Begin(TPoint(0,0)); |
|
1600 |
|
1601 TSize size = iPrevBitmap->SizeInPixels(); |
|
1602 TDisplayMode dmode = iPrevBitmap->DisplayMode(); |
|
1603 |
|
1604 TInt bufsize = size.iHeight * iPrevBitmap->ScanLineLength (size.iWidth, dmode); |
|
1605 TUint8 * ps = (TUint8*)( iPrevBitmap->DataAddress() ); |
|
1606 TUint8 * pd = (TUint8*)( iBufBitmap->DataAddress() ); |
|
1607 Mem::Copy (pd, ps, bufsize); |
|
1608 |
|
1609 bmptls.End(); |
|
1610 } |
|
1611 |
|
1612 //============================================================================= |
|
1613 void CImageEditorCropControl::DarkenUnselectedAreaL() |
|
1614 { |
|
1615 |
|
1616 LOG(KCropPluginLogFile, "CImageEditorCropControl::DarkenUnselectedAreaL()"); |
|
1617 |
|
1618 if (iBufBitmap) |
|
1619 { |
|
1620 // Compute crop rectangle inside the image area |
|
1621 TRect rect = iSysPars->VisibleImageRectPrev(); |
|
1622 TInt w = (rect.iBr.iX - rect.iTl.iX); |
|
1623 TInt h = (rect.iBr.iY - rect.iTl.iY); |
|
1624 TInt ulc = (TInt) (iULC * w + 0.5) + rect.iTl.iX; |
|
1625 TInt ulr = (TInt) (iULR * h + 0.5) + rect.iTl.iY; |
|
1626 TInt lrc = (TInt) (iLRC * w + 0.5) + rect.iTl.iX; |
|
1627 TInt lrr = (TInt) (iLRR * h + 0.5) + rect.iTl.iY; |
|
1628 |
|
1629 // Darken areas in the image that are outside crop rectangle |
|
1630 CFbsBitmapDevice * bitmapDevice = CFbsBitmapDevice::NewL (iBufBitmap); |
|
1631 CleanupStack::PushL (bitmapDevice); |
|
1632 |
|
1633 // Create bitmap graphics context |
|
1634 CFbsBitGc * bitmapContext = 0; |
|
1635 User::LeaveIfError (bitmapDevice->CreateContext (bitmapContext)); |
|
1636 CleanupStack::PushL (bitmapContext) ; |
|
1637 |
|
1638 |
|
1639 bitmapContext->SetDrawMode (CGraphicsContext::EDrawModeAND); |
|
1640 bitmapContext->SetPenStyle (CGraphicsContext::ENullPen); |
|
1641 bitmapContext->SetPenColor (KRgbBlack); |
|
1642 bitmapContext->SetBrushStyle (CGraphicsContext::EDiamondCrossHatchBrush); |
|
1643 bitmapContext->SetBrushColor (KRgbWhite); |
|
1644 |
|
1645 // Darken top |
|
1646 bitmapContext->DrawRect ( TRect ( rect.iTl.iX, 0, rect.iBr.iX, ulr ) ); |
|
1647 |
|
1648 // Darken left side |
|
1649 bitmapContext->DrawRect ( TRect( rect.iTl.iX, ulr, ulc, lrr ) ); |
|
1650 |
|
1651 // Darken right side |
|
1652 bitmapContext->DrawRect ( TRect( lrc, ulr, rect.iBr.iX, lrr ) ); |
|
1653 |
|
1654 // Darken bottom |
|
1655 bitmapContext->DrawRect ( TRect( rect.iTl.iX, lrr, rect.iBr.iX, Rect().iBr.iY ) ); |
|
1656 |
|
1657 CleanupStack::PopAndDestroy(2); // bitmapContext, bitmapDevice |
|
1658 } |
|
1659 } |
|
1660 |
|
1661 #endif // DOUBLE_BUFFERED_CROP |
|
1662 |
|
1663 //============================================================================= |
|
1664 void CImageEditorCropControl::UpdateCropRectangle() |
|
1665 { |
|
1666 |
|
1667 LOG(KCropPluginLogFile, "CImageEditorCropControl::UpdateCropRectangle()"); |
|
1668 |
|
1669 if ( iOldCropRectPrev == TRect (0,0,0,0) ) |
|
1670 { |
|
1671 return; |
|
1672 } |
|
1673 if (iULC < 0.0) |
|
1674 { |
|
1675 iULC = 0.0; |
|
1676 if ( !iIsCropModeManual ) |
|
1677 { |
|
1678 ComputePreservedLRR(); |
|
1679 } |
|
1680 } |
|
1681 if (iULR < 0.0) |
|
1682 { |
|
1683 iULR = 0.0; |
|
1684 if ( !iIsCropModeManual ) |
|
1685 { |
|
1686 ComputePreservedLRC(); |
|
1687 } |
|
1688 } |
|
1689 if (iLRC > 1.0) |
|
1690 { |
|
1691 iLRC = 1.0; |
|
1692 if ( !iIsCropModeManual ) |
|
1693 { |
|
1694 ComputePreservedLRR(); |
|
1695 } |
|
1696 } |
|
1697 if (iLRR > 1.0) |
|
1698 { |
|
1699 iLRR = 1.0; |
|
1700 if ( !iIsCropModeManual ) |
|
1701 { |
|
1702 ComputePreservedLRC(); |
|
1703 } |
|
1704 } |
|
1705 } |
|
1706 |
|
1707 //============================================================================= |
|
1708 void CImageEditorCropControl::StoreCropRelScreen() |
|
1709 { |
|
1710 LOG(KCropPluginLogFile, "CImageEditorCropControl::StoreCropRelScreen()"); |
|
1711 |
|
1712 TRect viprect = iSysPars->VisibleImageRectPrev(); |
|
1713 |
|
1714 TInt vipwidth = (viprect.iBr.iX - viprect.iTl.iX); |
|
1715 TInt vipheight = (viprect.iBr.iY - viprect.iTl.iY); |
|
1716 iOldCropRectPrev.iTl.iX = viprect.iTl.iX + (TInt)(iULC * vipwidth + 0.5); |
|
1717 iOldCropRectPrev.iTl.iY = viprect.iTl.iY + (TInt)(iULR * vipheight + 0.5); |
|
1718 iOldCropRectPrev.iBr.iX = viprect.iTl.iX + (TInt)(iLRC * vipwidth + 0.5); |
|
1719 iOldCropRectPrev.iBr.iY = viprect.iTl.iY + (TInt)(iLRR * vipheight + 0.5); |
|
1720 } |
|
1721 |
|
1722 //============================================================================= |
|
1723 void CImageEditorCropControl::RestoreCropRelScreen() |
|
1724 { |
|
1725 LOG(KCropPluginLogFile, "CImageEditorCropControl::RestoreCropRelScreen()"); |
|
1726 |
|
1727 TRect viprect = iSysPars->VisibleImageRectPrev(); |
|
1728 TInt width = (viprect.iBr.iX - viprect.iTl.iX); |
|
1729 TInt height = (viprect.iBr.iY - viprect.iTl.iY); |
|
1730 iULC = (float)(iOldCropRectPrev.iTl.iX - viprect.iTl.iX) / (float)width; |
|
1731 iULR = (float)(iOldCropRectPrev.iTl.iY - viprect.iTl.iY) / (float)height; |
|
1732 iLRC = (float)(iOldCropRectPrev.iBr.iX - viprect.iTl.iX) / (float)width; |
|
1733 iLRR = (float)(iOldCropRectPrev.iBr.iY - viprect.iTl.iY) / (float)height; |
|
1734 } |
|
1735 |
|
1736 //============================================================================= |
|
1737 void CImageEditorCropControl::StoreCropRelImage() |
|
1738 { |
|
1739 LOG(KCropPluginLogFile, "CImageEditorCropControl::StoreCropRelImage()"); |
|
1740 |
|
1741 TReal relscale = iSysPars->RelScale(); |
|
1742 TRect virect = iSysPars->VisibleImageRect(); |
|
1743 virect.iTl.iX = (TInt)((virect.iTl.iX / relscale) + 0.5); |
|
1744 virect.iTl.iY = (TInt)((virect.iTl.iY / relscale) + 0.5); |
|
1745 virect.iBr.iX = (TInt)((virect.iBr.iX / relscale) + 0.5); |
|
1746 virect.iBr.iY = (TInt)((virect.iBr.iY / relscale) + 0.5); |
|
1747 |
|
1748 TInt viwidth = (virect.iBr.iX - virect.iTl.iX); |
|
1749 TInt viheight = (virect.iBr.iY - virect.iTl.iY); |
|
1750 |
|
1751 iOldCropRectPrev.iTl.iX = virect.iTl.iX + (TInt)(iULC * viwidth + 0.5); |
|
1752 iOldCropRectPrev.iTl.iY = virect.iTl.iY + (TInt)(iULR * viheight + 0.5); |
|
1753 iOldCropRectPrev.iBr.iX = virect.iTl.iX + (TInt)(iLRC * viwidth + 0.5); |
|
1754 iOldCropRectPrev.iBr.iY = virect.iTl.iY + (TInt)(iLRR * viheight + 0.5); |
|
1755 |
|
1756 } |
|
1757 |
|
1758 //============================================================================= |
|
1759 void CImageEditorCropControl::RestoreCropRelImage() |
|
1760 { |
|
1761 LOG(KCropPluginLogFile, "CImageEditorCropControl::RestoreCropRelImage()"); |
|
1762 |
|
1763 TReal relscale = iSysPars->RelScale(); |
|
1764 TRect virect = iSysPars->VisibleImageRect(); |
|
1765 virect.iTl.iX = (TInt)(virect.iTl.iX / relscale + 0.5); |
|
1766 virect.iTl.iY = (TInt)(virect.iTl.iY / relscale + 0.5); |
|
1767 virect.iBr.iX = (TInt)(virect.iBr.iX / relscale + 0.5); |
|
1768 virect.iBr.iY = (TInt)(virect.iBr.iY / relscale + 0.5); |
|
1769 |
|
1770 TInt width = (virect.iBr.iX - virect.iTl.iX); |
|
1771 TInt height = (virect.iBr.iY - virect.iTl.iY); |
|
1772 |
|
1773 iULC = (float)(iOldCropRectPrev.iTl.iX - virect.iTl.iX) / width; |
|
1774 iULR = (float)(iOldCropRectPrev.iTl.iY - virect.iTl.iY) / height; |
|
1775 iLRC = (float)(iOldCropRectPrev.iBr.iX - virect.iTl.iX) / width; |
|
1776 iLRR = (float)(iOldCropRectPrev.iBr.iY - virect.iTl.iY) / height; |
|
1777 |
|
1778 } |
|
1779 |
|
1780 //============================================================================= |
|
1781 void CImageEditorCropControl::HandlePointerEventL( |
|
1782 const TPointerEvent &aPointerEvent ) |
|
1783 { |
|
1784 if( AknLayoutUtils::PenEnabled() ) |
|
1785 { |
|
1786 TBool redraw( ETrue ); |
|
1787 switch( aPointerEvent.iType ) |
|
1788 { |
|
1789 case TPointerEvent::EButton1Down: |
|
1790 { |
|
1791 iPopupController->HideInfoPopupNote(); |
|
1792 iTouchDragEnabled = EFalse; |
|
1793 // Store tapped position |
|
1794 iTappedPosition = aPointerEvent.iPosition; |
|
1795 |
|
1796 if ( iState == ECropStateFirst || iState == ECropStateSecond ) |
|
1797 { |
|
1798 // Check first if minimum crop area is tapped (priority 1) |
|
1799 if ( IsMinCropAreaTapped( aPointerEvent.iPosition ) ) |
|
1800 { |
|
1801 // enables immediate rectangle moving |
|
1802 redraw = ETrue; |
|
1803 iTouchDragEnabled = ETrue; |
|
1804 iState = ECropStateMove; |
|
1805 iEditorView->HandleCommandL ( |
|
1806 EImageEditorUpdateSoftkeys ); |
|
1807 } |
|
1808 // Check if corners are tapped (priority 2) |
|
1809 else if ( IsCursorTapped( aPointerEvent.iPosition ) ) |
|
1810 { |
|
1811 #ifdef RD_TACTILE_FEEDBACK |
|
1812 if ( iTouchFeedBack ) |
|
1813 { |
|
1814 iTouchFeedBack->InstantFeedback( ETouchFeedbackBasic ); |
|
1815 RDebug::Printf( "ImageEditor::ImageEditorCropControl: ETouchFeedback 1" ); |
|
1816 } |
|
1817 #endif /* RD_TACTILE_FEEDBACK */ |
|
1818 |
|
1819 // Just enable dragging, no need to change position |
|
1820 // here |
|
1821 iTouchDragEnabled = ETrue; |
|
1822 redraw = EFalse; |
|
1823 } |
|
1824 else if ( IsOppositeCornerTapped( |
|
1825 aPointerEvent.iPosition ) ) |
|
1826 { |
|
1827 #ifdef RD_TACTILE_FEEDBACK |
|
1828 if ( iTouchFeedBack ) |
|
1829 { |
|
1830 iTouchFeedBack->InstantFeedback( ETouchFeedbackBasic ); |
|
1831 RDebug::Printf( "ImageEditor::ImageEditorCropControl: ETouchFeedback 2" ); |
|
1832 } |
|
1833 #endif /* RD_TACTILE_FEEDBACK */ |
|
1834 |
|
1835 iTouchDragEnabled = ETrue; |
|
1836 if ( iState == ECropStateFirst ) |
|
1837 { |
|
1838 iState = ECropStateSecond; |
|
1839 } |
|
1840 else |
|
1841 { |
|
1842 iState = ECropStateFirst; |
|
1843 } |
|
1844 iEditorView->HandleCommandL ( |
|
1845 EImageEditorUpdateSoftkeys ); |
|
1846 redraw = ETrue; |
|
1847 } |
|
1848 // Change to move state |
|
1849 else if ( IsCropAreaTapped( aPointerEvent.iPosition ) ) |
|
1850 { |
|
1851 // enables immediate rectangle moving |
|
1852 redraw = ETrue; |
|
1853 iTouchDragEnabled = ETrue; |
|
1854 iState = ECropStateMove; |
|
1855 iEditorView->HandleCommandL ( |
|
1856 EImageEditorUpdateSoftkeys ); |
|
1857 } |
|
1858 } |
|
1859 else if ( iState == ECropStateMove ) |
|
1860 { |
|
1861 TInt corner; |
|
1862 |
|
1863 if ( IsMinCropAreaTapped( aPointerEvent.iPosition ) ) |
|
1864 { |
|
1865 // enables immediate rectangle moving |
|
1866 redraw = ETrue; |
|
1867 iTouchDragEnabled = ETrue; |
|
1868 iState = ECropStateMove; |
|
1869 //iEditorView->HandleCommandL ( |
|
1870 // EImageEditorUpdateSoftkeys ); |
|
1871 } |
|
1872 // Moving back to first or second state from Move state |
|
1873 // by pressing top-left or bottom-right corner |
|
1874 else if( IsCornerTapped( aPointerEvent.iPosition , corner) ) |
|
1875 { |
|
1876 #ifdef RD_TACTILE_FEEDBACK |
|
1877 if ( iTouchFeedBack ) |
|
1878 { |
|
1879 iTouchFeedBack->InstantFeedback( ETouchFeedbackBasic ); |
|
1880 RDebug::Printf( "ImageEditor::ImageEditorCropControl: ETouchFeedback 3" ); |
|
1881 } |
|
1882 #endif /* RD_TACTILE_FEEDBACK */ |
|
1883 if ( corner == ETLCorner ) |
|
1884 { |
|
1885 // enables immediate dragging |
|
1886 redraw = ETrue; |
|
1887 iTouchDragEnabled = ETrue; |
|
1888 iState = ECropStateFirst; |
|
1889 iEditorView->HandleCommandL ( |
|
1890 EImageEditorUpdateSoftkeys ); |
|
1891 } |
|
1892 else if ( corner == EBRCorner ) |
|
1893 { |
|
1894 redraw = ETrue; |
|
1895 iTouchDragEnabled = ETrue; |
|
1896 iState = ECropStateSecond; |
|
1897 iEditorView->HandleCommandL ( |
|
1898 EImageEditorUpdateSoftkeys ); |
|
1899 } |
|
1900 } |
|
1901 else if ( IsCropAreaTapped( aPointerEvent.iPosition ) ) |
|
1902 { |
|
1903 redraw = EFalse; |
|
1904 iTouchDragEnabled = ETrue; |
|
1905 iTappedPosition = aPointerEvent.iPosition; |
|
1906 } |
|
1907 } |
|
1908 break; |
|
1909 } |
|
1910 case TPointerEvent::EDrag: |
|
1911 { |
|
1912 if ( iState == ECropStateFirst && |
|
1913 iTouchDragEnabled ) |
|
1914 { |
|
1915 SetTLPosition( iTappedPosition, aPointerEvent.iPosition ); |
|
1916 iTappedPosition = aPointerEvent.iPosition; |
|
1917 } |
|
1918 else if ( iState == ECropStateSecond && |
|
1919 iTouchDragEnabled ) |
|
1920 { |
|
1921 SetBRPosition( iTappedPosition, aPointerEvent.iPosition ); |
|
1922 iTappedPosition = aPointerEvent.iPosition; |
|
1923 } |
|
1924 else if ( iState == ECropStateMove && iTouchDragEnabled ) |
|
1925 { |
|
1926 MoveCropArea( iTappedPosition, aPointerEvent.iPosition ); |
|
1927 iTappedPosition = aPointerEvent.iPosition; |
|
1928 } |
|
1929 redraw = ETrue; |
|
1930 break; |
|
1931 } |
|
1932 case TPointerEvent::EButton1Up: |
|
1933 { |
|
1934 iTouchDragEnabled = EFalse; |
|
1935 redraw = EFalse; |
|
1936 ShowTooltip(); |
|
1937 break; |
|
1938 } |
|
1939 |
|
1940 default: |
|
1941 { |
|
1942 break; |
|
1943 } |
|
1944 } |
|
1945 |
|
1946 if ( redraw ) |
|
1947 { |
|
1948 ComputeCropParams(); |
|
1949 |
|
1950 #ifdef DOUBLE_BUFFERED_CROP |
|
1951 |
|
1952 if ( iState == ECropStateFirst || |
|
1953 iState == ECropStateSecond || |
|
1954 iState == ECropStateMove ) |
|
1955 { |
|
1956 ClonePreviewBitmapL(); |
|
1957 } |
|
1958 DarkenUnselectedAreaL(); |
|
1959 |
|
1960 #endif // DOUBLE_BUFFERED_CROP |
|
1961 |
|
1962 iEditorView->HandleCommandL (EImageEditorUpdateNavipane); |
|
1963 DrawNow(); |
|
1964 } |
|
1965 CCoeControl::HandlePointerEventL( aPointerEvent ); |
|
1966 } |
|
1967 } |
|
1968 |
|
1969 //============================================================================= |
|
1970 void CImageEditorCropControl::SetTLPosition( TPoint aOldPosition, |
|
1971 TPoint aNewPosition ) |
|
1972 { |
|
1973 // Get system parameters |
|
1974 TRect visibleImageRectPrev( iSysPars->VisibleImageRectPrev() ); |
|
1975 |
|
1976 //Set new x value |
|
1977 iULC += TReal( aNewPosition.iX - aOldPosition.iX ) / |
|
1978 ( visibleImageRectPrev.iBr.iX - visibleImageRectPrev.iTl.iX ); |
|
1979 |
|
1980 //Set new y value |
|
1981 iULR += TReal( aNewPosition.iY - aOldPosition.iY ) / |
|
1982 ( visibleImageRectPrev.iBr.iY - visibleImageRectPrev.iTl.iY ); |
|
1983 |
|
1984 // check the limits |
|
1985 if (iULR < 0.0) |
|
1986 { |
|
1987 iULR = 0.0; |
|
1988 } |
|
1989 else if (iULR > iLRR - iMinY) |
|
1990 { |
|
1991 iULR = iLRR - iMinY; |
|
1992 } |
|
1993 |
|
1994 if ( !iIsCropModeManual ) |
|
1995 { |
|
1996 // To preserve selected aspect ratio |
|
1997 ComputePreservedULC(); |
|
1998 } |
|
1999 |
|
2000 if (iULC < 0.0) |
|
2001 { |
|
2002 iULC = 0.0; |
|
2003 } |
|
2004 else if (iULC > iLRC - iMinX) |
|
2005 { |
|
2006 iULC = iLRC - iMinX; |
|
2007 } |
|
2008 |
|
2009 if ( !iIsCropModeManual ) |
|
2010 { |
|
2011 // To preserve selected aspect ratio |
|
2012 ComputePreservedULR(); |
|
2013 } |
|
2014 } |
|
2015 |
|
2016 //============================================================================= |
|
2017 void CImageEditorCropControl::SetBRPosition( TPoint aOldPosition, |
|
2018 TPoint aNewPosition ) |
|
2019 { |
|
2020 |
|
2021 // Get system parameters |
|
2022 TRect visibleImageRectPrev( iSysPars->VisibleImageRectPrev() ); |
|
2023 |
|
2024 //Set new x value |
|
2025 iLRC += TReal( aNewPosition.iX - aOldPosition.iX ) / |
|
2026 ( visibleImageRectPrev.iBr.iX - visibleImageRectPrev.iTl.iX ); |
|
2027 |
|
2028 //Set new y value |
|
2029 iLRR += TReal( aNewPosition.iY - aOldPosition.iY ) / |
|
2030 ( visibleImageRectPrev.iBr.iY - visibleImageRectPrev.iTl.iY ); |
|
2031 |
|
2032 // check the limits |
|
2033 if (iLRR < iULR + iMinY) |
|
2034 { |
|
2035 iLRR = iULR + iMinY; |
|
2036 } |
|
2037 else if (iLRR > 1.0) |
|
2038 { |
|
2039 iLRR = 1.0; |
|
2040 } |
|
2041 |
|
2042 if ( !iIsCropModeManual ) |
|
2043 { |
|
2044 // To preserve selected aspect ratio |
|
2045 ComputePreservedLRC(); |
|
2046 } |
|
2047 |
|
2048 if (iLRC < iULC + iMinX) |
|
2049 { |
|
2050 iLRC = iULC + iMinX; |
|
2051 } |
|
2052 else if (iLRC > 1.0) |
|
2053 { |
|
2054 iLRC = 1.0; |
|
2055 } |
|
2056 |
|
2057 if ( !iIsCropModeManual ) |
|
2058 { |
|
2059 // To preserve selected aspect ratio |
|
2060 ComputePreservedLRR(); |
|
2061 } |
|
2062 } |
|
2063 |
|
2064 //============================================================================= |
|
2065 TBool CImageEditorCropControl::IsCursorTapped( TPoint aTappedPosition ) const |
|
2066 { |
|
2067 TInt corner; |
|
2068 |
|
2069 if ( IsCornerTapped( aTappedPosition, corner ) ) |
|
2070 { |
|
2071 if ( corner == ETLCorner && iState == ECropStateFirst ) |
|
2072 { |
|
2073 return ETrue; |
|
2074 } |
|
2075 else if ( corner == EBRCorner && iState == ECropStateSecond ) |
|
2076 { |
|
2077 return ETrue; |
|
2078 } |
|
2079 } |
|
2080 return EFalse; |
|
2081 } |
|
2082 |
|
2083 //============================================================================= |
|
2084 TBool CImageEditorCropControl::IsOppositeCornerTapped( |
|
2085 TPoint aTappedPosition ) const |
|
2086 { |
|
2087 TInt corner; |
|
2088 |
|
2089 if ( IsCornerTapped( aTappedPosition, corner ) ) |
|
2090 { |
|
2091 if ( corner == ETLCorner && iState == ECropStateSecond ) |
|
2092 { |
|
2093 return ETrue; |
|
2094 } |
|
2095 else if ( corner == EBRCorner && iState == ECropStateFirst ) |
|
2096 { |
|
2097 return ETrue; |
|
2098 } |
|
2099 } |
|
2100 return EFalse; |
|
2101 } |
|
2102 |
|
2103 //============================================================================= |
|
2104 TBool CImageEditorCropControl::IsCropAreaTapped( TPoint aTappedPosition ) const |
|
2105 { |
|
2106 TRect rect = iSysPars->VisibleImageRectPrev(); |
|
2107 TInt w = ( rect.iBr.iX - rect.iTl.iX ); |
|
2108 TInt h = ( rect.iBr.iY - rect.iTl.iY ); |
|
2109 TInt ulc = ( TInt ) ( iULC * w + 0.5 ) + rect.iTl.iX; |
|
2110 TInt ulr = ( TInt ) ( iULR * h + 0.5 ) + rect.iTl.iY; |
|
2111 TInt lrc = ( TInt ) ( iLRC * w + 0.5 ) + rect.iTl.iX; |
|
2112 TInt lrr = ( TInt) ( iLRR * h + 0.5 ) + rect.iTl.iY; |
|
2113 |
|
2114 TRect areaRect ( TPoint( ulc, ulr ), TPoint( lrc, lrr ) ); |
|
2115 |
|
2116 return areaRect.Contains( aTappedPosition ); |
|
2117 |
|
2118 } |
|
2119 |
|
2120 //============================================================================= |
|
2121 TBool CImageEditorCropControl::IsMinCropAreaTapped( TPoint aTappedPosition ) const |
|
2122 { |
|
2123 TRect rect = iSysPars->VisibleImageRectPrev(); |
|
2124 TInt w = ( rect.iBr.iX - rect.iTl.iX ); |
|
2125 TInt h = ( rect.iBr.iY - rect.iTl.iY ); |
|
2126 TInt ulc = ( TInt ) ( iULC * w + 0.5 ) + rect.iTl.iX; |
|
2127 TInt ulr = ( TInt ) ( iULR * h + 0.5 ) + rect.iTl.iY; |
|
2128 TInt lrc = ( TInt ) ( iLRC * w + 0.5 ) + rect.iTl.iX; |
|
2129 TInt lrr = ( TInt) ( iLRR * h + 0.5 ) + rect.iTl.iY; |
|
2130 |
|
2131 TPoint middlePoint = TPoint( ulc + ( lrc - ulc ) / 2, |
|
2132 ulr + ( lrr - ulr ) / 2 ); |
|
2133 |
|
2134 TReal relscale = iSysPars->RelScale(); |
|
2135 TInt minCrop = (TInt)(KMaxCropAbsoluteMin * relscale + 0.5); |
|
2136 |
|
2137 TRect areaRect ( TPoint( middlePoint.iX - minCrop, middlePoint.iY - minCrop ), |
|
2138 TPoint( middlePoint.iX + minCrop, middlePoint.iY + minCrop ) ); |
|
2139 |
|
2140 // restrict min crop area inside total cropping area |
|
2141 if( areaRect.iTl.iX < ulc ) |
|
2142 { |
|
2143 areaRect.iTl.iX = ulc; |
|
2144 } |
|
2145 if( areaRect.iTl.iY < ulr ) |
|
2146 { |
|
2147 areaRect.iTl.iY = ulr; |
|
2148 } |
|
2149 if( areaRect.iBr.iX > lrc ) |
|
2150 { |
|
2151 areaRect.iBr.iX = lrc; |
|
2152 } |
|
2153 if( areaRect.iBr.iY > lrr ) |
|
2154 { |
|
2155 areaRect.iBr.iY = lrr; |
|
2156 } |
|
2157 |
|
2158 return areaRect.Contains( aTappedPosition ); |
|
2159 |
|
2160 } |
|
2161 |
|
2162 //============================================================================= |
|
2163 TBool CImageEditorCropControl::IsCornerTapped( TPoint aTappedPosition, |
|
2164 TInt& aTappedCorner ) const |
|
2165 { |
|
2166 // Compute crop rectangle inside the image area |
|
2167 TRect rect = iSysPars->VisibleImageRectPrev(); |
|
2168 TInt w = ( rect.iBr.iX - rect.iTl.iX ); |
|
2169 TInt h = ( rect.iBr.iY - rect.iTl.iY ); |
|
2170 TInt ulc = ( TInt ) ( iULC * w + 0.5 ) + rect.iTl.iX; |
|
2171 TInt ulr = ( TInt ) ( iULR * h + 0.5 ) + rect.iTl.iY; |
|
2172 TInt lrc = ( TInt ) ( iLRC * w + 0.5 ) + rect.iTl.iX; |
|
2173 TInt lrr = ( TInt ) ( iLRR * h + 0.5 ) + rect.iTl.iY; |
|
2174 |
|
2175 TBool topLeftTapped = EFalse; |
|
2176 TBool bottomRightTapped = EFalse; |
|
2177 |
|
2178 TSize cursorSize = iCrossHair->SizeInPixels(); |
|
2179 TSize tripleCursorSize( 3 * cursorSize.iWidth, |
|
2180 3 * cursorSize.iHeight ); |
|
2181 |
|
2182 // Case1, upper left corner |
|
2183 TInt cx = ulc; |
|
2184 TInt cy = ulr; |
|
2185 TRect cursorRect( TPoint( cx - ( tripleCursorSize.iWidth / 2 ), |
|
2186 cy - ( tripleCursorSize.iHeight / 2 ) ), |
|
2187 tripleCursorSize ); |
|
2188 |
|
2189 // Calculate an estimate for the distance to top-left corner |
|
2190 // Change more accurate implementation if needed in future |
|
2191 // (this is fast) |
|
2192 TInt distTL = Abs( cx - aTappedPosition.iX ) + |
|
2193 Abs( cy - aTappedPosition.iY ); |
|
2194 |
|
2195 if ( cursorRect.Contains( aTappedPosition ) ) |
|
2196 { |
|
2197 topLeftTapped = ETrue; |
|
2198 } |
|
2199 |
|
2200 // Case2, lower right corner |
|
2201 cx = lrc - 1; |
|
2202 cy = lrr - 1; |
|
2203 cursorRect = TRect( TPoint( cx - ( tripleCursorSize.iWidth / 2 ), |
|
2204 cy - ( tripleCursorSize.iHeight / 2 ) ), |
|
2205 tripleCursorSize ); |
|
2206 |
|
2207 // Calculate an estimate for the distance to bottom-right corner |
|
2208 // Change more accurate implementation if needed in future |
|
2209 // (this is fast) |
|
2210 TInt distBR = Abs( cx - aTappedPosition.iX ) + |
|
2211 Abs( cy - aTappedPosition.iY ); |
|
2212 |
|
2213 if ( cursorRect.Contains( aTappedPosition ) ) |
|
2214 { |
|
2215 bottomRightTapped = ETrue; |
|
2216 } |
|
2217 |
|
2218 // Check tapped corner |
|
2219 if ( topLeftTapped || bottomRightTapped ) |
|
2220 { |
|
2221 if( topLeftTapped && !bottomRightTapped ) |
|
2222 { |
|
2223 aTappedCorner = ETLCorner; |
|
2224 } |
|
2225 else if( !topLeftTapped && bottomRightTapped ) |
|
2226 { |
|
2227 aTappedCorner = EBRCorner; |
|
2228 } |
|
2229 // Tapping happened inside of both corners. Check the closest. |
|
2230 else |
|
2231 { |
|
2232 if( distTL < distBR ) |
|
2233 { |
|
2234 aTappedCorner = ETLCorner; |
|
2235 } |
|
2236 else |
|
2237 { |
|
2238 aTappedCorner = EBRCorner; |
|
2239 } |
|
2240 } |
|
2241 return ETrue; |
|
2242 } |
|
2243 |
|
2244 // no top-left nor bottom-righ corner tapped |
|
2245 aTappedCorner = EInvalidCorner; |
|
2246 return EFalse; |
|
2247 } |
|
2248 |
|
2249 //============================================================================= |
|
2250 void CImageEditorCropControl::MoveCropArea( TPoint aOldPosition, |
|
2251 TPoint aNewPosition ) |
|
2252 { |
|
2253 TRect visibleImageRectPrev( iSysPars->VisibleImageRectPrev() ); |
|
2254 |
|
2255 // Change can be positive or negative |
|
2256 TInt xChange ( aNewPosition.iX - aOldPosition.iX ); |
|
2257 TInt yChange ( aNewPosition.iY - aOldPosition.iY ); |
|
2258 |
|
2259 // X-components |
|
2260 // store old x-values so they can be used if crop rect is trying to be |
|
2261 // moved outside the visible area |
|
2262 TReal ulcOld = iULC; |
|
2263 iULC += TReal( xChange ) / ( visibleImageRectPrev.iBr.iX - |
|
2264 visibleImageRectPrev.iTl.iX ); |
|
2265 TReal lrcOld = iLRC; |
|
2266 iLRC += TReal( xChange ) / ( visibleImageRectPrev.iBr.iX - |
|
2267 visibleImageRectPrev.iTl.iX ); |
|
2268 |
|
2269 // if limits are reached, move as much as possible (both sides) |
|
2270 if ( iULC < 0.0 ) |
|
2271 { |
|
2272 iULC = 0.0; |
|
2273 iLRC = lrcOld; |
|
2274 // ulc min limit reached, move lrc as much as it was possible |
|
2275 // to move ulc |
|
2276 iLRC += ( iULC - ulcOld ); |
|
2277 } |
|
2278 else if ( iLRC > 1.0 ) |
|
2279 { |
|
2280 iLRC = 1.0; |
|
2281 iULC = ulcOld; |
|
2282 iULC += ( iLRC - lrcOld ); |
|
2283 } |
|
2284 |
|
2285 // Y-components |
|
2286 TReal ulrOld = iULR; |
|
2287 iULR += TReal( yChange ) / ( visibleImageRectPrev.iBr.iY - |
|
2288 visibleImageRectPrev.iTl.iY ); |
|
2289 TReal lrrOld = iLRR; |
|
2290 iLRR += TReal( yChange ) / ( visibleImageRectPrev.iBr.iY - |
|
2291 visibleImageRectPrev.iTl.iY ); |
|
2292 |
|
2293 if ( iULR < 0.0 ) |
|
2294 { |
|
2295 iULR = 0.0; |
|
2296 iLRR = lrrOld; |
|
2297 iLRR += ( iULR - ulrOld ); |
|
2298 } |
|
2299 else if ( iLRR > 1.0 ) |
|
2300 { |
|
2301 iLRR = 1.0; |
|
2302 iULR = ulrOld; |
|
2303 iULR += ( iLRR - lrrOld ); |
|
2304 } |
|
2305 } |
|
2306 |
|
2307 //============================================================================= |
|
2308 void CImageEditorCropControl::ShowTooltip() |
|
2309 { |
|
2310 iPopupController->HideInfoPopupNote(); |
|
2311 |
|
2312 // Calculate visible image rect corner positions |
|
2313 TRect rect = iSysPars->VisibleImageRectPrev(); |
|
2314 TInt w = ( rect.iBr.iX - rect.iTl.iX ); |
|
2315 TInt h = ( rect.iBr.iY - rect.iTl.iY ); |
|
2316 TInt ulc = ( TInt ) ( iULC * w + 0.5 ) + rect.iTl.iX; |
|
2317 TInt ulr = ( TInt ) ( iULR * h + 0.5 ) + rect.iTl.iY; |
|
2318 TInt lrc = ( TInt ) ( iLRC * w + 0.5 ) + rect.iTl.iX; |
|
2319 TInt lrr = ( TInt ) ( iLRR * h + 0.5 ) + rect.iTl.iY; |
|
2320 |
|
2321 TSize cursorSize = iCrossHair->SizeInPixels(); |
|
2322 |
|
2323 // user is setting upper left corner |
|
2324 if ( iState == ECropStateFirst ) |
|
2325 { |
|
2326 TPoint middlePoint = TPoint( ulc, ulr ); |
|
2327 |
|
2328 SDrawUtils::ShowToolTip( iPopupController, |
|
2329 this, |
|
2330 middlePoint, |
|
2331 EHLeftVBottom, |
|
2332 *iTooltipResize ); |
|
2333 } |
|
2334 // user is setting lower right corner |
|
2335 else if ( iState == ECropStateSecond ) |
|
2336 { |
|
2337 TPoint middlePoint = TPoint( lrc - 1 , |
|
2338 lrr - 1 ); |
|
2339 |
|
2340 SDrawUtils::ShowToolTip ( iPopupController, |
|
2341 this, |
|
2342 middlePoint, |
|
2343 EHRightVBottom, |
|
2344 *iTooltipResize ); |
|
2345 } |
|
2346 // in move state |
|
2347 else if ( iState == ECropStateMove ) |
|
2348 { |
|
2349 TPoint middlePoint = TPoint( ulc + ( lrc - ulc ) / 2, |
|
2350 ulr + ( lrr - ulr ) / 2 ); |
|
2351 |
|
2352 SDrawUtils::ShowToolTip ( iPopupController, |
|
2353 this, |
|
2354 middlePoint, |
|
2355 EHCenterVCenter, |
|
2356 *iTooltipMove ); |
|
2357 } |
|
2358 } |
|
2359 |
|
2360 |
|
2361 // End of file |