summaryrefslogtreecommitdiff
path: root/src/lib/edje/edje_calc.c
diff options
context:
space:
mode:
authorYoungBok Shin <id213sin@gmail.com>2020-02-17 18:59:09 +0900
committerHermet Park <hermetpark@gmail.com>2020-02-17 18:59:09 +0900
commit2fe158ce652860b2aa5a2e883e6b2beb0ee1c670 (patch)
treea1de907a23578f956f7f0c695ea53e3e77b5b3c1 /src/lib/edje/edje_calc.c
parentba8c349eedd35608f94996aada44ab8d1c404d4a (diff)
edje: add json file support feature
Summary: It also starts to support following new edc properties. This is backported patch from Tizen 5.0 1. frame desc { "default" vector { frame: 0.5; // 0.0 ~ 1.0 } } 2. actions program { "vector_animation"; // VG_ANIM_PLAY, VG_ANIM_PLAY_BACK, VG_ANIM_LOOP, // VG_ANIM_STOP, VG_ANIM_PAUSE, VG_ANIM_RESUME action: VG_ANIM_PLAY; target: "your_vector_part"; } @feature Co-authored-by: Jaehyun Cho <jae_hyun.cho@samsung.com> - Fix to remove Efl.Canvas.Animation_Player on edje Test Plan: {F3840540} {F3840542} {F3840543} make and test attached file edje_cc -beta -id ./ json_edc.edc json.edj gcc -o test test_edc.c -g `pkg-config --cflags --libs evas elementary rlottie` ./test Reviewers: Hermet, Jaehyun_Cho, id213sin Reviewed By: Hermet Subscribers: segfaultxavi, raster, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D11228
Diffstat (limited to '')
-rw-r--r--src/lib/edje/edje_calc.c150
1 files changed, 143 insertions, 7 deletions
diff --git a/src/lib/edje/edje_calc.c b/src/lib/edje/edje_calc.c
index 4c11f6ab4e..eba505b721 100644
--- a/src/lib/edje/edje_calc.c
+++ b/src/lib/edje/edje_calc.c
@@ -3280,34 +3280,133 @@ _edje_image_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *p3, Edj
3280} 3280}
3281 3281
3282static void 3282static void
3283_edje_svg_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *p3 EINA_UNUSED, Edje_Part_Description_Vector *chosen_desc, FLOAT_T pos) 3283_edje_vector_animation_running_cb(void *data, const Efl_Event *event)
3284{ 3284{
3285 int new_svg = -1; //invalid svg 3285 double pos = *((double*)event->info);
3286 Edje_Real_Part *ep = (Edje_Real_Part *)data;
3287 int frame, frame_count;
3288
3289 frame_count = efl_gfx_frame_controller_frame_count_get(ep->object) - 1;
3290 if (frame_count < 0) frame_count = 0;
3291
3292 if (ep->typedata.vector->backward)
3293 frame = ep->typedata.vector->start_frame - (int) (frame_count * pos);
3294 else
3295 frame = ep->typedata.vector->start_frame + (int) (frame_count * pos);
3296
3297 efl_gfx_frame_controller_frame_set(ep->object, frame);
3298
3299 if ((ep->typedata.vector->backward && (frame <= 0)) ||
3300 (!ep->typedata.vector->backward && (frame >= frame_count)))
3301 {
3302 if (ep->typedata.vector->loop)
3303 {
3304 if (ep->typedata.vector->backward)
3305 ep->typedata.vector->start_frame = frame_count;
3306 else
3307 ep->typedata.vector->start_frame = 0;
3308
3309 efl_canvas_object_animation_start(ep->object,
3310 ep->typedata.vector->anim,
3311 1.0, 0.0);
3312 }
3313 else
3314 {
3315 efl_canvas_object_animation_stop(ep->object);
3316 }
3317 }
3318}
3319
3320static void
3321_edje_vector_load_json(Edje *ed, Edje_Real_Part *ep, const char *key)
3322{
3323 Edje_Part_Description_Vector *desc = (Edje_Part_Description_Vector *)ep->chosen_description;
3324 Eina_File *file;
3325 char *json_data;
3326 double frame_duration;
3327 int json_data_len = 0;
3328 int frame_count;
3329
3330 if (ep->typedata.vector->anim == NULL)
3331 {
3332 Eo *anim = efl_add(EFL_CANVAS_ANIMATION_CLASS, ed->base.evas);
3333 ep->typedata.vector->anim = anim;
3334 efl_event_callback_add(ep->object,
3335 EFL_CANVAS_OBJECT_ANIMATION_EVENT_ANIMATION_PROGRESS_UPDATED,
3336 _edje_vector_animation_running_cb, ep);
3337 }
3338
3339 if (ep->typedata.vector->current_id != desc->vg.id)
3340 {
3341 json_data = (char *)eet_read(ed->file->ef, key, &json_data_len);
3342 json_data[json_data_len] = '\0';
3343 file = eina_file_virtualize(NULL, json_data, json_data_len + 1, EINA_FALSE);
3344 efl_file_simple_mmap_load(ep->object, file, NULL);
3345
3346 if (ep->typedata.vector->json_virtual_file)
3347 eina_file_close(ep->typedata.vector->json_virtual_file);
3348 ep->typedata.vector->json_virtual_file = file;
3349
3350 if (ep->typedata.vector->json_data)
3351 free(ep->typedata.vector->json_data);
3352 ep->typedata.vector->json_data = json_data;
3353
3354 ep->typedata.vector->current_id = desc->vg.id;
3355 }
3356
3357 frame_duration = efl_gfx_frame_controller_frame_duration_get(ep->object, 0, 0);
3358 efl_animation_duration_set(ep->typedata.vector->anim, frame_duration);
3359
3360 if (!ep->typedata.vector->is_playing)
3361 {
3362 frame_count = efl_gfx_frame_controller_frame_count_get(ep->object);
3363 efl_gfx_frame_controller_frame_set(ep->object, (int)(frame_count * desc->vg.frame));
3364 }
3365}
3366
3367static void
3368_edje_vector_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *p3 EINA_UNUSED, Edje_Part_Description_Vector *chosen_desc, FLOAT_T pos)
3369{
3370 int new_id = -1; //invalid svg
3286 int w, h; 3371 int w, h;
3287 char src_key[32], dest_key[32]; 3372 char src_key[32], dest_key[32];
3288 Efl_VG *src_root, *dest_root, *root; 3373 Efl_VG *src_root, *dest_root, *root;
3374 Edje_Vector_File_Type type = chosen_desc->vg.type;
3375 Edje_Vector_File_Type new_type = EDJE_VECTOR_FILE_TYPE_SVG;
3289 3376
3290 evas_object_geometry_get(ep->object, NULL, NULL, &w, &h); 3377 evas_object_geometry_get(ep->object, NULL, NULL, &w, &h);
3291 if( (w == 0) || (h == 0)) return; 3378 if( (w == 0) || (h == 0)) return;
3292 3379
3293 snprintf(src_key, sizeof(src_key), "edje/vectors/%i", chosen_desc->vg.id); 3380 snprintf(src_key, sizeof(src_key), "edje/vectors/%i", chosen_desc->vg.id);
3294 3381
3382 if (type == EDJE_VECTOR_FILE_TYPE_JSON)
3383 {
3384 _edje_vector_load_json(ed, ep, src_key);
3385
3386 return;
3387 }
3388
3295 if (ep->param2) 3389 if (ep->param2)
3296 { 3390 {
3297 Edje_Part_Description_Vector *next_state = (Edje_Part_Description_Vector *)ep->param2->description; 3391 Edje_Part_Description_Vector *next_state = (Edje_Part_Description_Vector *)ep->param2->description;
3298 if (chosen_desc->vg.id != next_state->vg.id) 3392 if (chosen_desc->vg.id != next_state->vg.id)
3299 new_svg = next_state->vg.id; 3393 {
3394 new_id = next_state->vg.id;
3395 new_type = next_state->vg.type;
3396 }
3300 else 3397 else
3301 pos = 0; 3398 {
3399 pos = 0;
3400 }
3302 } 3401 }
3303 3402
3304 if (new_svg < 0) 3403 if ((new_id < 0) || (new_type == EDJE_VECTOR_FILE_TYPE_JSON))
3305 { 3404 {
3306 efl_file_simple_load(ep->object, ed->file->path, src_key); 3405 efl_file_simple_load(ep->object, ed->file->path, src_key);
3307 } 3406 }
3308 else 3407 else
3309 { 3408 {
3310 snprintf(dest_key, sizeof(dest_key), "edje/vectors/%i", new_svg); 3409 snprintf(dest_key, sizeof(dest_key), "edje/vectors/%i", new_id);
3311 3410
3312 efl_file_simple_load(ep->object, ed->file->path, src_key); 3411 efl_file_simple_load(ep->object, ed->file->path, src_key);
3313 src_root = efl_canvas_vg_object_root_node_get(ep->object); 3412 src_root = efl_canvas_vg_object_root_node_get(ep->object);
@@ -3329,6 +3428,43 @@ _edje_svg_recalc_apply(Edje *ed, Edje_Real_Part *ep, Edje_Calc_Params *p3 EINA_U
3329 } 3428 }
3330} 3429}
3331 3430
3431void
3432_edje_part_vector_anim_stop(Edje *ed EINA_UNUSED, Edje_Real_Part *rp)
3433{
3434 Edje_Part_Description_Vector *desc = (Edje_Part_Description_Vector *)rp->chosen_description;
3435 double frame_count = efl_gfx_frame_controller_frame_count_get(rp->object);
3436
3437 efl_canvas_object_animation_stop(rp->object);
3438 efl_gfx_frame_controller_frame_set(rp->object, (int)(frame_count * desc->vg.frame));
3439 rp->typedata.vector->is_playing = EINA_FALSE;
3440}
3441
3442void
3443_edje_part_vector_anim_pause(Edje *ed EINA_UNUSED, Edje_Real_Part *rp)
3444{
3445 efl_canvas_object_animation_pause_set(rp->object, EINA_TRUE);
3446}
3447
3448void
3449_edje_part_vector_anim_resume(Edje *ed EINA_UNUSED, Edje_Real_Part *rp)
3450{
3451 if (rp->typedata.vector->is_playing)
3452 {
3453 rp->typedata.vector->start_frame = efl_gfx_frame_controller_frame_get(rp->object);
3454 efl_canvas_object_animation_pause_set(rp->object, EINA_FALSE);
3455 }
3456}
3457
3458void
3459_edje_part_vector_anim_play(Edje *ed EINA_UNUSED, Edje_Real_Part *rp, Eina_Bool backward, Eina_Bool loop)
3460{
3461 rp->typedata.vector->backward = backward;
3462 rp->typedata.vector->loop = loop;
3463 rp->typedata.vector->start_frame = efl_gfx_frame_controller_frame_get(rp->object);
3464 rp->typedata.vector->is_playing = EINA_TRUE;
3465 efl_canvas_object_animation_start(rp->object, rp->typedata.vector->anim, 1.0, 0.0);
3466}
3467
3332static Edje_Real_Part * 3468static Edje_Real_Part *
3333_edje_real_part_state_get(Edje *ed, Edje_Real_Part *ep, int flags, int id, int *state) 3469_edje_real_part_state_get(Edje *ed, Edje_Real_Part *ep, int flags, int id, int *state)
3334{ 3470{
@@ -5089,7 +5225,7 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
5089 break; 5225 break;
5090 5226
5091 case EDJE_PART_TYPE_VECTOR: 5227 case EDJE_PART_TYPE_VECTOR:
5092 _edje_svg_recalc_apply(ed, ep, pf, (Edje_Part_Description_Vector *)chosen_desc, pos); 5228 _edje_vector_recalc_apply(ed, ep, pf, (Edje_Part_Description_Vector *)chosen_desc, pos);
5093 break; 5229 break;
5094 5230
5095 case EDJE_PART_TYPE_TEXTBLOCK: 5231 case EDJE_PART_TYPE_TEXTBLOCK: