Changed indicator bg color.
[platform/framework/native/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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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 "FUi_Math.h"
24 #include "FUiCtrl_IconListUtils.h"
25
26 namespace Tizen { namespace Ui { namespace Controls
27 {
28
29 namespace _IconListUtils
30 {
31
32 const float TouchAnimation::FRAME_RATIO[TouchAnimation::FRAME_COUNT] =
33 {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};
34
35 TouchAnimation::TouchAnimation(void)
36         : __frame(0.0f)
37 {
38
39 }
40
41 TouchAnimation::~TouchAnimation(void)
42 {
43
44 }
45
46 bool
47 TouchAnimation::GetTouchAnimationFrame(float& ratio)
48 {
49         ratio = FRAME_RATIO[__frame++];
50         if (__frame >= FRAME_COUNT)
51         {
52                 __frame = FRAME_COUNT - 1;
53                 return false;
54         }
55         return true;
56 }
57
58 float
59 TouchAnimation::GetCurrentAnimationFrame(void) const
60 {
61         return FRAME_RATIO[__frame];
62 }
63
64 void
65 TouchAnimation::StartAnimation(void)
66 {
67         __frame = 0;
68 }
69
70 MagneticScrollAnimation::MagneticScrollAnimation(void)
71         : __scroll(0)
72 {
73
74 }
75
76 MagneticScrollAnimation::~MagneticScrollAnimation(void)
77 {
78
79 }
80
81 bool
82 MagneticScrollAnimation::GetMagneticScrollAnimationFrame(float& diff)
83 {
84         if (_FloatCompare(__scroll, 0.0f))
85         {
86                 diff = 0.0f;
87                 return false;
88         }
89         else if (!_FloatCompareLE(__scroll, 0.0f))
90         {
91                 diff = (__scroll - 1) / MAGNETIC_SCROLL_EFFECT_DIVIDER + 1;
92                 __scroll -= diff;
93                 if (__scroll < 0.0f)
94                 {
95                         diff += __scroll;
96                         __scroll = 0.0f;
97                 }
98                 return true;
99         }
100         else
101         {
102                 diff = (__scroll + 1) / MAGNETIC_SCROLL_EFFECT_DIVIDER - 1;
103                 __scroll -= diff;
104                 if (__scroll > 0.0f)
105                 {
106                         diff += __scroll;
107                         __scroll = 0.0f;
108                 }
109                 return true;
110         }
111 }
112
113 void
114 MagneticScrollAnimation::StartAnimation(float scroll)
115 {
116         __scroll = scroll;
117 }
118
119 CheckAnimation::CheckAnimation(void)
120         : __frame(0)
121 {
122 }
123
124 CheckAnimation::~CheckAnimation(void)
125 {
126 }
127
128 bool
129 CheckAnimation::GetCheckAnimationFrame(float& ratio)
130 {
131         __frame++;
132         ratio = (float)__frame / (float)FRAME_COUNT;
133
134         if (__frame >= FRAME_COUNT)
135         {
136                 return false;
137         }
138
139         return true;
140 }
141
142 float
143 CheckAnimation::GetCurrentAnimationFrame(void) const
144 {
145         float frame = (float) __frame;
146         if (__frame <= 0)
147         {
148                 frame = 1.0f;
149         }
150
151         return frame / (float) FRAME_COUNT;
152 }
153
154 void
155 CheckAnimation::StartAnimation(void)
156 {
157         __frame = 0;
158 }
159
160 ListItemState
161 EnumConverter::ConvertIconListViewItemDrawingStatusToListItemState(IconListViewItemDrawingStatus status)
162 {
163         switch (status)
164         {
165         case ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL:
166                 return LIST_ITEM_STATE_NORMAL;
167
168         case ICON_LIST_VIEW_ITEM_DRAWING_STATUS_PRESSED:
169                 return LIST_ITEM_STATE_PRESSED;
170
171         case ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED:
172                 return LIST_ITEM_STATE_HIGHLIGHTED;
173         }
174
175         return LIST_ITEM_STATE_NORMAL;
176 }
177
178 IconListViewItemDrawingStatus
179 EnumConverter::ConvertListItemStateToIconListViewItemDrawingStatus(ListItemState state)
180 {
181         switch (state)
182         {
183         case LIST_ITEM_STATE_NORMAL:
184                 return ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL;
185
186         case LIST_ITEM_STATE_PRESSED:
187                 return ICON_LIST_VIEW_ITEM_DRAWING_STATUS_PRESSED;
188
189         case LIST_ITEM_STATE_HIGHLIGHTED:
190                 return ICON_LIST_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED;
191
192         default:
193                 return ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL;
194         }
195
196         return ICON_LIST_VIEW_ITEM_DRAWING_STATUS_NORMAL;
197 }
198
199 } // Tizen::Ui::Controls::_IconListUtils
200
201 }}} // Tizen::Ui::Controls