edje: Add embryo function get_image_id
authorDaniel Willmann <d.willmann@samsung.com>
Thu, 15 Nov 2012 09:31:08 +0000 (09:31 +0000)
committerDaniel Willmann <daniel@totalueberwachung.de>
Thu, 15 Nov 2012 09:31:08 +0000 (09:31 +0000)
This makes it possible to change the image from an embryo script

Signed-off-by: Daniel Willmann <d.willmann@samsung.com>
SVN revision: 79327

legacy/edje/AUTHORS
legacy/edje/ChangeLog
legacy/edje/NEWS
legacy/edje/data/include/edje.inc
legacy/edje/src/examples/Makefile.am
legacy/edje/src/examples/bubble-blue.png [new file with mode: 0644]
legacy/edje/src/examples/embryo_custom_state.edc
legacy/edje/src/lib/edje_embryo.c
legacy/edje/src/lib/edje_private.h

index bb02878..60107ef 100644 (file)
@@ -31,3 +31,4 @@ WooHyun Jung (woohyun) <woohyun0705@gmail.com>
 Guilherme Silveira <xguiga@gmail.com>
 Flavio Ceolin <flavio.ceolin@profusion.mobi>
 Daniel Zaoui <daniel.zaoui@yahoo.com>
+Daniel Willmann <d.willmann@samsung.com>
index 450b7b6..336978b 100644 (file)
 2012-11-02  ChunEon Park (Hermet)
 
         * Fix to not update map uv for proxy
+
+2012-11-15  Daniel Willmann
+
+        * Add embryo function get_image_id
index 07c274a..08aaf8b 100644 (file)
@@ -9,6 +9,7 @@ Additions:
     * Add EDJE_INPUT_PANEL_RETURN_KEY_TYPE_SIGNIN
     * Add edje_codegen - A code generator to working with edje files.
     * Add more tags(preedit_sub1~4) for a variety of preediting states.
+    * Add embryo function get_image_id
 
 Improvements:
     * Change Edje to use Eo.
index dfa5416..55eb9ee 100644 (file)
@@ -84,6 +84,7 @@ native       cancel_anim(id);
  */
 native       emit             (sig[], src[]);
 native       get_part_id      (part[]);
+native       get_image_id      (image[]);
 native       set_state        (part_id, state[], Float:state_val);
 native       get_state        (part_id, dst[], maxlen, &Float:val);
 native       set_tween_state  (part_id, Float:tween, state1[], Float:state1_val, state2[], Float:state2_val);
index 1c62c9e..99f32df 100644 (file)
@@ -60,6 +60,7 @@ filesdir = $(pkgdatadir)/examples
 files_DATA = \
 $(EDCS) \
 bubble.png \
+bubble-blue.png \
 red.png \
 test.png \
 Vera.ttf \
diff --git a/legacy/edje/src/examples/bubble-blue.png b/legacy/edje/src/examples/bubble-blue.png
new file mode 100644 (file)
index 0000000..7cf4dcd
Binary files /dev/null and b/legacy/edje/src/examples/bubble-blue.png differ
index 9277c90..35a3998 100644 (file)
@@ -1,10 +1,29 @@
 collections {
+   images {
+      image: "bubble.png" COMP;
+      image: "bubble-blue.png" COMP;
+   }
+
    group { name: "main";
       script {
          /* define 3 global vars to hold the rotation values */
          public rotx;
          public roty;
          public rotz;
+
+         public change_image(part[], img[]) {
+               new imgid;
+               new partid;
+
+               partid = get_part_id(part);
+               imgid = get_image_id(img);
+
+               custom_state(partid, "default", 0.0);
+               /* change the rotation in the custom state */
+               set_state_val(partid, STATE_IMAGE, imgid);
+               /* apply the custom state */
+               set_state(partid, "custom", 0.0);
+        }
       }
       parts {
          part { name: "bg";
@@ -13,6 +32,18 @@ collections {
                color: 255 255 255 255;
             }
          }
+         part { name: "img";
+            type: IMAGE;
+            description { state: "default" 0.0;
+              image { normal: "bubble.png"; }
+            }
+            /* Dummy state - otherwise edje_cc discards bubble-blue.png
+               as it thinks it's unused */
+            description { state: "foo" 0.0;
+              image { normal: "bubble-blue.png"; }
+            }
+         }
+            
          part { name: "title";
             type: TEXT;
             description { state: "default" 0.0;
@@ -61,6 +92,18 @@ collections {
                }
             }
          }
+         part { name: "setimg";
+            type: TEXT;
+            description { state: "default" 0.0;
+              color: 0 0 0 255;
+              text {
+                text: "Change image";
+                font: "Sans";
+                  size: 12;
+                  align: 0.5 1;
+               }
+            }
+         }
          part { name: "rect";
             type: RECT;
             mouse_events: 0;
@@ -129,6 +172,13 @@ collections {
                set_text(PART:"Z", buf);
             }
          }
+         program {
+            signal: "mouse,down,1";
+            source: "setimg";
+            script {
+               change_image("img", "bubble-blue.png");
+            }
+         }
       }
    }
 }
index cad3b60..16e6f02 100644 (file)
@@ -828,6 +828,33 @@ _edje_embryo_fn_get_part_id(Embryo_Program *ep, Embryo_Cell *params)
    return -1;
 }
 
+/* get_image_id(img[]) */
+static Embryo_Cell
+_edje_embryo_fn_get_image_id(Embryo_Program *ep, Embryo_Cell *params)
+{
+   Edje *ed;
+   Edje_File *file;
+   Edje_Image_Directory *dir;
+   Edje_Image_Directory_Entry *dirent;
+   char *p;
+   unsigned int i, j;
+
+   CHKPARAM(1);
+   ed = embryo_program_data_get(ep);
+   GETSTR(p, params[1]);
+   if (!p) return -1;
+   file = ed->file;
+   if (!file) return -1;
+   dir = file->image_dir;
+   dirent = dir->entries;
+   for (i = 0; i < dir->entries_count; i++, dirent++)
+     {
+        if (!dirent->entry) continue;
+        if (!strcmp(dirent->entry, p)) return dirent->id;
+     }
+   return -1;
+}
+
 static Embryo_Cell
 _edje_embryo_fn_play_sample(Embryo_Program *ep, Embryo_Cell *params)
 {
@@ -3022,6 +3049,7 @@ _edje_embryo_script_init(Edje_Part_Collection *edc)
 
    embryo_program_native_call_add(ep, "emit", _edje_embryo_fn_emit);
    embryo_program_native_call_add(ep, "get_part_id", _edje_embryo_fn_get_part_id);
+   embryo_program_native_call_add(ep, "get_image_id", _edje_embryo_fn_get_image_id);
    embryo_program_native_call_add(ep, "set_state", _edje_embryo_fn_set_state);
    embryo_program_native_call_add(ep, "get_state", _edje_embryo_fn_get_state);
    embryo_program_native_call_add(ep, "set_tween_state", _edje_embryo_fn_set_tween_state);
index 20439f4..0a93a34 100644 (file)
@@ -530,8 +530,8 @@ struct _Edje_Image_Directory
    Edje_Image_Directory_Entry *entries; /* an array of Edje_Image_Directory_Entry */
    unsigned int entries_count;
 
-   Edje_Image_Directory_Set *sets;
-   unsigned int sets_count; /* an array of Edje_Image_Directory_Set */
+   Edje_Image_Directory_Set *sets; /* an array of Edje_Image_Directory_Set */
+   unsigned int sets_count;
 };
 
 struct _Edje_Image_Directory_Entry