summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitalii Vorobiov <vi.vorobiov@samsung.com>2017-01-11 15:10:35 +0200
committerVitalii Vorobiov <vi.vorobiov@samsung.com>2017-01-11 17:25:05 +0200
commitb23289a2a0dccec04eef4037cee712cf721fb50d (patch)
treee32520c044387ba21b327678409123a40c7d2fdc
parente23a4521eaafbd279594791146dee895c1e4847a (diff)
Edje_Edit: first part of vector API implementation
edje_edit_vector_del edje_edit_vector_usage_list_get edje_edit_vector_id_get edje_edit_vectors_list_get edje_edit_state_vector_get edje_edit_state_vector_set
-rw-r--r--src/lib/edje/Edje_Edit.h88
-rw-r--r--src/lib/edje/edje_edit.c300
2 files changed, 387 insertions, 1 deletions
diff --git a/src/lib/edje/Edje_Edit.h b/src/lib/edje/Edje_Edit.h
index 1aa007539d..7997cbf8aa 100644
--- a/src/lib/edje/Edje_Edit.h
+++ b/src/lib/edje/Edje_Edit.h
@@ -109,6 +109,7 @@ typedef struct _Edje_Edit_Script_Error Edje_Edit_Script_Error;
109 * image is being used and pointed. 109 * image is being used and pointed.
110 * 110 *
111 * @see edje_edit_image_usage_list_get() 111 * @see edje_edit_image_usage_list_get()
112 * @see edje_edit_vector_usage_list_get()
112 * @see edje_edit_image_usage_list_free() 113 * @see edje_edit_image_usage_list_free()
113 */ 114 */
114struct _Edje_Part_Image_Use 115struct _Edje_Part_Image_Use
@@ -6747,7 +6748,8 @@ EAPI Eina_Bool edje_edit_image_rename(Evas_Object *obj, const char *name, const
6747 */ 6748 */
6748EAPI Eina_List* edje_edit_image_usage_list_get(Evas_Object *obj, const char *name, Eina_Bool first_only); 6749EAPI Eina_List* edje_edit_image_usage_list_get(Evas_Object *obj, const char *name, Eina_Bool first_only);
6749 6750
6750/** Free an Eina_List of (Edje_Part_Image_Use *) allocated by an edje_edit_image_usage_list_get() function. 6751/** Free an Eina_List of (Edje_Part_Image_Use *) allocated by an edje_edit_image_usage_list_get() or
6752 * an edje_edit_vector_usage_list_get() function.
6751 * 6753 *
6752 * @param lst List of strings to free. 6754 * @param lst List of strings to free.
6753 */ 6755 */
@@ -6792,6 +6794,33 @@ EAPI const char * edje_edit_state_image_get(Evas_Object *obj, const char *part,
6792 */ 6794 */
6793EAPI Eina_Bool edje_edit_state_image_set(Evas_Object *obj, const char *part, const char *state, double value, const char *image); 6795EAPI Eina_Bool edje_edit_state_image_set(Evas_Object *obj, const char *part, const char *state, double value, const char *image);
6794 6796
6797/** Get normal vector name for a given part state.
6798 * Part should be of type VECTOR
6799 *
6800 * @param obj Object being edited.
6801 * @param part Part that contain state.
6802 * @param state The name of the state to get the name that is being used (not including the state value).
6803 * @param value The state value.
6804 *
6805 * @return The name of the vector used by state.
6806 * @since 1.19
6807 */
6808EAPI const char * edje_edit_state_vector_get(Evas_Object *obj, const char *part, const char *state, double value);
6809
6810/** Set normal vector name for a given part state.
6811 * Part should be of type VECTOR
6812 *
6813 * @param obj Object being edited.
6814 * @param part Part that contain state.
6815 * @param state The name of the state to set the vector that will be used (not including the state value).
6816 * @param value The state value.
6817 * @param image The name of the vector (must be contained in the edje file).
6818 *
6819 * @return @c EINA_TRUE in case of success, @c EINA_FALSE otherwise.
6820 * @since 1.19
6821 */
6822EAPI Eina_Bool edje_edit_state_vector_set(Evas_Object *obj, const char *part, const char *state, double value, const char *image);
6823
6795/** Get image id for a given image name. 6824/** Get image id for a given image name.
6796 * 6825 *
6797 * @param obj Object being edited. 6826 * @param obj Object being edited.
@@ -7028,6 +7057,63 @@ EAPI Eina_Bool edje_edit_state_tween_del(Evas_Object *obj, const char *part, con
7028 7057
7029//@} 7058//@}
7030/******************************************************************************/ 7059/******************************************************************************/
7060/************************** VECTORS API ************************************/
7061/******************************************************************************/
7062
7063/** Get vector id for a given vector name.
7064 *
7065 * @param obj Object being edited.
7066 * @param vector_name The vector name.
7067 *
7068 * @return The id of the given vector name.
7069 * @since 1.19
7070 */
7071EAPI int edje_edit_vector_id_get(Evas_Object *obj, const char *vector_name);
7072
7073/** @name Vectors API
7074 * Functions to deal with vector objects of images (see @ref edcref).
7075 */ //@{
7076
7077/** Get the list of all the vectors in the given edje.
7078 * Use edje_edit_string_list_free() when you don't need the list anymore.
7079 *
7080 * @param obj Object being edited.
7081 *
7082 * @return A List containing all vector names found in the edje file.
7083 * @since 1.19
7084 */
7085EAPI Eina_List * edje_edit_vectors_list_get(Evas_Object *obj);
7086
7087/** Delete vector from the vector collection
7088 *
7089 * It actually write directly to the file so you don't have to save.
7090 * Can't delete vector if it is used by any part.
7091 *
7092 * @param obj Object being edited.
7093 * @param name The name of the vector file.
7094 *
7095 * @return @c EINA_TRUE in case of success, @c EINA_FALSE otherwise (including the
7096 * case when the name is not valid or vector is in use).
7097 * @since 1.19
7098 */
7099EAPI Eina_Bool edje_edit_vector_del(Evas_Object *obj, const char *name);
7100
7101/** Get list of (Edje_Part_Image_Use *) - group-part-state triplets where given
7102 * vector is used.
7103 *
7104 * Use edje_edit_image_usage_list_free() when you don't need it anymore.
7105 *
7106 * @param obj Object being edited.
7107 * @param name The name of the vector.
7108 * @param first_only If EINA_TRUE, return only one triplete.
7109 *
7110 * @return Eina_List containing Edje_Part_Image_Use if successful, NULL otherwise
7111 * @since 1.19
7112 */
7113EAPI Eina_List* edje_edit_vector_usage_list_get(Evas_Object *obj, const char *name, Eina_Bool first_only);
7114
7115//@}
7116/******************************************************************************/
7031/************************** SOUNDS API ************************************/ 7117/************************** SOUNDS API ************************************/
7032/******************************************************************************/ 7118/******************************************************************************/
7033/** @name Sounds API 7119/** @name Sounds API
diff --git a/src/lib/edje/edje_edit.c b/src/lib/edje/edje_edit.c
index 85aec1308b..c7eaa19d0e 100644
--- a/src/lib/edje/edje_edit.c
+++ b/src/lib/edje/edje_edit.c
@@ -313,6 +313,24 @@ _edje_part_description_find_byname(Edje_Edit *eed, const char *part, const char
313} 313}
314 314
315static int 315static int
316_edje_vector_id_find(Edje_Edit *eed, const char *vector_name)
317{
318 unsigned int i;
319
320 if (!eed->base->file) return -1;
321 if (!eed->base->file->image_dir) return -1;
322
323 //printf("SEARCH IMAGE %s\n", vector_name);
324
325 for (i = 0; i < eed->base->file->image_dir->vectors_count; ++i)
326 if (eed->base->file->image_dir->vectors[i].entry
327 && !strcmp(vector_name, eed->base->file->image_dir->vectors[i].entry))
328 return i;
329
330 return -1;
331}
332
333static int
316_edje_image_id_find(Edje_Edit *eed, const char *image_name) 334_edje_image_id_find(Edje_Edit *eed, const char *image_name)
317{ 335{
318 unsigned int i; 336 unsigned int i;
@@ -372,6 +390,17 @@ _edje_set_name_find(Edje_Edit *eed, int set_id)
372 return eed->base->file->image_dir->sets[set_id].name; 390 return eed->base->file->image_dir->sets[set_id].name;
373} 391}
374 392
393static const char *
394_edje_vector_name_find(Edje_Edit *eed, int vector_id)
395{
396 if (!eed->base->file) return NULL;
397 if (!eed->base->file->image_dir) return NULL;
398
399 if ((unsigned int)vector_id >= eed->base->file->image_dir->vectors_count)
400 return NULL;
401 return eed->base->file->image_dir->vectors[vector_id].entry;
402}
403
375static void 404static void
376_edje_real_part_free(Edje *ed, Edje_Real_Part *rp) 405_edje_real_part_free(Edje *ed, Edje_Real_Part *rp)
377{ 406{
@@ -9611,6 +9640,231 @@ edje_edit_image_set_image_border_scale_set(Evas_Object *obj, const char *set_nam
9611} 9640}
9612 9641
9613/****************/ 9642/****************/
9643/* VECTOR API */
9644/****************/
9645
9646EAPI Eina_List *
9647edje_edit_vectors_list_get(Evas_Object *obj)
9648{
9649 Eina_List *vectors = NULL;
9650 unsigned int i;
9651
9652 GET_ED_OR_RETURN(NULL);
9653
9654 if (!ed->file) return NULL;
9655 if (!ed->file->image_dir) return NULL;
9656
9657 for (i = 0; i < ed->file->image_dir->vectors_count; ++i)
9658 vectors = eina_list_append(vectors,
9659 eina_stringshare_add(ed->file->image_dir->vectors[i].entry));
9660
9661 return vectors;
9662}
9663
9664EAPI int
9665edje_edit_vector_id_get(Evas_Object *obj, const char *vector_name)
9666{
9667 GET_EED_OR_RETURN(-1);
9668
9669 return _edje_vector_id_find(eed, vector_name);
9670}
9671
9672EAPI Eina_List *
9673edje_edit_vector_usage_list_get(Evas_Object *obj, const char *name, Eina_Bool first_only)
9674{
9675 Eina_List *result = NULL;
9676 Eina_Iterator *it;
9677 Edje_Part_Collection_Directory_Entry *pce;
9678 Edje_Part_Image_Use *item;
9679 Edje_Part *part;
9680 Edje_Part_Description_Vector *part_desc_vector;
9681 unsigned int i, j;
9682 int vector_id;
9683
9684 GET_ED_OR_RETURN(NULL);
9685
9686 vector_id = edje_edit_vector_id_get(obj, name);
9687 if (vector_id < 0)
9688 return NULL;
9689
9690 it = eina_hash_iterator_data_new(ed->file->collection);
9691
9692#define ITEM_ADD() \
9693 item = (Edje_Part_Image_Use *)calloc(1, sizeof(Edje_Part_Image_Use)); \
9694 item->group = eina_stringshare_add(pce->entry); \
9695 item->part = eina_stringshare_add(part->name); \
9696 item->state.name = eina_stringshare_add(part_desc_vector->common.state.name);\
9697 item->state.value = part_desc_vector->common.state.value; \
9698 result = eina_list_append(result, item);
9699
9700#define FIND_IN_PART_DESCRIPTION() \
9701 if (part_desc_vector->vg.id == vector_id) \
9702 { \
9703 ITEM_ADD(); \
9704 if (first_only) \
9705 goto end; \
9706 else \
9707 continue; \
9708 }
9709
9710 EINA_ITERATOR_FOREACH(it, pce)
9711 {
9712 if (!pce->ref) continue;
9713 for (i = 0; i < pce->ref->parts_count; i++)
9714 {
9715 if (!pce->ref->parts) continue;
9716 part = pce->ref->parts[i];
9717 if (part->type == EDJE_PART_TYPE_VECTOR)
9718 {
9719 part_desc_vector = (Edje_Part_Description_Vector *)part->default_desc;
9720 FIND_IN_PART_DESCRIPTION();
9721 for (j = 0; j < part->other.desc_count; j++)
9722 {
9723 part_desc_vector = (Edje_Part_Description_Vector *)part->other.desc[j];
9724 FIND_IN_PART_DESCRIPTION();
9725 }
9726 }
9727 }
9728 }
9729
9730 #undef ITEM_ADD
9731 #undef FIND_IN_PART_DESCRIPTION
9732end:
9733 eina_iterator_free(it);
9734
9735 return result;
9736}
9737
9738EAPI Eina_Bool
9739edje_edit_vector_del(Evas_Object *obj, const char *name)
9740{
9741 Edje_Vector_Directory_Entry *de, *de_last;
9742 unsigned int i, j;
9743 Eina_List *used;
9744 Eina_Iterator *it;
9745 Edje_Part_Collection_Directory_Entry *pce;
9746
9747 GET_EED_OR_RETURN(EINA_FALSE);
9748 GET_ED_OR_RETURN(EINA_FALSE);
9749
9750 if (!name) return EINA_FALSE;
9751 if (!ed->file) return EINA_FALSE;
9752 if (!ed->path) return EINA_FALSE;
9753
9754 used = edje_edit_vector_usage_list_get(obj, name, EINA_TRUE);
9755 if (used)
9756 {
9757 edje_edit_image_usage_list_free(used);
9758 WRN("Vector \"%s\" is used", name);
9759 return EINA_FALSE;
9760 }
9761 edje_edit_image_usage_list_free(used);
9762
9763 /* Create Image_Directory if not exist */
9764 if (!ed->file->image_dir)
9765 goto invalid_image;
9766
9767 for (i = 0; i < ed->file->image_dir->vectors_count; ++i)
9768 {
9769 de = ed->file->image_dir->vectors + i;
9770
9771 if ((de->entry) && (!strcmp(name, de->entry)))
9772 break;
9773 }
9774 if (i == ed->file->image_dir->vectors_count)
9775 goto invalid_image;
9776
9777 de_last = ed->file->image_dir->vectors + ed->file->image_dir->vectors_count - 1;
9778
9779 {
9780 char entry[PATH_MAX];
9781 char last_entry[PATH_MAX];
9782 Eet_File *eetf;
9783 void *data;
9784 int size = 0;
9785
9786 /* open the eet file */
9787 eetf = _edje_edit_eet_open(ed, EET_FILE_MODE_READ_WRITE);
9788 if (!eetf)
9789 return EINA_FALSE;
9790
9791 snprintf(entry, sizeof(entry), "edje/vectors/%i", de->id);
9792
9793 if (eet_delete(eetf, entry) <= 0)
9794 {
9795 ERR("Unable to delete \"%s\" vector entry", entry);
9796 _edje_edit_eet_close(eetf);
9797 return EINA_FALSE;
9798 }
9799 if (de_last->id != de->id)
9800 {
9801 snprintf(last_entry, sizeof(last_entry), "edje/vectors/%i", de_last->id);
9802 data = eet_read(eetf, last_entry, &size);
9803 eet_delete(eetf, last_entry);
9804 eet_write(eetf, entry, data, size, 0);
9805 }
9806
9807 _edje_if_string_free(ed, &de->entry);
9808 --ed->file->image_dir->vectors_count;
9809
9810 if (de_last->id != de->id)
9811 {
9812 Edje_Part *part;
9813 Edje_Part_Description_Vector *part_desc_vector;
9814
9815 de->entry = de_last->entry;
9816 it = eina_hash_iterator_data_new(ed->file->collection);
9817 EINA_ITERATOR_FOREACH(it, pce)
9818 {
9819 if (!pce->ref) continue;
9820 for (i = 0; i < pce->ref->parts_count; i++)
9821 {
9822 if (!pce->ref->parts) continue;
9823 part = pce->ref->parts[i];
9824 if (part->type == EDJE_PART_TYPE_VECTOR)
9825 {
9826 part_desc_vector = (Edje_Part_Description_Vector *)part->default_desc;
9827 if (part_desc_vector->vg.id == de_last->id)
9828 part_desc_vector->vg.id = de->id;
9829
9830 for (j = 0; j < part->other.desc_count; j++)
9831 {
9832 part_desc_vector = (Edje_Part_Description_Vector *)part->other.desc[j];
9833 if (part_desc_vector->vg.id == de_last->id)
9834 part_desc_vector->vg.id = de->id;
9835 }
9836 }
9837 }
9838 if (!_edje_edit_collection_save(eetf, pce->ref))
9839 {
9840 _edje_edit_eet_close(eetf);
9841 return EINA_FALSE;
9842 }
9843 }
9844 eina_iterator_free(it);
9845 }
9846 ed->file->image_dir->vectors = realloc(ed->file->image_dir->vectors,
9847 sizeof(Edje_Vector_Directory_Entry) *
9848 ed->file->image_dir->vectors_count);
9849 /* write the edje_file */
9850 if (!_edje_edit_edje_file_save(eetf, ed->file))
9851 {
9852 _edje_edit_eet_close(eetf);
9853 return EINA_FALSE;
9854 }
9855
9856 _edje_edit_eet_close(eetf);
9857 }
9858 _edje_edit_flag_script_dirty(eed, EINA_TRUE);
9859
9860 return EINA_TRUE;
9861
9862invalid_image:
9863 WRN("Unable to find vector entry part \"%s\"", name);
9864 return EINA_FALSE;
9865}
9866
9867/****************/
9614/* IMAGES API */ 9868/* IMAGES API */
9615/****************/ 9869/****************/
9616 9870
@@ -10280,6 +10534,52 @@ edje_edit_state_image_set(Evas_Object *obj, const char *part, const char *state,
10280 return EINA_TRUE; 10534 return EINA_TRUE;
10281} 10535}
10282 10536
10537EAPI const char *
10538edje_edit_state_vector_get(Evas_Object *obj, const char *part, const char *state, double value)
10539{
10540 Edje_Part_Description_Vector *vec;
10541 const char *vector;
10542
10543 GET_PD_OR_RETURN(NULL);
10544
10545 if (rp->part->type != EDJE_PART_TYPE_VECTOR)
10546 return NULL;
10547
10548 vec = (Edje_Part_Description_Vector *)pd;
10549
10550 vector = _edje_vector_name_find(eed, vec->vg.id);
10551 if (!vector) return NULL;
10552
10553 //printf("GET IMAGE for %s [%s]\n", state, image);
10554 return eina_stringshare_add(vector);
10555}
10556
10557EAPI Eina_Bool
10558edje_edit_state_vector_set(Evas_Object *obj, const char *part, const char *state, double value, const char *vector)
10559{
10560 Edje_Part_Description_Vector *vec;
10561 int id;
10562
10563 if ((!obj) || (!part) || (!state) || (!vector))
10564 return EINA_FALSE;
10565
10566 eina_error_set(0);
10567 GET_PD_OR_RETURN(EINA_FALSE);
10568
10569 if (rp->part->type != EDJE_PART_TYPE_VECTOR)
10570 return EINA_FALSE;
10571
10572 vec = (Edje_Part_Description_Vector *)pd;
10573
10574 id = _edje_vector_id_find(eed, vector);
10575
10576 if (id > -1) vec->vg.id = id;
10577 else return EINA_FALSE;
10578
10579 edje_object_calc_force(obj);
10580 return EINA_TRUE;
10581}
10582
10283EAPI Eina_List * 10583EAPI Eina_List *
10284edje_edit_state_tweens_list_get(Evas_Object *obj, const char *part, const char *state, double value) 10584edje_edit_state_tweens_list_get(Evas_Object *obj, const char *part, const char *state, double value)
10285{ 10585{