Add smack rule
[apps/core/preloaded/ug-camera-efl.git] / src / cam_animation.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
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
7  *
8  *        http://floralicense.org/license/
9  *
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.
15  */
16
17
18 #include "cam_file.h"
19 #ifdef ENABLE_CAPTURE_ANIMATION
20 #include "cam_animation.h"
21 #include "camera_utils.h"
22
23 static void __cam_app_shutter_animation_finished(void *data, Evas_Object *obj,
24                                                  const char *emission,
25                                                  const char *source)
26 {
27         cam_debug(LOG_MM, " __cam_app_shutter_animation_finished \n\n ");
28         struct appdata *ad = (struct appdata *)data;
29 //      edje_object_signal_emit(_EDJ(ad->shutter_screen), "bright", "");
30         DEL_EVAS_OBJECT(ad->shutter_screen);
31         DEL_EVAS_OBJECT(ad->rect_image);
32
33         ad->is_capture_animation_processing = FALSE;
34 }
35
36 static void __cam_animation_get_preview_coordinate_by_direction(int *preview_offset_x,
37                                                                                 int *preview_offset_y,
38                                                                                 int *preview_w,
39                                                                                 int *preview_h,
40                                                                                 void *data)
41 {
42         struct appdata *ad = (struct appdata *)data;
43         cam_retm_if(ad == NULL, "appdata is NULL");
44         switch (ad->target_direction) {
45         case CAM_TARGET_DIRECTION_LANDSCAPE:
46         case CAM_TARGET_DIRECTION_LANDSCAPE_INVERSE:
47                 *preview_offset_x = ad->preview_offset_x;
48                 *preview_offset_y = ad->preview_offset_y;
49                 *preview_w = ad->preview_w;
50                 *preview_h = ad->preview_h;
51                 break;
52         case CAM_TARGET_DIRECTION_PORTRAIT:
53         case CAM_TARGET_DIRECTION_PORTRAIT_INVERSE:
54                 *preview_offset_x = ad->preview_offset_y;
55                 *preview_offset_y = ad->preview_offset_x;
56                 *preview_w = ad->preview_h;
57                 *preview_h = ad->preview_w;
58                 break;
59         default:
60                 DEBUG_TRACE("reached unable reached codes. error");
61         }
62 }
63
64 void cam_animation_create_rect_image(void *data)
65 {
66         struct appdata *ad = data;
67         Evas_Coord witdh = 0, height = 0;
68
69         char *group_name = "shutter_rect";
70
71         DEL_EVAS_OBJECT(ad->rect_image);
72
73         ad->rect_image = cam_app_load_edj(ad->ug_base, CAM_MAIN_LAYOUT_EDJ_NAME, group_name);
74         cam_retm_if(ad->rect_image == NULL, "rect_image load failed");
75
76         ecore_x_window_size_get(ad->main_xid, &witdh, &height);
77         evas_object_resize(ad->rect_image, witdh, height);
78         edje_object_signal_callback_add(_EDJ(ad->rect_image),
79                                         "shutter_rect,finish", "*",
80                                         __cam_app_shutter_animation_finished,
81                                         ad);
82         return;
83
84 }
85
86 Eina_Bool cam_start_capture_animation(void *data)
87 {
88         cam_debug(LOG_MM, " cam_start_capture_animation \n\n ");
89
90         struct appdata *ad = (struct appdata *)data;
91         CamAppData *camapp = NULL;
92
93         Evas_Coord x, y, w, h;
94         x = y = w = h = 0;
95
96         int window_width, window_height;
97         int pre_width, pre_height;
98         int pre_x, pre_y;
99
100         cam_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "appdata is NULL");
101         camapp = ad->camapp_handle;
102         cam_retvm_if(camapp == NULL, ECORE_CALLBACK_CANCEL, "camapp_handle is NULL");
103
104         window_width = ad->win_width;
105         window_height = ad->win_height;
106         pre_width = ad->preview_w;
107         pre_height = ad->preview_h;
108
109         __cam_animation_get_preview_coordinate_by_direction(&pre_x, &pre_y, &pre_width, &pre_height, ad);
110         if (ad->preview_w <= ad->win_width) {
111                 ad->shutter_src_rect.x =  pre_x;
112                 ad->shutter_src_rect.width = pre_width;
113         } else {
114                 ad->shutter_src_rect.x = 0;
115                 ad->shutter_src_rect.width = pre_width;
116         }
117
118         if (ad->preview_h <= ad->win_height) {
119                 ad->shutter_src_rect.y = pre_y;
120                 ad->shutter_src_rect.height = pre_height;
121         } else {
122                 ad->shutter_src_rect.y = 0;
123                 ad->shutter_src_rect.height = pre_height;
124         }
125
126         ad->shutter_des_rect.x = ad->shutter_src_rect.x;
127         ad->shutter_des_rect.y = y ;
128         ad->shutter_des_rect.width = w;
129         ad->shutter_des_rect.height = h;
130
131         evas_object_stack_above(ad->rect_image, ad->shutter_screen);
132         evas_object_resize(ad->rect_image, ad->shutter_src_rect.width, ad->shutter_src_rect.height);
133         evas_object_move(ad->rect_image, ad->shutter_src_rect.x, ad->shutter_src_rect.y);
134         evas_object_show(ad->rect_image);
135         edje_object_signal_emit(_EDJ(ad->rect_image), "shutter_rect,start", "prog");
136
137         return EINA_TRUE;
138 }
139
140 gboolean cam_app_create_start_animation(void *data)
141 {
142         struct appdata *ad = (struct appdata *)data;
143         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
144
145         ad->is_capture_animation_processing = TRUE;
146
147         cam_app_create_shutter_screen(ad);
148         cam_animation_create_rect_image(ad);
149         cam_start_capture_animation(ad);
150
151         return FALSE;
152 }
153
154 gboolean cam_app_create_screennail_and_start_animation(void *user_data)
155 {
156         struct appdata *ad = (struct appdata *)user_data;
157         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
158 #if 1/*note: using pipe handle*/
159         cam_utils_request_main_pipe_handler(ad, NULL, CAM_MAIN_PIPE_OP_TYPE_SHUTTER_ANIMATION);
160 #else
161         cam_app_create_start_animation(ad);
162 #endif
163         return TRUE;
164 }
165
166 gboolean cam_app_create_shutter_screen(void *data)
167 {
168         struct appdata *ad = data;
169         Evas_Coord witdh = 0, height = 0;
170
171         char *group_name = "shutter_image";
172
173         DEL_EVAS_OBJECT(ad->shutter_screen);
174
175         ad->shutter_screen = cam_app_load_edj(ad->ug_base, CAM_MAIN_LAYOUT_EDJ_NAME, group_name);
176         if (ad->shutter_screen == NULL) {
177                 cam_critical(LOG_UI, "shutter_screen load failed ");
178                 return FALSE;
179         }
180
181         ecore_x_window_size_get(ad->main_xid, &witdh, &height);
182         evas_object_resize(ad->shutter_screen, witdh, height);
183
184         /*evas_object_lower(ad->shutter_screen);*/
185         evas_object_show(ad->shutter_screen);
186         evas_object_show(ad->win_main);
187
188         /*edje_object_signal_emit(_EDJ(ad->shutter_screen), "start_animation", "");*/
189
190         edje_object_signal_callback_add(_EDJ(ad->shutter_screen),
191                                         "animation_finish", "*",
192                                         __cam_app_shutter_animation_finished,
193                                         ad);
194         return TRUE;
195 }
196 #endif