summaryrefslogtreecommitdiff
path: root/legacy/ephysics
diff options
context:
space:
mode:
authorLeandro Dorileo <dorileo@profusion.mobi>2012-10-09 20:00:03 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-10-09 20:00:03 +0000
commit179efa1d667de609626e95003dd376763f3f8fe2 (patch)
treeb018944b48c3525ea39e723e6d9bce2f094cf51c /legacy/ephysics
parent6f9e9a67f71981cf0945f0cabe0950af9dad2862 (diff)
EPhysics: soft body members stacking
Using evas stacking for soft body slices members. Patch by: Leandro Dorileo <dorileo@profusion.mobi> SVN revision: 77677
Diffstat (limited to 'legacy/ephysics')
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp41
1 files changed, 37 insertions, 4 deletions
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index 3e45a5cd51..d16f9d7954 100644
--- a/legacy/ephysics/src/lib/ephysics_body.cpp
+++ b/legacy/ephysics/src/lib/ephysics_body.cpp
@@ -36,6 +36,7 @@ typedef struct _EPhysics_Body_Soft_Body_Slice
36{ 36{
37 int index; 37 int index;
38 Evas_Object *evas_obj; 38 Evas_Object *evas_obj;
39 int stacking;
39} EPhysics_Body_Soft_Body_Slice; 40} EPhysics_Body_Soft_Body_Slice;
40 41
41static const Evas_Smart_Cb_Description _smart_callbacks[] = 42static const Evas_Smart_Cb_Description _smart_callbacks[] =
@@ -62,6 +63,23 @@ EVAS_SMART_SUBCLASS_NEW(SMART_CLASS_NAME,
62 Evas_Smart_Class, evas_object_smart_clipped_class_get, 63 Evas_Smart_Class, evas_object_smart_clipped_class_get,
63 _smart_callbacks); 64 _smart_callbacks);
64 65
66static int
67_ephysics_body_soft_body_slice_stacking_sort_cb(const void *d1, const void *d2)
68{
69 const EPhysics_Body_Soft_Body_Slice *slice1, *slice2;
70
71 slice1 = (const EPhysics_Body_Soft_Body_Slice *)d1;
72 slice2 = (const EPhysics_Body_Soft_Body_Slice *)d2;
73
74 if (!slice1) return 1;
75 if (!slice2) return -1;
76
77 if (slice1->stacking < slice2->stacking) return -1;
78 if (slice2->stacking > slice2->stacking) return 1;
79
80 return 0;
81}
82
65static void 83static void
66_ephysics_body_soft_body_slices_apply(Evas_Object *obj) 84_ephysics_body_soft_body_slices_apply(Evas_Object *obj)
67{ 85{
@@ -75,7 +93,7 @@ _ephysics_body_soft_body_slices_apply(Evas_Object *obj)
75 EPhysics_Body_Soft_Body_Slice *slice; 93 EPhysics_Body_Soft_Body_Slice *slice;
76 EPhysics_Body_Soft_Body_Smart_Data *smart_data; 94 EPhysics_Body_Soft_Body_Smart_Data *smart_data;
77 EPhysics_Body *body; 95 EPhysics_Body *body;
78 short z_factor; 96 Evas_Object *prev_obj = NULL;
79 97
80 EPHYSICS_BODY_SOFT_BODY_SMART_DATA_GET(obj, smart_data); 98 EPHYSICS_BODY_SOFT_BODY_SMART_DATA_GET(obj, smart_data);
81 body = smart_data->body; 99 body = smart_data->body;
@@ -103,10 +121,8 @@ _ephysics_body_soft_body_slices_apply(Evas_Object *obj)
103 z1 = p1.z() * rate; 121 z1 = p1.z() * rate;
104 z2 = p2.z() * rate; 122 z2 = p2.z() * rate;
105 123
106 z_factor = p0.z() + p1.z() + p2.z(); 124 slice->stacking = p0.z() + p1.z() + p2.z();
107 z_factor = (z_factor < 0) ? -z_factor : z_factor;
108 125
109 evas_object_layer_set(slice->evas_obj, z_factor);
110 evas_object_map_enable_set(slice->evas_obj, EINA_FALSE); 126 evas_object_map_enable_set(slice->evas_obj, EINA_FALSE);
111 map = (Evas_Map *)evas_object_map_get((const Evas_Object *) 127 map = (Evas_Map *)evas_object_map_get((const Evas_Object *)
112 slice->evas_obj); 128 slice->evas_obj);
@@ -122,6 +138,22 @@ _ephysics_body_soft_body_slices_apply(Evas_Object *obj)
122 evas_object_map_enable_set(slice->evas_obj, EINA_TRUE); 138 evas_object_map_enable_set(slice->evas_obj, EINA_TRUE);
123 evas_object_show(slice->evas_obj); 139 evas_object_show(slice->evas_obj);
124 } 140 }
141
142 smart_data->slices = eina_list_sort(smart_data->slices,
143 eina_list_count(smart_data->slices),
144 _ephysics_body_soft_body_slice_stacking_sort_cb);
145
146 EINA_LIST_FOREACH(smart_data->slices, l, data)
147 {
148 slice = (EPhysics_Body_Soft_Body_Slice *)data;
149
150 if (!prev_obj)
151 evas_object_lower(slice->evas_obj);
152 else
153 evas_object_stack_above(slice->evas_obj, prev_obj);
154
155 prev_obj = slice->evas_obj;
156 }
125} 157}
126 158
127static EPhysics_Body_Soft_Body_Slice * 159static EPhysics_Body_Soft_Body_Slice *
@@ -209,6 +241,7 @@ _ephysics_body_soft_body_slices_init(EPhysics_Body *body, Evas_Object *obj)
209 evas_map_free(map); 241 evas_map_free(map);
210 242
211 smart_data->slices = eina_list_append(smart_data->slices, slice); 243 smart_data->slices = eina_list_append(smart_data->slices, slice);
244 evas_object_smart_member_add(slice->evas_obj, obj);
212 } 245 }
213 246
214 return EINA_TRUE; 247 return EINA_TRUE;