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