change nodisplay of ring from false to true to fix TIVI-702
[profile/ivi/clock.git] / src / clock_animation.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <math.h>
18
19 #include "clock.h"
20 #include "clock_animation.h"
21
22 /**
23  * Get the current time
24  *
25  * @return    The current time
26  */
27 static unsigned int __current_time_get()
28 {
29         struct timeval timev;
30
31         gettimeofday(&timev, NULL);
32         return ((timev.tv_sec * 1000) + ((timev.tv_usec) / 1000));
33 }
34
35 /**
36  * Set the Evas_Object to the appointed position
37  *
38  * @param[in]  obj    Pointer to the selected Evas_Object
39  * @param[in]  x      Left
40  * @param[in]  y      Top
41  * @param[in]  w      Width
42  * @param[in]  h      Height
43  * @param[in]  angle  Angle
44  *
45  * @return
46  */
47 static void __set_evas_map(Evas_Object *obj, Evas_Coord x, Evas_Coord y,
48                            Evas_Coord w, Evas_Coord h, double angle)
49 {
50         if (obj == NULL) {
51                 return;
52         }
53         Evas_Map *map = evas_map_new(4);
54         if (map == NULL) {
55                 return;
56         }
57         evas_map_smooth_set(map, EINA_TRUE);
58         evas_map_util_points_populate_from_object_full(map, obj, 0);
59         evas_object_map_enable_set(obj, EINA_TRUE);
60         evas_map_util_3d_perspective(map, x + w / 2, y + h / 2, 0, w * 10);
61         evas_map_util_points_populate_from_geometry(map, x, y, w, h, 0);
62         evas_map_util_rotate(map, angle, x + w / 2, y + h / 2);
63         evas_object_map_set(obj, map);
64         evas_map_free(map);
65 }
66
67 #if 0
68 /**
69  * Set 3D position to the selected Evas_Object
70  *
71  * @param[in]  obj   Pointer to the selected Evas_Object
72  * @param[in]  x     Left
73  * @param[in]  y     Top
74  * @param[in]  w     Width
75  * @param[in]  h     Height
76  * @param[in]  dx
77  * @param[in]  dy
78  * @param[in]  dz
79  * @param[in]  cx
80  * @param[in]  cy
81  * @param[in]  cz
82  *
83  * @return
84  */
85 static void __set_evas_map_3d(Evas_Object *obj, Evas_Coord x, Evas_Coord y,
86                               Evas_Coord w, Evas_Coord h, double dx, double dy,
87                               double dz, Evas_Coord cx, Evas_Coord cy,
88                               Evas_Coord cz)
89 {
90         if (obj == NULL) {
91                 return;
92         }
93         Evas_Map *map = evas_map_new(4);
94         if (map == NULL) {
95                 return;
96         }
97         evas_map_smooth_set(map, EINA_TRUE);
98         evas_map_util_points_populate_from_object_full(map, obj, 0);
99         evas_object_map_enable_set(obj, EINA_TRUE);
100         evas_map_util_3d_perspective(map, x + w / 2, y + h / 2, 0, w * 10);
101         evas_map_util_points_populate_from_geometry(map, x, y, w, h, 0);
102         evas_map_util_3d_rotate(map, dx, dy, dz, cx, cy, cz);
103         evas_object_map_set(obj, map);
104         evas_map_free(map);
105 }
106 #endif
107 #if 0
108 /**
109  * Move the evas follow move animation setting
110  *
111  * @param[in]  data     Animation data
112  *
113  * @return    EINA_FALSE
114  */
115 static Eina_Bool __move_evas_map(void *data)
116 {
117         double t;
118
119         int dx, dy, dw, dh;
120
121         int px, py, pw, ph;
122
123         int x, y, w, h;
124
125         Animation_Data *ad = (Animation_Data *) data;
126         t = ELM_MAX(0.0, __current_time_get() - ad->start_time) / 1000;
127         dx = ad->tx - ad->fx;
128         dy = ad->ty - ad->fy;
129         dw = ad->tw - ad->fw;
130         dh = ad->th - ad->fh;
131         if (t <= ad->time) {
132                 x = (1 * sin((t / ad->time) * (M_PI / 2)) * dx);
133                 y = (1 * sin((t / ad->time) * (M_PI / 2)) * dy);
134                 w = (1 * sin((t / ad->time) * (M_PI / 2)) * dw);
135                 h = (1 * sin((t / ad->time) * (M_PI / 2)) * dh);
136         } else {
137                 x = dx;
138                 y = dy;
139                 w = dw;
140                 h = dh;
141         }
142         px = ad->fx + x;
143         py = ad->fy + y;
144         pw = ad->fw + w;
145         ph = ad->fh + h;
146         if (x == dx && y == dy && w == dw && h == dh) {
147                 ecore_animator_del(ad->timer);
148                 ad->timer = NULL;
149                 evas_object_geometry_get(ad->obj, &px, NULL, NULL, NULL);
150                 __set_evas_map(ad->obj, px, py, pw, ph, 0.0);
151                 if (ad->func != NULL) {
152                         ad->func(ad->data, ad->obj);
153                 }
154         } else {
155                 evas_object_geometry_get(ad->obj, &px, NULL, NULL, NULL);
156                 __set_evas_map(ad->obj, px, py, pw, ph, 0.0);
157         }
158         return EINA_TRUE;
159 }
160 #endif
161 /**
162  * Move evas object follow rotation animation setting
163  *
164  * @param[in]  data    Animation data
165  *
166  * @return     EINA_FALSE
167  */
168 static Eina_Bool __move_evas_map_rotate(void *data)
169 {
170         double t;
171
172         int dx, dy, dw, dh;
173         double dr;
174
175         int px, py, pw, ph;
176         double pr;
177
178         int x, y, w, h;
179         double r;
180
181         Animation_Data *ad = (Animation_Data *) data;
182         t = ELM_MAX(0.0, __current_time_get() - ad->start_time) / 1000;
183         dx = ad->tx - ad->fx;
184         dy = ad->ty - ad->fy;
185         dw = ad->tw - ad->fw;
186         dh = ad->th - ad->fh;
187         dr = ad->tr - ad->fr;
188         if (t <= ad->time) {
189                 x = (1 * sin((t / ad->time) * (M_PI / 2)) * dx);
190                 y = (1 * sin((t / ad->time) * (M_PI / 2)) * dy);
191                 w = (1 * sin((t / ad->time) * (M_PI / 2)) * dw);
192                 h = (1 * sin((t / ad->time) * (M_PI / 2)) * dh);
193                 r = (1 * sin((t / ad->time) * (M_PI / 2)) * dr);
194         } else {
195                 x = dx;
196                 y = dy;
197                 w = dw;
198                 h = dh;
199                 r = dr;
200         }
201         px = ad->fx + x;
202         py = ad->fy + y;
203         pw = ad->fw + w;
204         ph = ad->fh + h;
205         pr = ad->fr + r;
206         if (x == dx && y == dy && w == dw && h == dh && r == dr) {
207                 ecore_animator_del(ad->timer);
208                 ad->timer = NULL;
209                 __set_evas_map(ad->obj, px, py, pw, ph, pr);
210                 if (ad->func != NULL) {
211                         ad->func(ad->data, ad->obj);
212                 }
213         } else {
214                 __set_evas_map(ad->obj, px, py, pw, ph, pr);
215         }
216         return EINA_TRUE;
217 }
218
219 #if 0
220 /**
221  * Move evas object follow turning animation setting
222  *
223  * @param[in]  data     move Evas_Object follow turning animation
224  *
225  * @return     EINA_FALSE
226  */
227 static Eina_Bool __move_evas_map_turn(void *data)
228 {
229         double t;
230
231         int dx, dy, dw, dh;
232         double dr;
233
234         int px, py, pw, ph;
235         double pr;
236
237         int x, y, w, h;
238         double r;
239
240         Animation_Data *ad = (Animation_Data *) data;
241         t = ELM_MAX(0.0, __current_time_get() - ad->start_time) / 1000;
242         dx = ad->tx - ad->fx;
243         dy = ad->ty - ad->fy;
244         dw = ad->tw - ad->fw;
245         dh = ad->th - ad->fh;
246         dr = ad->tr - ad->fr;
247         if (t <= ad->time) {
248                 x = (1 * sin((t / ad->time) * (M_PI / 2)) * dx);
249                 y = (1 * sin((t / ad->time) * (M_PI / 2)) * dy);
250                 w = (1 * sin((t / ad->time) * (M_PI / 2)) * dw);
251                 h = (1 * sin((t / ad->time) * (M_PI / 2)) * dh);
252                 r = (1 * sin((t / ad->time) * (M_PI / 2)) * dr);
253         } else {
254                 x = dx;
255                 y = dy;
256                 w = dw;
257                 h = dh;
258                 r = dr;
259         }
260         px = ad->fx + x;
261         py = ad->fy + y;
262         pw = ad->fw + w;
263         ph = ad->fh + h;
264         pr = ad->fr + r;
265         if (x == dx && y == dy && w == dw && h == dh && r == dr) {
266                 ecore_animator_del(ad->timer);
267                 ad->timer = NULL;
268                 __set_evas_map_3d(ad->obj, px, py, pw, ph, pr, 0, 0, px, py, 0);
269                 if (ad->func != NULL) {
270                         ad->func(ad->data, ad->obj);
271                 }
272         } else {
273                 __set_evas_map_3d(ad->obj, px, py, pw, ph, pr, 0, 0, px, py, 0);
274         }
275         return EINA_TRUE;
276 }
277 #endif
278 /**
279  * Move the selected Evas_Object with animation setting
280  *
281  * @param[in]  obj      Pointer to the selected Evas_Object
282  * @param[in]  x        Start Left
283  * @param[in]  y        Start Top
284  * @param[in]  w        Start Width
285  * @param[in]  h        Start Height
286  * @param[in]  r        Start Rotate
287  * @param[in]  x_       End Left
288  * @param[in]  y_       End Top
289  * @param[in]  w_       End Width
290  * @param[in]  h_       End Height
291  * @param[in]  r_       End Rotate
292  * @param[in]  time     Cost time
293  * @param[in]  mv_func  Evas_Object moving function
294  * @param[in]  func     End processing function when animation finished
295  * @param[in]  data     Data used in this function
296  *
297  * @return
298  */
299 static void __move_object_with_animation(Evas_Object *obj, Evas_Coord x,
300                                          Evas_Coord y, Evas_Coord w,
301                                          Evas_Coord h, double r, Evas_Coord x_,
302                                          Evas_Coord y_, Evas_Coord w_,
303                                          Evas_Coord h_, double r_, double time,
304                                          Eina_Bool (*mv_func) (void *data),
305                                          void (*func) (void *data,
306                                                        Evas_Object *obj),
307                                          void *data)
308 {
309         Animation_Data *ad = CALLOC(1, Animation_Data);
310
311         if (NULL != ad) {
312                 ad->obj = obj;
313                 ad->fx = x;
314                 ad->fy = y;
315                 ad->fw = w;
316                 ad->fh = h;
317                 ad->fr = r;
318                 ad->tx = x_;
319                 ad->ty = y_;
320                 ad->tw = w_;
321                 ad->th = h_;
322                 ad->tr = r_;
323                 ad->start_time = __current_time_get();
324                 ad->time = time;
325                 ad->func = func;
326                 ad->data = data;
327                 ad->timer = ecore_animator_add(mv_func, ad);
328         }
329 }
330
331 /**
332  * Callback function for End processing about controlbar animation
333  *
334  * @param[in]  data   Data used in this function
335  * @param[in]  obj    Selected Evas_Object
336  *
337  * @return
338  */
339 static void __ctrlbar_animation_end_cb(void *data, Evas_Object *obj)
340 {
341         evas_object_map_enable_set(obj, EINA_FALSE);
342 }
343
344 #if 0
345 /**
346  * Moving Animation event processing function
347  *
348  * @param[in]  data         Data used in this function
349  * @param[in]  obj          Controlbar which will apply moving animation
350  * @param[in]  event_info   Information about this event
351  *
352  * @return
353  */
354 void clock_ctrlbar_animation(void *data, Evas_Object *obj, void *event_info)
355 {
356         Eina_List *list = NULL, *l = NULL;
357         Evas_Object *item = NULL;
358         Evas_Coord x, y, w, h;
359         float time = 0.5;
360
361         list = (Eina_List *)event_info;
362
363         EINA_LIST_FOREACH(list, l, item) {
364                 evas_object_geometry_get(item, &x, &y, &w, &h);
365                 __move_object_with_animation(item, x, y / 2, 0, 0, 0, x, y, w,
366                                              h, 0, time, __move_evas_map,
367                                              __ctrlbar_animation_end_cb, NULL);
368                 time += 0.05;
369         }
370 }
371 #endif
372 /**
373  * Rotate Animation event processing function
374  *
375  * @param[in]  data         Data used in this function
376  * @param[in]  obj          Controlbar which will apply rotate animation
377  * @param[in]  event_info   Information about this event
378  *
379  * @return
380  */
381 void clock_ctrlbar_animation_rotate(void *data, Evas_Object *obj,
382                                     void *event_info)
383 {
384         Eina_List *list = NULL, *l = NULL;
385         Evas_Object *item = NULL;
386         Evas_Coord x, y, w, h;
387         float t = 0.5;
388
389         srand(time(NULL));
390
391         list = (Eina_List *)event_info;
392
393         EINA_LIST_FOREACH(list, l, item) {
394                 evas_object_geometry_get(item, &x, &y, &w, &h);
395                 __move_object_with_animation(item, x, y, w, h, 0, x, y, w, h,
396                                              1080, t, __move_evas_map_rotate,
397                                              __ctrlbar_animation_end_cb, NULL);
398                 t += 0.25;
399         }
400 }
401
402 #if 0
403 /**
404  * Flying Animation event processing function
405  *
406  * @param[in]  data         Data used in this function
407  * @param[in]  obj          Controlbar which will apply flying animation
408  * @param[in]  event_info   Information about this event
409  *
410  * @return
411  */
412 void clock_ctrlbar_animation_fly(void *data, Evas_Object *obj, void *event_info)
413 {
414         Eina_List *list = NULL, *l = NULL;
415         Evas_Object *item = NULL;
416         Evas_Coord x, y, w, h, x_, y_;
417         float t = 0.5;
418
419         srand(time(NULL));
420
421         list = (Eina_List *)event_info;
422
423         EINA_LIST_FOREACH(list, l, item) {
424                 evas_object_geometry_get(item, &x, &y, &w, &h);
425                 if (x < 240)
426                         x_ = x + random() % 480;
427                 else
428                         x_ = x - random() % 480;
429                 y_ = y - random() % 800;
430                 __move_object_with_animation(item, x_, y_, w, h, 0, x, y, w, h,
431                                              1080, t, __move_evas_map_rotate,
432                                              __ctrlbar_animation_end_cb, NULL);
433                 //t = 0.7 + 2 * (0.2 - 1.0 / (float)(random()%5+3));
434                 t += 0.1;
435         }
436 }
437
438 /**
439  * Turn Animation event processing function
440  *
441  * @param[in]  data         Data used in this function
442  * @param[in]  obj          Controlbar which will apply turn animation
443  * @param[in]  event_info   Information about this event
444  *
445  * @return
446  */
447 void clock_ctrlbar_animation_turn(void *data, Evas_Object *obj,
448                                   void *event_info)
449 {
450         Eina_List *list = NULL, *l = NULL;
451         Evas_Object *item = NULL;
452         Evas_Coord x, y, w, h;
453         float t;
454
455         srand(time(NULL));
456
457         list = (Eina_List *)event_info;
458
459         EINA_LIST_FOREACH(list, l, item) {
460                 evas_object_geometry_get(item, &x, &y, &w, &h);
461                 t = 1.0 + 5 * (0.2 - 1.0 / (float)(random() % 5 + 3));
462                 __move_object_with_animation(item, x, y, w, h, 90, x, y, w, h,
463                                              360, t, __move_evas_map_turn,
464                                              __ctrlbar_animation_end_cb, NULL);
465         }
466 }
467 #endif