2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (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://www.tizenopensource.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 "gl-rotate-bg.h"
23 #define GL_ROTATE_BG_DATA_KEY "gl_bg_data"
24 #define GL_ROTATE_BG_GROUP "gl_bg_layout"
26 typedef struct _gl_bg {
32 static int __gl_rotate_bg_image_rotate_180(Evas_Object *obj)
34 GL_CHECK_VAL(obj, -1);
35 unsigned int *data = NULL;
36 unsigned int *data2 = NULL;
37 unsigned int *to = NULL;
38 unsigned int *from = NULL;
44 evas_object_image_size_get(obj, &iw, &ih);
45 int size = iw * ih * sizeof(unsigned int);
47 /* EINA_FALSE for reading */
48 data = evas_object_image_data_get(obj, EINA_FALSE);
50 data2 = calloc(1, size);
51 GL_CHECK_VAL(data2, -1);
52 memcpy(data2, data, size);
54 data = evas_object_image_data_get(obj, EINA_TRUE);
59 from = data2 + hw - 1;
66 #if 0 /* Failed to rotate icon created from original file */
83 evas_object_image_data_set(obj, data);
84 evas_object_image_data_update_add(obj, 0, 0, iw, ih);
88 static int __gl_rotate_bg_image_rotate_90(Evas_Object *obj)
90 GL_CHECK_VAL(obj, -1);
91 unsigned int *data = NULL;
92 unsigned int *data2 = NULL;
93 unsigned int *to = NULL;
94 unsigned int *from = NULL;
102 evas_object_image_size_get(obj, &iw, &ih);
103 int size = iw * ih * sizeof(unsigned int);
105 /* EINA_FALSE for reading */
106 data = evas_object_image_data_get(obj, EINA_FALSE);
108 data2 = calloc(1, size);
109 GL_CHECK_VAL(data2, -1);
110 memcpy(data2, data, size);
112 /* set width, height */
118 /* set width, height to image obj */
119 evas_object_image_size_set(obj, iw, ih);
120 data = evas_object_image_data_get(obj, EINA_TRUE);
125 for (x = iw; --x >= 0;) {
126 for (y = ih; --y >= 0;) {
138 evas_object_image_data_set(obj, data);
139 evas_object_image_data_update_add(obj, 0, 0, iw, ih);
143 static int __gl_rotate_bg_image_rotate_270(Evas_Object *obj)
145 GL_CHECK_VAL(obj, -1);
146 unsigned int *data = NULL;
147 unsigned int *data2 = NULL;
148 unsigned int *to = NULL;
149 unsigned int *from = NULL;
157 evas_object_image_size_get(obj, &iw, &ih);
158 int size = iw * ih * sizeof(unsigned int);
160 /* EINA_FALSE for reading */
161 data = evas_object_image_data_get(obj, EINA_FALSE);
163 data2 = calloc(1, size);
164 GL_CHECK_VAL(data2, -1);
165 memcpy(data2, data, size);
167 /* set width, height */
173 /* set width, height to image obj */
174 evas_object_image_size_set(obj, iw, ih);
175 data = evas_object_image_data_get(obj, EINA_TRUE);
182 for (x = iw; --x >= 0;) {
183 for (y = ih; --y >= 0;) {
195 evas_object_image_data_set(obj, data);
196 evas_object_image_data_update_add(obj, 0, 0, iw, ih);
200 /* check its orientation */
201 int __gl_rotate_bg_rotate_image(Evas_Object *obj, unsigned int orient)
204 case GL_ORIENTATION_ROT_90:
205 __gl_rotate_bg_image_rotate_90(obj);
207 case GL_ORIENTATION_ROT_180:
208 __gl_rotate_bg_image_rotate_180(obj);
210 case GL_ORIENTATION_ROT_270:
211 __gl_rotate_bg_image_rotate_270(obj);
220 static void __gl_rotate_bg_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
223 gl_bg *bg_data = (gl_bg *)data;
230 static void __gl_rotate_bg_custom_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
233 gl_bg *bg_data = (gl_bg *)data;
249 if ((!bg_data->img) || (!bg_data->base)) {
250 gl_dbgE("Invalid object!");
253 /* grab image size */
254 evas_object_image_size_get(bg_data->img, &iw, &ih);
255 if ((iw < 1) || (ih < 1)) {
256 gl_dbgE("(iw < 1) || (ih < 1)!");
260 /* grab base object dimensions */
261 evas_object_geometry_get(bg_data->base, &bx, &by, &bw, &bh);
263 /* set some defaults */
271 fh = ((ih * fw) / iw);
274 fw = ((iw * fh) / ih);
276 fx = ((bw - fw) / 2);
277 fy = ((bh - fh) / 2);
279 evas_object_move(bg_data->img, nx, ny);
280 evas_object_resize(bg_data->img, nw, nh);
281 evas_object_image_fill_set(bg_data->img, fx, fy, fw, fh);
284 Evas_Object *_gl_rotate_bg_add_layout(Evas_Object *parent, const char *file, const char *group)
286 Evas_Object *eo = NULL;
289 eo = elm_layout_add(parent);
291 r = elm_layout_file_set(eo, file, group);
297 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
298 evas_object_size_hint_align_set(eo, EVAS_HINT_FILL, EVAS_HINT_FILL);
304 Evas_Object *_gl_rotate_bg_add(Evas_Object *parent)
306 GL_CHECK_NULL(parent);
308 gl_bg *bg_data = (gl_bg *)calloc(1, sizeof(gl_bg));
309 GL_CHECK_NULL(bg_data);
311 Evas_Object *base = NULL;
312 base = _gl_rotate_bg_add_layout(parent, GL_EDJ_FILE, GL_ROTATE_BG_GROUP);
314 evas_object_event_callback_add(base, EVAS_CALLBACK_RESIZE,
315 __gl_rotate_bg_custom_resize, bg_data);
316 evas_object_event_callback_add(base, EVAS_CALLBACK_DEL,
317 __gl_rotate_bg_delete_cb, bg_data);
319 evas_object_data_set(base, GL_ROTATE_BG_DATA_KEY, bg_data);
323 int _gl_rotate_bg_set_file(Evas_Object *bg, const char *file, int w, int h)
325 GL_CHECK_VAL(file, -1);
326 GL_CHECK_VAL(bg, -1);
328 gl_bg *bg_data = evas_object_data_get(bg, GL_ROTATE_BG_DATA_KEY);
329 GL_CHECK_VAL(bg_data, -1);
331 Evas_Object *image_obj = NULL;
332 image_obj = evas_object_image_add(evas_object_evas_get(bg));
333 evas_object_repeat_events_set(image_obj, EINA_TRUE);
334 bg_data->img = image_obj;
335 bg_data->file = strdup(file);
336 elm_object_part_content_set(bg, "elm.swallow.image", image_obj);
337 evas_object_image_load_size_set(image_obj, w, h);
338 evas_object_image_file_set(image_obj, file, NULL);
339 evas_object_image_preload(image_obj, EINA_FALSE);
343 int _gl_rotate_bg_rotate_image(Evas_Object *bg, unsigned int orient)
345 GL_CHECK_VAL(bg, -1);
347 gl_bg *bg_data = evas_object_data_get(bg, GL_ROTATE_BG_DATA_KEY);
348 GL_CHECK_VAL(bg_data, -1);
350 if (bg_data->file && g_strcmp0(bg_data->file, GL_DEFAULT_THUMB_ICON))
351 __gl_rotate_bg_rotate_image(bg_data->img, orient);
353 __gl_rotate_bg_rotate_image(bg_data->img, GL_ORIENTATION_ROT_0);
354 __gl_rotate_bg_custom_resize(bg_data, NULL, NULL, NULL);
358 int _gl_rotate_bg_add_image(Evas_Object *bg, int w, int h)
360 GL_CHECK_VAL(bg, -1);
362 gl_bg *bg_data = evas_object_data_get(bg, GL_ROTATE_BG_DATA_KEY);
363 GL_CHECK_VAL(bg_data, -1);
365 Evas_Object *image_obj = NULL;
366 image_obj = evas_object_image_add(evas_object_evas_get(bg));
367 evas_object_image_size_set(image_obj, w, h);
368 evas_object_image_fill_set(image_obj, 0, 0, w, h);
369 evas_object_repeat_events_set(image_obj, EINA_TRUE);
370 bg_data->img = image_obj;
371 elm_object_part_content_set(bg, "elm.swallow.image", image_obj);
372 evas_object_image_load_size_set(image_obj, w, h);
376 int _gl_rotate_bg_set_image_file(Evas_Object *bg, const char *file)
378 GL_CHECK_VAL(bg, -1);
380 gl_bg *bg_data = evas_object_data_get(bg, GL_ROTATE_BG_DATA_KEY);
381 GL_CHECK_VAL(bg_data, -1);
382 GL_CHECK_VAL(bg_data->img, -1);
384 evas_object_image_file_set(bg_data->img, file, NULL);
385 evas_object_image_preload(bg_data->img, EINA_FALSE);
387 __gl_rotate_bg_custom_resize(bg_data, NULL, NULL, NULL);