Revert " modify license, permission and remove ^M char"
[framework/osp/uifw.git] / src / graphics / FGrp_ResUtil.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        FGrp_ResUtil.h
20  * @brief       This is the header file for internal _ResUtil namespace.
21  *
22  */
23
24 #ifndef _FGRP_INTERNAL_RES_UTIL_H_
25 #define _FGRP_INTERNAL_RES_UTIL_H_
26
27 #include <new>
28
29 #include <math.h>
30
31 #include <FBaseColArrayList.h>
32 #include <FGrpPoint.h>
33 #include <FGrpRectangle.h>
34
35 #include "util/FGrp_UtilType.h"
36 #include "FGrp_Screen.h"
37
38 #if 0
39 #include "FGrp_CoordSystem.h"
40 ////////////////////////////////////////////////////////////////////////////////
41 // Coordinate conversion
42
43 namespace Tizen { namespace Graphics
44 {
45
46 namespace _ResUtil
47 {
48 struct Rect
49 {
50         int x, y, w, h;
51
52         Rect()
53                 : x(0)
54                 , y(0)
55                 , w(0)
56                 , h(0)
57         {
58         }
59
60         Rect(int _x, int _y, int _w, int _h)
61                 : x(_x)
62                 , y(_y)
63                 , w(_w)
64                 , h(_h)
65         {
66         }
67 };
68
69 struct Pos
70 {
71         int x, y;
72
73         Pos()
74                 : x(0)
75                 , y(0)
76         {
77         }
78
79         Pos(int _x, int _y)
80                 : x(_x)
81                 , y(_y)
82         {
83         }
84 };
85
86 struct Size
87 {
88         int w, h;
89
90         Size()
91                 : w(0)
92                 , h(0)
93         {
94         }
95
96         Size(int _w, int _h)
97                 : w(_w)
98                 , h(_h)
99         {
100         }
101 };
102
103 // base template
104 template<unsigned int VirRes, unsigned int PhyRes>
105 struct ResConv1d
106 {
107         inline static int ToVirCoord(int phy);
108         inline static int ToPhyCoord(int vir);
109         inline static int ToPhyCoord4Size(int vir);
110 };
111
112 // 2D base template
113 template<unsigned int VirResX, unsigned int VirResY, unsigned int PhyResX, unsigned int PhyResY>
114 struct ResConv2d
115 {
116         inline static int ToVirCoordX(int phyX)
117         {
118                 return ResConv1d <VirResX, PhyResX>::ToVirCoord(phyX);
119         }
120
121         inline static int ToVirCoordY(int phyY)
122         {
123                 return ResConv1d <VirResY, PhyResY>::ToVirCoord(phyY);
124         }
125
126         inline static int ToPhyCoordX(int virX)
127         {
128                 return ResConv1d <VirResX, PhyResX>::ToPhyCoord(virX);
129         }
130
131         inline static int ToPhyCoordY(int virY)
132         {
133                 return ResConv1d <VirResY, PhyResY>::ToPhyCoord(virY);
134         }
135
136         inline static int ToPhyCoord4Size(int vir)
137         {
138                 return ResConv1d <VirResY, PhyResY>::ToPhyCoord4Size(vir);
139         }
140 };
141
142 /////////////////////
143
144 enum ResType
145 {
146         RES_WVGA,
147         RES_WQVGA,
148         RES_HVGA,
149         RES_WVGA_COMPAT,
150         RES_QHD
151 };
152
153 template<ResType Res>
154 struct ResTraits
155 {
156 };
157
158 template<ResType VirRes, ResType PhyRes>
159 struct ResConv
160 {
161         typedef ResConv2d <ResTraits <VirRes>::ResWidth, ResTraits <VirRes>::ResHeight, ResTraits <PhyRes>::ResWidth,
162                                          ResTraits <PhyRes>::ResHeight> CurrentResConv;
163
164         template<typename T>
165         inline static T ToPhyCoord(const T& sour)
166         {
167                 return CurrentResConv::ToPhyCoordY(sour);
168         }
169
170         template<typename T>
171         inline static T ToVirCoord(const T& sour)
172         {
173                 return CurrentResConv::ToVirCoordY(sour);
174         }
175
176         inline static int ToPhyCoordSize(int sour)
177         {
178                 return CurrentResConv::ToPhyCoord4Size(sour);
179         }
180
181         inline static int ToPhyCoordX(int sour)
182         {
183                 return CurrentResConv::ToPhyCoordX(sour);
184         }
185
186         inline static int ToPhyCoordY(int sour)
187         {
188                 return CurrentResConv::ToPhyCoordY(sour);
189         }
190
191         inline static int ToPhyCoordW(int sour)
192         {
193                 return CurrentResConv::ToPhyCoordX(sour);
194         }
195
196         inline static int ToPhyCoordH(int sour)
197         {
198                 return CurrentResConv::ToPhyCoordY(sour);
199         }
200
201         inline static int ToVirCoordX(int sour)
202         {
203                 return CurrentResConv::ToVirCoordX(sour);
204         }
205
206         inline static int ToVirCoordY(int sour)
207         {
208                 return CurrentResConv::ToVirCoordY(sour);
209         }
210
211         inline static int ToVirCoordW(int sour)
212         {
213                 return CurrentResConv::ToVirCoordX(sour);
214         }
215
216         inline static int ToVirCoordH(int sour)
217         {
218                 return CurrentResConv::ToVirCoordY(sour);
219         }
220
221         inline static Rect ToPhyCoord(const Rect& sour)
222         {
223                 int destX = CurrentResConv::ToPhyCoordX(sour.x);
224                 int destY = CurrentResConv::ToPhyCoordY(sour.y);
225
226                 return Rect
227                         (
228                                 destX,
229                                 destY,
230                                 CurrentResConv::ToPhyCoordX(sour.x + sour.w) - destX,
231                                 CurrentResConv::ToPhyCoordY(sour.y + sour.h) - destY
232                         );
233         }
234
235         inline static Pos ToPhyCoord(const Pos& sour)
236         {
237                 return Pos
238                         (
239                                 CurrentResConv::ToPhyCoordX(sour.x),
240                                 CurrentResConv::ToPhyCoordY(sour.y)
241                         );
242         }
243
244         inline static Size ToPhyCoord(const Size& sour)
245         {
246                 return Size
247                         (
248                                 CurrentResConv::ToPhyCoordX(sour.w),
249                                 CurrentResConv::ToPhyCoordY(sour.h)
250                         );
251         }
252
253         inline static Tizen::Graphics::Rectangle ToPhyCoord(const Tizen::Graphics::Rectangle& sour)
254         {
255                 Tizen::Graphics::Rectangle dest;
256
257                 dest.x = CurrentResConv::ToPhyCoordX(sour.x);
258                 dest.y = CurrentResConv::ToPhyCoordY(sour.y);
259                 ;
260                 dest.width = CurrentResConv::ToPhyCoordX(sour.x + sour.width) - dest.x;
261                 dest.height = CurrentResConv::ToPhyCoordY(sour.y + sour.height) - dest.y;
262
263                 return dest;
264         }
265
266         inline static Tizen::Graphics::Point ToPhyCoord(const Tizen::Graphics::Point& sour)
267         {
268                 return Tizen::Graphics::Point(CurrentResConv::ToPhyCoordX(sour.x), CurrentResConv::ToPhyCoordY(sour.y));
269         }
270
271         inline static Tizen::Graphics::Dimension ToPhyCoord(const Tizen::Graphics::Dimension& sour)
272         {
273                 return Tizen::Graphics::Dimension(CurrentResConv::ToPhyCoordX(sour.width), CurrentResConv::ToPhyCoordY(sour.height));
274         }
275
276         inline static Rect ToVirCoord(const Rect& sour)
277         {
278                 int destX = CurrentResConv::ToVirCoordX(sour.x);
279                 int destY = CurrentResConv::ToVirCoordY(sour.y);
280
281                 return Rect
282                         (
283                                 destX,
284                                 destY,
285                                 CurrentResConv::ToVirCoordX(sour.x + sour.w) - destX,
286                                 CurrentResConv::ToVirCoordY(sour.y + sour.h) - destY
287                         );
288         }
289
290         inline static Pos ToVirCoord(const Pos& sour)
291         {
292                 return Pos
293                         (
294                                 CurrentResConv::ToVirCoordX(sour.x),
295                                 CurrentResConv::ToVirCoordY(sour.y)
296                         );
297         }
298
299         inline static Size ToVirCoord(const Size& sour)
300         {
301                 return Size
302                         (
303                                 CurrentResConv::ToVirCoordX(sour.w),
304                                 CurrentResConv::ToVirCoordY(sour.h)
305                         );
306         }
307
308         inline static Tizen::Graphics::Rectangle ToVirCoord(const Tizen::Graphics::Rectangle& sour)
309         {
310                 Rect pc_rect = Rect(sour.x, sour.y, sour.width, sour.height);
311                 Rect vc_rect = ResConv <VirRes, PhyRes>::ToVirCoord(pc_rect);
312
313                 return Tizen::Graphics::Rectangle(vc_rect.x, vc_rect.y, vc_rect.w, vc_rect.h);
314         }
315
316         inline static Tizen::Graphics::Point ToVirCoord(const Tizen::Graphics::Point& sour)
317         {
318                 return Tizen::Graphics::Point(CurrentResConv::ToVirCoordX(sour.x), CurrentResConv::ToVirCoordY(sour.y));
319         }
320
321         inline static Tizen::Graphics::Dimension ToVirCoord(const Tizen::Graphics::Dimension& sour)
322         {
323                 return Tizen::Graphics::Dimension(CurrentResConv::ToVirCoordX(sour.width), CurrentResConv::ToVirCoordY(sour.height));
324         }
325 };
326
327 } // Tizen::Graphics::_ResUtil
328
329 }} // Tizen::Graphics
330
331 ////////////////////////////////////////////////////////////////////////////////
332 // Specialization
333
334 namespace Tizen { namespace Graphics
335 {
336
337 namespace _ResUtil
338 {
339 // (480x800) -> (240x400)
340 template<>
341 inline int
342 ResConv1d <480, 240>::ToVirCoord(int phy)
343 {
344         return (phy << 1);
345 };
346
347 template<>
348 inline int
349 ResConv1d <480, 240>::ToPhyCoord(int vir)
350 {
351         return (vir >> 1);
352 };
353
354 template<>
355 inline int
356 ResConv1d <480, 240>::ToPhyCoord4Size(int vir)
357 {
358         return (vir >= 0) ? ((vir + 1) >> 1) : (vir >> 1);
359 };
360
361 template<>
362 inline int
363 ResConv1d <800, 400>::ToVirCoord(int phy)
364 {
365         return (phy << 1);
366 };
367
368 template<>
369 inline int
370 ResConv1d <800, 400>::ToPhyCoord(int vir)
371 {
372         return (vir >> 1);
373 };
374
375 template<>
376 inline int
377 ResConv1d <800, 400>::ToPhyCoord4Size(int vir)
378 {
379         return (vir >= 0) ? ((vir + 1) >> 1) : (vir >> 1);
380 };
381
382 // (240x400) -> (480x800)
383 template<>
384 inline int
385 ResConv1d <240, 480>::ToVirCoord(int phy)
386 {
387         return (phy >> 1);
388 };
389
390 template<>
391 inline int
392 ResConv1d <240, 480>::ToPhyCoord(int vir)
393 {
394         return (vir << 1);
395 };
396
397 template<>
398 inline int
399 ResConv1d <240, 480>::ToPhyCoord4Size(int vir)
400 {
401         return (vir << 1);
402 };
403
404 template<>
405 inline int
406 ResConv1d <400, 800>::ToVirCoord(int phy)
407 {
408         return (phy >> 1);
409 };
410
411 template<>
412 inline int
413 ResConv1d <400, 800>::ToPhyCoord(int vir)
414 {
415         return (vir << 1);
416 };
417
418 template<>
419 inline int
420 ResConv1d <400, 800>::ToPhyCoord4Size(int vir)
421 {
422         return (vir << 1);
423 };
424
425 // (480x800) -> (320x480)
426 template<>
427 inline int
428 ResConv1d <480, 320>::ToVirCoord(int phy)
429 {
430         return ((phy) >= 0) ? ((phy) * 3 / 2) : (((phy) * 3 - 1) / 2);
431 };
432
433 template<>
434 inline int
435 ResConv1d <480, 320>::ToPhyCoord(int vir)
436 {
437         return ((vir) > 0) ? (((vir) + 1) * 2 / 3) : ((vir) * 2 / 3);
438 };
439
440 template<>
441 inline int
442 ResConv1d <480, 320>::ToPhyCoord4Size(int vir)
443 {
444         return ((vir) > 0) ? (((vir) + 1) * 2 / 3) : ((vir) * 2 / 3);
445 };
446
447 template<>
448 inline int
449 ResConv1d <800, 480>::ToVirCoord(int phy)
450 {
451         return ((phy) >= 0) ? ((phy) * 3 / 2) : (((phy) * 3 - 1) / 2);
452 };
453
454 template<>
455 inline int
456 ResConv1d <800, 480>::ToPhyCoord(int vir)
457 {
458         return ((vir) > 0) ? (((vir) + 1) * 2 / 3) : ((vir) * 2 / 3);
459 };
460
461 template<>
462 inline int
463 ResConv1d <800, 480>::ToPhyCoord4Size(int vir)
464 {
465         return ((vir) > 0) ? (((vir) + 1) * 2 / 3) : ((vir) * 2 / 3);
466 };
467
468 // (480x800) -> (320x480)  compatibility
469 template<>
470 inline int
471 ResConv1d <801, 480>::ToVirCoord(int phy)
472 {
473         return (phy * 5 / 3);
474 };
475
476 template<>
477 inline int
478 ResConv1d <801, 480>::ToPhyCoord(int vir)
479 {
480         return (vir * 3 / 5);
481 };
482
483 template<>
484 inline int
485 ResConv1d <801, 480>::ToPhyCoord4Size(int vir)
486 {
487         return (vir * 3 / 5);
488 };
489
490 // (240x400) -> (320x480) compatibility
491 template<>
492 inline int
493 ResConv1d <240, 320>::ToVirCoord(int phy)
494 {
495         return (phy * 3 / 4);
496 };
497
498 template<>
499 inline int
500 ResConv1d <240, 320>::ToPhyCoord(int vir)
501 {
502         return (vir * 4 / 3);
503 };
504
505 template<>
506 inline int
507 ResConv1d <240, 320>::ToPhyCoord4Size(int vir)
508 {
509         return (vir * 4 / 3);
510 };
511
512 template<>
513 inline int
514 ResConv1d <400, 480>::ToVirCoord(int phy)
515 {
516         return (phy * 5 / 6);
517 };
518
519 template<>
520 inline int
521 ResConv1d <400, 480>::ToPhyCoord(int vir)
522 {
523         return (vir * 6 / 5);
524 };
525
526 template<>
527 inline int
528 ResConv1d <400, 480>::ToPhyCoord4Size(int vir)
529 {
530         return (vir * 6 / 5);
531 };
532
533 // (480x800) -> (540x960)
534 template<>
535 inline int
536 ResConv1d <480, 540>::ToVirCoord(int phy)
537 {
538         return (phy * 8 / 9);
539 };
540
541 template<>
542 inline int
543 ResConv1d <480, 540>::ToPhyCoord(int vir)
544 {
545         return (vir * 9 / 8);
546 };
547
548 template<>
549 inline int
550 ResConv1d <480, 540>::ToPhyCoord4Size(int vir)
551 {
552         return (vir >= 0) ? ((vir + 5) * 9 / 8) : (vir * 9 / 8);
553 };
554
555 template<>
556 inline int
557 ResConv1d <800, 960>::ToVirCoord(int phy)
558 {
559         return (phy * 8 / 9);
560 };
561
562 template<>
563 inline int
564 ResConv1d <800, 960>::ToPhyCoord(int vir)
565 {
566         return (vir * 9 / 8);
567 };
568
569 template<>
570 inline int
571 ResConv1d <800, 960>::ToPhyCoord4Size(int vir)
572 {
573         return (vir >= 0) ? ((vir + 5) * 9 / 8) : (vir * 9 / 8);
574 };
575
576 ////////////////////////////////////////////////////////////////////////////////
577
578 template<>
579 struct ResTraits <RES_WVGA>
580 {
581         enum
582         {
583                 ResWidth = 480
584         };
585         enum
586         {
587                 ResHeight = 800
588         };
589 };
590
591 template<>
592 struct ResTraits <RES_WQVGA>
593 {
594         enum
595         {
596                 ResWidth = 240
597         };
598         enum
599         {
600                 ResHeight = 400
601         };
602 };
603
604 template<>
605 struct ResTraits <RES_HVGA>
606 {
607         enum
608         {
609                 ResWidth = 320
610         };
611         enum
612         {
613                 ResHeight = 480
614         };
615 };
616
617 template<>
618 struct ResTraits <RES_WVGA_COMPAT>
619 {
620         enum
621         {
622                 ResWidth = 480
623         };
624         enum
625         {
626                 ResHeight = (800 + 1)
627         };
628 };
629
630 template<>
631 struct ResTraits <RES_QHD>
632 {
633         enum
634         {
635                 ResWidth = 540
636         };
637         enum
638         {
639                 ResHeight = 960
640         };
641 };
642
643 } // Tizen::Graphics::_ResUtil
644
645 }} // Tizen::Graphics
646
647 ////////////////////////////////////////////////////////////////////////////////
648 // Macro
649
650 namespace Tizen { namespace Graphics
651 {
652
653 namespace _ResUtil
654 {
655
656 inline bool
657 NEED_TO_CONVERT(void)
658 {
659         _Resolution virRes = Tizen::Graphics::_CoordinateSystem::GetInstance()->GetInternalResolution();
660         _Resolution PhyRes = Tizen::Graphics::_CoordinateSystem::GetInstance()->GetDeviceResolution();
661
662         return (virRes != PhyRes);
663 }
664
665 typedef ResConv<RES_WQVGA, RES_WVGA> ResWQVGA2WVGA;
666 typedef ResConv<RES_WVGA, RES_WQVGA> ResWVGA2WQVGA;
667 typedef ResConv<RES_WVGA, RES_HVGA> ResWVGA2HVGA;
668 typedef ResConv<RES_WQVGA, RES_HVGA> ResWQVGA2HVGA;
669 typedef ResConv<RES_WVGA_COMPAT, RES_HVGA> ResWVGAcompat2HVGA;
670 typedef ResConv<RES_WVGA, RES_QHD> ResWVGA2QHD;
671
672 #if   defined(_MODEL_RES_WVGA)
673 // #error "Base resolution: 480 x 800"
674 typedef ResWQVGA2WVGA CurrentResConv;
675 #elif defined(_MODEL_RES_WQVGA)
676 // #error "Base resolution: 240 x 400"
677 typedef ResWVGA2WQVGA CurrentResConv;
678 #elif defined(_MODEL_RES_HVGA)
679 // #error "Base resolution: 320 x 480"
680 typedef ResWVGA2HVGA CurrentResConv;
681 #elif defined(_MODEL_RES_QHD)
682 // #error "Base resolution: 800 x 1280"
683 typedef ResWVGA2QHD CurrentResConv;
684 #else
685 //#error "Open CMakeLists.txt and define base resolution for new model"
686 typedef ResWVGA2WQVGA CurrentResConv;
687 #endif
688
689
690 #if 0 // defined(_MODEL_RES_HVGA)
691 #define NOT_FROM_WQVGA() (Tizen::Graphics::_CoordinateSystem::GetInstance()->GetInternalResolution() != \
692                                                   Tizen::Graphics::RESOLUTION_WQVGA)
693 #define NOT_FROM_WVGA_COMPAT() (Tizen::Graphics::_CoordinateSystem::GetInstance()->GetInternalResolution() !=   \
694                                                                 Tizen::Graphics::RESOLUTION_WVGA_COMPAT)
695 #define TRANSFORM(func, sour) \
696         ( \
697                 NEED_TO_CONVERT() \
698                 ? \
699                 ( \
700                         NOT_FROM_WQVGA() \
701                         ? \
702                         ( \
703                                 NOT_FROM_WVGA_COMPAT() \
704                                 ? \
705                                 ( \
706                                         CurrentResConv::func(sour) \
707                                 ) \
708                                 : \
709                                 ( \
710                                         ResWVGAcompat2HVGA::func(sour) \
711                                 ) \
712                         ) \
713                         : \
714                         ( \
715                                 ResWQVGA2HVGA::func(sour) \
716                         ) \
717                 ) \
718                 : \
719                 sour \
720         )
721
722 template<typename T>
723 inline T
724 TO_PHY_COORD(const T& sour)
725 {
726         return TRANSFORM(ToPhyCoord, sour);
727 }
728
729 template<typename T>
730 inline T
731 TO_VIR_COORD(const T& sour)
732 {
733         return TRANSFORM(ToVirCoord, sour);
734 }
735
736 #define CONVERT_TO_P_COORD_X(sour)      TRANSFORM(ToPhyCoordX, sour)
737 #define CONVERT_TO_P_COORD_Y(sour)      TRANSFORM(ToPhyCoordY, sour)
738 #define CONVERT_TO_P_COORD_W(sour)      TRANSFORM(ToPhyCoordW, sour)
739 #define CONVERT_TO_P_COORD_H(sour)      TRANSFORM(ToPhyCoordH, sour)
740 #define CONVERT_TO_P_COORD_SIZE(sour)   TRANSFORM(ToPhyCoordSize, sour)
741
742 #define CONVERT_TO_V_COORD_X(sour)      TRANSFORM(ToVirCoordX, sour)
743 #define CONVERT_TO_V_COORD_Y(sour)      TRANSFORM(ToVirCoordY, sour)
744 #define CONVERT_TO_V_COORD_W(sour)      TRANSFORM(ToVirCoordW, sour)
745 #define CONVERT_TO_V_COORD_H(sour)      TRANSFORM(ToVirCoordH, sour)
746
747 inline bool
748 CONVERT_TO_P_COORD_POINT_LIST(Tizen::Base::Collection::ArrayList& dest, const Tizen::Base::Collection::IList& sour)
749 {
750         result r;
751
752         if (NEED_TO_CONVERT())
753         {
754                 r = dest.Construct();
755
756                 if (r == E_SUCCESS)
757                 {
758                         for (int i = 0; i < sour.GetCount(); i++)
759                         {
760                                 Tizen::Graphics::Point* pSourPoint =
761                                         dynamic_cast <Tizen::Graphics::Point*>(const_cast <Tizen::Base::Object*>(sour.GetAt(i)));
762
763                                 if (pSourPoint == null)
764                                 {
765                                         return false;
766                                 }
767
768                                 Tizen::Graphics::Point* pDestPoint = new (std::nothrow) Tizen::Graphics::Point(pSourPoint->x, pSourPoint->y);
769
770                                 if (pDestPoint == null)
771                                 {
772                                         return false;
773                                 }
774
775                                 if (NOT_FROM_WQVGA())
776                                 {
777                                         if (NOT_FROM_WVGA_COMPAT())
778                                         {
779                                                 *pDestPoint = CurrentResConv::ToPhyCoord(*pDestPoint);
780                                         }
781                                         else
782                                         {
783                                                 *pDestPoint = ResWVGAcompat2HVGA::ToPhyCoord(*pDestPoint);
784                                         }
785                                 }
786                                 else
787                                 {
788                                         *pDestPoint = ResWQVGA2HVGA::ToPhyCoord(*pDestPoint);
789                                 }
790
791                                 dest.Add(*pDestPoint);
792                         }
793                 }
794         }
795         else
796         {
797                 r = dest.Construct(sour);
798         }
799
800         return (r == E_SUCCESS);
801 }
802
803 #else
804 template<typename T>
805 inline T
806 TO_PHY_COORD(const T& sour)
807 {
808         return _ResUtil::NEED_TO_CONVERT() ? _ResUtil::CurrentResConv::ToPhyCoord(sour) : sour;
809 }
810
811 template<typename T>
812 inline T
813 TO_VIR_COORD(const T& sour)
814 {
815         return NEED_TO_CONVERT() ? CurrentResConv::ToVirCoord(sour) : sour;
816 }
817
818 inline bool
819 CONVERT_TO_P_COORD_POINT_LIST(Tizen::Base::Collection::ArrayList& dest, const Tizen::Base::Collection::IList& sour)
820 {
821         result r;
822
823         if (NEED_TO_CONVERT())
824         {
825                 r = dest.Construct();
826
827                 if (r == E_SUCCESS)
828                 {
829                         for (int i = 0; i < sour.GetCount(); i++)
830                         {
831                                 Tizen::Graphics::Point* pSourPoint =
832                                         dynamic_cast <Tizen::Graphics::Point*>(const_cast <Tizen::Base::Object*>(sour.GetAt(i)));
833
834                                 if (pSourPoint == null)
835                                 {
836                                         return false;
837                                 }
838
839                                 Tizen::Graphics::Point* pDestPoint = new (std::nothrow) Tizen::Graphics::Point(pSourPoint->x, pSourPoint->y);
840
841                                 if (pDestPoint == null)
842                                 {
843                                         return false;
844                                 }
845
846                                 *pDestPoint = CurrentResConv::ToPhyCoord(*pDestPoint);
847
848                                 dest.Add(*pDestPoint);
849                         }
850                 }
851         }
852         else
853         {
854                 r = dest.Construct(sour);
855         }
856
857         return (r == E_SUCCESS);
858 }
859
860 #define CONVERT_TO_P_COORD_X(sour)      (_ResUtil::NEED_TO_CONVERT() ? _ResUtil::CurrentResConv::ToPhyCoordX(sour) : sour)
861 #define CONVERT_TO_P_COORD_Y(sour)      (_ResUtil::NEED_TO_CONVERT() ? _ResUtil::CurrentResConv::ToPhyCoordY(sour) : sour)
862 #define CONVERT_TO_P_COORD_W(sour)      (_ResUtil::NEED_TO_CONVERT() ? _ResUtil::CurrentResConv::ToPhyCoordW(sour) : sour)
863 #define CONVERT_TO_P_COORD_H(sour)      (_ResUtil::NEED_TO_CONVERT() ? _ResUtil::CurrentResConv::ToPhyCoordH(sour) : sour)
864 #define CONVERT_TO_P_COORD_SIZE(sour)   (_ResUtil::NEED_TO_CONVERT() ? _ResUtil::CurrentResConv::ToPhyCoordSize(sour) : sour)
865
866 #define CONVERT_TO_V_COORD_X(sour)      (_ResUtil::NEED_TO_CONVERT() ? _ResUtil::CurrentResConv::ToVirCoordX(sour) : sour)
867 #define CONVERT_TO_V_COORD_Y(sour)      (_ResUtil::NEED_TO_CONVERT() ? _ResUtil::CurrentResConv::ToVirCoordY(sour) : sour)
868 #define CONVERT_TO_V_COORD_W(sour)      (_ResUtil::NEED_TO_CONVERT() ? _ResUtil::CurrentResConv::ToVirCoordW(sour) : sour)
869 #define CONVERT_TO_V_COORD_H(sour)      (_ResUtil::NEED_TO_CONVERT() ? _ResUtil::CurrentResConv::ToVirCoordH(sour) : sour)
870
871 #endif // #if defined(_MODEL_RES_HVGA)
872
873 } // Tizen::Graphics::_ResUtil
874
875 }} // Tizen::Graphics
876
877 ////////////////////////////////////////////////////////////////////////////////
878 // struct CoordHolder
879
880 namespace Tizen { namespace Graphics
881 {
882
883 namespace _ResUtil
884 {
885 template<typename T>
886 struct CoordHolder
887 {
888         T required;
889         T phyCoord;
890         T virCoord;
891
892         void operator =(const T& in)
893         {
894                 required = in;
895                 phyCoord = TO_PHY_COORD(required);
896                 virCoord = TO_VIR_COORD(phyCoord);
897         }
898 };
899 } // Tizen::Graphics::_ResUtil
900
901 }} // Tizen::Graphics
902
903 #else
904
905 #include "FGrp_CoordinateSystem.h"
906
907 namespace Tizen { namespace Graphics
908 {
909
910 namespace _ResUtil
911 {
912
913 struct Rect
914 {
915         int x;
916         int y;
917         int w;
918         int h;
919
920         Rect()
921                 : x(0)
922                 , y(0)
923                 , w(0)
924                 , h(0)
925         {
926         }
927
928         Rect(int _x, int _y, int _w, int _h)
929                 : x(_x)
930                 , y(_y)
931                 , w(_w)
932                 , h(_h)
933         {
934         }
935 };
936
937 struct Pos
938 {
939         int x;
940         int y;
941
942         Pos()
943                 : x(0)
944                 , y(0)
945         {
946         }
947
948         Pos(int _x, int _y)
949                 : x(_x)
950                 , y(_y)
951         {
952         }
953 };
954
955 struct Size
956 {
957         int w;
958         int h;
959
960         Size()
961                 : w(0)
962                 , h(0)
963         {
964         }
965
966         Size(int _w, int _h)
967                 : w(_w)
968                 , h(_h)
969         {
970         }
971 };
972
973 ////////////////////////////////////////////////////////////////////////////////
974
975 namespace // unnamed
976 {
977
978 template<typename T>
979 inline T
980 ToPhyCoord(const T& sour)
981 {
982         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetTransformer();
983         return (pTransformer) ? pTransformer->Transform(sour) : sour;
984 }
985
986 template<typename T>
987 inline T
988 ToVirCoord(const T& sour)
989 {
990         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetInverseTransformer();
991         return (pTransformer) ? pTransformer->Transform(sour) : sour;
992 }
993
994 template<>
995 inline _Util::Point<int>
996 ToPhyCoord(const _Util::Point<int>& sour)
997 {
998         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetTransformer();
999
1000         if (pTransformer == null)
1001         {
1002                 return sour;
1003         }
1004
1005         _Util::Point<int> dest =
1006         {
1007                 pTransformer->TransformHorizontal(sour.x),
1008                 pTransformer->TransformVertical(sour.y)
1009         };
1010
1011         return dest;
1012 }
1013
1014 template<>
1015 inline _Util::Point<double>
1016 ToPhyCoord(const _Util::Point<double>& sour)
1017 {
1018         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetTransformer();
1019
1020         if (pTransformer)
1021         {
1022                 _Util::Point<double> temp =
1023                 {
1024                         sour.x * double(pTransformer->GetHorizontalScaleFactor()),
1025                         sour.y * double(pTransformer->GetVerticalScaleFactor())
1026                 };
1027
1028                 return temp;
1029         }
1030         else
1031         {
1032                 return sour;
1033         }
1034 }
1035
1036 template<>
1037 inline _Util::Point<float>
1038 ToPhyCoord(const _Util::Point<float>& sour)
1039 {
1040         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetTransformer();
1041
1042         if (pTransformer)
1043         {
1044                 _Util::Point<float> temp =
1045                 {
1046                         sour.x * float(pTransformer->GetHorizontalScaleFactor()),
1047                         sour.y * float(pTransformer->GetVerticalScaleFactor())
1048                 };
1049
1050                 return temp;
1051         }
1052         else
1053         {
1054                 return sour;
1055         }
1056 }
1057
1058 template<>
1059 inline _Util::Dimension<int>
1060 ToPhyCoord(const _Util::Dimension<int>& sour)
1061 {
1062         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetTransformer();
1063
1064         if (pTransformer == null)
1065         {
1066                 return sour;
1067         }
1068
1069         _Util::Dimension<int> dest =
1070         {
1071                 pTransformer->TransformHorizontal(sour.w),
1072                 pTransformer->TransformVertical(sour.h)
1073         };
1074
1075         return dest;
1076 }
1077
1078 template<>
1079 inline _Util::Dimension<double>
1080 ToPhyCoord(const _Util::Dimension<double>& sour)
1081 {
1082         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetTransformer();
1083
1084         if (pTransformer)
1085         {
1086                 _Util::Dimension<double> temp =
1087                 {
1088                         sour.w * double(pTransformer->GetHorizontalScaleFactor()),
1089                         sour.h * double(pTransformer->GetVerticalScaleFactor())
1090                 };
1091
1092                 return temp;
1093         }
1094         else
1095         {
1096                 return sour;
1097         }
1098 }
1099
1100 template<>
1101 inline _Util::Dimension<float>
1102 ToPhyCoord(const _Util::Dimension<float>& sour)
1103 {
1104         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetTransformer();
1105
1106         if (pTransformer)
1107         {
1108                 _Util::Dimension<float> temp =
1109                 {
1110                         sour.w * float(pTransformer->GetHorizontalScaleFactor()),
1111                         sour.h * float(pTransformer->GetVerticalScaleFactor())
1112                 };
1113
1114                 return temp;
1115         }
1116         else
1117         {
1118                 return sour;
1119         }
1120 }
1121
1122 template<>
1123 inline _Util::Rectangle<int>
1124 ToPhyCoord(const _Util::Rectangle<int>& sour)
1125 {
1126         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetTransformer();
1127
1128         if (pTransformer == null)
1129         {
1130                 return sour;
1131         }
1132
1133         _Util::Rectangle<int> dest =
1134         {
1135                 pTransformer->TransformHorizontal(sour.x),
1136                 pTransformer->TransformVertical(sour.y),
1137                 pTransformer->TransformHorizontal(sour.w),
1138                 pTransformer->TransformVertical(sour.h)
1139         };
1140
1141         return dest;
1142 }
1143
1144 template<>
1145 inline _Util::Rectangle<double>
1146 ToPhyCoord(const _Util::Rectangle<double>& sour)
1147 {
1148         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetTransformer();
1149
1150         if (pTransformer)
1151         {
1152                 _Util::Rectangle<double> temp =
1153                 {
1154                         sour.x * double(pTransformer->GetHorizontalScaleFactor()),
1155                         sour.y * double(pTransformer->GetVerticalScaleFactor()),
1156                         sour.w * double(pTransformer->GetHorizontalScaleFactor()),
1157                         sour.h * double(pTransformer->GetVerticalScaleFactor())
1158                 };
1159
1160                 return temp;
1161         }
1162         else
1163         {
1164                 return sour;
1165         }
1166 }
1167
1168 template<>
1169 inline _Util::Rectangle<float>
1170 ToPhyCoord(const _Util::Rectangle<float>& sour)
1171 {
1172         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetTransformer();
1173
1174         if (pTransformer)
1175         {
1176                 _Util::Rectangle<float> temp =
1177                 {
1178                         sour.x * float(pTransformer->GetHorizontalScaleFactor()),
1179                         sour.y * float(pTransformer->GetVerticalScaleFactor()),
1180                         sour.w * float(pTransformer->GetHorizontalScaleFactor()),
1181                         sour.h * float(pTransformer->GetVerticalScaleFactor())
1182                 };
1183
1184                 return temp;
1185         }
1186         else
1187         {
1188                 return sour;
1189         }
1190 }
1191
1192 template<>
1193 inline Rect
1194 ToPhyCoord(const Rect& sour)
1195 {
1196         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetTransformer();
1197
1198         if (pTransformer == null)
1199         {
1200                 return sour;
1201         }
1202
1203         Rectangle rect1(sour.x, sour.y, sour.w, sour.h);
1204         Rectangle rect2 = pTransformer->Transform(rect1);
1205
1206         return Rect(rect2.x, rect2.y, rect2.width, rect2.height);
1207 }
1208
1209 template<>
1210 inline Rect
1211 ToVirCoord(const Rect& sour)
1212 {
1213         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetInverseTransformer();
1214
1215         if (pTransformer == null)
1216         {
1217                 return sour;
1218         }
1219
1220         Rectangle rect1(sour.x, sour.y, sour.w, sour.h);
1221         Rectangle rect2 = pTransformer->Transform(rect1);
1222
1223         return Rect(rect2.x, rect2.y, rect2.width, rect2.height);
1224 }
1225
1226 template<>
1227 inline Pos
1228 ToPhyCoord(const Pos& sour)
1229 {
1230         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetTransformer();
1231
1232         if (pTransformer == null)
1233         {
1234                 return sour;
1235         }
1236
1237         Point point1(sour.x, sour.y);
1238         Point point2 = pTransformer->Transform(point1);
1239
1240         return Pos(point2.x, point2.y);
1241 }
1242
1243 template<>
1244 inline Pos
1245 ToVirCoord(const Pos& sour)
1246 {
1247         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetInverseTransformer();
1248
1249         if (pTransformer == null)
1250         {
1251                 return sour;
1252         }
1253
1254         Point point1(sour.x, sour.y);
1255         Point point2 = pTransformer->Transform(point1);
1256
1257         return Pos(point2.x, point2.y);
1258 }
1259
1260 template<>
1261 inline _Util::Dimension<int>
1262 ToVirCoord(const _Util::Dimension<int>& sour)
1263 {
1264         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetInverseTransformer();
1265
1266         if (pTransformer == null)
1267         {
1268                 return sour;
1269         }
1270
1271         Dimension dim1(sour.w, sour.h);
1272         Dimension dim2 = pTransformer->Transform(dim1);
1273
1274         _Util::Dimension<int> temp = { dim2.width, dim2.height };
1275
1276         return temp;
1277 }
1278
1279 ////////////////////////////////////////////////////////////////////////////////
1280
1281 template<typename T>
1282 inline T
1283 ToVirCoordX(const T& sour)
1284 {
1285         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetInverseTransformer();
1286         return (pTransformer) ? pTransformer->TransformHorizontal(sour) : sour;
1287 }
1288
1289 template<typename T>
1290 inline T
1291 ToVirCoordY(const T& sour)
1292 {
1293         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetInverseTransformer();
1294         return (pTransformer) ? pTransformer->TransformVertical(sour) : sour;
1295 }
1296
1297 template<typename T>
1298 inline T
1299 ToPhyCoordW(const T& sour)
1300 {
1301         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetTransformer();
1302         return (pTransformer) ? pTransformer->TransformHorizontal(sour) : sour;
1303 }
1304
1305 template<typename T>
1306 inline T
1307 ToVirCoordW(const T& sour)
1308 {
1309         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetInverseTransformer();
1310         return (pTransformer) ? pTransformer->TransformHorizontal(sour) : sour;
1311 }
1312
1313 template<typename T>
1314 inline T
1315 ToPhyCoordH(const T& sour)
1316 {
1317         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetTransformer();
1318         return (pTransformer) ? pTransformer->TransformVertical(sour) : sour;
1319 }
1320
1321 template<typename T>
1322 inline T
1323 ToVirCoordH(const T& sour)
1324 {
1325         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetInverseTransformer();
1326         return (pTransformer) ? pTransformer->TransformVertical(sour) : sour;
1327 }
1328
1329 template<typename T>
1330 inline T
1331 ToPhyCoordSize(const T& sour)
1332 {
1333         _ICoordinateSystemTransformer* pTransformer = _CoordinateSystem::GetInstance()->GetTransformer();
1334         return (pTransformer) ? pTransformer->TransformVertical(sour) : sour;
1335 }
1336
1337 }
1338
1339 ////////////////////////////////////////////////////////////////////////////////
1340
1341 inline bool
1342 NeedToConvertCoord(void)
1343 {
1344         int logicalResolution = Tizen::Graphics::_CoordinateSystem::GetInstance()->GetLogicalResolutionInt();
1345         int physicalResolution = (_Screen::GetWidth() < _Screen::GetHeight()) ? _Screen::GetWidth() : _Screen::GetHeight();
1346
1347         return (logicalResolution != physicalResolution);
1348 }
1349
1350 template<typename T>
1351 inline T
1352 ConvertToPhyCoord(const T& sour)
1353 {
1354         return NeedToConvertCoord() ? ToPhyCoord(sour) : sour;
1355 }
1356
1357 template<typename T>
1358 inline T
1359 ConvertToVirCoord(const T& sour)
1360 {
1361         return NeedToConvertCoord() ? ToVirCoord(sour) : sour;
1362 }
1363
1364 template<typename T>
1365 inline T
1366 ConvertToPhyCoordWidth(const T& sour)
1367 {
1368         return NeedToConvertCoord() ? ToPhyCoordW(sour) : sour;
1369 }
1370
1371 template<typename T>
1372 inline T
1373 ConvertToPhyCoordHeight(const T& sour)
1374 {
1375         return NeedToConvertCoord() ? ToPhyCoordH(sour) : sour;
1376 }
1377
1378 template<typename T>
1379 inline T
1380 ConvertToPhyCoordSize(const T& sour)
1381 {
1382         return NeedToConvertCoord() ? ToPhyCoordSize(sour) : sour;
1383 }
1384
1385 template<typename T>
1386 inline T
1387 ConvertToVirCoordX(const T& sour)
1388 {
1389         return NeedToConvertCoord() ? ToVirCoordX(sour) : sour;
1390 }
1391
1392 template<typename T>
1393 inline T
1394 ConvertToVirCoordY(const T& sour)
1395 {
1396         return NeedToConvertCoord() ? ToVirCoordY(sour) : sour;
1397 }
1398
1399 inline bool
1400 ConvertToPhyCoordPointList(Tizen::Base::Collection::ArrayList& dest, const Tizen::Base::Collection::IList& sour)
1401 {
1402         result r;
1403
1404         if (NeedToConvertCoord())
1405         {
1406                 r = dest.Construct();
1407
1408                 if (r == E_SUCCESS)
1409                 {
1410                         for (int i = 0; i < sour.GetCount(); i++)
1411                         {
1412                                 Tizen::Graphics::Point* pSourPoint =
1413                                         dynamic_cast <Tizen::Graphics::Point*>(const_cast <Tizen::Base::Object*>(sour.GetAt(i)));
1414
1415                                 if (pSourPoint == null)
1416                                 {
1417                                         dest.RemoveAll(true);
1418                                         return false;
1419                                 }
1420
1421                                 Tizen::Graphics::Point* pDestPoint = new (std::nothrow) Tizen::Graphics::Point(pSourPoint->x, pSourPoint->y);
1422
1423                                 if (pDestPoint == null)
1424                                 {
1425                                         dest.RemoveAll(true);
1426                                         return false;
1427                                 }
1428
1429                                 *pDestPoint = ToPhyCoord(*pDestPoint);
1430
1431                                 dest.Add(*pDestPoint);
1432                         }
1433                 }
1434         }
1435         else
1436         {
1437                 r = dest.Construct(sour);
1438         }
1439
1440         return (r == E_SUCCESS);
1441 }
1442
1443 ////////////////////////////////////////////////////////////////////////////////
1444
1445 template<typename T>
1446 struct CoordHolder
1447 {
1448         T required;
1449         T phyCoord;
1450         T virCoord;
1451
1452         void operator =(const T& in)
1453         {
1454                 required = in;
1455                 phyCoord = ConvertToPhyCoord(required);
1456                 virCoord = ConvertToVirCoord(phyCoord);
1457         }
1458 };
1459
1460 template<typename FloatType, typename IntType>
1461 struct CoordinateHolder
1462 {
1463         FloatType vcFloat;
1464         FloatType vcFloatActual;
1465         IntType vcInt;
1466         IntType pcInt;
1467 };
1468
1469 template<typename FloatType, typename IntType>
1470 struct CoordinateHolderSimple
1471 {
1472         FloatType vcFloat;
1473         IntType vcInt;
1474 };
1475
1476 } // _ResUtil
1477
1478 ////////////////////////////////////////////////////////////////////////////////
1479
1480 inline int _FloatToIntForPos(float f)
1481 {
1482         return static_cast<int>(floorf(f + 0.01f));
1483 }
1484
1485 inline int _DoubleToIntForPos(double f)
1486 {
1487         return static_cast<int>(floor(f + 0.01));
1488 }
1489
1490 inline int _FloatToIntForSize(float f)
1491 {
1492         if (f > 0.0f)
1493         {
1494                 int i = static_cast<int>(f + 0.01f);
1495                 return (i > 0) ? i : 1;
1496         }
1497         else
1498         {
1499                 return 0;
1500         }
1501 }
1502
1503 inline int _DoubleToIntForSize(double f)
1504 {
1505         if (f > 0.0)
1506         {
1507                 int i = static_cast<int>(f + 0.01);
1508                 return (i > 0) ? i : 1;
1509         }
1510         else
1511         {
1512                 return 0;
1513         }
1514 }
1515
1516 inline int _DoubleToIntForRound(double f)
1517 {
1518         return static_cast<int>(floor(f + 0.5));
1519 }
1520
1521 }} // Tizen::Graphics
1522
1523 #endif
1524
1525 #endif //_FGRP_INTERNAL_RES_UTIL_H_