New patch with the modifications suggested by Gustavo Barbieri.
On Wed, Oct 6, 2010 at 5:05 PM, Gustavo Sverzut Barbieri
<[email protected]> wrote:
> 2010/10/6 Tiago Falcão <[email protected]>:
>> I prefer two signals: "swipe,left" and "swipe,right". You can want register
>> both with the same callback.
>
> Ceolin asked me and I said "go with one, if required we do others
> later". Most software I've tested just listen for generic swipe action
> and the direction does not matter at all (if you think of left and
> right handed people this makes more sense).
>
Furthermore it is very easy to add these signals if necessary in the future.
>
>> I doesn't like listen and store 15 or N mouse_move events, i prefer listen
>> mouse_move only to validate the horizontal path and don't store all the
>> history.
>
> that's how we do for scroller kinetic detection. Keeping history we
> can avoid outliers (would need bit of algorithm changes).
>
>
>> We can calculate the swipe only in mouse_down and mouse_up, check the
>> horizontal distance and the time to know when emit or not the signal.
>>
>> So, we don't need one ecore.timer or the x/y array.
>>
>> But works fine, after anyone do some optimizations.
>
> yeah, the point is to have something usable and define an API. Maybe
> rasterman have some comments, but in my opinion it's ready to go in
> (after some changes I've already requested Ceolin and he should send
> soon).
>
> BR,
> --
> Gustavo Sverzut Barbieri
> http://profusion.mobi embedded systems
> --------------------------------------
> MSN: [email protected]
> Skype: gsbarbieri
> Mobile: +55 (19) 9225-2202
>
From 29bd136c8e03c333fd15a74eba25fd2d9b15d009 Mon Sep 17 00:00:00 2001
From: ceolin <[email protected]>
Date: Wed, 6 Oct 2010 10:24:21 -0300
Subject: [PATCH 1/2] swipe event
---
src/lib/elm_list.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 65 insertions(+), 0 deletions(-)
diff --git a/src/lib/elm_list.c b/src/lib/elm_list.c
index 4ee7728..17a2525 100644
--- a/src/lib/elm_list.c
+++ b/src/lib/elm_list.c
@@ -1,6 +1,8 @@
#include <Elementary.h>
#include "elm_priv.h"
+#define SWIPE_MOVES 12
+
/**
* @defgroup List List
*
@@ -20,6 +22,11 @@ struct _Widget_Data
Eina_Bool scr_minw : 1;
Eina_Bool scr_minh : 1;
int walking;
+ int movements;
+ struct {
+ Evas_Coord x, y;
+ } history[SWIPE_MOVES];
+ Eina_Bool swipe : 1;
Eina_Bool fix_pending : 1;
Eina_Bool on_hold : 1;
Eina_Bool multi : 1;
@@ -37,6 +44,7 @@ struct _Elm_List_Item
Evas_Object *icon, *end;
Evas_Smart_Cb func;
Ecore_Timer *long_timer;
+ Ecore_Timer *swipe_timer;
Eina_Bool deleted : 1;
Eina_Bool even : 1;
Eina_Bool is_even : 1;
@@ -102,6 +110,7 @@ _elm_list_item_free(Elm_List_Item *it)
eina_stringshare_del(it->label);
+ if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
if (it->long_timer) ecore_timer_del(it->long_timer);
if (it->icon) evas_object_del(it->icon);
if (it->end) evas_object_del(it->end);
@@ -593,6 +602,20 @@ _item_unselect(Elm_List_Item *it)
_elm_list_unwalk(wd);
}
+static Eina_Bool
+_swipe_cancel(void *data)
+{
+ Elm_List_Item *it = data;
+ Widget_Data *wd = elm_widget_data_get(it->base.widget);
+
+ if (!wd) return ECORE_CALLBACK_CANCEL;
+ ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ECORE_CALLBACK_CANCEL);
+ wd->swipe = EINA_FALSE;
+ memset(wd->history, 0, sizeof(wd->history[0]) * SWIPE_MOVES);
+ wd->movements = 0;
+ return ECORE_CALLBACK_RENEW;
+}
+
static void
_mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
{
@@ -615,6 +638,16 @@ _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void
if (!wd->wasselected)
_item_unselect(it);
}
+ if (wd->movements == SWIPE_MOVES) wd->swipe = EINA_TRUE;
+ else
+ {
+ wd->history[wd->movements].x = ev->cur.output.x;
+ wd->history[wd->movements].y = ev->cur.output.y;
+ if (abs((wd->history[wd->movements].x - wd->history[0].x)) > 40)
+ wd->swipe = EINA_TRUE;
+ else
+ wd->movements++;
+ }
}
}
@@ -633,6 +666,27 @@ _long_press(void *data)
}
static void
+_swipe(Elm_List_Item *it)
+{
+ int i, sum = 0;
+ Widget_Data *wd = elm_widget_data_get(it->base.widget);
+
+ ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
+ if (!wd) return;
+ if (!wd->swipe) return;
+ wd->swipe = EINA_FALSE;
+ for (i = 0; i < wd->movements; i++)
+ {
+ sum += wd->history[i].x;
+ if (abs(wd->history[0].y - wd->history[i].y) > 10) return;
+ }
+
+ sum /= wd->movements;
+ if (abs(sum - wd->history[0].x) <= 10) return;
+ evas_object_smart_callback_call(it->base.widget, "swipe", it);
+}
+
+static void
_mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
{
Elm_List_Item *it = data;
@@ -649,9 +703,14 @@ _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void
wd->longpressed = EINA_FALSE;
if (it->long_timer) ecore_timer_del(it->long_timer);
it->long_timer = ecore_timer_add(1.0, _long_press, it);
+ if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
+ it->swipe_timer = ecore_timer_add(0.4, _swipe_cancel, it);
/* Always call the callbacks last - the user may delete our context! */
if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
evas_object_smart_callback_call(it->base.widget, "clicked", it);
+ memset(wd->history, 0, sizeof(wd->history[0]) * SWIPE_MOVES);
+ wd->swipe = EINA_FALSE;
+ wd->movements = 0;
}
static void
@@ -672,9 +731,14 @@ _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *
ecore_timer_del(it->long_timer);
it->long_timer = NULL;
}
+ if (it->swipe_timer)
+ {
+ ecore_timer_del(it->swipe_timer);
+ it->swipe_timer = NULL;
+ }
if (wd->on_hold)
{
+ if (wd->swipe) _swipe(data);
wd->on_hold = EINA_FALSE;
return;
}
--
1.7.3.1
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.
Spend less time writing and rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel