parent
818e957c89
commit
7aff5fb13e
|
@ -6,13 +6,8 @@
|
||||||
|
|
||||||
typedef struct _Dragging_Data
|
typedef struct _Dragging_Data
|
||||||
{
|
{
|
||||||
int mouse_status; // 0, up, 1, down
|
|
||||||
EPhysics_Body *body;
|
EPhysics_Body *body;
|
||||||
struct {
|
int node;
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int node;
|
|
||||||
} click_data;
|
|
||||||
} Dragging_Data;
|
} Dragging_Data;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -29,40 +24,49 @@ _mouse_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_inf
|
||||||
Evas_Event_Mouse_Down *mdown = event_info;
|
Evas_Event_Mouse_Down *mdown = event_info;
|
||||||
Evas_Coord x, y;
|
Evas_Coord x, y;
|
||||||
|
|
||||||
|
if (mdown->button != 1) return;
|
||||||
|
|
||||||
evas_object_geometry_get(obj, &x, &y, NULL, NULL);
|
evas_object_geometry_get(obj, &x, &y, NULL, NULL);
|
||||||
dragging->mouse_status = 1;
|
dragging->node = ephysics_body_soft_body_triangle_index_get(
|
||||||
dragging->click_data.x = mdown->output.x - x;
|
dragging->body, mdown->output.x - x, mdown->output.y - y);
|
||||||
dragging->click_data.y = mdown->output.y - y;
|
|
||||||
dragging->click_data.node = ephysics_body_soft_body_triangle_index_get(
|
|
||||||
dragging->body, mdown->output.x, mdown->output.y);
|
|
||||||
|
|
||||||
ephysics_body_soft_body_dragging_set(dragging->body,
|
ephysics_body_soft_body_dragging_set(dragging->body,
|
||||||
dragging->click_data.node);
|
dragging->node);
|
||||||
|
|
||||||
|
DBG("Mouse down on %i, %i", mdown->output.x - x, mdown->output.y - y);
|
||||||
|
DBG("Selected node: %i", dragging->node);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
Evas_Event_Mouse_Up *mup = event_info;
|
||||||
Dragging_Data *dragging = data;
|
Dragging_Data *dragging = data;
|
||||||
|
if (mup->button != 1) return;
|
||||||
ephysics_body_soft_body_dragging_unset(dragging->body);
|
ephysics_body_soft_body_dragging_unset(dragging->body);
|
||||||
dragging->mouse_status = 0;
|
dragging->node = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
|
_mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
|
||||||
{
|
{
|
||||||
Dragging_Data *dragging = data;
|
Dragging_Data *dragging = data;
|
||||||
Evas_Event_Mouse_Move *mmove = event_info;
|
Evas_Event_Mouse_Move *mmove = event_info;
|
||||||
Evas_Coord nx, ny;
|
Evas_Coord nx, ny;
|
||||||
|
Evas_Coord x, y;
|
||||||
|
|
||||||
if (!dragging->mouse_status || dragging->click_data.node < 0) return;
|
evas_object_geometry_get(obj, &x, &y, NULL, NULL);
|
||||||
|
printf("canvas = (%i, %i), output = (%i, %i)\n", mmove->cur.canvas.x,
|
||||||
|
mmove->cur.canvas.y, mmove->cur.output.x, mmove->cur.output.y);
|
||||||
|
|
||||||
nx = mmove->cur.output.x;
|
if ((mmove->buttons != 1) || (dragging->node < 0)) return;
|
||||||
ny = mmove->cur.output.y;
|
|
||||||
|
|
||||||
DBG("node: %d, nx: %d, ny: %d\n", dragging->click_data.node, nx, ny);
|
nx = mmove->cur.canvas.x;
|
||||||
|
ny = mmove->cur.canvas.y;
|
||||||
|
|
||||||
|
DBG("Node: %d, nx: %d, ny: %d", dragging->node, nx, ny);
|
||||||
ephysics_body_soft_body_triangle_move(dragging->body,
|
ephysics_body_soft_body_triangle_move(dragging->body,
|
||||||
dragging->click_data.node, nx, ny, 10);
|
dragging->node, nx, ny, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -73,6 +77,7 @@ _world_populate(Test_Data *test_data)
|
||||||
Dragging_Data *dragging;
|
Dragging_Data *dragging;
|
||||||
|
|
||||||
dragging = calloc(1, sizeof(Dragging_Data));
|
dragging = calloc(1, sizeof(Dragging_Data));
|
||||||
|
dragging->node = -1;
|
||||||
|
|
||||||
evas_obj = elm_image_add(test_data->win);
|
evas_obj = elm_image_add(test_data->win);
|
||||||
elm_image_file_set(
|
elm_image_file_set(
|
||||||
|
@ -149,6 +154,7 @@ test_flag(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info _
|
||||||
elm_object_signal_emit(test_data->layout, "borders,show", "ephysics_test");
|
elm_object_signal_emit(test_data->layout, "borders,show", "ephysics_test");
|
||||||
|
|
||||||
world = ephysics_world_new();
|
world = ephysics_world_new();
|
||||||
|
ephysics_world_gravity_set(world, 100, 0, 0);
|
||||||
ephysics_world_render_geometry_set(world, 50, 40, -50,
|
ephysics_world_render_geometry_set(world, 50, 40, -50,
|
||||||
WIDTH - 100, FLOOR_Y - 40, DEPTH);
|
WIDTH - 100, FLOOR_Y - 40, DEPTH);
|
||||||
test_data->world = world;
|
test_data->world = world;
|
||||||
|
|
Loading…
Reference in New Issue