2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://floralicense.org/license/
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.
20 #include "clock_animation.h"
23 * Get the current time
25 * @return The current time
27 static unsigned int __current_time_get()
31 gettimeofday(&timev, NULL);
32 return ((timev.tv_sec * 1000) + ((timev.tv_usec) / 1000));
36 * Set the Evas_Object to the appointed position
38 * @param[in] obj Pointer to the selected Evas_Object
43 * @param[in] angle Angle
47 static void __set_evas_map(Evas_Object *obj, Evas_Coord x, Evas_Coord y,
48 Evas_Coord w, Evas_Coord h, double angle)
53 Evas_Map *map = evas_map_new(4);
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);
69 * Set 3D position to the selected Evas_Object
71 * @param[in] obj Pointer to the selected Evas_Object
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,
93 Evas_Map *map = evas_map_new(4);
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);
109 * Move the evas follow move animation setting
111 * @param[in] data Animation data
115 static Eina_Bool __move_evas_map(void *data)
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;
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);
146 if (x == dx && y == dy && w == dw && h == dh) {
147 ecore_animator_del(ad->timer);
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);
155 evas_object_geometry_get(ad->obj, &px, NULL, NULL, NULL);
156 __set_evas_map(ad->obj, px, py, pw, ph, 0.0);
162 * Move evas object follow rotation animation setting
164 * @param[in] data Animation data
168 static Eina_Bool __move_evas_map_rotate(void *data)
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;
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);
206 if (x == dx && y == dy && w == dw && h == dh && r == dr) {
207 ecore_animator_del(ad->timer);
209 __set_evas_map(ad->obj, px, py, pw, ph, pr);
210 if (ad->func != NULL) {
211 ad->func(ad->data, ad->obj);
214 __set_evas_map(ad->obj, px, py, pw, ph, pr);
221 * Move evas object follow turning animation setting
223 * @param[in] data move Evas_Object follow turning animation
227 static Eina_Bool __move_evas_map_turn(void *data)
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;
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);
265 if (x == dx && y == dy && w == dw && h == dh && r == dr) {
266 ecore_animator_del(ad->timer);
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);
273 __set_evas_map_3d(ad->obj, px, py, pw, ph, pr, 0, 0, px, py, 0);
279 * Move the selected Evas_Object with animation setting
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
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,
309 Animation_Data *ad = CALLOC(1, Animation_Data);
323 ad->start_time = __current_time_get();
327 ad->timer = ecore_animator_add(mv_func, ad);
332 * Callback function for End processing about controlbar animation
334 * @param[in] data Data used in this function
335 * @param[in] obj Selected Evas_Object
339 static void __ctrlbar_animation_end_cb(void *data, Evas_Object *obj)
341 evas_object_map_enable_set(obj, EINA_FALSE);
346 * Moving Animation event processing function
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
354 void clock_ctrlbar_animation(void *data, Evas_Object *obj, void *event_info)
356 Eina_List *list = NULL, *l = NULL;
357 Evas_Object *item = NULL;
358 Evas_Coord x, y, w, h;
361 list = (Eina_List *)event_info;
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);
373 * Rotate Animation event processing function
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
381 void clock_ctrlbar_animation_rotate(void *data, Evas_Object *obj,
384 Eina_List *list = NULL, *l = NULL;
385 Evas_Object *item = NULL;
386 Evas_Coord x, y, w, h;
391 list = (Eina_List *)event_info;
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);
404 * Flying Animation event processing function
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
412 void clock_ctrlbar_animation_fly(void *data, Evas_Object *obj, void *event_info)
414 Eina_List *list = NULL, *l = NULL;
415 Evas_Object *item = NULL;
416 Evas_Coord x, y, w, h, x_, y_;
421 list = (Eina_List *)event_info;
423 EINA_LIST_FOREACH(list, l, item) {
424 evas_object_geometry_get(item, &x, &y, &w, &h);
426 x_ = x + random() % 480;
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));
439 * Turn Animation event processing function
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
447 void clock_ctrlbar_animation_turn(void *data, Evas_Object *obj,
450 Eina_List *list = NULL, *l = NULL;
451 Evas_Object *item = NULL;
452 Evas_Coord x, y, w, h;
457 list = (Eina_List *)event_info;
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);