summaryrefslogtreecommitdiff
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
parent95618d431c0adec7fd33f960fef6262300d38630 (diff)
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 @@
5 5
6static void _targettrack_next(Evas_Object *origin, Egraph_Targettrack *track); 6static void _targettrack_next(Evas_Object *origin, Egraph_Targettrack *track);
7static void _targettrack_free(Egraph_Targettrack *track); 7static void _targettrack_free(Egraph_Targettrack *track);
8static void _update_coords(Egraph_Targettrack *track);
8static Eina_Bool _cb_targettrack(void *data, double pos); 9static Eina_Bool _cb_targettrack(void *data, double pos);
9 10static void _cb_obj_free(void *data, Evas *e, Evas_Object *obj, void *event_info);
10// XXX evas_callback free on targets
11// if target: move to next next_targets
12// if in next_targets: remove from next_targets
13 11
14Egraph_Targettrack * 12Egraph_Targettrack *
15egraph_targettrack(Evas_Object *obj, Evas_Object *origin, Evas_Object *target, Ecore_Pos_Map map, double total_time, Egraph_Targettrack_End_Cb cb_end) 13egraph_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 *
24egraph_targettrack_multi(Evas_Object *obj, Evas_Object *origin, Eina_List *targets, Ecore_Pos_Map map, double total_time, Egraph_Targettrack_End_Cb cb_end) 22egraph_targettrack_multi(Evas_Object *obj, Evas_Object *origin, Eina_List *targets, Ecore_Pos_Map map, double total_time, Egraph_Targettrack_End_Cb cb_end)
25{ 23{
26 Egraph_Targettrack *track; 24 Egraph_Targettrack *track;
25 Eina_List *l;
27 26
28 track = calloc(1, sizeof(Egraph_Targettrack)); 27 track = calloc(1, sizeof(Egraph_Targettrack));
29 if (!track) 28 if (!track)
@@ -34,6 +33,13 @@ egraph_targettrack_multi(Evas_Object *obj, Evas_Object *origin, Eina_List *targe
34 evas_object_geometry_get(track->obj, NULL, NULL, &track->obj_w, &track->obj_h); 33 evas_object_geometry_get(track->obj, NULL, NULL, &track->obj_w, &track->obj_h);
35 track->next_targets = targets; 34 track->next_targets = targets;
36 track->cb_end = cb_end; 35 track->cb_end = cb_end;
36
37 evas_object_event_callback_add(origin, EVAS_CALLBACK_FREE,
38 _cb_obj_free, track);
39 EINA_LIST_FOREACH(targets, l, obj)
40 evas_object_event_callback_add(obj, EVAS_CALLBACK_FREE,
41 _cb_obj_free, track);
42
37 _targettrack_next(origin, track); 43 _targettrack_next(origin, track);
38 return track; 44 return track;
39} 45}
@@ -44,59 +50,107 @@ _targettrack_next(Evas_Object *origin, Egraph_Targettrack *track)
44 track->origin = origin; 50 track->origin = origin;
45 track->target = eina_list_nth(track->next_targets, 0); 51 track->target = eina_list_nth(track->next_targets, 0);
46 track->next_targets = eina_list_remove(track->next_targets, track->target); 52 track->next_targets = eina_list_remove(track->next_targets, track->target);
53 _update_coords(track);
47 ecore_animator_timeline_add(track->total_time, _cb_targettrack, track); 54 ecore_animator_timeline_add(track->total_time, _cb_targettrack, track);
48} 55}
49 56
50static void 57static void
51_targettrack_free(Egraph_Targettrack *track) 58_targettrack_free(Egraph_Targettrack *track)
52{ 59{
60 Eina_List *l;
61 Evas_Object *t;
62
63 printf("_targettrack_free\n");
64 evas_object_event_callback_del_full(track->origin, EVAS_CALLBACK_FREE,
65 _cb_obj_free, track);
66 evas_object_event_callback_del_full(track->target, EVAS_CALLBACK_FREE,
67 _cb_obj_free, track);
68 EINA_LIST_FOREACH(track->next_targets, l, t)
69 evas_object_event_callback_del_full(t, EVAS_CALLBACK_FREE,
70 _cb_obj_free, track);
53 eina_list_free(track->next_targets); 71 eina_list_free(track->next_targets);
54 free(track); 72 free(track);
55} 73}
56 74
75static void
76_update_coords(Egraph_Targettrack *track)
77{
78 int ox, oy, ow, oh, tx, ty, tw, th;
79
80 if (track->origin) {
81 evas_object_geometry_get(track->origin, &ox, &oy, &ow, &oh);
82 track->origin_x = ox + ow / 2;
83 track->origin_y = oy + oh / 2;
84 }
85 if (track->target) {
86 evas_object_geometry_get(track->target, &tx, &ty, &tw, &th);
87 track->target_x = tx + tw / 2;
88 track->target_y = ty + th / 2;
89 }
90}
91
57static Eina_Bool 92static Eina_Bool
58_cb_targettrack(void *data, double pos) 93_cb_targettrack(void *data, double pos)
59{ 94{
60 Egraph_Targettrack *track; 95 Egraph_Targettrack *track;
61 Evas_Coord x, y, ox, oy, ow, oh, tx, ty, tw, th; 96 Evas_Coord x, y;
62 double pct; 97 double pct;
63 98
99 printf("_cb_targettrack pos %f\n", pos);
64 track = data; 100 track = data;
101 _update_coords(track);
65 102
66 evas_object_geometry_get(track->origin, &ox, &oy, &ow, &oh);
67 ox += ow / 2;
68 oy += oh / 2;
69 evas_object_geometry_get(track->target, &tx, &ty, &tw, &th);
70 tx += tw / 2;
71 ty += th / 2;
72
73 // XXX placement on origin->target line
74 pct = ecore_animator_pos_map(pos, track->map, 0.0, 0.0); 103 pct = ecore_animator_pos_map(pos, track->map, 0.0, 0.0);
75 x = lround(pct * (double)(tx - ox)) + ox; 104 x = lround(pct * (double)(track->target_x - track->origin_x)) + track->origin_x;
76 x -= track->obj_w / 2; 105 x -= track->obj_w / 2;
77 y = lround(pct * (double)(ty - oy)) + oy; 106 y = lround(pct * (double)(track->target_y - track->origin_y)) + track->origin_y;
78 y -= track->obj_h / 2; 107 y -= track->obj_h / 2;
79 evas_object_move(track->obj, x, y); 108 evas_object_move(track->obj, x, y);
80 109
81 // total_x = track->done_x + (tx - ox);
82 // x = lround(pct * (double)total_x) - ox;
83 // total_y = track->done_y + (ty - oy);
84 // y = lround(pct * (double)total_y) - oy;
85 // evas_object_move(track->obj, ox + x, oy + y);
86
87 // track->done_x += x;
88 // track->done_y += y;
89
90 if (pos != 1.0) 110 if (pos != 1.0)
91 return ECORE_CALLBACK_RENEW; 111 return ECORE_CALLBACK_RENEW;
92 112
93 /* this is the end */ 113 /* we reached target */
94 if (eina_list_count(track->next_targets) > 0) { 114 if (eina_list_count(track->next_targets) > 0) {
115 evas_object_event_callback_del_full(track->origin, EVAS_CALLBACK_FREE,
116 _cb_obj_free, track);
95 _targettrack_next(track->target, track); 117 _targettrack_next(track->target, track);
96 } else { 118 } else {
97 track->cb_end(track->obj); 119 track->cb_end(track->obj);
98 _targettrack_free(track); 120 _targettrack_free(track);
99 } 121 }
100 122
101 return ECORE_CALLBACK_RENEW; 123 return ECORE_CALLBACK_CANCEL;
124}
125
126/*
127 * evas_callback free on targets / orig
128 * if orig: use last orig coords
129 * if target: move to next next_targets, use last target coords as orig
130 * if in next_targets: remove from next_targets
131 */
132static void
133_cb_obj_free(void *data, Evas *e, Evas_Object *obj, void *event_info)
134{
135 Egraph_Targettrack *track;
136 Eina_List *l, *l_next;
137 Evas_Object *t;
138
139 printf("_cb_obj_free\n");
140 track = data;
141 if (obj == track->origin) {
142 printf(" origin\n");
143 track->origin = NULL;
144 }
145 if (obj == track->target) {
146 printf(" target\n");
147 track->target = NULL;
148 }
149 EINA_LIST_FOREACH_SAFE(track->next_targets, l, l_next, t) {
150 if (obj == t) {
151 track->next_targets = eina_list_remove(track->next_targets, t);
152 printf(" next_target\n");
153 }
154 }
102} 155}
156
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;
8struct Egraph_Targettrack { 8struct Egraph_Targettrack {
9 double total_time; 9 double total_time;
10 Ecore_Pos_Map map; 10 Ecore_Pos_Map map;
11 Evas_Object *obj; 11 Evas_Object *obj;
12 Evas_Coord obj_w, obj_h; 12 Evas_Coord obj_w, obj_h;
13 Evas_Object *origin; 13 Evas_Object *origin;
14 Evas_Object *target; 14 Evas_Coord origin_x, origin_y;
15 Eina_List *next_targets; 15 Evas_Object *target;
16 Evas_Coord target_x, target_y;
17 Eina_List *next_targets;
16 Egraph_Targettrack_End_Cb cb_end; 18 Egraph_Targettrack_End_Cb cb_end;
17}; 19};
18 20