12
#define FLOOR_Y (HEIGHT - 80)
13
#define SH_THRESHOLD (250)
14
#define SH_OFFSET_X (- 16)
16
#define PADDING_X_1 (16)
17
#define PADDING_X_2 (12)
18
#define PADDING_X_3 (22)
19
#define E_THRESHOLD (WIDTH + 560)
20
#define LAYER_SHADOW (10)
21
#define LAYER_LETTER (20)
23
#define CENTER(total, item) (((total) - (item)) / 2)
24
#define LIMIT(val, op, ref) (((val) op (ref)) ? (val) : (ref));
25
#define PROP_GET(pos, min, max) (((min) + ((max) - (min)) * (pos)) / (max))
28
_update_box_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info)
30
Evas_Object *image = event_info;
31
Evas_Object *shadow = evas_object_data_get(image, "shadow");
32
Evas_Object *light = evas_object_data_get(image, "light");
33
int x, y, w, h, floor_distance, alpha = 0;
35
/* modify the evas object according to the body */
36
ephysics_body_evas_object_update(body);
37
evas_object_geometry_get(image, &x, &y, &w, &h);
39
floor_distance = FLOOR_Y - h;
41
/* Bodies penetrates the ground slightly before bouncing. */
42
/* This is to be expected in realtime physics engines. */
43
// TODO BUG: should we move the object up by the difference????
44
//y = LIMIT(y, <=, floor_distance);
46
/* We should show the shadow when we're close enough to ground */
52
evas_object_image_size_get(shadow, &sh_w, &sh_h);
53
/* shadow is darker with bigger y */
54
alpha = 255 * (y - SH_THRESHOLD) / (floor_distance - SH_THRESHOLD);
55
/* and with bigger x -- it's proportional to x / WIDTH, but varies
58
pos_x = (double) x / (WIDTH - w);
59
alpha = alpha * PROP_GET(pos_x, 100, 255);
60
/* box shadow is not resized, just moved */
61
evas_object_move(shadow, x + CENTER(w, sh_w) + SH_OFFSET_X,
64
evas_object_color_set(shadow, alpha, alpha, alpha, alpha);
66
evas_object_move(light, x, y);
67
/* it's lighter with bigger y */
68
alpha = (y <= 0) ? 0 : y * 255 / floor_distance;
69
/* and with bigger x */
70
alpha = alpha * (x - OFFSET_X + 80) / (WIDTH - OFFSET_X);
71
evas_object_color_set(light, alpha, alpha, alpha, alpha);
75
_update_circle_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info)
77
Evas_Object *image = event_info;
78
Evas_Object *shadow = evas_object_data_get(image, "shadow");
79
Evas_Object *light = evas_object_data_get(image, "light");
80
int x, y, w, h, sh_w, sh_h, alpha = 0;
83
/* modify the evas object according to the body */
84
ephysics_body_evas_object_update(body);
85
evas_object_geometry_get(image, &x, &y, &w, &h);
87
evas_object_move(light, x, y);
88
alpha = x * 255 / (WIDTH - w);
89
evas_object_color_set(light, alpha, alpha, alpha, alpha);
91
/* use the same map from image to the light (rotate it) */
92
map = evas_object_map_get(image);
93
evas_object_map_set(light, map);
94
evas_object_map_enable_set(light, EINA_TRUE);
96
evas_object_image_size_get(shadow, &sh_w, &sh_h);
97
evas_object_move(shadow, x + CENTER(w, sh_w) + SH_OFFSET_X,
99
alpha = 127 + alpha / 2;
100
evas_object_color_set(shadow, alpha, alpha, alpha, alpha);
103
ephysics_body_move(body, -w - 1, y, -15);
107
_letter_add(Evas *evas, const char *letter, Evas_Object **image, Evas_Object **light, Evas_Object **shadow)
109
int w, h, sh_w, sh_h;
112
snprintf(buf, sizeof(buf), PACKAGE_DATA_DIR "/logo_shadow-%s.png", letter);
113
*shadow = evas_object_image_filled_add(evas);
114
evas_object_image_file_set(*shadow, buf, NULL);
115
evas_object_image_size_get(*shadow, &sh_w, &sh_h);
116
evas_object_resize(*shadow, sh_w, sh_h);
117
evas_object_color_set(*shadow, 0, 0, 0, 0);
118
evas_object_layer_set(*shadow, LAYER_SHADOW);
119
evas_object_show(*shadow);
121
snprintf(buf, sizeof(buf), PACKAGE_DATA_DIR "/logo_letter-%s.png", letter);
122
*image = evas_object_image_filled_add(evas);
123
evas_object_image_file_set(*image, buf, NULL);
124
evas_object_image_size_get(*image, &w, &h);
125
evas_object_resize(*image, w, h);
126
evas_object_layer_set(*image, LAYER_LETTER);
127
evas_object_show(*image);
129
snprintf(buf, sizeof(buf), PACKAGE_DATA_DIR "/logo_light-%s.png", letter);
130
*light = evas_object_image_filled_add(evas);
131
evas_object_image_file_set(*light, buf, NULL);
132
evas_object_resize(*light, w, h);
133
evas_object_layer_set(*light, LAYER_LETTER);
134
evas_object_show(*light);
136
/* allow easy access to shadow and light from the letter image */
137
evas_object_data_set(*image, "shadow", *shadow);
138
evas_object_data_set(*image, "light", *light);
142
_letter_body_setup_common(EPhysics_Body *body, Evas_Object *view)
144
ephysics_body_evas_object_set(body, view, EINA_TRUE);
145
ephysics_body_mass_set(body, 1.2);
146
ephysics_body_restitution_set(body, 0.6);
147
ephysics_body_angular_movement_enable_set(body, EINA_FALSE, EINA_FALSE,
151
static EPhysics_Body *
152
_letter_body_box_add(EPhysics_World *world, Evas_Object *image)
154
EPhysics_Body *body = ephysics_body_box_add(world);
156
_letter_body_setup_common(body, image);
158
ephysics_body_event_callback_add
159
(body, EPHYSICS_CALLBACK_BODY_UPDATE, _update_box_cb, NULL);
164
static EPhysics_Body *
165
_letter_body_circle_add(EPhysics_World *world, Evas_Object *image)
167
EPhysics_Body *body = ephysics_body_cylinder_add(world);
169
_letter_body_setup_common(body, image);
171
ephysics_body_event_callback_add
172
(body, EPHYSICS_CALLBACK_BODY_UPDATE, _update_circle_cb, NULL);
178
elm_main(int argc __UNUSED__, char **argv __UNUSED__)
180
Evas_Object *win, *bg, *image, *light, *shadow;
181
EPhysics_Body *ground_body, *letter_body;
182
EPhysics_World *world;
190
} falling_letters[] = {
200
if (!ephysics_init())
203
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
205
win = elm_win_add(NULL, "main", ELM_WIN_SPLASH);
206
elm_win_title_set(win, "EPhysics Logo");
207
elm_win_autodel_set(win, EINA_TRUE);
208
evas_object_show(win);
210
bg = elm_bg_add(win);
211
elm_bg_file_set(bg, PACKAGE_DATA_DIR "/logo_background.png", NULL);
212
elm_win_resize_object_add(win, bg);
213
evas_object_size_hint_min_set(bg, WIDTH, HEIGHT);
214
evas_object_size_hint_max_set(bg, WIDTH, HEIGHT);
215
evas_object_show(bg);
217
world = ephysics_world_new();
218
ephysics_world_render_geometry_set(world, 0, 0, -50, WIDTH, HEIGHT, DEPTH);
220
ground_body = ephysics_body_box_add(world);
221
ephysics_body_mass_set(ground_body, EPHYSICS_BODY_MASS_STATIC);
222
ephysics_body_geometry_set(ground_body, -100, FLOOR_Y, -15, WIDTH + 800, 10,
224
ephysics_body_restitution_set(ground_body, 0.65);
225
ephysics_body_friction_set(ground_body, 0.8);
227
evas = evas_object_evas_get(win);
230
for (i = 0; i < EINA_C_ARRAY_LENGTH(falling_letters); i++)
232
_letter_add(evas, falling_letters[i].letter, &image, &light, &shadow);
234
evas_object_image_size_get(shadow, &sh_w, NULL);
235
evas_object_image_size_get(image, &w, &h);
237
/* place image and light on top, above what the viewport can show */
238
evas_object_move(image, x, -h * (i + 1) - 50);
239
evas_object_move(light, x, -h * (i + 1) - 50);
240
/* place shadow below the hit-line: FLOOR_Y, centered at image */
241
evas_object_move(shadow, x + CENTER(w, sh_w), FLOOR_Y);
243
x += falling_letters[i].padding + w;
245
letter_body = _letter_body_box_add(world, image);
246
ephysics_body_friction_set(letter_body, 0.4);
249
/* E is a circle that comes rolling on the floor */
250
_letter_add(evas, "E", &image, &light, &shadow);
251
evas_object_color_set(shadow, 255, 255, 255, 255);
253
evas_object_image_size_get(shadow, &sh_w, NULL);
254
evas_object_image_size_get(image, &w, &h);
255
/* place image and light so they are above the floor,
256
* and to the left of viewport
258
evas_object_move(image, -w - 1, FLOOR_Y - h + 1);
259
evas_object_move(light, -w - 1, FLOOR_Y - h + 1);
260
/* place the shadow below the hit-line: FLOOR_Y, centered at image */
261
evas_object_move(shadow, -w - 1 + CENTER(w, sh_w), FLOOR_Y);
263
letter_body = _letter_body_circle_add(world, image);
264
ephysics_body_friction_set(letter_body, 1);
265
ephysics_body_mass_set(letter_body, 1);
266
ephysics_body_angular_movement_enable_set(letter_body, EINA_FALSE,
267
EINA_FALSE, EINA_TRUE);
269
/* make the "E" logo get into the viewport by applying an horizontal force */
270
ephysics_body_central_impulse_apply(letter_body, 390, 0, 0);
274
ephysics_world_del(world);