ephysics: small fixes on grab test
Remove unneeded field of drag structure and vars, rename vars, add checks, fix indenting. SVN revision: 79053
This commit is contained in:
parent
6b66a1854a
commit
b25a7d2816
|
@ -4,71 +4,68 @@
|
||||||
|
|
||||||
#include "ephysics_test.h"
|
#include "ephysics_test.h"
|
||||||
|
|
||||||
typedef struct _Dragging_Data
|
typedef struct _Dragging_Data {
|
||||||
{
|
int mouse_status; // 0, up, 1, down
|
||||||
int mouse_status; // 0, up, 1, down
|
double curr_mass;
|
||||||
EPhysics_Body *body;
|
struct {
|
||||||
double curr_mass;
|
int x;
|
||||||
struct {
|
int y;
|
||||||
int x;
|
} clicked_position;
|
||||||
int y;
|
|
||||||
} clicked_position;
|
|
||||||
} Dragging_Data;
|
} Dragging_Data;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_on_delete(void *data __UNUSED__, EPhysics_Body *body, void *event_info __UNUSED__)
|
_on_delete(void *data __UNUSED__, EPhysics_Body *body, void *event_info __UNUSED__)
|
||||||
{
|
{
|
||||||
Dragging_Data *dragging = ephysics_body_data_get(body);
|
Dragging_Data *dragging = ephysics_body_data_get(body);
|
||||||
free(dragging);
|
if (dragging)
|
||||||
|
free(dragging);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_mouse_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
_mouse_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
|
||||||
{
|
{
|
||||||
Dragging_Data *dragging = ephysics_body_data_get(data);
|
Dragging_Data *dragging = ephysics_body_data_get(data);
|
||||||
Evas_Event_Mouse_Down *mdown = event_info;
|
Evas_Event_Mouse_Down *mdown = event_info;
|
||||||
Evas_Coord x, y;
|
Evas_Coord x, y;
|
||||||
|
|
||||||
evas_object_geometry_get(obj, &x, &y, NULL, NULL);
|
evas_object_geometry_get(obj, &x, &y, NULL, NULL);
|
||||||
dragging->mouse_status = 1;
|
dragging->mouse_status = 1;
|
||||||
dragging->clicked_position.x = mdown->output.x - x;
|
dragging->clicked_position.x = mdown->output.x - x;
|
||||||
dragging->clicked_position.y = mdown->output.y - y;
|
dragging->clicked_position.y = mdown->output.y - y;
|
||||||
ephysics_body_mass_get(data);
|
dragging->curr_mass = ephysics_body_mass_get(data);
|
||||||
dragging->curr_mass = ephysics_body_mass_get(data);
|
ephysics_body_mass_set(data, 0);
|
||||||
ephysics_body_mass_set(data, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||||
{
|
{
|
||||||
Dragging_Data *dragging = ephysics_body_data_get(data);
|
Dragging_Data *dragging = ephysics_body_data_get(data);
|
||||||
dragging->mouse_status = 0;
|
dragging->mouse_status = 0;
|
||||||
ephysics_body_mass_set(data, dragging->curr_mass);
|
ephysics_body_mass_set(data, dragging->curr_mass);
|
||||||
dragging->curr_mass = 0;
|
dragging->curr_mass = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
|
_mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
|
||||||
{
|
{
|
||||||
Dragging_Data *dragging = ephysics_body_data_get(data);
|
EPhysics_Body *body = data;
|
||||||
Evas_Event_Mouse_Move *mmove = event_info;
|
Dragging_Data *dragging = ephysics_body_data_get(body);
|
||||||
Evas_Coord x, y, w, h, nx, ny;
|
Evas_Event_Mouse_Move *mmove = event_info;
|
||||||
|
Evas_Coord nx, ny;
|
||||||
|
|
||||||
if (!dragging->mouse_status) return;
|
if (!dragging->mouse_status) return;
|
||||||
|
|
||||||
nx = mmove->cur.output.x - dragging->clicked_position.x;
|
nx = mmove->cur.output.x - dragging->clicked_position.x;
|
||||||
ny = mmove->cur.output.y - dragging->clicked_position.y;
|
ny = mmove->cur.output.y - dragging->clicked_position.y;
|
||||||
|
|
||||||
if (nx < 0 || ny < 0) return;
|
if (nx < 0 || ny < 0) return;
|
||||||
|
ephysics_body_move(body, nx, ny, -15);
|
||||||
evas_object_geometry_get(obj, &x, &y, &w, &h);
|
|
||||||
ephysics_body_move(dragging->body, nx, ny, -15);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_box_add(Test_Data *test_data, Evas_Coord x, Evas_Coord y, const char *file)
|
_box_add(Test_Data *test_data, Evas_Coord x, Evas_Coord y, const char *file)
|
||||||
{
|
{
|
||||||
Evas_Object *evas, *shadow;
|
Evas_Object *evas_obj, *shadow;
|
||||||
EPhysics_Body *body;
|
EPhysics_Body *body;
|
||||||
Dragging_Data *dragging;
|
Dragging_Data *dragging;
|
||||||
|
|
||||||
|
@ -80,34 +77,31 @@ _box_add(Test_Data *test_data, Evas_Coord x, Evas_Coord y, const char *file)
|
||||||
evas_object_show(shadow);
|
evas_object_show(shadow);
|
||||||
test_data->evas_objs = eina_list_append(test_data->evas_objs, shadow);
|
test_data->evas_objs = eina_list_append(test_data->evas_objs, shadow);
|
||||||
|
|
||||||
evas = elm_image_add(test_data->win);
|
evas_obj = elm_image_add(test_data->win);
|
||||||
elm_image_file_set(
|
elm_image_file_set(
|
||||||
evas, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", file);
|
evas_obj, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", file);
|
||||||
evas_object_move(evas, x, y - 70);
|
evas_object_move(evas_obj, x, y - 70);
|
||||||
evas_object_resize(evas, 70, 70);
|
evas_object_resize(evas_obj, 70, 70);
|
||||||
evas_object_show(evas);
|
evas_object_show(evas_obj);
|
||||||
test_data->evas_objs = eina_list_append(test_data->evas_objs, evas);
|
test_data->evas_objs = eina_list_append(test_data->evas_objs, evas_obj);
|
||||||
|
|
||||||
body = ephysics_body_box_add(test_data->world);
|
body = ephysics_body_box_add(test_data->world);
|
||||||
ephysics_body_evas_object_set(body, evas, EINA_TRUE);
|
ephysics_body_evas_object_set(body, evas_obj, EINA_TRUE);
|
||||||
ephysics_body_event_callback_add(body, EPHYSICS_CALLBACK_BODY_UPDATE,
|
ephysics_body_event_callback_add(body, EPHYSICS_CALLBACK_BODY_UPDATE,
|
||||||
update_object_cb, shadow);
|
update_object_cb, shadow);
|
||||||
test_data->bodies = eina_list_append(test_data->bodies, body);
|
test_data->bodies = eina_list_append(test_data->bodies, body);
|
||||||
test_data->data = body;
|
|
||||||
|
|
||||||
dragging = calloc(1, sizeof(Dragging_Data));
|
dragging = calloc(1, sizeof(Dragging_Data));
|
||||||
dragging->body = body;
|
|
||||||
ephysics_body_data_set(body, dragging);
|
ephysics_body_data_set(body, dragging);
|
||||||
|
|
||||||
evas_object_event_callback_add(evas, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down_cb,
|
evas_object_event_callback_add(evas_obj, EVAS_CALLBACK_MOUSE_DOWN,
|
||||||
body);
|
_mouse_down_cb, body);
|
||||||
evas_object_event_callback_add(evas, EVAS_CALLBACK_MOUSE_UP, _mouse_up_cb,
|
evas_object_event_callback_add(evas_obj, EVAS_CALLBACK_MOUSE_UP,
|
||||||
body);
|
_mouse_up_cb, body);
|
||||||
evas_object_event_callback_add(evas, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move_cb,
|
evas_object_event_callback_add(evas_obj, EVAS_CALLBACK_MOUSE_MOVE,
|
||||||
body);
|
_mouse_move_cb, body);
|
||||||
|
ephysics_body_event_callback_add(body, EPHYSICS_CALLBACK_BODY_DEL,
|
||||||
ephysics_body_event_callback_add(body, EPHYSICS_CALLBACK_BODY_DEL, _on_delete,
|
_on_delete, NULL);
|
||||||
NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue