From ecd61b29afe35de33bf6430ac8277435c2713a10 Mon Sep 17 00:00:00 2001 From: Leandro Dorileo Date: Fri, 23 Nov 2012 21:51:44 +0000 Subject: [PATCH] EPhysics: add api to get the slice index based on its evas object Patch by: Leandro Dorileo SVN revision: 79604 --- legacy/ephysics/src/lib/EPhysics.h | 18 +++++++ legacy/ephysics/src/lib/ephysics_body.cpp | 65 +++++++++++++++++------ 2 files changed, 66 insertions(+), 17 deletions(-) diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h index 2f3a0bcaae..9172ab00e1 100644 --- a/legacy/ephysics/src/lib/EPhysics.h +++ b/legacy/ephysics/src/lib/EPhysics.h @@ -2386,6 +2386,24 @@ EAPI void ephysics_body_soft_body_dragging_unset(EPhysics_Body *body); */ EAPI int ephysics_body_soft_body_triangle_index_get(EPhysics_Body *body, Evas_Coord x, Evas_Coord y); +/** + * @brief + * Get the slice index of a soft body based on its slice`s Evas Object. + * + * Registering a mouse event callback on an associated evas object one can get + * the clicked slice evas object. With that pointer the user can get the slice + * index based on its related evas object. + * + * @param body The body to get the slice index from. + * @param slice The slice evas object. + * @return The slice index on success, -1 otherwise. + * + * @see ephysics_body_soft_body_triangle_index_get(). + * + * @ingroup EPhysics_Body + */ +EAPI int ephysics_body_soft_body_slice_index_get(EPhysics_Body *body, Evas_Object *slice); + /** * @brief * Add a soft ellipsoid. diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp index 8085df9446..6119d4fa25 100644 --- a/legacy/ephysics/src/lib/ephysics_body.cpp +++ b/legacy/ephysics/src/lib/ephysics_body.cpp @@ -205,6 +205,54 @@ _ephysics_body_soft_body_slice_new(EPhysics_Body *body, double delta, double max return slice; } +static Eina_List * +_ephysics_body_soft_body_slices_get(EPhysics_Body *body) +{ + Eina_List *l, *slices_list, *slices = NULL; + void *ldata, *slice_data; + EPhysics_Body_Face_Slice *face_slice; + + EINA_LIST_FOREACH(body->faces_slices, l, ldata) + { + face_slice = (EPhysics_Body_Face_Slice *)ldata; + EINA_LIST_FOREACH(face_slice->slices, slices_list, slice_data) + slices = eina_list_append(slices, slice_data); + } + + return slices; +} + +EAPI int +ephysics_body_soft_body_slice_index_get(EPhysics_Body *body, Evas_Object *slice) +{ + Eina_List *slices; + void *ldata; + EPhysics_Body_Soft_Body_Slice *slice_data; + + if (!body) + { + ERR("Can't get soft body slice index, body is null."); + return -1; + } + + if (body->type == EPHYSICS_BODY_TYPE_RIGID) + { + ERR("Can't get soft body slice index, operation not allowed for rigid" + " bodies."); + return -1; + } + + slices = _ephysics_body_soft_body_slices_get(body); + EINA_LIST_FREE(slices, ldata) + { + slice_data = (EPhysics_Body_Soft_Body_Slice *)ldata; + if (slice_data->evas_obj == slice) + return slice_data->index; + } + + return -1; +} + static void _ephysics_body_soft_body_slices_init(EPhysics_Body *body, Evas_Object *obj, Eina_List *slices) { @@ -333,23 +381,6 @@ _ephysics_body_evas_stacking_new(Evas_Object *obj, float index) return stacking; } -static Eina_List * -_ephysics_body_soft_body_slices_get(EPhysics_Body *body) -{ - Eina_List *l, *slices_list, *slices = NULL; - void *ldata, *slice_data; - EPhysics_Body_Face_Slice *face_slice; - - EINA_LIST_FOREACH(body->faces_slices, l, ldata) - { - face_slice = (EPhysics_Body_Face_Slice *)ldata; - EINA_LIST_FOREACH(face_slice->slices, slices_list, slice_data) - slices = eina_list_append(slices, slice_data); - } - - return slices; -} - void ephysics_body_evas_objects_restack(EPhysics_World *world) {