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.
20 * @brief This is the header file for internal _Util namespace.
24 #ifndef _FGRP_INTERNAL_UTIL_H_
25 #define _FGRP_INTERNAL_UTIL_H_
29 #include <FGrpPoint.h>
30 #include <FGrpFloatPoint.h>
32 #include <FGrpDimension.h>
33 #include <FGrpFloatDimension.h>
35 #include <FGrpRectangle.h>
36 #include <FGrpFloatRectangle.h>
38 #include <FGrpBufferInfo.h>
39 #include <FGrpBitmap.h>
40 #include <FGrpCanvas.h>
42 #include <FGrpEnrichedText.h>
44 #include "FGrp_BitmapImpl.h"
45 #include "FGrp_CanvasImpl.h"
46 #include "FGrp_FontImpl.h"
47 #include "FGrp_EnrichedTextImpl.h"
49 #include "FGrp_UtilTemplate.h"
50 #include "FGrp_UtilType.h"
53 namespace Tizen { namespace Graphics
63 result Validate(const ::Tizen::Graphics::Rectangle& rtSrc, const ::Tizen::Graphics::Rectangle& rtDest);
64 result Validate(const ::Tizen::Graphics::Point& ptSrc, const ::Tizen::Graphics::Rectangle& rtDest);
67 result ValidateT(const Rectangle<T>& rtSrc, const Rectangle<T>& rtDest)
69 // check 1. is width/height less or equal than 0?
70 if (rtSrc.w <= 0 || rtSrc.h <= 0 || rtDest.w <= 0 || rtDest.h <= 0)
72 SysTryReturnResult(NID_GRP, 0, E_OUT_OF_RANGE, "The argument is out of range. (src(w:%d,h:%d), dst(w:%d,h:%d)).",
73 rtSrc.w, rtSrc.h, rtDest.w, rtDest.h);
76 // check 2. is src exiting outside of dest entirely?
77 if (rtSrc.x > rtDest.x + rtDest.w - 1 || rtSrc.x + rtSrc.w - 1 < rtDest.x)
79 SysTryReturnResult(NID_GRP, 0, E_OUT_OF_RANGE,
80 "The argument is out of range. (src(x:%d,y:%d,w:%d,h:%d), dst(x:%d,y:%d,w:%d,h:%d)).",
81 rtSrc.x, rtSrc.y, rtSrc.w, rtSrc.h, rtDest.x, rtDest.y, rtDest.w, rtDest.h);
84 if (rtSrc.y > rtDest.y + rtDest.h - 1 || rtSrc.y + rtSrc.h - 1 < rtDest.y)
86 SysTryReturnResult(NID_GRP, 0, E_OUT_OF_RANGE,
87 "The argument is out of range. (src(x:%d,y:%d,w:%d,h:%d), dst(x:%d,y:%d,w:%d,h:%d)).",
88 rtSrc.x, rtSrc.y, rtSrc.w, rtSrc.h, rtDest.x, rtDest.y, rtDest.w, rtDest.h);
95 result ValidateT(const Point<T>& ptSrc, const Rectangle<T>& rtDest)
97 SysTryReturnResult(NID_GRP, rtDest.x <= ptSrc.x &&
98 ptSrc.x < rtDest.x + rtDest.w &&
99 rtDest.y <= ptSrc.y &&
100 ptSrc.y < rtDest.y + rtDest.h,
101 E_OUT_OF_RANGE, "The argument is out of range. (src(x:%d,y:%d), dst(x:%d,y:%d,w:%d,h:%d)).\n",
102 ptSrc.x, ptSrc.y, rtDest.x, rtDest.y, rtDest.w, rtDest.h);
107 bool IntersectRect(Rectangle<int>& outRect, const Rectangle<int>& srcRect1, const Rectangle<int>& srcRect2);
108 bool IntersectRect(Rectangle<float>& outRect, const Rectangle<float>& srcRect1, const Rectangle<float>& srcRect2);
110 ////////////////////////////////////////////////////////////////////////////
116 LockManager(const class _Bitmap& bitmap);
117 LockManager(const class _Canvas& canvas);
118 LockManager(const class _BitmapImpl& bitmapImpl);
119 LockManager(const class _CanvasImpl& canvasImpl);
122 bool IsValid(void) const;
123 result GetResult(void) const;
124 const BufferInfo& GetBufferInfo(void) const;
131 _BitmapImpl* __pBitmapImpl;
132 _CanvasImpl* __pCanvasImpl;
133 BufferInfo __bufferInfo;
136 ////////////////////////////////////////////////////////////////////////////
137 // ScalarHolder structure
150 ScalarHolder(int initValue)
151 : applied(AS_INTEGER)
152 , asInteger(initValue)
153 , asDouble(double(initValue))
157 ScalarHolder(double initValue)
159 , asInteger(int(initValue + 0.5))
160 , asDouble(initValue)
164 int operator=(int value)
166 applied = AS_INTEGER;
168 asDouble = double(value);
173 double operator=(double value)
176 asInteger = int(value + 0.5);
183 ////////////////////////////////////////////////////////////////////////////
186 result GetPatchList(AccumList <Pair <Rectangle<int>, Rectangle<int> > >& outList, const ::Tizen::Graphics::Rectangle& rect, const _Bitmap& bitmap);
188 ////////////////////////////////////////////////////////////////////////////
193 CheckValidity(T* pInstance)
195 return (pInstance != null);
200 CheckValidity(const Bitmap* pInstance)
202 return (pInstance && _BitmapImpl::GetInstance(*pInstance));
207 CheckValidity(Bitmap* pInstance)
209 return (pInstance && _BitmapImpl::GetInstance(*pInstance));
214 CheckValidity(const Canvas* pInstance)
216 return (pInstance && _CanvasImpl::GetInstance(*pInstance));
221 CheckValidity(Canvas* pInstance)
223 return (pInstance && _CanvasImpl::GetInstance(*pInstance));
228 CheckValidity(const Font* pInstance)
230 return (pInstance && _FontImpl::GetInstance(*pInstance));
235 CheckValidity(Font* pInstance)
237 return (pInstance && _FontImpl::GetInstance(*pInstance));
242 CheckValidity(const EnrichedText* pInstance)
244 return (pInstance && _EnrichedTextImpl::GetInstance(*pInstance));
249 CheckValidity(EnrichedText* pInstance)
251 return (pInstance && _EnrichedTextImpl::GetInstance(*pInstance));
254 ////////////////////////////////////////////////////////////////////////////
257 template <typename T1, typename T2>
258 inline T2 Convert(const T1&);
261 inline _Util::Point<int> Convert<Tizen::Graphics::Point, _Util::Point<int> >(const Tizen::Graphics::Point& pos)
263 _Util::Point<int> temp =
273 inline _Util::Point<double> Convert<Tizen::Graphics::Point, _Util::Point<double> >(const Tizen::Graphics::Point& pos)
275 _Util::Point<double> temp =
277 static_cast<double>(pos.x),
278 static_cast<double>(pos.y)
285 inline _Util::Point<double> Convert<Tizen::Graphics::FloatPoint, _Util::Point<double> >(const Tizen::Graphics::FloatPoint& pos)
287 _Util::Point<double> temp = { pos.x, pos.y };
293 inline _Util::Dimension<double> Convert<Tizen::Graphics::Dimension, _Util::Dimension<double> >(const Tizen::Graphics::Dimension& dim)
295 _Util::Dimension<double> temp =
297 static_cast<double>(dim.width),
298 static_cast<double>(dim.height)
305 inline _Util::Dimension<double> Convert<Tizen::Graphics::FloatDimension, _Util::Dimension<double> >(const Tizen::Graphics::FloatDimension& dim)
307 _Util::Dimension<double> temp = { dim.width, dim.height };
313 inline _Util::Rectangle<double> Convert<Tizen::Graphics::Rectangle, _Util::Rectangle<double> >(const Tizen::Graphics::Rectangle& rect)
315 _Util::Rectangle<double> temp =
317 static_cast<double>(rect.x),
318 static_cast<double>(rect.y),
319 static_cast<double>(rect.width),
320 static_cast<double>(rect.height)
327 inline _Util::Rectangle<double> Convert<Tizen::Graphics::FloatRectangle, _Util::Rectangle<double> >(const Tizen::Graphics::FloatRectangle& rect)
329 _Util::Rectangle<double> temp = { rect.x, rect.y, rect.width, rect.height };
334 } // Tizen::Graphics::_Util
336 }} // Tizen::Graphics
338 #endif // _FGRP_INTERNAL_UTIL_H_