diff options
-rw-r--r-- | src/lib/elementary/efl_ui_spotlight_manager_stack.c | 156 |
1 files changed, 40 insertions, 116 deletions
diff --git a/src/lib/elementary/efl_ui_spotlight_manager_stack.c b/src/lib/elementary/efl_ui_spotlight_manager_stack.c index 16e721560f..3696eb991e 100644 --- a/src/lib/elementary/efl_ui_spotlight_manager_stack.c +++ b/src/lib/elementary/efl_ui_spotlight_manager_stack.c | |||
@@ -9,9 +9,9 @@ | |||
9 | typedef struct { | 9 | typedef struct { |
10 | Efl_Ui_Spotlight_Container * container; | 10 | Efl_Ui_Spotlight_Container * container; |
11 | Efl_Gfx_Entity *group; | 11 | Efl_Gfx_Entity *group; |
12 | Efl_Canvas_Animation_Player *hide, *show; | 12 | Efl_Canvas_Animation_Player *alpha_anim; |
13 | int from, to; | 13 | Efl_Gfx_Entity *content[2]; |
14 | Efl_Gfx_Entity *content; | 14 | int ids[2]; //only used when in animation |
15 | Eina_Size2D page_size; | 15 | Eina_Size2D page_size; |
16 | Eina_Bool animation; | 16 | Eina_Bool animation; |
17 | } Efl_Ui_Spotlight_Manager_Stack_Data; | 17 | } Efl_Ui_Spotlight_Manager_Stack_Data; |
@@ -21,29 +21,16 @@ typedef struct { | |||
21 | static void | 21 | static void |
22 | _geom_sync(Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Manager_Stack_Data *pd) | 22 | _geom_sync(Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Manager_Stack_Data *pd) |
23 | { | 23 | { |
24 | Eina_Array *array = eina_array_new(2); | ||
25 | Eina_Rect group_pos = efl_gfx_entity_geometry_get(pd->group); | 24 | Eina_Rect group_pos = efl_gfx_entity_geometry_get(pd->group); |
26 | if (efl_player_playing_get(pd->hide)) | ||
27 | { | ||
28 | //we are currently in animation, sync the geometry of the targets | ||
29 | eina_array_push(array, efl_animation_player_target_get(pd->hide)); | ||
30 | eina_array_push(array, efl_animation_player_target_get(pd->show)); | ||
31 | } | ||
32 | else | ||
33 | { | ||
34 | //we only have our content right now, or nothing | ||
35 | eina_array_push(array, pd->content); | ||
36 | } | ||
37 | Eina_Rect goal = EINA_RECT_EMPTY(); | 25 | Eina_Rect goal = EINA_RECT_EMPTY(); |
38 | goal.size = pd->page_size; | 26 | goal.size = pd->page_size; |
39 | goal.y = (group_pos.y + group_pos.h/2)-pd->page_size.h/2; | 27 | goal.y = (group_pos.y + group_pos.h/2)-pd->page_size.h/2; |
40 | goal.x = (group_pos.x + group_pos.w/2)-pd->page_size.w/2; | 28 | goal.x = (group_pos.x + group_pos.w/2)-pd->page_size.w/2; |
41 | while (eina_array_count(array) > 0) | 29 | for (int i = 0; i < 2; ++i) |
42 | { | 30 | { |
43 | Efl_Gfx_Entity *subobj = eina_array_pop(array); | 31 | if (pd->content[i]) |
44 | efl_gfx_entity_geometry_set(subobj, goal); | 32 | efl_gfx_entity_geometry_set(pd->content[i], goal); |
45 | } | 33 | } |
46 | eina_array_free(array); | ||
47 | } | 34 | } |
48 | 35 | ||
49 | static void | 36 | static void |
@@ -66,85 +53,36 @@ _running_cb(void *data, const Efl_Event *ev EINA_UNUSED) | |||
66 | 53 | ||
67 | EINA_SAFETY_ON_NULL_RETURN(pd); | 54 | EINA_SAFETY_ON_NULL_RETURN(pd); |
68 | //calculate absolut position, multiply pos with 2.0 because duration is only 0.5) | 55 | //calculate absolut position, multiply pos with 2.0 because duration is only 0.5) |
69 | absolut_position = pd->from + (pd->to - pd->from)*(efl_player_playback_position_get(pd->show)*2.0); | 56 | absolut_position = pd->ids[0] + (pd->ids[1] - pd->ids[0])*(efl_canvas_object_animation_progress_get(ev->object)); |
70 | efl_event_callback_call(data, EFL_UI_SPOTLIGHT_MANAGER_EVENT_POS_UPDATE, &absolut_position); | 57 | efl_event_callback_call(data, EFL_UI_SPOTLIGHT_MANAGER_EVENT_POS_UPDATE, &absolut_position); |
71 | } | 58 | } |
72 | 59 | ||
73 | static void | 60 | static void |
74 | _anim_started_cb(void *data EINA_UNUSED, const Efl_Event *event) | 61 | _hide_object_cb(void *data, const Efl_Event *ev) |
75 | { | 62 | { |
76 | Efl_Canvas_Object *content; | 63 | if (!ev->info) |
77 | 64 | { | |
78 | content = efl_animation_player_target_get(event->object); | 65 | efl_gfx_entity_visible_set(ev->object, EINA_FALSE); |
79 | efl_gfx_entity_visible_set(content, EINA_TRUE); | 66 | efl_event_callback_del(ev->object, ev->desc, _hide_object_cb, data); |
80 | } | 67 | efl_event_callback_del(ev->object, EFL_CANVAS_OBJECT_ANIMATION_EVENT_ANIMATION_PROGRESS_UPDATED, _running_cb, data); |
81 | 68 | } | |
82 | static void | ||
83 | _hide_anim_ended_cb(void *data, const Efl_Event *event EINA_UNUSED) | ||
84 | { | ||
85 | Efl_Ui_Spotlight_Manager_Stack_Data *pd = efl_data_scope_safe_get(data, MY_CLASS); | ||
86 | Efl_Canvas_Object *content; | ||
87 | |||
88 | EINA_SAFETY_ON_NULL_RETURN(pd); | ||
89 | content = efl_animation_player_target_get(pd->hide); | ||
90 | efl_gfx_entity_visible_set(content, EINA_FALSE); | ||
91 | } | ||
92 | |||
93 | static void | ||
94 | _show_anim_ended_cb(void *data, const Efl_Event *event EINA_UNUSED) | ||
95 | { | ||
96 | Efl_Ui_Spotlight_Manager_Stack_Data *pd = efl_data_scope_safe_get(data, MY_CLASS); | ||
97 | Efl_Canvas_Object *content; | ||
98 | |||
99 | EINA_SAFETY_ON_NULL_RETURN(pd); | ||
100 | content = efl_animation_player_target_get(pd->show); | ||
101 | efl_gfx_entity_visible_set(content, EINA_TRUE); | ||
102 | pd->content = content; | ||
103 | } | 69 | } |
104 | 70 | ||
105 | EFL_CALLBACKS_ARRAY_DEFINE(_anim_show_event_cb, | ||
106 | {EFL_ANIMATION_PLAYER_EVENT_RUNNING, _running_cb}, | ||
107 | {EFL_ANIMATION_PLAYER_EVENT_STARTED, _anim_started_cb}, | ||
108 | {EFL_ANIMATION_PLAYER_EVENT_ENDED, _show_anim_ended_cb}, | ||
109 | ) | ||
110 | |||
111 | EFL_CALLBACKS_ARRAY_DEFINE(_anim_hide_event_cb, | ||
112 | {EFL_ANIMATION_PLAYER_EVENT_STARTED, _anim_started_cb}, | ||
113 | {EFL_ANIMATION_PLAYER_EVENT_ENDED, _hide_anim_ended_cb}, | ||
114 | ) | ||
115 | |||
116 | EOLIAN static void | 71 | EOLIAN static void |
117 | _efl_ui_spotlight_manager_stack_efl_ui_spotlight_manager_bind(Eo *obj, Efl_Ui_Spotlight_Manager_Stack_Data *pd, Efl_Ui_Spotlight_Container *spotlight, Efl_Canvas_Group *group) | 72 | _efl_ui_spotlight_manager_stack_efl_ui_spotlight_manager_bind(Eo *obj, Efl_Ui_Spotlight_Manager_Stack_Data *pd, Efl_Ui_Spotlight_Container *spotlight, Efl_Canvas_Group *group) |
118 | { | 73 | { |
119 | if (spotlight && group) | 74 | if (spotlight && group) |
120 | { | 75 | { |
121 | Efl_Canvas_Animation_Alpha *show_anim, *hide_anim; | ||
122 | pd->container = spotlight; | 76 | pd->container = spotlight; |
123 | pd->group = group; | 77 | pd->group = group; |
124 | 78 | ||
125 | efl_event_callback_add(pd->group, EFL_GFX_ENTITY_EVENT_SIZE_CHANGED, _resize_cb, obj); | 79 | efl_event_callback_add(pd->group, EFL_GFX_ENTITY_EVENT_SIZE_CHANGED, _resize_cb, obj); |
126 | efl_event_callback_add(pd->group, EFL_GFX_ENTITY_EVENT_POSITION_CHANGED, _move_cb, obj); | 80 | efl_event_callback_add(pd->group, EFL_GFX_ENTITY_EVENT_POSITION_CHANGED, _move_cb, obj); |
127 | 81 | ||
128 | show_anim = efl_add(EFL_CANVAS_ANIMATION_ALPHA_CLASS, obj); | 82 | pd->alpha_anim = efl_add(EFL_CANVAS_ANIMATION_ALPHA_CLASS, obj); |
129 | efl_animation_alpha_set(show_anim, 0.0, 1.0); | 83 | efl_animation_alpha_set(pd->alpha_anim, 0.0, 1.0); |
130 | efl_animation_duration_set(show_anim, 0.5); | 84 | efl_animation_duration_set(pd->alpha_anim, 0.5); |
131 | efl_animation_final_state_keep_set(show_anim, EINA_TRUE); | 85 | efl_animation_final_state_keep_set(pd->alpha_anim, EINA_TRUE); |
132 | |||
133 | pd->show = efl_add(EFL_CANVAS_ANIMATION_PLAYER_CLASS, obj); | ||
134 | efl_animation_player_animation_set(pd->show, show_anim); | ||
135 | efl_player_playing_set(pd->show, EINA_FALSE); | ||
136 | efl_event_callback_array_add(pd->show, _anim_show_event_cb(), obj); | ||
137 | |||
138 | //Default Hide Animation | ||
139 | hide_anim = efl_add(EFL_CANVAS_ANIMATION_ALPHA_CLASS, obj); | ||
140 | efl_animation_alpha_set(hide_anim, 1.0, 0.0); | ||
141 | efl_animation_duration_set(hide_anim, 0.5); | ||
142 | efl_animation_final_state_keep_set(hide_anim, EINA_TRUE); | ||
143 | |||
144 | pd->hide = efl_add(EFL_CANVAS_ANIMATION_PLAYER_CLASS, obj); | ||
145 | efl_animation_player_animation_set(pd->hide, hide_anim); | ||
146 | efl_player_playing_set(pd->hide, EINA_FALSE); | ||
147 | efl_event_callback_array_add(pd->hide, _anim_hide_event_cb(), obj); | ||
148 | 86 | ||
149 | for (int i = 0; i < efl_content_count(spotlight) ; ++i) { | 87 | for (int i = 0; i < efl_content_count(spotlight) ; ++i) { |
150 | Efl_Gfx_Entity *elem = efl_pack_content_get(spotlight, i); | 88 | Efl_Gfx_Entity *elem = efl_pack_content_get(spotlight, i); |
@@ -153,8 +91,8 @@ _efl_ui_spotlight_manager_stack_efl_ui_spotlight_manager_bind(Eo *obj, Efl_Ui_Sp | |||
153 | } | 91 | } |
154 | if (efl_ui_spotlight_active_element_get(spotlight)) | 92 | if (efl_ui_spotlight_active_element_get(spotlight)) |
155 | { | 93 | { |
156 | pd->content = efl_ui_spotlight_active_element_get(spotlight); | 94 | pd->content[0] = efl_ui_spotlight_active_element_get(spotlight); |
157 | efl_gfx_entity_visible_set(pd->content, EINA_TRUE); | 95 | efl_gfx_entity_visible_set(pd->content[0], EINA_TRUE); |
158 | _geom_sync(obj, pd); | 96 | _geom_sync(obj, pd); |
159 | } | 97 | } |
160 | } | 98 | } |
@@ -173,14 +111,6 @@ _efl_ui_spotlight_manager_stack_efl_ui_spotlight_manager_content_del(Eo *obj EIN | |||
173 | efl_canvas_group_member_remove(pd->container, subobj); | 111 | efl_canvas_group_member_remove(pd->container, subobj); |
174 | } | 112 | } |
175 | 113 | ||
176 | static void | ||
177 | _setup_anim(Efl_Animation_Player *player, Efl_Gfx_Entity *entity) | ||
178 | { | ||
179 | efl_player_playing_set(player, EINA_FALSE); | ||
180 | efl_animation_player_target_set(player, entity); | ||
181 | efl_player_playing_set(player, EINA_TRUE); | ||
182 | } | ||
183 | |||
184 | static Eina_Bool | 114 | static Eina_Bool |
185 | is_valid(Eo *obj, int index) | 115 | is_valid(Eo *obj, int index) |
186 | { | 116 | { |
@@ -193,33 +123,35 @@ is_valid(Eo *obj, int index) | |||
193 | EOLIAN static void | 123 | EOLIAN static void |
194 | _efl_ui_spotlight_manager_stack_efl_ui_spotlight_manager_switch_to(Eo *obj, Efl_Ui_Spotlight_Manager_Stack_Data *pd, int from, int to) | 124 | _efl_ui_spotlight_manager_stack_efl_ui_spotlight_manager_switch_to(Eo *obj, Efl_Ui_Spotlight_Manager_Stack_Data *pd, int from, int to) |
195 | { | 125 | { |
196 | if (efl_pack_content_get(pd->container, to) == pd->content) | 126 | if (efl_pack_content_get(pd->container, to) == pd->content[1]) |
197 | return; | 127 | return; |
198 | 128 | ||
199 | if (is_valid(pd->container, to) && is_valid(pd->container, from)) | 129 | if (is_valid(pd->container, to) && is_valid(pd->container, from)) |
200 | { | 130 | { |
201 | if (pd->animation) | 131 | int tmp[2] = {from, to}; |
132 | |||
133 | for (int i = 0; i < 2; ++i) | ||
202 | { | 134 | { |
203 | pd->from = from; | 135 | pd->ids[i] = tmp[i]; |
204 | pd->to = to; | 136 | pd->content[i] = efl_pack_content_get(pd->container, pd->ids[i]); |
205 | pd->content = NULL; | 137 | if (pd->animation) |
206 | _setup_anim(pd->hide, efl_pack_content_get(pd->container, from)); | 138 | efl_canvas_object_animation_start(pd->content[i], pd->alpha_anim, -1.0+2.0*i, 0.0); |
207 | _setup_anim(pd->show, efl_pack_content_get(pd->container, to)); | 139 | efl_gfx_entity_visible_set(pd->content[i], EINA_TRUE); |
208 | } | 140 | } |
209 | else | 141 | if (pd->animation) |
210 | { | 142 | { |
211 | efl_gfx_entity_visible_set(efl_pack_content_get(pd->container, from), EINA_FALSE); | 143 | efl_event_callback_add(pd->content[0], EFL_CANVAS_OBJECT_ANIMATION_EVENT_ANIMATION_CHANGED, _hide_object_cb, obj); |
212 | pd->content = efl_pack_content_get(pd->container, to); | 144 | efl_event_callback_add(pd->content[0], EFL_CANVAS_OBJECT_ANIMATION_EVENT_ANIMATION_PROGRESS_UPDATED, _running_cb, obj); |
213 | efl_gfx_entity_visible_set(pd->content, EINA_TRUE); | ||
214 | } | 145 | } |
215 | } | 146 | } |
216 | else | 147 | else |
217 | { | 148 | { |
218 | double pos = to; | 149 | double pos = to; |
219 | 150 | ||
220 | pd->content = efl_pack_content_get(pd->container, to); | 151 | pd->content[0] = efl_pack_content_get(pd->container, to); |
221 | efl_gfx_entity_visible_set(pd->content, EINA_TRUE); | 152 | efl_gfx_entity_visible_set(pd->content[0], EINA_TRUE); |
222 | efl_event_callback_call(obj, EFL_UI_SPOTLIGHT_MANAGER_EVENT_POS_UPDATE, &pos); | 153 | efl_event_callback_call(obj, EFL_UI_SPOTLIGHT_MANAGER_EVENT_POS_UPDATE, &pos); |
154 | pd->content[1] = NULL; | ||
223 | } | 155 | } |
224 | 156 | ||
225 | _geom_sync(obj, pd); | 157 | _geom_sync(obj, pd); |
@@ -250,22 +182,14 @@ _efl_ui_spotlight_manager_stack_efl_object_invalidate(Eo *obj, Efl_Ui_Spotlight_ | |||
250 | } | 182 | } |
251 | } | 183 | } |
252 | 184 | ||
253 | static void | ||
254 | _reset_player(Efl_Animation_Player *player, Eina_Bool vis) | ||
255 | { | ||
256 | Efl_Gfx_Entity *obj; | ||
257 | |||
258 | obj = efl_animation_player_target_get(player); | ||
259 | efl_player_playing_set(player, EINA_FALSE); | ||
260 | efl_animation_player_target_set(player, NULL); | ||
261 | efl_gfx_entity_visible_set(obj, vis); | ||
262 | } | ||
263 | |||
264 | EOLIAN static void | 185 | EOLIAN static void |
265 | _efl_ui_spotlight_manager_stack_efl_ui_spotlight_manager_animated_transition_set(Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Manager_Stack_Data *pd, Eina_Bool animation) | 186 | _efl_ui_spotlight_manager_stack_efl_ui_spotlight_manager_animated_transition_set(Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Manager_Stack_Data *pd, Eina_Bool animation) |
266 | { | 187 | { |
267 | _reset_player(pd->hide, EINA_FALSE); | 188 | for (int i = 0; i < 2; ++i) |
268 | _reset_player(pd->show, EINA_TRUE); | 189 | { |
190 | if (pd->content[i]) | ||
191 | efl_canvas_object_animation_stop(pd->content[i]); | ||
192 | } | ||
269 | pd->animation = animation; | 193 | pd->animation = animation; |
270 | } | 194 | } |
271 | 195 | ||