edje: keep real part geometry updated
authorBruno Dilly <bdilly@profusion.mobi>
Wed, 5 Dec 2012 19:30:00 +0000 (19:30 +0000)
committerBruno Dilly <bdilly@profusion.mobi>
Wed, 5 Dec 2012 19:30:00 +0000 (19:30 +0000)
Using a callback for body and world update events for that.
It will make it possible to set parts to be relative
to parts that have a physics body.

SVN revision: 80277

legacy/edje/src/examples/physics_complex.edc
legacy/edje/src/lib/edje_calc.c
legacy/edje/src/lib/edje_load.c

index 8ea5670..ed7be97 100644 (file)
@@ -48,6 +48,23 @@ collections {
          }
 
          part {
+            name: "box_shadow";
+            type: RECT;
+            description {
+               state: "default" 0.0;
+               color: 0 0 0 120;
+               rel1 {
+                  to_y: "red_box";
+                  relative: 0.9 0.1;
+               }
+               rel2 {
+                  to_y: "red_box";
+                  relative: 1 0.9;
+               }
+            }
+         }
+
+         part {
             name: "blue_circle";
             type: IMAGE;
             physics_body: RIGID_CIRCLE;
index a26dc62..bb18de9 100644 (file)
@@ -2456,6 +2456,10 @@ _edje_physics_body_props_update(Edje_Real_Part *ep, Edje_Calc_Params *pf, Eina_B
                                         NULL, NULL, NULL);
              ephysics_body_move(ep->body, ep->edje->x + pf->x,
                                 ep->edje->y + pf->y, z);
+             ep->x = pf->x;
+             ep->y = pf->y;
+             ep->w = pf->w;
+             ep->h = pf->h;
           }
         ephysics_body_mass_set(ep->body, pf->physics.mass);
      }
@@ -2465,6 +2469,16 @@ _edje_physics_body_props_update(Edje_Real_Part *ep, Edje_Calc_Params *pf, Eina_B
 }
 
 static void
+_edje_physics_body_update_cb(void *data, EPhysics_Body *body, void *event_info __UNUSED__)
+{
+   Edje_Real_Part *rp = data;
+   ephysics_body_geometry_get(body, &(rp->x), &(rp->y), NULL,
+                              &(rp->w), &(rp->h), NULL);
+   ephysics_body_evas_object_update(body);
+   rp->edje->dirty = EINA_TRUE;
+}
+
+static void
 _edje_physics_body_add(Edje_Real_Part *rp, EPhysics_World *world)
 {
    Eina_Bool resize = EINA_TRUE;
@@ -2516,6 +2530,8 @@ _edje_physics_body_add(Edje_Real_Part *rp, EPhysics_World *world)
      }
 
    ephysics_body_evas_object_set(rp->body, rp->object, resize);
+   ephysics_body_event_callback_add(rp->body, EPHYSICS_CALLBACK_BODY_UPDATE,
+                                    _edje_physics_body_update_cb, rp);
 }
 #endif
 
@@ -3283,24 +3299,34 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
                }
              else
                {
+#ifdef HAVE_EPHYSICS
+                  if (!ep->body)
+                    {
+#endif
                   evas_object_map_enable_set(mo, 0);
                   evas_object_map_set(mo, NULL);
+#ifdef HAVE_EPHYSICS
+                    }
+#endif
                }
           }
      }
 
+#ifdef HAVE_EPHYSICS
+   ep->prev_description = chosen_desc;
+   if (!ep->body)
+     {
+#endif
    ep->x = pf->x;
    ep->y = pf->y;
    ep->w = pf->w;
    ep->h = pf->h;
-
-   ep->calculated |= flags;
-   ep->calculating = FLAG_NONE;
-
 #ifdef HAVE_EPHYSICS
-   ep->prev_description = chosen_desc;
+     }
 #endif
 
+   ep->calculated |= flags;
+   ep->calculating = FLAG_NONE;
 
 #ifdef EDJE_CALC_CACHE
    if (ep->calculated == FLAG_XY)
index 7263295..05b52e0 100644 (file)
@@ -341,6 +341,15 @@ _edje_programs_patterns_init(Edje *ed)
    ssp->sources_patterns = edje_match_programs_source_init(all, j);
 }
 
+#ifdef HAVE_EPHYSICS
+static void
+_edje_physics_world_update_cb(void *data, EPhysics_World *world __UNUSED__, void *event_info __UNUSED__)
+{
+   Edje *edje = data;
+   _edje_recalc_do(edje);
+}
+#endif
+
 int
 _edje_object_file_set_internal(Evas_Object *obj, const char *file, const char *group, const char *parent, Eina_List *group_path, Eina_Array *nested)
 {
@@ -447,6 +456,9 @@ _edje_object_file_set_internal(Evas_Object *obj, const char *file, const char *g
                {
                   ephysics_init();
                   ed->world = ephysics_world_new();
+                  ephysics_world_event_callback_add(
+                     ed->world, EPHYSICS_CALLBACK_WORLD_UPDATE,
+                     _edje_physics_world_update_cb, ed);
                }
 #endif