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 <FBaseColArrayList.h>
18 #include <FGrpCanvas.h>
19 #include <FGrpFloatRectangle.h>
20 #include <FGrpPoint.h>
21 #include <FGrpRectangle.h>
22 #include <FUiAnimVisualElementPropertyAnimation.h>
23 #include <FBaseSysLog.h>
24 #include "FUiAnim_VisualElement.h"
25 #include "FUiCtrl_GalleryCanvas.h"
26 #include "FUiCtrl_GalleryBitmap.h"
29 using namespace Tizen::Base;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Ui;
32 using namespace Tizen::Ui::Animations;
34 namespace Tizen { namespace Ui { namespace Controls
37 _GalleryAnimationProvider::_GalleryAnimationProvider(void)
38 : __pAnimationDelegator(null)
40 __animationTiming.duration_ms = 0;
41 __animationTiming.timingFunction = GALLERY_ANIMATION_TIMING_FUNC_LINEAR;
44 _GalleryAnimationProvider::~_GalleryAnimationProvider(void)
49 VisualElementAnimation*
50 _GalleryAnimationProvider::CreateAnimationForProperty(VisualElement& source, const String& property)
52 const IVisualElementAnimationTimingFunction* pTimingFunction = GetTimingFunc(__animationTiming.timingFunction);
54 VisualElementAnimation* pAnimation = VisualElementAnimationProvider::CreateAnimationForProperty(source, property);//dynamic_cast<VisualElementPropertyAnimation*>(visualElement.CreateAnimationForPropertyN(visualElement, VEPropTransform));
55 if (pAnimation != null)
57 result r = pAnimation->SetDuration(__animationTiming.duration_ms);
58 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
60 pAnimation->SetTimingFunction(pTimingFunction);
61 pAnimation->SetVisualElementAnimationStatusEventListener(__pAnimationDelegator);
64 SetLastResult(E_SUCCESS);
75 _GalleryAnimationProvider::SetAnimationDelegator(IVisualElementAnimationStatusEventListener* pAnimationDelegator)
77 __pAnimationDelegator = pAnimationDelegator;
82 _GalleryAnimationProvider::SetGalleryAnimationTiming(_GalleryAnimationTiming animationTiming)
84 __animationTiming = animationTiming;
88 const IVisualElementAnimationTimingFunction*
89 _GalleryAnimationProvider::GetTimingFunc(_GalleryAnimationTimingFunction timingFunction) const
91 const IVisualElementAnimationTimingFunction* pTimingFunc = null;
92 switch (timingFunction)
94 case GALLERY_ANIMATION_TIMING_FUNC_LINEAR:
95 pTimingFunc = VisualElementAnimation::GetTimingFunctionByName("Linear");
97 case GALLERY_ANIMATION_TIMING_FUNC_EASEIN:
98 pTimingFunc = VisualElementAnimation::GetTimingFunctionByName("EaseIn");
100 case GALLERY_ANIMATION_TIMING_FUNC_EASEOUT:
101 pTimingFunc = VisualElementAnimation::GetTimingFunctionByName("EaseOut");
103 case GALLERY_ANIMATION_TIMING_FUNC_EASEINOUT:
104 pTimingFunc = VisualElementAnimation::GetTimingFunctionByName("EaseInOut");
116 _GalleryCanvas::CreateGalleryCanvasN(Rectangle& canvasBounds)
118 result r = E_SUCCESS;
120 _GalleryCanvas* pCanvas = new (std::nothrow) _GalleryCanvas();
121 SysTryCatch(NID_UI_CTRL, pCanvas != null, , E_OUT_OF_MEMORY,
122 "[E_OUT_OF_MEMORY] Failed to allocate the memory for the _GalleryCanvas.");
124 r = pCanvas->Construct(canvasBounds);
125 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
127 SetLastResult(E_SUCCESS);
138 _GalleryCanvas::SetImage(const _GalleryBitmap* pImage, const Rectangle& viewBounds, _GalleryFittingType fittingType)
145 Rectangle canvasBounds = GetBounds();
146 canvasBounds.width = viewBounds.width;
147 canvasBounds.height = viewBounds.height;
148 result r = SetBounds(canvasBounds);
149 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
151 _GalleryBitmap* pCanvasImage = _GalleryBitmap::CloneN(const_cast<_GalleryBitmap*>(pImage));
153 SysTryReturn(NID_UI_CTRL, pCanvasImage != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
156 __pImage = pCanvasImage;
158 if (__pImage->IsInitialize() == false || __visualElementBoundsChanged == true)
160 result r = __pImage->Initialize(__pRootCanvas->GetControlSize(), fittingType);
161 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
163 Dimension imageSize = __pImage->GetSize();
165 if (__imageVerticalAlignment == GALLERY_VERTICAL_ALIGN_MIDDLE)
167 position.y = (__bounds.height - imageSize.height) >> 1;
169 else if (__imageVerticalAlignment == GALLERY_VERTICAL_ALIGN_BOTTOM)
171 position.y = (__bounds.height - imageSize.height);
173 if (__imageHorizontalAlignment == GALLERY_HORIZONTAL_ALIGN_CENTER)
175 position.x = (__bounds.width - imageSize.width) >> 1;
177 else if (__imageHorizontalAlignment == GALLERY_HORIZONTAL_ALIGN_RIGHT)
179 position.x = (__bounds.width - imageSize.width);
182 Rectangle visualElementBounds(position.x, position.y, imageSize.width, imageSize.height);
183 r = SetVisualElementBounds(visualElementBounds);
184 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
186 __originalImageBounds = visualElementBounds;
187 SetImageBounds(GetBounds());
189 __visualElementBoundsChanged = false;
192 SetNeedUpdateImage(true);
198 _GalleryCanvas::GetImage(void) const
204 _GalleryCanvas::SetBounds(const Rectangle& bounds)
206 SysTryReturnResult(NID_UI_CTRL, bounds.width >= 0 && bounds.height >= 0, E_INVALID_ARG,
207 "The bounds width or height is negative value.");
209 if (GetFrameVisualElement().IsClipChildrenEnabled() == true)
211 FloatRectangle floatBounds(bounds.x, bounds.y, bounds.width, bounds.height);
212 GetFrameVisualElement().SetBounds(floatBounds);
218 _GalleryCanvas::GetBounds(void) const
224 _GalleryCanvas::SetVisibility(bool visibility)
226 GetImageVisualElement().SetImplicitAnimationEnabled(false);
227 GetImageVisualElement().SetShowState(visibility);
228 GetFrameVisualElement().SetImplicitAnimationEnabled(false);
229 GetFrameVisualElement().SetShowState(visibility);
235 _GalleryCanvas::IsVisibility(void) const
237 return GetImageVisualElement().GetShowState();
241 _GalleryCanvas::RefreshCanvas(void)
243 return GetImageVisualElement().InvalidateRectangle(null);
247 _GalleryCanvas::LoadImage(void)
249 Canvas* pCanvas = null;
250 result r = E_SUCCESS;
252 if (IsNeedUpdateImage() == true)
254 _GalleryBitmap* pImage = GetImage();
257 pCanvas = GetImageVisualElement().GetCanvasN();
259 SysTryCatch(NID_UI_CTRL, pCanvas != null, , r, "[%s] Propagating.", GetErrorMessage(r));
261 r = pCanvas->DrawBitmap(Point(0, 0), *pImage->GetInternalBitmap());
262 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
264 r = GetImageVisualElement().SetFlushNeeded();
265 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
269 SetNeedUpdateImage(false);
279 _GalleryCanvas::_GalleryCanvas(void)
280 : __pImageVisualElement(null)
281 , __pFrameVisualElement(null)
283 , __bounds(0, 0, 0, 0)
285 , __visableRegionOfImage(0, 0, 0, 0)
286 , __needUpdateImage(false)
287 , __visualElementBoundsChanged(false)
288 , __imageBounds(0, 0, 0, 0)
289 , __originalImageBounds(0, 0, 0, 0)
290 , __pRootCanvas(null)
292 , __imageAnchor(0, 0)
293 , __imageVerticalAlignment(GALLERY_VERTICAL_ALIGN_MIDDLE)
294 , __imageHorizontalAlignment(GALLERY_HORIZONTAL_ALIGN_CENTER)
299 _GalleryCanvas::~_GalleryCanvas(void)
301 GetImageVisualElement().RemoveAllAnimations();
306 if (__pImageVisualElement != null)
308 __pImageVisualElement->Destroy();
311 if (__pFrameVisualElement != null)
313 __pFrameVisualElement->Destroy();
318 _GalleryCanvas::Construct(Rectangle& canvasBounds)
320 result r = E_SUCCESS;
321 _VisualElement* pImageVisualElement = null;
322 _VisualElement* pFrameVisualElement = null;
323 FloatRectangle floatBounds(canvasBounds.x, canvasBounds.y, canvasBounds.width, canvasBounds.height);
325 pImageVisualElement = new (std::nothrow) _VisualElement();
326 SysTryCatch(NID_UI_CTRL, pImageVisualElement != null, , E_OUT_OF_MEMORY,
327 "[E_OUT_OF_MEMORY] Failed to allocate the memory for the _VisualElement.");
329 r = pImageVisualElement->Construct();
330 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
332 pImageVisualElement->SetImplicitAnimationEnabled(false);
333 pImageVisualElement->SetBounds(floatBounds);
335 pImageVisualElement->SetShowState(true);
337 r = pImageVisualElement->SetSurfaceOpaque(false);
338 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
340 SetImageVisualElement(*pImageVisualElement);
342 pFrameVisualElement = new (std::nothrow) _VisualElement();
343 SysTryCatch(NID_UI_CTRL, pFrameVisualElement != null, , E_OUT_OF_MEMORY,
344 "[E_OUT_OF_MEMORY] Failed to allocate the memory for the _VisualElement.");
345 r = pFrameVisualElement->Construct();
346 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
348 pFrameVisualElement->SetImplicitAnimationEnabled(false);
349 pFrameVisualElement->SetBounds(floatBounds);
351 pFrameVisualElement->SetShowState(true);
353 SetFrameVisualElement(*pFrameVisualElement);
355 r = GetFrameVisualElement().AttachChild(GetImageVisualElement());
356 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
358 GetFrameVisualElement().SetClipChildrenEnabled(true);
363 if (pImageVisualElement != null)
365 pImageVisualElement->Destroy();
368 if (pFrameVisualElement != null)
370 pFrameVisualElement->Destroy();
372 __pImageVisualElement = null;
373 __pFrameVisualElement = null;
379 _GalleryCanvas::SetImageVisualElement(_VisualElement& visualElement)
381 __pImageVisualElement = &visualElement;
386 _GalleryCanvas::GetImageVisualElement(void) const
388 return *__pImageVisualElement;
392 _GalleryCanvas::SetFrameVisualElement(_VisualElement& visualElement)
394 __pFrameVisualElement = &visualElement;
399 _GalleryCanvas::GetFrameVisualElement(void) const
401 return *__pFrameVisualElement;
405 _GalleryCanvas::SetAnimation(VisualElementPropertyAnimation& animation)
407 __pAnimation = &animation;
411 VisualElementPropertyAnimation&
412 _GalleryCanvas::GetAnimation(void) const
414 return *__pAnimation;
418 _GalleryCanvas::SetNeedUpdateImage(bool needUpdate)
420 __needUpdateImage = needUpdate;
425 _GalleryCanvas::IsNeedUpdateImage(void) const
427 return __needUpdateImage;
431 _GalleryCanvas::SetCanvasFactor(float factor)
438 _GalleryCanvas::GetCanvasFactor(void) const
444 _GalleryCanvas::SetVisualElementBounds(const Rectangle& bounds)
446 __visualElementBoundsChanged = true;
447 FloatRectangle floatBounds(bounds.x, bounds.y, bounds.width, bounds.height);
448 return GetImageVisualElement().SetBounds(floatBounds);
452 _GalleryCanvas::GetImageVisualElementBounds(void) const
454 FloatRectangle floatRect = GetImageVisualElement().GetBounds();
455 Rectangle bounds(floatRect.x, floatRect.y, floatRect.width, floatRect.height);
461 _GalleryCanvas::SetImageBounds(const Rectangle& canvasBounds)
463 float factor = GetCanvasFactor();
464 if (__visualElementBoundsChanged == true)
468 __imageBounds.width = __originalImageBounds.width * factor;
469 __imageBounds.height = __originalImageBounds.height * factor;
471 if (__imageVerticalAlignment == GALLERY_VERTICAL_ALIGN_MIDDLE)
473 __imageBounds.y = (canvasBounds.height - __imageBounds.height) >> 1;
475 else if (__imageVerticalAlignment == GALLERY_VERTICAL_ALIGN_BOTTOM)
477 __imageBounds.y = (canvasBounds.height - __imageBounds.height);
479 if (__imageHorizontalAlignment == GALLERY_HORIZONTAL_ALIGN_CENTER)
481 __imageBounds.x = (canvasBounds.width - __imageBounds.width) >> 1;
483 else if (__imageHorizontalAlignment == GALLERY_HORIZONTAL_ALIGN_RIGHT)
485 __imageBounds.x = (canvasBounds.width - __imageBounds.width);
492 _GalleryCanvas::GetOriginalImageBounds(void) const
494 return __originalImageBounds;
498 _GalleryCanvas::GetImageBounds(void) const
500 return __imageBounds;
504 _GalleryCanvas::SetAnimationDelegator(_GalleryAnimationProvider* pVEDelegator)
506 result r = GetImageVisualElement().SetAnimationProvider(pVEDelegator);
507 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
509 r = GetFrameVisualElement().SetAnimationProvider(pVEDelegator);
510 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
516 _GalleryCanvas::SetRootCanvas(_GalleryRootCanvas& rootCanvas)
518 __pRootCanvas = &rootCanvas;
523 _GalleryCanvas::SetImageAnchor(Tizen::Graphics::FloatPoint anchor)
525 __imageAnchor = anchor;
530 _GalleryCanvas::GetImageAnchor(void) const
532 return __imageAnchor;
536 _GalleryCanvas::GetAlignBoundary(void) const
538 Rectangle imageBounds = GetImageBounds();
539 if (__originalImageBounds.width != imageBounds.width || __originalImageBounds.height != imageBounds.height)
541 imageBounds.x += GetBounds().x;
542 imageBounds.y += GetBounds().y;
547 return Rectangle(-1, -1, -1, -1);
552 _GalleryCanvas::SetClippingOfFrameVisualElement(bool clipping)
554 GetFrameVisualElement().SetClipChildrenEnabled(clipping);
558 _GalleryCanvas::SetImageAlignment(_GalleryVerticalAlignment imageVerticalAlignment
559 , _GalleryHorizontalAlignment imageHorizontalAlignment)
561 __imageVerticalAlignment = imageVerticalAlignment;
562 __imageHorizontalAlignment = imageHorizontalAlignment;
566 _GalleryCanvas::GetImageAlignment(_GalleryVerticalAlignment& imageVerticalAlignment
567 , _GalleryHorizontalAlignment& imageHorizontalAlignment) const
569 imageVerticalAlignment = __imageVerticalAlignment;
570 imageHorizontalAlignment = __imageHorizontalAlignment;
574 // _GalleryRootCanvas
576 _GalleryRootCanvas::CreateGalleryRootCanvasN(_Control& control)
578 _GalleryRootCanvas* pRootCanvas = new (std::nothrow) _GalleryRootCanvas(control);
579 SysTryReturn(NID_UI_CTRL, pRootCanvas != null, null, E_OUT_OF_MEMORY,
580 "[E_OUT_OF_MEMORY] Failed to allocate the memory for the _GalleryRootCanvas.");
582 SetLastResult(E_SUCCESS);
588 _GalleryRootCanvas::SetBackgroundImage(const _GalleryBitmap* pImage)
590 __pBackgroundImage = const_cast <_GalleryBitmap*>(pImage);
595 _GalleryRootCanvas::GetBackgroundImage(void) const
597 return __pBackgroundImage;
601 _GalleryRootCanvas::GetBackgroundColor(void) const
603 return GetControl().GetBackgroundColor();
607 _GalleryRootCanvas::SetBounds(const Rectangle& bounds)
609 return GetControl().SetBounds(bounds);
613 _GalleryRootCanvas::GetBounds(void) const
615 return GetControl().GetBounds();
619 _GalleryRootCanvas::GetControlSize(void) const
621 return GetControl().GetSize();
625 _GalleryRootCanvas::SetVisibility(bool visibility)
627 GetControl().SetVisibleState(visibility);
633 _GalleryRootCanvas::IsVisibility(void) const
635 return GetControl().GetVisibleState();
639 _GalleryRootCanvas::AddChildCanvas(_GalleryCanvas& canvas)
641 _VisualElement& childVisualElement = canvas.GetFrameVisualElement();
642 _VisualElement* pRootVisualElement = GetImageVisualElement();
643 SysTryReturn(NID_UI_CTRL, pRootVisualElement != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Root VisualElement is null.");
645 result r = pRootVisualElement->AttachChild(childVisualElement);
646 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
648 canvas.SetRootCanvas(*this);
654 _GalleryRootCanvas::RemoveChildCanvas(_GalleryCanvas& canvas)
656 _VisualElement& childVisualElement = canvas.GetFrameVisualElement();
657 _VisualElement* pRootVisualElement = GetImageVisualElement();
658 SysTryReturn(NID_UI_CTRL, pRootVisualElement != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Root VisualElement is null.");
660 result r = pRootVisualElement->DetachChild(childVisualElement);
661 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
667 _GalleryRootCanvas::RefreshCanvas(void)
669 //GetControl().Draw();
670 GetControl().Invalidate();
674 _GalleryRootCanvas::_GalleryRootCanvas(_Control& control)
676 , __bounds(0, 0, 0, 0)
677 , __pBackgroundImage(null)
678 , __needUpdateBackgroundImage(false)
683 _GalleryRootCanvas::~_GalleryRootCanvas(void)
689 _GalleryRootCanvas::SetControl(_Control& control)
691 __pControl = &control;
696 _GalleryRootCanvas::GetControl(void) const
702 _GalleryRootCanvas::GetImageVisualElement(void) const
704 return GetControl().GetVisualElement();
707 }}} // Tizen::Ui::Controls