Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / inc / FUiAnim_VisualElementCoordinateSystem.h
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.h
20  * @brief       This is the header file for the _VisualElementCoordinateSystem class.
21  *
22  * This header file contains the declarations of the _VisualElementCoordinateSystem class.
23  */
24
25 #ifndef _FUI_ANIM_INTERNAL_VISUAL_ELEMENT_COORDINATE_SYSTEM_H_
26 #define _FUI_ANIM_INTERNAL_VISUAL_ELEMENT_COORDINATE_SYSTEM_H_
27
28 #include <math.h>
29
30 namespace Tizen { namespace Ui { namespace Animations
31 {
32
33 class _OSP_EXPORT_ _VisualElementCoordinateSystem
34 {
35 public:
36         static void Initialize(void);
37
38         static void MakeIntegralPoint(float& x, float& y)
39         {
40                 x = floorf(x + floatIntegralEpsilon);
41                 y = floorf(y + floatIntegralEpsilon);
42         }
43
44         static void MakeIntegralPoint(float x, float y, int& intX, int& intY)
45         {
46                 intX = int(floorf(x + floatIntegralEpsilon));
47                 intY = int(floorf(y + floatIntegralEpsilon));
48         }
49
50         static void MakeIntegralDimension(float& width, float& height)
51         {
52                 width = floorf(width + floatIntegralEpsilon);
53                 height = floorf(height + floatIntegralEpsilon);
54         }
55
56         static void MakeIntegralDimension(float width, float height, int& intWidth, int& intHeight)
57         {
58                 intWidth = int(floorf(width + floatIntegralEpsilon));
59                 intHeight = int(floorf(height + floatIntegralEpsilon));
60         }
61
62         static void ConvertDimensionToPhysical(float& width, float& height)
63         {
64                 if (unlikely(needScale))
65                 {
66                         width *= scaleFactorX;
67                         height *= scaleFactorY;
68                 }
69         }
70
71         static void ConvertRectangleToPhysical(float& x, float& y, float& width, float& height)
72         {
73                 if (unlikely(needScale))
74                 {
75                         ConvertPointToPhysical(x, y);
76                         ConvertDimensionToPhysical(width, height);;
77                 }
78         }
79
80         static void ConvertDimensionToPhysicalIntegral(float& width, float& height)
81         {
82                 if (unlikely(needScale))
83                 {
84                         width *= scaleFactorX;
85                         height *= scaleFactorY;
86
87                         // WARNING:
88                         //      Because auto-scaling coordinate system of graphics ceils only for down-scaling, we do the same !
89                         // CHECKME:
90                         //      Separate Horz/Vert handling ?
91                         MakeIntegralDimension(width, height);
92                 }
93         }
94
95         static void ConvertDimensionToPhysicalIntegral(float width, float height, int& intWidth, int& intHeight)
96         {
97                 ConvertDimensionToPhysicalIntegral(width, height);
98                 intWidth = static_cast< int >(width);
99                 intHeight = static_cast< int >(height);
100         }
101
102         static void ConvertDimensionToLogicalIntegral(float& width, float& height)
103         {
104                 if (unlikely(needScale))
105                 {
106                         width /= scaleFactorX;
107                         height /= scaleFactorY;
108
109                         // WARNING:
110                         //      Because auto-scaling coordinate system of graphics ceils only for down-scaling, we do the same !
111                         // CHECKME:
112                         //      Separate Horz/Vert handling ?
113                         MakeIntegralDimension(width, height);
114                 }
115         }
116
117         static void ConvertDimensionToLogicalIntegral(float width, float height, int& intWidth, int& intHeight)
118         {
119                 ConvertDimensionToLogicalIntegral(width, height);
120                 intWidth = static_cast< int >(width);
121                 intHeight = static_cast< int >(height);
122         }
123
124         static void ConvertDimensionToLogical(float& width, float& height)
125         {
126                 if (unlikely(needScale))
127                 {
128                         width /= scaleFactorX;
129                         height /= scaleFactorY;
130                 }
131         }
132
133         static void ConvertPointToPhysical(float& x, float& y)
134         {
135                 if (unlikely(needScale))
136                 {
137                         x *= scaleFactorX;
138                         y *= scaleFactorY;
139                 }
140         }
141
142         static void ConvertPointToLogical(float& x, float& y)
143         {
144                 if (unlikely(needScale))
145                 {
146                         x /= scaleFactorX;
147                         y /= scaleFactorY;
148                 }
149         }
150
151 public:
152         // WARNING:
153         //      Some float functions like sin and cos emit too-much float-error.
154         //      So, the rounding const must be a bigger value than expected.
155         static const float floatIntegralEpsilon = 0.01f;
156
157         static bool needScale;
158         static float scaleFactorX;
159         static float scaleFactorY;
160         static int logScreenWidth;
161         static int logScreenHeight;
162 };              // _VisualElementCoordinateSystem
163
164 }}}             // Tizen::Ui::Animations
165
166 #endif  // _FUI_ANIM_INTERNAL_VISUAL_ELEMENT_COORDINATE_SYSTEM_H_
167