edje: support faces for 3d effects

SVN revision: 80658
This commit is contained in:
Bruno Dilly 2012-12-11 14:09:03 +00:00
parent 0d1b29e5e1
commit c982de65d3
11 changed files with 612 additions and 87 deletions

View File

@ -25,7 +25,7 @@ syn keyword cStructure part parts dragable description rel1 rel2
syn keyword cStatement text image font fill origin size tag syn keyword cStatement text image font fill origin size tag
syn keyword cStructure programs program script script_only lua_script lua_script_only styles style base syn keyword cStructure programs program script script_only lua_script lua_script_only styles style base
syn keyword cStructure spectra spectrum box syn keyword cStructure spectra spectrum box
syn keyword cStructure physics movement_freedom syn keyword cStructure physics movement_freedom faces face
syn match cType "+ + +;" contained syn match cType "+ + +;" contained
syn keyword cLabel item name min max type effect syn keyword cLabel item name min max type effect
@ -73,7 +73,17 @@ syn keyword cConstant BOUNDARY_RIGHT BOUNDARY_FRONT BOUNDARY_BACK
syn keyword cConstant PHYSICS_IMPULSE PHYSICS_TORQUE_IMPULSE syn keyword cConstant PHYSICS_IMPULSE PHYSICS_TORQUE_IMPULSE
syn keyword cConstant PHYSICS_FORCE PHYSICS_TORQUE PHYSICS_STOP syn keyword cConstant PHYSICS_FORCE PHYSICS_TORQUE PHYSICS_STOP
syn keyword cConstant PHYSICS_FORCES_CLEAR PHYSICS_VEL_SET syn keyword cConstant PHYSICS_FORCES_CLEAR PHYSICS_VEL_SET
syn keyword cConstant PHYSICS_ANG_VEL_SET syn keyword cConstant PHYSICS_ANG_VEL_SET BOX_MIDDLE_FRONT
syn keyword cConstant BOX_MIDDLE_BACK BOX_FRONT BOX_BACK BOX_LEFT
syn keyword cConstant BOX_RIGHT BOX_TOP BOX_BOTTOM
syn keyword cConstant CYLINDER_MIDDLE_FRONT CYLINDER_MIDDLE_BACK
syn keyword cConstant CYLINDER_FRONT CYLINDER_BACK CYLINDER_CURVED
syn keyword cConstant CLOTH_FRONT CLOTH_BACK SOFT_BOX_MIDDLE_FRONT
syn keyword cConstant SOFT_BOX_MIDDLE_BACK SOFT_BOX_FRONT
syn keyword cConstant SOFT_BOX_BACK SOFT_BOX_LEFT SOFT_BOX_RIGHT
syn keyword cConstant SOFT_BOX_TOP SOFT_BOX_BOTTOM SOFT_CIRCLE_BACK
syn keyword cConstant SOFT_CIRCLE_MIDDLE_FRONT SOFT_CIRCLE_FRONT
syn keyword cConstant SOFT_CIRCLE_MIDDLE_BACK SOFT_CIRCLE_CURVED
syn keyword cTodo contained TODO FIXME XXX syn keyword cTodo contained TODO FIXME XXX

View File

@ -142,6 +142,7 @@ struct _Edje_Part_Parser
/* global fn calls */ /* global fn calls */
void data_setup(void); void data_setup(void);
void data_write(void); void data_write(void);
void data_queue_face_group_lookup(const char *name);
void data_queue_group_lookup(const char *name, Edje_Part *part); void data_queue_group_lookup(const char *name, Edje_Part *part);
void data_queue_part_lookup(Edje_Part_Collection *pc, const char *name, int *dest); void data_queue_part_lookup(Edje_Part_Collection *pc, const char *name, int *dest);
void data_queue_copied_part_lookup(Edje_Part_Collection *pc, int *src, int *dest); void data_queue_copied_part_lookup(Edje_Part_Collection *pc, int *src, int *dest);

View File

@ -323,6 +323,9 @@ static void st_collections_group_parts_part_description_physics_light_on(void);
static void st_collections_group_parts_part_description_physics_movement_freedom_linear(void); static void st_collections_group_parts_part_description_physics_movement_freedom_linear(void);
static void st_collections_group_parts_part_description_physics_movement_freedom_angular(void); static void st_collections_group_parts_part_description_physics_movement_freedom_angular(void);
static void st_collections_group_parts_part_description_physics_backface_cull(void); static void st_collections_group_parts_part_description_physics_backface_cull(void);
static void st_collections_group_parts_part_description_physics_face(void);
static void st_collections_group_parts_part_description_physics_face_type(void);
static void st_collections_group_parts_part_description_physics_face_source(void);
#endif #endif
static void st_collections_group_parts_part_description_map_perspective(void); static void st_collections_group_parts_part_description_map_perspective(void);
static void st_collections_group_parts_part_description_map_light(void); static void st_collections_group_parts_part_description_map_light(void);
@ -618,6 +621,8 @@ New_Statement_Handler statement_handlers[] =
{"collections.group.parts.part.description.physics.ignore_part_pos", st_collections_group_parts_part_description_physics_ignore_part_pos}, {"collections.group.parts.part.description.physics.ignore_part_pos", st_collections_group_parts_part_description_physics_ignore_part_pos},
{"collections.group.parts.part.description.physics.light_on", st_collections_group_parts_part_description_physics_light_on}, {"collections.group.parts.part.description.physics.light_on", st_collections_group_parts_part_description_physics_light_on},
{"collections.group.parts.part.description.physics.backface_cull", st_collections_group_parts_part_description_physics_backface_cull}, {"collections.group.parts.part.description.physics.backface_cull", st_collections_group_parts_part_description_physics_backface_cull},
{"collections.group.parts.part.description.physics.faces.face.type", st_collections_group_parts_part_description_physics_face_type},
{"collections.group.parts.part.description.physics.faces.face.source", st_collections_group_parts_part_description_physics_face_source},
#endif #endif
{"collections.group.parts.part.description.map.perspective", st_collections_group_parts_part_description_map_perspective}, {"collections.group.parts.part.description.map.perspective", st_collections_group_parts_part_description_map_perspective},
{"collections.group.parts.part.description.map.light", st_collections_group_parts_part_description_map_light}, {"collections.group.parts.part.description.map.light", st_collections_group_parts_part_description_map_light},
@ -867,6 +872,8 @@ New_Object_Handler object_handlers[] =
#ifdef HAVE_EPHYSICS #ifdef HAVE_EPHYSICS
{"collections.group.parts.part.description.physics", NULL}, {"collections.group.parts.part.description.physics", NULL},
{"collections.group.parts.part.description.physics.movement_freedom", NULL}, {"collections.group.parts.part.description.physics.movement_freedom", NULL},
{"collections.group.parts.part.description.physics.faces", NULL},
{"collections.group.parts.part.description.physics.faces.face", st_collections_group_parts_part_description_physics_face},
#endif #endif
{"collections.group.parts.part.description.map", NULL}, {"collections.group.parts.part.description.map", NULL},
{"collections.group.parts.part.description.map.rotation", NULL}, {"collections.group.parts.part.description.map.rotation", NULL},
@ -7217,8 +7224,10 @@ st_collections_group_parts_part_description_table_min(void)
hardness: 0.42; hardness: 0.42;
light_on: 1; light_on: 1;
movement_freedom { movement_freedom {
linear: 1 1 0; ..
angular: 0 0 1; }
faces {
..
} }
} }
.. ..
@ -7609,6 +7618,158 @@ st_collections_group_parts_part_description_physics_movement_freedom_angular(voi
} }
#endif #endif
/**
@page edcref
@block
faces
@context
faces {
face {
type: BOX_FRONT;
source: "groupname";
}
..
}
@description
The "faces" block contains a list of one or more "face" blocks.
The "faces" block is used to list the faces that compose the body.
Each face is described by a "face" block, that associates a part
to a specific face of the body's shape.
Only the "faces" block declared in the "default" description
will be considered.
@endblock
*/
#ifdef HAVE_EPHYSICS
static void
st_collections_group_parts_part_description_physics_face(void)
{
Edje_Physics_Face *pface;
pface = mem_alloc(SZ(Edje_Physics_Face));
current_desc->physics.faces = eina_list_append(current_desc->physics.faces,
pface);
pface->type = 0;
pface->source = NULL;
}
#endif
/**
@page edcref
@property
type
@parameters
[FACE]
@effect
Set the face (all caps) from among the available body's shape faces.
Valid faces:
* BOX_MIDDLE_FRONT,
* BOX_MIDDLE_BACK,
* BOX_FRONT,
* BOX_BACK,
* BOX_LEFT,
* BOX_RIGHT,
* BOX_TOP,
* BOX_BOTTOM,
* CYLINDER_MIDDLE_FRONT,
* CYLINDER_MIDDLE_BACK,
* CYLINDER_FRONT,
* CYLINDER_BACK,
* CYLINDER_CURVED,
* CLOTH_FRONT,
* CLOTH_BACK
* SOFT_BOX_MIDDLE_FRONT,
* SOFT_BOX_MIDDLE_BACK,
* SOFT_BOX_FRONT,
* SOFT_BOX_BACK,
* SOFT_BOX_LEFT,
* SOFT_BOX_RIGHT,
* SOFT_BOX_TOP,
* SOFT_BOX_BOTTOM,
* SOFT_CIRCLE_MIDDLE_FRONT,
* SOFT_CIRCLE_MIDDLE_BACK,
* SOFT_CIRCLE_FRONT,
* SOFT_CIRCLE_BACK,
* SOFT_CIRCLE_CURVED,
@endproperty
*/
#ifdef HAVE_EPHYSICS
static void
st_collections_group_parts_part_description_physics_face_type(void)
{
Edje_Physics_Face *pface, *pface2;
Eina_List *l;
pface = eina_list_data_get(eina_list_last(current_desc->physics.faces));
pface->type = parse_enum(0,
"BOX_MIDDLE_FRONT", EPHYSICS_BODY_BOX_FACE_MIDDLE_FRONT,
"BOX_MIDDLE_BACK", EPHYSICS_BODY_BOX_FACE_MIDDLE_BACK,
"BOX_FRONT", EPHYSICS_BODY_BOX_FACE_FRONT,
"BOX_BACK", EPHYSICS_BODY_BOX_FACE_BACK,
"BOX_LEFT", EPHYSICS_BODY_BOX_FACE_LEFT,
"BOX_RIGHT", EPHYSICS_BODY_BOX_FACE_RIGHT,
"BOX_TOP", EPHYSICS_BODY_BOX_FACE_TOP,
"BOX_BOTTOM", EPHYSICS_BODY_BOX_FACE_BOTTOM,
"CYLINDER_MIDDLE_FRONT", EPHYSICS_BODY_CYLINDER_FACE_MIDDLE_FRONT,
"CYLINDER_MIDDLE_BACK", EPHYSICS_BODY_CYLINDER_FACE_MIDDLE_BACK,
"CYLINDER_FRONT", EPHYSICS_BODY_CYLINDER_FACE_FRONT,
"CYLINDER_BACK", EPHYSICS_BODY_CYLINDER_FACE_BACK,
"CYLINDER_CURVED", EPHYSICS_BODY_CYLINDER_FACE_CURVED,
"CLOTH_FRONT", EPHYSICS_BODY_CLOTH_FACE_FRONT,
"CLOTH_BACK", EPHYSICS_BODY_CLOTH_FACE_BACK,
"SOFT_ELLIPSOID_FRONT", EPHYSICS_BODY_SOFT_ELLIPSOID_FACE_FRONT,
"SOFT_ELLIPSOID_BACK", EPHYSICS_BODY_SOFT_ELLIPSOID_FACE_BACK,
"SOFT_BOX_MIDDLE_FRONT", EPHYSICS_BODY_SOFT_BOX_FACE_MIDDLE_FRONT,
"SOFT_BOX_MIDDLE_BACK", EPHYSICS_BODY_SOFT_BOX_FACE_MIDDLE_BACK,
"SOFT_BOX_FRONT", EPHYSICS_BODY_SOFT_BOX_FACE_FRONT,
"SOFT_BOX_BACK", EPHYSICS_BODY_SOFT_BOX_FACE_BACK,
"SOFT_BOX_LEFT", EPHYSICS_BODY_SOFT_BOX_FACE_LEFT,
"SOFT_BOX_RIGHT", EPHYSICS_BODY_SOFT_BOX_FACE_RIGHT,
"SOFT_BOX_TOP", EPHYSICS_BODY_SOFT_BOX_FACE_TOP,
"SOFT_BOX_BOTTOM", EPHYSICS_BODY_SOFT_BOX_FACE_BOTTOM,
"SOFT_CIRCLE_MIDDLE_FRONT", EPHYSICS_BODY_SOFT_CIRCLE_FACE_MIDDLE_FRONT,
"SOFT_CIRCLE_MIDDLE_BACK", EPHYSICS_BODY_SOFT_CIRCLE_FACE_MIDDLE_BACK,
"SOFT_CIRCLE_FRONT", EPHYSICS_BODY_SOFT_CIRCLE_FACE_FRONT,
"SOFT_CIRCLE_BACK", EPHYSICS_BODY_SOFT_CIRCLE_FACE_BACK,
"SOFT_CIRCLE_CURVES", EPHYSICS_BODY_SOFT_CIRCLE_FACE_CURVED,
NULL);
EINA_LIST_FOREACH(current_desc->physics.faces, l, pface2)
{
if ((pface != pface2) && (pface->type == pface2->type))
{
ERR("parse error %s:%i. There is already a face of type \"%i\"",
file_in, line - 1, pface->type);
exit(-1);
}
}
}
#endif
/**
@page edcref
@property
source
@parameters
[another group's name]
@effect
This sets the group that is used as the object representing the physics
body face.
@endproperty
*/
#ifdef HAVE_EPHYSICS
static void
st_collections_group_parts_part_description_physics_face_source(void)
{
Edje_Physics_Face *pface;
pface = eina_list_data_get(eina_list_last(current_desc->physics.faces));
check_arg_count(1);
pface->source = parse_str(0);
data_queue_face_group_lookup(pface->source);
}
#endif
/** /**
@edcsubsection{collections_group_parts_description_map,Map} @edcsubsection{collections_group_parts_description_map,Map}
*/ */

View File

@ -195,6 +195,7 @@ static Eet_Data_Descriptor *edd_edje_part_collection = NULL;
static Eina_List *program_lookups = NULL; static Eina_List *program_lookups = NULL;
static Eina_List *group_lookups = NULL; static Eina_List *group_lookups = NULL;
static Eina_List *face_group_lookups = NULL;
static Eina_List *image_lookups = NULL; static Eina_List *image_lookups = NULL;
static Eina_List *part_slave_lookups = NULL; static Eina_List *part_slave_lookups = NULL;
static Eina_List *image_slave_lookups= NULL; static Eina_List *image_slave_lookups= NULL;
@ -1773,6 +1774,17 @@ data_queue_group_lookup(const char *name, Edje_Part *part)
gl->part = part; gl->part = part;
} }
void
data_queue_face_group_lookup(const char *name)
{
char *group_name;
if (!name || !name[0]) return;
group_name = mem_strdup(name);
face_group_lookups = eina_list_append(face_group_lookups, group_name);
}
void void
data_queue_part_lookup(Edje_Part_Collection *pc, const char *name, int *dest) data_queue_part_lookup(Edje_Part_Collection *pc, const char *name, int *dest)
{ {
@ -2030,6 +2042,7 @@ data_process_lookups(void)
Eina_List *l; Eina_List *l;
Eina_Hash *images_in_use; Eina_Hash *images_in_use;
void *data; void *data;
char *group_name;
Eina_Bool is_lua = EINA_FALSE; Eina_Bool is_lua = EINA_FALSE;
/* remove all unreferenced Edje_Part_Collection */ /* remove all unreferenced Edje_Part_Collection */
@ -2227,6 +2240,34 @@ free_group:
free(group); free(group);
} }
EINA_LIST_FREE(face_group_lookups, group_name)
{
Edje_Part_Collection_Directory_Entry *de;
de = eina_hash_find(edje_file->collection, group_name);
if (!de)
{
Eina_Bool found = EINA_FALSE;
EINA_LIST_FOREACH(aliases, l, de)
if (strcmp(de->entry, group_name) == 0)
{
found = EINA_TRUE;
break;
}
if (!found) de = NULL;
}
if (!de)
{
ERR("Unable to find group name \"%s\".", group_name);
exit(-1);
}
free(group_name);
}
images_in_use = eina_hash_string_superfast_new(NULL); images_in_use = eina_hash_string_superfast_new(NULL);
EINA_LIST_FREE(image_lookups, image) EINA_LIST_FREE(image_lookups, image)

View File

@ -56,6 +56,7 @@ if ENABLE_EPHYSICS
EDCS += \ EDCS += \
physics_3d.edc \ physics_3d.edc \
physics_actions.edc \ physics_actions.edc \
physics_backcull.edc \
physics_basic.edc \ physics_basic.edc \
physics_complex.edc \ physics_complex.edc \
physics_soft_bodies.edc physics_soft_bodies.edc

View File

@ -1,27 +1,101 @@
/* It can be tested with edje_player slave mode /* It can be tested with edje_player slave mode
* $ edje_player -S -p physics_3d.edj * $ edje_player -S -p -g example_group physics_3d.edj
* *
* signal on backcull -> allow movement in all axes, enable backface cull * message 1 FLOAT_SET 3 80 -100 0 -> apply an impulse on red box with
* signal off backcull -> allow movement in all axes, disable backface cull
*
* message 1 FLOAT_SET 3 50 -100 0 -> apply an impulse on red box with
* x = 50, y = -100, z = 0, for example * x = 50, y = -100, z = 0, for example
* message 2 FLOAT_SET 3 0 0 8.2 -> apply a torque impulse on red box with * message 2 FLOAT_SET 3 0 100 0 -> apply a torque impulse on red box with
* x = 4, y = 0, z = 0.8, for example * x = 4, y = 0, z = 0.8, for example
* message 3 FLOAT_SET 3 0 1 0 -> allow linear movement on axes x, y, z
* message 4 FLOAT_SET 3 0 1 0 -> allow angular movement on axes x, y, z
* message 5 STRING "linear" -> return a message with part's movement freedom
* for "linear" or "angular.
*/ */
#define ID_IMPULSE (1) #define ID_IMPULSE (1)
#define ID_TORQUE_IMPULSE (2) #define ID_TORQUE_IMPULSE (2)
#define ID_LIN_SET (3)
#define ID_ANG_SET (4)
#define ID_GET (5)
collections { collections {
group {
name: "right";
parts {
part {
name: "face";
type: RECT;
description {
state: "default" 0.0;
color: 0 0 255 255; /* blue */
}
}
}
}
group {
name: "left";
parts {
part {
name: "face";
type: RECT;
description {
state: "default" 0.0;
color: 0 255 0 255; /* green */
}
}
}
}
group {
name: "front";
parts {
part {
name: "face";
type: RECT;
description {
state: "default" 0.0;
color: 0 0 0 255; /* black */
}
}
}
}
group {
name: "back";
parts {
part {
name: "face";
type: RECT;
description {
state: "default" 0.0;
color: 120 120 120 255; /* gray */
}
}
}
}
group {
name: "top";
parts {
part {
name: "face";
type: RECT;
description {
state: "default" 0.0;
color: 255 0 255 255; /* purple */
}
}
}
}
group {
name: "bottom";
parts {
part {
name: "face";
type: RECT;
description {
state: "default" 0.0;
color: 0 255 255 255; /* yellow */
}
}
}
}
group { group {
name: "example_group"; name: "example_group";
@ -45,47 +119,6 @@ collections {
z = getfarg(4); z = getfarg(4);
physics_torque_impulse(PART:"red_box", x, y, z); physics_torque_impulse(PART:"red_box", x, y, z);
} }
else if ((id == ID_LIN_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);
custom_state(PART:"red_box", "default", 0.0);
set_state_val(PART:"red_box", STATE_PHYSICS_MOV_FREEDOM_LIN,
x, y, z);
set_state(PART:"red_box", "custom", 0.0);
}
else if ((id == ID_ANG_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);
custom_state(PART:"red_box", "default", 0.0);
set_state_val(PART:"red_box", STATE_PHYSICS_MOV_FREEDOM_ANG,
x, y, z);
set_state(PART:"red_box", "custom", 0.0);
}
else if ((id == ID_GET) && (type == MSG_STRING)) {
new Float:x, Float:y, Float:z;
new name[1024];
getsarg(2, name, sizeof(name));
if (!strcmp(name, "linear"))
{
get_state_val(PART:"red_box",
STATE_PHYSICS_MOV_FREEDOM_LIN, x, y, z);
send_message(MSG_STRING_FLOAT_SET, 1, "Linear", x, y, z);
}
else if (!strcmp(name, "angular"))
{
get_state_val(PART:"red_box",
STATE_PHYSICS_MOV_FREEDOM_ANG, x, y, z);
send_message(MSG_STRING_FLOAT_SET, 1, "Angular", x, y, z);
}
}
} }
} }
@ -109,8 +142,8 @@ collections {
description { description {
state: "default" 0.0; state: "default" 0.0;
color: 255 0 0 255; /* light red */ color: 255 0 0 255; /* light red */
rel1.relative: 0.45 0.1; rel1.relative: 0.4 0.1;
rel2.relative: 0.55 0.2; rel2.relative: 0.55 0.3;
aspect: 1 1; aspect: 1 1;
physics { physics {
mass: 30; mass: 30;
@ -119,13 +152,34 @@ collections {
linear: 1 1 1; linear: 1 1 1;
angular: 1 1 1; angular: 1 1 1;
} }
faces {
face {
type: BOX_FRONT;
source: "front";
}
face {
type: BOX_BACK;
source: "back";
}
face {
type: BOX_TOP;
source: "top";
}
face {
type: BOX_BOTTOM;
source: "bottom";
}
face {
type: BOX_LEFT;
source: "left";
}
face {
type: BOX_RIGHT;
source: "right";
}
}
} }
} }
description {
state: "backface_culled" 0.0;
inherit: "default" 0.0;
physics.backface_cull: 1;
}
} }
part { part {
@ -194,24 +248,5 @@ collections {
} }
} }
programs {
program {
name: "backcull,on";
signal: "on";
source: "backcull";
action: STATE_SET "backface_culled" 0.0;
target: "red_box";
}
program {
name: "backcull,off";
signal: "off";
source: "backcull";
action: STATE_SET "default" 0.0;
target: "red_box";
}
}
} }
} }

View File

@ -0,0 +1,217 @@
/* It can be tested with edje_player slave mode
* $ edje_player -S -p physics_backcull.edj
*
* signal on backcull -> allow movement in all axes, enable backface cull
* signal off backcull -> allow movement in all axes, disable backface cull
*
* message 1 FLOAT_SET 3 50 -100 0 -> apply an impulse on red box with
* x = 50, y = -100, z = 0, for example
* message 2 FLOAT_SET 3 0 0 8.2 -> apply a torque impulse on red box with
* x = 4, y = 0, z = 0.8, for example
* message 3 FLOAT_SET 3 0 1 0 -> allow linear movement on axes x, y, z
* message 4 FLOAT_SET 3 0 1 0 -> allow angular movement on axes x, y, z
* message 5 STRING "linear" -> return a message with part's movement freedom
* for "linear" or "angular.
*/
#define ID_IMPULSE (1)
#define ID_TORQUE_IMPULSE (2)
#define ID_LIN_SET (3)
#define ID_ANG_SET (4)
#define ID_GET (5)
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:"red_box", x, y, z);
}
else if ((id == ID_TORQUE_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_torque_impulse(PART:"red_box", x, y, z);
}
else if ((id == ID_LIN_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);
custom_state(PART:"red_box", "default", 0.0);
set_state_val(PART:"red_box", STATE_PHYSICS_MOV_FREEDOM_LIN,
x, y, z);
set_state(PART:"red_box", "custom", 0.0);
}
else if ((id == ID_ANG_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);
custom_state(PART:"red_box", "default", 0.0);
set_state_val(PART:"red_box", STATE_PHYSICS_MOV_FREEDOM_ANG,
x, y, z);
set_state(PART:"red_box", "custom", 0.0);
}
else if ((id == ID_GET) && (type == MSG_STRING)) {
new Float:x, Float:y, Float:z;
new name[1024];
getsarg(2, name, sizeof(name));
if (!strcmp(name, "linear"))
{
get_state_val(PART:"red_box",
STATE_PHYSICS_MOV_FREEDOM_LIN, x, y, z);
send_message(MSG_STRING_FLOAT_SET, 1, "Linear", x, y, z);
}
else if (!strcmp(name, "angular"))
{
get_state_val(PART:"red_box",
STATE_PHYSICS_MOV_FREEDOM_ANG, x, y, z);
send_message(MSG_STRING_FLOAT_SET, 1, "Angular", x, y, z);
}
}
}
}
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: "red_box";
type: RECT;
physics_body: RIGID_BOX;
description {
state: "default" 0.0;
color: 255 0 0 255; /* light red */
rel1.relative: 0.45 0.1;
rel2.relative: 0.55 0.2;
aspect: 1 1;
physics {
mass: 30;
restitution: 0.85;
movement_freedom {
linear: 1 1 1;
angular: 1 1 1;
}
}
}
description {
state: "backface_culled" 0.0;
inherit: "default" 0.0;
physics.backface_cull: 1;
}
}
part {
name: "floor";
type: RECT;
physics_body: BOUNDARY_BOTTOM;
description {
state: "default" 0.0;
visible: 0;
physics {
restitution: 0.8;
}
}
}
part {
name: "front";
type: RECT;
physics_body: BOUNDARY_FRONT;
description {
state: "default" 0.0;
visible: 0;
physics {
restitution: 0.4;
}
}
}
part {
name: "back";
type: RECT;
physics_body: BOUNDARY_BACK;
description {
state: "default" 0.0;
visible: 0;
physics {
restitution: 0.4;
}
}
}
part {
name: "left";
type: RECT;
physics_body: BOUNDARY_LEFT;
description {
state: "default" 0.0;
visible: 0;
physics {
restitution: 0.4;
}
}
}
part {
name: "right";
type: RECT;
physics_body: BOUNDARY_RIGHT;
description {
state: "default" 0.0;
visible: 0;
physics {
restitution: 0.4;
}
}
}
}
programs {
program {
name: "backcull,on";
signal: "on";
source: "backcull";
action: STATE_SET "backface_culled" 0.0;
target: "red_box";
}
program {
name: "backcull,off";
signal: "off";
source: "backcull";
action: STATE_SET "default" 0.0;
target: "red_box";
}
}
}
}

View File

@ -2539,6 +2539,8 @@ static void
_edje_physics_body_add(Edje_Real_Part *rp, EPhysics_World *world) _edje_physics_body_add(Edje_Real_Part *rp, EPhysics_World *world)
{ {
Eina_Bool resize = EINA_TRUE; Eina_Bool resize = EINA_TRUE;
Edje_Physics_Face *pface;
Eina_List *l;
switch (rp->part->physics_body) switch (rp->part->physics_body)
{ {
@ -2586,6 +2588,24 @@ _edje_physics_body_add(Edje_Real_Part *rp, EPhysics_World *world)
return; return;
} }
EINA_LIST_FOREACH(rp->part->default_desc->physics.faces, l, pface)
{
Evas_Object *edje_obj;
Evas *evas;
if (!pface->source) continue;
evas = evas_object_evas_get(rp->object);
edje_obj = edje_object_add(evas);
if (!edje_obj) continue;
edje_object_file_set(edje_obj, rp->edje->path, pface->source);
evas_object_resize(edje_obj, 1, 1);
ephysics_body_face_evas_object_set(rp->body, pface->type,
edje_obj, EINA_FALSE);
rp->body_faces = eina_list_append(rp->body_faces, edje_obj);
}
ephysics_body_evas_object_set(rp->body, rp->object, resize); ephysics_body_evas_object_set(rp->body, rp->object, resize);
ephysics_body_event_callback_add(rp->body, EPHYSICS_CALLBACK_BODY_UPDATE, ephysics_body_event_callback_add(rp->body, EPHYSICS_CALLBACK_BODY_UPDATE,
_edje_physics_body_update_cb, rp); _edje_physics_body_update_cb, rp);
@ -3190,12 +3210,24 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
#ifdef HAVE_EPHYSICS #ifdef HAVE_EPHYSICS
/* body attributes should be updated for invisible objects */ /* body attributes should be updated for invisible objects */
if (!pf->visible) if (!ep->part->physics_body)
{ {
if (!pf->visible)
{
evas_object_hide(ep->object);
break;
}
evas_object_show(ep->object);
}
else if (!pf->visible)
{
Evas_Object *face_obj;
Eina_List *l;
EINA_LIST_FOREACH(ep->body_faces, l, face_obj)
evas_object_hide(face_obj);
evas_object_hide(ep->object); evas_object_hide(ep->object);
} }
else
evas_object_show(ep->object);
#else #else
if (!pf->visible) if (!pf->visible)
{ {

View File

@ -56,6 +56,7 @@ Eet_Data_Descriptor *_edje_edd_edje_part_image_id = NULL;
Eet_Data_Descriptor *_edje_edd_edje_part_image_id_pointer = NULL; Eet_Data_Descriptor *_edje_edd_edje_part_image_id_pointer = NULL;
Eet_Data_Descriptor *_edje_edd_edje_external_param = NULL; Eet_Data_Descriptor *_edje_edd_edje_external_param = NULL;
Eet_Data_Descriptor *_edje_edd_edje_part_limit = NULL; Eet_Data_Descriptor *_edje_edd_edje_part_limit = NULL;
Eet_Data_Descriptor *_edje_edd_edje_physics_face = NULL;
#define EMP(Type, Minus) \ #define EMP(Type, Minus) \
EAPI Eina_Mempool *_emp_##Type = NULL; \ EAPI Eina_Mempool *_emp_##Type = NULL; \
@ -220,6 +221,7 @@ _edje_edd_shutdown(void)
FREED(_edje_edd_edje_image_directory_set); FREED(_edje_edd_edje_image_directory_set);
FREED(_edje_edd_edje_image_directory_set_entry); FREED(_edje_edd_edje_image_directory_set_entry);
FREED(_edje_edd_edje_part_limit); FREED(_edje_edd_edje_part_limit);
FREED(_edje_edd_edje_physics_face);
} }
#define EDJE_DEFINE_POINTER_TYPE(Type, Name) \ #define EDJE_DEFINE_POINTER_TYPE(Type, Name) \
@ -458,6 +460,11 @@ _edje_edd_init(void)
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_external_param, Edje_External_Param, "d", d, EET_T_DOUBLE); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_external_param, Edje_External_Param, "d", d, EET_T_DOUBLE);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_external_param, Edje_External_Param, "s", s, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_external_param, Edje_External_Param, "s", s, EET_T_STRING);
EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Edje_Physics_Face);
_edje_edd_edje_physics_face = eet_data_descriptor_file_new(&eddc);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_physics_face, Edje_Physics_Face, "type", type, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_physics_face, Edje_Physics_Face, "source", source, EET_T_STRING);
#define EDJE_DATA_DESCRIPTOR_DESCRIPTION_COMMON_FIELDS(Edd, Type) \ #define EDJE_DATA_DESCRIPTOR_DESCRIPTION_COMMON_FIELDS(Edd, Type) \
EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "state.name", state.name, EET_T_STRING); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "state.name", state.name, EET_T_STRING); \
EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "state.value", state.value, EET_T_DOUBLE); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "state.value", state.value, EET_T_DOUBLE); \
@ -539,6 +546,7 @@ _edje_edd_init(void)
EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mov_freedom.ang.x", physics.mov_freedom.ang.x, EET_T_UCHAR); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mov_freedom.ang.x", physics.mov_freedom.ang.x, EET_T_UCHAR); \
EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mov_freedom.ang.y", physics.mov_freedom.ang.y, EET_T_UCHAR); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mov_freedom.ang.y", physics.mov_freedom.ang.y, EET_T_UCHAR); \
EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mov_freedom.ang.z", physics.mov_freedom.ang.z, EET_T_UCHAR); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mov_freedom.ang.z", physics.mov_freedom.ang.z, EET_T_UCHAR); \
EET_DATA_DESCRIPTOR_ADD_LIST(Edd, Type, "physics.faces", physics.faces, _edje_edd_edje_physics_face); \
} }
#else #else
#define EDJE_DATA_DESCRIPTOR_DESCRIPTION_COMMON(Edd, Type) \ #define EDJE_DATA_DESCRIPTOR_DESCRIPTION_COMMON(Edd, Type) \
@ -622,6 +630,7 @@ _edje_edd_init(void)
EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mov_freedom.ang.x", Dec.physics.mov_freedom.ang.x, EET_T_UCHAR); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mov_freedom.ang.x", Dec.physics.mov_freedom.ang.x, EET_T_UCHAR); \
EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mov_freedom.ang.y", Dec.physics.mov_freedom.ang.y, EET_T_UCHAR); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mov_freedom.ang.y", Dec.physics.mov_freedom.ang.y, EET_T_UCHAR); \
EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mov_freedom.ang.z", Dec.physics.mov_freedom.ang.z, EET_T_UCHAR); \ EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "physics.mov_freedom.ang.z", Dec.physics.mov_freedom.ang.z, EET_T_UCHAR); \
EET_DATA_DESCRIPTOR_ADD_LIST(Edd, Type, "physics.faces", Dec.physics.faces, _edje_edd_edje_physics_face); \
} }
#else #else
#define EDJE_DATA_DESCRIPTOR_DESCRIPTION_COMMON_SUB(Edd, Type, Dec) \ #define EDJE_DATA_DESCRIPTOR_DESCRIPTION_COMMON_SUB(Edd, Type, Dec) \

View File

@ -1300,8 +1300,17 @@ _edje_file_del(Edje *ed)
for (i = 0; i < ed->table_parts_size; i++) for (i = 0; i < ed->table_parts_size; i++)
{ {
Edje_Real_Part *rp; Edje_Real_Part *rp;
#ifdef HAVE_EPHYSICS
Evas_Object *face_obj;
#endif
rp = ed->table_parts[i]; rp = ed->table_parts[i];
#ifdef HAVE_EPHYSICS
EINA_LIST_FREE(rp->body_faces, face_obj)
evas_object_del(face_obj);
#endif
if (rp->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE) if (rp->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE)
_edje_entry_real_part_shutdown(rp); _edje_entry_real_part_shutdown(rp);
if (rp->object) if (rp->object)

View File

@ -315,6 +315,7 @@ typedef struct _Edje_Part_Description_Spec_Proxy Edje_Part_Description_Spec_
typedef struct _Edje_Part_Description_Spec_Text Edje_Part_Description_Spec_Text; typedef struct _Edje_Part_Description_Spec_Text Edje_Part_Description_Spec_Text;
typedef struct _Edje_Part_Description_Spec_Box Edje_Part_Description_Spec_Box; typedef struct _Edje_Part_Description_Spec_Box Edje_Part_Description_Spec_Box;
typedef struct _Edje_Part_Description_Spec_Table Edje_Part_Description_Spec_Table; typedef struct _Edje_Part_Description_Spec_Table Edje_Part_Description_Spec_Table;
typedef struct _Edje_Physics_Face Edje_Physics_Face;
typedef struct _Edje_Patterns Edje_Patterns; typedef struct _Edje_Patterns Edje_Patterns;
typedef struct _Edje_Part_Box_Animation Edje_Part_Box_Animation; typedef struct _Edje_Part_Box_Animation Edje_Part_Box_Animation;
typedef struct _Edje_Part_Limit Edje_Part_Limit; typedef struct _Edje_Part_Limit Edje_Part_Limit;
@ -751,6 +752,12 @@ struct _Edje_Pack_Element
unsigned short colspan, rowspan; unsigned short colspan, rowspan;
}; };
struct _Edje_Physics_Face
{
unsigned char type; /* BOX_FRONT BOX_BACK BOX_RIGHT CYLINDER_BACK ... */
const char *source; /* group name to use as source for this element */
};
typedef enum { typedef enum {
EDJE_PART_LIMIT_UNKNOWN = 0, EDJE_PART_LIMIT_UNKNOWN = 0,
EDJE_PART_LIMIT_BELOW, EDJE_PART_LIMIT_BELOW,
@ -994,6 +1001,7 @@ struct _Edje_Part_Description_Common
double linear; double linear;
double angular; double angular;
} sleep; } sleep;
Eina_List *faces; /* faces for 3d effects */
struct { struct {
struct { struct {
unsigned char x; unsigned char x;
@ -1487,6 +1495,7 @@ struct _Edje_Real_Part
#ifdef HAVE_EPHYSICS #ifdef HAVE_EPHYSICS
Edje_Part_Description_Common *prev_description; // 4 Edje_Part_Description_Common *prev_description; // 4
EPhysics_Body *body; // 4 EPhysics_Body *body; // 4
Eina_List *body_faces; // 4
#endif #endif
union { union {
Edje_Real_Part_Text *text; Edje_Real_Part_Text *text;