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.
19 * @file FUiAnim_VisualElementCanvas.cpp
20 * @brief This file contains implementation of _VisualElementCanvas class
22 * This file contains implementation _VisualElementCanvas class.
25 #include <FBaseSysLog.h>
26 #include <FGrpPoint.h>
27 #include <FGrpCanvas.h>
28 #include <FGrp_CanvasImpl.h>
29 #include <FGrp_Canvas.h>
30 #include <FGrp_CanvasCoordHolder.h>
31 #include <FUiAnimVisualElementSurface.h>
33 #include "FUi_CoordinateSystemUtils.h"
34 #include "FUiAnim_VisualElementCanvas.h"
35 #include "FUiAnim_VisualElementSurfaceImpl.h"
38 namespace Tizen { namespace Ui { namespace Animations
41 // TBD: from WinCanvas...... new class really needed???
42 //class _VisualElementCanvas :
43 // public Tizen::Ui::__WinCanvas
47 _VisualElementCanvas::_VisualElementCanvas(void)
51 _VisualElementCanvas::~_VisualElementCanvas(void)
56 // need to convert rectangle into physical coordinates internally...
59 _VisualElementCanvas::Construct(const VisualElementSurface& surface, const Tizen::Graphics::Rectangle& rectangle)
64 Tizen::Graphics::_CanvasImpl* pCanvasImpl = Tizen::Graphics::_CanvasImpl::GetInstance(*this);
65 Tizen::Graphics::_Canvas* pNativeCanvas = (pCanvasImpl) ? pCanvasImpl->_pNativeCanvas : 0;
67 SysTryReturnResult(NID_UI, pCanvasImpl && pNativeCanvas, E_OUT_OF_MEMORY, "Memory allocation failed.");
68 SysTryReturnResult(NID_UI, _VisualElementSurfaceImpl::GetInstance(surface), E_SYSTEM, "A system error has been occurred. Invalid surface.");
70 Handle window = _VisualElementSurfaceImpl::GetInstance(surface)->GetNativeHandle();
71 r = pNativeCanvas->Construct(window, _CoordinateSystemUtils::Transform(rectangle));
72 SysTryReturnResult(NID_UI, r == E_SUCCESS, r, "Failed to construct Canvas with the size (%d:%d).", rectangle.width, rectangle.height);
74 pNativeCanvas->__windowHandle = static_cast< Handle >(window);
76 Tizen::Graphics::Rectangle realBounds = pNativeCanvas->GetBounds();
78 Tizen::Graphics::Dimension adoptedSize;
80 Tizen::Graphics::Dimension revisedSize = _CoordinateSystemUtils::InverseTransform(Tizen::Graphics::Dimension(realBounds.width, realBounds.height));
81 Tizen::Graphics::Rectangle physicalGivenBounds = _CoordinateSystemUtils::Transform(rectangle);
83 adoptedSize.width = (physicalGivenBounds.width == realBounds.width) ? rectangle.width : revisedSize.width;
84 adoptedSize.height = (physicalGivenBounds.height == realBounds.height) ? rectangle.height : revisedSize.height;
86 Tizen::Graphics::Rectangle revisedBounds(rectangle.x, rectangle.y, adoptedSize.width, adoptedSize.height);
88 if (pCanvasImpl->_pCoordHolder)
90 pCanvasImpl->_pCoordHolder->Init(revisedBounds);