1 #include <Elementary.h>
3 # include "elementary_config.h"
5 #ifndef ELM_LIB_QUICKLAUNCH
9 typedef struct _State State;
10 typedef struct _Slice Slice;
12 typedef struct _Vertex2 Vertex2;
13 typedef struct _Vertex3 Vertex3;
17 Evas_Object *orig, *win;
18 Evas_Coord down_x, down_y;
33 double x[4], y[4], z[4];
63 sl = calloc(1, sizeof(Slice));
65 sl->obj = evas_object_image_add(evas_object_evas_get(st->win));
66 evas_object_image_smooth_scale_set(sl->obj, 0);
67 evas_object_pass_events_set(sl->obj, 1);
68 evas_object_image_source_set(sl->obj, st->orig);
69 evas_object_show(sl->obj);
74 _slice_free(Slice *sl)
76 evas_object_del(sl->obj);
81 _slice_apply(Slice *sl, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
87 evas_map_smooth_set(m, 0);
89 for (i = 0; i < 4; i++)
91 evas_map_point_coord_set(m, i, x + sl->x[i], y + sl->y[i], sl->z[i]);
92 evas_map_point_image_uv_set(m, i, sl->u[i] , sl->v[i]);
93 evas_map_point_color_set(m, i, 255, 255, 255, 255);
96 evas_map_util_3d_perspective(m, x + (w / 2), y + (h / 2), 0, 512);
99 // FIXME: lighting should be manual with pt 0 and 3 being white and
100 // 2 and 3 matching the
101 evas_map_util_3d_lighting(m,
107 evas_object_map_enable_set(sl->obj, EINA_TRUE);
108 evas_object_image_fill_set(sl->obj, 0, 0, w, h);
109 evas_object_map_set(sl->obj, m);
114 _slice_xyz(Slice *sl,
115 double x1, double y1, double z1,
116 double x2, double y2, double z2,
117 double x3, double y3, double z3,
118 double x4, double y4, double z4)
120 sl->x[0] = x1; sl->y[0] = y1; sl->z[0] = z1;
121 sl->x[1] = x2; sl->y[1] = y2; sl->z[1] = z2;
122 sl->x[2] = x3; sl->y[2] = y3; sl->z[2] = z3;
123 sl->x[3] = x4; sl->y[3] = y4; sl->z[3] = z4;
128 double u1, double v1,
129 double u2, double v2,
130 double u3, double v3,
131 double u4, double v4)
133 sl->u[0] = u1; sl->v[0] = v1;
134 sl->u[1] = u2; sl->v[1] = v2;
135 sl->u[2] = u3; sl->v[2] = v3;
136 sl->u[3] = u4; sl->v[3] = v4;
140 _slice_update(State *st)
142 Evas_Coord x1, y1, x2, y2, mx, my, px, rx, ry, prx, pry, dst, dx, dy, pdst;
143 Evas_Coord x, y, w, h;
148 evas_object_geometry_get(st->orig, &x, &y, &w, &h);
157 else if (mx >= w) mx = w - 1;
159 else if (my >= h) my = h - 1;
161 if (!st->base) st->base = _slice_new(st);
174 _slice_apply(sl, x, y, w, h);
176 EINA_LIST_FREE(st->slices, sl) _slice_free(sl);
178 // cylinder radius is width / 8
180 if (rad < (w / 16)) rad = (w / 16);
181 if (rad > (w / 8)) rad = w / 8;
188 for (i = 1; i < RES; i++)
190 rx = (double)rad * sin((i * M_PI) / RES);
191 ry = (double)rad * cos((i * M_PI) / RES);
194 dst = sqrt((dx * dx) + (dy * dy));
199 rx = prx + (((rx - prx) * dst) / pdst);
200 ry = pry + (((ry - pry) * dst) / pdst);
207 mx + prx, 0, -(rad - pry),
208 mx + rx, 0, -(rad - ry),
209 mx + rx, h, -(rad - ry),
210 mx + prx, h, -(rad - pry));
216 _slice_apply(sl, x, y, w, h);
217 st->slices = eina_list_append(st->slices, sl);
228 mx + prx, 0, -(rad - pry),
229 mx + (px - w), 0, -(rad * 2),
230 mx + (px - w), h, -(rad * 2),
231 mx + prx, h, -(rad - pry));
237 _slice_apply(sl, x, y, w, h);
238 st->slices = eina_list_append(st->slices, sl);
243 _slice_end(State *st)
247 if (st->base) _slice_free(st->base);
249 EINA_LIST_FREE(st->slices, sl) _slice_free(sl);
254 static Evas_Object *sl_rho, *sl_theta, *sl_A;
257 _deform_point(Vertex2 *vi, Vertex3 *vo, double rho, double theta, double A)
263 // theta == cone angle (0 -> PI/2)
264 // A == distance of cone apex from origin
265 // rho == angle of cone from vertical axis (...-PI/2 to PI/2...)
266 Vertex3 v1; // First stage of the deformation
269 // Radius of the circle circumscribed by vertex (vi->x, vi->y) around A
271 R = sqrt(vi->x * vi->x + pow(vi->y - A, 2));
272 // Now get the radius of the cone cross section intersected by our vertex
275 // Angle subtended by arc |ST| on the cone cross section.
276 beta = asin(vi->x / R) / sin(theta);
279 v1.x = r * sin(beta);
280 v1.y = R + A - r * (1 - cos(beta)) * sin(theta);
281 v1.z = r * (1 - cos(beta)) * cos(theta);
283 // Apply a basic rotation transform around the y axis to rotate the curled
284 // page. These two steps could be combined through simple substitution,
285 // but are left separate to keep the math simple for debugging and
286 // illustrative purposes.
287 vo->x = (v1.x * cos(rho)) - (v1.z * sin(rho));
289 vo->z = (v1.x * sin(rho)) + (v1.z * cos(rho));
295 static Eina_List *pts = NULL;
299 Evas_Coord x, y, w, h;
302 EINA_LIST_FREE(pts, o) evas_object_del(o);
304 evas_object_geometry_get(st->orig, &x, &y, &w, &h);
305 for (j = 0; j < h; j += 20)
307 for (i = 0; i < w; i += 20)
311 double rho, theta, A, n;
315 rho = elm_slider_value_get(sl_rho);
316 A = elm_slider_value_get(sl_A);
317 theta = elm_slider_value_get(sl_theta);
319 _deform_point(&vi, &vo, rho, theta, A);
321 o = evas_object_image_add(evas_object_evas_get(st->win));
322 evas_object_image_smooth_scale_set(o, 0);
323 evas_object_pass_events_set(o, 1);
324 evas_object_image_source_set(o, st->orig);
328 evas_map_smooth_set(m, 0);
331 evas_map_point_coord_set(m, k, x + vo.x, y + vo.y, -vo.z);
332 evas_map_point_image_uv_set(m, k, 0 , 0);
333 evas_map_point_color_set(m, k, 255, 255, 255, 255);
335 evas_map_point_coord_set(m, k, x + vo.x + 10, y + vo.y, -vo.z);
336 evas_map_point_image_uv_set(m, k, w , 0);
337 evas_map_point_color_set(m, k, 255, 255, 255, 255);
339 evas_map_point_coord_set(m, k, x + vo.x + 10, y + vo.y + 10, -vo.z);
340 evas_map_point_image_uv_set(m, k, w , h);
341 evas_map_point_color_set(m, k, 255, 255, 255, 255);
343 evas_map_point_coord_set(m, k, x + vo.x, y + vo.y + 10, -vo.z);
344 evas_map_point_image_uv_set(m, k, 0 , h);
345 evas_map_point_color_set(m, k, 255, 255, 255, 255);
348 evas_map_util_3d_perspective(m, x + (w / 2), y + (h / 2), 0, 512);
350 evas_object_map_enable_set(o, EINA_TRUE);
351 evas_object_image_fill_set(o, 0, 0, w, h);
352 evas_object_map_set(o, m);
355 pts = eina_list_append(pts, o);
361 _sl_ch(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
368 im_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
370 Evas_Event_Mouse_Down *ev = event_info;
371 Evas_Object *win = data;
374 if (ev->button != 1) return;
375 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
379 state.x = ev->canvas.x - x;
380 state.y = ev->canvas.y - y;
381 state.down_x = state.x;
382 state.down_y = state.y;
383 evas_object_lower(obj);
384 printf("v %i %i\n", state.x, state.y);
385 _slice_update(&state);
389 im_up_cb(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
391 Evas_Event_Mouse_Up *ev = event_info;
394 if (ev->button != 1) return;
395 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
397 state.x = ev->canvas.x - x;
398 state.y = ev->canvas.y - y;
399 evas_object_raise(obj);
400 printf("^ %i %i\n", state.x, state.y);
405 im_move_cb(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
407 Evas_Event_Mouse_Move *ev = event_info;
410 if (!state.down) return;
411 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
412 state.x = ev->cur.canvas.x - x;
413 state.y = ev->cur.canvas.y - y;
414 printf("@ %i %i\n", state.x, state.y);
415 _slice_update(&state);
419 test_flip_page(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
421 Evas_Object *win, *bg, *im;
424 win = elm_win_add(NULL, "flip_page", ELM_WIN_BASIC);
425 elm_win_title_set(win, "Flip Page");
426 elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
427 elm_win_autodel_set(win, 1);
429 bg = elm_bg_add(win);
430 elm_win_resize_object_add(win, bg);
431 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
432 evas_object_show(bg);
435 im = elm_layout_add(win);
436 snprintf(buf, sizeof(buf), "%s/objects/test.edj", PACKAGE_DATA_DIR);
437 elm_layout_file_set(im, buf, "layout");
439 im = evas_object_image_filled_add(evas_object_evas_get(win));
440 snprintf(buf, sizeof(buf), "%s/images/%s",
441 PACKAGE_DATA_DIR, "twofish.jpg");
442 evas_object_image_file_set(im, buf, NULL);
444 evas_object_move(im, 40, 40);
445 evas_object_resize(im, 400, 400);
446 evas_object_show(im);
448 evas_object_event_callback_add(im, EVAS_CALLBACK_MOUSE_DOWN, im_down_cb, win);
449 evas_object_event_callback_add(im, EVAS_CALLBACK_MOUSE_UP, im_up_cb, win);
450 evas_object_event_callback_add(im, EVAS_CALLBACK_MOUSE_MOVE, im_move_cb, win);
452 evas_object_resize(win, 480, 480);
453 evas_object_show(win);
458 sl = elm_slider_add(win);
459 elm_slider_min_max_set(sl, -5, 5);
460 elm_slider_value_set(sl, 0);
462 evas_object_smart_callback_add(sl, "changed", _sl_ch, NULL);
463 elm_slider_label_set(sl, "rho");
464 elm_slider_unit_format_set(sl, "%1.2f");
465 elm_slider_span_size_set(sl, 320);
466 evas_object_move(sl, 10, 20);
467 evas_object_resize(sl, 460, 40);
468 evas_object_layer_set(sl, 100);
469 evas_object_show(sl);
471 sl = elm_slider_add(win);
472 elm_slider_min_max_set(sl, 0, 10);
473 elm_slider_value_set(sl, 7.86);
475 evas_object_smart_callback_add(sl, "changed", _sl_ch, NULL);
476 elm_slider_label_set(sl, "theta");
477 elm_slider_unit_format_set(sl, "%1.2f");
478 elm_slider_span_size_set(sl, 320);
479 evas_object_move(sl, 10, 60);
480 evas_object_resize(sl, 460, 40);
481 evas_object_layer_set(sl, 100);
482 evas_object_show(sl);
484 sl = elm_slider_add(win);
485 elm_slider_min_max_set(sl, -800, 800);
486 elm_slider_value_set(sl, -400);
488 evas_object_smart_callback_add(sl, "changed", _sl_ch, NULL);
489 elm_slider_label_set(sl, "A");
490 elm_slider_unit_format_set(sl, "%1.2f");
491 elm_slider_span_size_set(sl, 320);
492 evas_object_move(sl, 10, 100);
493 evas_object_resize(sl, 460, 40);
494 evas_object_layer_set(sl, 100);
495 evas_object_show(sl);