1 #include <Elementary.h>
4 typedef struct _Smart_Data Smart_Data;
12 Eina_Bool fill_inside : 1;
13 Eina_Bool scale_up : 1;
14 Eina_Bool scale_down : 1;
15 Eina_Bool preloading : 1;
19 Eina_Bool aspect_ratio_retained: 1;
20 Elm_Image_Orient orient;
23 /* local subsystem functions */
24 static void _smart_reconfigure(Smart_Data *sd);
25 static void _smart_init(void);
26 static void _smart_add(Evas_Object *obj);
27 static void _smart_del(Evas_Object *obj);
28 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
29 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
30 static void _smart_show(Evas_Object *obj);
31 static void _smart_hide(Evas_Object *obj);
32 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
33 static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
34 static void _smart_clip_unset(Evas_Object *obj);
36 static void _els_smart_icon_flip_horizontal(Smart_Data *sd);
37 static void _els_smart_icon_flip_vertical(Smart_Data *sd);
38 static void _els_smart_icon_rotate_180(Smart_Data *sd);
39 static Eina_Bool _els_smart_icon_dropcb(void *,Evas_Object *, Elm_Selection_Data *);
41 /* local subsystem globals */
42 static Evas_Smart *_e_smart = NULL;
44 /* externally accessible functions */
46 _els_smart_icon_add(Evas *evas)
49 return evas_object_smart_add(evas, _e_smart);
53 _preloaded(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
55 Smart_Data *sd = data;
57 sd->preloading = EINA_FALSE;
59 evas_object_show(sd->obj);
63 _els_smart_icon_file_key_set(Evas_Object *obj, const char *file, const char *key)
68 sd = evas_object_smart_data_get(obj);
69 if (!sd) return EINA_FALSE;
73 pclip = evas_object_clip_get(sd->obj);
74 if (sd->obj) evas_object_del(sd->obj);
75 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
76 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
77 evas_object_smart_member_add(sd->obj, obj);
78 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
80 evas_object_clip_set(sd->obj, pclip);
81 sd->edje = EINA_FALSE;
84 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
85 evas_object_image_file_set(sd->obj, file, key);
86 /* by default preload off by seok.j.jeong */
87 sd->preloading = EINA_FALSE;
90 evas_object_image_preload(sd->obj, EINA_FALSE);
91 /* sd->preloading can be changed by above function. so add "if (sd->preloading)" as below */
93 evas_object_hide(sd->obj);
94 if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
96 _smart_reconfigure(sd);
101 _els_smart_icon_file_edje_set(Evas_Object *obj, const char *file, const char *part)
106 sd = evas_object_smart_data_get(obj);
107 if (!sd) return EINA_FALSE;
108 /* smart code here */
111 pclip = evas_object_clip_get(sd->obj);
112 if (sd->obj) evas_object_del(sd->obj);
113 sd->obj = edje_object_add(evas_object_evas_get(obj));
114 evas_object_smart_member_add(sd->obj, obj);
115 if (sd->show) evas_object_show(sd->obj);
116 evas_object_clip_set(sd->obj, pclip);
118 sd->edje = EINA_TRUE;
119 if (!edje_object_file_set(sd->obj, file, part))
121 _smart_reconfigure(sd);
126 _els_smart_icon_file_get(const Evas_Object *obj, const char **file, const char **key)
128 Smart_Data *sd = evas_object_smart_data_get(obj);
131 edje_object_file_get(sd->obj, file, key);
133 evas_object_image_file_get(sd->obj, file, key);
137 _els_smart_icon_smooth_scale_set(Evas_Object *obj, Eina_Bool smooth)
139 Smart_Data *sd = evas_object_smart_data_get(obj);
143 evas_object_image_smooth_scale_set(sd->obj, smooth);
147 _els_smart_icon_smooth_scale_get(const Evas_Object *obj)
149 Smart_Data *sd = evas_object_smart_data_get(obj);
150 if (!sd) return EINA_FALSE;
153 return evas_object_image_smooth_scale_get(sd->obj);
157 _els_smart_icon_object_get(const Evas_Object *obj)
159 Smart_Data *sd = evas_object_smart_data_get(obj);
160 if (!sd) return NULL;
165 _els_smart_icon_size_get(const Evas_Object *obj, int *w, int *h)
170 sd = evas_object_smart_data_get(obj);
172 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
173 edje_object_size_min_get(sd->obj, &tw, &th);
175 evas_object_image_size_get(sd->obj, &tw, &th);
176 tw = ((double)tw) * sd->scale;
177 th = ((double)th) * sd->scale;
183 _els_smart_icon_fill_inside_set(Evas_Object *obj, Eina_Bool fill_inside)
187 sd = evas_object_smart_data_get(obj);
189 if (((sd->fill_inside) && (fill_inside)) ||
190 ((!sd->fill_inside) && (!fill_inside))) return;
191 sd->fill_inside = fill_inside;
192 _smart_reconfigure(sd);
196 _els_smart_icon_fill_inside_get(const Evas_Object *obj)
198 Smart_Data *sd = evas_object_smart_data_get(obj);
199 if (!sd) return EINA_FALSE;
200 return sd->fill_inside;
204 _els_smart_icon_scale_up_set(Evas_Object *obj, Eina_Bool scale_up)
208 sd = evas_object_smart_data_get(obj);
210 if (((sd->scale_up) && (scale_up)) ||
211 ((!sd->scale_up) && (!scale_up))) return;
212 sd->scale_up = scale_up;
213 _smart_reconfigure(sd);
217 _els_smart_icon_scale_up_get(const Evas_Object *obj)
219 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
220 if (!sd) return EINA_FALSE;
225 _els_smart_icon_scale_down_set(Evas_Object *obj, Eina_Bool scale_down)
229 sd = evas_object_smart_data_get(obj);
231 if (((sd->scale_down) && (scale_down)) ||
232 ((!sd->scale_down) && (!scale_down))) return;
233 sd->scale_down = scale_down;
234 _smart_reconfigure(sd);
238 _els_smart_icon_scale_down_get(const Evas_Object *obj)
240 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
241 if (!sd) return EINA_FALSE;
246 _els_smart_icon_scale_size_set(Evas_Object *obj, int size)
250 sd = evas_object_smart_data_get(obj);
253 if (!sd->obj) return;
256 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
260 _els_smart_icon_scale_size_get(const Evas_Object *obj)
262 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
268 _els_smart_icon_scale_set(Evas_Object *obj, double scale)
270 Smart_Data *sd = evas_object_smart_data_get(obj);
273 _smart_reconfigure(sd);
277 _els_smart_icon_scale_get(const Evas_Object *obj)
279 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
285 _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
289 unsigned int *data, *data2, *to, *from;
290 int x, y, w, hw, iw, ih;
291 const char *file, *key;
293 sd = evas_object_smart_data_get(obj);
300 case ELM_IMAGE_FLIP_HORIZONTAL:
301 _els_smart_icon_flip_horizontal(sd);
303 case ELM_IMAGE_FLIP_VERTICAL:
304 _els_smart_icon_flip_vertical(sd);
306 case ELM_IMAGE_ROTATE_180_CW:
307 _els_smart_icon_rotate_180(sd);
313 evas_object_image_size_get(sd->obj, &iw, &ih);
314 evas_object_image_file_get(sd->obj, &file, &key);
315 tmp = evas_object_image_add(evas_object_evas_get(sd->obj));
316 evas_object_image_file_set(tmp, file, key);
317 data2 = evas_object_image_data_get(tmp, EINA_FALSE);
324 evas_object_image_size_set(sd->obj, iw, ih);
325 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
328 case ELM_IMAGE_FLIP_TRANSPOSE:
332 case ELM_IMAGE_FLIP_TRANSVERSE:
337 case ELM_IMAGE_ROTATE_90_CW:
341 case ELM_IMAGE_ROTATE_90_CCW:
347 ERR("unknown orient %d", orient);
348 evas_object_del(tmp);
349 evas_object_image_data_set(sd->obj, data); // give it back
353 for (x = iw; --x >= 0;)
355 for (y = ih; --y >= 0;)
364 evas_object_del(tmp);
365 evas_object_image_data_set(sd->obj, data);
366 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
367 _smart_reconfigure(sd);
371 _els_smart_icon_orient_get(const Evas_Object *obj)
373 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
379 * Turns on editing through drag and drop and copy and paste.
382 _els_smart_icon_edit_set(Evas_Object *obj, Eina_Bool edit, Evas_Object *parent)
384 Smart_Data *sd = evas_object_smart_data_get(obj);
389 printf("No editing edje objects yet (ever)\n");
393 /* Unfortunately eina bool is not a bool, but a char */
394 if (edit == sd->edit) return;
399 elm_drop_target_add(obj, ELM_SEL_FORMAT_IMAGE, _els_smart_icon_dropcb,
402 elm_drop_target_del(obj);
406 _els_smart_icon_edit_get(const Evas_Object *obj)
408 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
409 if (!sd) return EINA_FALSE;
414 _els_smart_icon_edje_get(Evas_Object *obj)
416 Smart_Data *sd = evas_object_smart_data_get(obj);
417 if (!sd) return NULL;
418 if (!sd->edje) return NULL;
423 _els_smart_icon_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained)
427 sd = evas_object_smart_data_get(obj);
430 retained = !!retained;
431 if (sd->aspect_ratio_retained == retained) return;
432 sd->aspect_ratio_retained = retained;
433 _smart_reconfigure(sd);
437 _els_smart_icon_aspect_ratio_retained_get(const Evas_Object *obj)
441 sd = evas_object_smart_data_get(obj);
442 if (!sd) return EINA_FALSE;
443 return sd->aspect_ratio_retained;
446 /* local subsystem globals */
448 _smart_reconfigure(Smart_Data *sd)
450 Evas_Coord x, y, w, h;
452 if (!sd->obj) return;
457 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
461 evas_object_move(sd->obj, x, y);
462 evas_object_resize(sd->obj, w, h);
468 evas_object_image_size_get(sd->obj, &iw, &ih);
470 iw = ((double)iw) * sd->scale;
471 ih = ((double)ih) * sd->scale;
476 if (sd->aspect_ratio_retained)
478 h = ((double)ih * w) / (double)iw;
484 w = ((double)iw * h) / (double)ih;
492 w = ((double)iw * h) / (double)ih;
506 x = sd->x + ((sd->w - w) / 2);
507 y = sd->y + ((sd->h - h) / 2);
508 evas_object_move(sd->obj, x, y);
509 evas_object_image_fill_set(sd->obj, 0, 0, w, h);
510 evas_object_resize(sd->obj, w, h);
517 if (_e_smart) return;
519 static const Evas_Smart_Class sc =
522 EVAS_SMART_CLASS_VERSION,
540 _e_smart = evas_smart_class_new(&sc);
545 _smart_add(Evas_Object *obj)
549 sd = calloc(1, sizeof(Smart_Data));
551 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
552 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
557 sd->fill_inside = EINA_TRUE;
558 sd->scale_up = EINA_TRUE;
559 sd->scale_down = EINA_TRUE;
560 sd->aspect_ratio_retained = EINA_TRUE;
563 evas_object_smart_member_add(sd->obj, obj);
564 evas_object_smart_data_set(obj, sd);
565 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
570 _smart_del(Evas_Object *obj)
574 sd = evas_object_smart_data_get(obj);
576 evas_object_del(sd->obj);
581 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
585 sd = evas_object_smart_data_get(obj);
587 if ((sd->x == x) && (sd->y == y)) return;
590 _smart_reconfigure(sd);
594 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
598 sd = evas_object_smart_data_get(obj);
600 if ((sd->w == w) && (sd->h == h)) return;
603 _smart_reconfigure(sd);
607 _smart_show(Evas_Object *obj)
611 sd = evas_object_smart_data_get(obj);
613 sd->show = EINA_TRUE;
615 evas_object_show(sd->obj);
619 _smart_hide(Evas_Object *obj)
623 sd = evas_object_smart_data_get(obj);
625 sd->show = EINA_FALSE;
626 evas_object_hide(sd->obj);
630 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
634 sd = evas_object_smart_data_get(obj);
636 evas_object_color_set(sd->obj, r, g, b, a);
640 _smart_clip_set(Evas_Object *obj, Evas_Object * clip)
644 sd = evas_object_smart_data_get(obj);
646 evas_object_clip_set(sd->obj, clip);
650 _smart_clip_unset(Evas_Object *obj)
654 sd = evas_object_smart_data_get(obj);
656 evas_object_clip_unset(sd->obj);
660 _els_smart_icon_flip_horizontal(Smart_Data *sd)
663 unsigned int *p1, *p2, tmp;
666 evas_object_image_size_get(sd->obj, &iw, &ih);
667 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
669 for (y = 0; y < ih; y++)
671 p1 = data + (y * iw);
672 p2 = data + ((y + 1) * iw) - 1;
673 for (x = 0; x < (iw >> 1); x++)
683 evas_object_image_data_set(sd->obj, data);
684 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
685 _smart_reconfigure(sd);
689 _els_smart_icon_flip_vertical(Smart_Data *sd)
692 unsigned int *p1, *p2, tmp;
695 evas_object_image_size_get(sd->obj, &iw, &ih);
696 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
698 for (y = 0; y < (ih >> 1); y++)
700 p1 = data + (y * iw);
701 p2 = data + ((ih - 1 - y) * iw);
702 for (x = 0; x < iw; x++)
712 evas_object_image_data_set(sd->obj, data);
713 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
714 _smart_reconfigure(sd);
718 _els_smart_icon_rotate_180(Smart_Data *sd)
721 unsigned int *p1, *p2, tmp;
724 evas_object_image_size_get(sd->obj, &iw, &ih);
725 data = evas_object_image_data_get(sd->obj, 1);
739 evas_object_image_data_set(sd->obj, data);
740 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
741 _smart_reconfigure(sd);
745 _els_smart_icon_dropcb(void *elmobj,Evas_Object *obj, Elm_Selection_Data *drop)
747 _els_smart_icon_file_key_set(obj, drop->data, NULL);
748 evas_object_smart_callback_call(elmobj, "drop", drop->data);
752 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/