summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-01-26 16:13:23 -0800
committerCedric BAIL <cedric@osg.samsung.com>2016-02-01 14:21:27 -0800
commit72eacc5086666d83f4f4701b73454d68f32d5385 (patch)
tree7caad20c624b69f7e234e886912a944e3a9dcff8
parentff1dd7be08fcbcf518018d8fab5ccff81e7801a0 (diff)
photocam: switch to use canvas animator.
-rw-r--r--src/lib/elm_photocam.c172
-rw-r--r--src/lib/elm_widget_photocam.h2
2 files changed, 83 insertions, 91 deletions
diff --git a/src/lib/elm_photocam.c b/src/lib/elm_photocam.c
index 991de5a32..6e63fc9b6 100644
--- a/src/lib/elm_photocam.c
+++ b/src/lib/elm_photocam.c
@@ -766,10 +766,12 @@ _zoom_do(Evas_Object *obj,
766} 766}
767 767
768static Eina_Bool 768static Eina_Bool
769_zoom_anim_cb(void *data) 769_zoom_anim_cb(void *data,
770 Eo *o EINA_UNUSED,
771 const Eo_Event_Description *desc EINA_UNUSED,
772 void *event_info EINA_UNUSED)
770{ 773{
771 double t; 774 double t;
772 Eina_Bool go;
773 Evas_Object *obj = data; 775 Evas_Object *obj = data;
774 776
775 ELM_PHOTOCAM_DATA_GET(obj, sd); 777 ELM_PHOTOCAM_DATA_GET(obj, sd);
@@ -783,16 +785,16 @@ _zoom_anim_cb(void *data)
783 t = 1.0; 785 t = 1.0;
784 t = 1.0 - t; 786 t = 1.0 - t;
785 t = 1.0 - (t * t); 787 t = 1.0 - (t * t);
786 go = _zoom_do(obj, t); 788 if (!_zoom_do(obj, t))
787 if (!go)
788 { 789 {
789 sd->no_smooth--; 790 sd->no_smooth--;
790 if (!sd->no_smooth) _smooth_update(data); 791 if (!sd->no_smooth) _smooth_update(data);
791 sd->zoom_animator = NULL; 792 eo_do(evas_object_evas_get(obj),
793 eo_event_callback_del(EVAS_CANVAS_EVENT_ANIMATOR_TICK, _zoom_anim_cb, obj));
792 eo_do(obj, eo_event_callback_call(EVAS_ZOOMABLE_INTERFACE_EVENT_ZOOM_STOP, NULL)); 794 eo_do(obj, eo_event_callback_call(EVAS_ZOOMABLE_INTERFACE_EVENT_ZOOM_STOP, NULL));
793 } 795 }
794 796
795 return go; 797 return EO_CALLBACK_CONTINUE;
796} 798}
797 799
798static Eina_Bool 800static Eina_Bool
@@ -1037,8 +1039,11 @@ _elm_photocam_elm_widget_event(Eo *obj, Elm_Photocam_Data *_pd EINA_UNUSED, Evas
1037 return EINA_TRUE; 1039 return EINA_TRUE;
1038} 1040}
1039 1041
1040Eina_Bool 1042static Eina_Bool
1041_bounce_eval(void *data) 1043_bounce_eval(void *data,
1044 Eo *o EINA_UNUSED,
1045 const Eo_Event_Description *desc EINA_UNUSED,
1046 void *event_info EINA_UNUSED)
1042{ 1047{
1043 Evas_Object *obj = data; 1048 Evas_Object *obj = data;
1044 ELM_PHOTOCAM_DATA_GET(obj, sd); 1049 ELM_PHOTOCAM_DATA_GET(obj, sd);
@@ -1046,16 +1051,7 @@ _bounce_eval(void *data)
1046 1051
1047 if ((sd->g_layer_zoom.imx == sd->g_layer_zoom.bounce.x_end) && 1052 if ((sd->g_layer_zoom.imx == sd->g_layer_zoom.bounce.x_end) &&
1048 (sd->g_layer_zoom.imy == sd->g_layer_zoom.bounce.y_end)) 1053 (sd->g_layer_zoom.imy == sd->g_layer_zoom.bounce.y_end))
1049 { 1054 goto on_end;
1050 sd->g_layer_zoom.imx = 0;
1051 sd->g_layer_zoom.imy = 0;
1052 sd->zoom_g_layer = EINA_FALSE;
1053 sd->g_layer_zoom.bounce.animator = NULL;
1054
1055 eo_do(obj, elm_interface_scrollable_freeze_set(EINA_FALSE));
1056
1057 return ECORE_CALLBACK_CANCEL;
1058 }
1059 1055
1060 t = ecore_loop_time_get(); 1056 t = ecore_loop_time_get();
1061 tt = (t - sd->g_layer_zoom.bounce.t_start) / 1057 tt = (t - sd->g_layer_zoom.bounce.t_start) /
@@ -1066,15 +1062,8 @@ _bounce_eval(void *data)
1066 1062
1067 if (t > sd->g_layer_zoom.bounce.t_end) 1063 if (t > sd->g_layer_zoom.bounce.t_end)
1068 { 1064 {
1069 sd->g_layer_zoom.imx = 0;
1070 sd->g_layer_zoom.imy = 0;
1071 sd->zoom_g_layer = EINA_FALSE;
1072
1073 eo_do(obj, elm_interface_scrollable_freeze_set(EINA_FALSE));
1074
1075 _zoom_do(obj, 1.0); 1065 _zoom_do(obj, 1.0);
1076 sd->g_layer_zoom.bounce.animator = NULL; 1066 goto on_end;
1077 return ECORE_CALLBACK_CANCEL;
1078 } 1067 }
1079 1068
1080 if (sd->g_layer_zoom.imx != sd->g_layer_zoom.bounce.x_end) 1069 if (sd->g_layer_zoom.imx != sd->g_layer_zoom.bounce.x_end)
@@ -1089,7 +1078,44 @@ _bounce_eval(void *data)
1089 1078
1090 _zoom_do(obj, 1.0 - (1.0 - tt)); 1079 _zoom_do(obj, 1.0 - (1.0 - tt));
1091 1080
1092 return ECORE_CALLBACK_RENEW; 1081 return EO_CALLBACK_CONTINUE;
1082
1083 on_end:
1084 sd->g_layer_zoom.imx = 0;
1085 sd->g_layer_zoom.imy = 0;
1086 sd->zoom_g_layer = EINA_FALSE;
1087
1088 eo_do(obj, elm_interface_scrollable_freeze_set(EINA_FALSE));
1089
1090 eo_do(evas_object_evas_get(obj),
1091 eo_event_callback_del(EVAS_CANVAS_EVENT_ANIMATOR_TICK, _bounce_eval, obj));
1092 return EO_CALLBACK_CONTINUE;
1093}
1094
1095static void
1096_elm_photocam_bounce_reset(Eo *obj, Elm_Photocam_Data *sd EINA_UNUSED)
1097{
1098 Eina_Bool r;
1099
1100 eo_do(evas_object_evas_get(obj),
1101 r = eo_event_callback_del(EVAS_CANVAS_EVENT_ANIMATOR_TICK, _bounce_eval, obj));
1102 if (r) _zoom_do(obj, 1.0);
1103}
1104
1105static void
1106_elm_photocam_zoom_reset(Eo *obj, Elm_Photocam_Data *sd)
1107{
1108 Eina_Bool r;
1109
1110 eo_do(evas_object_evas_get(obj),
1111 r = eo_event_callback_del(EVAS_CANVAS_EVENT_ANIMATOR_TICK, _zoom_anim_cb, obj));
1112 if (r)
1113 {
1114 sd->no_smooth--;
1115 if (!sd->no_smooth) _smooth_update(obj);
1116 _zoom_do(obj, 1.0);
1117 eo_do(obj, eo_event_callback_call(EVAS_ZOOMABLE_INTERFACE_EVENT_ZOOM_STOP, NULL));
1118 }
1093} 1119}
1094 1120
1095static void 1121static void
@@ -1165,7 +1191,7 @@ _g_layer_zoom_start_cb(void *data,
1165 Evas_Coord rw = 0, rh = 0; 1191 Evas_Coord rw = 0, rh = 0;
1166 int x, y, w, h; 1192 int x, y, w, h;
1167 1193
1168 ELM_SAFE_FREE(sd->g_layer_zoom.bounce.animator, ecore_animator_del); 1194 _elm_photocam_bounce_reset(obj, sd);
1169 sd->zoom_g_layer = EINA_TRUE; 1195 sd->zoom_g_layer = EINA_TRUE;
1170 1196
1171 eo_do(obj, elm_interface_scrollable_freeze_set(EINA_TRUE)); 1197 eo_do(obj, elm_interface_scrollable_freeze_set(EINA_TRUE));
@@ -1287,8 +1313,8 @@ _g_layer_zoom_end_cb(void *data,
1287 sd->g_layer_zoom.bounce.t_end = t + 1313 sd->g_layer_zoom.bounce.t_end = t +
1288 _elm_config->page_scroll_friction; 1314 _elm_config->page_scroll_friction;
1289 1315
1290 sd->g_layer_zoom.bounce.animator = 1316 eo_do(evas_object_evas_get(obj),
1291 ecore_animator_add(_bounce_eval, obj); 1317 eo_event_callback_add(EVAS_CANVAS_EVENT_ANIMATOR_TICK, _bounce_eval, obj));
1292 } 1318 }
1293 else 1319 else
1294 { 1320 {
@@ -1457,8 +1483,9 @@ _elm_photocam_evas_object_smart_del(Eo *obj, Elm_Photocam_Data *sd)
1457 ecore_job_del(sd->calc_job); 1483 ecore_job_del(sd->calc_job);
1458 ecore_timer_del(sd->scr_timer); 1484 ecore_timer_del(sd->scr_timer);
1459 ecore_timer_del(sd->long_timer); 1485 ecore_timer_del(sd->long_timer);
1460 ecore_animator_del(sd->zoom_animator); 1486 eo_do(evas_object_evas_get(obj),
1461 ecore_animator_del(sd->g_layer_zoom.bounce.animator); 1487 eo_event_callback_del(EVAS_CANVAS_EVENT_ANIMATOR_TICK, _zoom_anim_cb, obj),
1488 eo_event_callback_del(EVAS_CANVAS_EVENT_ANIMATOR_TICK, _bounce_eval, obj));
1462 1489
1463 eo_do_super(obj, MY_CLASS, evas_obj_smart_del()); 1490 eo_do_super(obj, MY_CLASS, evas_obj_smart_del());
1464} 1491}
@@ -1645,14 +1672,11 @@ _elm_photocam_file_set_internal(Eo *obj, Elm_Photocam_Data *sd, const char *file
1645 unsigned int i; 1672 unsigned int i;
1646 1673
1647 _grid_clear_all(obj); 1674 _grid_clear_all(obj);
1648 ELM_SAFE_FREE(sd->g_layer_zoom.bounce.animator, ecore_animator_del); 1675 _elm_photocam_zoom_reset(obj, sd);
1649 if (sd->zoom_animator) 1676 _elm_photocam_bounce_reset(obj, sd);
1650 { 1677 sd->no_smooth--;
1651 sd->no_smooth--; 1678 if (sd->no_smooth == 0) _smooth_update(obj);
1652 if (sd->no_smooth == 0) _smooth_update(obj); 1679
1653 ecore_animator_del(sd->zoom_animator);
1654 sd->zoom_animator = NULL;
1655 }
1656 ecore_job_del(sd->calc_job); 1680 ecore_job_del(sd->calc_job);
1657 evas_object_hide(sd->img); 1681 evas_object_hide(sd->img);
1658 if (sd->f) eina_file_close(sd->f); 1682 if (sd->f) eina_file_close(sd->f);
@@ -1747,10 +1771,10 @@ _elm_photocam_zoom_set(Eo *obj, Elm_Photocam_Data *sd, double zoom)
1747{ 1771{
1748 double z; 1772 double z;
1749 Eina_List *l; 1773 Eina_List *l;
1750 Ecore_Animator *an;
1751 Elm_Phocam_Grid *g, *g_zoom = NULL; 1774 Elm_Phocam_Grid *g, *g_zoom = NULL;
1752 Evas_Coord pw, ph, rx, ry, rw, rh; 1775 Evas_Coord pw, ph, rx, ry, rw, rh;
1753 int zoom_changed = 0, started = 0; 1776 int zoom_changed = 0, started = 0;
1777 Eina_Bool an = EINA_FALSE;
1754 1778
1755 if (zoom <= (1.0 / 256.0)) zoom = (1.0 / 256.0); 1779 if (zoom <= (1.0 / 256.0)) zoom = (1.0 / 256.0);
1756 if (zoom == sd->zoom) return; 1780 if (zoom == sd->zoom) return;
@@ -1932,22 +1956,24 @@ done:
1932 } 1956 }
1933 else 1957 else
1934 { 1958 {
1935 if (!sd->zoom_animator) 1959 eo_do(evas_object_evas_get(obj),
1960 an = eo_event_callback_del(EVAS_CANVAS_EVENT_ANIMATOR_TICK, _zoom_anim_cb, obj),
1961 eo_event_callback_add(EVAS_CANVAS_EVENT_ANIMATOR_TICK, _zoom_anim_cb, obj));
1962 if (!an)
1936 { 1963 {
1937 sd->zoom_animator = ecore_animator_add(_zoom_anim_cb, obj);
1938 sd->no_smooth++; 1964 sd->no_smooth++;
1939 if (sd->no_smooth == 1) _smooth_update(obj); 1965 if (sd->no_smooth == 1) _smooth_update(obj);
1940 started = 1; 1966 started = 1;
1941 } 1967 }
1942 } 1968 }
1943 1969
1944 an = sd->zoom_animator;
1945 if (an) 1970 if (an)
1946 { 1971 {
1947 if (!_zoom_anim_cb(obj)) 1972 // FIXME: If one day we do support partial animator in photocam, this would require change
1973 if (!_zoom_anim_cb(obj, evas_object_evas_get(obj), NULL, NULL))
1948 { 1974 {
1949 ecore_animator_del(an); 1975 _elm_photocam_bounce_reset(obj, sd);
1950 an = NULL; 1976 an = 0;
1951 } 1977 }
1952 } 1978 }
1953 1979
@@ -2060,20 +2086,10 @@ _elm_photocam_image_region_show(Eo *obj, Elm_Photocam_Data *sd, int x, int y, in
2060 if (rh < 1) rh = 1; 2086 if (rh < 1) rh = 1;
2061 if ((rx + rw) > sd->size.w) rx = sd->size.w - rw; 2087 if ((rx + rw) > sd->size.w) rx = sd->size.w - rw;
2062 if ((ry + rh) > sd->size.h) ry = sd->size.h - rh; 2088 if ((ry + rh) > sd->size.h) ry = sd->size.h - rh;
2063 if (sd->g_layer_zoom.bounce.animator) 2089
2064 { 2090 _elm_photocam_bounce_reset(obj, sd);
2065 ecore_animator_del(sd->g_layer_zoom.bounce.animator); 2091 _elm_photocam_zoom_reset(obj, sd);
2066 sd->g_layer_zoom.bounce.animator = NULL; 2092
2067 _zoom_do(obj, 1.0);
2068 }
2069 if (sd->zoom_animator)
2070 {
2071 sd->no_smooth--;
2072 ecore_animator_del(sd->zoom_animator);
2073 sd->zoom_animator = NULL;
2074 _zoom_do(obj, 1.0);
2075 eo_do(obj, eo_event_callback_call(EVAS_ZOOMABLE_INTERFACE_EVENT_ZOOM_STOP, NULL));
2076 }
2077 eo_do(obj, elm_interface_scrollable_content_region_show(rx, ry, rw, rh)); 2093 eo_do(obj, elm_interface_scrollable_content_region_show(rx, ry, rw, rh));
2078} 2094}
2079 2095
@@ -2102,21 +2118,10 @@ _elm_photocam_elm_interface_scrollable_region_bring_in(Eo *obj, Elm_Photocam_Dat
2102 if (rh < 1) rh = 1; 2118 if (rh < 1) rh = 1;
2103 if ((rx + rw) > sd->size.w) rx = sd->size.w - rw; 2119 if ((rx + rw) > sd->size.w) rx = sd->size.w - rw;
2104 if ((ry + rh) > sd->size.h) ry = sd->size.h - rh; 2120 if ((ry + rh) > sd->size.h) ry = sd->size.h - rh;
2105 if (sd->g_layer_zoom.bounce.animator) 2121
2106 { 2122 _elm_photocam_bounce_reset(obj, sd);
2107 ecore_animator_del(sd->g_layer_zoom.bounce.animator); 2123 _elm_photocam_zoom_reset(obj, sd);
2108 sd->g_layer_zoom.bounce.animator = NULL; 2124
2109 _zoom_do(obj, 1.0);
2110 }
2111 if (sd->zoom_animator)
2112 {
2113 sd->no_smooth--;
2114 if (!sd->no_smooth) _smooth_update(obj);
2115 ecore_animator_del(sd->zoom_animator);
2116 sd->zoom_animator = NULL;
2117 _zoom_do(obj, 1.0);
2118 eo_do(obj, eo_event_callback_call(EVAS_ZOOMABLE_INTERFACE_EVENT_ZOOM_STOP, NULL));
2119 }
2120 eo_do_super(obj, MY_CLASS, elm_interface_scrollable_region_bring_in(rx, ry, rw, rh)); 2125 eo_do_super(obj, MY_CLASS, elm_interface_scrollable_region_bring_in(rx, ry, rw, rh));
2121} 2126}
2122 2127
@@ -2129,19 +2134,8 @@ _elm_photocam_paused_set(Eo *obj, Elm_Photocam_Data *sd, Eina_Bool paused)
2129 sd->paused = paused; 2134 sd->paused = paused;
2130 if (!sd->paused) return; 2135 if (!sd->paused) return;
2131 2136
2132 if (sd->g_layer_zoom.bounce.animator) 2137 _elm_photocam_bounce_reset(obj, sd);
2133 { 2138 _elm_photocam_zoom_reset(obj, sd);
2134 ecore_animator_del(sd->g_layer_zoom.bounce.animator);
2135 sd->g_layer_zoom.bounce.animator = NULL;
2136 _zoom_do(obj, 1.0);
2137 }
2138 if (sd->zoom_animator)
2139 {
2140 ecore_animator_del(sd->zoom_animator);
2141 sd->zoom_animator = NULL;
2142 _zoom_do(obj, 1.0);
2143 eo_do(obj, eo_event_callback_call(EVAS_ZOOMABLE_INTERFACE_EVENT_ZOOM_STOP, NULL));
2144 }
2145} 2139}
2146 2140
2147EOLIAN static Eina_Bool 2141EOLIAN static Eina_Bool
diff --git a/src/lib/elm_widget_photocam.h b/src/lib/elm_widget_photocam.h
index b255ec146..8c03e59f5 100644
--- a/src/lib/elm_widget_photocam.h
+++ b/src/lib/elm_widget_photocam.h
@@ -81,7 +81,6 @@ struct _Elm_Photocam_Data
81 int x_end, y_end; 81 int x_end, y_end;
82 double t_start; 82 double t_start;
83 double t_end; 83 double t_end;
84 Ecore_Animator *animator;
85 } bounce; 84 } bounce;
86 } g_layer_zoom; 85 } g_layer_zoom;
87 86
@@ -94,7 +93,6 @@ struct _Elm_Photocam_Data
94 Ecore_Job *calc_job; 93 Ecore_Job *calc_job;
95 Ecore_Timer *scr_timer; 94 Ecore_Timer *scr_timer;
96 Ecore_Timer *long_timer; 95 Ecore_Timer *long_timer;
97 Ecore_Animator *zoom_animator;
98 double t_start, t_end; 96 double t_start, t_end;
99 97
100 struct 98 struct