summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAharon Hillel <a.hillel@partner.samsung.com>2012-01-01 12:30:46 +0000
committerTom Hacohen <tom@stosb.com>2012-01-01 12:30:46 +0000
commit36070f43da2f2c969bc4c3c42168da883d214eb9 (patch)
treef3d5fb33b0167dc4aa69a3a93de8d01cbb094df5 /src
parent7057d1b1b047f1aeef2803f04df088758f6faf9a (diff)
Elm test glayer: Added momentum support on x,y axis
Signed-off-by: Aharon Hillel <a.hillel@partner.samsung.com> SVN revision: 66715
Diffstat (limited to 'src')
-rw-r--r--src/bin/test_gesture_layer3.c90
1 files changed, 52 insertions, 38 deletions
diff --git a/src/bin/test_gesture_layer3.c b/src/bin/test_gesture_layer3.c
index 1eb385db1..96a6997cb 100644
--- a/src/bin/test_gesture_layer3.c
+++ b/src/bin/test_gesture_layer3.c
@@ -15,7 +15,8 @@
15#define SHADOW_H 118 15#define SHADOW_H 118
16//#define RAD2DEG(x) ((x) * 57.295779513) 16//#define RAD2DEG(x) ((x) * 57.295779513)
17 17
18#define MOMENTUM_FRICTION 2000 18#define MOMENTUM_FACTOR 30
19#define MOMENTUM_FRICTION 1000
19#define ROTATE_MOMENTUM_FRICTION 30 20#define ROTATE_MOMENTUM_FRICTION 30
20#define ZOOM_MOMENTUM_FRICTION 8 21#define ZOOM_MOMENTUM_FRICTION 8
21#define TIMER_TICK 0.1 22#define TIMER_TICK 0.1
@@ -26,9 +27,9 @@ struct _Photo_Object {
26 Evas_Object *gl; 27 Evas_Object *gl;
27 28
28 /* 3 transit object to implement momentum animation */ 29 /* 3 transit object to implement momentum animation */
29 Elm_Transit *momentum;
30 Elm_Transit *zoom_momentum; 30 Elm_Transit *zoom_momentum;
31 Ecore_Timer *rot_timer; 31 Ecore_Timer *rot_timer;
32 Ecore_Timer *mom_timer;
32 double rot_tot_time; 33 double rot_tot_time;
33 double rot_progress; 34 double rot_progress;
34 /* bx, by - current wanted coordinates of the photo object. 35 /* bx, by - current wanted coordinates of the photo object.
@@ -43,7 +44,10 @@ struct _Photo_Object {
43 * per gesture, we have to keep the current rotate/zoom factor and the 44 * per gesture, we have to keep the current rotate/zoom factor and the
44 * one that was before we started the gesture. */ 45 * one that was before we started the gesture. */
45 int base_rotate, rotate; /* base - initial angle */ 46 int base_rotate, rotate; /* base - initial angle */
47 double mx, my; /* momentum on x, y */
48 double mom_x_acc, mom_y_acc;
46 double rot_momentum, zoom_mom; 49 double rot_momentum, zoom_mom;
50 double mom_tot_time;
47 double zoom_mom_time; 51 double zoom_mom_time;
48 double base_zoom, zoom; 52 double base_zoom, zoom;
49 double shadow_zoom; 53 double shadow_zoom;
@@ -200,17 +204,6 @@ rotate_momentum_animation_operation(void *_po)
200 return rc; 204 return rc;
201} 205}
202 206
203/* Momentum animation */
204static void
205momentum_animation_operation(void *_po, Elm_Transit *transit __UNUSED__,
206 double progress __UNUSED__)
207{
208 Photo_Object *po = (Photo_Object *) _po;
209 po->bx += po->m_dx;
210 po->by += po->m_dy;
211 apply_changes(po);
212}
213
214static void 207static void
215pic_obj_keep_inframe(void *_po) 208pic_obj_keep_inframe(void *_po)
216{ /* Make sure middle is in the screen, if not, fix it. */ 209{ /* Make sure middle is in the screen, if not, fix it. */
@@ -232,17 +225,6 @@ pic_obj_keep_inframe(void *_po)
232 po->by = 800 - (po->bh / 2); 225 po->by = 800 - (po->bh / 2);
233} 226}
234 227
235static void
236momentum_animation_end(void *_po, Elm_Transit *transit __UNUSED__)
237{
238 Photo_Object *po = (Photo_Object *) _po;
239
240 pic_obj_keep_inframe(po);
241 apply_changes(po);
242
243 po->momentum = NULL;
244}
245
246static Evas_Event_Flags 228static Evas_Event_Flags
247rotate_start(void *_po, void *event_info) 229rotate_start(void *_po, void *event_info)
248{ 230{
@@ -377,10 +359,10 @@ momentum_start(void *_po, void *event_info)
377 printf("momentum_start po->rotate=<%d> <%d,%d>\n", po->rotate, p->x2, p->y2); 359 printf("momentum_start po->rotate=<%d> <%d,%d>\n", po->rotate, p->x2, p->y2);
378 360
379 /* If there's an active animator, stop it */ 361 /* If there's an active animator, stop it */
380 if (po->momentum) 362 if (po->mom_timer)
381 { 363 {
382 elm_transit_del(po->momentum); 364 ecore_timer_del(po->mom_timer);
383 po->momentum = NULL; 365 po->mom_timer = NULL;
384 } 366 }
385 367
386 po->dx = p->x2 - po->bx; 368 po->dx = p->x2 - po->bx;
@@ -404,25 +386,57 @@ momentum_move(void *_po, void *event_info)
404 return EVAS_EVENT_FLAG_NONE; 386 return EVAS_EVENT_FLAG_NONE;
405} 387}
406 388
389/* Momentum animation */
390static Eina_Bool
391momentum_animation_operation(void *_po)
392{
393 Photo_Object *po = (Photo_Object *) _po;
394 Eina_Bool rc = ECORE_CALLBACK_RENEW;
395 Evas_Coord x = po->bx;
396 Evas_Coord y = po->by;
397 po->mom_tot_time -= TIMER_TICK;
398 if (po->mom_tot_time <= 0)
399 {
400 po->mom_timer = NULL;
401 rc = ECORE_CALLBACK_CANCEL;
402 }
403
404 /* x = v0t + 0.5at^2 */
405 po->bx += ((po->mx * po->mom_tot_time) +
406 (0.5 * po->mom_x_acc * (po->mom_tot_time * po->mom_tot_time)));
407
408 po->by += ((po->my * po->mom_tot_time) +
409 (0.5 * po->mom_y_acc * (po->mom_tot_time * po->mom_tot_time)));
410
411 printf("%s prev_bx-new_bx,y=(%d,%d)\n", __func__, x-po->bx, y-po->by);
412 if (rc == ECORE_CALLBACK_CANCEL)
413 pic_obj_keep_inframe(po);
414
415 apply_changes(po);
416 return rc;
417}
418
407static Evas_Event_Flags 419static Evas_Event_Flags
408momentum_end(void *_po, void *event_info) 420momentum_end(void *_po, void *event_info)
409{ 421{
410 Photo_Object *po = (Photo_Object *) _po; 422 Photo_Object *po = (Photo_Object *) _po;
411 Elm_Gesture_Momentum_Info *p = (Elm_Gesture_Momentum_Info *) event_info; 423 Elm_Gesture_Momentum_Info *p = (Elm_Gesture_Momentum_Info *) event_info;
412 printf("momentum end po->rotate=<%d> <%d,%d> <%d,%d>\n", po->rotate, p->x2, p->y2, p->mx, p->my); 424 printf("momentum end x2,y2=<%d,%d> mx,my=<%d,%d>\n", p->x2, p->y2, p->mx, p->my);
413 pic_obj_keep_inframe(po); 425 pic_obj_keep_inframe(po);
414 apply_changes(po); 426 apply_changes(po);
415 po->m_dx = p->mx / 200; 427 /* Make up some total-time for the movement */
416 po->m_dy = p->my / 200; 428 po->mom_tot_time = sqrt((p->mx * p->mx) + (p->my * p->my))
417
418 po->momentum = elm_transit_add();
419 double tot_time = sqrt((p->mx * p->mx) + (p->my * p->my))
420 / MOMENTUM_FRICTION; 429 / MOMENTUM_FRICTION;
421 printf("%s tot_time=<%f>\n", __func__, tot_time); 430
422 elm_transit_duration_set(po->momentum, tot_time); 431 if (po->mom_tot_time)
423 elm_transit_effect_add(po->momentum, momentum_animation_operation, po, 432 { /* Compute acceleration for both compenents, and launch timer */
424 momentum_animation_end); 433 po->mom_x_acc = (p->mx) / po->mom_tot_time; /* a = (v-v0) / t */
425 elm_transit_go(po->momentum); 434 po->mom_y_acc = (p->my) / po->mom_tot_time; /* a = (v-v0) / t */
435 po->mom_x_acc /= MOMENTUM_FACTOR;
436 po->mom_y_acc /= MOMENTUM_FACTOR;
437 po->mom_timer = ecore_timer_add(TIMER_TICK, momentum_animation_operation, po);
438 }
439
426 return EVAS_EVENT_FLAG_NONE; 440 return EVAS_EVENT_FLAG_NONE;
427} 441}
428 442