summaryrefslogtreecommitdiff
path: root/legacy/ephysics/src/bin/test_soft_button.c
diff options
context:
space:
mode:
authorLeandro Dorileo <dorileo@profusion.mobi>2012-11-23 21:52:18 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-11-23 21:52:18 +0000
commitffecc4ac0f51fc4e72e37097fb6d3631277f70d8 (patch)
treeff0609557983425d496c1740fd2760721b920b80 /legacy/ephysics/src/bin/test_soft_button.c
parent1a1adc1a5fd0ff1b8c289da72a685692af5d1874 (diff)
EPhysics: soft button test
A new test with a soft button deforming while clicking on it. Patch by: Leandro Dorileo <dorileo@profusion.mobi> SVN revision: 79608
Diffstat (limited to '')
-rw-r--r--legacy/ephysics/src/bin/test_soft_button.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/legacy/ephysics/src/bin/test_soft_button.c b/legacy/ephysics/src/bin/test_soft_button.c
new file mode 100644
index 0000000000..645f0817b1
--- /dev/null
+++ b/legacy/ephysics/src/bin/test_soft_button.c
@@ -0,0 +1,123 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "ephysics_test.h"
6
7static void
8_mouse_down_cb(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
9{
10 EPhysics_Body *body = data;
11 Evas_Event_Mouse_Down *mdown = event_info;
12 Evas_Coord w, h, x, y, z, zz, d;
13 Eina_List *triangles;
14 int *ldata;
15
16 ephysics_body_geometry_get(body, NULL, NULL, &z, NULL, NULL, &d);
17
18 w = 70;
19 h = 70;
20 x = mdown->output.x - (w / 2);
21 y = mdown->output.y - (h / 2);
22 zz = z + (d / 2);
23 d = z;
24
25 triangles = ephysics_body_soft_body_triangles_inside_get(body, x, y, zz,
26 w, h, d);
27 ephysics_body_soft_body_triangle_list_impulse_apply(body, triangles, 0, 0,
28 -100);
29 EINA_LIST_FREE(triangles, ldata)
30 free(ldata);
31}
32
33static void
34_soft_ellipsoid_add(Test_Data *test_data, Evas_Object *front_face, Evas_Object *back_face)
35{
36 EPhysics_Body *body;
37 Evas_Coord w, h;
38
39
40 body = ephysics_body_soft_ellipsoid_add(test_data->world, 100);
41
42 ephysics_body_face_evas_object_set(body,
43 EPHYSICS_BODY_SOFT_ELLIPSOID_FACE_FRONT, front_face, EINA_TRUE);
44
45 ephysics_body_face_evas_object_set(body,
46 EPHYSICS_BODY_SOFT_ELLIPSOID_FACE_BACK, back_face, EINA_TRUE);
47
48 ephysics_body_geometry_get(body, NULL, NULL, NULL, &w, &h, NULL);
49 ephysics_body_resize(body, w, h, h);
50 test_data->bodies = eina_list_append(test_data->bodies, body);
51
52 ephysics_body_linear_movement_enable_set(body, EINA_FALSE, EINA_FALSE,
53 EINA_FALSE);
54 ephysics_body_angular_movement_enable_set(body, EINA_FALSE, EINA_FALSE,
55 EINA_FALSE);
56
57 evas_object_event_callback_add(front_face, EVAS_CALLBACK_MOUSE_DOWN,
58 _mouse_down_cb, body);
59
60 evas_object_event_callback_add(back_face, EVAS_CALLBACK_MOUSE_DOWN,
61 _mouse_down_cb, body);
62}
63
64static void
65_world_populate(Test_Data *test_data)
66{
67 Evas_Object *front_face, *back_face;
68
69 front_face = elm_image_add(test_data->win);
70 elm_image_file_set(
71 front_face, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "blue-cube");
72 evas_object_move(front_face, WIDTH / 2 - 35, HEIGHT / 2 - 35);
73 evas_object_resize(front_face, 70, 70);
74 evas_object_show(front_face);
75 test_data->evas_objs = eina_list_append(test_data->evas_objs, front_face);
76
77 back_face = elm_image_add(test_data->win);
78 elm_image_file_set(
79 back_face, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "blue-cube");
80 evas_object_move(back_face, WIDTH / 2 - 35, HEIGHT / 2 - 35);
81 evas_object_resize(back_face, 70, 70);
82 evas_object_show(back_face);
83 test_data->evas_objs = eina_list_append(test_data->evas_objs, back_face);
84
85 _soft_ellipsoid_add(test_data, front_face, back_face);
86}
87
88static void
89_restart(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
90{
91 Test_Data *test_data = data;
92
93 DBG("Restart pressed");
94 test_clean(test_data);
95 _world_populate(test_data);
96}
97
98void
99test_soft_button(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
100{
101 EPhysics_World *world;
102 Test_Data *test_data;
103
104 if (!ephysics_init())
105 return;
106
107 test_data = test_data_new();
108 test_win_add(test_data, "Soft Button", EINA_TRUE);
109
110 elm_layout_signal_callback_add(test_data->layout, "restart", "test-theme",
111 _restart, test_data);
112 elm_object_signal_emit(test_data->layout, "borders,show", "ephysics_test");
113
114 world = ephysics_world_new();
115 ephysics_world_simulation_set(world, 1/150.f, 5);
116 ephysics_world_render_geometry_set(world, 50, 40, -50,
117 WIDTH - 100, FLOOR_Y - 40, DEPTH);
118 test_data->world = world;
119
120 ephysics_world_point_light_position_set(world, 300, 50, -200);
121
122 _world_populate(test_data);
123}