summaryrefslogtreecommitdiff
path: root/src/lib/edje/edje_calc.c
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2018-02-26 18:54:38 -0500
committerMike Blumenkrantz <zmike@osg.samsung.com>2018-02-28 16:02:38 -0500
commit3d9dcbd478e0e9e8a120b08344e08154cbc25d39 (patch)
tree265665cee10ea0747c81b9e44dbde2a62bb1b066 /src/lib/edje/edje_calc.c
parent3a86768f3bf4f38ff41adad8054060ed57eae384 (diff)
edje: add ability to reference images from other edje files
this uses the just-added "id" property to allow referencing images by name from that theme. example: =FILE1= id: "myfile"; images.image: "someimage.png" COMP; =FILE2= requires: "myfile"; images.image: "someimage.png" EXTERNAL "myfile"; FILE2 will now load someimage.png from FILE1 at runtime if FILE1 is currently opened in edje, and FILE1 will be kept open until FILE2 is closed @feature
Diffstat (limited to '')
-rw-r--r--src/lib/edje/edje_calc.c163
1 files changed, 104 insertions, 59 deletions
diff --git a/src/lib/edje/edje_calc.c b/src/lib/edje/edje_calc.c
index 1bb2833265..4a9dde787b 100644
--- a/src/lib/edje/edje_calc.c
+++ b/src/lib/edje/edje_calc.c
@@ -597,6 +597,100 @@ _edje_image_find(Evas_Object *obj, Edje *ed, Edje_Real_Part_Set **eps,
597} 597}
598 598
599static void 599static void
600_edje_real_part_image_error_check(Edje_Real_Part *ep)
601{
602 switch (evas_object_image_load_error_get(ep->object))
603 {
604 case EVAS_LOAD_ERROR_GENERIC:
605 ERR("Error type: EVAS_LOAD_ERROR_GENERIC");
606 break;
607
608 case EVAS_LOAD_ERROR_DOES_NOT_EXIST:
609 ERR("Error type: EVAS_LOAD_ERROR_DOES_NOT_EXIST");
610 break;
611
612 case EVAS_LOAD_ERROR_PERMISSION_DENIED:
613 ERR("Error type: EVAS_LOAD_ERROR_PERMISSION_DENIED");
614 break;
615
616 case EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED:
617 ERR("Error type: EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED");
618 break;
619
620 case EVAS_LOAD_ERROR_CORRUPT_FILE:
621 ERR("Error type: EVAS_LOAD_ERROR_CORRUPT_FILE");
622 break;
623
624 case EVAS_LOAD_ERROR_UNKNOWN_FORMAT:
625 ERR("Error type: EVAS_LOAD_ERROR_UNKNOWN_FORMAT");
626 break;
627
628 default:
629 ERR("Error type: ???");
630 break;
631 }
632}
633
634static Eina_Bool
635_edje_real_part_image_internal_set(Edje_File *edf, Edje_Real_Part *ep, int image_id)
636{
637 char buf[1024] = "edje/images/";
638
639 /* Replace snprint("edje/images/%i") == memcpy + itoa */
640 eina_convert_itoa(image_id, buf + 12); /* No need to check length as 2³² need only 10 characteres. */
641
642 evas_object_image_mmap_set(ep->object, edf->f, buf);
643 if (evas_object_image_load_error_get(ep->object) != EVAS_LOAD_ERROR_NONE)
644 {
645 ERR("Error loading image collection \"%s\" from "
646 "file \"%s\". Missing EET Evas loader module?",
647 buf, edf->path);
648 _edje_real_part_image_error_check(ep);
649 return EINA_FALSE;
650 }
651 return EINA_TRUE;
652}
653
654static Eina_Bool
655_edje_real_part_image_external_set(Edje_File *edf, Edje_Real_Part *ep, int image_id)
656{
657 Edje_Image_Directory_Entry *ie;
658
659 if (!edf->image_dir) return EINA_FALSE;
660 ie = edf->image_dir->entries + (-image_id) - 1;
661 if ((ie) &&
662 (ie->source_type == EDJE_IMAGE_SOURCE_TYPE_USER) &&
663 (ie->entry))
664 {
665 evas_object_image_file_set(ep->object, ie->entry, NULL);
666 _edje_real_part_image_error_check(ep);
667 return EINA_TRUE;
668 }
669 else if ((ie) &&
670 (ie->source_type == EDJE_IMAGE_SOURCE_TYPE_EXTERNAL) &&
671 (ie->entry))
672 {
673 Edje_File *edff;
674 Eina_List *l, *ll;
675
676 l = eina_hash_find(_edje_id_hash, ie->external_id);
677 EINA_LIST_FOREACH(l, ll, edff)
678 {
679 Edje_Image_Hash *eih = eina_hash_find(edff->image_id_hash, ie->entry);
680
681 if (!eih) continue;
682 if (eih->id < 0)
683 return _edje_real_part_image_external_set(edff, ep, eih->id);
684 else
685 _edje_real_part_image_internal_set(edff, ep, eih->id);
686 return EINA_TRUE;
687 }
688 return EINA_FALSE;
689 }
690 return EINA_FALSE;
691}
692
693static void
600_edje_real_part_image_set(Edje *ed, Edje_Real_Part *ep, Edje_Real_Part_Set **set, FLOAT_T pos) 694_edje_real_part_image_set(Edje *ed, Edje_Real_Part *ep, Edje_Real_Part_Set **set, FLOAT_T pos)
601{ 695{
602 int image_id; 696 int image_id;
@@ -609,16 +703,7 @@ _edje_real_part_image_set(Edje *ed, Edje_Real_Part *ep, Edje_Real_Part_Set **set
609 if (set) *set = ep->param1.set; 703 if (set) *set = ep->param1.set;
610 if (image_id < 0) 704 if (image_id < 0)
611 { 705 {
612 Edje_Image_Directory_Entry *ie; 706 _edje_real_part_image_external_set(ed->file, ep, image_id);
613
614 if (!ed->file->image_dir) ie = NULL;
615 else ie = ed->file->image_dir->entries + (-image_id) - 1;
616 if ((ie) &&
617 (ie->source_type == EDJE_IMAGE_SOURCE_TYPE_USER) &&
618 (ie->entry))
619 {
620 evas_object_image_file_set(ep->object, ie->entry, NULL);
621 }
622 } 707 }
623 else 708 else
624 { 709 {
@@ -659,58 +744,18 @@ _edje_real_part_image_set(Edje *ed, Edje_Real_Part *ep, Edje_Real_Part_Set **set
659 } 744 }
660 if (image_id < 0) 745 if (image_id < 0)
661 { 746 {
662 ERR("Part \"%s\" description, " 747 if (!_edje_real_part_image_external_set(ed->file, ep, image_id))
663 "\"%s\" %3.3f with image %i index has a missing image id in a set of %i !!!", 748 ERR("Part \"%s\" description, "
664 ep->part->name, 749 "\"%s\" %3.3f with image %i index has a missing image id in a set of %i !!!",
665 ep->param1.description->state.name, 750 ep->part->name,
666 ep->param1.description->state.value, 751 ep->param1.description->state.name,
667 image_num, 752 ep->param1.description->state.value,
668 image_count); 753 image_num,
754 image_count);
669 } 755 }
670 else 756 else
671 { 757 {
672 char buf[1024] = "edje/images/"; 758 _edje_real_part_image_internal_set(ed->file, ep, image_id);
673
674 /* Replace snprint("edje/images/%i") == memcpy + itoa */
675 eina_convert_itoa(image_id, buf + 12); /* No need to check length as 2³² need only 10 characteres. */
676
677 evas_object_image_mmap_set(ep->object, ed->file->f, buf);
678 if (evas_object_image_load_error_get(ep->object) != EVAS_LOAD_ERROR_NONE)
679 {
680 ERR("Error loading image collection \"%s\" from "
681 "file \"%s\". Missing EET Evas loader module?",
682 buf, ed->file->path);
683 switch (evas_object_image_load_error_get(ep->object))
684 {
685 case EVAS_LOAD_ERROR_GENERIC:
686 ERR("Error type: EVAS_LOAD_ERROR_GENERIC");
687 break;
688
689 case EVAS_LOAD_ERROR_DOES_NOT_EXIST:
690 ERR("Error type: EVAS_LOAD_ERROR_DOES_NOT_EXIST");
691 break;
692
693 case EVAS_LOAD_ERROR_PERMISSION_DENIED:
694 ERR("Error type: EVAS_LOAD_ERROR_PERMISSION_DENIED");
695 break;
696
697 case EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED:
698 ERR("Error type: EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED");
699 break;
700
701 case EVAS_LOAD_ERROR_CORRUPT_FILE:
702 ERR("Error type: EVAS_LOAD_ERROR_CORRUPT_FILE");
703 break;
704
705 case EVAS_LOAD_ERROR_UNKNOWN_FORMAT:
706 ERR("Error type: EVAS_LOAD_ERROR_UNKNOWN_FORMAT");
707 break;
708
709 default:
710 ERR("Error type: ???");
711 break;
712 }
713 }
714 } 759 }
715 } 760 }
716} 761}