2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "dynamic_index.h"
20 #include <Elementary.h>
22 #include "homescreen-efl.h"
24 #include "livebox/livebox_panel.h"
27 static Evas_Object *__dynamic_index_create_indice(Evas_Object *box);
28 static Eina_Bool __dynamic_index_fill_box(dynamic_index_t *dynamic_index);
30 static void __dynamic_index_page_count_changed_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
31 static void __dynamic_index_page_area_changed_cb(void *data, Evas_Object *obj, void *event_info);
33 static void __dynamic_index_current_page_changed_start_cb(void *data, Evas_Object *obj, void *event_info);
34 static void __dynamic_index_current_page_changed_stop_cb(void *data, Evas_Object *obj, void *event_info);
35 static void __dynamic_index_set_properties(Evas_Object *index, double percent);
36 static Evas_Object *__dynamic_index_box_create(void);
37 static void __dynamic_index_rotate(Evas_Object *element, double angle, double alpha);
39 HAPI dynamic_index_t *dynamic_index_new(Evas_Object *page_scroller)
41 dynamic_index_t *dynamic_index = NULL;
42 Evas_Object *box = NULL;
45 LOGD("Invalid parameter : page_scroller is NULL");
49 dynamic_index = (dynamic_index_t *) malloc (sizeof(dynamic_index_t));
53 box = __dynamic_index_box_create();
55 dynamic_index->scroller = page_scroller;
56 dynamic_index->box = box;
57 dynamic_index->page_count = page_scroller_get_page_count(page_scroller);
58 dynamic_index->page_current = page_scroller_get_current_page(page_scroller);
60 elm_scroller_page_size_get(page_scroller, &dynamic_index->page_width, NULL);
61 elm_scroller_region_get(page_scroller, &dynamic_index->x_current, NULL, NULL, NULL);
63 if (!__dynamic_index_fill_box(dynamic_index)) {
64 LOGD("Box fill failed");
70 elm_object_signal_callback_add(page_scroller, "scroller,count,changed", "*", __dynamic_index_page_count_changed_cb, dynamic_index);
71 evas_object_smart_callback_add(page_scroller, "scroll", __dynamic_index_page_area_changed_cb, dynamic_index);
73 evas_object_smart_callback_add(page_scroller, "scroll,drag,start", __dynamic_index_current_page_changed_start_cb, dynamic_index);
74 evas_object_smart_callback_add(page_scroller, "scroll,anim,stop", __dynamic_index_current_page_changed_stop_cb, dynamic_index);
76 evas_object_data_set(page_scroller, KEY_INDEX, dynamic_index);
81 HAPI void dynamic_index_clear(dynamic_index_t *dynamic_index)
86 LOGE("Invalid parameter");
90 for (i = 0; i < dynamic_index->page_count; i++) {
91 if (dynamic_index->indices[i]) {
92 evas_object_del(dynamic_index->indices[i]);
93 dynamic_index->indices[i] = NULL;
97 elm_box_clear(dynamic_index->box);
100 HAPI void dynamic_index_del(dynamic_index_t *dynamic_index)
102 if (!dynamic_index) {
103 LOGE("[INVALID_PARAM][dynamic_index='%p']", dynamic_index);
107 elm_object_signal_callback_del(dynamic_index->scroller, "scroller,count,changed", "*", __dynamic_index_page_count_changed_cb);
109 evas_object_smart_callback_del(dynamic_index->scroller, "scroll", __dynamic_index_page_area_changed_cb);
110 evas_object_smart_callback_del(dynamic_index->scroller, "scroll,drag,start", __dynamic_index_current_page_changed_start_cb);
111 evas_object_smart_callback_del(dynamic_index->scroller, "scroll,anim,stop", __dynamic_index_current_page_changed_stop_cb);
113 dynamic_index_clear(dynamic_index);
117 HAPI void dynamic_index_reload(dynamic_index_t *dynamic_index, int idx, int page_count)
119 if (!dynamic_index) {
120 LOGE("[INVALID_PARAMS]");
124 dynamic_index_clear(dynamic_index);
125 dynamic_index->page_current = idx;
126 dynamic_index->page_count = page_count;
128 __dynamic_index_fill_box(dynamic_index);
131 static Evas_Object *__dynamic_index_create_indice(Evas_Object *box)
133 Evas_Object *layout = NULL;
134 Evas_Object *size_setter_rect = NULL;
136 int idx_width = (INDEX_ELEMENT_CONTAINER_WIDTH / ROOT_WIN_W) * home_screen_get_root_width();
137 int idx_height = (INDEX_ELEMENT_CONTAINER_HEIGHT / ROOT_WIN_H) * home_screen_get_root_height();
141 LOGD("Invalid argument : box is NULL");
145 layout = elm_layout_add(box);
147 LOGD("Layout creation failed");
151 if (!elm_layout_file_set(layout, INDEX_EDJE, GROUP_INDEX_ELEMENT)) {
152 evas_object_del(layout);
156 size_setter_rect = evas_object_rectangle_add(evas_object_evas_get(home_screen_get_win()));
157 if (!size_setter_rect) {
158 LOGE("Failed to create size setter rectangle");
162 elm_object_part_content_set(layout, INDICE_SIZE_SETTER, size_setter_rect);
164 evas_object_color_set(size_setter_rect, 0, 0, 0, 0);
165 evas_object_size_hint_min_set(size_setter_rect, idx_width, idx_height);
166 evas_object_size_hint_max_set(size_setter_rect, idx_width, idx_height);
167 evas_object_resize(size_setter_rect, idx_width, idx_height);
169 evas_object_show(layout);
170 elm_box_pack_end(box, layout);
175 static void __dynamic_index_set_properties(Evas_Object *index, double percent)
177 double size = (percent*INDEX_CURRENT_SIZE+(1.0-percent)*INDEX_NORMAL_SIZE)*home_screen_get_root_width();
178 evas_object_size_hint_min_set(index, size, size);
179 evas_object_size_hint_max_set(index, size, size);
180 evas_object_color_set(index, 255, 255, 255, percent*INDEX_CURRENT_ALPHA+(1.0-percent)*INDEX_NORMAL_ALPHA);
183 static Eina_Bool __dynamic_index_fill_box(dynamic_index_t *dynamic_index)
185 int i = 0, c_page = -1;
187 Evas_Object *layout = NULL;
192 if (!dynamic_index->box || dynamic_index->page_count < 1) {
193 LOGD("Invalid parameters : box is NULL or elements_count is < 1");
197 c_page = dynamic_index->page_current;
198 if(c_page < 0 || c_page > dynamic_index->page_count)
200 LOGE("Failed to get current_page ");
204 for (i = 0 ; i < dynamic_index->page_count; i++) {
205 layout = __dynamic_index_create_indice(dynamic_index->box);
207 LOGE("Failed to append index element into the box");
208 dynamic_index_clear(dynamic_index);
212 dynamic_index->indices[i] = layout;
215 elm_layout_signal_emit(dynamic_index->indices[c_page], SIGNAL_SET_CURRENT, SIGNAL_SOURCE);
216 __dynamic_index_set_properties(dynamic_index->indices[dynamic_index->page_current], 1.0);
221 static void __dynamic_index_page_count_changed_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
223 LOGD("The page count has changed");
224 dynamic_index_t *dynamic_index = (dynamic_index_t *)data;
225 dynamic_index_clear(dynamic_index);
226 dynamic_index->page_count = page_scroller_get_page_count(dynamic_index->scroller);
228 LOGD("page count : %d ", dynamic_index->page_count);
230 if (!dynamic_index->page_count)
233 dynamic_index->page_current = page_scroller_get_current_page(dynamic_index->scroller);
235 if (!__dynamic_index_fill_box(dynamic_index)) {
236 elm_object_signal_callback_del(dynamic_index->scroller, "scroller,count,changed", "*", __dynamic_index_page_count_changed_cb);
237 evas_object_smart_callback_del(dynamic_index->scroller, "scroll", __dynamic_index_page_area_changed_cb);
238 evas_object_smart_callback_del(dynamic_index->scroller, "scroll,drag,start", __dynamic_index_current_page_changed_start_cb);
239 evas_object_smart_callback_del(dynamic_index->scroller, "scroll,anim,stop", __dynamic_index_current_page_changed_stop_cb);
243 HAPI double _dist(int current, int page_x, int page_width)
245 return 1.0-((double)fabs(page_x-current))/page_width;
248 static void __dynamic_index_page_area_changed_cb(void *data, Evas_Object *obj, void *event_info)
255 dynamic_index_t *dynamic_index = (dynamic_index_t*) data;
258 LOGE("Invalid dynamic_index");
261 elm_scroller_region_get(obj, &x, NULL, NULL, NULL);
263 angle = (double)(x - dynamic_index->x_current)/dynamic_index->page_width * 90.0;
265 if(fabs(x - dynamic_index->x_current) <= dynamic_index->page_width)
267 next_page = x > dynamic_index->x_current ? (dynamic_index->page_current+1) % dynamic_index->page_count : dynamic_index->page_current-1;
268 color = fabs(angle) * 2;
272 if(x > dynamic_index->x_current)
274 next_page = dynamic_index->page_count-1;
275 color = (double)(dynamic_index->page_width*dynamic_index->page_count - x)/dynamic_index->page_width * 180.0;
284 if (next_page == dynamic_index->page_count - 1 && dynamic_index->page_current == 0 && dynamic_index->page_count % 2 == 1)
285 angle = angle - 270.0;
287 __dynamic_index_rotate(dynamic_index->indices[dynamic_index->page_current], 90.0 + angle, 255.0 - color);
288 __dynamic_index_rotate(dynamic_index->indices[next_page], angle, 75.0 + color);
291 static Evas_Object *__dynamic_index_box_create(void)
293 Evas_Object *box = NULL;
295 box = elm_box_add(home_screen_get_win());
297 LOGD("Box creation failed");
301 elm_box_homogeneous_set(box, EINA_TRUE);
302 elm_box_horizontal_set(box, EINA_TRUE);
304 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
306 elm_box_align_set(box, 0.5, 0.5);
307 evas_object_show(box);
312 static void __dynamic_index_current_page_changed_start_cb(void *data, Evas_Object *obj, void *event_info)
314 dynamic_index_t *dynamic_index = (dynamic_index_t*) data;
317 LOGE("Invalid data");
321 elm_scroller_current_page_get(obj, &dynamic_index->page_current, NULL);
322 elm_scroller_region_get(obj, &dynamic_index->x_current, NULL, NULL, NULL);
325 static void __dynamic_index_current_page_changed_stop_cb(void *data, Evas_Object *obj, void *event_info)
327 dynamic_index_t *dynamic_index = (dynamic_index_t*)data;
332 LOGE("Invalid data");
336 elm_scroller_current_page_get(obj, &dynamic_index->page_current, NULL);
337 for(i = 0; i<dynamic_index->page_current; i++)
339 elm_object_signal_emit(dynamic_index->indices[i], SIGNAL_SET_DEFAULT, SIGNAL_SOURCE);
341 elm_object_signal_emit(dynamic_index->indices[dynamic_index->page_current], SIGNAL_SET_CURRENT, SIGNAL_SOURCE);
342 for(i = dynamic_index->page_current+1; i<dynamic_index->page_count; i++)
344 elm_object_signal_emit(dynamic_index->indices[i], SIGNAL_SET_DEFAULT, SIGNAL_SOURCE);
348 static void __dynamic_index_rotate(Evas_Object *element, double angle, double alpha)
350 Evas_Object *edje = NULL;
354 LOGE("Invalid argument : element is NULL");
358 edje = elm_layout_edje_get(element);
361 LOGE("Failed to get edje from layout");
365 Edje_Message_Float_Set *msg = malloc(sizeof(*msg) + sizeof(double));
370 edje_object_message_send(edje, EDJE_MESSAGE_FLOAT_SET, 1, msg);
371 edje_object_signal_emit(edje, "rot_changed", "ly");