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 FUi_Rectanglef.h
20 * @brief Header file of _Rectanglef class
22 * This file contains declarations _Rectanglef class.
25 #ifndef _FUI_ANIM_INTERNAL_RECTANGLEF_H_
26 #define _FUI_ANIM_INTERNAL_RECTANGLEF_H_
28 #include <FGrpRectangle.h>
31 #include "FUi_Pointf.h"
32 #include "FUi_Dimensionf.h"
34 namespace Tizen { namespace Ui { namespace Animations
42 __left = __top = __width = __height = 0.0f;
45 _Rectanglef(float left, float top, float width, float height)
53 _Rectanglef(const Tizen::Graphics::Rectangle& rt)
55 __left = static_cast<float>(rt.x);
56 __top = static_cast<float>(rt.y);
57 __width = static_cast<float>(rt.width);
58 __height = static_cast<float>(rt.height);
61 _Rectanglef(const Tizen::Graphics::FloatRectangle& rt)
69 _Rectanglef(const _Rectanglef& rt) { *this = rt;}
71 bool operator ==(const _Rectanglef& rt) const
73 return (__left == rt.__left && __top == rt.__top && __width == rt.__width && __height == rt.__height);
76 bool operator ==(const Tizen::Graphics::FloatRectangle& rt) const
78 return (__left == rt.x && __top == rt.y && __width == rt.width && __height == rt.height);
81 bool operator !=(const _Rectanglef& rt) const
83 return !(__left == rt.__left && __top == rt.__top && __width == rt.__width && __height == rt.__height);
86 bool operator !=(const Tizen::Graphics::FloatRectangle& rt) const
88 return !(__left == rt.x && __top == rt.y && __width == rt.width && __height == rt.height);
91 _Rectanglef& operator =(const _Rectanglef& rt)
98 __height = rt.__height;
104 _Rectanglef& operator =(const Tizen::Graphics::FloatRectangle& rt)
109 __height = rt.height;
113 operator Tizen::Graphics::Rectangle(void) const
115 return Tizen::Graphics::Rectangle(
116 static_cast<int>(__left),
117 static_cast<int>(__top),
118 static_cast<int>(__left + __width) - static_cast<int>(__left),
119 static_cast<int>(__top + __height) - static_cast<int>(__top)
123 bool IsEmpty(void) const
125 if (__width <= 0.0f || __height <= 0.0f)
133 __left = __top = __width = __height = 0.0f;
136 bool IsIntersected(const _Rectanglef& rt) const
138 if (IsEmpty() || rt.IsEmpty())
141 if (__left >= rt.Right())
144 if (__top >= rt.Bottom())
147 if (Right() <= rt.__left)
150 if (Bottom() <= rt.__top)
156 /* TODO: rename method names such as MakeIntersect */
157 _Rectanglef Intersect(const _Rectanglef& rt) const
161 if (IsIntersected(rt))
163 retRect.__left = _Max(__left, rt.__left);
164 retRect.__top = _Max(__top, rt.__top);
165 retRect.__width = _Min(Right(), rt.Right()) - retRect.__left;
166 retRect.__height = _Min(Bottom(), rt.Bottom()) - retRect.__top;
172 _Rectanglef Union(const _Rectanglef& rt) const
179 return _Rectanglef();
189 retRect.__left = _Min(__left, rt.__left);
190 retRect.__top = _Min(__top, rt.__top);
191 retRect.__width = _Max(Right(), rt.Right()) - retRect.__left;
192 retRect.__height = _Max(Bottom(), rt.Bottom()) - retRect.__top;
197 void OffsetRect(const _Pointf& point)
203 void OffsetRect(float dx, float dy)
209 void InflateRect(float dx, float dy)
217 void SetRect(float l, float t, float w, float h)
225 bool Contains(float x, float y) const
227 return (x >= __left && x < Right() && y >= __top && y < Bottom());
230 bool Contains(const _Pointf& pt) const
232 return Contains(pt.x, pt.y);
235 bool Contains(const _Rectanglef& rt) const
237 return (!rt.IsEmpty() && __left <= rt.__left && __top <= rt.__top && Right() >= rt.Right() && Bottom() >= rt.Bottom());
240 _Rectanglef& SetLeftTop(float left, float top) { __left = left;__top = top;return *this;}
241 _Rectanglef& SetLeftTop(const _Pointf& leftTop) { __left = leftTop.X();__top = leftTop.Y();return *this;}
242 _Rectanglef& SetSize(const _Dimensionf& size) { __width = size.Width();__height = size.Height();return *this;}
244 _Pointf LeftTop(void) const { return _Pointf(__left, __top);}
245 _Pointf RightBottom(void) const { return _Pointf(__left + __width, __top + __height);}
247 float& Left(void) { return __left;}
248 float& Top(void) { return __top;}
249 float& Width(void) { return __width;}
250 float& Height(void) { return __height;}
252 float Left(void) const { return __left;}
253 float Top(void) const { return __top;}
254 float Right(void) const { return __left + __width;}
255 float Bottom(void) const { return __top + __height;}
256 float Width(void) const { return __width;}
257 float Height(void) const { return __height;}
259 int IntegralLeft(void) const { return (int) __left;}
260 int IntegralTop(void) const { return (int) __top;}
261 int IntegralWidth(void) const { return (int) Right() - IntegralLeft();}
262 int IntegralHeight(void) const { return (int) Bottom() - IntegralTop();}
271 }}} // Tizen::Ui::Animations
273 #endif // _FUI_ANIM_INTERNAL_RECTANGLEF_H_