1 #include <Elementary.h>
4 typedef struct _Smart_Data Smart_Data;
13 Eina_Bool fill_inside : 1;
14 Eina_Bool scale_up : 1;
15 Eina_Bool scale_down : 1;
16 Eina_Bool preloading : 1;
20 Eina_Bool aspect_ratio_retained: 1;
21 Elm_Image_Orient orient;
24 /* local subsystem functions */
25 static void _smart_reconfigure(Smart_Data *sd);
26 static void _smart_init(void);
27 static void _smart_add(Evas_Object *obj);
28 static void _smart_del(Evas_Object *obj);
29 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
30 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
31 static void _smart_show(Evas_Object *obj);
32 static void _smart_hide(Evas_Object *obj);
33 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
34 static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
35 static void _smart_clip_unset(Evas_Object *obj);
37 static void _els_smart_icon_flip_horizontal(Smart_Data *sd);
38 static void _els_smart_icon_flip_vertical(Smart_Data *sd);
39 static void _els_smart_icon_rotate_180(Smart_Data *sd);
40 static Eina_Bool _els_smart_icon_dropcb(void *,Evas_Object *, Elm_Selection_Data *);
42 /* local subsystem globals */
43 static Evas_Smart *_e_smart = NULL;
45 /* externally accessible functions */
47 _els_smart_icon_add(Evas *evas)
50 return evas_object_smart_add(evas, _e_smart);
54 _preloaded(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
56 Smart_Data *sd = data;
58 sd->preloading = EINA_FALSE;
62 evas_object_show(sd->obj);
64 if (sd->prev) evas_object_del(sd->prev);
69 _els_smart_icon_file_key_set(Evas_Object *obj, const char *file, const char *key)
74 sd = evas_object_smart_data_get(obj);
75 if (!sd) return EINA_FALSE;
77 if (sd->prev) evas_object_del(sd->prev);
78 pclip = evas_object_clip_get(sd->obj);
79 if (sd->obj) sd->prev = sd->obj;
80 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
81 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
83 evas_object_smart_member_add(sd->obj, obj);
84 if (sd->prev) evas_object_smart_member_add(sd->prev, obj);
85 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
86 evas_object_clip_set(sd->obj, pclip);
88 sd->edje = EINA_FALSE;
91 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
92 evas_object_image_file_set(sd->obj, file, key);
93 // NOTE: Do not merge upstream for sd->preloading.
94 sd->preloading = EINA_FALSE; // by default preload off by seok.j.jeong
96 // NOTE: Do not merge upstream for sd->preloading.
98 evas_object_image_preload(sd->obj, EINA_FALSE);
99 // NOTE: Do not merge upstream for sd->preloading.
100 if (sd->preloading) // sd->preloading can be changed by above function. so add "if (sd->preloading)" as below
101 evas_object_hide(sd->obj);
102 if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
104 ERR("Things are going bad for '%s' (%p)", file, sd->obj);
107 _smart_reconfigure(sd);
112 _els_smart_icon_file_edje_set(Evas_Object *obj, const char *file, const char *part)
117 sd = evas_object_smart_data_get(obj);
118 if (!sd) return EINA_FALSE;
119 /* smart code here */
120 if (sd->prev) evas_object_del(sd->prev);
125 pclip = evas_object_clip_get(sd->obj);
126 if (sd->obj) evas_object_del(sd->obj);
127 sd->obj = edje_object_add(evas_object_evas_get(obj));
128 evas_object_smart_member_add(sd->obj, obj);
129 if (sd->show) evas_object_show(sd->obj);
130 evas_object_clip_set(sd->obj, pclip);
132 sd->edje = EINA_TRUE;
133 if (!edje_object_file_set(sd->obj, file, part))
135 _smart_reconfigure(sd);
140 _els_smart_icon_file_get(const Evas_Object *obj, const char **file, const char **key)
142 Smart_Data *sd = evas_object_smart_data_get(obj);
145 edje_object_file_get(sd->obj, file, key);
147 evas_object_image_file_get(sd->obj, file, key);
151 _els_smart_icon_smooth_scale_set(Evas_Object *obj, Eina_Bool smooth)
153 Smart_Data *sd = evas_object_smart_data_get(obj);
157 evas_object_image_smooth_scale_set(sd->obj, smooth);
161 _els_smart_icon_smooth_scale_get(const Evas_Object *obj)
163 Smart_Data *sd = evas_object_smart_data_get(obj);
164 if (!sd) return EINA_FALSE;
167 return evas_object_image_smooth_scale_get(sd->obj);
171 _els_smart_icon_object_get(const Evas_Object *obj)
173 Smart_Data *sd = evas_object_smart_data_get(obj);
174 if (!sd) return NULL;
179 _els_smart_icon_size_get(const Evas_Object *obj, int *w, int *h)
185 sd = evas_object_smart_data_get(obj);
187 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
188 edje_object_size_min_get(sd->obj, &tw, &th);
190 evas_object_image_size_get(sd->obj, &tw, &th);
191 evas_object_geometry_get(sd->obj, NULL, NULL, &cw, &ch);
192 tw = tw > cw ? tw : cw;
193 th = th > ch ? th : ch;
194 tw = ((double)tw) * sd->scale;
195 th = ((double)th) * sd->scale;
201 _els_smart_icon_fill_inside_set(Evas_Object *obj, Eina_Bool fill_inside)
205 sd = evas_object_smart_data_get(obj);
207 if (((sd->fill_inside) && (fill_inside)) ||
208 ((!sd->fill_inside) && (!fill_inside))) return;
209 sd->fill_inside = fill_inside;
210 _smart_reconfigure(sd);
214 _els_smart_icon_fill_inside_get(const Evas_Object *obj)
216 Smart_Data *sd = evas_object_smart_data_get(obj);
217 if (!sd) return EINA_FALSE;
218 return sd->fill_inside;
222 _els_smart_icon_scale_up_set(Evas_Object *obj, Eina_Bool scale_up)
226 sd = evas_object_smart_data_get(obj);
228 if (((sd->scale_up) && (scale_up)) ||
229 ((!sd->scale_up) && (!scale_up))) return;
230 sd->scale_up = scale_up;
231 _smart_reconfigure(sd);
235 _els_smart_icon_scale_up_get(const Evas_Object *obj)
237 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
238 if (!sd) return EINA_FALSE;
243 _els_smart_icon_scale_down_set(Evas_Object *obj, Eina_Bool scale_down)
247 sd = evas_object_smart_data_get(obj);
249 if (((sd->scale_down) && (scale_down)) ||
250 ((!sd->scale_down) && (!scale_down))) return;
251 sd->scale_down = scale_down;
252 _smart_reconfigure(sd);
256 _els_smart_icon_scale_down_get(const Evas_Object *obj)
258 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
259 if (!sd) return EINA_FALSE;
264 _els_smart_icon_scale_size_set(Evas_Object *obj, int size)
268 sd = evas_object_smart_data_get(obj);
271 if (!sd->obj) return;
274 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
278 _els_smart_icon_scale_size_get(const Evas_Object *obj)
280 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
286 _els_smart_icon_scale_set(Evas_Object *obj, double scale)
288 Smart_Data *sd = evas_object_smart_data_get(obj);
291 _smart_reconfigure(sd);
295 _els_smart_icon_scale_get(const Evas_Object *obj)
297 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
303 _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
307 unsigned int *data, *data2, *to, *from;
308 int x, y, w, hw, iw, ih;
309 const char *file, *key;
311 sd = evas_object_smart_data_get(obj);
318 case ELM_IMAGE_FLIP_HORIZONTAL:
319 _els_smart_icon_flip_horizontal(sd);
321 case ELM_IMAGE_FLIP_VERTICAL:
322 _els_smart_icon_flip_vertical(sd);
324 case ELM_IMAGE_ROTATE_180_CW:
325 _els_smart_icon_rotate_180(sd);
331 evas_object_image_size_get(sd->obj, &iw, &ih);
332 evas_object_image_file_get(sd->obj, &file, &key);
333 tmp = evas_object_image_add(evas_object_evas_get(sd->obj));
334 evas_object_image_file_set(tmp, file, key);
335 data2 = evas_object_image_data_get(tmp, EINA_FALSE);
342 evas_object_image_size_set(sd->obj, iw, ih);
343 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
346 case ELM_IMAGE_FLIP_TRANSPOSE:
350 case ELM_IMAGE_FLIP_TRANSVERSE:
355 case ELM_IMAGE_ROTATE_90_CW:
359 case ELM_IMAGE_ROTATE_90_CCW:
365 ERR("unknown orient %d", orient);
366 evas_object_del(tmp);
367 evas_object_image_data_set(sd->obj, data); // give it back
371 for (x = iw; --x >= 0;)
373 for (y = ih; --y >= 0;)
382 evas_object_del(tmp);
383 evas_object_image_data_set(sd->obj, data);
384 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
385 _smart_reconfigure(sd);
389 _els_smart_icon_orient_get(const Evas_Object *obj)
391 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
397 * Turns on editing through drag and drop and copy and paste.
400 _els_smart_icon_edit_set(Evas_Object *obj, Eina_Bool edit, Evas_Object *parent)
402 Smart_Data *sd = evas_object_smart_data_get(obj);
407 printf("No editing edje objects yet (ever)\n");
411 /* Unfortunately eina bool is not a bool, but a char */
412 if (edit == sd->edit) return;
417 elm_drop_target_add(obj, ELM_SEL_FORMAT_IMAGE, _els_smart_icon_dropcb,
420 elm_drop_target_del(obj);
424 _els_smart_icon_edit_get(const Evas_Object *obj)
426 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
427 if (!sd) return EINA_FALSE;
432 _els_smart_icon_edje_get(Evas_Object *obj)
434 Smart_Data *sd = evas_object_smart_data_get(obj);
435 if (!sd) return NULL;
436 if (!sd->edje) return NULL;
441 _els_smart_icon_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained)
445 sd = evas_object_smart_data_get(obj);
448 retained = !!retained;
449 if (sd->aspect_ratio_retained == retained) return;
450 sd->aspect_ratio_retained = retained;
451 _smart_reconfigure(sd);
455 _els_smart_icon_aspect_ratio_retained_get(const Evas_Object *obj)
459 sd = evas_object_smart_data_get(obj);
460 if (!sd) return EINA_FALSE;
461 return sd->aspect_ratio_retained;
464 /* local subsystem globals */
466 _smart_reconfigure(Smart_Data *sd)
468 Evas_Coord x, y, w, h;
470 if (!sd->obj) return;
475 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
479 evas_object_move(sd->obj, x, y);
480 evas_object_resize(sd->obj, w, h);
486 evas_object_image_size_get(sd->obj, &iw, &ih);
488 iw = ((double)iw) * sd->scale;
489 ih = ((double)ih) * sd->scale;
494 if (sd->aspect_ratio_retained)
496 h = ((double)ih * w) / (double)iw;
502 w = ((double)iw * h) / (double)ih;
510 w = ((double)iw * h) / (double)ih;
524 x = sd->x + ((sd->w - w) / 2);
525 y = sd->y + ((sd->h - h) / 2);
526 evas_object_move(sd->obj, x, y);
527 evas_object_image_fill_set(sd->obj, 0, 0, w, h);
528 evas_object_resize(sd->obj, w, h);
535 if (_e_smart) return;
537 static const Evas_Smart_Class sc =
540 EVAS_SMART_CLASS_VERSION,
558 _e_smart = evas_smart_class_new(&sc);
563 _smart_add(Evas_Object *obj)
567 sd = calloc(1, sizeof(Smart_Data));
569 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
571 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
576 sd->fill_inside = EINA_TRUE;
577 sd->scale_up = EINA_TRUE;
578 sd->scale_down = EINA_TRUE;
579 sd->aspect_ratio_retained = EINA_TRUE;
582 evas_object_smart_member_add(sd->obj, obj);
583 evas_object_smart_data_set(obj, sd);
584 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
589 _smart_del(Evas_Object *obj)
593 sd = evas_object_smart_data_get(obj);
595 evas_object_del(sd->obj);
596 if (sd->prev) evas_object_del(sd->prev);
601 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
605 sd = evas_object_smart_data_get(obj);
607 if ((sd->x == x) && (sd->y == y)) return;
610 _smart_reconfigure(sd);
614 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
618 sd = evas_object_smart_data_get(obj);
620 if ((sd->w == w) && (sd->h == h)) return;
623 _smart_reconfigure(sd);
627 _smart_show(Evas_Object *obj)
631 sd = evas_object_smart_data_get(obj);
633 sd->show = EINA_TRUE;
636 evas_object_show(sd->obj);
637 if (sd->prev) evas_object_del(sd->prev);
643 _smart_hide(Evas_Object *obj)
647 sd = evas_object_smart_data_get(obj);
649 sd->show = EINA_FALSE;
650 evas_object_hide(sd->obj);
651 if (sd->prev) evas_object_del(sd->prev);
656 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
660 sd = evas_object_smart_data_get(obj);
662 evas_object_color_set(sd->obj, r, g, b, a);
663 if (sd->prev) evas_object_color_set(sd->prev, r, g, b, a);
667 _smart_clip_set(Evas_Object *obj, Evas_Object * clip)
671 sd = evas_object_smart_data_get(obj);
673 evas_object_clip_set(sd->obj, clip);
674 if (sd->prev) evas_object_clip_set(sd->prev, clip);
678 _smart_clip_unset(Evas_Object *obj)
682 sd = evas_object_smart_data_get(obj);
684 evas_object_clip_unset(sd->obj);
685 if (sd->prev) evas_object_clip_unset(sd->prev);
689 _els_smart_icon_flip_horizontal(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; y++)
700 p1 = data + (y * iw);
701 p2 = data + ((y + 1) * iw) - 1;
702 for (x = 0; x < (iw >> 1); 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_flip_vertical(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, EINA_TRUE);
727 for (y = 0; y < (ih >> 1); y++)
729 p1 = data + (y * iw);
730 p2 = data + ((ih - 1 - y) * iw);
731 for (x = 0; x < iw; x++)
741 evas_object_image_data_set(sd->obj, data);
742 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
743 _smart_reconfigure(sd);
747 _els_smart_icon_rotate_180(Smart_Data *sd)
750 unsigned int *p1, *p2, tmp;
753 evas_object_image_size_get(sd->obj, &iw, &ih);
754 data = evas_object_image_data_get(sd->obj, 1);
768 evas_object_image_data_set(sd->obj, data);
769 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
770 _smart_reconfigure(sd);
774 _els_smart_icon_dropcb(void *elmobj,Evas_Object *obj, Elm_Selection_Data *drop)
776 _els_smart_icon_file_key_set(obj, drop->data, NULL);
777 evas_object_smart_callback_call(elmobj, "drop", drop->data);
781 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/