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 /* by default preload off by seok.j.jeong */
86 sd->preloading = EINA_FALSE;
89 evas_object_image_preload(sd->obj, EINA_FALSE);
91 evas_object_hide(sd->obj);
92 if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
94 _smart_reconfigure(sd);
99 _els_smart_icon_file_edje_set(Evas_Object *obj, const char *file, const char *part)
104 sd = evas_object_smart_data_get(obj);
105 if (!sd) return EINA_FALSE;
106 /* smart code here */
109 pclip = evas_object_clip_get(sd->obj);
110 if (sd->obj) evas_object_del(sd->obj);
111 sd->obj = edje_object_add(evas_object_evas_get(obj));
112 evas_object_smart_member_add(sd->obj, obj);
113 if (sd->show) evas_object_show(sd->obj);
114 evas_object_clip_set(sd->obj, pclip);
116 sd->edje = EINA_TRUE;
117 if (!edje_object_file_set(sd->obj, file, part))
119 _smart_reconfigure(sd);
124 _els_smart_icon_file_get(const Evas_Object *obj, const char **file, const char **key)
126 Smart_Data *sd = evas_object_smart_data_get(obj);
129 edje_object_file_get(sd->obj, file, key);
131 evas_object_image_file_get(sd->obj, file, key);
135 _els_smart_icon_smooth_scale_set(Evas_Object *obj, Eina_Bool smooth)
137 Smart_Data *sd = evas_object_smart_data_get(obj);
141 evas_object_image_smooth_scale_set(sd->obj, smooth);
145 _els_smart_icon_smooth_scale_get(const Evas_Object *obj)
147 Smart_Data *sd = evas_object_smart_data_get(obj);
148 if (!sd) return EINA_FALSE;
151 return evas_object_image_smooth_scale_get(sd->obj);
155 _els_smart_icon_object_get(const Evas_Object *obj)
157 Smart_Data *sd = evas_object_smart_data_get(obj);
158 if (!sd) return NULL;
163 _els_smart_icon_size_get(const Evas_Object *obj, int *w, int *h)
168 sd = evas_object_smart_data_get(obj);
170 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
171 edje_object_size_min_get(sd->obj, &tw, &th);
173 evas_object_image_size_get(sd->obj, &tw, &th);
174 tw = ((double)tw) * sd->scale;
175 th = ((double)th) * sd->scale;
181 _els_smart_icon_fill_inside_set(Evas_Object *obj, Eina_Bool fill_inside)
185 sd = evas_object_smart_data_get(obj);
187 if (((sd->fill_inside) && (fill_inside)) ||
188 ((!sd->fill_inside) && (!fill_inside))) return;
189 sd->fill_inside = fill_inside;
190 _smart_reconfigure(sd);
194 _els_smart_icon_fill_inside_get(const Evas_Object *obj)
196 Smart_Data *sd = evas_object_smart_data_get(obj);
197 if (!sd) return EINA_FALSE;
198 return sd->fill_inside;
202 _els_smart_icon_scale_up_set(Evas_Object *obj, Eina_Bool scale_up)
206 sd = evas_object_smart_data_get(obj);
208 if (((sd->scale_up) && (scale_up)) ||
209 ((!sd->scale_up) && (!scale_up))) return;
210 sd->scale_up = scale_up;
211 _smart_reconfigure(sd);
215 _els_smart_icon_scale_up_get(const Evas_Object *obj)
217 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
218 if (!sd) return EINA_FALSE;
223 _els_smart_icon_scale_down_set(Evas_Object *obj, Eina_Bool scale_down)
227 sd = evas_object_smart_data_get(obj);
229 if (((sd->scale_down) && (scale_down)) ||
230 ((!sd->scale_down) && (!scale_down))) return;
231 sd->scale_down = scale_down;
232 _smart_reconfigure(sd);
236 _els_smart_icon_scale_down_get(const Evas_Object *obj)
238 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
239 if (!sd) return EINA_FALSE;
244 _els_smart_icon_scale_size_set(Evas_Object *obj, int size)
248 sd = evas_object_smart_data_get(obj);
251 if (!sd->obj) return;
254 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
258 _els_smart_icon_scale_size_get(const Evas_Object *obj)
260 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
266 _els_smart_icon_scale_set(Evas_Object *obj, double scale)
268 Smart_Data *sd = evas_object_smart_data_get(obj);
271 _smart_reconfigure(sd);
275 _els_smart_icon_scale_get(const Evas_Object *obj)
277 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
283 _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
287 unsigned int *data, *data2, *to, *from;
288 int x, y, w, hw, iw, ih;
289 const char *file, *key;
291 sd = evas_object_smart_data_get(obj);
298 case ELM_IMAGE_FLIP_HORIZONTAL:
299 _els_smart_icon_flip_horizontal(sd);
301 case ELM_IMAGE_FLIP_VERTICAL:
302 _els_smart_icon_flip_vertical(sd);
304 case ELM_IMAGE_ROTATE_180_CW:
305 _els_smart_icon_rotate_180(sd);
311 evas_object_image_size_get(sd->obj, &iw, &ih);
312 evas_object_image_file_get(sd->obj, &file, &key);
313 tmp = evas_object_image_add(evas_object_evas_get(sd->obj));
314 evas_object_image_file_set(tmp, file, key);
315 data2 = evas_object_image_data_get(tmp, EINA_FALSE);
322 evas_object_image_size_set(sd->obj, iw, ih);
323 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
326 case ELM_IMAGE_FLIP_TRANSPOSE:
330 case ELM_IMAGE_FLIP_TRANSVERSE:
335 case ELM_IMAGE_ROTATE_90_CW:
339 case ELM_IMAGE_ROTATE_90_CCW:
345 ERR("unknown orient %d", orient);
346 evas_object_del(tmp);
347 evas_object_image_data_set(sd->obj, data); // give it back
351 for (x = iw; --x >= 0;)
353 for (y = ih; --y >= 0;)
362 evas_object_del(tmp);
363 evas_object_image_data_set(sd->obj, data);
364 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
365 _smart_reconfigure(sd);
369 _els_smart_icon_orient_get(const Evas_Object *obj)
371 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
377 * Turns on editing through drag and drop and copy and paste.
380 _els_smart_icon_edit_set(Evas_Object *obj, Eina_Bool edit, Evas_Object *parent)
382 Smart_Data *sd = evas_object_smart_data_get(obj);
387 printf("No editing edje objects yet (ever)\n");
391 /* Unfortunately eina bool is not a bool, but a char */
392 if (edit == sd->edit) return;
397 elm_drop_target_add(obj, ELM_SEL_FORMAT_IMAGE, _els_smart_icon_dropcb,
400 elm_drop_target_del(obj);
404 _els_smart_icon_edit_get(const Evas_Object *obj)
406 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
407 if (!sd) return EINA_FALSE;
412 _els_smart_icon_edje_get(Evas_Object *obj)
414 Smart_Data *sd = evas_object_smart_data_get(obj);
415 if (!sd) return NULL;
416 if (!sd->edje) return NULL;
420 /* local subsystem globals */
422 _smart_reconfigure(Smart_Data *sd)
424 Evas_Coord x, y, w, h;
426 if (!sd->obj) return;
427 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
433 evas_object_move(sd->obj, x, y);
434 evas_object_resize(sd->obj, w, h);
440 evas_object_image_size_get(sd->obj, &iw, &ih);
442 iw = ((double)iw) * sd->scale;
443 ih = ((double)ih) * sd->scale;
451 h = ((double)ih * w) / (double)iw;
455 w = ((double)iw * h) / (double)ih;
461 h = ((double)ih * w) / (double)iw;
465 w = ((double)iw * h) / (double)ih;
470 if ((w > iw) || (h > ih))
478 if ((w < iw) || (h < ih))
484 x = sd->x + ((sd->w - w) / 2);
485 y = sd->y + ((sd->h - h) / 2);
486 evas_object_move(sd->obj, x, y);
487 evas_object_image_fill_set(sd->obj, 0, 0, w, h);
488 evas_object_resize(sd->obj, w, h);
495 if (_e_smart) return;
497 static const Evas_Smart_Class sc =
500 EVAS_SMART_CLASS_VERSION,
518 _e_smart = evas_smart_class_new(&sc);
523 _smart_add(Evas_Object *obj)
527 sd = calloc(1, sizeof(Smart_Data));
529 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
530 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
535 sd->fill_inside = EINA_TRUE;
536 sd->scale_up = EINA_TRUE;
537 sd->scale_down = EINA_TRUE;
540 evas_object_smart_member_add(sd->obj, obj);
541 evas_object_smart_data_set(obj, sd);
542 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
547 _smart_del(Evas_Object *obj)
551 sd = evas_object_smart_data_get(obj);
553 evas_object_del(sd->obj);
558 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
562 sd = evas_object_smart_data_get(obj);
564 if ((sd->x == x) && (sd->y == y)) return;
567 _smart_reconfigure(sd);
571 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
575 sd = evas_object_smart_data_get(obj);
577 if ((sd->w == w) && (sd->h == h)) return;
580 _smart_reconfigure(sd);
584 _smart_show(Evas_Object *obj)
588 sd = evas_object_smart_data_get(obj);
590 sd->show = EINA_TRUE;
592 evas_object_show(sd->obj);
596 _smart_hide(Evas_Object *obj)
600 sd = evas_object_smart_data_get(obj);
602 sd->show = EINA_FALSE;
603 evas_object_hide(sd->obj);
607 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
611 sd = evas_object_smart_data_get(obj);
613 evas_object_color_set(sd->obj, r, g, b, a);
617 _smart_clip_set(Evas_Object *obj, Evas_Object * clip)
621 sd = evas_object_smart_data_get(obj);
623 evas_object_clip_set(sd->obj, clip);
627 _smart_clip_unset(Evas_Object *obj)
631 sd = evas_object_smart_data_get(obj);
633 evas_object_clip_unset(sd->obj);
637 _els_smart_icon_flip_horizontal(Smart_Data *sd)
640 unsigned int *p1, *p2, tmp;
643 evas_object_image_size_get(sd->obj, &iw, &ih);
644 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
646 for (y = 0; y < ih; y++)
648 p1 = data + (y * iw);
649 p2 = data + ((y + 1) * iw) - 1;
650 for (x = 0; x < (iw >> 1); x++)
660 evas_object_image_data_set(sd->obj, data);
661 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
662 _smart_reconfigure(sd);
666 _els_smart_icon_flip_vertical(Smart_Data *sd)
669 unsigned int *p1, *p2, tmp;
672 evas_object_image_size_get(sd->obj, &iw, &ih);
673 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
675 for (y = 0; y < (ih >> 1); y++)
677 p1 = data + (y * iw);
678 p2 = data + ((ih - 1 - y) * iw);
679 for (x = 0; x < iw; x++)
689 evas_object_image_data_set(sd->obj, data);
690 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
691 _smart_reconfigure(sd);
695 _els_smart_icon_rotate_180(Smart_Data *sd)
698 unsigned int *p1, *p2, tmp;
701 evas_object_image_size_get(sd->obj, &iw, &ih);
702 data = evas_object_image_data_get(sd->obj, 1);
716 evas_object_image_data_set(sd->obj, data);
717 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
718 _smart_reconfigure(sd);
722 _els_smart_icon_dropcb(void *elmobj,Evas_Object *obj, Elm_Selection_Data *drop)
724 _els_smart_icon_file_key_set(obj, drop->data, NULL);
725 evas_object_smart_callback_call(elmobj, "drop", drop->data);
729 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/