devilhorns pushed a commit to branch master.

http://git.enlightenment.org/apps/express.git/commit/?id=4519bfb63ad98601aa61432c7da921b924b4f5d5

commit 4519bfb63ad98601aa61432c7da921b924b4f5d5
Author: Chris Michael <cp.mich...@samsung.com>
Date:   Mon Aug 3 14:21:37 2015 -0400

    express: Add support for scaleable media (svg, etc)
    
    Signed-off-by: Chris Michael <cp.mich...@samsung.com>
---
 src/bin/media.c | 233 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 219 insertions(+), 14 deletions(-)

diff --git a/src/bin/media.c b/src/bin/media.c
index 6b811ae..b122081 100644
--- a/src/bin/media.c
+++ b/src/bin/media.c
@@ -15,6 +15,7 @@ struct _Media
    Evas_Object *o_ctrl;
    Evas_Object *o_busy;
    Evas_Object *o_event;
+   Evas_Object *o_tmp;
 
    Ecore_Con_Url *url;
    Ecore_Event_Handler *_prog_hdlr, *_compl_hdlr;
@@ -28,7 +29,9 @@ struct _Media
    int w, h, iw, ih, sw, sh;
    int mode, resizes;
    int frame, frame_num, loops;
-   Ecore_Timer *anim;
+
+   Ecore_Timer *anim_tmr;
+   Ecore_Timer *smooth_tmr;
 
    Media_Type type;
 
@@ -38,6 +41,7 @@ struct _Media
         Eina_Bool down : 1;
      } down;
 
+   Eina_Bool nosmooth : 1;
    Eina_Bool downloading : 1;
    Eina_Bool queued : 1;
 };
@@ -53,7 +57,7 @@ static void _thumb_type_init(Evas_Object *obj);
 static void _ethumb_init(void);
 
 static void 
-_media_cb_img_preloaded(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj 
EINA_UNUSED, void *event EINA_UNUSED)
+_img_cb_preloaded(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj 
EINA_UNUSED, void *event EINA_UNUSED)
 {
    Media *sd;
 
@@ -79,7 +83,7 @@ _img_cb_frame(void *data)
         if (evas_object_image_animated_loop_type_get(sd->o_img) ==
             EVAS_IMAGE_ANIMATED_HINT_NONE)
           {
-             sd->anim = NULL;
+             sd->anim_tmr = NULL;
              return EINA_FALSE;
           }
 
@@ -89,7 +93,7 @@ _img_cb_frame(void *data)
           {
              if (loops < sd->loops)
                {
-                  sd->anim = NULL;
+                  sd->anim_tmr = NULL;
                   return EINA_FALSE;
                }
           }
@@ -97,7 +101,7 @@ _img_cb_frame(void *data)
 
    evas_object_image_animated_frame_set(sd->o_img, frame);
    t = evas_object_image_animated_frame_duration_get(sd->o_img, frame, 0);
-   ecore_timer_interval_set(sd->anim, t);
+   ecore_timer_interval_set(sd->anim_tmr, t);
 
    return EINA_TRUE;
 }
@@ -114,7 +118,7 @@ _img_type_anim_handle(Evas_Object *obj)
    sd->frame_num = evas_object_image_animated_frame_count_get(sd->o_img);
    if (sd->frame_num < 2) return;
    t = evas_object_image_animated_frame_duration_get(sd->o_img, sd->frame, 0);
-   sd->anim = ecore_timer_add(t, _img_cb_frame, obj);
+   sd->anim_tmr = ecore_timer_add(t, _img_cb_frame, obj);
 }
 
 static void 
@@ -129,7 +133,7 @@ _img_type_init(Evas_Object *obj)
    evas_object_clip_set(sd->o_img, sd->o_clip);
    evas_object_raise(sd->o_event);
    evas_object_event_callback_add(sd->o_img, EVAS_CALLBACK_IMAGE_PRELOADED,
-                                  _media_cb_img_preloaded, obj);
+                                  _img_cb_preloaded, obj);
    evas_object_image_load_orientation_set(sd->o_img, EINA_TRUE);
    evas_object_image_file_set(sd->o_img, sd->realf, NULL);
    evas_object_image_size_get(sd->o_img, &sd->iw, &sd->ih);
@@ -379,6 +383,203 @@ _thumb_type_init(Evas_Object *obj)
    _thumb_type_theme_init(obj);
 }
 
+static void
+_scale_cb_preloaded(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj 
EINA_UNUSED, void *event EINA_UNUSED)
+{
+   Media *sd;
+
+   if (!(sd = evas_object_smart_data_get(data))) return;
+
+   if (!sd->o_tmp)
+     {
+        evas_object_show(sd->o_img);
+        evas_object_show(sd->o_clip);
+     }
+   else
+     {
+        evas_object_del(sd->o_img);
+        sd->o_img = sd->o_tmp;
+        sd->o_tmp = NULL;
+        evas_object_show(sd->o_img);
+        evas_object_show(sd->o_clip);
+     }
+}
+
+static void
+_scale_type_calc(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, 
Evas_Coord h)
+{
+   Media *sd;
+
+   if (!(sd = evas_object_smart_data_get(obj))) return;
+
+   if ((w <= 0) || (h <= 0) || (sd->iw <= 0) || (sd->ih <= 0))
+     {
+        w = 1;
+        h = 1;
+     }
+   else
+     {
+        int iw = 1, ih = 1;
+
+        if ((sd->mode & MEDIA_SIZE_MASK) == MEDIA_BG)
+          {
+             iw = w;
+             ih = (sd->ih * w) / sd->iw;
+             if (ih < h)
+               {
+                  ih = h;
+                  iw = (sd->iw * h) / sd->ih;
+                  if (iw < w) iw = w;
+               }
+          }
+        else if ((sd->mode & MEDIA_SIZE_MASK) == MEDIA_POP)
+          {
+             iw = w;
+             ih = (sd->ih * w) / sd->iw;
+             if (ih > h)
+               {
+                  ih = h;
+                  iw = (sd->iw * h) / sd->ih;
+                  if (iw > w) iw = w;
+               }
+             /* if ((iw > sd->iw) || (ih > sd->ih)) */
+             /*   { */
+             /*      iw = sd->iw; */
+             /*      ih = sd->ih; */
+             /*   } */
+          }
+        else if ((sd->mode & MEDIA_SIZE_MASK) == MEDIA_STRETCH)
+          {
+             iw = w;
+             ih = h;
+          }
+        x += ((w - iw) / 2);
+        y += ((h - ih) / 2);
+        w = iw;
+        h = ih;
+     }
+
+   if (!sd->nosmooth)
+     {
+        Evas_Coord sw, sh;
+
+        sw = w;
+        sh = h;
+        if (sw < 256) sw = 256;
+        if (sh < 256) sh = 256;
+        if ((sw != sd->sw) || (sh != sd->sh))
+          {
+             sd->o_tmp =
+               evas_object_image_filled_add(evas_object_evas_get(sd->o_event));
+             evas_object_event_callback_add(sd->o_tmp,
+                                            EVAS_CALLBACK_IMAGE_PRELOADED,
+                                            _scale_cb_preloaded, sd);
+             evas_object_image_load_orientation_set(sd->o_tmp, EINA_TRUE);
+             evas_object_image_file_set(sd->o_tmp, sd->realf, NULL);
+             evas_object_image_load_size_set(sd->o_tmp, sw, sh);
+             evas_object_image_preload(sd->o_tmp, EINA_FALSE);
+
+             evas_object_smart_member_add(sd->o_tmp, obj);
+             evas_object_clip_set(sd->o_tmp, sd->o_clip);
+             evas_object_raise(sd->o_event);
+          }
+
+        sd->sw = sw;
+        sd->sh = sh;
+     }
+
+   if (sd->o_tmp)
+     {
+        evas_object_move(sd->o_tmp, x, y);
+        evas_object_resize(sd->o_tmp, w, h);
+     }
+
+   evas_object_move(sd->o_img, x, y);
+   evas_object_resize(sd->o_img, w, h);
+}
+
+static void
+_scale_type_init(Evas_Object *obj)
+{
+   Media *sd;
+
+   if (!(sd = evas_object_smart_data_get(obj))) return;
+
+   sd->o_img = evas_object_image_filled_add(evas_object_evas_get(obj));
+   evas_object_event_callback_add(sd->o_img, EVAS_CALLBACK_IMAGE_PRELOADED,
+                                  _scale_cb_preloaded, obj);
+   evas_object_image_load_orientation_set(sd->o_img, EINA_TRUE);
+   evas_object_image_file_set(sd->o_img, sd->realf, NULL);
+   evas_object_image_size_get(sd->o_img, &sd->iw, &sd->ih);
+   evas_object_image_preload(sd->o_img, EINA_FALSE);
+   evas_object_smart_member_add(sd->o_img, obj);
+   evas_object_clip_set(sd->o_img, sd->o_clip);
+   evas_object_raise(sd->o_event);
+}
+
+static Eina_Bool
+_unsmooth_timeout(void *data)
+{
+   Media *sd;
+
+   if (!(sd = evas_object_smart_data_get(data))) return EINA_FALSE;
+
+   sd->smooth_tmr = NULL;
+   sd->nosmooth = EINA_FALSE;
+
+   if ((sd->type == MEDIA_TYPE_IMG) || (sd->type == MEDIA_TYPE_SCALE))
+     {
+        evas_object_image_smooth_scale_set(sd->o_img, !sd->nosmooth);
+        if (sd->o_tmp)
+          evas_object_image_smooth_scale_set(sd->o_tmp, !sd->nosmooth);
+
+        if (sd->type == MEDIA_TYPE_SCALE)
+          {
+             Evas_Coord ox, oy, ow, oh;
+
+             evas_object_geometry_get(data, &ox, &oy, &ow, &oh);
+             _scale_type_calc(data, ox, oy, ow, oh);
+          }
+     }
+   else if (sd->type == MEDIA_TYPE_MOV)
+     emotion_object_smooth_scale_set(sd->o_img, !sd->nosmooth);
+
+   return EINA_FALSE;
+}
+
+static void
+_smooth_handler(Evas_Object *obj)
+{
+   Media *sd;
+   double interval;
+
+   if (!(sd = evas_object_smart_data_get(obj))) return;
+
+   interval = ecore_animator_frametime_get();
+   if (interval <= 0.0) interval = 1.0 / 60.0;
+
+   if (!sd->nosmooth)
+     {
+        if (sd->resizes >= 2)
+          {
+             sd->nosmooth = EINA_TRUE;
+             sd->resizes = 0;
+             if ((sd->type == MEDIA_TYPE_IMG) || (sd->type == 
MEDIA_TYPE_SCALE))
+               {
+                  evas_object_image_smooth_scale_set(sd->o_img, !sd->nosmooth);
+                  if (sd->o_tmp)
+                    evas_object_image_smooth_scale_set(sd->o_tmp, 
!sd->nosmooth);
+               }
+             else if (sd->type == MEDIA_TYPE_MOV)
+               emotion_object_smooth_scale_set(sd->o_img, !sd->nosmooth);
+          }
+     }
+
+   if (sd->smooth_tmr) ecore_timer_del(sd->smooth_tmr);
+   sd->smooth_tmr =
+     ecore_timer_add(interval * 10, _unsmooth_timeout, obj);
+}
+
 static void 
 _media_cb_mouse_down(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj 
EINA_UNUSED, void *event)
 {
@@ -470,9 +671,9 @@ _media_cb_compl(void *data, int type EINA_UNUSED, void 
*event)
       case MEDIA_TYPE_IMG:
         _img_type_init(obj);
         break;
-      /* case MEDIA_TYPE_SCALE: */
-      /*   _scale_type_init(obj); */
-      /*   break; */
+      case MEDIA_TYPE_SCALE:
+        _scale_type_init(obj);
+        break;
       /* case MEDIA_TYPE_EDJE: */
       /*   _edje_type_init(obj); */
       /*   break; */
@@ -541,7 +742,9 @@ _smart_del(Evas_Object *obj)
    if (sd->o_busy) evas_object_del(sd->o_busy);
    if (sd->o_event) evas_object_del(sd->o_event);
 
-   if (sd->anim) ecore_timer_del(sd->anim);
+   if (sd->anim_tmr) ecore_timer_del(sd->anim_tmr);
+   if (sd->smooth_tmr) ecore_timer_del(sd->smooth_tmr);
+
    if ((et_client) && (sd->et_req))
      ethumb_client_thumb_async_cancel(et_client, sd->et_req);
    if (sd->queued) et_queue = eina_list_remove(et_queue, obj);
@@ -575,6 +778,8 @@ _smart_calculate(Evas_Object *obj)
    if ((ow != sd->w) || (oh != sd->h)) sd->resizes++;
    else sd->resizes = 0;
 
+   _smooth_handler(obj);
+
    sd->w = ow;
    sd->h = oh;
    switch (sd->type)
@@ -582,9 +787,9 @@ _smart_calculate(Evas_Object *obj)
       case MEDIA_TYPE_IMG:
         _img_type_calc(sd, ox, oy, ow, oh);
         break;
-      /* case MEDIA_TYPE_SCALE: */
-      /*   _scale_type_calc(sd, ox, oy, ow, oh); */
-      /*   break; */
+      case MEDIA_TYPE_SCALE:
+        _scale_type_calc(obj, ox, oy, ow, oh);
+        break;
       /* case MEDIA_TYPE_EDJE: */
       /*   _edje_type_calc(sd, ox, oy, ow, oh); */
       /*   break; */

-- 


Reply via email to