Subject: [E-devel] [Patch] [Evas] Patch to provide information of
touched points
Hello,
I made a new patch to get information of current touched point instead
of Touch Event.
I added touch_points (Eina_List) to the Evas structure and it maintains touched points on the evas.
New touched point is added to the touch_points when we get Mouse_Down and Multi_Down,
touched point is updated when we get Mouse_Move and Mult_Move,
and touched point is removed when we get Mouse_Up and Multi_Up.
The each touch point has coordinate, id and state information as follows:
id - identifier. 0 for Mouse Event and device id for Multi Event. coordinate - (x, y) coordinate of point.
state - state of point. type is Evas_Touch_Point_State enum.
(EVAS_TOUCH_POINT_DOWN, EVAS_TOUCH_POINT_UP, EVAS_TOUCH_POINT_MOVE,
EVAS_TOUCH_POINT_STILL, EVAS_TOUCH_POINT_CANCEL)
There are 4 new APIs to get touch point's information as follows:
unsigned int evas_touch_point_list_count(Evas *e);
void evas_touch_point_list_nth_xy_get(Evas *e, unsigned int n, Evas_Coord *x, Evas_Coord *y);
int evas_touch_point_list_nth_id_get(Evas *e, unsigned int n);
Evas_Touch_Point_State evas_touch_point_list_nth_state_get(Evas *e, unsigned int n);
I added APIs to get each information instead of exposing whole
structure to make it easy to expand in the future as you mentioned in
the below e-mail :)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@64373
7cbeb6ba-43b4-40fd-8cce-
4c39aea84d33
} Evas_Event_Flags; /**< Flags for Events */
/**
+ * State of Evas_Coord_Touch_Point
+ */
+typedef enum _Evas_Touch_Point_State
+{
+ EVAS_TOUCH_POINT_DOWN, /**< Touch point is pressed down */
+ EVAS_TOUCH_POINT_UP, /**< Touch point is released */
+ EVAS_TOUCH_POINT_MOVE, /**< Touch point is moved */
+ EVAS_TOUCH_POINT_STILL, /**< Touch point is not moved after pressed */
+ EVAS_TOUCH_POINT_CANCEL /**< Touch point is calcelled */
+} Evas_Touch_Point_State;
+
+/**
* Flags for Font Hinting
* @ingroup Evas_Font_Group
*/
* @}
*/
+/**
+ * @defgroup Evas_Touch_Point_List Touch Point List Functions
+ *
+ * Functions to get information of touched points in the Evas.
+ *
+ * Evas maintains list of touched points on the canvas. Each point has
+ * its co-ordinates, id and state. You can get the number of touched
+ * points and information of each point using evas_touch_point_list
+ * functions.
+ *
+ * @ingroup Evas_Canvas
+ */
+
+/**
+ * @addtogroup Evas_Touch_Point_List
+ * @{
+ */
+
+/**
+ * Get the number of touched point in the evas.
+ *
+ * @param e The pointer to the Evas canvas.
+ * @return The number of touched point on the evas.
+ *
+ * New touched point is added to the list whenever touching the evas
+ * and point is removed whenever removing touched point from the evas.
+ *
+ * Example:
+ * @code
+ * extern Evas *evas;
+ * int count;
+ *
+ * count = evas_touch_point_list_count(evas);
+ * printf("The count of touch points: %i\n", count);
+ * @endcode
+ *
+ * @see evas_touch_point_list_nth_xy_get()
+ * @see evas_touch_point_list_nth_id_get()
+ * @see evas_touch_point_list_nth_state_get()
+ */
+EAPI unsigned int evas_touch_point_list_count(Evas *e) EINA_ARG_NONNULL(1);
+
+/**
+ * This function returns the nth touch point's co-ordinates.
+ *
+ * @param e The pointer to the Evas canvas.
+ * @param n The number of the touched point (0 being the first).
+ * @param x The pointer to a Evas_Coord to be filled in.
+ * @param y The pointer to a Evas_Coord to be filled in.
+ *
+ * Touch point's co-ordinates is updated whenever moving that point
+ * on the canvas.
+ *
+ * Example:
+ * @code
+ * extern Evas *evas;
+ * Evas_Coord x, y;
+ *
+ * if (evas_touch_point_list_count(evas))
+ * {
+ * evas_touch_point_nth_xy_get(evas, 0, &x, &y);
+ * printf("The first touch point's co-ordinate: (%i, %i)\n", x, y);
+ * }
+ * @endcode
+ *
+ * @see evas_touch_point_list_count()
+ * @see evas_touch_point_list_nth_id_get()
+ * @see evas_touch_point_list_nth_state_get()
+ */
+EAPI void evas_touch_point_list_nth_xy_get(Evas *e, unsigned int n, Evas_Coord *x, Evas_Coord *y) EINA_ARG_NONNULL(1);
+
+/**
+ * This function returns the @p id of nth touch point.
+ *
+ * @param e The pointer to the Evas canvas.
+ * @param n The number of the touched point (0 being the first).
+ * @return id of nth touch point, if the call succeeded, -1 otherwise.
+ *
+ * The point which comes from Mouse Event has @p id 0 and The point
+ * which comes from Multi Event has @p id that is same as Multi
+ * Event's device id.
+ *
+ * Example:
+ * @code
+ * extern Evas *evas;
+ * int id;
+ *
+ * if (evas_touch_point_list_count(evas))
+ * {
+ * id = evas_touch_point_nth_id_get(evas, 0);
+ * printf("The first touch point's id: %i\n", id);
+ * }
+ * @endcode
+ *
+ * @see evas_touch_point_list_count()
+ * @see evas_touch_point_list_nth_xy_get()
+ * @see evas_touch_point_list_nth_state_get()
+ */
+EAPI int evas_touch_point_list_nth_id_get(Evas *e, unsigned int n) EINA_ARG_NONNULL(1);
+
+/**
+ * This function returns the @p state of nth touch point.
+ *
+ * @param e The pointer to the Evas canvas.
+ * @param n The number of the touched point (0 being the first).
+ * @return @p state of nth touch point, if the call succeeded,
+ * EVAS_TOUCH_POINT_CANCEL otherwise.
+ *
+ * The point's @p state is EVAS_TOUCH_POINT_DOWN when pressed,
+ * EVAS_TOUCH_POINT_STILL when the point is not moved after pressed,
+ * EVAS_TOUCH_POINT_MOVE when moved at least once after pressed and
+ * EVAS_TOUCH_POINT_UP when released.
+ *
+ * Example:
+ * @code
+ * extern Evas *evas;
+ * Evas_Touch_Point_State state;
+ *
+ * if (evas_touch_point_list_count(evas))
+ * {
+ * state = evas_touch_point_nth_state_get(evas, 0);
+ * printf("The first touch point's state: %i\n", state);
+ * }
+ * @endcode
+ *
+ * @see evas_touch_point_list_count()
+ * @see evas_touch_point_list_nth_xy_get()
+ * @see evas_touch_point_list_nth_id_get()
+ */
+EAPI Evas_Touch_Point_State evas_touch_point_list_nth_state_get(Evas *e, unsigned int n) EINA_ARG_NONNULL(1);
+
+/**
+ * @}
+ */
+
#ifdef __cplusplus
}
#endif
evas_stack.c \
evas_async_events.c \
evas_stats.c \
+evas_touch_point.c \
evas_map.c \
evas_gl.c
ev.event_flags = EVAS_EVENT_FLAG_NONE;
_evas_walk(e);
+ /* append new touch point to the touch point list */
+ _evas_touch_point_append(e, 0, e->pointer.x, e->pointer.y);
/* If this is the first finger down, i.e no other fingers pressed,
* get a new event list, otherwise, keep the current grabbed list. */
if (e->pointer.mouse_grabbed == 0)
if (copy) eina_list_free(copy);
e->last_mouse_down_counter++;
_evas_post_event_callback_call(e);
+ /* update touch point's state to EVAS_TOUCH_POINT_STILL */
+ _evas_touch_point_update(e, 0, e->pointer.x, e->pointer.y, EVAS_TOUCH_POINT_STILL);
_evas_unwalk(e);
}
ev.event_flags = EVAS_EVENT_FLAG_NONE;
_evas_walk(e);
+ /* update released touch point */
+ _evas_touch_point_update(e, 0, e->pointer.x, e->pointer.y, EVAS_TOUCH_POINT_UP);
copy = evas_event_list_copy(e->pointer.object.in);
EINA_LIST_FOREACH(copy, l, obj)
{
if ((e->pointer.button & (1 << i)))
evas_event_feed_mouse_up(e, i + 1, 0, timestamp, data);
}
+ /* remove released touch point from the touch point list */
+ _evas_touch_point_remove(e, 0);
_evas_unwalk(e);
}
//// e->pointer.canvas_y = evas_coord_screen_y_to_world(e, y);
if ((!e->pointer.inside) && (e->pointer.mouse_grabbed == 0)) return;
_evas_walk(e);
+ /* update moved touch point */
+ if ((px != x) || (py != y))
+ _evas_touch_point_update(e, 0, e->pointer.x, e->pointer.y, EVAS_TOUCH_POINT_MOVE);
/* if our mouse button is grabbed to any objects */
if (e->pointer.mouse_grabbed > 0)
{
ev.event_flags = EVAS_EVENT_FLAG_NONE;
_evas_walk(e);
+ /* append new touch point to the touch point list */
+ _evas_touch_point_append(e, d, x, y);
copy = evas_event_list_copy(e->pointer.object.in);
EINA_LIST_FOREACH(copy, l, obj)
{
}
if (copy) eina_list_free(copy);
_evas_post_event_callback_call(e);
+ /* update touch point's state to EVAS_TOUCH_POINT_STILL */
+ _evas_touch_point_update(e, d, x, y, EVAS_TOUCH_POINT_STILL);
_evas_unwalk(e);
}
ev.event_flags = EVAS_EVENT_FLAG_NONE;
_evas_walk(e);
+ /* update released touch point */
+ _evas_touch_point_update(e, d, x, y, EVAS_TOUCH_POINT_UP);
copy = evas_event_list_copy(e->pointer.object.in);
EINA_LIST_FOREACH(copy, l, obj)
{
if (copy) copy = eina_list_free(copy);
if ((e->pointer.mouse_grabbed == 0) && !_post_up_handle(e, timestamp, data))
_evas_post_event_callback_call(e);
+ /* remove released touch point from the touch point list */
+ _evas_touch_point_remove(e, d);
_evas_unwalk(e);
}
if (!e->pointer.inside) return;
_evas_walk(e);
+ /* update moved touch point */
+ _evas_touch_point_update(e, d, x, y, EVAS_TOUCH_POINT_MOVE);
/* if our mouse button is grabbed to any objects */
if (e->pointer.mouse_grabbed > 0)
{
evas_free(Evas *e)
{
Eina_Rectangle *r;
+ Evas_Coord_Touch_Point *touch_point;
Evas_Layer *lay;
int i;
int del;
eina_array_flush(&e->calculate_objects);
eina_array_flush(&e->clip_changes);
+ EINA_LIST_FREE(e->touch_points, touch_point)
+ free(touch_point);
+
e->magic = 0;
free(e);
}
--- /dev/null
+#include "evas_common.h"
+#include "evas_private.h"
+
+void
+_evas_touch_point_append(Evas *e, int id, Evas_Coord x, Evas_Coord y)
+{
+ Evas_Coord_Touch_Point *point;
+
+ /* create new Evas_Coord_Touch_Point */
+ point = (Evas_Coord_Touch_Point *)calloc(1, sizeof(Evas_Coord_Touch_Point));
+ point->x = x;
+ point->y = y;
+ point->id = id;
+ point->state = EVAS_TOUCH_POINT_DOWN;
+ e->touch_points = eina_list_append(e->touch_points, point);
+}
+
+void
+_evas_touch_point_update(Evas *e, int id, Evas_Coord x, Evas_Coord y, Evas_Touch_Point_State state)
+{
+ Eina_List *l;
+ Evas_Coord_Touch_Point *point = NULL;
+
+ EINA_LIST_FOREACH(e->touch_points, l, point)
+ {
+ if (point->id == id)
+ {
+ point->x = x;
+ point->y = y;
+ point->state = state;
+ break;
+ }
+ }
+}
+
+void
+_evas_touch_point_remove(Evas *e, int id)
+{
+ Eina_List *l;
+ Evas_Coord_Touch_Point *point = NULL;
+
+ EINA_LIST_FOREACH(e->touch_points, l, point)
+ {
+ if (point->id == id)
+ {
+ e->touch_points = eina_list_remove(e->touch_points, point);
+ free(point);
+ break;
+ }
+ }
+}
+
+EAPI unsigned int
+evas_touch_point_list_count(Evas *e)
+{
+ MAGIC_CHECK(e, Evas, MAGIC_EVAS);
+ return 0;
+ MAGIC_CHECK_END();
+ return eina_list_count(e->touch_points);
+}
+
+EAPI void
+evas_touch_point_list_nth_xy_get(Evas *e, unsigned int n, Evas_Coord *x, Evas_Coord *y)
+{
+ Evas_Coord_Touch_Point *point = NULL;
+
+ MAGIC_CHECK(e, Evas, MAGIC_EVAS);
+ if (x) *x = 0;
+ if (y) *y = 0;
+ return;
+ MAGIC_CHECK_END();
+
+ point = (Evas_Coord_Touch_Point *)eina_list_nth(e->touch_points, n);
+ if (!point)
+ {
+ if (x) *x = 0;
+ if (y) *y = 0;
+ return;
+ }
+ if (x) *x = point->x;
+ if (y) *y = point->y;
+}
+
+EAPI int
+evas_touch_point_list_nth_id_get(Evas *e, unsigned int n)
+{
+ Evas_Coord_Touch_Point *point = NULL;
+
+ MAGIC_CHECK(e, Evas, MAGIC_EVAS);
+ return -1;
+ MAGIC_CHECK_END();
+
+ point = (Evas_Coord_Touch_Point *)eina_list_nth(e->touch_points, n);
+ if (!point) return -1;
+ return point->id;
+}
+
+EAPI Evas_Touch_Point_State
+evas_touch_point_list_nth_state_get(Evas *e, unsigned int n)
+{
+ Evas_Coord_Touch_Point *point = NULL;
+
+ MAGIC_CHECK(e, Evas, MAGIC_EVAS);
+ return EVAS_TOUCH_POINT_CANCEL;
+ MAGIC_CHECK_END();
+
+ point = (Evas_Coord_Touch_Point *)eina_list_nth(e->touch_points, n);
+ if (!point) return EVAS_TOUCH_POINT_CANCEL;
+ return point->state;
+}
typedef struct _Evas_Map_Point Evas_Map_Point;
typedef struct _Evas_Smart_Cb_Description_Array Evas_Smart_Cb_Description_Array;
typedef struct _Evas_Post_Callback Evas_Post_Callback;
+typedef struct _Evas_Coord_Touch_Point Evas_Coord_Touch_Point;
enum _Evas_Font_Style
{
(o)->prev.key = NULL; \
}
+struct _Evas_Coord_Touch_Point
+{
+ Evas_Coord x, y; // point's x, y position
+ int id; // id in order to distinguish each point
+ Evas_Touch_Point_State state;
+};
+
struct _Evas_Key_Grab
{
char *keyname;
unsigned char invalidate : 1;
unsigned char cleanup : 1;
unsigned char focus : 1;
+
+ Eina_List *touch_points;
};
struct _Evas_Layer
Eina_List *evas_module_engine_list(void);
+/* for updating touch point list */
+void _evas_touch_point_append(Evas *e, int id, Evas_Coord x, Evas_Coord y);
+void _evas_touch_point_update(Evas *e, int id, Evas_Coord x, Evas_Coord y, Evas_Touch_Point_State state);
+void _evas_touch_point_remove(Evas *e, int id);
+
/****************************************************************************/
/*****************************************/
/********************/