2017-09-12 22:59:22 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "elementary_config.h"
|
|
|
|
#endif
|
|
|
|
#include <Elementary.h>
|
|
|
|
|
|
|
|
#define INTERP_NUM 7
|
|
|
|
#define BTN_NUM (INTERP_NUM + 1)
|
|
|
|
#define BTN_W 50
|
|
|
|
#define BTN_H 50
|
|
|
|
#define WIN_H (BTN_NUM * BTN_H)
|
|
|
|
#define WIN_W WIN_H
|
|
|
|
|
|
|
|
typedef struct _App_Data
|
|
|
|
{
|
2018-02-21 10:38:39 -08:00
|
|
|
Efl_Canvas_Animation *anim[INTERP_NUM];
|
2019-11-10 10:10:02 -08:00
|
|
|
Efl_Ui_Button *btns[INTERP_NUM];
|
2017-09-12 22:59:22 -07:00
|
|
|
|
|
|
|
Evas_Object *btn[INTERP_NUM];
|
|
|
|
Evas_Object *start_all_btn;
|
|
|
|
|
|
|
|
Eina_Bool running_anim_cnt;
|
|
|
|
} App_Data;
|
|
|
|
|
|
|
|
static Efl_Interpolator *
|
2018-01-17 01:43:35 -08:00
|
|
|
_interpolator_create(int index, Evas_Object *win)
|
2017-09-12 22:59:22 -07:00
|
|
|
{
|
|
|
|
Efl_Interpolator *interp = NULL;
|
|
|
|
|
|
|
|
if (index == 0)
|
|
|
|
{
|
2018-11-23 04:26:00 -08:00
|
|
|
interp = efl_add(EFL_LINEAR_INTERPOLATOR_CLASS, win);
|
2017-09-12 22:59:22 -07:00
|
|
|
}
|
|
|
|
else if (index == 1)
|
|
|
|
{
|
2018-11-23 04:26:00 -08:00
|
|
|
interp = efl_add(EFL_SINUSOIDAL_INTERPOLATOR_CLASS, win);
|
2019-11-05 11:26:14 -08:00
|
|
|
efl_sinusoidal_interpolator_slope_set(interp, 1.0);
|
2017-09-12 22:59:22 -07:00
|
|
|
}
|
|
|
|
else if (index == 2)
|
|
|
|
{
|
2018-11-23 04:26:00 -08:00
|
|
|
interp = efl_add(EFL_DECELERATE_INTERPOLATOR_CLASS, win);
|
2019-11-05 11:26:14 -08:00
|
|
|
efl_decelerate_interpolator_slope_set(interp, 1.0);
|
2017-09-12 22:59:22 -07:00
|
|
|
}
|
|
|
|
else if (index == 3)
|
|
|
|
{
|
2018-11-23 04:26:00 -08:00
|
|
|
interp = efl_add(EFL_ACCELERATE_INTERPOLATOR_CLASS, win);
|
2019-11-05 11:26:14 -08:00
|
|
|
efl_accelerate_interpolator_slope_set(interp, 1.0);
|
2017-09-12 22:59:22 -07:00
|
|
|
}
|
|
|
|
else if (index == 4)
|
|
|
|
{
|
2018-11-23 04:26:00 -08:00
|
|
|
interp = efl_add(EFL_DIVISOR_INTERPOLATOR_CLASS, win);
|
2019-11-05 11:26:14 -08:00
|
|
|
efl_divisor_interpolator_divisor_set(interp, 1.0);
|
|
|
|
efl_divisor_interpolator_power_set(interp, 1);
|
2017-09-12 22:59:22 -07:00
|
|
|
}
|
|
|
|
else if (index == 5)
|
|
|
|
{
|
2018-11-23 04:26:00 -08:00
|
|
|
interp = efl_add(EFL_BOUNCE_INTERPOLATOR_CLASS, win);
|
2019-11-05 11:26:14 -08:00
|
|
|
efl_bounce_interpolator_rigidness_set(interp, 1.0);
|
|
|
|
efl_bounce_interpolator_bounces_set(interp, 1);
|
2017-09-12 22:59:22 -07:00
|
|
|
}
|
|
|
|
else if (index == 6)
|
|
|
|
{
|
2018-11-23 04:26:00 -08:00
|
|
|
interp = efl_add(EFL_SPRING_INTERPOLATOR_CLASS, win);
|
2019-11-05 11:26:14 -08:00
|
|
|
efl_spring_interpolator_decay_set(interp, 1.0);
|
|
|
|
efl_spring_interpolator_oscillations_set(interp, 1);
|
2017-09-12 22:59:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return interp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-10 10:10:02 -08:00
|
|
|
_anim_changed_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
|
2017-09-12 22:59:22 -07:00
|
|
|
{
|
2019-11-10 10:10:02 -08:00
|
|
|
Eo *anim = event->info;
|
2017-09-12 22:59:22 -07:00
|
|
|
App_Data *ad = data;
|
|
|
|
|
2019-11-10 10:10:02 -08:00
|
|
|
if (anim)
|
|
|
|
{
|
|
|
|
printf("Animation has been started!\n");
|
|
|
|
ad->running_anim_cnt++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int i;
|
2017-09-12 22:59:22 -07:00
|
|
|
|
2019-11-10 10:10:02 -08:00
|
|
|
printf("Animation has been ended!\n");
|
|
|
|
ad->running_anim_cnt--;
|
2017-09-12 22:59:22 -07:00
|
|
|
|
2019-11-10 10:10:02 -08:00
|
|
|
for (i = 0; i < INTERP_NUM; i++)
|
2017-09-12 22:59:22 -07:00
|
|
|
{
|
2019-11-10 10:10:02 -08:00
|
|
|
if (ad->btns[i] == event->object)
|
|
|
|
{
|
|
|
|
elm_object_disabled_set(ad->btn[i], EINA_FALSE);
|
|
|
|
break;
|
|
|
|
}
|
2017-09-12 22:59:22 -07:00
|
|
|
}
|
|
|
|
|
2019-11-10 10:10:02 -08:00
|
|
|
if (ad->running_anim_cnt == 0)
|
|
|
|
elm_object_disabled_set(ad->start_all_btn, EINA_FALSE);
|
|
|
|
}
|
2017-09-12 22:59:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_anim_running_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
|
|
|
{
|
2019-11-10 10:10:02 -08:00
|
|
|
double *progress = event->info;
|
|
|
|
printf("Animation is running! Current progress(%lf)\n", *progress);
|
2017-09-12 22:59:22 -07:00
|
|
|
}
|
|
|
|
|
2019-11-10 10:10:02 -08:00
|
|
|
EFL_CALLBACKS_ARRAY_DEFINE(animation_stats_cb,
|
|
|
|
{EFL_CANVAS_OBJECT_ANIMATION_EVENT_ANIMATION_CHANGED, _anim_changed_cb },
|
|
|
|
{EFL_CANVAS_OBJECT_ANIMATION_EVENT_ANIMATION_PROGRESS_UPDATED, _anim_running_cb },
|
|
|
|
)
|
|
|
|
|
2017-09-12 22:59:22 -07:00
|
|
|
static void
|
|
|
|
_anim_start(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
App_Data *ad = data;
|
|
|
|
|
|
|
|
int index = (uintptr_t)evas_object_data_get(obj, "index");
|
|
|
|
|
|
|
|
//Let Animation Object start animation
|
2019-11-10 10:10:02 -08:00
|
|
|
efl_canvas_object_animation_start(ad->btns[index], ad->anim[index], 1.0, 0.0);
|
2017-09-12 22:59:22 -07:00
|
|
|
|
|
|
|
elm_object_disabled_set(obj, EINA_TRUE);
|
|
|
|
elm_object_disabled_set(ad->start_all_btn, EINA_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_anim_start_all(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
App_Data *ad = data;
|
|
|
|
int i;
|
2019-01-16 06:49:13 -08:00
|
|
|
|
2017-09-12 22:59:22 -07:00
|
|
|
for (i = 0; i < INTERP_NUM; i++)
|
|
|
|
{
|
|
|
|
//Let Animation Object start animation
|
2019-11-10 10:10:02 -08:00
|
|
|
efl_canvas_object_animation_start(ad->btns[i], ad->anim[i], 1.0, 0.0);
|
2017-09-12 22:59:22 -07:00
|
|
|
elm_object_disabled_set(ad->btn[i], EINA_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
elm_object_disabled_set(obj, EINA_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_win_del_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
App_Data *ad = data;
|
2019-01-16 07:07:12 -08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < INTERP_NUM; i++)
|
|
|
|
{
|
|
|
|
//Unregister callback called when window deletes
|
2019-11-10 10:10:02 -08:00
|
|
|
efl_event_callback_array_del(ad->btns[i], animation_stats_cb(), ad);
|
2019-01-16 07:07:12 -08:00
|
|
|
}
|
|
|
|
|
2017-09-12 22:59:22 -07:00
|
|
|
free(ad);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
test_efl_anim_interpolator(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
|
|
|
{
|
2019-01-16 06:49:13 -08:00
|
|
|
int i;
|
|
|
|
|
2017-09-12 22:59:22 -07:00
|
|
|
App_Data *ad = calloc(1, sizeof(App_Data));
|
|
|
|
if (!ad) return;
|
|
|
|
|
|
|
|
const char *modes[] = {"LINEAR", "SINUSOIDAL", "DECELERATE", "ACCELERATE",
|
|
|
|
"DIVISOR_INTERP", "BOUNCE", "SPRING"};
|
|
|
|
|
2019-01-16 06:49:13 -08:00
|
|
|
Evas_Object *win =
|
|
|
|
elm_win_add(NULL, "Efl Animation Interpolator", ELM_WIN_BASIC);
|
2017-09-12 22:59:22 -07:00
|
|
|
elm_win_title_set(win, "Efl Animation Interpolator");
|
|
|
|
elm_win_autodel_set(win, EINA_TRUE);
|
|
|
|
evas_object_smart_callback_add(win, "delete,request", _win_del_cb, ad);
|
|
|
|
|
|
|
|
//Button to start all animations
|
|
|
|
Evas_Object *start_all_btn = elm_button_add(win);
|
|
|
|
elm_object_text_set(start_all_btn, "Start All");
|
|
|
|
evas_object_resize(start_all_btn, WIN_W, BTN_H);
|
|
|
|
evas_object_move(start_all_btn, 0, (WIN_H - BTN_H));
|
|
|
|
evas_object_show(start_all_btn);
|
2019-01-16 06:49:13 -08:00
|
|
|
evas_object_smart_callback_add(start_all_btn, "clicked",
|
|
|
|
_anim_start_all, ad);
|
2017-09-12 22:59:22 -07:00
|
|
|
ad->start_all_btn = start_all_btn;
|
|
|
|
|
|
|
|
for (i = 0; i < INTERP_NUM; i++)
|
|
|
|
{
|
|
|
|
Evas_Object *label = elm_label_add(win);
|
|
|
|
elm_object_text_set(label, modes[i]);
|
|
|
|
evas_object_resize(label, WIN_W, BTN_H);
|
|
|
|
evas_object_move(label, 0, (i * BTN_H));
|
|
|
|
evas_object_show(label);
|
|
|
|
|
|
|
|
//Button to be animated
|
|
|
|
Evas_Object *btn = elm_button_add(win);
|
|
|
|
evas_object_data_set(btn, "index", (void *)(uintptr_t)i);
|
|
|
|
elm_object_text_set(btn, "Start");
|
|
|
|
evas_object_resize(btn, BTN_W, BTN_H);
|
|
|
|
evas_object_move(btn, 0, (i * BTN_H));
|
|
|
|
evas_object_show(btn);
|
|
|
|
evas_object_smart_callback_add(btn, "clicked", _anim_start, ad);
|
|
|
|
ad->btn[i] = btn;
|
|
|
|
|
2019-01-16 06:49:13 -08:00
|
|
|
Efl_Canvas_Animation *anim =
|
efl_canvas_animation: rename Animation_XXX to XXX_Animation
Summary:
In animation classes, "Animation" is not used as a namespace but it is
used as a prefix in the class names.
e.g. Efl.Canvas.Animation_Alpha
However, those classes are basically animation classes with different
features. Therefore, "Animation" should be used as a postfix in the
class names.
e.g. Efl.Canvas.Animation_Alpha -> Efl.Canvas.Alpha_Animation
However, for the easier usage of C APIs, c_prefix of animation classes
are remained to be "efl_animation_xxx".
Reviewers: segfaultxavi, bu5hm4n, zmike, Hermet, jsuya
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D11108
2020-01-19 19:53:09 -08:00
|
|
|
efl_add(EFL_CANVAS_TRANSLATE_ANIMATION_CLASS, win);
|
2019-10-30 07:30:20 -07:00
|
|
|
efl_animation_translate_set(anim, EINA_POSITION2D(0, 0), EINA_POSITION2D((WIN_W - BTN_W), 0));
|
2017-09-12 22:59:22 -07:00
|
|
|
efl_animation_duration_set(anim, 2.0);
|
2018-01-16 03:31:15 -08:00
|
|
|
efl_animation_final_state_keep_set(anim, EINA_FALSE);
|
2017-09-12 22:59:22 -07:00
|
|
|
|
2018-01-17 01:43:35 -08:00
|
|
|
Efl_Interpolator *interp = _interpolator_create(i, win);
|
2017-09-12 22:59:22 -07:00
|
|
|
efl_animation_interpolator_set(anim, interp);
|
|
|
|
ad->anim[i] = anim;
|
2018-01-16 03:31:15 -08:00
|
|
|
|
|
|
|
//Create Animation Object from Animation
|
2019-11-10 10:10:02 -08:00
|
|
|
ad->btns[i] = btn;
|
|
|
|
efl_event_callback_array_add(btn, animation_stats_cb(), ad);
|
2017-09-12 22:59:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ad->running_anim_cnt = 0;
|
|
|
|
|
|
|
|
evas_object_resize(win, WIN_W, WIN_H);
|
|
|
|
evas_object_show(win);
|
|
|
|
}
|