default_backend: implements frame_duration to proceed each frame at a different speed
[platform/core/uifw/libpui.git] / backends / notification / default_ani_alarm.c
index fbafe63..1324cc7 100644 (file)
@@ -49,20 +49,23 @@ _ani_backend_alarm_free_frame(default_frame_info_t *frame)
 static default_frame_info_t *
 _ani_backend_alarm_get_frame(default_ani_info *ani_info)
 {
-#define SMOOTH_FRAME 75
-#define ALARM_REPEAT 3
-#define ALARM_FRAME 10
-       default_frame_info_t *frame, *key_frame;
-       int idx;
+/* FIXME: ALAMR_FRAME need to changed after we imply animation type, suchas ease function */
+#define ALARM_FRAME 18
+       default_frame_info_t *frame, *key_frame, *key_frame2;
+       int idx, idx2;
        unsigned int r, g, b, r2, g2, b2;
        int r3, g3, b3;
        double div;
-       int fade_out_frame;
 
        frame = (default_frame_info_t *)calloc(sizeof(default_frame_info_t), 1);
        if (!frame) return NULL;
 
-       idx = ((int)(ani_info->frame_idx / ALARM_FRAME)) % ani_info->num_key_frames;
+       if (ani_info->frame_idx == 0)
+       {
+               ani_info->frame_max = (unsigned int)(ani_info->frames[ani_info->key_frame_cur].frame_duration / ani_info->interval);
+       }
+
+       idx = ani_info->key_frame_cur;
        key_frame = &ani_info->frames[idx];
 
        frame->num_led = key_frame->num_led;
@@ -73,10 +76,7 @@ _ani_backend_alarm_get_frame(default_ani_info *ani_info)
                return NULL;
        }
 
-       /* FIXME: calculate this data before animation start. this is not changed value */
-       fade_out_frame = (ALARM_FRAME) * ani_info->num_key_frames * (ALARM_REPEAT);
-
-       if (ani_info->frame_idx < fade_out_frame)
+       if (ani_info->key_frame_cur < ALARM_FRAME)
        {
                for (int i = 0; i < key_frame->num_led; i++)
                {
@@ -85,12 +85,14 @@ _ani_backend_alarm_get_frame(default_ani_info *ani_info)
        }
        else
        {
-               key_frame = &ani_info->frames[0];
-               r2 = g2 = b2 = 0x00;
+               idx2 = (idx + 1) % ani_info->num_key_frames;
+               key_frame2 = &ani_info->frames[idx2];
+               div = (double)(ani_info->frame_idx) / (double)ani_info->frame_max;
+               r = g = b = r2 = g2 = b2 = 0x0;
                for (int i = 0; i < key_frame->num_led; i++)
                {
-                       div = (double)(ani_info->frame_idx - fade_out_frame) / (double)SMOOTH_FRAME;
                        _ani_backend_alarm_get_led_rgb(key_frame, i, &r, &g, &b);
+                       _ani_backend_alarm_get_led_rgb(key_frame2, i, &r2, &g2, &b2);
                        r3 = (int)(r2 - r) * div + r;
                        g3 = (int)(g2 - g) * div + g;
                        b3 = (int)(b2 - b) * div + b;
@@ -100,11 +102,12 @@ _ani_backend_alarm_get_frame(default_ani_info *ani_info)
        }
 
        ani_info->frame_idx++;
-       if (ani_info->frame_idx >= (fade_out_frame + SMOOTH_FRAME))
+       if (ani_info->frame_idx >= ani_info->frame_max)
        {
-               if (ani_info->repeat >= 0)
-                       ani_info->repeat_cur++;
                ani_info->frame_idx = 0;
+               ani_info->key_frame_cur = (ani_info->key_frame_cur + 1) % ani_info->num_key_frames;
+               if (ani_info->repeat >= 0 && ani_info->key_frame_cur == 0)
+                       ani_info->repeat_cur++;
        }
 
        return frame;
@@ -191,6 +194,10 @@ _ani_alarm_start(pui_ani_t *ani, int repeat)
        if (repeat == 0) info->repeat = 1;
        else info->repeat = repeat;
 
+       info->key_frame_cur = 0;
+       info->frame_idx = 0;
+       info->repeat_cur = 0;
+
        ret = pui_backend_ani_add_frame_cb(ani, _ani_backend_alarm_frame_cb, info->interval / 1000.0);
        if (!ret)
        {