aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2013-07-03 10:46:44 +0200
committerLaurent Ghigonis <laurent@p1sec.com>2013-07-03 10:46:44 +0200
commitb2f455874b4f7bbaa811994c25441299f9952e73 (patch)
treeb377bb6d78881a132a67f4e2d380ffc6a4bd3992
parentblobs time should be floating point (diff)
downloadegraph-b2f455874b4f7bbaa811994c25441299f9952e73.tar.gz
targettrack now handling deletion of origin / targets
-rw-r--r--targettrack.c106
-rw-r--r--targettrack.h12
2 files changed, 87 insertions, 31 deletions
diff --git a/targettrack.c b/targettrack.c
index 9acfee8..ddd49c4 100644
--- a/targettrack.c
+++ b/targettrack.c
@@ -5,11 +5,9 @@
static void _targettrack_next(Evas_Object *origin, Egraph_Targettrack *track);
static void _targettrack_free(Egraph_Targettrack *track);
+static void _update_coords(Egraph_Targettrack *track);
static Eina_Bool _cb_targettrack(void *data, double pos);
-
-// XXX evas_callback free on targets
-// if target: move to next next_targets
-// if in next_targets: remove from next_targets
+static void _cb_obj_free(void *data, Evas *e, Evas_Object *obj, void *event_info);
Egraph_Targettrack *
egraph_targettrack(Evas_Object *obj, Evas_Object *origin, Evas_Object *target, Ecore_Pos_Map map, double total_time, Egraph_Targettrack_End_Cb cb_end)
@@ -24,6 +22,7 @@ Egraph_Targettrack *
egraph_targettrack_multi(Evas_Object *obj, Evas_Object *origin, Eina_List *targets, Ecore_Pos_Map map, double total_time, Egraph_Targettrack_End_Cb cb_end)
{
Egraph_Targettrack *track;
+ Eina_List *l;
track = calloc(1, sizeof(Egraph_Targettrack));
if (!track)
@@ -34,6 +33,13 @@ egraph_targettrack_multi(Evas_Object *obj, Evas_Object *origin, Eina_List *targe
evas_object_geometry_get(track->obj, NULL, NULL, &track->obj_w, &track->obj_h);
track->next_targets = targets;
track->cb_end = cb_end;
+
+ evas_object_event_callback_add(origin, EVAS_CALLBACK_FREE,
+ _cb_obj_free, track);
+ EINA_LIST_FOREACH(targets, l, obj)
+ evas_object_event_callback_add(obj, EVAS_CALLBACK_FREE,
+ _cb_obj_free, track);
+
_targettrack_next(origin, track);
return track;
}
@@ -44,59 +50,107 @@ _targettrack_next(Evas_Object *origin, Egraph_Targettrack *track)
track->origin = origin;
track->target = eina_list_nth(track->next_targets, 0);
track->next_targets = eina_list_remove(track->next_targets, track->target);
+ _update_coords(track);
ecore_animator_timeline_add(track->total_time, _cb_targettrack, track);
}
static void
_targettrack_free(Egraph_Targettrack *track)
{
+ Eina_List *l;
+ Evas_Object *t;
+
+ printf("_targettrack_free\n");
+ evas_object_event_callback_del_full(track->origin, EVAS_CALLBACK_FREE,
+ _cb_obj_free, track);
+ evas_object_event_callback_del_full(track->target, EVAS_CALLBACK_FREE,
+ _cb_obj_free, track);
+ EINA_LIST_FOREACH(track->next_targets, l, t)
+ evas_object_event_callback_del_full(t, EVAS_CALLBACK_FREE,
+ _cb_obj_free, track);
eina_list_free(track->next_targets);
free(track);
}
+static void
+_update_coords(Egraph_Targettrack *track)
+{
+ int ox, oy, ow, oh, tx, ty, tw, th;
+
+ if (track->origin) {
+ evas_object_geometry_get(track->origin, &ox, &oy, &ow, &oh);
+ track->origin_x = ox + ow / 2;
+ track->origin_y = oy + oh / 2;
+ }
+ if (track->target) {
+ evas_object_geometry_get(track->target, &tx, &ty, &tw, &th);
+ track->target_x = tx + tw / 2;
+ track->target_y = ty + th / 2;
+ }
+}
+
static Eina_Bool
_cb_targettrack(void *data, double pos)
{
Egraph_Targettrack *track;
- Evas_Coord x, y, ox, oy, ow, oh, tx, ty, tw, th;
+ Evas_Coord x, y;
double pct;
+ printf("_cb_targettrack pos %f\n", pos);
track = data;
+ _update_coords(track);
- evas_object_geometry_get(track->origin, &ox, &oy, &ow, &oh);
- ox += ow / 2;
- oy += oh / 2;
- evas_object_geometry_get(track->target, &tx, &ty, &tw, &th);
- tx += tw / 2;
- ty += th / 2;
-
- // XXX placement on origin->target line
pct = ecore_animator_pos_map(pos, track->map, 0.0, 0.0);
- x = lround(pct * (double)(tx - ox)) + ox;
+ x = lround(pct * (double)(track->target_x - track->origin_x)) + track->origin_x;
x -= track->obj_w / 2;
- y = lround(pct * (double)(ty - oy)) + oy;
+ y = lround(pct * (double)(track->target_y - track->origin_y)) + track->origin_y;
y -= track->obj_h / 2;
evas_object_move(track->obj, x, y);
- // total_x = track->done_x + (tx - ox);
- // x = lround(pct * (double)total_x) - ox;
- // total_y = track->done_y + (ty - oy);
- // y = lround(pct * (double)total_y) - oy;
- // evas_object_move(track->obj, ox + x, oy + y);
-
- // track->done_x += x;
- // track->done_y += y;
-
if (pos != 1.0)
return ECORE_CALLBACK_RENEW;
- /* this is the end */
+ /* we reached target */
if (eina_list_count(track->next_targets) > 0) {
+ evas_object_event_callback_del_full(track->origin, EVAS_CALLBACK_FREE,
+ _cb_obj_free, track);
_targettrack_next(track->target, track);
} else {
track->cb_end(track->obj);
_targettrack_free(track);
}
- return ECORE_CALLBACK_RENEW;
+ return ECORE_CALLBACK_CANCEL;
+}
+
+/*
+ * evas_callback free on targets / orig
+ * if orig: use last orig coords
+ * if target: move to next next_targets, use last target coords as orig
+ * if in next_targets: remove from next_targets
+ */
+static void
+_cb_obj_free(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ Egraph_Targettrack *track;
+ Eina_List *l, *l_next;
+ Evas_Object *t;
+
+ printf("_cb_obj_free\n");
+ track = data;
+ if (obj == track->origin) {
+ printf(" origin\n");
+ track->origin = NULL;
+ }
+ if (obj == track->target) {
+ printf(" target\n");
+ track->target = NULL;
+ }
+ EINA_LIST_FOREACH_SAFE(track->next_targets, l, l_next, t) {
+ if (obj == t) {
+ track->next_targets = eina_list_remove(track->next_targets, t);
+ printf(" next_target\n");
+ }
+ }
}
+
diff --git a/targettrack.h b/targettrack.h
index ba67d99..c25c988 100644
--- a/targettrack.h
+++ b/targettrack.h
@@ -8,11 +8,13 @@ typedef struct Egraph_Targettrack Egraph_Targettrack;
struct Egraph_Targettrack {
double total_time;
Ecore_Pos_Map map;
- Evas_Object *obj;
- Evas_Coord obj_w, obj_h;
- Evas_Object *origin;
- Evas_Object *target;
- Eina_List *next_targets;
+ Evas_Object *obj;
+ Evas_Coord obj_w, obj_h;
+ Evas_Object *origin;
+ Evas_Coord origin_x, origin_y;
+ Evas_Object *target;
+ Evas_Coord target_x, target_y;
+ Eina_List *next_targets;
Egraph_Targettrack_End_Cb cb_end;
};