1 #include <Elementary.h>
4 typedef struct _Smart_Data Smart_Data;
12 unsigned char fill_inside : 1;
13 unsigned char scale_up : 1;
14 unsigned char scale_down : 1;
15 unsigned char preloading : 1;
16 unsigned char show : 1;
19 /* local subsystem functions */
20 static void _smart_reconfigure(Smart_Data *sd);
21 static void _smart_init(void);
22 static void _smart_add(Evas_Object *obj);
23 static void _smart_del(Evas_Object *obj);
24 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
25 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
26 static void _smart_show(Evas_Object *obj);
27 static void _smart_hide(Evas_Object *obj);
28 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
29 static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
30 static void _smart_clip_unset(Evas_Object *obj);
32 static void _els_smart_icon_flip_horizontal(Smart_Data *sd);
33 static void _els_smart_icon_flip_vertical(Smart_Data *sd);
34 static void _els_smart_icon_rotate_180(Smart_Data *sd);
36 /* local subsystem globals */
37 static Evas_Smart *_e_smart = NULL;
39 /* externally accessible functions */
41 _els_smart_icon_add(Evas *evas)
44 return evas_object_smart_add(evas, _e_smart);
48 _els_smart_icon_file_key_set(Evas_Object *obj, const char *file, const char *key)
52 sd = evas_object_smart_data_get(obj);
53 if (!sd) return EINA_FALSE;
56 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
57 evas_object_image_file_set(sd->obj, file, key);
59 evas_object_image_preload(sd->obj, EINA_FALSE);
60 evas_object_hide(sd->obj);
61 if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
63 _smart_reconfigure(sd);
68 _els_smart_icon_file_edje_set(Evas_Object *obj, const char *file, const char *part)
72 sd = evas_object_smart_data_get(obj);
73 if (!sd) return EINA_FALSE;
75 if (sd->obj) evas_object_del(sd->obj);
76 sd->obj = edje_object_add(evas_object_evas_get(obj));
77 evas_object_smart_member_add(sd->obj, obj);
78 if (!edje_object_file_set(sd->obj, file, part))
80 _smart_reconfigure(sd);
85 _els_smart_icon_smooth_scale_set(Evas_Object *obj, int smooth)
89 sd = evas_object_smart_data_get(obj);
91 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
93 evas_object_image_smooth_scale_set(sd->obj, smooth);
97 _els_smart_icon_object_get(Evas_Object *obj)
100 sd = evas_object_smart_data_get(obj);
101 if (!sd) return NULL;
106 _els_smart_icon_size_get(Evas_Object *obj, int *w, int *h)
111 sd = evas_object_smart_data_get(obj);
113 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
114 edje_object_size_min_get(sd->obj, &tw, &th);
116 evas_object_image_size_get(sd->obj, &tw, &th);
117 tw = ((double)tw) * sd->scale;
118 th = ((double)th) * sd->scale;
124 _els_smart_icon_fill_inside_set(Evas_Object *obj, int fill_inside)
128 sd = evas_object_smart_data_get(obj);
130 if (((sd->fill_inside) && (fill_inside)) ||
131 ((!sd->fill_inside) && (!fill_inside))) return;
132 sd->fill_inside = fill_inside;
133 _smart_reconfigure(sd);
137 _els_smart_icon_scale_up_set(Evas_Object *obj, int scale_up)
141 sd = evas_object_smart_data_get(obj);
143 if (((sd->scale_up) && (scale_up)) ||
144 ((!sd->scale_up) && (!scale_up))) return;
145 sd->scale_up = scale_up;
146 _smart_reconfigure(sd);
150 _els_smart_icon_scale_down_set(Evas_Object *obj, int scale_down)
154 sd = evas_object_smart_data_get(obj);
156 if (((sd->scale_down) && (scale_down)) ||
157 ((!sd->scale_down) && (!scale_down))) return;
158 sd->scale_down = scale_down;
159 _smart_reconfigure(sd);
163 _els_smart_icon_scale_size_set(Evas_Object *obj, int size)
167 sd = evas_object_smart_data_get(obj);
170 if (!sd->obj) return;
171 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
173 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
177 _els_smart_icon_scale_set(Evas_Object *obj, double scale)
181 sd = evas_object_smart_data_get(obj);
184 _smart_reconfigure(sd);
188 _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
192 unsigned int *data, *data2, *to, *from;
193 int x, y, w, hw, iw, ih;
194 const char *file, *key;
196 sd = evas_object_smart_data_get(obj);
198 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
203 case ELM_IMAGE_FLIP_HORIZONTAL:
204 _els_smart_icon_flip_horizontal(sd);
206 case ELM_IMAGE_FLIP_VERTICAL:
207 _els_smart_icon_flip_vertical(sd);
209 case ELM_IMAGE_ROTATE_180_CW:
210 _els_smart_icon_rotate_180(sd);
216 evas_object_image_size_get(sd->obj, &iw, &ih);
217 evas_object_image_file_get(sd->obj, &file, &key);
218 tmp = evas_object_image_add(evas_object_evas_get(sd->obj));
219 evas_object_image_file_set(tmp, file, key);
220 data2 = evas_object_image_data_get(tmp, 0);
227 evas_object_image_size_set(sd->obj, iw, ih);
228 data = evas_object_image_data_get(sd->obj, 1);
231 case ELM_IMAGE_FLIP_TRANSPOSE:
235 case ELM_IMAGE_FLIP_TRANSVERSE:
240 case ELM_IMAGE_ROTATE_90_CW:
244 case ELM_IMAGE_ROTATE_90_CCW:
250 ERR("unknown orient %d", orient);
251 evas_object_del(tmp);
252 evas_object_image_data_set(sd->obj, data); // give it back
256 for (x = iw; --x >= 0;)
258 for (y = ih; --y >= 0;)
266 evas_object_del(tmp);
267 evas_object_image_data_set(sd->obj, data);
268 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
269 _smart_reconfigure(sd);
272 /* local subsystem globals */
274 _smart_reconfigure(Smart_Data *sd)
277 Evas_Coord x, y, w, h;
279 if (!sd->obj) return;
280 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
286 evas_object_move(sd->obj, x, y);
287 evas_object_resize(sd->obj, w, h);
293 evas_object_image_size_get(sd->obj, &iw, &ih);
295 iw = ((double)iw) * sd->scale;
296 ih = ((double)ih) * sd->scale;
304 h = ((double)ih * w) / (double)iw;
308 w = ((double)iw * h) / (double)ih;
314 h = ((double)ih * w) / (double)iw;
318 w = ((double)iw * h) / (double)ih;
323 if ((w > iw) || (h > ih))
331 if ((w < iw) || (h < ih))
337 x = sd->x + ((sd->w - w) / 2);
338 y = sd->y + ((sd->h - h) / 2);
339 evas_object_move(sd->obj, x, y);
340 evas_object_image_fill_set(sd->obj, 0, 0, w, h);
341 evas_object_resize(sd->obj, w, h);
346 _preloaded(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
348 Smart_Data *sd = data;
352 evas_object_show(sd->obj);
358 if (_e_smart) return;
360 static const Evas_Smart_Class sc =
363 EVAS_SMART_CLASS_VERSION,
381 _e_smart = evas_smart_class_new(&sc);
386 _smart_add(Evas_Object *obj)
390 sd = calloc(1, sizeof(Smart_Data));
392 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
393 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
403 evas_object_smart_member_add(sd->obj, obj);
404 evas_object_smart_data_set(obj, sd);
405 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED, _preloaded, sd);
409 _smart_del(Evas_Object *obj)
413 sd = evas_object_smart_data_get(obj);
415 evas_object_del(sd->obj);
420 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
424 sd = evas_object_smart_data_get(obj);
426 if ((sd->x == x) && (sd->y == y)) return;
429 _smart_reconfigure(sd);
433 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
437 sd = evas_object_smart_data_get(obj);
439 if ((sd->w == w) && (sd->h == h)) return;
442 _smart_reconfigure(sd);
446 _smart_show(Evas_Object *obj)
450 sd = evas_object_smart_data_get(obj);
454 evas_object_show(sd->obj);
458 _smart_hide(Evas_Object *obj)
462 sd = evas_object_smart_data_get(obj);
465 evas_object_hide(sd->obj);
469 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
473 sd = evas_object_smart_data_get(obj);
475 evas_object_color_set(sd->obj, r, g, b, a);
479 _smart_clip_set(Evas_Object *obj, Evas_Object * clip)
483 sd = evas_object_smart_data_get(obj);
485 evas_object_clip_set(sd->obj, clip);
489 _smart_clip_unset(Evas_Object *obj)
493 sd = evas_object_smart_data_get(obj);
495 evas_object_clip_unset(sd->obj);
499 _els_smart_icon_flip_horizontal(Smart_Data *sd)
502 unsigned int *p1, *p2, tmp;
505 evas_object_image_size_get(sd->obj, &iw, &ih);
506 data = evas_object_image_data_get(sd->obj, 1);
508 for (y = 0; y < ih; y++)
510 p1 = data + (y * iw);
511 p2 = data + ((y + 1) * iw) - 1;
512 for (x = 0; x < (iw >> 1); x++)
522 evas_object_image_data_set(sd->obj, data);
523 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
524 _smart_reconfigure(sd);
528 _els_smart_icon_flip_vertical(Smart_Data *sd)
531 unsigned int *p1, *p2, tmp;
534 evas_object_image_size_get(sd->obj, &iw, &ih);
535 data = evas_object_image_data_get(sd->obj, 1);
537 for (y = 0; y < (ih >> 1); y++)
539 p1 = data + (y * iw);
540 p2 = data + ((ih - 1 - y) * iw);
541 for (x = 0; x < iw; x++)
551 evas_object_image_data_set(sd->obj, data);
552 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
553 _smart_reconfigure(sd);
557 _els_smart_icon_rotate_180(Smart_Data *sd)
560 unsigned int *p1, *p2, tmp;
563 evas_object_image_size_get(sd->obj, &iw, &ih);
564 data = evas_object_image_data_get(sd->obj, 1);
578 evas_object_image_data_set(sd->obj, data);
579 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
580 _smart_reconfigure(sd);