Languages

Menu
Sites
Language
About API for animation

Hello, dear.

 

Recently, I'm making animation  when app was launched.

I want to stop the animation after  rotation, once.

But, this animation by my code is working continuosly.

I wonder if I change the property of animation's repeatable such as once or repeatedly,

below is mine.

If you know how to get it, please let me know.

Thank you for your advice.

Bye.

 

 Evas_Object *loadingImg;
 char buf[PATH_MAX];
 
 loadingImg = elm_image_add(grid);
 app_get_resource("images/loading.gif", buf, (int)PATH_MAX);
 elm_image_file_set(loadingImg, buf, NULL);
 
 evas_object_size_hint_min_set(loadingImg, 64, 64);
 elm_image_resizable_set(loadingImg, EINA_TRUE, EINA_TRUE);
 
 if (elm_image_animated_available_get(loadingImg))
 {

 dlog_print(DLOG_INFO, TAG, "elm_image_animated_available_get )");
  elm_image_animated_set(loadingImg, true);
  elm_image_animated_play_set(loadingImg, true);
 }
 
 evas_object_show(loadingImg);

 

Responses

4 Replies
Jeongsu Kim

Unfortunately, it seems that elm_image doesn't support one time animation.

But you can make it by evas_object_image_animated_* functions.

Refer below elm_image implementation.

https://review.tizen.org/git/?p=framework/uifw/elementary.git;a=blob;f=src/lib/elm_image.c;h=d90f61b8149fcb98ba4a63b320ddb217231d079e;hb=refs/heads/tizen_2.3#l51

In the _elm_image_animate_cb function, it checks current frame is greater than frame count. You can return ECORE_TIMER_CANCEL here to stop animation.

pius lee

This is my implementation of once playing function.

static const char *_data_key = "_pius_anim";

struct anim_data {
    int frame_count;
	int cur_frame;
	int frame_duration;
	Eina_Bool repeat;
	Eina_Bool play;
	Ecore_Timer *anim_timer;
	Evas_Object *img;
};

static void _pius_animated_data_deleted_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
	struct anim_data *d = evas_object_data_del(obj, _data_key);
	if (d != NULL) {
		free(d);
	}
	evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL, _pius_animated_data_deleted_cb);
}

static Eina_Bool _pius_animated_cb(void *user_data)
{
	struct anim_data *data = user_data;
	if (!data->play) return ECORE_CALLBACK_CANCEL;

	data->cur_frame++;
	if (data->cur_frame > data->frame_count) {
		if (!data->repeat) {
			data->play = EINA_FALSE;
			return ECORE_CALLBACK_CANCEL;
		}
		data->cur_frame = data->cur_frame % data->frame_count;
	}
	evas_object_image_animated_frame_set(data->img, data->cur_frame);
	data->frame_duration = evas_object_image_animated_frame_duration_get(data->img, data->cur_frame, 0);

	if (data->frame_duration > 0) {
		ecore_timer_interval_set(data->anim_timer, data->frame_duration);
	}

	return ECORE_CALLBACK_RENEW;
}

void pius_animated_play_set(Evas_Object *obj, Eina_Bool play, Eina_Bool repeat, Eina_Bool reset)
{
	if (strcmp("elm_image", evas_object_type_get(obj)))
			return;

	struct anim_data *data = evas_object_data_get(obj, _data_key);
	if (data == NULL) return;

	data->repeat = repeat;

	if (data->play == play) return;

	if (play) {
		if (reset) {
			data->frame_count = evas_object_image_animated_frame_count_get(data->img);
			data->cur_frame = 1;
			data->frame_duration = evas_object_image_animated_frame_duration_get(data->img, data->cur_frame, 0);
			evas_object_image_animated_frame_set(data->img, data->cur_frame);
		}
		if (data->anim_timer) ecore_timer_del(data->anim_timer);

		data->anim_timer = ecore_timer_add(data->frame_duration, _pius_animated_cb, data);
	} else {
		if (data->anim_timer) {
			ecore_timer_del(data->anim_timer);
			data->anim_timer = NULL;
		}
	}
	data->play = play;
}

void pius_animated_set(Evas_Object *obj, Eina_Bool play)
{
	if (strcmp("elm_image", evas_object_type_get(obj)))
		return;

	struct anim_data *data = evas_object_data_get(obj, _data_key);

	Evas_Object *img = elm_image_object_get(obj);
	if (!evas_object_image_animated_get(img)) return;

	if (play) {
		if (data == NULL) {
			data = malloc(sizeof(struct anim_data));
		}

		evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL, _pius_animated_data_deleted_cb);
		evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _pius_animated_data_deleted_cb, NULL);

		data->img = img;
		data->frame_count = evas_object_image_animated_frame_count_get(img);
		data->cur_frame = 1;
		data->frame_duration = evas_object_image_animated_frame_duration_get(img, data->cur_frame, 0);
		evas_object_image_animated_frame_set(img, data->cur_frame);
		evas_object_data_set(obj, _data_key, data);
	} else {
		if (data != NULL) {
			evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL, _pius_animated_data_deleted_cb);
			free(data);
		}
	}
}

 

use it like this

if (elm_image_animated_available_get(loadingImg)) {
	pius_animated_set(loadingImg, true);
	pius_animated_play_set(loadingImg, true, false, true);
}

 

Kim

Thank you so much~

With your advice, It working well.

Thanks, again. Bye.