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