Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_IconListUtils.cpp
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                FUiCtrl_IconListUtils.cpp
20  * @brief               This is the implementation file for the _IconListUtils.
21  */
22
23 #include "FUiCtrl_IconListUtils.h"
24
25 namespace Tizen { namespace Ui { namespace Controls
26 {
27
28 namespace _IconListUtils
29 {
30
31 const float TouchAnimation::FRAME_RATIO[TouchAnimation::FRAME_COUNT] =
32 {0.9375, 0.875, 0.8125, 0.75, 0.6875, 0.625, 0.5625, 0.5, 0.5625, 0.625, 0.6875, 0.75, 0.8125, 0.875, 0.9375, 1.0};
33
34 TouchAnimation::TouchAnimation(void)
35         : __frame(0)
36 {
37
38 }
39
40 TouchAnimation::~TouchAnimation(void)
41 {
42
43 }
44
45 bool
46 TouchAnimation::GetTouchAnimationFrame(float& ratio)
47 {
48         ratio = FRAME_RATIO[__frame++];
49         if (__frame >= FRAME_COUNT)
50         {
51                 __frame = FRAME_COUNT - 1;
52                 return false;
53         }
54         return true;
55 }
56
57 float
58 TouchAnimation::GetCurrentAnimationFrame(void) const
59 {
60         return FRAME_RATIO[__frame];
61 }
62
63 void
64 TouchAnimation::StartAnimation(void)
65 {
66         __frame = 0;
67 }
68
69 MagneticScrollAnimation::MagneticScrollAnimation(void)
70         : __scroll(0)
71 {
72
73 }
74
75 MagneticScrollAnimation::~MagneticScrollAnimation(void)
76 {
77
78 }
79
80 bool
81 MagneticScrollAnimation::GetMagneticScrollAnimationFrame(int& dif)
82 {
83         if (__scroll == 0)
84         {
85                 dif = 0;
86                 return false;
87         }
88         else if (__scroll > 0)
89         {
90                 dif = (__scroll - 1) / MAGNETIC_SCROLL_EFFECT_DIVIDER + 1;
91         }
92         else
93         {
94                 dif = (__scroll + 1) / MAGNETIC_SCROLL_EFFECT_DIVIDER - 1;
95         }
96
97         __scroll -= dif;
98         return true;
99 }
100
101 void
102 MagneticScrollAnimation::StartAnimation(int scroll)
103 {
104         __scroll = scroll;
105 }
106
107 CheckAnimation::CheckAnimation(void)
108         : __frame(0)
109 {
110 }
111
112 CheckAnimation::~CheckAnimation(void)
113 {
114 }
115
116 bool
117 CheckAnimation::GetCheckAnimationFrame(float& ratio)
118 {
119         __frame++;
120         ratio = (float)__frame / (float)FRAME_COUNT;
121
122         if (__frame >= FRAME_COUNT)
123         {
124                 return false;
125         }
126
127         return true;
128 }
129
130 float
131 CheckAnimation::GetCurrentAnimationFrame(void) const
132 {
133         float frame = (float)__frame;
134         if (__frame <= 0)
135         {
136                 frame = 1.0f;
137         }
138
139         return frame / (float)FRAME_COUNT;
140 }
141
142 void
143 CheckAnimation::StartAnimation(void)
144 {
145         __frame = 0;
146 }
147
148 ListItemState
149 EnumConverter::ConvertIconListViewItemDrawingStatusToListItemState(IconListViewItemDrawingStatus status)
150 {
151         switch (status)
152         {
153         case ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL:
154                 return LIST_ITEM_STATE_NORMAL;
155
156         case ICON_LIST_VIEW_ITEM_DRAWING_STATUS_PRESSED:
157                 return LIST_ITEM_STATE_PRESSED;
158
159         case ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED:
160                 return LIST_ITEM_STATE_HIGHLIGHTED;
161         }
162
163         return LIST_ITEM_STATE_NORMAL;
164 }
165
166 IconListViewItemDrawingStatus
167 EnumConverter::ConvertListItemStateToIconListViewItemDrawingStatus(ListItemState state)
168 {
169         switch (state)
170         {
171         case LIST_ITEM_STATE_NORMAL:
172                 return ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL;
173
174         case LIST_ITEM_STATE_PRESSED:
175                 return ICON_LIST_VIEW_ITEM_DRAWING_STATUS_PRESSED;
176
177         case LIST_ITEM_STATE_HIGHLIGHTED:
178                 return ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED;
179
180         default:
181                 return ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL;
182         }
183
184         return ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL;
185 }
186
187 } // Tizen::Ui::Controls::_IconListUtils
188
189 }}} // Tizen::Ui::Controls