From: Bruno Dilly Date: Wed, 5 Dec 2012 21:09:18 +0000 (+0000) Subject: edje: support applying impulse via script X-Git-Tag: submit/devel/efl/20131022.203902~3084 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8783eb70bbaea0a87f7fd4d41d6b062adecf5f67;p=platform%2Fupstream%2Fefl.git edje: support applying impulse via script SVN revision: 80279 --- diff --git a/legacy/edje/data/include/edje.inc b/legacy/edje/data/include/edje.inc index 50f2bbe..b84e25d 100644 --- a/legacy/edje/data/include/edje.inc +++ b/legacy/edje/data/include/edje.inc @@ -219,3 +219,12 @@ native get_state_val(part_id, State_Param:p, ...); /* Multisense */ native play_sample (sample_name[], Float:speed); native play_tone (tone_name[], Float:duration); + +/***********************************************************/ +/* Edje physics calls. */ +/***********************************************************/ +/* Example: + * + * physics_impulse(PART:"logo", 0, 50.8, 0); + */ +native physics_impulse (part_id, Float:x, Float:y, Float:z); diff --git a/legacy/edje/src/examples/physics_actions.edc b/legacy/edje/src/examples/physics_actions.edc index 5fb0add..44a59a8 100644 --- a/legacy/edje/src/examples/physics_actions.edc +++ b/legacy/edje/src/examples/physics_actions.edc @@ -2,8 +2,12 @@ * $ edje_player -S physics_actions.edj * signal up impulse -> will throw both balls up * signal left impulse -> will throw blue ball to the left + * message 1 FLOAT_SET 3 50 -100 0 -> apply an impulse on blue ball with + * x = 50, y = -100, z = 0, for example */ +#define ID_IMPULSE (1) + collections { images { @@ -13,6 +17,20 @@ collections { group { name: "example_group"; + script { + public message(Msg_Type:type, id, ...) { + if ((id == ID_IMPULSE) && (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_impulse(PART:"blue_circle", x, y, z); + } + } + } + parts { part { name: "background"; diff --git a/legacy/edje/src/lib/edje_embryo.c b/legacy/edje/src/lib/edje_embryo.c index 77f23b1..2902af6 100644 --- a/legacy/edje/src/lib/edje_embryo.c +++ b/legacy/edje/src/lib/edje_embryo.c @@ -200,6 +200,8 @@ * external_param_get_bool(id, param_name[]) * external_param_set_bool(id, param_name[], value) * + * physics_impulse(part_id, Float:x, Float:y, Float:z) + * * ADD/DEL CUSTOM OBJECTS UNDER SOLE EMBRYO SCRIPT CONTROL * */ @@ -3029,6 +3031,39 @@ _edje_embryo_fn_external_param_set_bool(Embryo_Program *ep, Embryo_Cell *params) return _edje_external_param_set(NULL, rp, &eep); } +#ifdef HAVE_EPHYSICS +/* physics_impulse(part_id, Float:x, Float:y, Float:z) */ +static Embryo_Cell +_edje_embryo_fn_physics_impulse(Embryo_Program *ep, Embryo_Cell *params) +{ + Edje_Real_Part *rp; + int part_id = 0; + Edje *ed; + + CHKPARAM(4); + + 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) + { + if (rp->body) + { + double x, y, z; + + x = (double) EMBRYO_CELL_TO_FLOAT(params[2]); + y = (double) EMBRYO_CELL_TO_FLOAT(params[3]); + z = (double) EMBRYO_CELL_TO_FLOAT(params[4]); + + ephysics_body_central_impulse_apply(rp->body, x, y, z); + } + } + return 0; +} +#endif + void _edje_embryo_script_init(Edje_Part_Collection *edc) { @@ -3123,6 +3158,10 @@ _edje_embryo_script_init(Edje_Part_Collection *edc) embryo_program_native_call_add(ep, "external_param_set_choice", _edje_embryo_fn_external_param_set_choice); embryo_program_native_call_add(ep, "external_param_get_bool", _edje_embryo_fn_external_param_get_bool); embryo_program_native_call_add(ep, "external_param_set_bool", _edje_embryo_fn_external_param_set_bool); + +#ifdef HAVE_EPHYSICS + embryo_program_native_call_add(ep, "physics_impulse", _edje_embryo_fn_physics_impulse); +#endif } void