Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnim_VisualElementCoordinateSystem.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_VisualElementCoordinateSystem.cpp
20  * @brief       This file contains implementation of _VisualElementCoordinateSystem class
21  *
22  * This file contains implementation _VisualElementCoordinateSystem class.
23  */
24
25 #include <FGrpFloatPoint.h>
26 #include <FGrpFloatDimension.h>
27 #include <FGrpFloatRectangle.h>
28 #include <FGrp_Screen.h>
29
30 #include "FUi_CoordinateSystemUtils.h"
31 #include "FUiAnim_VisualElementCoordinateSystem.h"
32
33 namespace Tizen { namespace Ui { namespace Animations
34 {
35
36 float _VisualElementCoordinateSystem::scaleFactorX = 1.0f;
37 float _VisualElementCoordinateSystem::scaleFactorY = 1.0f;
38 int _VisualElementCoordinateSystem::logScreenWidth = 0;
39 int _VisualElementCoordinateSystem::logScreenHeight = 0;
40 bool _VisualElementCoordinateSystem::needScale = false;
41
42 void
43 _VisualElementCoordinateSystem::Initialize(void)
44 {
45         needScale = false;
46
47         // Initialize auto-scale factors
48         Tizen::Graphics::_CoordinateSystem* pCoordSys = Tizen::Graphics::_CoordinateSystem::GetInstance();
49
50         if (pCoordSys->IsTransformEnabled() == true)
51         {
52                 scaleFactorX = pCoordSys->GetTransformer()->GetHorizontalScaleFactor();
53                 scaleFactorY = pCoordSys->GetTransformer()->GetVerticalScaleFactor();
54
55                 // WARNING:
56                 //      1. The values 'scaleFactorX' and 'scaleFactorY' may be greater than expected 'cause of float-error.
57                 //      So, it is needed to cut-off some significant digits to ensure the scale factors are always less or equal than real values.
58                 //      The cut-off position should be lower than the compensation value(> 10^3 due to rounding), too.
59                 //      2. The number fo siginificant digits for float is about 6 (5 for sure).
60                 //      So, the scaleFactor to cut-off should be less or equal than 10^6.
61
62                 const float scaleFactor = 1000.0f / floatIntegralEpsilon;
63                 //SysAssert(scaleFactor <= 1000000.0f);
64
65                 scaleFactorX = floorf(scaleFactorX * scaleFactor) / scaleFactor;
66                 scaleFactorY = floorf(scaleFactorY * scaleFactor) / scaleFactor;
67
68                 needScale = true;
69         }
70
71         int physScreenWidth = Tizen::Graphics::_Screen::GetWidth();
72         int physScreenHeight = Tizen::Graphics::_Screen::GetHeight();
73         float sWidth = static_cast< float >(physScreenWidth);
74         float sHeight = static_cast< float >(physScreenHeight);
75
76         ConvertDimensionToLogicalIntegral(sWidth, sHeight);
77         logScreenWidth = static_cast< int >(sWidth);
78         logScreenHeight = static_cast< int >(sHeight);
79
80         ConvertDimensionToPhysicalIntegral(sWidth, sHeight);
81
82         SysAssert(static_cast< int >(sWidth) <= physScreenWidth);
83         SysAssert(static_cast< int >(sHeight) <= physScreenHeight);
84 }
85
86 }}}     // Tizen::Ui::Animations
87