aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/elementary/src/bin/test_flip_page.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/elementary/src/bin/test_flip_page.c913
1 files changed, 913 insertions, 0 deletions
diff --git a/libraries/elementary/src/bin/test_flip_page.c b/libraries/elementary/src/bin/test_flip_page.c
new file mode 100644
index 0000000..20cafb3
--- /dev/null
+++ b/libraries/elementary/src/bin/test_flip_page.c
@@ -0,0 +1,913 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4#include <Elementary.h>
5#ifndef ELM_LIB_QUICKLAUNCH
6
7typedef struct _State State;
8typedef struct _Slice Slice;
9
10typedef struct _Vertex2 Vertex2;
11typedef struct _Vertex3 Vertex3;
12
13struct _State
14{
15 Evas_Object *front, *back;
16 Evas_Coord down_x, down_y, x, y;
17 Eina_Bool down : 1;
18 Eina_Bool backflip : 1;
19
20 Ecore_Animator *anim;
21 Ecore_Job *job;
22 Evas_Coord ox, oy, w, h;
23 int slices_w, slices_h;
24 Slice **slices, **slices2;
25 int dir; // 0 == left, 1 == right, 2 == up, 3 == down
26 int finish;
27};
28
29struct _Slice
30{
31 Evas_Object *obj;
32 // (0)---(1)
33 // | |
34 // | |
35 // (3)---(2)
36 double u[4], v[4], x[4], y[4], z[4];
37};
38
39struct _Vertex2
40{
41 double x, y;
42};
43
44struct _Vertex3
45{
46 double x, y, z;
47};
48
49static State state =
50{
51 NULL, NULL,
52 0, 0, 0, 0,
53 0,
54 0,
55
56 NULL,
57 NULL,
58 0, 0, 0, 0,
59 0, 0,
60 NULL, NULL,
61 -1,
62 0
63};
64
65static Slice *
66_slice_new(State *st __UNUSED__, Evas_Object *obj)
67{
68 Slice *sl;
69
70 sl = calloc(1, sizeof(Slice));
71 if (!sl) return NULL;
72 sl->obj = evas_object_image_add(evas_object_evas_get(obj));
73 evas_object_image_smooth_scale_set(sl->obj, 0);
74 evas_object_pass_events_set(sl->obj, 1);
75 evas_object_image_source_set(sl->obj, obj);
76 return sl;
77}
78
79static void
80_slice_free(Slice *sl)
81{
82 evas_object_del(sl->obj);
83 free(sl);
84}
85
86static void
87_slice_apply(State *st, Slice *sl,
88 Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__, Evas_Coord w, Evas_Coord h __UNUSED__,
89 Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
90{
91 Evas_Map *m;
92 int i;
93
94 m = evas_map_new(4);
95 if (!m) return;
96 evas_map_smooth_set(m, 0);
97 for (i = 0; i < 4; i++)
98 {
99 evas_map_point_color_set(m, i, 255, 255, 255, 255);
100 if (st->dir == 0)
101 {
102 int p[4] = { 0, 1, 2, 3 };
103 evas_map_point_coord_set(m, i, ox + sl->x[p[i]], oy + sl->y[p[i]], sl->z[p[i]]);
104 evas_map_point_image_uv_set(m, i, sl->u[p[i]] , sl->v[p[i]]);
105 }
106 else if (st->dir == 1)
107 {
108 int p[4] = { 1, 0, 3, 2 };
109 evas_map_point_coord_set(m, i, ox + (w - sl->x[p[i]]), oy + sl->y[p[i]], sl->z[p[i]]);
110 evas_map_point_image_uv_set(m, i, ow - sl->u[p[i]] , sl->v[p[i]]);
111 }
112 else if (st->dir == 2)
113 {
114 int p[4] = { 1, 0, 3, 2 };
115 evas_map_point_coord_set(m, i, ox + sl->y[p[i]], oy + sl->x[p[i]], sl->z[p[i]]);
116 evas_map_point_image_uv_set(m, i, sl->v[p[i]] , sl->u[p[i]]);
117 }
118 else if (st->dir == 3)
119 {
120 int p[4] = { 0, 1, 2, 3 };
121 evas_map_point_coord_set(m, i, ox + sl->y[p[i]], oy + (w - sl->x[p[i]]), sl->z[p[i]]);
122 evas_map_point_image_uv_set(m, i, sl->v[p[i]] , oh - sl->u[p[i]]);
123 }
124 }
125 evas_object_map_enable_set(sl->obj, EINA_TRUE);
126 evas_object_image_fill_set(sl->obj, 0, 0, ow, oh);
127 evas_object_map_set(sl->obj, m);
128 evas_map_free(m);
129}
130
131static void
132_slice_3d(State *st __UNUSED__, Slice *sl, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
133{
134 Evas_Map *m = (Evas_Map *)evas_object_map_get(sl->obj);
135 int i;
136
137 if (!m) return;
138 // vanishing point is center of page, and focal dist is 1024
139 evas_map_util_3d_perspective(m, x + (w / 2), y + (h / 2), 0, 1024);
140 for (i = 0; i < 4; i++)
141 {
142 Evas_Coord xx, yy, zz;
143 evas_map_point_coord_get(m, i, &xx, &yy, &zz);
144 evas_map_point_coord_set(m, i, xx, yy, 0);
145 }
146 if (evas_map_util_clockwise_get(m)) evas_object_show(sl->obj);
147 else evas_object_hide(sl->obj);
148 evas_object_map_set(sl->obj, m);
149}
150
151static void
152_slice_light(State *st __UNUSED__, Slice *sl, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
153{
154 Evas_Map *m = (Evas_Map *)evas_object_map_get(sl->obj);
155 int i;
156
157 if (!m) return;
158 evas_map_util_3d_lighting(m,
159 // light position
160 // (centered over page 10 * h toward camera)
161 x + (w / 2) , y + (h / 2) , -10000,
162 255, 255, 255, // light color
163 0 , 0 , 0); // ambient minimum
164 // multiply brightness by 1.2 to make lightish bits all white so we dont
165 // add shading where we could otherwise be pure white
166 for (i = 0; i < 4; i++)
167 {
168 int r, g, b, a;
169
170 evas_map_point_color_get(m, i, &r, &g, &b, &a);
171 r = (double)r * 1.2; if (r > 255) r = 255;
172 g = (double)g * 1.2; if (g > 255) g = 255;
173 b = (double)b * 1.2; if (b > 255) b = 255;
174 evas_map_point_color_set(m, i, r, g, b, a);
175 }
176 evas_object_map_set(sl->obj, m);
177}
178
179static void
180_slice_xyz(State *st __UNUSED__, Slice *sl,
181 double xx1, double yy1, double zz1,
182 double xx2, double yy2, double zz2,
183 double xx3, double yy3, double zz3,
184 double xx4, double yy4, double zz4)
185{
186 sl->x[0] = xx1; sl->y[0] = yy1; sl->z[0] = zz1;
187 sl->x[1] = xx2; sl->y[1] = yy2; sl->z[1] = zz2;
188 sl->x[2] = xx3; sl->y[2] = yy3; sl->z[2] = zz3;
189 sl->x[3] = xx4; sl->y[3] = yy4; sl->z[3] = zz4;
190}
191
192static void
193_slice_uv(State *st __UNUSED__, Slice *sl,
194 double u1, double v1,
195 double u2, double v2,
196 double u3, double v3,
197 double u4, double v4)
198{
199 sl->u[0] = u1; sl->v[0] = v1;
200 sl->u[1] = u2; sl->v[1] = v2;
201 sl->u[2] = u3; sl->v[2] = v3;
202 sl->u[3] = u4; sl->v[3] = v4;
203}
204
205static void
206_deform_point(Vertex2 *vi, Vertex3 *vo, double rho, double theta, double A)
207{
208 // ^Y
209 // |
210 // | X
211 // +---->
212 // theta == cone angle (0 -> PI/2)
213 // A == distance of cone apex from origin
214 // rho == angle of cone from vertical axis (...-PI/2 to PI/2...)
215 Vertex3 v1;
216 double d, r, b;
217
218 d = sqrt((vi->x * vi->x) + pow(vi->y - A, 2));
219 r = d * sin(theta);
220 b = asin(vi->x / d) / sin(theta);
221
222 v1.x = r * sin(b);
223 v1.y = d + A - (r * (1 - cos(b)) * sin(theta));
224 v1.z = r * (1 - cos(b)) * cos(theta);
225
226 vo->x = (v1.x * cos(rho)) - (v1.z * sin(rho));
227 vo->y = v1.y;
228 vo->z = (v1.x * sin(rho)) + (v1.z * cos(rho));
229}
230
231static void
232_interp_point(Vertex3 *vi1, Vertex3 *vi2, Vertex3 *vo, double v)
233{
234 vo->x = (v * vi2->x) + ((1.0 - v) * vi1->x);
235 vo->y = (v * vi2->y) + ((1.0 - v) * vi1->y);
236 vo->z = (v * vi2->z) + ((1.0 - v) * vi1->z);
237}
238
239static void
240_state_slices_clear(State *st)
241{
242 int i, j, num;
243
244 if (st->slices)
245 {
246 num = 0;
247 for (j = 0; j < st->slices_h; j++)
248 {
249 for (i = 0; i < st->slices_w; i++)
250 {
251 if (st->slices[num]) _slice_free(st->slices[num]);
252 if (st->slices2[num]) _slice_free(st->slices2[num]);
253 num++;
254 }
255 }
256 free(st->slices);
257 free(st->slices2);
258 st->slices = NULL;
259 st->slices2 = NULL;
260 }
261 st->slices_w = 0;
262 st->slices_h = 0;
263}
264
265static int
266_slice_obj_color_sum(Slice *s, int p, int *r, int *g, int *b, int *a)
267{
268 Evas_Map *m;
269 int rr = 0, gg = 0, bb = 0, aa = 0;
270
271 if (!s) return 0;
272 m = (Evas_Map *)evas_object_map_get(s->obj);
273 if (!m) return 0;
274 evas_map_point_color_get(m, p, &rr, &gg, &bb, &aa);
275 *r += rr; *g += gg; *b += bb; *a += aa;
276 return 1;
277}
278
279static void
280_slice_obj_color_set(Slice *s, int p, int r, int g, int b, int a)
281{
282 Evas_Map *m;
283
284 if (!s) return;
285 m = (Evas_Map *)evas_object_map_get(s->obj);
286 if (!m) return;
287 evas_map_point_color_set(m, p, r, g, b, a);
288 evas_object_map_set(s->obj, m);
289}
290
291static void
292_slice_obj_vert_color_merge(Slice *s1, int p1, Slice *s2, int p2,
293 Slice *s3, int p3, Slice *s4, int p4)
294{
295 int r = 0, g = 0, b = 0, a = 0, n = 0;
296
297 n += _slice_obj_color_sum(s1, p1, &r, &g, &b, &a);
298 n += _slice_obj_color_sum(s2, p2, &r, &g, &b, &a);
299 n += _slice_obj_color_sum(s3, p3, &r, &g, &b, &a);
300 n += _slice_obj_color_sum(s4, p4, &r, &g, &b, &a);
301
302 if (n < 1) return;
303 r /= n; g /= n; b /= n; a /= n;
304
305 _slice_obj_color_set(s1, p1, r, g, b, a);
306 _slice_obj_color_set(s2, p2, r, g, b, a);
307 _slice_obj_color_set(s3, p3, r, g, b, a);
308 _slice_obj_color_set(s4, p4, r, g, b, a);
309}
310
311static int
312_state_update(State *st)
313{
314 Evas_Coord xx1, yy1, xx2, yy2, mx, my, dst, dx, dy;
315 Evas_Coord x, y, w, h, ox, oy, ow, oh;
316 int i, j, num, nn, jump, num2;
317 Slice *sl;
318 double b, minv = 0.0, minva, mgrad;
319 int gx, gy, gszw, gszh, gw, gh, col, row, nw, nh;
320 double rho, A, theta, perc, percm, n, rhol, Al, thetal;
321 Vertex3 *tvo, *tvol;
322
323 st->backflip = 0;
324
325 evas_object_geometry_get(st->front, &x, &y, &w, &h);
326 ox = x; oy = y; ow = w; oh = h;
327 xx1 = st->down_x;
328 yy1 = st->down_y;
329 xx2 = st->x;
330 yy2 = st->y;
331
332 dx = xx2 - xx1;
333 dy = yy2 - yy1;
334 dst = sqrt((dx * dx) + (dy * dy));
335 if (st->dir == -1)
336 {
337 if (dst < 20) // MAGIC: 20 == drag hysterisis
338 return 0;
339 }
340 if (st->dir == -1)
341 {
342 if ((xx1 > (w / 2)) && (dx < 0) && (abs(dx) > abs(dy))) st->dir = 0; // left
343 else if ((xx1 < (w / 2)) && (dx >= 0) && (abs(dx) > abs(dy))) st->dir = 1; // right
344 else if ((yy1 > (h / 2)) && (dy < 0) && (abs(dy) >= abs(dx))) st->dir = 2; // up
345 else if ((yy1 < (h / 2)) && (dy >= 0) && (abs(dy) >= abs(dx))) st->dir = 3; // down
346 if (st->dir == -1) return 0;
347 }
348 if (st->dir == 0)
349 {
350 // no nothing. left drag is standard
351 }
352 else if (st->dir == 1)
353 {
354 xx1 = (w - 1) - xx1;
355 xx2 = (w - 1) - xx2;
356 }
357 else if (st->dir == 2)
358 {
359 Evas_Coord tmp;
360
361 tmp = xx1; xx1 = yy1; yy1 = tmp;
362 tmp = xx2; xx2 = yy2; yy2 = tmp;
363 tmp = w; w = h; h = tmp;
364 }
365 else if (st->dir == 3)
366 {
367 Evas_Coord tmp;
368
369 tmp = xx1; xx1 = yy1; yy1 = tmp;
370 tmp = xx2; xx2 = yy2; yy2 = tmp;
371 tmp = w; w = h; h = tmp;
372 xx1 = (w - 1) - xx1;
373 xx2 = (w - 1) - xx2;
374 }
375
376 if (xx2 >= xx1) xx2 = xx1 - 1;
377 mx = (xx1 + xx2) / 2;
378 my = (yy1 + yy2) / 2;
379
380 if (mx < 0) mx = 0;
381 else if (mx >= w) mx = w - 1;
382 if (my < 0) my = 0;
383 else if (my >= h) my = h - 1;
384
385 mgrad = (double)(yy1 - yy2) / (double)(xx1 - xx2);
386
387 if (mx < 1) mx = 1; // quick hack to keep curl line visible
388
389 if (mgrad == 0.0) // special horizontal case
390 mgrad = 0.001; // quick dirty hack for now
391 // else
392 {
393 minv = 1.0 / mgrad;
394 // y = (m * x) + b
395 b = my + (minv * mx);
396 }
397 if ((b >= -5) && (b <= (h + 5)))
398 {
399 if (minv > 0.0) // clamp to h
400 {
401 minv = (double)(h + 5 - my) / (double)(mx);
402 b = my + (minv * mx);
403 }
404 else // clamp to 0
405 {
406 minv = (double)(-5 - my) / (double)(mx);
407 b = my + (minv * mx);
408 }
409 }
410
411 perc = (double)xx2 / (double)xx1;
412 percm = (double)mx / (double)xx1;
413 if (perc < 0.0) perc = 0.0;
414 else if (perc > 1.0) perc = 1.0;
415 if (percm < 0.0) percm = 0.0;
416 else if (percm > 1.0) percm = 1.0;
417
418 minva = atan(minv) / (M_PI / 2);
419 if (minva < 0.0) minva = -minva;
420
421 // A = apex of cone
422 if (b <= 0) A = b;
423 else A = h - b;
424 if (A < -(h * 20)) A = -h * 20;
425 //--//
426 Al = -5;
427
428 // rho = is how much the page is turned
429 n = 1.0 - perc;
430 n = 1.0 - cos(n * M_PI / 2.0);
431 n = n * n;
432 rho = -(n * M_PI);
433 //--//
434 rhol = -(n * M_PI);
435
436 // theta == curliness (how much page culrs in on itself
437 n = sin((1.0 - perc) * M_PI);
438 n = n * 1.2;
439 theta = 7.86 + n;
440 //--//
441 n = sin((1.0 - perc) * M_PI);
442 n = 1.0 - n;
443 n = n * n;
444 n = 1.0 - n;
445 thetal = 7.86 + n;
446
447 nw = 16;
448 nh = 16;
449 gszw = w / nw;
450 gszh = h / nh;
451 if (gszw < 4) gszw = 4;
452 if (gszh < 4) gszh = 4;
453
454 nw = (w + gszw - 1) / gszw;
455 nh = (h + gszh - 1) / gszh;
456 if ((st->slices_w != nw) || (st->slices_h != nh)) _state_slices_clear(st);
457 st->slices_w = nw;
458 st->slices_h = nh;
459 if (!st->slices)
460 {
461 st->slices = calloc(st->slices_w * st->slices_h, sizeof(Slice *));
462 if (!st->slices) return 0;
463 st->slices2 = calloc(st->slices_w * st->slices_h, sizeof(Slice *));
464 if (!st->slices2)
465 {
466 free(st->slices);
467 st->slices = NULL;
468 return 0;
469 }
470 }
471
472 num = (st->slices_w + 1) * (st->slices_h + 1);
473
474 tvo = alloca(sizeof(Vertex3) * num);
475 tvol = alloca(sizeof(Vertex3) * (st->slices_w + 1));
476
477 for (col = 0, gx = 0; gx <= (w + gszw - 1); gx += gszw, col++)
478 {
479 Vertex2 vil;
480
481 vil.x = gx;
482 vil.y = h - gx;
483 _deform_point(&vil, &(tvol[col]), rhol, thetal, Al);
484 }
485
486 n = minva * sin(perc * M_PI);
487 n = n * n;
488
489 num = 0;
490 for (col = 0, gx = 0; gx <= (w + gszw - 1); gx += gszw, col++)
491 {
492 for (gy = 0; gy <= (h + gszh - 1); gy += gszh)
493 {
494 Vertex2 vi;
495 Vertex3 vo, tvo1;
496
497 if (gx > w) vi.x = w;
498 else vi.x = gx;
499 if (gy > h) vi.y = h;
500 else vi.y = gy;
501 _deform_point(&vi, &vo, rho, theta, A);
502 tvo1 = tvol[col];
503 if (gy > h) tvo1.y = h;
504 else tvo1.y = gy;
505 _interp_point(&vo, &tvo1, &(tvo[num]), n);
506 num++;
507 }
508 }
509
510 jump = st->slices_h + 1;
511 for (col = 0, gx = 0; gx < w; gx += gszw, col++)
512 {
513 num = st->slices_h * col;
514 num2 = jump * col;
515
516 gw = gszw;
517 if ((gx + gw) > w) gw = w - gx;
518
519 for (row = 0, gy = 0; gy < h; gy += gszh, row++)
520 {
521 Vertex3 vo[4];
522
523 if (b > 0) nn = num + st->slices_h - row - 1;
524 else nn = num + row;
525
526 gh = gszh;
527 if ((gy + gh) > h) gh = h - gy;
528
529 vo[0] = tvo[num2 + row];
530 vo[1] = tvo[num2 + row + jump];
531 vo[2] = tvo[num2 + row + jump + 1];
532 vo[3] = tvo[num2 + row + 1];
533#define SWP(a, b) do {typeof(a) vt; vt = (a); (a) = (b); (b) = vt;} while (0)
534 if (b > 0)
535 {
536 SWP(vo[0], vo[3]);
537 SWP(vo[1], vo[2]);
538 vo[0].y = h - vo[0].y;
539 vo[1].y = h - vo[1].y;
540 vo[2].y = h - vo[2].y;
541 vo[3].y = h - vo[3].y;
542 }
543
544 // FRONT
545 sl = st->slices[nn];
546 if (!sl)
547 {
548 sl = _slice_new(st, st->front);
549 st->slices[nn] = sl;
550 }
551 _slice_xyz(st, sl,
552 vo[0].x, vo[0].y, vo[0].z,
553 vo[1].x, vo[1].y, vo[1].z,
554 vo[2].x, vo[2].y, vo[2].z,
555 vo[3].x, vo[3].y, vo[3].z);
556 if (b <= 0)
557 _slice_uv(st, sl,
558 gx, gy, gx + gw, gy,
559 gx + gw, gy + gh, gx, gy + gh);
560 else
561 _slice_uv(st, sl,
562 gx, h - (gy + gh), gx + gw, h - (gy + gh),
563 gx + gw, h - gy, gx, h - gy);
564
565 // BACK
566 sl = st->slices2[nn];
567 if (!sl)
568 {
569 sl = _slice_new(st, st->back);
570 st->slices2[nn] = sl;
571 }
572
573 _slice_xyz(st, sl,
574 vo[1].x, vo[1].y, vo[1].z,
575 vo[0].x, vo[0].y, vo[0].z,
576 vo[3].x, vo[3].y, vo[3].z,
577 vo[2].x, vo[2].y, vo[2].z);
578 if (st->backflip)
579 {
580 if (b <= 0)
581 _slice_uv(st, sl,
582 gx + gw, gy, gx, gy,
583 gx, gy + gh, gx + gw, gy + gh);
584 else
585 _slice_uv(st, sl,
586 gx + gw, h - (gy + gh), gx, h - (gy + gh),
587 gx, h - gy, gx + gw, h - gy);
588 }
589 else
590 {
591 if (b <= 0)
592 _slice_uv(st, sl,
593 w - (gx + gw), gy, w - (gx), gy,
594 w - (gx), gy + gh, w - (gx + gw), gy + gh);
595 else
596 _slice_uv(st, sl,
597 w - (gx + gw), h - (gy + gh), w - (gx), h - (gy + gh),
598 w - (gx), h - gy, w - (gx + gw), h - gy);
599 }
600 }
601 }
602
603 num = 0;
604 for (j = 0; j < st->slices_h; j++)
605 {
606 for (i = 0; i < st->slices_w; i++)
607 {
608 _slice_apply(st, st->slices[num], x, y, w, h, ox, oy, ow, oh);
609 _slice_apply(st, st->slices2[num], x, y, w, h, ox, oy, ow, oh);
610 _slice_light(st, st->slices[num], ox, oy, ow, oh);
611 _slice_light(st, st->slices2[num], ox, oy, ow, oh);
612 num++;
613 }
614 }
615
616 for (i = 0; i <= st->slices_w; i++)
617 {
618 num = i * st->slices_h;
619 for (j = 0; j <= st->slices_h; j++)
620 {
621 Slice *s[4];
622
623 s[0] = s[1] = s[2] = s[3] = NULL;
624 if ((i > 0) && (j > 0))
625 s[0] = st->slices[num - 1 - st->slices_h];
626 if ((i < st->slices_w) && (j > 0))
627 s[1] = st->slices[num - 1];
628 if ((i > 0) && (j < st->slices_h))
629 s[2] = st->slices[num - st->slices_h];
630 if ((i < st->slices_w) && (j < st->slices_h))
631 s[3] = st->slices[num];
632 if (st->dir == 0)
633 _slice_obj_vert_color_merge(s[0], 2, s[1], 3,
634 s[2], 1, s[3], 0);
635 else if (st->dir == 1)
636 _slice_obj_vert_color_merge(s[0], 3, s[1], 2,
637 s[2], 0, s[3], 1);
638 else if (st->dir == 2)
639 _slice_obj_vert_color_merge(s[0], 3, s[1], 2,
640 s[2], 0, s[3], 1);
641 else if (st->dir == 3)
642 _slice_obj_vert_color_merge(s[0], 2, s[1], 3,
643 s[2], 1, s[3], 0);
644 s[0] = s[1] = s[2] = s[3] = NULL;
645 if ((i > 0) && (j > 0))
646 s[0] = st->slices2[num - 1 - st->slices_h];
647 if ((i < st->slices_w) && (j > 0))
648 s[1] = st->slices2[num - 1];
649 if ((i > 0) && (j < st->slices_h))
650 s[2] = st->slices2[num - st->slices_h];
651 if ((i < st->slices_w) && (j < st->slices_h))
652 s[3] = st->slices2[num];
653 if (st->dir == 0)
654 _slice_obj_vert_color_merge(s[0], 3, s[1], 2,
655 s[2], 0, s[3], 1);
656 else if (st->dir == 1)
657 _slice_obj_vert_color_merge(s[0], 2, s[1], 3,
658 s[2], 1, s[3], 0);
659 else if (st->dir == 2)
660 _slice_obj_vert_color_merge(s[0], 2, s[1], 3,
661 s[2], 1, s[3], 0);
662 else if (st->dir == 3)
663 _slice_obj_vert_color_merge(s[0], 3, s[1], 2,
664 s[2], 0, s[3], 1);
665 num++;
666 }
667 }
668
669 num = 0;
670 for (i = 0; i < st->slices_w; i++)
671 {
672 for (j = 0; j < st->slices_h; j++)
673 {
674 _slice_3d(st, st->slices[num], ox, oy, ow, oh);
675 _slice_3d(st, st->slices2[num], ox, oy, ow, oh);
676 num++;
677 }
678 }
679
680 return 1;
681}
682
683static void
684_state_end(State *st)
685{
686 _state_slices_clear(st);
687}
688
689static Eina_Bool
690_state_anim(void *data, double pos)
691{
692 State *st = data;
693 double p;
694
695 p = ecore_animator_pos_map(pos, ECORE_POS_MAP_ACCELERATE, 0.0, 0.0);
696 if (st->finish)
697 {
698 if (st->dir == 0)
699 st->x = st->ox * (1.0 - p);
700 else if (st->dir == 1)
701 st->x = st->ox + ((st->w - st->ox) * p);
702 else if (st->dir == 2)
703 st->y = st->oy * (1.0 - p);
704 else if (st->dir == 3)
705 st->y = st->oy + ((st->h - st->oy) * p);
706 }
707 else
708 {
709 if (st->dir == 0)
710 st->x = st->ox + ((st->w - st->ox) * p);
711 else if (st->dir == 1)
712 st->x = st->ox * (1.0 - p);
713 else if (st->dir == 2)
714 st->y = st->oy + ((st->h - st->oy) * p);
715 else if (st->dir == 3)
716 st->y = st->oy * (1.0 - p);
717 }
718 _state_update(st);
719 if (pos < 1.0) return EINA_TRUE;
720 evas_object_show(st->front);
721 evas_object_show(st->back);
722 _state_end(st);
723 st->anim = NULL;
724 return EINA_FALSE;
725}
726
727static void
728_update_curl_job(void *data)
729{
730 State *st = data;
731 st->job = NULL;
732 if (_state_update(st))
733 {
734 evas_object_hide(st->front);
735 evas_object_hide(st->back);
736 }
737}
738
739static void
740im_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
741{
742 State *st = &state;
743 Evas_Event_Mouse_Down *ev = event_info;
744 Evas_Coord x, y, w, h;
745
746 if (ev->button != 1) return;
747 st->front = data;
748 st->back = evas_object_data_get(data, "im2");
749 st->backflip = 1;
750 st->down = 1;
751 evas_object_geometry_get(st->front, &x, &y, &w, &h);
752 st->x = ev->canvas.x - x;
753 st->y = ev->canvas.y - y;
754 st->w = w;
755 st->h = h;
756 st->down_x = st->x;
757 st->down_y = st->y;
758 st->dir = -1;
759 if (_state_update(st))
760 {
761 evas_object_hide(st->front);
762 evas_object_hide(st->back);
763 }
764}
765
766static void
767im_up_cb(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
768{
769 State *st = &state;
770 Evas_Event_Mouse_Up *ev = event_info;
771 Evas_Coord x, y, w, h;
772 double tm = 0.5;
773
774 if (ev->button != 1) return;
775 st->down = 0;
776 evas_object_geometry_get(st->front, &x, &y, &w, &h);
777 st->x = ev->canvas.x - x;
778 st->y = ev->canvas.y - y;
779 st->w = w;
780 st->h = h;
781 st->ox = st->x;
782 st->oy = st->y;
783 if (st->job)
784 {
785 ecore_job_del(st->job);
786 st->job = NULL;
787 }
788 if (st->anim) ecore_animator_del(st->anim);
789 st->finish = 0;
790 if (st->dir == 0)
791 {
792 tm = (double)st->x / (double)st->w;
793 if (st->x < (st->w / 2)) st->finish = 1;
794 }
795 else if (st->dir == 1)
796 {
797 if (st->x > (st->w / 2)) st->finish = 1;
798 tm = 1.0 - ((double)st->x / (double)st->w);
799 }
800 else if (st->dir == 2)
801 {
802 if (st->y < (st->h / 2)) st->finish = 1;
803 tm = (double)st->y / (double)st->h;
804 }
805 else if (st->dir == 3)
806 {
807 if (st->y > (st->h / 2)) st->finish = 1;
808 tm = 1.0 - ((double)st->y / (double)st->h);
809 }
810 if (tm < 0.01) tm = 0.01;
811 else if (tm > 0.99) tm = 0.99;
812 if (!st->finish) tm = 1.0 - tm;
813 tm *= 0.5;
814 st->anim = ecore_animator_timeline_add(tm, _state_anim, st);
815 _state_anim(st, 0.0);
816}
817
818static void
819im_move_cb(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
820{
821 State *st = &state;
822 Evas_Event_Mouse_Move *ev = event_info;
823 Evas_Coord x, y, w, h;
824
825 if (!st->down) return;
826 evas_object_geometry_get(st->front, &x, &y, &w, &h);
827 st->x = ev->cur.canvas.x - x;
828 st->y = ev->cur.canvas.y - y;
829 st->w = w;
830 st->h = h;
831 if (st->job) ecore_job_del(st->job);
832 st->job = ecore_job_add(_update_curl_job, st);
833}
834
835void
836test_flip_page(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
837{
838 Evas_Object *win, *im, *im2, *rc;
839 char buf[PATH_MAX];
840
841 win = elm_win_util_standard_add("flip-page", "Flip Page");
842 elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
843 elm_win_autodel_set(win, EINA_TRUE);
844
845 im2 = evas_object_image_filled_add(evas_object_evas_get(win));
846 snprintf(buf, sizeof(buf), "%s/images/%s",
847 elm_app_data_dir_get(), "sky_04.jpg");
848 evas_object_image_file_set(im2, buf, NULL);
849 evas_object_move(im2, 40, 40);
850 evas_object_resize(im2, 400, 400);
851 evas_object_show(im2);
852
853#if 0
854 im = elm_layout_add(win);
855 snprintf(buf, sizeof(buf), "%s/objects/test.edj", elm_app_data_dir_get());
856 elm_layout_file_set(im, buf, "layout");
857#else
858 im = evas_object_image_filled_add(evas_object_evas_get(win));
859 snprintf(buf, sizeof(buf), "%s/images/%s",
860 elm_app_data_dir_get(), "twofish.jpg");
861 evas_object_image_file_set(im, buf, NULL);
862#endif
863 evas_object_move(im, 40, 40);
864 evas_object_resize(im, 400, 400);
865 evas_object_show(im);
866
867 evas_object_data_set(im, "im2", im2);
868
869
870 rc = evas_object_rectangle_add(evas_object_evas_get(win));
871 evas_object_color_set(rc, 0, 0, 0, 0);
872 evas_object_move(rc, 40, 340);
873 evas_object_resize(rc, 400, 100);
874 evas_object_show(rc);
875
876 evas_object_event_callback_add(rc, EVAS_CALLBACK_MOUSE_DOWN, im_down_cb, im);
877 evas_object_event_callback_add(rc, EVAS_CALLBACK_MOUSE_UP, im_up_cb, im);
878 evas_object_event_callback_add(rc, EVAS_CALLBACK_MOUSE_MOVE, im_move_cb, im);
879
880 rc = evas_object_rectangle_add(evas_object_evas_get(win));
881 evas_object_color_set(rc, 0, 0, 0, 0);
882 evas_object_move(rc, 40, 40);
883 evas_object_resize(rc, 400, 100);
884 evas_object_show(rc);
885
886 evas_object_event_callback_add(rc, EVAS_CALLBACK_MOUSE_DOWN, im_down_cb, im);
887 evas_object_event_callback_add(rc, EVAS_CALLBACK_MOUSE_UP, im_up_cb, im);
888 evas_object_event_callback_add(rc, EVAS_CALLBACK_MOUSE_MOVE, im_move_cb, im);
889
890 rc = evas_object_rectangle_add(evas_object_evas_get(win));
891 evas_object_color_set(rc, 0, 0, 0, 0);
892 evas_object_move(rc, 340, 40);
893 evas_object_resize(rc, 100, 400);
894 evas_object_show(rc);
895
896 evas_object_event_callback_add(rc, EVAS_CALLBACK_MOUSE_DOWN, im_down_cb, im);
897 evas_object_event_callback_add(rc, EVAS_CALLBACK_MOUSE_UP, im_up_cb, im);
898 evas_object_event_callback_add(rc, EVAS_CALLBACK_MOUSE_MOVE, im_move_cb, im);
899
900 rc = evas_object_rectangle_add(evas_object_evas_get(win));
901 evas_object_color_set(rc, 0, 0, 0, 0);
902 evas_object_move(rc, 40, 40);
903 evas_object_resize(rc, 100, 400);
904 evas_object_show(rc);
905
906 evas_object_event_callback_add(rc, EVAS_CALLBACK_MOUSE_DOWN, im_down_cb, im);
907 evas_object_event_callback_add(rc, EVAS_CALLBACK_MOUSE_UP, im_up_cb, im);
908 evas_object_event_callback_add(rc, EVAS_CALLBACK_MOUSE_MOVE, im_move_cb, im);
909
910 evas_object_resize(win, 480, 480);
911 evas_object_show(win);
912}
913#endif