summaryrefslogtreecommitdiff
path: root/legacy/ephysics/src/bin/test_win_resize.c
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-12-13 21:03:41 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-12-13 21:03:41 +0000
commit7a504551b298713bd23da73dd5ce27c4399d57e6 (patch)
tree6ab2f9538f78411fd6803f064d616642498abee3 /legacy/ephysics/src/bin/test_win_resize.c
parentceae5649b6c526bd508f913001b6c94f39bd94a4 (diff)
Create trunk/ephysics_tests
And mv / cp test stuff from ephysics to ephysics_tests SVN revision: 80893
Diffstat (limited to '')
-rw-r--r--legacy/ephysics/src/bin/test_win_resize.c200
1 files changed, 0 insertions, 200 deletions
diff --git a/legacy/ephysics/src/bin/test_win_resize.c b/legacy/ephysics/src/bin/test_win_resize.c
deleted file mode 100644
index 8df93bfa59..0000000000
--- a/legacy/ephysics/src/bin/test_win_resize.c
+++ /dev/null
@@ -1,200 +0,0 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "ephysics_test.h"
6
7typedef struct _Old_Rate Old_Rate;
8struct _Old_Rate {
9 EPhysics_Body *body;
10 double w;
11 double h;
12};
13
14static void
15_win_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
16{
17 free(data);
18}
19
20static void
21_win_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
22{
23 Test_Data *test_data = data;
24 EPhysics_Body *sphere_body;
25 double ratew, rateh;
26 Evas_Object *sphere;
27 Old_Rate *old_rate;
28 int ww, wh, x, y;
29
30 evas_object_geometry_get(obj, NULL, NULL, &ww, &wh);
31 ratew = (double) ww / WIDTH;
32 rateh = (double) wh / HEIGHT;
33
34 /* Since we don't support different rates on ephysics world, we
35 should make sure window keeps its aspect.
36 Maybe if we decide it should be supported someday,
37 this example could be modified just dropping the following check. */
38 if (ratew > rateh)
39 {
40 ww = rateh * WIDTH;
41 evas_object_resize(obj, ww, wh);
42 return;
43 }
44 else if (ratew < rateh)
45 {
46 wh = ratew * HEIGHT;
47 evas_object_resize(obj, ww, wh);
48 return;
49 }
50
51 evas_object_resize(test_data->layout, ww, wh);
52 ephysics_world_rate_set(test_data->world, 30 * rateh);
53 ephysics_world_render_geometry_set(test_data->world, 50 * ratew, 40 *rateh,
54 -50,
55 (WIDTH - 100) * ratew,
56 (FLOOR_Y - 40) * rateh,
57 DEPTH);
58
59 old_rate = test_data->data;
60 if (!old_rate) return;
61 sphere_body = old_rate->body;
62
63 sphere = ephysics_body_evas_object_get(sphere_body);
64 evas_object_geometry_get(sphere, &x, &y, NULL, NULL);
65
66 ephysics_body_move(sphere_body, x * (ratew / old_rate->w),
67 y * (rateh / old_rate->h), -15);
68 evas_object_resize(sphere, 70 * ratew, 70 * rateh);
69
70 old_rate->w = ratew;
71 old_rate->h = rateh;
72}
73
74static void
75_update_object_cb(void *data, EPhysics_Body *body, void *event_info)
76{
77 Evas_Object *sphere = event_info;
78 Evas_Object *shadow = data;
79 Edje_Message_Float msg;
80 Old_Rate *old_rate;
81 Evas_Object *edje;
82 int x, y, w, h;
83
84 ephysics_body_evas_object_update(body);
85 old_rate = ephysics_body_data_get(body);
86 evas_object_geometry_get(sphere, &x, &y, &w, &h);
87
88 if (y > SH_THRESHOLD * old_rate->h)
89 {
90 int sh_w;
91
92 msg.val = (double) (y - SH_THRESHOLD * old_rate->h) /
93 ((FLOOR_Y - SH_THRESHOLD) * old_rate->h - h);
94 sh_w = (1 + 2 * msg.val) * w / 3;
95 evas_object_resize(shadow, sh_w, 3 * old_rate->h);
96 evas_object_move(shadow, x + (w - sh_w) / 2, FLOOR_Y * old_rate->h);
97 }
98 else
99 msg.val = 0;
100
101 edje = elm_layout_edje_get(shadow);
102 edje_object_message_send(edje, EDJE_MESSAGE_FLOAT, SHADOW_ALPHA_ID, &msg);
103}
104
105static void
106_world_populate(Test_Data *test_data)
107{
108 Evas_Object *sphere, *shadow;
109 EPhysics_Body *sphere_body;
110 Old_Rate *old_rate;
111 int w, h;
112
113 old_rate = test_data->data;
114 if (!test_data->data)
115 old_rate = calloc(1, sizeof(Old_Rate));
116 if (!old_rate) return;
117 test_data->data = old_rate;
118
119 evas_object_geometry_get(test_data->win, NULL, NULL, &w, &h);
120 old_rate->w = (double) w / WIDTH;
121 old_rate->h = (double) h / HEIGHT;
122
123 shadow = elm_layout_add(test_data->win);
124 elm_layout_file_set(
125 shadow, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "shadow-ball");
126 evas_object_move(shadow, WIDTH / 3 * old_rate->w, FLOOR_Y * old_rate->h);
127 evas_object_resize(shadow, 70 * old_rate->w, 3 * old_rate->h);
128 evas_object_show(shadow);
129 test_data->evas_objs = eina_list_append(test_data->evas_objs, shadow);
130
131 sphere = elm_image_add(test_data->win);
132 elm_image_file_set(
133 sphere, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "big-blue-ball");
134 evas_object_move(sphere, WIDTH / 3 * old_rate->w, HEIGHT / 2 * old_rate->h);
135 evas_object_resize(sphere, 70 * old_rate->w, 70 * old_rate->h);
136 evas_object_show(sphere);
137 test_data->evas_objs = eina_list_append(test_data->evas_objs, sphere);
138
139 sphere_body = ephysics_body_sphere_add(test_data->world);
140 ephysics_body_evas_object_set(sphere_body, sphere, EINA_TRUE);
141 ephysics_body_restitution_set(sphere_body, 1.0);
142 ephysics_body_event_callback_add(sphere_body, EPHYSICS_CALLBACK_BODY_UPDATE,
143 _update_object_cb, shadow);
144 test_data->bodies = eina_list_append(test_data->bodies, sphere_body);
145 old_rate->body = sphere_body;
146 ephysics_body_data_set(sphere_body, old_rate);
147}
148
149static void
150_restart(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
151{
152 Test_Data *test_data = data;
153
154 DBG("Restart pressed");
155 test_clean(test_data);
156 _world_populate(test_data);
157}
158
159void
160test_win_resize(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
161{
162 EPhysics_Body *boundary;
163 EPhysics_World *world;
164 Test_Data *test_data;
165
166 if (!ephysics_init())
167 return;
168
169 test_data = test_data_new();
170 test_win_add(test_data, "Win Resize", EINA_TRUE);
171 evas_object_event_callback_add(test_data->win, EVAS_CALLBACK_RESIZE,
172 _win_resize_cb, test_data);
173
174 elm_layout_signal_callback_add(test_data->layout, "restart", "test-theme",
175 _restart, test_data);
176 elm_object_signal_emit(test_data->layout, "borders,show", "ephysics_test");
177 evas_object_size_hint_weight_set(test_data->layout, EVAS_HINT_EXPAND,
178 EVAS_HINT_EXPAND);
179 elm_win_aspect_set(test_data->win, (double) WIDTH / HEIGHT);
180 evas_object_event_callback_add(test_data->win, EVAS_CALLBACK_DEL,
181 _win_del, test_data->data);
182
183 world = ephysics_world_new();
184 ephysics_world_render_geometry_set(world, 50, 40, -50,
185 WIDTH - 100, FLOOR_Y - 40, DEPTH);
186 test_data->world = world;
187
188 boundary = ephysics_body_bottom_boundary_add(test_data->world);
189 ephysics_body_restitution_set(boundary, 1.0);
190
191 boundary = ephysics_body_right_boundary_add(test_data->world);
192 ephysics_body_restitution_set(boundary, 1.0);
193
194 boundary = ephysics_body_left_boundary_add(test_data->world);
195 ephysics_body_restitution_set(boundary, 1.0);
196
197 ephysics_body_top_boundary_add(test_data->world);
198
199 _world_populate(test_data);
200}