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;
21 int slices_w, slices_h;
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, 1024);
99 evas_map_util_3d_lighting(m,
100 x + (w / 2) , y + (h / 2) , -h * 10,
103 for (i = 0; i < 4; i++)
107 evas_map_point_color_get(m, i, &r, &g, &b, &a);
108 r = (double)r * 1.2; if (r > 255) r = 255;
109 g = (double)g * 1.2; if (g > 255) g = 255;
110 b = (double)b * 1.2; if (b > 255) b = 255;
111 evas_map_point_color_set(m, i, r, g, b, a);
115 evas_object_map_enable_set(sl->obj, EINA_TRUE);
116 evas_object_image_fill_set(sl->obj, 0, 0, w, h);
117 evas_object_map_set(sl->obj, m);
122 _slice_xyz(Slice *sl,
123 double x1, double y1, double z1,
124 double x2, double y2, double z2,
125 double x3, double y3, double z3,
126 double x4, double y4, double z4)
128 sl->x[0] = x1; sl->y[0] = y1; sl->z[0] = z1;
129 sl->x[1] = x2; sl->y[1] = y2; sl->z[1] = z2;
130 sl->x[2] = x3; sl->y[2] = y3; sl->z[2] = z3;
131 sl->x[3] = x4; sl->y[3] = y4; sl->z[3] = z4;
136 double u1, double v1,
137 double u2, double v2,
138 double u3, double v3,
139 double u4, double v4)
141 sl->u[0] = u1; sl->v[0] = v1;
142 sl->u[1] = u2; sl->v[1] = v2;
143 sl->u[2] = u3; sl->v[2] = v3;
144 sl->u[3] = u4; sl->v[3] = v4;
148 _deform_point(Vertex2 *vi, Vertex3 *vo, double rho, double theta, double A)
154 // theta == cone angle (0 -> PI/2)
155 // A == distance of cone apex from origin
156 // rho == angle of cone from vertical axis (...-PI/2 to PI/2...)
160 d = sqrt((vi->x * vi->x) + pow(vi->y - A, 2));
162 b = asin(vi->x / d) / sin(theta);
165 v1.y = d + A - (r * (1 - cos(b)) * sin(theta));
166 v1.z = r * (1 - cos(b)) * cos(theta);
168 vo->x = (v1.x * cos(rho)) - (v1.z * sin(rho));
170 vo->z = (v1.x * sin(rho)) + (v1.z * cos(rho));
174 _interp_point(Vertex3 *vi1, Vertex3 *vi2, Vertex3 *vo, double v)
176 vo->x = (v * vi2->x) + ((1.0 - v) * vi1->x);
177 vo->y = (v * vi2->y) + ((1.0 - v) * vi1->y);
178 vo->z = (v * vi2->z) + ((1.0 - v) * vi1->z);
182 _state_slices_clear(State *st)
189 for (j = 0; j < st->slices_h; j++)
191 for (i = 0; i < st->slices_w; i++)
195 _slice_free(st->slices[num]);
196 st->slices[num] = NULL;
210 _slice_obj_vert_color_merge(Slice *s1, int p1, Slice *s2, int p2,
211 Slice *s3, int p3, Slice *s4, int p4)
213 int r1 = 0, g1 = 0, b1 = 0, a1 = 0, r2 = 0, g2 = 0, b2 = 0, a2 = 0, n = 0;
218 m = (Evas_Map *)evas_object_map_get(s1->obj);
219 evas_map_point_color_get(m, p1, &r1, &g1, &b1, &a1);
220 r2 += r1; g2 += g1; b2 += b1; a2 += a1;
225 m = (Evas_Map *)evas_object_map_get(s2->obj);
226 evas_map_point_color_get(m, p2, &r1, &g1, &b1, &a1);
227 r2 += r1; g2 += g1; b2 += b1; a2 += a1;
232 m = (Evas_Map *)evas_object_map_get(s3->obj);
233 evas_map_point_color_get(m, p3, &r1, &g1, &b1, &a1);
234 r2 += r1; g2 += g1; b2 += b1; a2 += a1;
239 m = (Evas_Map *)evas_object_map_get(s4->obj);
240 evas_map_point_color_get(m, p4, &r1, &g1, &b1, &a1);
241 r2 += r1; g2 += g1; b2 += b1; a2 += a1;
245 r2 /= n; g2 /= n; b2 /= n; a2 /= n;
249 m = (Evas_Map *)evas_object_map_get(s1->obj);
250 evas_map_point_color_set(m, p1, r2, g2, b2, a2);
251 evas_object_map_set(s1->obj, m);
255 m = (Evas_Map *)evas_object_map_get(s2->obj);
256 evas_map_point_color_set(m, p2, r2, g2, b2, a2);
257 evas_object_map_set(s2->obj, m);
261 m = (Evas_Map *)evas_object_map_get(s3->obj);
262 evas_map_point_color_set(m, p3, r2, g2, b2, a2);
263 evas_object_map_set(s3->obj, m);
267 m = (Evas_Map *)evas_object_map_get(s4->obj);
268 evas_map_point_color_set(m, p4, r2, g2, b2, a2);
269 evas_object_map_set(s4->obj, m);
275 _state_update(State *st)
277 Evas_Coord x1, y1, x2, y2, mx, my, dst, dx, dy;
278 Evas_Coord x, y, w, h;
281 double b, minv = 0.0, minva, mgrad;
282 int gx, gy, gsz, gw, gh;
283 double rho, A, theta, perc, percm, n, rhol, Al, thetal;
285 evas_object_geometry_get(st->orig, &x, &y, &w, &h);
290 if (x2 >= x1) x2 = x1 - 1;
295 else if (mx >= w) mx = w - 1;
297 else if (my >= h) my = h - 1;
301 dst = sqrt((dx * dx) + (dy * dy));
304 // FIXME: clean up old objects
309 mgrad = (double)(y1 - y2) / (double)(x1 - x2);
313 _state_slices_clear(st);
315 st->slices_w = (w + gsz - 1) / gsz;
316 st->slices_h = (h + gsz - 1) / gsz;
317 st->slices = calloc(st->slices_w * st->slices_h, sizeof(Slice *));
318 if (!st->slices) return 0;
320 if (mx < 1) mx = 1; // quick hack to keep curl line visible
322 if (mgrad == 0.0) // special horizontal case
323 mgrad = 0.001; // quick dirty hack for now
328 b = my + (minv * mx);
330 if ((b >= -5) && (b <= (h + 5)))
332 if (minv > 0.0) // clamp to h
334 minv = (double)(h + 5 - my) / (double)(mx);
335 b = my + (minv * mx);
339 minv = (double)(-5 - my) / (double)(mx);
340 b = my + (minv * mx);
345 static Evas_Object *ol = NULL;
346 Evas_Coord lx1, ly1, lx2, ly2;
347 if (!ol) ol = evas_object_line_add(evas_object_evas_get(st->win));
348 evas_object_color_set(ol, 128, 0, 0, 128);
352 ly2 = y + b + (-minv * w);
353 evas_object_line_xy_set(ol, lx1, ly1, lx2, ly2);
354 evas_object_show(ol);
357 perc = (double)x2 / (double)x1;
358 percm = (double)mx / (double)x1;
359 if (perc < 0.0) perc = 0.0;
360 else if (perc > 1.0) perc = 1.0;
361 if (percm < 0.0) percm = 0.0;
362 else if (percm > 1.0) percm = 1.0;
364 minva = atan(minv) / (M_PI / 2);
365 if (minva < 0.0) minva = -minva;
370 if (A < -(h * 20)) A = -h * 20;
374 // rho = is how much the page is turned
376 n = 1.0 - cos(n * M_PI / 2.0);
382 // theta == curliness (how much page culrs in on itself
383 n = sin((1.0 - perc) * M_PI);
387 n = sin((1.0 - perc) * M_PI);
394 for (gx = 0; gx < w; gx += gsz)
396 for (gy = 0; gy < h; gy += gsz)
398 Vertex2 vi[4], vil[2];
399 Vertex3 vo[4], vol[2];
402 if ((gx + gw) > w) gw = w - gx;
403 if ((gy + gh) > h) gh = h - gy;
405 vi[0].x = gx; vi[0].y = gy;
406 vi[1].x = gx + gw; vi[1].y = gy;
407 vi[2].x = gx + gw; vi[2].y = gy + gh;
408 vi[3].x = gx; vi[3].y = gy + gh;
410 vil[0].x = gx; vil[0].y = h - gx;
411 vil[1].x = gx + gw; vil[1].y = h - (gx + gw);
413 for (i = 0; i < 2; i++)
415 _deform_point(&(vil[i]), &(vol[i]), rhol, thetal, Al);
417 for (i = 0; i < 4; i++)
419 _deform_point(&(vi[i]), &(vo[i]), rho, theta, A);
421 n = minva * sin(perc * M_PI);
425 _interp_point(&(vo[0]), &(vol[0]), &(vo[0]), n);
426 _interp_point(&(vo[1]), &(vol[1]), &(vo[1]), n);
429 _interp_point(&(vo[2]), &(vol[1]), &(vo[2]), n);
430 _interp_point(&(vo[3]), &(vol[0]), &(vo[3]), n);
435 #define SWPV3(a, b) do {vt = (a); (a) = (b); (b) = vt;} while (0)
438 vo[0].y = h - vo[0].y;
439 vo[1].y = h - vo[1].y;
440 vo[2].y = h - vo[2].y;
441 vo[3].y = h - vo[3].y;
445 st->slices[num] = sl;
448 vo[0].x, vo[0].y, vo[0].z,
449 vo[1].x, vo[1].y, vo[1].z,
450 vo[2].x, vo[2].y, vo[2].z,
451 vo[3].x, vo[3].y, vo[3].z);
455 gx + gw, gy + gh, gx, gy + gh);
458 gx, h - (gy + gh), gx + gw, h - (gy + gh),
459 gx + gw, h - gy, gx, h - gy);
460 _slice_apply(sl, x, y, w, h);
464 // FIX shading in the verticies to blend at the points
467 for (j = 0; j < st->slices_h; j++)
469 for (i = 0; i < st->slices_w; i++)
473 s[0] = s[1] = s[2] = s[3] = NULL;
475 if ((i > 0) && (j > 0)) s[0] = st->slices[num - 1 - st->slices_w];
476 if (j > 0) s[1] = st->slices[num - st->slices_w];
478 if (i > 0) s[2] = st->slices[num - 1];
479 s[3] = st->slices[num];
481 _slice_obj_vert_color_merge(s[0], 2, s[1], 3,
491 _state_end(State *st)
493 _state_slices_clear(st);
507 static Evas_Object *sl_rho, *sl_theta, *sl_A;
512 static Eina_List *pts = NULL;
516 Evas_Coord x, y, w, h;
519 EINA_LIST_FREE(pts, o) evas_object_del(o);
521 evas_object_geometry_get(st->orig, &x, &y, &w, &h);
522 for (j = 0; j < h; j += 20)
524 for (i = 0; i < w; i += 20)
528 double rho, theta, A, n;
532 rho = elm_slider_value_get(sl_rho);
533 A = elm_slider_value_get(sl_A);
534 theta = elm_slider_value_get(sl_theta);
536 _deform_point(&vi, &vo, rho, theta, A);
538 o = evas_object_image_add(evas_object_evas_get(st->win));
539 evas_object_image_smooth_scale_set(o, 0);
540 evas_object_pass_events_set(o, 1);
541 evas_object_image_source_set(o, st->orig);
545 evas_map_smooth_set(m, 0);
548 evas_map_point_coord_set(m, k, x + vo.x, y + vo.y, -vo.z);
549 evas_map_point_image_uv_set(m, k, 0 , 0);
550 evas_map_point_color_set(m, k, 255, 255, 255, 255);
552 evas_map_point_coord_set(m, k, x + vo.x + 10, y + vo.y, -vo.z);
553 evas_map_point_image_uv_set(m, k, w , 0);
554 evas_map_point_color_set(m, k, 255, 255, 255, 255);
556 evas_map_point_coord_set(m, k, x + vo.x + 10, y + vo.y + 10, -vo.z);
557 evas_map_point_image_uv_set(m, k, w , h);
558 evas_map_point_color_set(m, k, 255, 255, 255, 255);
560 evas_map_point_coord_set(m, k, x + vo.x, y + vo.y + 10, -vo.z);
561 evas_map_point_image_uv_set(m, k, 0 , h);
562 evas_map_point_color_set(m, k, 255, 255, 255, 255);
565 evas_map_util_3d_perspective(m, x + (w / 2), y + (h / 2), 0, 1024);
567 evas_object_map_enable_set(o, EINA_TRUE);
568 evas_object_image_fill_set(o, 0, 0, w, h);
569 evas_object_map_set(o, m);
572 pts = eina_list_append(pts, o);
578 _sl_ch(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
595 im_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
597 Evas_Event_Mouse_Down *ev = event_info;
598 Evas_Object *win = data;
601 if (ev->button != 1) return;
602 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
606 state.x = ev->canvas.x - x;
607 state.y = ev->canvas.y - y;
608 state.down_x = state.x;
609 state.down_y = state.y;
610 if (_state_update(&state))
611 evas_object_lower(obj);
612 printf("v %i %i\n", state.x, state.y);
616 im_up_cb(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
618 Evas_Event_Mouse_Up *ev = event_info;
621 if (ev->button != 1) return;
622 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
624 state.x = ev->canvas.x - x;
625 state.y = ev->canvas.y - y;
626 evas_object_raise(obj);
627 printf("^ %i %i\n", state.x, state.y);
632 im_move_cb(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
634 Evas_Event_Mouse_Move *ev = event_info;
637 if (!state.down) return;
638 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
639 state.x = ev->cur.canvas.x - x;
640 state.y = ev->cur.canvas.y - y;
641 printf("@ %i %i\n", state.x, state.y);
642 if (_state_update(&state))
643 evas_object_lower(obj);
647 test_flip_page(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
649 Evas_Object *win, *bg, *im;
652 win = elm_win_add(NULL, "flip_page", ELM_WIN_BASIC);
653 elm_win_title_set(win, "Flip Page");
654 elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
655 elm_win_autodel_set(win, 1);
657 bg = elm_bg_add(win);
658 elm_win_resize_object_add(win, bg);
659 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
660 evas_object_show(bg);
663 im = elm_layout_add(win);
664 snprintf(buf, sizeof(buf), "%s/objects/test.edj", PACKAGE_DATA_DIR);
665 elm_layout_file_set(im, buf, "layout");
667 im = evas_object_image_filled_add(evas_object_evas_get(win));
668 snprintf(buf, sizeof(buf), "%s/images/%s",
669 PACKAGE_DATA_DIR, "twofish.jpg");
670 evas_object_image_file_set(im, buf, NULL);
672 evas_object_move(im, 140, 140);
673 evas_object_resize(im, 200, 200);
674 evas_object_show(im);
676 evas_object_event_callback_add(im, EVAS_CALLBACK_MOUSE_DOWN, im_down_cb, win);
677 evas_object_event_callback_add(im, EVAS_CALLBACK_MOUSE_UP, im_up_cb, win);
678 evas_object_event_callback_add(im, EVAS_CALLBACK_MOUSE_MOVE, im_move_cb, win);
680 evas_object_resize(win, 480, 480);
681 evas_object_show(win);
686 sl = elm_slider_add(win);
687 elm_slider_min_max_set(sl, -5, 5);
688 elm_slider_value_set(sl, 0);
690 evas_object_smart_callback_add(sl, "changed", _sl_ch, NULL);
691 elm_slider_label_set(sl, "rho");
692 elm_slider_unit_format_set(sl, "%1.2f");
693 elm_slider_span_size_set(sl, 320);
694 evas_object_move(sl, 10, 20);
695 evas_object_resize(sl, 460, 40);
696 evas_object_layer_set(sl, 100);
697 evas_object_show(sl);
699 sl = elm_slider_add(win);
700 elm_slider_min_max_set(sl, 0, 10);
701 elm_slider_value_set(sl, 7.86);
703 evas_object_smart_callback_add(sl, "changed", _sl_ch, NULL);
704 elm_slider_label_set(sl, "theta");
705 elm_slider_unit_format_set(sl, "%1.2f");
706 elm_slider_span_size_set(sl, 320);
707 evas_object_move(sl, 10, 60);
708 evas_object_resize(sl, 460, 40);
709 evas_object_layer_set(sl, 100);
710 evas_object_show(sl);
712 sl = elm_slider_add(win);
713 elm_slider_min_max_set(sl, -800, 800);
714 elm_slider_value_set(sl, -400);
716 evas_object_smart_callback_add(sl, "changed", _sl_ch, NULL);
717 elm_slider_label_set(sl, "A");
718 elm_slider_unit_format_set(sl, "%1.2f");
719 elm_slider_span_size_set(sl, 320);
720 evas_object_move(sl, 10, 100);
721 evas_object_resize(sl, 460, 40);
722 evas_object_layer_set(sl, 100);
723 evas_object_show(sl);