2 * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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.
18 #ifdef _USE_ROTATE_BG_GE
20 #include "ge-rotate-bg.h"
25 #define GE_ROTATE_BG_DATA_KEY "ge_bg_data"
26 #define GE_ROTATE_BG_GROUP "ge_bg_layout"
28 typedef struct _ge_bg {
35 static int __ge_rotate_bg_image_rotate_180(Evas_Object *obj)
37 GE_CHECK_VAL(obj, -1);
38 unsigned int *data = NULL;
39 unsigned int *data2 = NULL;
40 unsigned int *to = NULL;
41 unsigned int *from = NULL;
47 evas_object_image_size_get(obj, &iw, &ih);
48 int size = iw * ih * sizeof(unsigned int);
50 /* EINA_FALSE for reading */
51 data = evas_object_image_data_get(obj, EINA_FALSE);
53 data2 = calloc(1, size);
54 GE_CHECK_VAL(data2, -1);
55 memcpy(data2, data, size);
57 data = evas_object_image_data_get(obj, EINA_TRUE);
62 from = data2 + hw - 1;
72 evas_object_image_data_set(obj, data);
73 evas_object_image_data_update_add(obj, 0, 0, iw, ih);
77 static int __ge_rotate_bg_image_rotate_90(Evas_Object *obj)
79 GE_CHECK_VAL(obj, -1);
80 unsigned int *data = NULL;
81 unsigned int *data2 = NULL;
82 unsigned int *to = NULL;
83 unsigned int *from = NULL;
91 evas_object_image_size_get(obj, &iw, &ih);
92 int size = iw * ih * sizeof(unsigned int);
94 /* EINA_FALSE for reading */
95 data = evas_object_image_data_get(obj, EINA_FALSE);
97 data2 = calloc(1, size);
98 GE_CHECK_VAL(data2, -1);
99 memcpy(data2, data, size);
101 /* set width, height */
107 /* set width, height to image obj */
108 evas_object_image_size_set(obj, iw, ih);
109 data = evas_object_image_data_get(obj, EINA_TRUE);
114 for (x = iw; --x >= 0;) {
115 for (y = ih; --y >= 0;) {
126 evas_object_image_data_set(obj, data);
127 evas_object_image_data_update_add(obj, 0, 0, iw, ih);
131 static int __ge_rotate_bg_image_rotate_270(Evas_Object *obj)
133 GE_CHECK_VAL(obj, -1);
134 unsigned int *data = NULL;
135 unsigned int *data2 = NULL;
136 unsigned int *to = NULL;
137 unsigned int *from = NULL;
145 evas_object_image_size_get(obj, &iw, &ih);
146 int size = iw * ih * sizeof(unsigned int);
148 /* EINA_FALSE for reading */
149 data = evas_object_image_data_get(obj, EINA_FALSE);
151 data2 = calloc(1, size);
152 GE_CHECK_VAL(data2, -1);
153 memcpy(data2, data, size);
155 /* set width, height */
161 /* set width, height to image obj */
162 evas_object_image_size_set(obj, iw, ih);
163 data = evas_object_image_data_get(obj, EINA_TRUE);
170 for (x = iw; --x >= 0;) {
171 for (y = ih; --y >= 0;) {
182 evas_object_image_data_set(obj, data);
183 evas_object_image_data_update_add(obj, 0, 0, iw, ih);
187 /* check its orientation */
188 int __ge_rotate_bg_rotate_image(Evas_Object *obj, unsigned int orient)
191 case GE_ORIENTATION_ROT_90:
192 __ge_rotate_bg_image_rotate_90(obj);
194 case GE_ORIENTATION_ROT_180:
195 __ge_rotate_bg_image_rotate_180(obj);
197 case GE_ORIENTATION_ROT_270:
198 __ge_rotate_bg_image_rotate_270(obj);
207 static void __ge_rotate_bg_delete_cb(void *data, Evas *e, Evas_Object *obj,
211 ge_bg *bg_data = (ge_bg *)data;
212 GE_FREEIF(bg_data->file);
217 static void __ge_rotate_bg_custom_resize(void *data, Evas *e, Evas_Object *obj,
221 ge_bg *bg_data = (ge_bg *)data;
237 if ((!bg_data->img) || (!bg_data->base)) {
238 ge_dbgE("Invalid object!");
241 /* grab image size */
242 evas_object_image_size_get(bg_data->img, &iw, &ih);
243 if ((iw < 1) || (ih < 1)) {
244 ge_dbgE("(iw < 1) || (ih < 1)!");
248 /* grab base object dimensions */
249 evas_object_geometry_get(bg_data->base, &bx, &by, &bw, &bh);
251 /* set some defaults */
259 fh = ((ih * fw) / iw);
262 fw = ((iw * fh) / ih);
264 fx = ((bw - fw) / 2);
265 fy = ((bh - fh) / 2);
267 evas_object_move(bg_data->img, nx, ny);
268 evas_object_resize(bg_data->img, nw, nh);
269 evas_object_image_fill_set(bg_data->img, fx, fy, fw, fh);
272 Evas_Object *_ge_rotate_bg_add_layout(Evas_Object *parent, const char *file,
275 Evas_Object *eo = NULL;
278 eo = elm_layout_add(parent);
280 r = elm_layout_file_set(eo, file, group);
286 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
287 evas_object_size_hint_align_set(eo, EVAS_HINT_FILL, EVAS_HINT_FILL);
293 Evas_Object *_ge_rotate_bg_add(Evas_Object *parent, bool b_preload)
295 GE_CHECK_NULL(parent);
297 ge_bg *bg_data = (ge_bg *)calloc(1, sizeof(ge_bg));
298 GE_CHECK_NULL(bg_data);
300 Evas_Object *base = NULL;
301 base = _ge_rotate_bg_add_layout(parent, GE_EDJ_FILE,
309 bg_data->b_preload= b_preload;
311 evas_object_event_callback_add(base, EVAS_CALLBACK_RESIZE,
312 __ge_rotate_bg_custom_resize,
314 evas_object_event_callback_add(base, EVAS_CALLBACK_DEL,
315 __ge_rotate_bg_delete_cb, bg_data);
317 evas_object_data_set(base, GE_ROTATE_BG_DATA_KEY, bg_data);
321 int _ge_rotate_bg_set_file(Evas_Object *bg, const char *file, int w, int h)
323 GE_CHECK_VAL(file, -1);
324 GE_CHECK_VAL(bg, -1);
326 ge_bg *bg_data = evas_object_data_get(bg, GE_ROTATE_BG_DATA_KEY);
327 GE_CHECK_VAL(bg_data, -1);
329 Evas_Object *image_obj = NULL;
330 if (!bg_data->b_preload) {
331 image_obj = evas_object_image_add(evas_object_evas_get(bg));
332 evas_object_repeat_events_set(image_obj, EINA_TRUE);
333 bg_data->img = image_obj;
334 bg_data->file = strdup(file);
335 elm_object_part_content_set(bg, "elm.swallow.image", image_obj);
336 evas_object_image_load_size_set(image_obj, w, h);
337 evas_object_image_file_set(image_obj, file, NULL);
338 evas_object_image_preload(image_obj, EINA_TRUE);
340 image_obj = elm_image_add(bg);
341 evas_object_repeat_events_set(image_obj, EINA_TRUE);
342 bg_data->img = image_obj;
343 bg_data->file = strdup(file);
344 elm_object_part_content_set(bg, "elm.swallow.image", image_obj);
345 elm_image_fill_outside_set(image_obj, EINA_TRUE);
346 elm_image_file_set(image_obj, file, NULL);
347 elm_image_preload_disabled_set(image_obj, EINA_FALSE);
348 elm_image_smooth_set(image_obj, EINA_FALSE);
353 int _ge_rotate_bg_rotate_image(Evas_Object *bg, unsigned int orient)
355 GE_CHECK_VAL(bg, -1);
357 ge_bg *bg_data = evas_object_data_get(bg, GE_ROTATE_BG_DATA_KEY);
358 GE_CHECK_VAL(bg_data, -1);
360 if (bg_data->file && g_strcmp0(bg_data->file, GE_ICON_NO_THUMBNAIL) &&
361 g_strcmp0(bg_data->file, GE_ICON_CONTENTS_BROKEN))
362 __ge_rotate_bg_rotate_image(bg_data->img, orient);
364 __ge_rotate_bg_rotate_image(bg_data->img, GE_ORIENTATION_ROT_0);
365 if (!bg_data->b_preload)
366 __ge_rotate_bg_custom_resize(bg_data, NULL, NULL, NULL);
370 int _ge_rotate_bg_add_image(Evas_Object *bg, int w, int h)
372 GE_CHECK_VAL(bg, -1);
374 ge_bg *bg_data = evas_object_data_get(bg, GE_ROTATE_BG_DATA_KEY);
375 GE_CHECK_VAL(bg_data, -1);
377 Evas_Object *image_obj = NULL;
378 if (!bg_data->b_preload) {
379 image_obj = evas_object_image_add(evas_object_evas_get(bg));
380 evas_object_repeat_events_set(image_obj, EINA_TRUE);
381 bg_data->img = image_obj;
382 elm_object_part_content_set(bg, "elm.swallow.image", image_obj);
383 evas_object_image_load_size_set(image_obj, w, h);
385 image_obj = elm_image_add(bg);
386 evas_object_repeat_events_set(image_obj, EINA_TRUE);
387 bg_data->img = image_obj;
388 elm_object_part_content_set(bg, "elm.swallow.image", image_obj);
393 int _ge_rotate_bg_set_image_file(Evas_Object *bg, const char *file)
395 GE_CHECK_VAL(bg, -1);
397 ge_bg *bg_data = evas_object_data_get(bg, GE_ROTATE_BG_DATA_KEY);
398 GE_CHECK_VAL(bg_data, -1);
399 GE_CHECK_VAL(bg_data->img, -1);
401 if (!bg_data->b_preload) {
402 evas_object_image_file_set(bg_data->img, file, NULL);
403 evas_object_image_preload(bg_data->img, EINA_FALSE);
404 __ge_rotate_bg_custom_resize(bg_data, NULL, NULL, NULL);
406 elm_image_fill_outside_set(bg_data->img, EINA_TRUE);
407 elm_image_file_set(bg_data->img, file, NULL);
408 elm_image_preload_disabled_set(bg_data->img, EINA_FALSE);
409 elm_image_smooth_set(bg_data->img, EINA_FALSE);