edje: support velocity family actions and scripts
authorBruno Dilly <bdilly@profusion.mobi>
Thu, 6 Dec 2012 22:10:59 +0000 (22:10 +0000)
committerBruno Dilly <bdilly@profusion.mobi>
Thu, 6 Dec 2012 22:10:59 +0000 (22:10 +0000)
SVN revision: 80397

legacy/edje/data/include/edje.inc
legacy/edje/src/bin/edje_cc_handlers.c
legacy/edje/src/examples/physics_actions.edc
legacy/edje/src/lib/Edje.h
legacy/edje/src/lib/edje_embryo.c
legacy/edje/src/lib/edje_program.c

index a358d58..5ca9488 100644 (file)
@@ -231,12 +231,22 @@ native       play_tone        (tone_name[], Float:duration);
  * physics_force(PART:"logo", 0, 240, 0);
  * physics_torque(PART:"logo", 0, 0, 2.2);
  * physics_forces_clear(PART:"logo");
+ *
+ * physics_set_velocity(PART:"logo", 40.5, 0, 0);
+ * physics_set_ang_velocity(PART:"logo", 0, 0, -3);
+ * physics_stop(PART:"logo");
  */
-native       physics_impulse         (part_id, Float:x, Float:y, Float:z);
-native       physics_torque_impulse  (part_id, Float:x, Float:y, Float:z);
-
-native       physics_torque          (part_id, Float:x, Float:y, Float:z);
-native       physics_torques_get     (part_id, &Float:x, &Float:y, &Float:z);
-native       physics_force           (part_id, Float:x, Float:y, Float:z);
-native       physics_forces_get      (part_id, &Float:x, &Float:y, &Float:z);
-native       physics_forces_clear    (part_id);
+native       physics_impulse          (part_id, Float:x, Float:y, Float:z);
+native       physics_torque_impulse   (part_id, Float:x, Float:y, Float:z);
+
+native       physics_torque           (part_id, Float:x, Float:y, Float:z);
+native       physics_torques_get      (part_id, &Float:x, &Float:y, &Float:z);
+native       physics_force            (part_id, Float:x, Float:y, Float:z);
+native       physics_forces_get       (part_id, &Float:x, &Float:y, &Float:z);
+native       physics_forces_clear     (part_id);
+
+native       physics_set_velocity     (part_id, Float:x, Float:y, Float:z);
+native       physics_get_velocity     (part_id, &Float:x, &Float:y, &Float:z);
+native       physics_set_ang_velocity (part_id, Float:x, Float:y, Float:z);
+native       physics_get_ang_velocity (part_id, &Float:x, &Float:y, &Float:z);
+native       physics_stop             (part_id);
index 3372ace..367b493 100644 (file)
@@ -8032,7 +8032,8 @@ st_collections_group_programs_program_in(void)
         ACTION_STOP, SIGNAL_EMIT, DRAG_VAL_SET, DRAG_VAL_STEP, DRAG_VAL_PAGE,
         FOCUS_SET, PARAM_COPY, PARAM_SET, PLAY_SAMPLE, PLAY_TONE,
         PHYSICS_IMPULSE, PHYSICS_TORQUE_IMPULSE, PHYSICS_FORCE, PHYSICS_TORQUE,
-        PHYSICS_FORCES_CLEAR
+        PHYSICS_FORCES_CLEAR, PHYSICS_VEL_SET, PHYSICS_ANG_VEL_SET,
+        PHYSICS_STOP
         Only one action can be specified per program. Examples:\n
            action: STATE_SET "statename" 0.5;\n
            action: ACTION_STOP;\n
@@ -8051,6 +8052,9 @@ st_collections_group_programs_program_in(void)
            action: PHYSICS_FORCE -20.8 0 30.85;\n
            action: PHYSICS_TORQUE 0 0 4.8;\n
            action: PHYSICS_FORCES_CLEAR;\n
+           action: PHYSICS_VEL_SET 40.9 0 0;\n
+           action: PHYSICS_ANG_VEL_SET 12.4 0 0.66;\n
+           action: PHYSICS_STOP;\n
     @endproperty
 */
 static void
@@ -8083,6 +8087,10 @@ st_collections_group_programs_program_action(void)
                            "PHYSICS_TORQUE", EDJE_ACTION_TYPE_PHYSICS_TORQUE,
                            "PHYSICS_FORCES_CLEAR",
                            EDJE_ACTION_TYPE_PHYSICS_FORCES_CLEAR,
+                           "PHYSICS_VEL_SET", EDJE_ACTION_TYPE_PHYSICS_VEL_SET,
+                           "PHYSICS_ANG_VEL_SET",
+                           EDJE_ACTION_TYPE_PHYSICS_ANG_VEL_SET,
+                           "PHYSICS_STOP", EDJE_ACTION_TYPE_PHYSICS_STOP,
                            NULL);
    if (ep->action == EDJE_ACTION_TYPE_STATE_SET)
      {
@@ -8172,7 +8180,9 @@ st_collections_group_programs_program_action(void)
    else if ((ep->action == EDJE_ACTION_TYPE_PHYSICS_IMPULSE) ||
             (ep->action == EDJE_ACTION_TYPE_PHYSICS_TORQUE_IMPULSE) ||
             (ep->action == EDJE_ACTION_TYPE_PHYSICS_FORCE) ||
-            (ep->action == EDJE_ACTION_TYPE_PHYSICS_TORQUE))
+            (ep->action == EDJE_ACTION_TYPE_PHYSICS_TORQUE) ||
+            (ep->action == EDJE_ACTION_TYPE_PHYSICS_VEL_SET) ||
+            (ep->action == EDJE_ACTION_TYPE_PHYSICS_ANG_VEL_SET))
      {
         ep->physics.x = parse_float(1);
         ep->physics.y = parse_float(2);
@@ -8190,6 +8200,7 @@ st_collections_group_programs_program_action(void)
       case EDJE_ACTION_TYPE_FOCUS_OBJECT:
       case EDJE_ACTION_TYPE_FOCUS_SET:
       case EDJE_ACTION_TYPE_PHYSICS_FORCES_CLEAR:
+      case EDJE_ACTION_TYPE_PHYSICS_STOP:
         check_arg_count(1);
         break;
       case EDJE_ACTION_TYPE_PARAM_SET:
@@ -8197,6 +8208,8 @@ st_collections_group_programs_program_action(void)
       case EDJE_ACTION_TYPE_PHYSICS_TORQUE_IMPULSE:
       case EDJE_ACTION_TYPE_PHYSICS_FORCE:
       case EDJE_ACTION_TYPE_PHYSICS_TORQUE:
+      case EDJE_ACTION_TYPE_PHYSICS_VEL_SET:
+      case EDJE_ACTION_TYPE_PHYSICS_ANG_VEL_SET:
         check_arg_count(4);
         break;
       case EDJE_ACTION_TYPE_PARAM_COPY:
@@ -8401,6 +8414,9 @@ st_collections_group_programs_program_target(void)
            case EDJE_ACTION_TYPE_PHYSICS_FORCE:
            case EDJE_ACTION_TYPE_PHYSICS_TORQUE:
            case EDJE_ACTION_TYPE_PHYSICS_FORCES_CLEAR:
+           case EDJE_ACTION_TYPE_PHYSICS_VEL_SET:
+           case EDJE_ACTION_TYPE_PHYSICS_ANG_VEL_SET:
+           case EDJE_ACTION_TYPE_PHYSICS_STOP:
 #endif
               data_queue_part_lookup(pc, name, &(et->id));
               break;
index 0b49439..f73e879 100644 (file)
@@ -2,7 +2,9 @@
  * $ edje_player -S -p physics_actions.edj
  *
  * signal up impulse   -> will throw both balls up
+ * signal down impulse   -> will throw both balls down
  * signal left impulse -> will throw blue ball to the left
+ * signal right impulse -> will throw red ball to the right
  * signal clockwise impulse -> will roll blue ball in clockwise
  * signal counterclockwise impulse -> will roll blue ball in counterclockwise
  * signal up force -> will apply a force up in blue ball
  * signal counterclockwise torque -> will apply a counterclockwise torque
  *                                   in blue ball
  * signal clear force -> will clear all forces applied over blue ball
+ * signal up velocity -> will set a velocity up in blue ball
+ * signal down velocity -> will set a velocity down in blue ball
+ * signal left velocity -> will set a velocity left in blue ball
+ * signal right velocity -> will set a velocity right in blue ball
+ * signal clockwise velocity -> will set a clockwise velocity in blue ball
+ * signal counterclockwise velocity -> will set a counterclockwise velocity
+ *                                   in blue ball
+ * signal stop velocity -> will stop the blue ball
  *
  * message 1 FLOAT_SET 3 50 -100 0 -> apply an impulse on blue ball with
  *    x = 50, y = -100, z = 0, for example
  *    over the part.
  * message 7 STRING "blue_circle" -> return a message with all torques applied
  *    over the part.
+ * message 8 FLOAT_SET 3 300 -103.2 0 -> set linear velocity of the blue ball
+ *    with x = 300, y = -103.2, z = 150, for example
+ * message 9 STRING "blue_circle" -> return a message with part's linear
+ *    velocity.
+ * message 10 FLOAT_SET 3 0 0 150 -> set angular velocity of the blue ball
+ *    with x = 0, y = 0, z = 150, for example
+ * message 11 STRING "blue_circle" -> return a message with part's angular
+ *    velocity.
+ * message 12 STRING "blue_circle" -> stop the part.
  */
 
 #define ID_IMPULSE (1)
 #define ID_FORCES_CLEAR (5)
 #define ID_FORCES_GET (6)
 #define ID_TORQUES_GET (7)
+#define ID_VEL_SET (8)
+#define ID_VEL_GET (9)
+#define ID_ANG_VEL_SET (10)
+#define ID_ANG_VEL_GET (11)
+#define ID_STOP (12)
 
 collections {
 
@@ -111,6 +135,49 @@ collections {
                physics_torques_get(pid, x, y, z);
                send_message(MSG_FLOAT_SET, id, x, y, z);
             }
+            else if ((id == ID_VEL_SET) && (type == MSG_FLOAT_SET)) {
+               new Float:x, Float:y, Float:z;
+               new n = numargs();
+               if (n < 5) return;
+               x = getfarg(2);
+               y = getfarg(3);
+               z = getfarg(4);
+               physics_set_velocity(PART:"blue_circle", x, y, z);
+            }
+            else if ((id == ID_VEL_GET) && (type == MSG_STRING)) {
+               new Float:x, Float:y, Float:z;
+               new pid, name[1024];
+               getsarg(2, name, sizeof(name));
+               pid = get_part_id(name);
+               if (!pid) return;
+               physics_get_velocity(pid, x, y, z);
+               send_message(MSG_FLOAT_SET, id, x, y, z);
+            }
+            else if ((id == ID_ANG_VEL_SET) && (type == MSG_FLOAT_SET)) {
+               new Float:x, Float:y, Float:z;
+               new n = numargs();
+               if (n < 5) return;
+               x = getfarg(2);
+               y = getfarg(3);
+               z = getfarg(4);
+               physics_set_ang_velocity(PART:"blue_circle", x, y, z);
+            }
+            else if ((id == ID_ANG_VEL_GET) && (type == MSG_STRING)) {
+               new Float:x, Float:y, Float:z;
+               new pid, name[1024];
+               getsarg(2, name, sizeof(name));
+               pid = get_part_id(name);
+               if (!pid) return;
+               physics_get_ang_velocity(pid, x, y, z);
+               send_message(MSG_FLOAT_SET, id, x, y, z);
+            }
+            else if ((id == ID_STOP) && (type == MSG_STRING)) {
+               new pid, name[1024];
+               getsarg(2, name, sizeof(name));
+               pid = get_part_id(name);
+               if (!pid) return;
+               physics_stop(pid);
+            }
          }
       }
 
@@ -328,6 +395,62 @@ collections {
             target: "blue_circle";
          }
 
+         program {
+            name: "velocity_up";
+            signal: "up";
+            source: "velocity";
+            action: PHYSICS_VEL_SET 0 -200 0;
+            target: "blue_circle";
+         }
+
+         program {
+            name: "velocity_down";
+            signal: "down";
+            source: "velocity";
+            action: PHYSICS_VEL_SET 0 200 0;
+            target: "blue_circle";
+         }
+
+         program {
+            name: "velocity_left";
+            signal: "left";
+            source: "velocity";
+            action: PHYSICS_VEL_SET -200 0 0;
+            target: "blue_circle";
+         }
+
+         program {
+            name: "velocity_right";
+            signal: "right";
+            source: "velocity";
+            action: PHYSICS_VEL_SET 200 0 0;
+            target: "blue_circle";
+         }
+
+         program {
+            name: "velocity_clockwise";
+            signal: "clockwise";
+            source: "velocity";
+            action: PHYSICS_ANG_VEL_SET 0 0 80;
+            target: "blue_circle";
+         }
+
+         program {
+            name: "velocity_counterclockwise";
+            signal: "counterclockwise";
+            source: "velocity";
+            action: PHYSICS_ANG_VEL_SET 0 0 -80;
+            target: "blue_circle";
+         }
+
+         program {
+            name: "stop";
+            signal: "stop";
+            source: "velocity";
+            action: PHYSICS_STOP;
+            target: "blue_circle";
+         }
+
       }
 
    }
index 40b8520..4854b04 100644 (file)
@@ -4152,7 +4152,10 @@ typedef enum _Edje_Action_Type
    EDJE_ACTION_TYPE_PHYSICS_FORCE            = 17, /**< @since 1.8 */
    EDJE_ACTION_TYPE_PHYSICS_TORQUE           = 18, /**< @since 1.8 */
    EDJE_ACTION_TYPE_PHYSICS_FORCES_CLEAR     = 19, /**< @since 1.8 */
-   EDJE_ACTION_TYPE_LAST                     = 20
+   EDJE_ACTION_TYPE_PHYSICS_VEL_SET          = 20, /**< @since 1.8 */
+   EDJE_ACTION_TYPE_PHYSICS_ANG_VEL_SET      = 21, /**< @since 1.8 */
+   EDJE_ACTION_TYPE_PHYSICS_STOP             = 22, /**< @since 1.8 */
+   EDJE_ACTION_TYPE_LAST                     = 23
 } Edje_Action_Type;
 
 /**
index f2280b7..2dde916 100644 (file)
  * physics_forces_clear(part_id)
  * physics_forces_get(part_id, &Float:x, &Float:y, &Float:z)
  * physics_torques_get(part_id, &Float:x, &Float:y, &Float:z)
+ * physics_set_velocity(part_id, Float:x, Float:y, Float:z)
+ * physics_get_velocity(part_id, &Float:x, &Float:y, &Float:z)
+ * physics_set_ang_velocity(part_id, Float:x, Float:y, Float:z)
+ * physics_get_ang_velocity(part_id, &Float:x, &Float:y, &Float:z)
+ * physics_stop(part_id)
  *
  * ADD/DEL CUSTOM OBJECTS UNDER SOLE EMBRYO SCRIPT CONTROL
  *
@@ -3166,6 +3171,59 @@ _edje_embryo_fn_physics_torques_get(Embryo_Program *ep, Embryo_Cell *params)
    return _edje_embryo_fn_physics_components_get(
       ep, params, ephysics_body_torques_get);
 }
+
+/* physics_set_velocity(part_id, Float:x, Float:y, Float:z) */
+static Embryo_Cell
+_edje_embryo_fn_physics_set_velocity(Embryo_Program *ep, Embryo_Cell *params)
+{
+   return _edje_embryo_fn_physics_components_set(
+      ep, params, ephysics_body_linear_velocity_set);
+}
+
+/* physics_get_velocity(part_id, &Float:x, &Float:y, &Float:z) */
+static Embryo_Cell
+_edje_embryo_fn_physics_get_velocity(Embryo_Program *ep, Embryo_Cell *params)
+{
+   return _edje_embryo_fn_physics_components_get(
+      ep, params, ephysics_body_linear_velocity_get);
+}
+
+/* physics_set_ang_velocity(part_id, Float:x, Float:y, Float:z) */
+static Embryo_Cell
+_edje_embryo_fn_physics_set_ang_velocity(Embryo_Program *ep, Embryo_Cell *params)
+{
+   return _edje_embryo_fn_physics_components_set(
+      ep, params, ephysics_body_angular_velocity_set);
+}
+
+/* physics_get_ang_velocity(part_id, &Float:x, &Float:y, &Float:z) */
+static Embryo_Cell
+_edje_embryo_fn_physics_get_ang_velocity(Embryo_Program *ep, Embryo_Cell *params)
+{
+   return _edje_embryo_fn_physics_components_get(
+      ep, params, ephysics_body_angular_velocity_get);
+}
+
+/* physics_stop(part_id) */
+static Embryo_Cell
+_edje_embryo_fn_physics_stop(Embryo_Program *ep, Embryo_Cell *params)
+{
+   Edje_Real_Part *rp;
+   int part_id = 0;
+   Edje *ed;
+
+   CHKPARAM(1);
+
+   ed = embryo_program_data_get(ep);
+   part_id = params[1];
+   if (part_id < 0) return 0;
+
+   rp = ed->table_parts[part_id % ed->table_parts_size];
+   if ((rp) && (rp->body))
+     ephysics_body_stop(rp->body);
+
+   return 0;
+}
 #endif
 
 void
@@ -3271,6 +3329,11 @@ _edje_embryo_script_init(Edje_Part_Collection *edc)
    embryo_program_native_call_add(ep, "physics_forces_clear", _edje_embryo_fn_physics_forces_clear);
    embryo_program_native_call_add(ep, "physics_forces_get", _edje_embryo_fn_physics_forces_get);
    embryo_program_native_call_add(ep, "physics_torques_get", _edje_embryo_fn_physics_torques_get);
+   embryo_program_native_call_add(ep, "physics_set_velocity", _edje_embryo_fn_physics_set_velocity);
+   embryo_program_native_call_add(ep, "physics_get_velocity", _edje_embryo_fn_physics_get_velocity);
+   embryo_program_native_call_add(ep, "physics_set_ang_velocity", _edje_embryo_fn_physics_set_ang_velocity);
+   embryo_program_native_call_add(ep, "physics_get_ang_velocity", _edje_embryo_fn_physics_get_ang_velocity);
+   embryo_program_native_call_add(ep, "physics_stop", _edje_embryo_fn_physics_stop);
 #endif
 }
 
index d06bf8c..f6013af 100644 (file)
@@ -991,6 +991,29 @@ _edje_program_run(Edje *ed, Edje_Program *pr, Eina_Bool force, const char *ssig,
                }
           }
         break;
+     case EDJE_ACTION_TYPE_PHYSICS_VEL_SET:
+        if (!_edje_physics_action_set(
+              ed, pr, ephysics_body_linear_velocity_set))
+          goto break_prog;
+        break;
+     case EDJE_ACTION_TYPE_PHYSICS_ANG_VEL_SET:
+        if (!_edje_physics_action_set(
+              ed, pr, ephysics_body_angular_velocity_set))
+          goto break_prog;
+        break;
+     case EDJE_ACTION_TYPE_PHYSICS_STOP:
+        if (_edje_block_break(ed))
+          goto break_prog;
+        EINA_LIST_FOREACH(pr->targets, l, pt)
+          {
+             if (pt->id >= 0)
+               {
+                  rp = ed->table_parts[pt->id % ed->table_parts_size];
+                  if ((rp) && (rp->body))
+                    ephysics_body_stop(rp->body);
+               }
+          }
+        break;
 #endif
      default:
         // _edje_emit(ed, "program,start", pr->name);