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 Elm_Image_Orient orient;
22 /* local subsystem functions */
23 static void _smart_reconfigure(Smart_Data *sd);
24 static void _smart_init(void);
25 static void _smart_add(Evas_Object *obj);
26 static void _smart_del(Evas_Object *obj);
27 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
28 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
29 static void _smart_show(Evas_Object *obj);
30 static void _smart_hide(Evas_Object *obj);
31 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
32 static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
33 static void _smart_clip_unset(Evas_Object *obj);
35 static void _els_smart_icon_flip_horizontal(Smart_Data *sd);
36 static void _els_smart_icon_flip_vertical(Smart_Data *sd);
37 static void _els_smart_icon_rotate_180(Smart_Data *sd);
38 static Eina_Bool _els_smart_icon_dropcb(void *,Evas_Object *, Elm_Selection_Data *);
40 /* local subsystem globals */
41 static Evas_Smart *_e_smart = NULL;
43 /* externally accessible functions */
45 _els_smart_icon_add(Evas *evas)
48 return evas_object_smart_add(evas, _e_smart);
52 _preloaded(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
54 Smart_Data *sd = data;
56 sd->preloading = EINA_FALSE;
58 evas_object_show(sd->obj);
62 _els_smart_icon_file_key_set(Evas_Object *obj, const char *file, const char *key)
67 sd = evas_object_smart_data_get(obj);
68 if (!sd) return EINA_FALSE;
72 pclip = evas_object_clip_get(sd->obj);
73 if (sd->obj) evas_object_del(sd->obj);
74 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
75 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
76 evas_object_smart_member_add(sd->obj, obj);
77 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
79 evas_object_clip_set(sd->obj, pclip);
80 sd->edje = EINA_FALSE;
83 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
84 evas_object_image_file_set(sd->obj, file, key);
85 sd->preloading = EINA_TRUE;
87 evas_object_hide(sd->obj);
88 evas_object_image_preload(sd->obj, EINA_FALSE);
89 if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
91 _smart_reconfigure(sd);
96 _els_smart_icon_file_edje_set(Evas_Object *obj, const char *file, const char *part)
101 sd = evas_object_smart_data_get(obj);
102 if (!sd) return EINA_FALSE;
103 /* smart code here */
106 pclip = evas_object_clip_get(sd->obj);
107 if (sd->obj) evas_object_del(sd->obj);
108 sd->obj = edje_object_add(evas_object_evas_get(obj));
109 evas_object_smart_member_add(sd->obj, obj);
110 if (sd->show) evas_object_show(sd->obj);
111 evas_object_clip_set(sd->obj, pclip);
113 sd->edje = EINA_TRUE;
114 if (!edje_object_file_set(sd->obj, file, part))
116 _smart_reconfigure(sd);
121 _els_smart_icon_file_get(const Evas_Object *obj, const char **file, const char **key)
123 Smart_Data *sd = evas_object_smart_data_get(obj);
126 edje_object_file_get(sd->obj, file, key);
128 evas_object_image_file_get(sd->obj, file, key);
132 _els_smart_icon_smooth_scale_set(Evas_Object *obj, Eina_Bool smooth)
134 Smart_Data *sd = evas_object_smart_data_get(obj);
138 evas_object_image_smooth_scale_set(sd->obj, smooth);
142 _els_smart_icon_smooth_scale_get(const Evas_Object *obj)
144 Smart_Data *sd = evas_object_smart_data_get(obj);
145 if (!sd) return EINA_FALSE;
148 return evas_object_image_smooth_scale_get(sd->obj);
152 _els_smart_icon_object_get(const Evas_Object *obj)
154 Smart_Data *sd = evas_object_smart_data_get(obj);
155 if (!sd) return NULL;
160 _els_smart_icon_size_get(const Evas_Object *obj, int *w, int *h)
165 sd = evas_object_smart_data_get(obj);
167 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
168 edje_object_size_min_get(sd->obj, &tw, &th);
170 evas_object_image_size_get(sd->obj, &tw, &th);
171 tw = ((double)tw) * sd->scale;
172 th = ((double)th) * sd->scale;
178 _els_smart_icon_fill_inside_set(Evas_Object *obj, Eina_Bool fill_inside)
182 sd = evas_object_smart_data_get(obj);
184 if (((sd->fill_inside) && (fill_inside)) ||
185 ((!sd->fill_inside) && (!fill_inside))) return;
186 sd->fill_inside = fill_inside;
187 _smart_reconfigure(sd);
191 _els_smart_icon_fill_inside_get(const Evas_Object *obj)
193 Smart_Data *sd = evas_object_smart_data_get(obj);
194 if (!sd) return EINA_FALSE;
195 return sd->fill_inside;
199 _els_smart_icon_scale_up_set(Evas_Object *obj, Eina_Bool scale_up)
203 sd = evas_object_smart_data_get(obj);
205 if (((sd->scale_up) && (scale_up)) ||
206 ((!sd->scale_up) && (!scale_up))) return;
207 sd->scale_up = scale_up;
208 _smart_reconfigure(sd);
212 _els_smart_icon_scale_up_get(const Evas_Object *obj)
214 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
215 if (!sd) return EINA_FALSE;
220 _els_smart_icon_scale_down_set(Evas_Object *obj, Eina_Bool scale_down)
224 sd = evas_object_smart_data_get(obj);
226 if (((sd->scale_down) && (scale_down)) ||
227 ((!sd->scale_down) && (!scale_down))) return;
228 sd->scale_down = scale_down;
229 _smart_reconfigure(sd);
233 _els_smart_icon_scale_down_get(const Evas_Object *obj)
235 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
236 if (!sd) return EINA_FALSE;
241 _els_smart_icon_scale_size_set(Evas_Object *obj, int size)
245 sd = evas_object_smart_data_get(obj);
248 if (!sd->obj) return;
251 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
255 _els_smart_icon_scale_size_get(const Evas_Object *obj)
257 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
263 _els_smart_icon_scale_set(Evas_Object *obj, double scale)
265 Smart_Data *sd = evas_object_smart_data_get(obj);
268 _smart_reconfigure(sd);
272 _els_smart_icon_scale_get(const Evas_Object *obj)
274 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
280 _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
284 unsigned int *data, *data2, *to, *from;
285 int x, y, w, hw, iw, ih;
286 const char *file, *key;
288 sd = evas_object_smart_data_get(obj);
295 case ELM_IMAGE_FLIP_HORIZONTAL:
296 _els_smart_icon_flip_horizontal(sd);
298 case ELM_IMAGE_FLIP_VERTICAL:
299 _els_smart_icon_flip_vertical(sd);
301 case ELM_IMAGE_ROTATE_180_CW:
302 _els_smart_icon_rotate_180(sd);
308 evas_object_image_size_get(sd->obj, &iw, &ih);
309 evas_object_image_file_get(sd->obj, &file, &key);
310 tmp = evas_object_image_add(evas_object_evas_get(sd->obj));
311 evas_object_image_file_set(tmp, file, key);
312 data2 = evas_object_image_data_get(tmp, EINA_FALSE);
319 evas_object_image_size_set(sd->obj, iw, ih);
320 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
323 case ELM_IMAGE_FLIP_TRANSPOSE:
327 case ELM_IMAGE_FLIP_TRANSVERSE:
332 case ELM_IMAGE_ROTATE_90_CW:
336 case ELM_IMAGE_ROTATE_90_CCW:
342 ERR("unknown orient %d", orient);
343 evas_object_del(tmp);
344 evas_object_image_data_set(sd->obj, data); // give it back
348 for (x = iw; --x >= 0;)
350 for (y = ih; --y >= 0;)
359 evas_object_del(tmp);
360 evas_object_image_data_set(sd->obj, data);
361 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
362 _smart_reconfigure(sd);
366 _els_smart_icon_orient_get(const Evas_Object *obj)
368 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
374 * Turns on editing through drag and drop and copy and paste.
377 _els_smart_icon_edit_set(Evas_Object *obj, Eina_Bool edit, Evas_Object *parent)
379 Smart_Data *sd = evas_object_smart_data_get(obj);
384 printf("No editing edje objects yet (ever)\n");
388 /* Unfortunately eina bool is not a bool, but a char */
389 if (edit == sd->edit) return;
394 elm_drop_target_add(obj, ELM_SEL_FORMAT_IMAGE, _els_smart_icon_dropcb,
397 elm_drop_target_del(obj);
401 _els_smart_icon_edit_get(const Evas_Object *obj)
403 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
404 if (!sd) return EINA_FALSE;
409 _els_smart_icon_edje_get(Evas_Object *obj)
411 Smart_Data *sd = evas_object_smart_data_get(obj);
412 if (!sd) return NULL;
413 if (!sd->edje) return NULL;
417 /* local subsystem globals */
419 _smart_reconfigure(Smart_Data *sd)
421 Evas_Coord x, y, w, h;
423 if (!sd->obj) return;
424 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
430 evas_object_move(sd->obj, x, y);
431 evas_object_resize(sd->obj, w, h);
437 evas_object_image_size_get(sd->obj, &iw, &ih);
439 iw = ((double)iw) * sd->scale;
440 ih = ((double)ih) * sd->scale;
448 h = ((double)ih * w) / (double)iw;
452 w = ((double)iw * h) / (double)ih;
458 h = ((double)ih * w) / (double)iw;
462 w = ((double)iw * h) / (double)ih;
467 if ((w > iw) || (h > ih))
475 if ((w < iw) || (h < ih))
481 x = sd->x + ((sd->w - w) / 2);
482 y = sd->y + ((sd->h - h) / 2);
483 evas_object_move(sd->obj, x, y);
484 evas_object_image_fill_set(sd->obj, 0, 0, w, h);
485 evas_object_resize(sd->obj, w, h);
492 if (_e_smart) return;
494 static const Evas_Smart_Class sc =
497 EVAS_SMART_CLASS_VERSION,
515 _e_smart = evas_smart_class_new(&sc);
520 _smart_add(Evas_Object *obj)
524 sd = calloc(1, sizeof(Smart_Data));
526 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
527 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
532 sd->fill_inside = EINA_TRUE;
533 sd->scale_up = EINA_TRUE;
534 sd->scale_down = EINA_TRUE;
537 evas_object_smart_member_add(sd->obj, obj);
538 evas_object_smart_data_set(obj, sd);
539 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
544 _smart_del(Evas_Object *obj)
548 sd = evas_object_smart_data_get(obj);
550 evas_object_del(sd->obj);
555 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
559 sd = evas_object_smart_data_get(obj);
561 if ((sd->x == x) && (sd->y == y)) return;
564 _smart_reconfigure(sd);
568 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
572 sd = evas_object_smart_data_get(obj);
574 if ((sd->w == w) && (sd->h == h)) return;
577 _smart_reconfigure(sd);
581 _smart_show(Evas_Object *obj)
585 sd = evas_object_smart_data_get(obj);
587 sd->show = EINA_TRUE;
589 evas_object_show(sd->obj);
593 _smart_hide(Evas_Object *obj)
597 sd = evas_object_smart_data_get(obj);
599 sd->show = EINA_FALSE;
600 evas_object_hide(sd->obj);
604 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
608 sd = evas_object_smart_data_get(obj);
610 evas_object_color_set(sd->obj, r, g, b, a);
614 _smart_clip_set(Evas_Object *obj, Evas_Object * clip)
618 sd = evas_object_smart_data_get(obj);
620 evas_object_clip_set(sd->obj, clip);
624 _smart_clip_unset(Evas_Object *obj)
628 sd = evas_object_smart_data_get(obj);
630 evas_object_clip_unset(sd->obj);
634 _els_smart_icon_flip_horizontal(Smart_Data *sd)
637 unsigned int *p1, *p2, tmp;
640 evas_object_image_size_get(sd->obj, &iw, &ih);
641 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
643 for (y = 0; y < ih; y++)
645 p1 = data + (y * iw);
646 p2 = data + ((y + 1) * iw) - 1;
647 for (x = 0; x < (iw >> 1); x++)
657 evas_object_image_data_set(sd->obj, data);
658 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
659 _smart_reconfigure(sd);
663 _els_smart_icon_flip_vertical(Smart_Data *sd)
666 unsigned int *p1, *p2, tmp;
669 evas_object_image_size_get(sd->obj, &iw, &ih);
670 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
672 for (y = 0; y < (ih >> 1); y++)
674 p1 = data + (y * iw);
675 p2 = data + ((ih - 1 - y) * iw);
676 for (x = 0; x < iw; x++)
686 evas_object_image_data_set(sd->obj, data);
687 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
688 _smart_reconfigure(sd);
692 _els_smart_icon_rotate_180(Smart_Data *sd)
695 unsigned int *p1, *p2, tmp;
698 evas_object_image_size_get(sd->obj, &iw, &ih);
699 data = evas_object_image_data_get(sd->obj, 1);
713 evas_object_image_data_set(sd->obj, data);
714 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
715 _smart_reconfigure(sd);
719 _els_smart_icon_dropcb(void *elmobj,Evas_Object *obj, Elm_Selection_Data *drop)
721 _els_smart_icon_file_key_set(obj, drop->data, NULL);
722 evas_object_smart_callback_call(elmobj, "drop", drop->data);
726 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/