Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / ui / animations / FUiAnim_VisualElementCanvas.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17
18 /**
19  * @file        FUiAnim_VisualElementCanvas.cpp
20  * @brief       This file contains implementation of _VisualElementCanvas class
21  *
22  * This file contains implementation _VisualElementCanvas class.
23  */
24
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>
32
33 #include "FUi_CoordinateSystemUtils.h"
34 #include "FUiAnim_VisualElementCanvas.h"
35 #include "FUiAnim_VisualElementSurfaceImpl.h"
36
37
38 namespace Tizen { namespace Ui { namespace Animations
39 {
40
41 // TBD: from WinCanvas...... new class really needed???
42 //class _VisualElementCanvas :
43 //      public Tizen::Ui::__WinCanvas
44 //{
45 //};
46
47 _VisualElementCanvas::_VisualElementCanvas(void)
48 {
49 }
50
51 _VisualElementCanvas::~_VisualElementCanvas(void)
52 {
53 }
54
55 // TODO:
56 //      need to convert rectangle into physical coordinates internally...
57 //
58 result
59 _VisualElementCanvas::Construct(const VisualElementSurface& surface, const Tizen::Graphics::Rectangle& rectangle)
60 {
61         ClearLastResult();
62         result r = E_SUCCESS;
63
64         Tizen::Graphics::_CanvasImpl* pCanvasImpl = Tizen::Graphics::_CanvasImpl::GetInstance(*this);
65         Tizen::Graphics::_Canvas* pNativeCanvas = (pCanvasImpl) ? pCanvasImpl->_pNativeCanvas : 0;
66
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.");
69
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);
73
74         pNativeCanvas->__windowHandle = static_cast< Handle >(window);
75
76         Tizen::Graphics::Rectangle realBounds = pNativeCanvas->GetBounds();
77
78         Tizen::Graphics::Dimension adoptedSize;
79
80         Tizen::Graphics::Dimension revisedSize = _CoordinateSystemUtils::InverseTransform(Tizen::Graphics::Dimension(realBounds.width, realBounds.height));
81         Tizen::Graphics::Rectangle physicalGivenBounds = _CoordinateSystemUtils::Transform(rectangle);
82
83         adoptedSize.width = (physicalGivenBounds.width == realBounds.width) ? rectangle.width : revisedSize.width;
84         adoptedSize.height = (physicalGivenBounds.height == realBounds.height) ? rectangle.height : revisedSize.height;
85
86         Tizen::Graphics::Rectangle revisedBounds(rectangle.x, rectangle.y, adoptedSize.width, adoptedSize.height);
87
88         if (pCanvasImpl->_pCoordHolder)
89         {
90                 pCanvasImpl->_pCoordHolder->Init(revisedBounds);
91         }
92
93         return r;
94 }
95
96
97 }}}