2 * Copyright 2012 Samsung Electronics Co., Ltd
\r
4 * Licensed under the Flora License, Version 1.1 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://floralicense.org/license/
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 #include "cam_ui_rotate_utils.h"
\r
19 #include "cam_toolbar_edc_callback.h"
\r
21 static void __cam_ui_rotate_utils_rotation_del_cb(void *data, Elm_Transit *transit)
\r
23 DEBUG_TRACE("rotate transition will be deleted");
\r
26 static Ecore_Idler *__cam_ui_rotate_utils_idler = NULL;
\r
27 static Eina_Bool __cam_ui_rotate_utils_obj_rotation_idler_cb(void *data)
\r
29 if (__cam_ui_rotate_utils_idler) {
\r
30 ecore_idler_del(__cam_ui_rotate_utils_idler);
\r
31 __cam_ui_rotate_utils_idler = NULL;
\r
34 struct cam_ui_rotate_obj_params *rotate_obj_params = (struct cam_ui_rotate_obj_params *)data;
\r
35 if (!rotate_obj_params)
\r
36 return ECORE_CALLBACK_CANCEL;
\r
37 if (!rotate_obj_params->obj)
\r
38 return ECORE_CALLBACK_CANCEL;
\r
40 struct appdata *ad = (struct appdata *)cam_appdata_get();
\r
41 cam_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "appdata is NULL");
\r
43 Evas_Object *obj = rotate_obj_params->obj;
\r
45 ////TODO:add a function, to unset popup
\r
46 Evas_Coord x, y, w, h;
\r
47 evas_object_geometry_get(obj, &x, &y, &w, &h);
\r
48 static int repeat_count = 0;
\r
49 if (w == 0 || h == 0) {
\r
50 if (repeat_count++ == 10) {
\r
52 return ECORE_CALLBACK_CANCEL;
\r
54 DEBUG_TRACE("repeat_count = %d", repeat_count);
\r
55 return ECORE_CALLBACK_RENEW;
\r
58 elm_object_part_content_unset(ad->toolbar_edje, "camera/setting/popup/area/toolbar");
\r
59 DEBUG_TRACE("rotate_obj_params->x = %d", rotate_obj_params->x);
\r
60 DEBUG_TRACE("rotate_obj_params->y = %d", rotate_obj_params->y);
\r
61 cam_ui_rotate_utils_map_rotate(obj, rotate_obj_params->x, rotate_obj_params->y, rotate_obj_params->degree);
\r
62 free(rotate_obj_params);
\r
63 rotate_obj_params = NULL;
\r
65 edje_object_signal_emit(_EDJ(obj), "set.popup.show", "prog");
\r
66 evas_object_raise(obj);
\r
67 evas_object_show(obj);
\r
69 return ECORE_CALLBACK_CANCEL;
\r
72 void cam_ui_rotate_utils_map_setting_popup_rotate(Evas_Object *obj,
\r
77 DEBUG_TRACE("degree = %f", degree);
\r
78 struct cam_ui_rotate_obj_params *rotate_obj_params = calloc( 1, sizeof( struct cam_ui_rotate_obj_params ) );
\r
79 if (!rotate_obj_params) return;
\r
80 rotate_obj_params->obj = obj;
\r
81 rotate_obj_params->x = start_x;
\r
82 rotate_obj_params->y = start_y;
\r
83 rotate_obj_params->degree = degree;
\r
84 DEBUG_TRACE("rotate_obj_params->x = %d", start_x);
\r
85 DEBUG_TRACE("rotate_obj_params->y = %d", start_y);
\r
86 DEBUG_TRACE("rotate_obj_params->x = %d", start_x);
\r
87 DEBUG_TRACE("rotate_obj_params->degree = %f", degree);
\r
88 if (__cam_ui_rotate_utils_idler) {
\r
89 ecore_idler_del(__cam_ui_rotate_utils_idler);
\r
90 __cam_ui_rotate_utils_idler = NULL;
\r
93 __cam_ui_rotate_utils_idler = ecore_idler_add(__cam_ui_rotate_utils_obj_rotation_idler_cb, (void *)rotate_obj_params);
\r
96 void cam_ui_rotate_utils_map_rotate(Evas_Object *obj,
\r
102 Evas_Map *map = NULL;
\r
103 map = evas_map_new(4);
\r
106 Evas_Coord x, y, w, h;
\r
107 float half_w, half_h;
\r
109 evas_map_util_points_populate_from_object_full(map, obj, 0);
\r
110 evas_object_geometry_get(obj, &x, &y, &w, &h);
\r
111 DEBUG_TRACE("obj x, y, w, h:%d %d %d %d", x, y, w, h);
\r
112 DEBUG_TRACE("start x, y, w, h: %d %d %d %d", start_x, start_y, w, h);
\r
113 half_w = (float)w * 0.5;
\r
114 half_h = (float)h * 0.5;
\r
115 evas_map_point_coord_set(map, 0, start_x, start_y, 0);
\r
116 evas_map_point_coord_set(map, 1, start_x + w , start_y, 0);
\r
117 evas_map_point_coord_set(map, 2, start_x + w , start_y + h, 0);
\r
118 evas_map_point_coord_set(map, 3, start_x, start_y + h, 0);
\r
119 evas_map_util_rotate(map, degree, start_x + half_w, start_y + half_h);
\r
120 /*note:foc 2000, just default*/
\r
121 evas_map_util_3d_perspective(map, start_x + half_w, start_y + half_h, 0, 2000);
\r
122 evas_object_map_enable_set(obj, EINA_TRUE);
\r
123 evas_object_map_set(obj, map);
\r
125 evas_map_free(map);
\r
130 void cam_ui_rotate_utils_map_self_rotate(Evas_Object *obj,
\r
134 Evas_Map *map = NULL;
\r
135 map = evas_map_new(4);
\r
138 Evas_Coord x, y, w, h;
\r
139 float half_w, half_h;
\r
141 evas_map_util_points_populate_from_object_full(map, obj, 0);
\r
142 evas_object_geometry_get(obj, &x, &y, &w, &h);
\r
143 DEBUG_TRACE("obj x, y, w, h:%d %d %d %d", x, y, w, h);
\r
144 half_w = (float)w * 0.5;
\r
145 half_h = (float)h * 0.5;
\r
146 evas_map_point_coord_set(map, 0, x, y, 0);
\r
147 evas_map_point_coord_set(map, 1, x + w , y, 0);
\r
148 evas_map_point_coord_set(map, 2, x + w , y + h, 0);
\r
149 evas_map_point_coord_set(map, 3, x, y + h, 0);
\r
150 evas_map_util_rotate(map, degree, x + half_w, y + half_h);
\r
151 /*note:foc 2000, just default*/
\r
152 evas_map_util_3d_perspective(map, x + half_w, y + half_h, 0, 2000);
\r
153 evas_object_map_enable_set(obj, EINA_TRUE);
\r
154 evas_object_map_set(obj, map);
\r
156 evas_map_free(map);
\r
162 void cam_ui_rotate_utils_rotation_effect(Evas_Object *obj,
\r
166 void (*cb) (void *data, Elm_Transit *transit),
\r
170 Evas_Object *nf = obj;
\r
171 Elm_Transit *transit = elm_transit_add();
\r
172 /*360 degree rotation effect with clock wise direction.*/
\r
173 elm_transit_object_add(transit, nf);
\r
174 elm_transit_effect_rotation_add(transit, from_degree, to_degree);
\r
175 elm_transit_duration_set(transit, duration);
\r
177 elm_transit_del_cb_set(transit, cb, data);
\r
179 elm_transit_del_cb_set(transit, __cam_ui_rotate_utils_rotation_del_cb, data);
\r
180 elm_transit_objects_final_state_keep_set(transit, TRUE);
\r
181 elm_transit_go(transit);
\r
184 /*note: below is for icon rotate*/
\r
186 static gboolean cam_ui_rotate_utils_get_clockwise_state(struct appdata *ad)
\r
188 gboolean IsClockwise = FALSE;
\r
190 if (ad->rot_previous == APP_DEVICE_ORIENTATION_270) {
\r
191 if (ad->rot_current > ad->rot_previous){
\r
192 IsClockwise = TRUE;
\r
194 IsClockwise = FALSE;
\r
197 if(ad->rot_current > ad->rot_previous) {
\r
198 IsClockwise = FALSE;
\r
200 IsClockwise = TRUE;
\r
203 return IsClockwise;
\r
206 void cam_ui_rotate_utils_get_rotation_degree(void* data, int* from_degree, int* to_degree)
\r
208 struct appdata *ad = (struct appdata *)data;
\r
209 cam_retm_if(ad == NULL, "appdata is NULL");
\r
211 int tmp_to_degree = 0;
\r
212 int tmp_from_degree = 0;
\r
213 gboolean IsClockwise = FALSE;
\r
215 if (ad->rot_previous == APP_DEVICE_ORIENTATION_270) {
\r
216 if (ad->rot_current > ad->rot_previous){
\r
217 IsClockwise = TRUE;
\r
219 IsClockwise = FALSE;
\r
222 if(ad->rot_current > ad->rot_previous) {
\r
223 IsClockwise = FALSE;
\r
225 IsClockwise = TRUE;
\r
229 switch(ad->rot_previous) {
\r
230 case APP_DEVICE_ORIENTATION_270:
\r
231 if(ad->rot_current == APP_DEVICE_ORIENTATION_0) {
\r
232 tmp_from_degree = 360;
\r
234 tmp_from_degree = 0;
\r
237 case APP_DEVICE_ORIENTATION_0:
\r
238 tmp_from_degree = 270;
\r
240 case APP_DEVICE_ORIENTATION_90:
\r
241 tmp_from_degree = 180;
\r
243 case APP_DEVICE_ORIENTATION_180:
\r
244 tmp_from_degree = 90;
\r
250 switch(ad->rot_current) {
\r
251 case APP_DEVICE_ORIENTATION_270:
\r
252 if( ad->rot_previous == APP_DEVICE_ORIENTATION_0) {
\r
253 tmp_to_degree = 360;
\r
258 case APP_DEVICE_ORIENTATION_0:
\r
259 tmp_to_degree = 270;
\r
261 case APP_DEVICE_ORIENTATION_90:
\r
262 tmp_to_degree = 180;
\r
264 case APP_DEVICE_ORIENTATION_180:
\r
265 tmp_to_degree = 90;
\r
271 *from_degree = tmp_from_degree;
\r
272 *to_degree = tmp_to_degree;
\r
274 cam_debug(LOG_UI, "from_degree : %d, to_degree : %d ", *from_degree, *to_degree );
\r
278 void cam_ui_rotate_utils_get_rotation_degree_map(void* data, int* degree)
\r
280 struct appdata *ad = (struct appdata *)data;
\r
281 cam_retm_if(ad == NULL, "appdata is NULL");
\r
283 int tmp_degree = 0;
\r
285 gboolean IsClockwise = FALSE;
\r
287 if (ad->rot_previous == APP_DEVICE_ORIENTATION_270) {
\r
288 if (ad->rot_current > ad->rot_previous) {
\r
289 IsClockwise = TRUE;
\r
291 IsClockwise = FALSE;
\r
294 if (ad->rot_current > ad->rot_previous) {
\r
295 IsClockwise = FALSE;
\r
297 IsClockwise = TRUE;
\r
301 switch(ad->rot_current) {
\r
302 case APP_DEVICE_ORIENTATION_0:
\r
305 case APP_DEVICE_ORIENTATION_90:
\r
308 case APP_DEVICE_ORIENTATION_180:
\r
311 case APP_DEVICE_ORIENTATION_270:
\r
318 *degree = tmp_degree;
\r
320 cam_debug(LOG_UI, "degree : %d", *degree );
\r
324 static void __cam_ui_rotate_utils_focus_coordate_rotate(struct appdata *ad)
\r
326 /*TODO: for animator, we just rotate when popup create*/
\r
327 cam_retm_if(ad == NULL, "appdata is NULL");
\r
329 int af_start_x, af_start_y;
\r
330 af_start_x = af_start_y = 0;
\r
334 if (ad->angle == 90
\r
335 || ad->angle == 270) {
\r
336 x_w = 1280 * elm_config_scale_get();
\r
337 y_h = 720 * elm_config_scale_get();
\r
338 } else if (ad->angle == 0
\r
339 || ad->angle == 180) {
\r
340 x_w = 720 * elm_config_scale_get();
\r
341 y_h = 1280 * elm_config_scale_get();
\r
343 DEBUG_TRACE("%d", ad->angle_pre);
\r
344 x_w = 1280 * elm_config_scale_get();
\r
345 y_h = 720 * elm_config_scale_get();
\r
348 switch (ad->rotate_angle) {
\r
350 af_start_x = ad->af_start_x;
\r
351 af_start_y = ad->af_start_y;
\r
353 case 90:/*un-clockwise*/
\r
354 af_start_x = ad->af_start_y;
\r
355 af_start_y = y_h - ad->af_start_x;
\r
356 if (ad->angle == 0 || ad->angle == 180) {
\r
357 af_start_y -= ad->camera_focus_w;
\r
359 af_start_y -= ad->camera_focus_h;
\r
363 af_start_x = x_w - ad->af_start_y;
\r
364 af_start_y = ad->af_start_x;
\r
365 if (ad->angle == 0 || ad->angle == 180) {
\r
366 af_start_x -= ad->camera_focus_h;
\r
368 af_start_x -= ad->camera_focus_w;
\r
373 af_start_x = x_w - ad->af_start_x;
\r
374 af_start_y = y_h - ad->af_start_y;
\r
375 if (ad->angle == 0 || ad->angle == 180) {
\r
376 af_start_x -= ad->camera_focus_h;
\r
377 af_start_y -= ad->camera_focus_w;
\r
379 af_start_x -= ad->camera_focus_w;
\r
380 af_start_y -= ad->camera_focus_h;
\r
384 DEBUG_TRACE("%d", ad->rotate_angle);
\r
387 ad->af_start_x = af_start_x;
\r
388 ad->af_start_y = af_start_y;
\r
392 static void __cam_ui_rotate_utils_after_rotate_cb(void *data, Elm_Transit *transit)
\r
395 struct appdata *ad = (struct appdata *)data;
\r
396 cam_retm_if(ad == NULL, "appdata is NULL");
\r
398 __cam_ui_rotate_utils_focus_coordate_rotate(ad);
\r
399 ad->angle_pre = ad->angle;/*must called after __cam_ui_roate_utils_focus_coordate_rotate*/
\r
400 cam_app_screen_rotate(ad);
\r
401 /*cam_screen_rotate(ad);*/
\r
404 static void __cam_ui_rotate_utils_after_shortcuts_rotate_cb(void *data, Elm_Transit *transit)
\r
407 struct appdata *ad = (struct appdata *)data;
\r
408 cam_retm_if(ad == NULL, "appdata is NULL");
\r
409 cam_retm_if(ad->toolbar_edje == NULL, "appdata is NULL");
\r
410 edje_object_signal_emit(_EDJ(ad->toolbar_edje),
\r
411 "toolbar_1_icon,normal", "prog");
\r
412 edje_object_signal_emit(_EDJ(ad->toolbar_edje),
\r
413 "toolbar_2_icon,normal", "prog");
\r
414 edje_object_signal_emit(_EDJ(ad->toolbar_edje),
\r
415 "toolbar_3_icon,normal", "prog");
\r
416 edje_object_signal_emit(_EDJ(ad->toolbar_edje),
\r
417 "toolbar_4_icon,normal", "prog");
\r
421 gboolean cam_ui_rotate_utils_rotate_start(void *data, double duration)
\r
423 struct appdata *ad = (struct appdata *)data;
\r
424 cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
\r
426 if (ad->toolbar_setting_popup) {
\r
427 ad->show_setting_popup_after_rotate = TRUE;
\r
428 cam_toolbar_setting_popup_destroy(ad);
\r
431 if (ad->setting_ctxpopup) {
\r
432 cam_toolbar_setting_popup_destroy(ad);
\r
435 if (ad->edit_shortcuts_popup) {
\r
436 ad->show_edit_shortcuts_popup_after_rotate = TRUE;
\r
437 toolbar_destroy_shortcuts_popup(ad);
\r
440 cam_debug(LOG_UI, "duration : %d", duration);
\r
442 ad->is_rotating = TRUE;
\r
443 Elm_Transit* transit= elm_transit_add();
\r
445 int from_degree = 0;
\r
449 for (i = CAM_MENU_BAR_LEFT_0; i < CAM_MENU_BAR_LEFT_MAX_NUM; i++) {
\r
450 int type = ad->toolbar_menu_arrays[i].menu_type;
\r
451 Evas_Object *icon = ad->toolbar_menu_arrays[i].icon;
\r
452 if (icon == NULL) {
\r
453 cam_debug(LOG_UI, "toolbar_0_icon is null" );
\r
455 elm_transit_object_add(transit, icon);
\r
459 #if 0 /*TODO: block temporary, good solution should be consider*/
\r
460 if (ad->indicator_edje) {
\r
461 elm_transit_object_add(transit, ad->indicator_edje);
\r
466 if (ad->focus_edje) {
\r
467 elm_transit_object_add(transit, ad->focus_edje);
\r
469 if (ad->timer_icon_edje) {
\r
470 elm_transit_object_add(transit, ad->timer_icon_edje);
\r
472 if (ad->capturebtn_edje) {
\r
473 elm_transit_object_add(transit, ad->capturebtn_edje);
\r
475 if (ad->shutterbtn_camera_icon) {
\r
476 elm_transit_object_add(transit, ad->shutterbtn_camera_icon);
\r
478 if (ad->recordingbtn) {
\r
479 elm_transit_object_add(transit, ad->recordingbtn);
\r
481 if (ad->recording_stop_btn) {
\r
482 elm_transit_object_add(transit, ad->recording_stop_btn);
\r
484 if (ad->toolbar.quickview_item.edje) {
\r
485 elm_transit_object_add(transit, ad->toolbar.quickview_item.edje);
\r
488 elm_transit_object_add(transit, ad->backbtn);
\r
490 if (ad->caf_button) {
\r
491 elm_transit_object_add(transit, ad->caf_button);
\r
495 if (ad->recording_edje
\r
496 && cam_mm_get_state() == RECORDER_STATE_RECORDING)
\r
497 elm_transit_object_add(transit, ad->recording_edje);*/
\r
498 cam_ui_rotate_utils_get_rotation_degree(ad, &from_degree, &to_degree);
\r
499 from_degree = ad->angle_pre;
\r
500 to_degree = ad->angle;
\r
503 if ((from_degree == 0 && to_degree == 90)
\r
504 || (from_degree == 90 && to_degree == 180)
\r
505 || (from_degree == 180 && to_degree == 270)
\r
506 || (from_degree == 270 && to_degree == 0)) {
\r
509 DEBUG_TRACE("CLOCKWISE");
\r
510 } else if ((from_degree == 90 && to_degree == 0)
\r
511 || (from_degree == 180 && to_degree == 90)
\r
512 || (from_degree == 270 && to_degree == 180)
\r
513 || (from_degree == 0 && to_degree == 270)) {
\r
516 DEBUG_TRACE("UN-CLOCKWISE");
\r
519 DEBUG_TRACE("from_degree->to_degree %d->%d", from_degree, to_degree);
\r
521 if ((to_degree - from_degree) == 270) {
\r
524 ad->rotate_angle = 90;
\r
525 } else if ((to_degree - from_degree) == -270) {
\r
528 ad->rotate_angle = -90;
\r
530 to_degree = (to_degree - from_degree) *(-1);
\r
532 ad->rotate_angle = to_degree;
\r
534 DEBUG_TRACE("from_degree->to_degree %d->%d", from_degree, to_degree);
\r
536 cam_debug(LOG_UI, "ad->angle : %d, ad->angle_pre : %d ", ad->angle, ad->angle_pre );
\r
537 gboolean is_clockwise = cam_ui_rotate_utils_get_clockwise_state(ad);
\r
538 cam_debug(LOG_UI, "is_clockwise : %d, ", is_clockwise );
\r
539 elm_transit_effect_rotation_add(transit, from_degree, to_degree);
\r
540 elm_transit_duration_set(transit, duration);
\r
541 elm_transit_del_cb_set(transit, __cam_ui_rotate_utils_after_rotate_cb, data);
\r
542 elm_transit_objects_final_state_keep_set(transit, TRUE);
\r
543 elm_transit_go(transit);
\r
545 cam_debug(LOG_UI, "real_from_degree : %d, real_to_degree : %d ", from_degree, to_degree );
\r
546 /*ad->angle_pre = ad->angle;*/
\r
551 gboolean cam_ui_rotate_utils_rotate_toolbar_shortcuts(void *data, double duration)
\r
553 struct appdata *ad = (struct appdata *)data;
\r
554 cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
\r
556 cam_debug(LOG_UI, "duration : %d", duration);
\r
558 Elm_Transit* transit= elm_transit_add();
\r
560 int from_degree = 0;
\r
565 for (i = CAM_MENU_BAR_LEFT_0; i < CAM_MENU_BAR_LEFT_MAX_NUM; i++) {
\r
566 int type = ad->toolbar_menu_arrays[i].menu_type;
\r
567 Evas_Object *icon = ad->toolbar_menu_arrays[i].icon;
\r
568 if (icon == NULL) {
\r
569 cam_debug(LOG_UI, "toolbar_0_icon is null" );
\r
571 elm_transit_object_add(transit, icon);
\r
575 cam_ui_rotate_utils_get_rotation_degree(ad, &from_degree, &to_degree);
\r
577 elm_transit_effect_rotation_add(transit, from_degree, to_degree);
\r
578 elm_transit_duration_set(transit, duration);
\r
579 elm_transit_del_cb_set(transit, __cam_ui_rotate_utils_after_shortcuts_rotate_cb, data);
\r
580 elm_transit_objects_final_state_keep_set(transit, TRUE);
\r
581 elm_transit_go(transit);
\r
583 cam_debug(LOG_UI, "real_from_degree : %d, real_to_degree : %d ", from_degree, to_degree );
\r