elm_gengrid reorder mode effect added
authorJeongHyun Yun <jh0506.yun@samsung.com>
Thu, 9 Jun 2011 07:06:46 +0000 (16:06 +0900)
committerJeongHyun Yun <jh0506.yun@samsung.com>
Thu, 9 Jun 2011 07:06:46 +0000 (16:06 +0900)
src/lib/elm_gengrid.c

index d99fc80..d20588a 100644 (file)
  typedef struct _Pan         Pan;
 
 #define PRELOAD 1
+#define REORDER_EFFECT_TIME 0.5
 
  struct _Elm_Gengrid_Item
 {
    Evas_Object                  *spacer;
    const Elm_Gengrid_Item_Class *gic;
    Ecore_Timer                  *long_timer;
+   Ecore_Animator               *item_moving_effect_timer;
    Widget_Data                  *wd;
    Eina_List                    *labels, *icons, *states, *icon_objs;
    struct
         const void   *data;
      } func;
 
-   Evas_Coord x, y, dx, dy;
-   int        relcount;
-   int        walking;
+   Evas_Coord   x, y, dx, dy, ox, oy, tx, ty, rx, ry;
+   unsigned int moving_effect_start_time;
+   int          relcount;
+   int          walking;
 
    struct
      {
    Eina_Bool   disabled : 1;
    Eina_Bool   selected : 1;
    Eina_Bool   hilighted : 1;
+   Eina_Bool   moving : 1;
 };
 
 struct _Widget_Data
@@ -197,7 +201,7 @@ struct _Widget_Data
    Elm_Gengrid_Item *last_selected_item, *reorder_item;
    double            align_x, align_y;
 
-   Evas_Coord        pan_x, pan_y;
+   Evas_Coord        pan_x, pan_y, old_pan_x, old_pan_y;
    Evas_Coord        item_width, item_height; /* Each item size */
    Evas_Coord        minw, minh; /* Total obj size */
    Evas_Coord        reorder_item_x, reorder_item_y;
@@ -217,6 +221,7 @@ struct _Widget_Data
    Eina_Bool         v_bounce : 1;
    Eina_Bool         reorder_mode : 1;
    Eina_Bool         reorder_item_changed : 1;
+   Eina_Bool         move_effect_enabled : 1;
 };
 
 #define ELM_GENGRID_ITEM_FROM_INLIST(item) \
@@ -268,6 +273,7 @@ static const char SIG_DRAG[] = "drag";
 static const char SIG_SCROLL[] = "scroll";
 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
+static const char SIG_MOVED[] = "moved";
 
 static const Evas_Smart_Cb_Description _signals[] = {
        {SIG_CLICKED_DOUBLE, ""},
@@ -285,6 +291,7 @@ static const Evas_Smart_Cb_Description _signals[] = {
        {SIG_SCROLL, ""},
        {SIG_SCROLL_DRAG_START, ""},
        {SIG_SCROLL_DRAG_STOP, ""},
+       {SIG_MOVED, ""},
        {NULL, NULL}
 };
 
@@ -881,7 +888,7 @@ _long_press(void *data)
         evas_object_raise(item->base.view);
         elm_smart_scroller_hold_set(item->wd->scr, EINA_TRUE);
         elm_smart_scroller_bounce_allow_set(item->wd->scr, EINA_FALSE, EINA_FALSE);
-        edje_object_signal_emit(item->base.view, "elm,state,reorder_enabled", "elm");
+        edje_object_signal_emit(item->base.view, "elm,state,reorder,enabled", "elm");
      }
    return ECORE_CALLBACK_CANCEL;
 }
@@ -956,11 +963,11 @@ _mouse_up(void            *data,
         if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
           item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
 
-        evas_object_smart_callback_call(item->wd->self, "moved", item->wd->reorder_item);
+        evas_object_smart_callback_call(item->wd->self, SIG_MOVED, item->wd->reorder_item);
         item->wd->reorder_item = NULL;
         elm_smart_scroller_hold_set(item->wd->scr, EINA_FALSE);
         elm_smart_scroller_bounce_allow_set(item->wd->scr, item->wd->h_bounce, item->wd->v_bounce);
-        edje_object_signal_emit(item->base.view, "elm,state,reorder_disabled", "elm");
+        edje_object_signal_emit(item->base.view, "elm,state,reorder,disabled", "elm");
      }
    if (item->wd->longpressed)
      {
@@ -1166,6 +1173,45 @@ _item_unrealize(Elm_Gengrid_Item *item)
    item->want_unrealize = EINA_FALSE;
 }
 
+static Eina_Bool
+_reorder_item_moving_effect_timer_cb(void *data)
+{
+   Elm_Gengrid_Item *item = data;
+   double time, t;
+   Evas_Coord dx, dy;
+
+   time = REORDER_EFFECT_TIME;
+   t = ((0.0 > (t = ecore_loop_time_get()-item->moving_effect_start_time)) ? 0.0 : t);
+   dx = ((item->tx - item->ox) / 10) * _elm_config->scale;
+   dy = ((item->ty - item->oy) / 10) * _elm_config->scale;
+
+   if (t <= time)
+     {
+        item->rx += (1 * sin((t / time) * (M_PI / 2)) * dx);
+        item->ry += (1 * sin((t / time) * (M_PI / 2)) * dy);
+     }
+   else
+     {
+        item->rx += dx;
+        item->ry += dy;
+     }
+
+   if ((((dx > 0) && (item->rx >= item->tx)) || ((dx <= 0) && (item->rx <= item->tx))) &&
+       (((dy > 0) && (item->ry >= item->ty)) || ((dy <= 0) && (item->ry <= item->ty))))
+     {
+        evas_object_move(item->base.view, item->tx, item->ty);
+        evas_object_resize(item->base.view, item->wd->item_width, item->wd->item_height);
+        item->moving = EINA_FALSE;
+        item->item_moving_effect_timer = NULL;
+        return ECORE_CALLBACK_CANCEL;
+     }
+
+   evas_object_move(item->base.view, item->rx, item->ry);
+   evas_object_resize(item->base.view, item->wd->item_width, item->wd->item_height);
+
+   return ECORE_CALLBACK_RENEW;
+}
+
 static void
 _item_place(Elm_Gengrid_Item *item,
             Evas_Coord        cx,
@@ -1251,6 +1297,13 @@ _item_place(Elm_Gengrid_Item *item,
           evas_object_smart_callback_call(item->wd->self, SIG_REALIZED, item);
         if ((item->wd->reorder_mode) && (item->wd->reorder_item))
           {
+             if (item->moving) return;
+
+             if (!item->wd->move_effect_enabled)
+               {
+                  item->ox = x;
+                  item->oy = y;
+               }
              if (item->wd->reorder_item == item)
                {
                   evas_object_move(item->base.view,
@@ -1261,6 +1314,26 @@ _item_place(Elm_Gengrid_Item *item,
                }
              else
                {
+                  if (item->wd->move_effect_enabled)
+                    {
+                       if ((item->ox != x) || (item->oy != y))
+                         {
+                            if (((item->wd->old_pan_x == item->wd->pan_x) && (item->wd->old_pan_y == item->wd->pan_y)) ||
+                                ((item->wd->old_pan_x != item->wd->pan_x) && !(item->ox - item->wd->pan_x + item->wd->old_pan_x == x)) ||
+                                ((item->wd->old_pan_y != item->wd->pan_y) && !(item->oy - item->wd->pan_y + item->wd->old_pan_y == y)))
+                              {
+                                 item->tx = x;
+                                 item->ty = y;
+                                 item->rx = item->ox;
+                                 item->ry = item->oy;
+                                 item->moving = EINA_TRUE;
+                                 item->moving_effect_start_time = ecore_loop_time_get();
+                                 item->item_moving_effect_timer = ecore_animator_add(_reorder_item_moving_effect_timer_cb, item);
+                                 return;
+                              }
+                         }
+                    }
+
                   if (ELM_RECTS_INTERSECT(item->wd->reorder_item_x, item->wd->reorder_item_y,
                                           item->wd->item_width, item->wd->item_height,
                                           x+(item->wd->item_width/2), y+(item->wd->item_height/2),
@@ -1291,7 +1364,7 @@ _item_place(Elm_Gengrid_Item *item,
                                                                        EINA_INLIST_GET(item));
 
                        item->wd->reorder_item_changed = EINA_TRUE;
-
+                       item->wd->move_effect_enabled = EINA_TRUE;
                        if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
                          item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
 
@@ -1569,6 +1642,16 @@ _pan_calculate(Evas_Object *obj)
              if (!cx) cy++;
           }
      }
+
+   if ((sd->wd->reorder_mode) && (sd->wd->reorder_item))
+     {
+        if (!sd->wd->reorder_item_changed)
+          {
+             sd->wd->old_pan_x = sd->wd->pan_x;
+             sd->wd->old_pan_y = sd->wd->pan_y;
+          }
+        sd->wd->move_effect_enabled = EINA_FALSE;
+     }
    evas_object_smart_callback_call(sd->wd->self, SIG_CHANGED, NULL);
 }
 
@@ -1699,6 +1782,8 @@ elm_gengrid_add(Evas_Object *parent)
    wd->self = obj;
    wd->align_x = 0.5;
    wd->align_y = 0.5;
+   wd->h_bounce = bounce;
+   wd->v_bounce = bounce;
    wd->no_select = EINA_FALSE;
 
    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);