diff options
author | Jaehwan Kim <jae.hwan.kim@samsung.com> | 2014-11-10 20:45:33 +0900 |
---|---|---|
committer | Jaehwan Kim <jae.hwan.kim@samsung.com> | 2014-11-10 21:01:19 +0900 |
commit | e4a1696a72c9c6081624c3add4f791b9c374c0f8 (patch) | |
tree | 9f141ad0bc5114bbd5bab6fcb1383388d7715b95 /src/bin/edje | |
parent | 9aba5eb3462872a13520cf50282178302df15d42 (diff) |
Edje: Set the min, max sizes of the image automatically.
Set the min, max sizes of the image automatically,
if it uses image set and there's no setting about min, max sizes.
This idea is originated by Jinsol Park.
@feature
Diffstat (limited to 'src/bin/edje')
-rwxr-xr-x | src/bin/edje/edje_cc_out.c | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/src/bin/edje/edje_cc_out.c b/src/bin/edje/edje_cc_out.c index 053ec3eadc..b11d933360 100755 --- a/src/bin/edje/edje_cc_out.c +++ b/src/bin/edje/edje_cc_out.c | |||
@@ -2536,6 +2536,131 @@ data_process_part_set(Part_Lookup *target, int value) | |||
2536 | return EINA_FALSE; | 2536 | return EINA_FALSE; |
2537 | } | 2537 | } |
2538 | 2538 | ||
2539 | static int | ||
2540 | _data_image_w_size_compare_cb(const void *data1, const void *data2) | ||
2541 | { | ||
2542 | const Edje_Image_Directory_Set_Entry *img1 = data1; | ||
2543 | const Edje_Image_Directory_Set_Entry *img2 = data2; | ||
2544 | |||
2545 | if (img1->size.w < img2->size.w) return -1; | ||
2546 | if (img1->size.w > img2->size.w) return 1; | ||
2547 | |||
2548 | return 0; | ||
2549 | } | ||
2550 | |||
2551 | static int | ||
2552 | _data_image_h_size_compare_cb(const void *data1, const void *data2) | ||
2553 | { | ||
2554 | const Edje_Image_Directory_Set_Entry *img1 = data1; | ||
2555 | const Edje_Image_Directory_Set_Entry *img2 = data2; | ||
2556 | |||
2557 | if (img1->size.h < img2->size.h) return -1; | ||
2558 | if (img1->size.h > img2->size.h) return 1; | ||
2559 | |||
2560 | return 0; | ||
2561 | } | ||
2562 | |||
2563 | static void | ||
2564 | _data_image_sets_size_set() | ||
2565 | { | ||
2566 | Evas *evas; | ||
2567 | Ecore_Evas *ee; | ||
2568 | Edje_Image_Directory_Set *set; | ||
2569 | Edje_Image_Directory_Set_Entry *simg, *preimg; | ||
2570 | Eina_List *l, *entries; | ||
2571 | unsigned int i; | ||
2572 | |||
2573 | ecore_evas_init(); | ||
2574 | ee = ecore_evas_buffer_new(1, 1); | ||
2575 | if (!ee) | ||
2576 | { | ||
2577 | ERR("Cannot create buffer engine canvas for image load."); | ||
2578 | exit(-1); | ||
2579 | } | ||
2580 | evas = ecore_evas_get(ee); | ||
2581 | |||
2582 | for (i = 0; i < edje_file->image_dir->sets_count; i++) | ||
2583 | { | ||
2584 | set = edje_file->image_dir->sets + i; | ||
2585 | |||
2586 | EINA_LIST_FOREACH(set->entries, l, simg) | ||
2587 | { | ||
2588 | Evas_Object *im; | ||
2589 | Eina_List *ll; | ||
2590 | char *s; | ||
2591 | |||
2592 | im = evas_object_image_add(evas); | ||
2593 | EINA_LIST_FOREACH(img_dirs, ll, s) | ||
2594 | { | ||
2595 | char buf[PATH_MAX]; | ||
2596 | int load_err = EVAS_LOAD_ERROR_NONE; | ||
2597 | |||
2598 | snprintf(buf, sizeof(buf), "%s/%s", s, simg->name); | ||
2599 | evas_object_image_file_set(im, buf, NULL); | ||
2600 | load_err = evas_object_image_load_error_get(im); | ||
2601 | if (load_err == EVAS_LOAD_ERROR_NONE) | ||
2602 | { | ||
2603 | evas_object_image_size_get(im, &simg->size.w, &simg->size.h); | ||
2604 | break; | ||
2605 | } | ||
2606 | } | ||
2607 | evas_object_del(im); | ||
2608 | } | ||
2609 | |||
2610 | entries = eina_list_clone(set->entries); | ||
2611 | |||
2612 | entries = eina_list_sort(entries, 0, _data_image_w_size_compare_cb); | ||
2613 | preimg = eina_list_data_get(entries); | ||
2614 | EINA_LIST_FOREACH(entries, l, simg) | ||
2615 | { | ||
2616 | if (simg == preimg) continue; | ||
2617 | if (!(preimg->size.max.w) && !(simg->size.min.w)) | ||
2618 | { | ||
2619 | preimg->size.max.w = (preimg->size.w + simg->size.w) / 2; | ||
2620 | simg->size.min.w = preimg->size.max.w + 1; | ||
2621 | if (simg->size.min.w <= (simg->border.l + simg->border.r)) | ||
2622 | { | ||
2623 | preimg->size.max.w = simg->border.l + simg->border.r; | ||
2624 | simg->size.min.w = preimg->size.max.w + 1; | ||
2625 | } | ||
2626 | } | ||
2627 | else if (preimg->size.max.w && !(simg->size.min.w)) | ||
2628 | simg->size.min.w = preimg->size.max.w + 1; | ||
2629 | else if (!(preimg->size.max.w) && simg->size.min.w) | ||
2630 | preimg->size.max.w = simg->size.min.w - 1; | ||
2631 | preimg = simg; | ||
2632 | } | ||
2633 | simg = eina_list_data_get(eina_list_last(entries)); | ||
2634 | if (!(simg->size.max.w)) simg->size.max.w = 99999; | ||
2635 | |||
2636 | entries = eina_list_sort(entries, 0, _data_image_h_size_compare_cb); | ||
2637 | preimg = eina_list_data_get(entries); | ||
2638 | EINA_LIST_FOREACH(entries, l, simg) | ||
2639 | { | ||
2640 | if (simg == preimg) continue; | ||
2641 | if (!(preimg->size.max.h) && !(simg->size.min.h)) | ||
2642 | { | ||
2643 | preimg->size.max.h = (preimg->size.h + simg->size.h) / 2; | ||
2644 | simg->size.min.h = preimg->size.max.h + 1; | ||
2645 | if (simg->size.min.h <= (simg->border.t + simg->border.b)) | ||
2646 | { | ||
2647 | preimg->size.max.h = simg->border.t + simg->border.b; | ||
2648 | simg->size.min.h = preimg->size.max.h + 1; | ||
2649 | } | ||
2650 | } | ||
2651 | else if (preimg->size.max.h && !(simg->size.min.h)) | ||
2652 | simg->size.min.h = preimg->size.max.h + 1; | ||
2653 | else if (!(preimg->size.max.h) && simg->size.min.h) | ||
2654 | preimg->size.max.h = simg->size.min.h - 1; | ||
2655 | preimg = simg; | ||
2656 | } | ||
2657 | simg = eina_list_data_get(eina_list_last(entries)); | ||
2658 | if (!(simg->size.max.h)) simg->size.max.h = 99999; | ||
2659 | |||
2660 | eina_list_free(entries); | ||
2661 | } | ||
2662 | } | ||
2663 | |||
2539 | static void | 2664 | static void |
2540 | _data_image_id_update(Eina_List *images_unused_list) | 2665 | _data_image_id_update(Eina_List *images_unused_list) |
2541 | { | 2666 | { |
@@ -2980,10 +3105,13 @@ free_group: | |||
2980 | free(set_e); | 3105 | free(set_e); |
2981 | } | 3106 | } |
2982 | } | 3107 | } |
3108 | |||
2983 | /* update image id in parts */ | 3109 | /* update image id in parts */ |
2984 | if (images_unused_list) _data_image_id_update(images_unused_list); | 3110 | if (images_unused_list) _data_image_id_update(images_unused_list); |
2985 | EINA_LIST_FREE(images_unused_list, iui) | 3111 | EINA_LIST_FREE(images_unused_list, iui) |
2986 | free(iui); | 3112 | free(iui); |
3113 | |||
3114 | _data_image_sets_size_set(); | ||
2987 | } | 3115 | } |
2988 | 3116 | ||
2989 | eina_hash_free(images_in_use); | 3117 | eina_hash_free(images_in_use); |