From ebf6290be7c9ab9dfdf8cdd2b9c62c9ad365940c Mon Sep 17 00:00:00 2001 From: Bruno Dilly Date: Wed, 5 Dec 2012 19:30:08 +0000 Subject: [PATCH] edje: support new action: PHYSICS_IMPULSE It will apply a central impulse over a body's part. SVN revision: 80278 --- legacy/edje/src/bin/edje_cc_handlers.c | 22 +++- legacy/edje/src/examples/Makefile.am | 1 + legacy/edje/src/examples/physics_actions.edc | 161 +++++++++++++++++++++++++++ legacy/edje/src/lib/Edje.h | 3 +- legacy/edje/src/lib/edje_data.c | 6 + legacy/edje/src/lib/edje_private.h | 11 ++ legacy/edje/src/lib/edje_program.c | 17 +++ 7 files changed, 218 insertions(+), 3 deletions(-) create mode 100644 legacy/edje/src/examples/physics_actions.edc diff --git a/legacy/edje/src/bin/edje_cc_handlers.c b/legacy/edje/src/bin/edje_cc_handlers.c index 52fd13c..b55e010 100644 --- a/legacy/edje/src/bin/edje_cc_handlers.c +++ b/legacy/edje/src/bin/edje_cc_handlers.c @@ -8030,7 +8030,8 @@ st_collections_group_programs_program_in(void) @effect Action to be performed by the program. Valid actions are: STATE_SET, ACTION_STOP, SIGNAL_EMIT, DRAG_VAL_SET, DRAG_VAL_STEP, DRAG_VAL_PAGE, - FOCUS_SET, PARAM_COPY, PARAM_SET, PLAY_SAMPLE, PLAY_TONE + FOCUS_SET, PARAM_COPY, PARAM_SET, PLAY_SAMPLE, PLAY_TONE, + PHYSICS_IMPULSE Only one action can be specified per program. Examples:\n action: STATE_SET "statename" 0.5;\n action: ACTION_STOP;\n @@ -8044,6 +8045,7 @@ st_collections_group_programs_program_in(void) action: PARAM_SET "part" "param" "value";\n action: PLAY_SAMPLE "sample name";\n action: PLAY_TONE "tone name" duration in seconds ( Range 0.1 to 10.0 );\n + action: PHYSICS_IMPULSE 10 -23.4 0;\n @endproperty */ static void @@ -8069,6 +8071,7 @@ st_collections_group_programs_program_action(void) "PARAM_SET", EDJE_ACTION_TYPE_PARAM_SET, "PLAY_SAMPLE", EDJE_ACTION_TYPE_SOUND_SAMPLE, "PLAY_TONE", EDJE_ACTION_TYPE_SOUND_TONE, + "PHYSICS_IMPULSE", EDJE_ACTION_TYPE_PHYSICS_IMPULSE, NULL); if (ep->action == EDJE_ACTION_TYPE_STATE_SET) { @@ -8154,7 +8157,15 @@ st_collections_group_programs_program_action(void) data_queue_part_lookup(pc, part, &(ep->param.dst)); free(part); } - +#ifdef HAVE_EPHYSICS + else if (ep->action == EDJE_ACTION_TYPE_PHYSICS_IMPULSE) + { + ep->physics.impulse.x = parse_float(1); + ep->physics.impulse.y = parse_float(2); + ep->physics.impulse.z = parse_float(3); + } +#endif + switch (ep->action) { case EDJE_ACTION_TYPE_ACTION_STOP: @@ -8180,6 +8191,9 @@ st_collections_group_programs_program_action(void) case EDJE_ACTION_TYPE_SOUND_TONE: check_arg_count(3); break; + case EDJE_ACTION_TYPE_PHYSICS_IMPULSE: + check_arg_count(4); + break; default: check_arg_count(3); } @@ -8376,6 +8390,10 @@ st_collections_group_programs_program_target(void) data_queue_part_lookup(pc, name, &(et->id)); else if (ep->action == EDJE_ACTION_TYPE_FOCUS_OBJECT) data_queue_part_lookup(pc, name, &(et->id)); +#ifdef HAVE_EPHYSICS + else if (ep->action == EDJE_ACTION_TYPE_PHYSICS_IMPULSE) + data_queue_part_lookup(pc, name, &(et->id)); +#endif else { ERR("parse error %s:%i. target may only be used after action", diff --git a/legacy/edje/src/examples/Makefile.am b/legacy/edje/src/examples/Makefile.am index 645c211..5debecd 100644 --- a/legacy/edje/src/examples/Makefile.am +++ b/legacy/edje/src/examples/Makefile.am @@ -54,6 +54,7 @@ endif if ENABLE_EPHYSICS EDCS += \ +physics_actions.edc \ physics_basic.edc \ physics_complex.edc endif diff --git a/legacy/edje/src/examples/physics_actions.edc b/legacy/edje/src/examples/physics_actions.edc new file mode 100644 index 0000000..5fb0add --- /dev/null +++ b/legacy/edje/src/examples/physics_actions.edc @@ -0,0 +1,161 @@ +/* It can be tested with edje_player slave mode + * $ edje_player -S physics_actions.edj + * signal up impulse -> will throw both balls up + * signal left impulse -> will throw blue ball to the left + */ + +collections { + + images { + image: "bubble-blue.png" COMP; + } + + group { + name: "example_group"; + + parts { + part { + name: "background"; + type: RECT; + physics_body: NONE; + description { + state: "default" 0.0; + color: 255 255 255 255; /* white */ + rel1.relative: 0.0 0.0; + rel2.relative: 1.0 1.0; + } + } + + part { + name: "blue_circle"; + type: IMAGE; + physics_body: RIGID_CIRCLE; + description { + state: "default" 0.0; + rel1.relative: 0.35 0.1; + rel2.relative: 0.55 0.2; + aspect: 1 1; + image { + normal: "bubble-blue.png"; + } + physics { + restitution: 0.85; + friction: 1.0; + } + } + } + + part { + name: "red_circle"; + type: IMAGE; + physics_body: RIGID_CIRCLE; + description { + state: "default" 0.0; + color: 255 0 0 255; /* light red */ + rel1.relative: 0.65 0.1; + rel2.relative: 0.85 0.2; + aspect: 1 1; + image { + normal: "bubble-blue.png"; + } + physics { + restitution: 0.85; + friction: 1.0; + } + } + } + + part { + name: "floor"; + type: RECT; + physics_body: BOUNDARY_BOTTOM; + description { + state: "default" 0.0; + visible: 0; + physics { + restitution: 0.6; + friction: 1.0; + } + } + } + + part { + name: "right_wall"; + type: RECT; + physics_body: BOUNDARY_RIGHT; + description { + state: "default" 0.0; + visible: 0; + physics { + restitution: 0.3; + } + } + } + + part { + name: "left_wall"; + type: RECT; + physics_body: BOUNDARY_LEFT; + description { + state: "default" 0.0; + visible: 0; + physics { + restitution: 0.3; + } + } + } + + part { + name: "roof"; + type: RECT; + physics_body: BOUNDARY_TOP; + description { + state: "default" 0.0; + visible: 0; + physics { + restitution: 0.2; + } + } + } + } + + programs { + + program { + name: "impulse_up"; + signal: "up"; + source: "impulse"; + action: PHYSICS_IMPULSE 0 -300 0; + target: "blue_circle"; + target: "red_circle"; + } + + program { + name: "impulse_down"; + signal: "down"; + source: "impulse"; + action: PHYSICS_IMPULSE 0 300 0; + target: "red_circle"; + target: "blue_circle"; + } + + program { + name: "impulse_left"; + signal: "left"; + source: "impulse"; + action: PHYSICS_IMPULSE -300 0 0; + target: "blue_circle"; + } + + program { + name: "impulse_right"; + signal: "right"; + source: "impulse"; + action: PHYSICS_IMPULSE 300 0 0; + target: "red_circle"; + } + + } + + } +} diff --git a/legacy/edje/src/lib/Edje.h b/legacy/edje/src/lib/Edje.h index 49f4357..b76fb5b 100644 --- a/legacy/edje/src/lib/Edje.h +++ b/legacy/edje/src/lib/Edje.h @@ -4155,7 +4155,8 @@ typedef enum _Edje_Action_Type EDJE_ACTION_TYPE_PARAM_SET = 12, EDJE_ACTION_TYPE_SOUND_SAMPLE = 13, /**< @since 1.1 */ EDJE_ACTION_TYPE_SOUND_TONE = 14, /**< @since 1.1 */ - EDJE_ACTION_TYPE_LAST = 15 + EDJE_ACTION_TYPE_PHYSICS_IMPULSE = 15, /**< @since 1.8 */ + EDJE_ACTION_TYPE_LAST = 16 } Edje_Action_Type; /** diff --git a/legacy/edje/src/lib/edje_data.c b/legacy/edje/src/lib/edje_data.c index 4db53c8..b30f5c0 100644 --- a/legacy/edje/src/lib/edje_data.c +++ b/legacy/edje/src/lib/edje_data.c @@ -436,6 +436,12 @@ _edje_edd_init(void) EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_program, Edje_Program, "param.src", param.src, EET_T_INT); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_program, Edje_Program, "param.dst", param.dst, EET_T_INT); +#ifdef HAVE_EPHYSICS + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_program, Edje_Program, "physics.impulse.x", physics.impulse.x, EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_program, Edje_Program, "physics.impulse.y", physics.impulse.y, EET_T_DOUBLE); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_program, Edje_Program, "physics.impulse.z", physics.impulse.z, EET_T_DOUBLE); +#endif + EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Edje_Part_Image_Id); _edje_edd_edje_part_image_id = eet_data_descriptor_file_new(&eddc); diff --git a/legacy/edje/src/lib/edje_private.h b/legacy/edje/src/lib/edje_private.h index 61b8a7f..fe7fcec 100644 --- a/legacy/edje/src/lib/edje_private.h +++ b/legacy/edje/src/lib/edje_private.h @@ -646,6 +646,17 @@ struct _Edje_Program /* a conditional program to be run */ int dst; /* part where parameter is being stored */ } param; +#ifdef HAVE_EPHYSICS + /* used for actions related to physics, as PHYSICS_IMPULSE */ + struct { + struct { + double x; + double y; + double z; + } impulse; + } physics; +#endif + Eina_Bool exec : 1; }; diff --git a/legacy/edje/src/lib/edje_program.c b/legacy/edje/src/lib/edje_program.c index 2cf4cf9..853f524 100644 --- a/legacy/edje/src/lib/edje_program.c +++ b/legacy/edje/src/lib/edje_program.c @@ -933,6 +933,23 @@ _edje_program_run(Edje *ed, Edje_Program *pr, Eina_Bool force, const char *ssig, if (_edje_block_break(ed)) goto break_prog; } break; +#ifdef HAVE_EPHYSICS + case EDJE_ACTION_TYPE_PHYSICS_IMPULSE: + 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_central_impulse_apply( + rp->body, pr->physics.impulse.x, pr->physics.impulse.y, + pr->physics.impulse.z); + } + } + break; +#endif default: // _edje_emit(ed, "program,start", pr->name); // _edje_emit(ed, "program,stop", pr->name); -- 2.7.4