2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 #include <FBaseErrors.h>
18 #include <FGrpDimension.h>
19 #include <FBaseSysLog.h>
20 #include "FUiCtrl_GalleryImageReader.h"
21 #include "FUiCtrl_GalleryPresenter.h"
22 #include "FUiCtrl_GalleryViewEventInfo.h"
23 #include "FUiCtrl_GalleryViewEventHandler.h"
24 #include "FUiCtrl_IGalleryRenderer.h"
27 using namespace Tizen::Graphics;
29 namespace Tizen { namespace Ui { namespace Controls {
33 const int FLICK_ANIMATION_DURATION = 500;
34 const int ALIGH_ANIMATION_DURATION = 1000;
35 const int ZOOM_ANIMATION_DURATION = 1000;
36 const int PINCH_ZOOM_ANIMATION_DURATION = 500;
37 const int DOUBLE_PRESSE_ZOOM_DISTANCE = 1000;
38 const int FLICK_MOVE_ANIMATION_DURATION = 500;
39 const int FLICK_MOVE_DISTANCE = 200;
40 const float MAX_ZOOM_RATIO = 3.0;
41 const float MIN_ZOOM_RATIO = 0.3;
42 const int NO_CHANGE_ITEM_INDEX = -1;
45 _GalleryViewEventHandler::_GalleryViewEventHandler(_GalleryPresenter& presenter, _IGalleryRenderer& galleryRenderer,
46 _GalleryImageReader& galleryImageReader)
47 : __galleryPresenter(presenter)
48 , __galleryRenderer(galleryRenderer)
49 , __galleryImageReader(galleryImageReader)
50 , __previousPosition(0, 0)
51 , __startPinchCenterPosition(0, 0)
52 , __flickingDirection(FLICK_DIRECTION_NONE)
53 , __pinchInitialArea(0)
57 , __zoomAnimationComplete(true)
60 , __currentItemIndex(NO_CHANGE_ITEM_INDEX)
65 _GalleryViewEventHandler::~_GalleryViewEventHandler(void)
71 _GalleryViewEventHandler::Construct(void)
73 return __galleryRenderer.AddNotiListener(*this);
77 _GalleryViewEventHandler::OnTouchPressed(_GalleryViewEventInfo& eventInfo)
79 SysTryReturn(NID_UI_CTRL, __pressed == false, true, E_SYSTEM, "[E_SYSTEM] Already pressed state.");
80 result r = SetVisibleCanvas();
81 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
84 __previousPosition.SetPosition(eventInfo.GetCurrentPosition());
86 __touchPointId = eventInfo.GetPointId();
88 //SetLastResult(E_SUCCESS);
98 _GalleryViewEventHandler::OnTouchDoublePressed(_GalleryViewEventInfo& eventInfo)
100 _GalleryAnimationTiming animation = {ZOOM_ANIMATION_DURATION, GALLERY_ANIMATION_TIMING_FUNC_EASEOUT};
102 int distance = DOUBLE_PRESSE_ZOOM_DISTANCE;
103 if (__zoomMode == false)
105 center = __previousPosition;
110 Rectangle viewRect = __galleryRenderer.GetViewRect();
111 center.SetPosition(viewRect.width / 2, viewRect.height / 2);
113 int currentCanvasIndex = __galleryPresenter.SearchCanvasIndex(__galleryPresenter.GetCurrentItemIndex());
114 Rectangle canvasRect = __galleryRenderer.GetCanvasBounds(currentCanvasIndex);
115 distance = canvasRect.width - viewRect.width;
117 result r = ZoomCanvas(distance, center, __zoomMode, &animation);
118 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
120 __zoomAnimationComplete = false;
124 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
126 //SetLastResult(E_SUCCESS);
132 _GalleryViewEventHandler::OnTouchMoved(_GalleryViewEventInfo& eventInfo)
134 if (__pinchMode == true || __touchPointId != eventInfo.GetPointId())
140 distance.width = __previousPosition.x - eventInfo.GetCurrentPosition().x;
141 distance.height = __previousPosition.y - eventInfo.GetCurrentPosition().y;
143 result r = MoveCanvas(distance);
144 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
147 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
149 __previousPosition.SetPosition(eventInfo.GetCurrentPosition());
151 //SetLastResult(E_SUCCESS);
157 _GalleryViewEventHandler::OnTouchReleased(_GalleryViewEventInfo& eventInfo)
159 result r = E_SUCCESS;
160 bool itemClickedSuccess = true;
161 if (__pressed == true)
163 if (__moving == true)
166 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
171 itemClickedSuccess = __galleryPresenter.ClickedItem();
176 if (__pinchMode == true)
178 Rectangle viewRect = __galleryRenderer.GetViewRect();
180 int currentCanvasIndex = __galleryPresenter.SearchCanvasIndex(__galleryPresenter.GetCurrentItemIndex());
181 Rectangle canvasRect = __galleryRenderer.GetCanvasBounds(currentCanvasIndex);
182 int distance = canvasRect.width - viewRect.width;
186 Point center(viewRect.width / 2, viewRect.height / 2);
187 _GalleryAnimationTiming animation = {PINCH_ZOOM_ANIMATION_DURATION, GALLERY_ANIMATION_TIMING_FUNC_EASEOUT};
188 r = ZoomCanvas(distance, center, false, &animation);
189 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
190 //__zoomMode = false;
194 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
195 __pinchInitialArea = 0;
196 __startPinchCenterPosition.SetPosition(0, 0);
201 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
202 __flickingDirection = FLICK_DIRECTION_NONE;
204 //SetLastResult(E_SUCCESS);
212 __pinchInitialArea = 0;
214 __flickingDirection = FLICK_DIRECTION_NONE;
219 _GalleryViewEventHandler::OnTouchPinchZoom(_GalleryViewEventInfo& eventInfo)
221 if (__galleryPresenter.IsZoomingEnabled() == false)
226 if (__moving == true)
231 Point center = eventInfo.GetPinchCenterPosition();
232 int currentCanvasIndex = __galleryPresenter.SearchCanvasIndex(__galleryPresenter.GetCurrentItemIndex());
233 Rectangle canvasRect = __galleryRenderer.GetCanvasBounds(currentCanvasIndex);
234 Rectangle viewRect = __galleryRenderer.GetViewRect();
236 int area = eventInfo.GetPinchArea();
238 if (__pinchInitialArea == 0)
240 __pinchInitialArea = area;
245 area -= __pinchInitialArea;
246 __pinchInitialArea += area;
258 if (__startPinchCenterPosition.x == 0 && __startPinchCenterPosition.y == 0)
260 float factor = (float)canvasRect.width / (float)viewRect.width;
261 __startPinchCenterPosition = center;
262 __startPinchCenterPosition.x = CalculateRound((__startPinchCenterPosition.x - canvasRect.x) / factor);
263 __startPinchCenterPosition.y = CalculateRound((__startPinchCenterPosition.y - canvasRect.y) / factor);
266 //_GalleryAnimationTiming animation = {PINCH_ZOOM_ANIMATION_DURATION, GALLERY_ANIMATION_TIMING_FUNC_EASEOUT};
267 //result r = ZoomCanvas(area, center, zoomIn, &animation);
268 result r = PinchZoomCanvas(area, center, zoomIn);
269 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
271 __pressed = false; //???
273 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
275 SetLastResult(E_SUCCESS);
281 _GalleryViewEventHandler::OnTouchFlicked(_GalleryViewEventInfo& eventInfo)
283 if (__pinchMode == true)
288 result r = E_SUCCESS;
289 if (__zoomMode == false)
291 if (eventInfo.GetFlickPosition().x > 0)
293 r = FlickToTheRight();
295 else if (eventInfo.GetFlickPosition().x < 0)
297 r = FlickToTheLeft();
299 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
303 _GalleryAnimationTiming animation = {FLICK_MOVE_ANIMATION_DURATION, GALLERY_ANIMATION_TIMING_FUNC_EASEOUT};
307 if (eventInfo.GetFlickPosition().x > 0)
309 moveX = -FLICK_MOVE_DISTANCE;
313 moveX = FLICK_MOVE_DISTANCE;
316 if (eventInfo.GetFlickPosition().y > 0)
318 moveY = -FLICK_MOVE_DISTANCE;
322 moveY = FLICK_MOVE_DISTANCE;
325 Dimension dim(moveX, moveY);
326 r = MoveCanvas(dim, &animation);
327 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
331 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
333 //SetLastResult(E_SUCCESS);
344 _GalleryViewEventHandler::OnTransitionCancel(void)
349 _GalleryViewEventHandler::OnTransitionCompleted(void)
354 _GalleryViewEventHandler::OnCanvasAnimationCancel(void)
356 __zoomAnimationComplete = true;
357 __flickingDirection = FLICK_DIRECTION_NONE;
358 result r = CallChangeItemIndex();
359 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
362 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
364 //SetLastResult(E_SUCCESS);
368 _GalleryViewEventHandler::OnCanvasAnimationCompleted(void)
370 result r = E_SUCCESS;
372 if (__zoomAnimationComplete == false)
375 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
376 __zoomAnimationComplete = true;
379 if (__zoomMode == true)
381 r = AlignCanvas(false);
382 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
384 r = __galleryPresenter.SetPartialCanvasImage();
385 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
387 __flickingDirection = FLICK_DIRECTION_NONE;
389 r = CallChangeItemIndex();
390 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
393 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
395 //SetLastResult(E_SUCCESS);
399 _GalleryViewEventHandler::OnCanvasAnimationStarted(void)
405 _GalleryViewEventHandler::SetZoomFlag(bool zoomMode)
407 __zoomMode = zoomMode;
411 _GalleryViewEventHandler::IsZoomFlag(void) const
417 _GalleryViewEventHandler::RefreshView(void)
419 return __galleryRenderer.RefreshView();
423 _GalleryViewEventHandler::SetVisibleCanvas(void)
425 int currentItemIndex = __galleryPresenter.GetCurrentItemIndex();
426 SysTryReturn(NID_UI_CTRL, currentItemIndex >= 0 && currentItemIndex < __galleryPresenter.GetItemCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
427 "[E_OUT_OF_RANGE] This value(%d) is out of range(%d ~ %d)", currentItemIndex, 0, __galleryPresenter.GetItemCount());
429 Rectangle viewRect = __galleryRenderer.GetViewRect();
430 Rectangle rect = viewRect;
433 int currentCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex);
434 result r = E_SUCCESS;
435 if (currentCanvasIndex == NOT_EXIST_CANVAS)
437 r = __galleryPresenter.SetCanvasImage(currentItemIndex);
438 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
441 if (__zoomMode == false)
443 r = __galleryRenderer.SetCanvasBounds(currentCanvasIndex, rect);
444 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
448 Rectangle currentCanvasRect = __galleryRenderer.GetCanvasBounds(currentCanvasIndex);
449 r = __galleryRenderer.SetCanvasBounds(currentCanvasIndex, currentCanvasRect);
450 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
453 r = __galleryRenderer.SetCanvasVisibility(currentCanvasIndex, true);
454 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
456 Rectangle currentCanvasAlignBoundary = __galleryRenderer.GetCanvasAlignBoundary(currentCanvasIndex);
458 if (currentItemIndex - 1 >= 0 && currentItemIndex - 1 < __galleryPresenter.GetItemCount())
460 int leftCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex - 1);
461 if (leftCanvasIndex == NOT_EXIST_CANVAS)
463 r = __galleryPresenter.SetCanvasImage(currentItemIndex - 1);
464 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
465 leftCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex - 1);
466 SysTryReturn(NID_UI_CTRL, leftCanvasIndex != NOT_EXIST_CANVAS, GetLastResult(), GetLastResult(),
467 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
470 rect.x = currentCanvasAlignBoundary.x - viewRect.width - __galleryPresenter.GetItemSpacing();
471 r = __galleryRenderer.SetCanvasBounds(leftCanvasIndex, rect);
472 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
474 r = __galleryRenderer.SetCanvasVisibility(leftCanvasIndex, true);
475 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
479 if (currentItemIndex + 1 >= 0 && currentItemIndex + 1 < __galleryPresenter.GetItemCount())
481 int rightCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex + 1);
482 if (rightCanvasIndex == NOT_EXIST_CANVAS)
484 r = __galleryPresenter.SetCanvasImage(currentItemIndex + 1);
485 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
486 rightCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex + 1);
487 SysTryReturn(NID_UI_CTRL, rightCanvasIndex != NOT_EXIST_CANVAS, GetLastResult(), GetLastResult(),
488 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
491 rect.x = currentCanvasAlignBoundary.x + currentCanvasAlignBoundary.width + __galleryPresenter.GetItemSpacing();
492 r = __galleryRenderer.SetCanvasBounds(rightCanvasIndex, rect);
493 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
495 r = __galleryRenderer.SetCanvasVisibility(rightCanvasIndex, true);
496 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
503 _GalleryViewEventHandler::SetInvisibleCanvas(void)
505 int currentItemIndex = __galleryPresenter.GetCurrentItemIndex();
506 SysTryReturn(NID_UI_CTRL, currentItemIndex >= 0 && currentItemIndex < __galleryPresenter.GetItemCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
507 "[E_OUT_OF_RANGE] This value(%d) is out of range(%d ~ %d)", currentItemIndex, 0, __galleryPresenter.GetItemCount());
509 int leftCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex - 1);
510 int rightCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex + 1);
512 result r = E_SUCCESS;
513 if (leftCanvasIndex != NOT_EXIST_CANVAS)
515 r = __galleryRenderer.SetCanvasVisibility(leftCanvasIndex, false);
516 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
518 if (rightCanvasIndex != NOT_EXIST_CANVAS)
520 r = __galleryRenderer.SetCanvasVisibility(rightCanvasIndex, false);
521 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
528 _GalleryViewEventHandler::FlickToTheRight(void)
530 result r = E_SUCCESS;
531 Rectangle viewRect = __galleryRenderer.GetViewRect();
532 Rectangle rect = viewRect;
533 int currentItemIndex = __galleryPresenter.GetCurrentItemIndex();
534 int leftCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex - 1);
536 __flickingDirection = FLICK_DIRECTION_RIGHT;
537 if (leftCanvasIndex == NOT_EXIST_CANVAS)
539 if (currentItemIndex - 1 < 0)
545 r = __galleryPresenter.SetCanvasImage(currentItemIndex - 1);
546 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
548 leftCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex - 1);
550 SysTryReturn(NID_UI_CTRL, leftCanvasIndex != NOT_EXIST_CANVAS, r, r, "[%s] Propagating.", GetErrorMessage(r));
552 rect.x = viewRect.x - viewRect.width - __galleryPresenter.GetItemSpacing();
553 r = __galleryRenderer.SetCanvasBounds(leftCanvasIndex, rect);
554 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
556 r = __galleryRenderer.SetCanvasVisibility(leftCanvasIndex, true);
557 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
561 int currentCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex);
562 int rightCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex + 1);
564 _GalleryAnimationTiming animation = {FLICK_ANIMATION_DURATION, GALLERY_ANIMATION_TIMING_FUNC_EASEOUT};
566 rect.x = viewRect.x + viewRect.width + __galleryPresenter.GetItemSpacing();
567 r = __galleryRenderer.SetCanvasBounds(currentCanvasIndex, rect, &animation);
568 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
571 r = __galleryRenderer.SetCanvasBounds(leftCanvasIndex, rect, &animation);
572 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
574 if (rightCanvasIndex != NOT_EXIST_CANVAS)
576 rect.x = viewRect.x + viewRect.width * 2 + __galleryPresenter.GetItemSpacing();
577 r = __galleryRenderer.SetCanvasBounds(rightCanvasIndex, rect, &animation);
578 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
581 r = SetCurrentItemIndex(__galleryPresenter.GetCurrentItemIndex() - 1);
582 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
588 _GalleryViewEventHandler::FlickToTheLeft(void)
590 result r = E_SUCCESS;
591 Rectangle viewRect = __galleryRenderer.GetViewRect();
592 Rectangle rect = viewRect;
593 int currentItemIndex = __galleryPresenter.GetCurrentItemIndex();
594 int rightCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex + 1);
596 __flickingDirection = FLICK_DIRECTION_LEFT;
597 if (rightCanvasIndex == NOT_EXIST_CANVAS)
599 if (currentItemIndex + 1 >= __galleryPresenter.GetItemCount())
605 r = __galleryPresenter.SetCanvasImage(currentItemIndex + 1);
606 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
608 rightCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex + 1);
610 SysTryReturn(NID_UI_CTRL, rightCanvasIndex != NOT_EXIST_CANVAS, r, r, "[%s] Propagating.", GetErrorMessage(r));
612 rect.x = viewRect.x + viewRect.width + __galleryPresenter.GetItemSpacing();
613 r = __galleryRenderer.SetCanvasBounds(rightCanvasIndex, rect);
614 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
616 r = __galleryRenderer.SetCanvasVisibility(rightCanvasIndex, true);
617 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
621 int currentCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex);
622 int leftCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex - 1);
623 _GalleryAnimationTiming animation = {FLICK_ANIMATION_DURATION, GALLERY_ANIMATION_TIMING_FUNC_EASEOUT};
625 rect.x = viewRect.x - viewRect.width - __galleryPresenter.GetItemSpacing();
626 r = __galleryRenderer.SetCanvasBounds(currentCanvasIndex, rect, &animation);
627 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
630 r = __galleryRenderer.SetCanvasBounds(rightCanvasIndex, rect, &animation);
631 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
633 if (leftCanvasIndex != NOT_EXIST_CANVAS)
635 rect.x = viewRect.x - viewRect.width * 2 - __galleryPresenter.GetItemSpacing();
636 r = __galleryRenderer.SetCanvasBounds(leftCanvasIndex, rect, &animation);
637 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
640 r = SetCurrentItemIndex(__galleryPresenter.GetCurrentItemIndex() + 1);
641 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
647 _GalleryViewEventHandler::ZoomCanvas(int distance, const Point& center, bool zoomIn, _GalleryAnimationTiming* pAnimation)
649 if (__galleryPresenter.IsZoomingEnabled() == false || distance == 0)
655 int currentItemIndex = __galleryPresenter.GetCurrentItemIndex();
656 int currentCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex);
657 if (__galleryRenderer.IsCanvasVisibility(currentCanvasIndex) == false)
659 result r = __galleryRenderer.SetCanvasVisibility(currentCanvasIndex, true);
660 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
663 Rectangle canvasBounds = __galleryRenderer.GetCanvasBounds(currentCanvasIndex);
664 Rectangle imageBounds = __galleryRenderer.GetCanvasImageBounds(currentCanvasIndex);
665 Rectangle viewBounds = __galleryRenderer.GetViewRect();
669 factor = (float)(canvasBounds.width + distance) / (float)viewBounds.width;
670 canvasBounds.width = factor * viewBounds.width;
671 canvasBounds.height = factor * viewBounds.height;
672 canvasBounds.x = -(center.x * factor - viewBounds.width / 2);
673 canvasBounds.y = -(center.y * factor - viewBounds.height/ 2);
675 imageBounds.x *= factor;
676 imageBounds.y *= factor;
677 imageBounds.width *= factor;
678 imageBounds.height *= factor;
680 CorrectCanvasPosition(canvasBounds, imageBounds);
684 canvasBounds = viewBounds;
687 result r = __galleryRenderer.SetCanvasBounds(currentCanvasIndex, canvasBounds, pAnimation);
688 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
690 if (canvasBounds.width > viewBounds.width)
703 _GalleryViewEventHandler::PinchZoomCanvas(int area, const Point& center, bool zoomIn)
705 if (__galleryPresenter.IsZoomingEnabled() == false || area == 0 ||
706 __startPinchCenterPosition.x == 0 || __startPinchCenterPosition.y == 0)
711 int currentItemIndex = __galleryPresenter.GetCurrentItemIndex();
712 int currentCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex);
714 Rectangle bounds = __galleryRenderer.GetCanvasBounds(currentCanvasIndex);
715 Rectangle viewBounds = __galleryRenderer.GetViewRect();
720 factor = (float)(bounds.width + area) / (float)viewBounds.width;
721 if (factor > MAX_ZOOM_RATIO)
723 factor = MAX_ZOOM_RATIO;
728 factor = (float)(bounds.width - area) / (float)viewBounds.width;
729 if (factor < MIN_ZOOM_RATIO)
731 factor = MIN_ZOOM_RATIO;
735 bounds.width = CalculateRound(factor * viewBounds.width);
736 if (bounds.width < 1)
741 bounds.height = CalculateRound(factor * viewBounds.height);
742 if (bounds.height < 1)
747 if (bounds.width > viewBounds.width || bounds.height > viewBounds.height)
749 bounds.x = center.x - CalculateRound(__startPinchCenterPosition.x * factor);
750 bounds.y = center.y - CalculateRound(__startPinchCenterPosition.y * factor);
756 else if (bounds.x < -(bounds.width - viewBounds.width))
758 bounds.x = -(bounds.width - viewBounds.width);
765 else if (bounds.y < -(bounds.height- viewBounds.height))
767 bounds.y = -(bounds.height - viewBounds.height);
772 bounds.x = (viewBounds.width / 2) - CalculateRound(viewBounds.width / 2 * factor);
773 bounds.y = (viewBounds.height / 2) - CalculateRound(viewBounds.height / 2 * factor);
776 result r = __galleryRenderer.SetCanvasBounds(currentCanvasIndex, bounds);
777 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
779 if (bounds.width > viewBounds.width)
792 _GalleryViewEventHandler::MoveCanvas(const Dimension& distance, _GalleryAnimationTiming* pAnimation)
794 SysTryReturn(NID_UI_CTRL, __pressed == true, E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] not pressed state.");
796 int currentItemIndex = __galleryPresenter.GetCurrentItemIndex();
797 int currentCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex);
798 int rightCanvasIndex = NOT_EXIST_CANVAS;
799 int leftCanvasIndex = NOT_EXIST_CANVAS;
801 if (currentItemIndex != 0)
803 leftCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex - 1);
805 if (currentItemIndex < __galleryPresenter.GetItemCount())
807 rightCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex + 1);
810 Rectangle viewRect = __galleryRenderer.GetViewRect();
811 Rectangle currentCanvasRect = __galleryRenderer.GetCanvasBounds(currentCanvasIndex);
812 Rectangle rect = currentCanvasRect;
814 Rectangle canvasImageBounds = __galleryRenderer.GetCanvasImageBounds(currentCanvasIndex);
815 if (IsZoomFlag() == true)
817 if (canvasImageBounds.y + rect.y > 0)
819 rect.y -= (distance.height / 2);
821 else if (canvasImageBounds.y + canvasImageBounds.height + rect.y < viewRect.height)
823 rect.y -= (distance.height / 2);
827 rect.y -= distance.height;
830 if (leftCanvasIndex == NOT_EXIST_CANVAS && canvasImageBounds.x + rect.x > 0 && distance.width < 0)
832 rect.x -= (distance.width / 2);
834 else if (rightCanvasIndex == NOT_EXIST_CANVAS
835 && canvasImageBounds.x + canvasImageBounds.width + rect.x < viewRect.width
836 && distance.width > 0)
838 rect.x -= (distance.width / 2);
842 rect.x -= distance.width;
847 rect.x -= distance.width;
850 if (rect.x > 0 && leftCanvasIndex == NOT_EXIST_CANVAS && __zoomMode == false)
854 else if (rect.x < 0 && rightCanvasIndex == NOT_EXIST_CANVAS && __zoomMode == false)
859 result r = __galleryRenderer.SetCanvasBounds(currentCanvasIndex, rect, pAnimation);
860 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
862 if (rightCanvasIndex != NOT_EXIST_CANVAS)
864 rect = __galleryRenderer.GetCanvasBounds(rightCanvasIndex);
865 //rect.x = currentCanvasRect.x - distance.width + currentCanvasRect.width + __galleryPresenter.GetItemSpacing();
866 rect.x -= distance.width;
867 r = __galleryRenderer.SetCanvasBounds(rightCanvasIndex, rect, pAnimation);
868 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
871 if (leftCanvasIndex != NOT_EXIST_CANVAS)
873 rect = __galleryRenderer.GetCanvasBounds(leftCanvasIndex);
874 //rect.x = currentCanvasRect.x - distance.width - rect.width - __galleryPresenter.GetItemSpacing();
875 rect.x -= distance.width;
876 r = __galleryRenderer.SetCanvasBounds(leftCanvasIndex, rect, pAnimation);
877 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
886 _GalleryViewEventHandler::AlignCanvas(bool animation)
888 int currentItemIndex = __galleryPresenter.GetCurrentItemIndex();
889 int currentCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex);
890 int leftCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex - 1);
891 int rightCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex + 1);
893 result r = E_SUCCESS;
894 Rectangle viewRect = __galleryRenderer.GetViewRect();
895 Rectangle currentCanvasRect = __galleryRenderer.GetCanvasBounds(currentCanvasIndex);
896 Rectangle canvasImageBounds = __galleryRenderer.GetCanvasImageBounds(currentCanvasIndex);
898 Rectangle rect = viewRect;
899 _GalleryAnimationTiming* pAnimationTimingFunction = null;
900 bool immediatePartialCanvasChange = false;
902 if (animation == true)
904 pAnimationTimingFunction = new(std::nothrow) _GalleryAnimationTiming();
905 SysTryCatch(NID_UI_CTRL, pAnimationTimingFunction != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
906 pAnimationTimingFunction->duration_ms = ALIGH_ANIMATION_DURATION;
907 pAnimationTimingFunction->timingFunction = GALLERY_ANIMATION_TIMING_FUNC_EASEOUT;
910 if (canvasImageBounds.height > viewRect.height) // zoom mode
912 if (!(viewRect.y < canvasImageBounds.y && viewRect.height > canvasImageBounds.height + canvasImageBounds.y))
914 immediatePartialCanvasChange = true;
918 if ((IsZoomFlag() == true
919 && currentCanvasRect.x + canvasImageBounds.x > __galleryRenderer.GetViewRect().width / 2
920 && (leftCanvasIndex != NOT_EXIST_CANVAS))
921 || (IsZoomFlag() == false
922 && (canvasImageBounds.width / 2 + canvasImageBounds.x) < canvasImageBounds.x + currentCanvasRect.x)) // ----> align
924 r = __galleryRenderer.SetCanvasBounds(leftCanvasIndex, rect, pAnimationTimingFunction);
925 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
927 r = SetCurrentItemIndex(currentItemIndex - 1);
928 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
931 rect.x = viewRect.width + __galleryPresenter.GetItemSpacing();
932 r = __galleryRenderer.SetCanvasBounds(currentCanvasIndex, rect, pAnimationTimingFunction);
933 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
935 else if ((IsZoomFlag() == true
936 && currentCanvasRect.x + (canvasImageBounds.x + canvasImageBounds.width) < __galleryRenderer.GetViewRect().width / 2
937 && (rightCanvasIndex != NOT_EXIST_CANVAS))
938 ||(IsZoomFlag() == false
939 && (canvasImageBounds.width / 2 + canvasImageBounds.x) > currentCanvasRect.x + currentCanvasRect.width)) // <---- align
941 r = __galleryRenderer.SetCanvasBounds(rightCanvasIndex, rect, pAnimationTimingFunction);
942 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
944 r = SetCurrentItemIndex(currentItemIndex + 1);
945 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
948 rect.x = -viewRect.width - __galleryPresenter.GetItemSpacing();
949 r = __galleryRenderer.SetCanvasBounds(currentCanvasIndex, rect, pAnimationTimingFunction);
950 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
952 else if (currentCanvasRect.x != 0 || currentCanvasRect.width != viewRect.width)// return align (before position)
954 if (currentCanvasIndex != NOT_EXIST_CANVAS)
956 rect = currentCanvasRect;
957 if (__zoomMode == true)
959 bool corrected = CorrectCanvasPosition(rect, canvasImageBounds);
960 if (corrected == false && immediatePartialCanvasChange == true && __zoomAnimationComplete == true)
962 r = __galleryPresenter.SetPartialCanvasImage();
963 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
971 r = __galleryRenderer.SetCanvasBounds(currentCanvasIndex, rect, pAnimationTimingFunction);
972 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
974 Rectangle currentCanvasAlignBoundary = __galleryRenderer.GetCanvasAlignBoundary(currentCanvasIndex);
975 if (rightCanvasIndex != NOT_EXIST_CANVAS)
978 rect.x = currentCanvasAlignBoundary.x + currentCanvasAlignBoundary.width + __galleryPresenter.GetItemSpacing();
979 r = __galleryRenderer.SetCanvasBounds(rightCanvasIndex, rect, pAnimationTimingFunction);
980 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
982 if (leftCanvasIndex != NOT_EXIST_CANVAS)
985 rect.x = currentCanvasAlignBoundary.x - rect.width - __galleryPresenter.GetItemSpacing();
986 r = __galleryRenderer.SetCanvasBounds(leftCanvasIndex, rect, pAnimationTimingFunction);
987 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
991 delete pAnimationTimingFunction;
996 delete pAnimationTimingFunction;
1001 _GalleryViewEventHandler::SetRollbackCanvas(void)
1003 int currentItemIndex = __galleryPresenter.GetCurrentItemIndex();
1004 int currentCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex);
1005 int leftCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex - 1);
1006 int rightCanvasIndex = __galleryPresenter.SearchCanvasIndex(currentItemIndex + 1);
1008 Rectangle viewRect = __galleryRenderer.GetViewRect();
1010 result r = __galleryRenderer.SetCanvasBounds(currentCanvasIndex, viewRect);
1011 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1013 r = __galleryRenderer.SetCanvasVisibility(leftCanvasIndex, false);
1014 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1016 r = __galleryRenderer.SetCanvasVisibility(rightCanvasIndex, false);
1017 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1019 //SetLastResult(E_SUCCESS);
1023 _GalleryViewEventHandler::CalculateRound(float value)
1025 int returnValue = ((int)((value) * 10)) % 10 > 5 ? value + 0.5 : value;
1030 _GalleryViewEventHandler::CorrectCanvasPosition(Rectangle& canvasBounds, const Rectangle& imageBounds)
1032 if (IsZoomFlag() == false)
1036 Rectangle viewBounds = __galleryRenderer.GetViewRect();
1037 bool corrected = false;
1038 if (imageBounds.width > viewBounds.width)
1040 if (viewBounds.x < imageBounds.x + canvasBounds.x)
1042 canvasBounds.x = -imageBounds.x;
1045 else if (viewBounds.width > imageBounds.x + imageBounds.width + canvasBounds.x)
1047 canvasBounds.x = (viewBounds.x + viewBounds.width) - (imageBounds.x + imageBounds.width);
1053 canvasBounds.x = viewBounds.width / 2 -((imageBounds.width / 2 + imageBounds.x));
1057 if (imageBounds.height > viewBounds.height)
1059 if (viewBounds.y < imageBounds.y + canvasBounds.y)
1061 canvasBounds.y = -imageBounds.y;
1064 else if (viewBounds.height > imageBounds.height + imageBounds.y + canvasBounds.y)
1066 canvasBounds.y = (viewBounds.y + viewBounds.height) - (imageBounds.y + imageBounds.height);
1072 canvasBounds.y = viewBounds.height / 2 -((imageBounds.height / 2 + imageBounds.y));
1080 _GalleryViewEventHandler::SetCurrentItemIndex(int index)
1082 __currentItemIndex = index;
1084 return __galleryPresenter.SetCurrentItemIndex(__currentItemIndex, false);
1088 _GalleryViewEventHandler::CallChangeItemIndex(void)
1090 result r = E_SUCCESS;
1091 if (__currentItemIndex != NO_CHANGE_ITEM_INDEX)
1093 r = __galleryPresenter.SetCurrentItemIndex(__currentItemIndex);
1094 __currentItemIndex = NO_CHANGE_ITEM_INDEX;
1095 __galleryPresenter.ChangedItem();
1100 }}} // Tizen::Ui::Controls