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.
19 #include "livebox/livebox_utils.h"
20 #include "homescreen-efl.h"
24 Evas_Object *selected_livebox;
25 Evas_Object *selected_livebox_layout;
26 Evas_Object *prev_livebox_layout;
30 .selected_livebox = NULL,
31 .selected_livebox_layout = NULL,
32 .prev_livebox_layout = NULL,
36 static Evas_Object *__livebox_utils_create_grid_bg(Evas_Object *parent);
37 static Eina_Rectangle *__livebox_utils_get_grid_rectangle(Evas_Object *obj);
38 static bool __livebox_utils_check_intersection(Evas_Object *obj_a,
39 Eina_Rectangle *rect);
41 Eina_Rectangle *livebox_utils_get_widget_rectangle(Evas_Object *obj)
47 Eina_Rectangle *rect = NULL;
53 evas_object_geometry_get(obj, &x, &y, &w, &h);
55 rect = eina_rectangle_new(x, y, w, h);
64 Eina_Rectangle *livebox_utils_get_grid_widget_rectangle(Evas_Object *obj)
70 Eina_Rectangle *rect = NULL;
76 elm_grid_pack_get(obj, &x, &y, &w, &h);
78 rect = eina_rectangle_new(x, y, w, h);
87 Eina_Rectangle *livebox_utils_convert_virtual_grid_geo_to_screen(Evas_Object *grid,
88 int x, int y, int w, int h)
98 Eina_Rectangle *rec = NULL;
101 LOGE("grid == NULL");
105 evas_object_geometry_get(grid, &gx, &gy, &gw, &gh);
106 elm_grid_size_get(grid, &vw, &vh);
108 rec = eina_rectangle_new(
109 gx + (int)((float)x/vw * gw),
110 gy + (int)((float)y/vh * gh),
111 (int)((float)w/vw*gw),
112 (int)((float)h/vh*gh)
123 bool livebox_utils_check_rect_list_grid_interesction(Eina_Rectangle *rect,
124 Evas_Object *obj, Eina_List *list)
127 Evas_Object *list_obj = NULL;
130 LOGE("list == NULL");
134 EINA_LIST_FOREACH(list, l, list_obj) {
136 LOGE("list_obj == NULL");
140 if (list_obj != obj && __livebox_utils_check_intersection(
142 LOGD("Intersection found");
150 Eina_List *livebox_utils_get_liveboxes_on_gird(Evas_Object *grid)
152 Eina_List *livebox_list = NULL;
155 LOGE("grid == NULL");
159 livebox_list = elm_grid_children_get(grid);
161 LOGE("livebox_list == NULL");
164 livebox_list = eina_list_remove(livebox_list, s_info.shadow);
170 Eina_List *livebox_utils_get_liveboxes_on_page_list(Evas_Object *obj)
172 Evas_Object *grid = NULL;
179 grid = elm_layout_content_get(obj, SIGNAL_CONTENT_SOURCE);
181 LOGE("grid == NULL");
185 return livebox_utils_get_liveboxes_on_gird(grid);
187 /* ---------------------------------------------------------------------------*/
189 Evas_Object *livebox_utils_get_selected_livebox_layout(void)
191 return s_info.selected_livebox_layout;
194 Evas_Object *livebox_utils_get_prev_livebox_layout(void)
196 return s_info.prev_livebox_layout;
199 Evas_Object *livebox_utils_selected_livebox_get(void)
201 return s_info.selected_livebox;
204 void livebox_utils_set_selected_livebox(Evas_Object *livebox,
207 LOGD("Selected_livebox_layout = %p; prev = %p",
208 s_info.selected_livebox_layout, s_info.prev_livebox_layout);
210 s_info.prev_livebox_layout = s_info.selected_livebox_layout;
211 s_info.selected_livebox = livebox;
212 s_info.selected_livebox_layout = layout;
215 Evas_Object *livebox_utils_get_livebox_container_grid(Evas_Object *container)
217 Evas_Object *grid = elm_layout_content_get(container, "content");
219 LOGE("grid == NULL");
227 void livebox_utils_set_grid_object_pack(Evas_Object *livebox,
228 Evas_Object *item_to_pack, Evas_Object *grid)
230 int x = -1, y = -1, w = -1, h = -1;
234 LOGE("grid == NULL");
239 LOGE("livebox == NULL");
244 LOGE("item_to_pack == NULL");
248 livebox_utils_convert_size_to_grid_coord(livebox, grid, &x, &y, &w, &h);
249 livebox_utils_normalize_grid_pos(x, y, w, h, &out_x, &out_y);
250 elm_grid_pack_set(item_to_pack, out_x, out_y, w, h);
253 void livebox_utils_repack_grid_object(Evas_Object *livebox,
254 Evas_Object *item_to_pack, Evas_Object *grid_from, Evas_Object *grid_to)
256 int x = -1, y = -1, w = -1, h = -1;
260 LOGE("item_to_pack == NULL");
265 elm_grid_pack_get(item_to_pack, &x, &y, &w, &h);
266 LOGD("Unpacking from: %p -> %d %d %d %d",
267 grid_from, x, y, w, h);
269 elm_grid_unpack(grid_from, item_to_pack);
272 if (livebox && grid_to) {
273 livebox_utils_convert_size_to_grid_coord(livebox,
274 grid_to, &x, &y, &w, &h);
275 livebox_utils_normalize_grid_pos(x, y, w, h, &out_x, &out_y);
276 elm_grid_pack(grid_to, item_to_pack, out_x, out_y, w, h);
281 void livebox_utils_convert_size_to_grid_coord(Evas_Object *livebox, Evas_Object *grid,
282 int *out_x, int *out_y, int *out_w, int *out_h)
284 int lx = 0, ly, lw = 0, lh = 0;
285 int gx = 0, gy, gw = 0, gh = 0;
286 float ratio_x = 0, ratio_y = 0;
289 LOGE("livebox == NULL");
294 LOGE("grid == NULL");
298 if (!out_w || !out_h) {
299 LOGE("output: out_w == %p; out_h == %p", out_w, out_h);
303 evas_object_geometry_get(livebox, &lx, &ly, &lw, &lh);
304 evas_object_geometry_get(grid, &gx, &gy, &gw, &gh);
306 if (gw == 0 || gh == 0) {
307 LOGE("Grid wrong size gw == %d; gh == %d", gw, gh);
314 ratio_x = (float)lx / gw;
315 ratio_y = (float)ly / gh;
317 *out_x = round(ratio_x * LIVEBOX_TOTAL_COLUMNS);
318 *out_y = round(ratio_y * LIVEBOX_TOTAL_ROWS);
320 ratio_x = (float)lw / gw;
321 ratio_y = (float)lh / gh;
323 *out_w = round(ratio_x * LIVEBOX_TOTAL_COLUMNS);
324 *out_h = round(ratio_y * LIVEBOX_TOTAL_ROWS);
326 *out_x /= LIVEBOX_GRID_ROWS_CELLS_MULTI;
327 *out_x *= LIVEBOX_GRID_ROWS_CELLS_MULTI;
329 *out_y /= LIVEBOX_GRID_ROWS_CELLS_MULTI;
330 *out_y *= LIVEBOX_GRID_ROWS_CELLS_MULTI;
333 void livebox_utils_normalize_grid_pos(int obj_x, int obj_y, int obj_w,
334 int obj_h, int *out_x, int *out_y)
336 int dx = obj_x + obj_w;
337 int dy = obj_y + obj_h;
339 if (dx > LIVEBOX_TOTAL_COLUMNS)
340 obj_x = (LIVEBOX_TOTAL_COLUMNS - obj_w);
342 if (dy > LIVEBOX_TOTAL_ROWS)
343 obj_y = (LIVEBOX_TOTAL_ROWS - obj_h);
355 /* -------------------------------------- SHADOW -----------------------------*/
357 Evas_Object *livebox_utils_get_shadow()
359 if (!s_info.shadow) {
360 LOGE("s_info.shadow == NULL");
364 return s_info.shadow;
367 void livebox_utils_shadow_unpack(void)
369 Evas_Object *page = NULL;
370 Evas_Object *grid = NULL;
372 page = livebox_utils_selected_livebox_get();
374 LOGE("page == NULL");
378 grid = livebox_utils_get_livebox_container_grid(page);
380 LOGE("grid == NULL");
384 livebox_utils_repack_grid_object(NULL, livebox_utils_get_shadow(),
388 void livebox_utils_create_shadow(Evas_Object *parent)
391 Evas_Object *shadow = NULL;
394 LOGE("parent == NULL");
398 e = evas_object_evas_get(parent);
400 LOGE("parent == NULL");
405 shadow = evas_object_rectangle_add(e);
407 LOGE("shadow == NULL");
411 s_info.shadow = shadow;
412 evas_object_color_set(shadow, LIVEBOX_GRID_BG_ALPHA,
413 LIVEBOX_GRID_BG_ALPHA, LIVEBOX_GRID_BG_ALPHA,
414 LIVEBOX_GRID_BG_ALPHA);
415 evas_object_pass_events_set(shadow, true);
418 void livebox_utils_set_shadow_visibility(bool visible)
420 if (!s_info.shadow) {
421 LOGE("s_info.shadow == NULL");
426 evas_object_color_set(s_info.shadow, LIVEBOX_GRID_BG_ALPHA,
427 LIVEBOX_GRID_BG_ALPHA, LIVEBOX_GRID_BG_ALPHA,
428 LIVEBOX_GRID_BG_ALPHA);
429 evas_object_show(s_info.shadow);
431 evas_object_color_set(s_info.shadow, 0, 0, 0, 0);
432 evas_object_hide(s_info.shadow);
436 void livebox_utils_create_grid_shadow_clipper(Evas_Object *livebox_container)
438 Evas_Object *grid_bg = NULL;
440 if (!livebox_container) {
441 LOGD("livebox_container == NULL");
445 grid_bg = __livebox_utils_create_grid_bg(livebox_container);
447 LOGD("grid_bg == NULL");
451 elm_object_part_content_set(livebox_container, PART_GRID_BG, grid_bg);
452 evas_object_clip_set(grid_bg, s_info.shadow);
454 elm_layout_signal_emit(livebox_container,
455 SIGNAL_GRID_SHADOW_HIDE, PART_GRID_BG);
458 static Evas_Object *__livebox_utils_create_grid_bg(Evas_Object *parent)
461 Evas_Object *table = NULL;
467 LOGE("parent == NULL");
471 e = evas_object_evas_get(parent);
473 LOGE("parent == NULL");
477 table = elm_table_add(parent);
479 LOGE("table == NULL");
483 w = (LIVEBOX_GRID_BG_PADDING /
484 (float)ROOT_WIN_W) * home_screen_get_root_width();
485 h = (LIVEBOX_GRID_BG_PADDING /
486 (float)ROOT_WIN_H) * home_screen_get_root_height();
488 elm_table_padding_set(table, w, h);
489 elm_table_homogeneous_set(table, EINA_TRUE);
491 for (i = 0; i < LIVEBOX_GRID_COLUMNS; ++i) {
492 for (j = 0; j < LIVEBOX_GRID_ROWS; ++j) {
493 item = evas_object_rectangle_add(e);
495 LOGE("item == NULL");
496 evas_object_del(table);
500 evas_object_color_set(item, 255, 255, 255, 255);
501 evas_object_pass_events_set(item, true);
502 evas_object_show(item);
503 evas_object_size_hint_weight_set(item,
504 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
505 evas_object_size_hint_fill_set(item,
506 EVAS_HINT_FILL, EVAS_HINT_FILL);
507 elm_table_pack(table, item, i, j, 1, 1);
514 void livebox_utils_get_cursor_pos(int *mx, int *my)
516 Evas *e = evas_object_evas_get(home_screen_get_win());
521 evas_pointer_canvas_xy_get(e, mx, my);
524 static Eina_Rectangle *__livebox_utils_get_grid_rectangle(Evas_Object *obj)
527 Eina_Rectangle *rect;
528 int x = -1, y = -1, w = -1, h = -1;
534 elm_grid_pack_get(obj, &x, &y, &w, &h);
535 rect = eina_rectangle_new(x, y, w, h);
538 LOGE("rect == NULL");
545 static bool __livebox_utils_check_intersection(Evas_Object *obj_a,
546 Eina_Rectangle *rect)
548 Eina_Rectangle *rect_o = NULL;
556 rect_o = __livebox_utils_get_grid_rectangle(obj_a);
558 if (!rect_o || !rect) {
559 LOGE("Rectangle not created: rect_o = %p; rect = %p",
564 LOGD("Intersection: <%dx%d - %dx%d> - <%dx%d - %dx%d>",
565 rect_o->x, rect_o->y, rect_o->w, rect_o->h,
566 rect->x, rect->y, rect->w, rect->h);
568 out = eina_rectangles_intersect(rect_o, rect);
570 eina_rectangle_free(rect_o);