summaryrefslogtreecommitdiff
path: root/legacy/edje
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-12-10 11:47:22 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-12-10 11:47:22 +0000
commit75ceec585abf3403d50ec061f565bd338d9dab7a (patch)
tree8fcdbcc7d457aaecf57ee5b0f6823c1d8c091ebc /legacy/edje
parentf96d02f8b3d41b3202f9f5a4396f1f16f71a7bd0 (diff)
edje: make it possible to set body's material
And density as well. SVN revision: 80600
Diffstat (limited to 'legacy/edje')
-rw-r--r--legacy/edje/data/include/edje.inc4
-rw-r--r--legacy/edje/src/bin/edje_cc_handlers.c71
-rw-r--r--legacy/edje/src/examples/physics_complex.edc6
-rw-r--r--legacy/edje/src/lib/edje_calc.c27
-rw-r--r--legacy/edje/src/lib/edje_data.c4
-rw-r--r--legacy/edje/src/lib/edje_embryo.c20
-rw-r--r--legacy/edje/src/lib/edje_private.h12
7 files changed, 136 insertions, 8 deletions
diff --git a/legacy/edje/data/include/edje.inc b/legacy/edje/data/include/edje.inc
index 9ee0cdeda7..9e89e74838 100644
--- a/legacy/edje/data/include/edje.inc
+++ b/legacy/edje/data/include/edje.inc
@@ -215,7 +215,9 @@ enum State_Param
215 STATE_PHYSICS_FRICTION = 44, 215 STATE_PHYSICS_FRICTION = 44,
216 STATE_PHYSICS_RESTITUTION = 45, 216 STATE_PHYSICS_RESTITUTION = 45,
217 STATE_PHYSICS_DAMPING = 46, 217 STATE_PHYSICS_DAMPING = 46,
218 STATE_PHYSICS_SLEEP = 47 218 STATE_PHYSICS_SLEEP = 47,
219 STATE_PHYSICS_MATERIAL = 48,
220 STATE_PHYSICS_DENSITY = 49
219}; 221};
220 222
221native set_state_val(part_id, State_Param:p, ...); 223native set_state_val(part_id, State_Param:p, ...);
diff --git a/legacy/edje/src/bin/edje_cc_handlers.c b/legacy/edje/src/bin/edje_cc_handlers.c
index 8cb1da8bb9..b64af56dc6 100644
--- a/legacy/edje/src/bin/edje_cc_handlers.c
+++ b/legacy/edje/src/bin/edje_cc_handlers.c
@@ -315,6 +315,8 @@ static void st_collections_group_parts_part_description_physics_restitution(void
315static void st_collections_group_parts_part_description_physics_friction(void); 315static void st_collections_group_parts_part_description_physics_friction(void);
316static void st_collections_group_parts_part_description_physics_damping(void); 316static void st_collections_group_parts_part_description_physics_damping(void);
317static void st_collections_group_parts_part_description_physics_sleep(void); 317static void st_collections_group_parts_part_description_physics_sleep(void);
318static void st_collections_group_parts_part_description_physics_material(void);
319static void st_collections_group_parts_part_description_physics_density(void);
318static void st_collections_group_parts_part_description_physics_ignore_part_position(void); 320static void st_collections_group_parts_part_description_physics_ignore_part_position(void);
319#endif 321#endif
320static void st_collections_group_parts_part_description_map_perspective(void); 322static void st_collections_group_parts_part_description_map_perspective(void);
@@ -603,6 +605,8 @@ New_Statement_Handler statement_handlers[] =
603 {"collections.group.parts.part.description.physics.friction", st_collections_group_parts_part_description_physics_friction}, 605 {"collections.group.parts.part.description.physics.friction", st_collections_group_parts_part_description_physics_friction},
604 {"collections.group.parts.part.description.physics.damping", st_collections_group_parts_part_description_physics_damping}, 606 {"collections.group.parts.part.description.physics.damping", st_collections_group_parts_part_description_physics_damping},
605 {"collections.group.parts.part.description.physics.sleep", st_collections_group_parts_part_description_physics_sleep}, 607 {"collections.group.parts.part.description.physics.sleep", st_collections_group_parts_part_description_physics_sleep},
608 {"collections.group.parts.part.description.physics.material", st_collections_group_parts_part_description_physics_material},
609 {"collections.group.parts.part.description.physics.density", st_collections_group_parts_part_description_physics_density},
606 {"collections.group.parts.part.description.physics.ignore_part_position", st_collections_group_parts_part_description_physics_ignore_part_position}, 610 {"collections.group.parts.part.description.physics.ignore_part_position", st_collections_group_parts_part_description_physics_ignore_part_position},
607#endif 611#endif
608 {"collections.group.parts.part.description.map.perspective", st_collections_group_parts_part_description_map_perspective}, 612 {"collections.group.parts.part.description.map.perspective", st_collections_group_parts_part_description_map_perspective},
@@ -7193,6 +7197,8 @@ st_collections_group_parts_part_description_table_min(void)
7193 restitution: 0.82; 7197 restitution: 0.82;
7194 damping: 0.4 0.24; 7198 damping: 0.4 0.24;
7195 sleep: 32 18.9; 7199 sleep: 32 18.9;
7200 material: IRON;
7201 density: 3.2;
7196 } 7202 }
7197 .. 7203 ..
7198 } 7204 }
@@ -7368,6 +7374,71 @@ st_collections_group_parts_part_description_physics_sleep(void)
7368#endif 7374#endif
7369 7375
7370/** 7376/**
7377 @page edcref
7378 @property
7379 material
7380 @parameters
7381 [body's material]
7382 @effect
7383 Set the type (all caps) from among the available material types,
7384 it's set to CUSTOM by default.
7385 Each material has specific properties to be
7386 applied on the body, as density, friction and restitution.
7387 So if a material different of CUSTOM is set, the properties cited above
7388 won't be considered.
7389 Valid types:
7390 * CUSTOM
7391 * CONCRETE
7392 * IRON
7393 * PLASTIC
7394 * POLYSTYRENE
7395 * RUBBER
7396 * WOOD
7397 @endproperty
7398 @since 1.8.0
7399*/
7400#ifdef HAVE_EPHYSICS
7401static void
7402st_collections_group_parts_part_description_physics_material(void)
7403{
7404 check_arg_count(1);
7405
7406 current_desc->physics.material = parse_enum(0,
7407 "CUSTOM", EPHYSICS_BODY_MATERIAL_CUSTOM,
7408 "CONCRETE", EPHYSICS_BODY_MATERIAL_CONCRETE,
7409 "IRON", EPHYSICS_BODY_MATERIAL_IRON,
7410 "PLASTIC", EPHYSICS_BODY_MATERIAL_PLASTIC,
7411 "POLYSTYRENE", EPHYSICS_BODY_MATERIAL_POLYSTYRENE,
7412 "RUBBER", EPHYSICS_BODY_MATERIAL_RUBBER,
7413 "WOOD", EPHYSICS_BODY_MATERIAL_WOOD,
7414 NULL);
7415}
7416#endif
7417
7418/**
7419 @page edcref
7420 @property
7421 density
7422 @parameters
7423 [body's material density]
7424 @effect
7425 It will set the body mass considering its volume. While a density is
7426 set, resizing a body will always recalculate its mass.
7427 When a mass is explicitely set the density will be unset.
7428 @endproperty
7429 @since 1.8.0
7430*/
7431#ifdef HAVE_EPHYSICS
7432static void
7433st_collections_group_parts_part_description_physics_density(void)
7434{
7435 check_arg_count(1);
7436
7437 current_desc->physics.density = parse_float(0);
7438}
7439#endif
7440
7441/**
7371 @edcsubsection{collections_group_parts_description_map,Map} 7442 @edcsubsection{collections_group_parts_description_map,Map}
7372 */ 7443 */
7373 7444
diff --git a/legacy/edje/src/examples/physics_complex.edc b/legacy/edje/src/examples/physics_complex.edc
index db90d01041..50cd0580fb 100644
--- a/legacy/edje/src/examples/physics_complex.edc
+++ b/legacy/edje/src/examples/physics_complex.edc
@@ -80,7 +80,7 @@ collections {
80 } 80 }
81 physics { 81 physics {
82 ignore_part_position: 0; 82 ignore_part_position: 0;
83 restitution: 0.6; 83 material: IRON;
84 } 84 }
85 } 85 }
86 description { 86 description {
@@ -88,6 +88,10 @@ collections {
88 inherit: "default" 0.0; 88 inherit: "default" 0.0;
89 rel1.relative: 0 0.1; 89 rel1.relative: 0 0.1;
90 rel2.relative: 0.25 0.3; 90 rel2.relative: 0.25 0.3;
91 physics {
92 material: CUSTOM;
93 density: 40;
94 }
91 } 95 }
92 } 96 }
93 97
diff --git a/legacy/edje/src/lib/edje_calc.c b/legacy/edje/src/lib/edje_calc.c
index b05af57831..cb221005a6 100644
--- a/legacy/edje/src/lib/edje_calc.c
+++ b/legacy/edje/src/lib/edje_calc.c
@@ -2304,6 +2304,8 @@ _edje_part_recalc_single(Edje *ed,
2304 params->physics.damping.angular = desc->physics.damping.angular; 2304 params->physics.damping.angular = desc->physics.damping.angular;
2305 params->physics.sleep.linear = desc->physics.sleep.linear; 2305 params->physics.sleep.linear = desc->physics.sleep.linear;
2306 params->physics.sleep.angular = desc->physics.sleep.angular; 2306 params->physics.sleep.angular = desc->physics.sleep.angular;
2307 params->physics.material = desc->physics.material;
2308 params->physics.density = desc->physics.density;
2307 params->ignore_part_position = desc->physics.ignore_part_position; 2309 params->ignore_part_position = desc->physics.ignore_part_position;
2308#endif 2310#endif
2309 _edje_part_recalc_single_map(ed, ep, center, light, persp, desc, chosen_desc, params); 2311 _edje_part_recalc_single_map(ed, ep, center, light, persp, desc, chosen_desc, params);
@@ -2476,11 +2478,23 @@ _edje_physics_body_props_update(Edje_Real_Part *ep, Edje_Calc_Params *pf, Eina_B
2476 ep->w = pf->w; 2478 ep->w = pf->w;
2477 ep->h = pf->h; 2479 ep->h = pf->h;
2478 } 2480 }
2479 ephysics_body_mass_set(ep->body, pf->physics.mass); 2481
2482 ephysics_body_material_set(ep->body, pf->physics.material);
2483 if (!pf->physics.material)
2484 {
2485 if (pf->physics.density)
2486 ephysics_body_density_set(ep->body, pf->physics.density);
2487 else
2488 ephysics_body_mass_set(ep->body, pf->physics.mass);
2489 }
2490 }
2491
2492 if (!pf->physics.material)
2493 {
2494 ephysics_body_restitution_set(ep->body, pf->physics.restitution);
2495 ephysics_body_friction_set(ep->body, pf->physics.friction);
2480 } 2496 }
2481 2497
2482 ephysics_body_restitution_set(ep->body, pf->physics.restitution);
2483 ephysics_body_friction_set(ep->body, pf->physics.friction);
2484 ephysics_body_damping_set(ep->body, pf->physics.damping.linear, 2498 ephysics_body_damping_set(ep->body, pf->physics.damping.linear,
2485 pf->physics.damping.angular); 2499 pf->physics.damping.angular);
2486 ephysics_body_sleeping_threshold_set(ep->body, pf->physics.sleep.linear, 2500 ephysics_body_sleeping_threshold_set(ep->body, pf->physics.sleep.linear,
@@ -2936,6 +2950,8 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
2936 pos)); 2950 pos));
2937 p3->physics.friction = TO_DOUBLE(FINTP(p1->physics.friction, 2951 p3->physics.friction = TO_DOUBLE(FINTP(p1->physics.friction,
2938 p2->physics.friction, pos)); 2952 p2->physics.friction, pos));
2953 p3->physics.density = TO_DOUBLE(FINTP(p1->physics.density,
2954 p2->physics.density, pos));
2939 2955
2940 p3->physics.damping.linear = TO_DOUBLE(FINTP( 2956 p3->physics.damping.linear = TO_DOUBLE(FINTP(
2941 p1->physics.damping.linear, p2->physics.damping.linear, pos)); 2957 p1->physics.damping.linear, p2->physics.damping.linear, pos));
@@ -2951,6 +2967,11 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
2951 p3->ignore_part_position = 1; 2967 p3->ignore_part_position = 1;
2952 else 2968 else
2953 p3->ignore_part_position = 0; 2969 p3->ignore_part_position = 0;
2970
2971 if ((p1->physics.material) && (p2->physics.material))
2972 p3->physics.material = p1->physics.material;
2973 else
2974 p3->physics.material = EPHYSICS_BODY_MATERIAL_CUSTOM;
2954#endif 2975#endif
2955 2976
2956 switch (part_type) 2977 switch (part_type)
diff --git a/legacy/edje/src/lib/edje_data.c b/legacy/edje/src/lib/edje_data.c
index f34834b7cc..b6a39885dd 100644
--- a/legacy/edje/src/lib/edje_data.c
+++ b/legacy/edje/src/lib/edje_data.c
@@ -526,6 +526,8 @@ _edje_edd_init(void)
526 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.damping.angular", physics.damping.angular, EET_T_DOUBLE); \ 526 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.damping.angular", physics.damping.angular, EET_T_DOUBLE); \
527 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.sleep.linear", physics.sleep.linear, EET_T_DOUBLE); \ 527 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.sleep.linear", physics.sleep.linear, EET_T_DOUBLE); \
528 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.sleep.angular", physics.sleep.angular, EET_T_DOUBLE); \ 528 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.sleep.angular", physics.sleep.angular, EET_T_DOUBLE); \
529 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.material", physics.material, EET_T_UCHAR); \
530 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.density", physics.density, EET_T_DOUBLE); \
529 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.ignore_part_position", physics.ignore_part_position, EET_T_UCHAR); \ 531 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.ignore_part_position", physics.ignore_part_position, EET_T_UCHAR); \
530 } 532 }
531#else 533#else
@@ -598,6 +600,8 @@ _edje_edd_init(void)
598 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.damping.angular", Dec.physics.damping.angular, EET_T_DOUBLE); \ 600 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.damping.angular", Dec.physics.damping.angular, EET_T_DOUBLE); \
599 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.sleep.linear", Dec.physics.sleep.linear, EET_T_DOUBLE); \ 601 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.sleep.linear", Dec.physics.sleep.linear, EET_T_DOUBLE); \
600 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.sleep.angular", Dec.physics.sleep.angular, EET_T_DOUBLE); \ 602 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.sleep.angular", Dec.physics.sleep.angular, EET_T_DOUBLE); \
603 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.material", Dec.physics.material, EET_T_UCHAR); \
604 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.density", Dec.physics.density, EET_T_DOUBLE); \
601 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.ignore_part_position", Dec.physics.ignore_part_position, EET_T_UCHAR); \ 605 EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.ignore_part_position", Dec.physics.ignore_part_position, EET_T_UCHAR); \
602 } 606 }
603#else 607#else
diff --git a/legacy/edje/src/lib/edje_embryo.c b/legacy/edje/src/lib/edje_embryo.c
index 7e90e78baf..af7d56197a 100644
--- a/legacy/edje/src/lib/edje_embryo.c
+++ b/legacy/edje/src/lib/edje_embryo.c
@@ -2292,6 +2292,16 @@ _edje_embryo_fn_set_state_val(Embryo_Program *ep, Embryo_Cell *params)
2292 GETFLOAT_T(rp->custom->description->physics.sleep.angular, params[4]); 2292 GETFLOAT_T(rp->custom->description->physics.sleep.angular, params[4]);
2293 2293
2294 break; 2294 break;
2295 case EDJE_STATE_PARAM_PHYSICS_MATERIAL:
2296 CHKPARAM(3);
2297
2298 GETINT(rp->custom->description->physics.material, params[3]);
2299 break;
2300 case EDJE_STATE_PARAM_PHYSICS_DENSITY:
2301 CHKPARAM(3);
2302
2303 GETFLOAT_T(rp->custom->description->physics.density, params[3]);
2304 break;
2295#endif 2305#endif
2296 default: 2306 default:
2297 break; 2307 break;
@@ -2776,6 +2786,16 @@ _edje_embryo_fn_get_state_val(Embryo_Program *ep, Embryo_Cell *params)
2776 SETFLOAT_T(rp->custom->description->physics.sleep.angular, params[4]); 2786 SETFLOAT_T(rp->custom->description->physics.sleep.angular, params[4]);
2777 2787
2778 break; 2788 break;
2789 case EDJE_STATE_PARAM_PHYSICS_MATERIAL:
2790 CHKPARAM(3);
2791
2792 SETINT(rp->custom->description->physics.material, params[3]);
2793 break;
2794 case EDJE_STATE_PARAM_PHYSICS_DENSITY:
2795 CHKPARAM(3);
2796
2797 SETFLOAT_T(rp->custom->description->physics.density, params[3]);
2798 break;
2779#endif 2799#endif
2780 default: 2800 default:
2781 break; 2801 break;
diff --git a/legacy/edje/src/lib/edje_private.h b/legacy/edje/src/lib/edje_private.h
index 7587b0715b..e326592348 100644
--- a/legacy/edje/src/lib/edje_private.h
+++ b/legacy/edje/src/lib/edje_private.h
@@ -419,7 +419,9 @@ typedef struct _Edje_Markup_Filter_Callback Edje_Markup_Filter_Callback;
419#define EDJE_STATE_PARAM_PHYSICS_RESTITUTION 45 419#define EDJE_STATE_PARAM_PHYSICS_RESTITUTION 45
420#define EDJE_STATE_PARAM_PHYSICS_DAMPING 46 420#define EDJE_STATE_PARAM_PHYSICS_DAMPING 46
421#define EDJE_STATE_PARAM_PHYSICS_SLEEP 47 421#define EDJE_STATE_PARAM_PHYSICS_SLEEP 47
422#define EDJE_STATE_PARAM_LAST 48 422#define EDJE_STATE_PARAM_PHYSICS_MATERIAL 48
423#define EDJE_STATE_PARAM_PHYSICS_DENSITY 49
424#define EDJE_STATE_PARAM_LAST 50
423 425
424#define EDJE_ENTRY_EDIT_MODE_NONE 0 426#define EDJE_ENTRY_EDIT_MODE_NONE 0
425#define EDJE_ENTRY_EDIT_MODE_SELECTABLE 1 427#define EDJE_ENTRY_EDIT_MODE_SELECTABLE 1
@@ -975,6 +977,7 @@ struct _Edje_Part_Description_Common
975 double mass; 977 double mass;
976 double restitution; 978 double restitution;
977 double friction; 979 double friction;
980 double density;
978 struct { 981 struct {
979 double linear; 982 double linear;
980 double angular; 983 double angular;
@@ -983,6 +986,7 @@ struct _Edje_Part_Description_Common
983 double linear; 986 double linear;
984 double angular; 987 double angular;
985 } sleep; 988 } sleep;
989 unsigned char material; /* (custom, iron, wood, ...) */
986 unsigned char ignore_part_position; 990 unsigned char ignore_part_position;
987 } physics; 991 } physics;
988#endif 992#endif
@@ -1320,6 +1324,7 @@ struct _Edje_Calc_Params
1320 double mass; // 8 1324 double mass; // 8
1321 double restitution; // 8 1325 double restitution; // 8
1322 double friction; // 8 1326 double friction; // 8
1327 double density; // 8
1323 struct { 1328 struct {
1324 double linear; //8 1329 double linear; //8
1325 double angular; //8 1330 double angular; //8
@@ -1328,8 +1333,9 @@ struct _Edje_Calc_Params
1328 double linear; //8 1333 double linear; //8
1329 double angular; //8 1334 double angular; //8
1330 } sleep; // 16 1335 } sleep; // 16
1331 } physics; // 56 1336 unsigned char material; // 1
1332 unsigned char ignore_part_position : 1; 1337 } physics; // 65
1338 unsigned char ignore_part_position : 1; //1
1333#endif 1339#endif
1334 unsigned char persp_on : 1; 1340 unsigned char persp_on : 1;
1335 unsigned char lighted : 1; 1341 unsigned char lighted : 1;