From: Jiyoun Park <jy0703.park@samsung.com>
authorraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 11 Aug 2011 06:05:05 +0000 (06:05 +0000)
committerraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 11 Aug 2011 06:05:05 +0000 (06:05 +0000)
Subject: RE: [E-devel] [Patch] Animation gif feature patch

animated image support in elm icon - from jy.

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/elementary@62332 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

data/images/Makefile.am
data/images/animated_logo.gif [new file with mode: 0644]
src/bin/Makefile.am
src/bin/test.c
src/bin/test_icon_animated.c [new file with mode: 0644]
src/lib/Elementary.h.in
src/lib/elm_icon.c

index 637b248..f0179f5 100644 (file)
@@ -18,6 +18,7 @@ sky_04.jpg \
 wood_01.jpg \
 logo.png \
 logo_small.png \
+animated_logo.gif \
 parking.png \
 icon_00.png \
 icon_01.png \
diff --git a/data/images/animated_logo.gif b/data/images/animated_logo.gif
new file mode 100644 (file)
index 0000000..ef201af
Binary files /dev/null and b/data/images/animated_logo.gif differ
index bdbdcff..6691a7b 100644 (file)
@@ -73,6 +73,7 @@ test_hover.c \
 test_hoversel.c \
 test_icon.c \
 test_icon_desktops.c \
+test_icon_animated.c \
 test_index.c \
 test_inwin.c \
 test_label.c \
index 693a425..d0fdf75 100644 (file)
@@ -96,6 +96,7 @@ void test_photocam(void *data, Evas_Object *obj, void *event_info);
 void test_photo(void *data, Evas_Object *obj, void *event_info);
 void test_thumb(void *data, Evas_Object *obj, void *event_info);
 void test_icon_desktops(void *data, Evas_Object *obj, void *event_info);
+void test_icon_animated(void *data, Evas_Object *obj, void *event_info);
 void test_notify(void *data, Evas_Object *obj, void *event_info);
 void test_slideshow(void *data, Evas_Object *obj, void *event_info);
 void test_menu(void *data, Evas_Object *obj, void *event_info);
@@ -285,6 +286,7 @@ my_win_main(char *autorun, Eina_Bool test_win_only)
    ADD_TEST("Bg Image", test_bg_image);
    ADD_TEST("Bg Options", test_bg_options);
    ADD_TEST("Icon Transparent", test_icon);
+   ADD_TEST("Icon Animation", test_icon_animated);
    ADD_TEST("Box Vert", test_box_vert);
    ADD_TEST("Box Vert 2", test_box_vert2);
    ADD_TEST("Box Horiz", test_box_horiz);
diff --git a/src/bin/test_icon_animated.c b/src/bin/test_icon_animated.c
new file mode 100644 (file)
index 0000000..100681b
--- /dev/null
@@ -0,0 +1,50 @@
+#include <Elementary.h>
+#ifdef HAVE_CONFIG_H
+# include "elementary_config.h"
+#endif
+#ifndef ELM_LIB_QUICKLAUNCH
+static void
+icon_clicked(void *data , Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+   Evas_Object *ic;
+   ic = data;
+   Eina_Bool rec;
+   rec = elm_icon_animated_play_get(ic);
+   rec = !rec;
+   printf("clicked!rec =%d\n",rec);
+   elm_icon_animated_play_set(ic, rec);
+
+}
+
+void
+test_icon_animated(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+   Evas_Object *win, *ic;
+   char buf[PATH_MAX];
+
+   win = elm_win_add(NULL, "icon-animated-gif", ELM_WIN_BASIC);
+   elm_win_title_set(win, "Icon Animated Gif");
+   elm_win_autodel_set(win, 1);
+   elm_win_alpha_set(win, 1);
+
+   ic = elm_icon_add(win);
+   snprintf(buf, sizeof(buf), "%s/images/animated_logo.gif", PACKAGE_DATA_DIR);
+   elm_icon_file_set(ic, buf, NULL);
+   if (elm_icon_animated_available_get(ic))
+     {
+        printf("============Support animator==============\n");
+     }
+   elm_icon_animated_set(ic, TRUE);
+   elm_icon_animated_play_set(ic, TRUE);
+   elm_icon_scale_set(ic, 0, 0);
+   elm_icon_no_scale_set(ic, 1);
+   evas_object_size_hint_weight_set(ic, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_fill_set(ic, 0.5, 0.5);
+   elm_win_resize_object_add(win, ic);
+   evas_object_show(ic);
+
+   evas_object_smart_callback_add(ic, "clicked", icon_clicked, ic);
+
+   evas_object_show(win);
+}
+#endif
index 43c21a7..e2bfdbb 100644 (file)
@@ -4736,6 +4736,70 @@ extern "C" {
     * @ingroup Icon
     */
    EAPI Elm_Icon_Lookup_Order elm_icon_order_lookup_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
+   /**
+    * Get the flag related with elm icon can support animation
+    *
+    * @param obj The icon object
+    * @return The flag of animation available
+    *
+    * Return this elm icon's image can be animated
+    * Currently Evas only support gif's animation
+    * If the return value of this function is EINA_FALSE,
+    * other elm_icon_animated_XXX functions don't work
+    * @ingroup Icon
+    */
+   EAPI Eina_Bool           elm_icon_animated_available_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
+   /**
+    * Set animation mode of the icon.
+    *
+    * @param obj The icon object
+    * @param anim @c EINA_TRUE if the object do animation job,
+    * @c EINA_FALSE otherwise. Default is @c EINA_FALSE.
+    *
+    * Even though elm icon's file can be animated, 
+    * sometimes appication developer want to just first page of image.
+    * In that time, don't call this function, because default value is EINA_FALSE
+    * Only when you want icon support anition, 
+    * use this function and set animated to EINA_TURE
+    * @ingroup Icon
+    */
+   EAPI void                elm_icon_animated_set(Evas_Object *obj, Eina_Bool animated) EINA_ARG_NONNULL(1);
+   /**
+    * Get animation mode of the icon.
+    *
+    * @param obj The icon object
+    * @return The animation mode of the icon object
+    * @see elm_icon_animated_set
+    * @ingroup Icon
+    */
+   EAPI Eina_Bool           elm_icon_animated_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
+   /**
+    * Set animation play mode of the icon.
+    *
+    * @param obj The icon object
+    * @param play @c EINA_TRUE the object play animation images,
+    * @c EINA_FALSE otherwise. Default is @c EINA_FALSE.
+    * 
+    * If you want to play elm icon's animation, you set play to EINA_TURE.
+    * For example, you make gif player using this set/get API and click event.
+    *
+    * 1. Click event occurs
+    * 2. Check play flag using elm_icon_animaged_play_get
+    * 3. If elm icon was playing, set play to EINA_FALSE. 
+    *    Then animation will be stopped and vice versa
+    * @ingroup Icon
+    */
+   EAPI void                elm_icon_animated_play_set(Evas_Object *obj, Eina_Bool play) EINA_ARG_NONNULL(1);
+   /**
+    * Get animation play mode of the icon.
+    *
+    * @param obj The icon object
+    * @return The play mode of the icon object
+    *
+    * @see elm_icon_animated_lay_get
+    * @ingroup Icon
+    */
+   EAPI Eina_Bool           elm_icon_animated_play_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
 
    /**
     * @}
@@ -4746,6 +4810,7 @@ extern "C" {
     *
     * @image html img/widget/image/preview-00.png
     * @image latex img/widget/image/preview-00.eps
+
     *
     * An object that allows one to load an image file to it. It can be used
     * anywhere like any other elementary widget.
index 56eaaf7..f9fa698 100644 (file)
@@ -44,6 +44,14 @@ struct _Widget_Data
    Eina_Bool smooth : 1;
    Eina_Bool fill_outside : 1;
    Eina_Bool no_scale : 1;
+
+   /* for animation feature */
+   Ecore_Timer *timer;
+   int frame_count;
+   int cur_frame;
+   double duration;
+   Eina_Bool anim : 1;
+   Eina_Bool play : 1;
 };
 
 #ifdef HAVE_ELEMENTARY_ETHUMB
@@ -330,6 +338,8 @@ _del_hook(Evas_Object *obj)
      ecore_event_handler_del(wd->thumb.eeh);
 #endif
 
+   if (wd->timer)
+     ecore_timer_del(wd->timer);
    free(wd);
 }
 
@@ -430,6 +440,28 @@ _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *eve
    evas_object_smart_callback_call(data, SIG_CLICKED, event_info);
 }
 
+static Eina_Bool
+_elm_icon_animate_cb(void *data)
+{
+   Widget_Data  *wd = data;
+   Evas_Object  *img_obj;
+
+   if (!wd) return ECORE_CALLBACK_CANCEL;
+   if (!wd->anim) return ECORE_CALLBACK_CANCEL;
+
+   img_obj = _els_smart_icon_object_get(wd->img);
+   wd->cur_frame++;
+   if (wd->cur_frame > wd->frame_count)
+     wd->cur_frame = wd->cur_frame % wd->frame_count;
+   evas_object_image_animated_frame_set(img_obj, wd->cur_frame);
+
+   wd->duration = evas_object_image_animated_frame_duration_get(img_obj, wd->cur_frame, 0);
+
+   if (wd->duration > 0)
+     ecore_timer_interval_set(wd->timer, wd->duration);
+   return ECORE_CALLBACK_RENEW;
+}
+
 EAPI Evas_Object *
 elm_icon_add(Evas_Object *parent)
 {
@@ -544,6 +576,91 @@ elm_icon_thumb_set(const Evas_Object *obj, const char *file, const char *group)
 #endif
 }
 
+
+EAPI Eina_Bool
+elm_icon_animated_available_get(const Evas_Object *obj)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
+   Evas_Object *img_obj ;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return EINA_FALSE;
+
+   img_obj = _els_smart_icon_object_get(wd->img);
+
+   return evas_object_image_animated_get(img_obj);
+}
+
+EAPI void
+elm_icon_animated_set(Evas_Object *obj, Eina_Bool anim)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Evas_Object *img_obj ;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   if (wd->anim == anim) return;
+
+   img_obj = _els_smart_icon_object_get(wd->img);
+   if (!evas_object_image_animated_get(img_obj)) return;
+   if (anim)
+     {
+        wd->frame_count = evas_object_image_animated_frame_count_get(img_obj);
+        wd->cur_frame = 1;
+        wd->duration = evas_object_image_animated_frame_duration_get(img_obj, wd->cur_frame, 0);
+        evas_object_image_animated_frame_set(img_obj, wd->cur_frame);
+     }
+   else
+     {
+        wd->frame_count = -1;
+        wd->cur_frame = -1;
+        wd->duration = -1;
+     }
+   wd->anim = anim;
+   return;
+}
+
+EAPI Eina_Bool
+elm_icon_animated_get(const Evas_Object *obj)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return EINA_FALSE;
+   return wd->anim;
+}
+
+EAPI void
+elm_icon_animated_play_set(Evas_Object *obj, Eina_Bool play)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   if (!wd->anim) return;
+   if (wd->play == play) return;
+
+   if (play)
+     {
+        wd->timer = ecore_timer_add(wd->duration, _elm_icon_animate_cb, wd);
+     }
+   else
+     {
+        if (wd->timer)
+          {
+             ecore_timer_del(wd->timer);
+             wd->timer = NULL;
+          }
+     }
+   wd->play = play;
+
+}
+
+EAPI Eina_Bool
+elm_icon_animated_play_get(const Evas_Object *obj)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return EINA_FALSE;
+   return wd->play;
+}
+
 static Eina_Bool
 _icon_standard_set(Widget_Data *wd, Evas_Object *obj, const char *name)
 {