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);
58 /* by default preload off by seok.j.jeong */
62 evas_object_image_preload(sd->obj, EINA_FALSE);
64 evas_object_hide(sd->obj);
65 if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
67 _smart_reconfigure(sd);
72 _els_smart_icon_file_edje_set(Evas_Object *obj, const char *file, const char *part)
76 sd = evas_object_smart_data_get(obj);
77 if (!sd) return EINA_FALSE;
79 if (sd->obj) evas_object_del(sd->obj);
80 sd->obj = edje_object_add(evas_object_evas_get(obj));
81 evas_object_smart_member_add(sd->obj, obj);
82 if (!edje_object_file_set(sd->obj, file, part))
84 _smart_reconfigure(sd);
89 _els_smart_icon_smooth_scale_set(Evas_Object *obj, int smooth)
93 sd = evas_object_smart_data_get(obj);
95 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
97 evas_object_image_smooth_scale_set(sd->obj, smooth);
101 _els_smart_icon_object_get(Evas_Object *obj)
104 sd = evas_object_smart_data_get(obj);
105 if (!sd) return NULL;
110 _els_smart_icon_size_get(Evas_Object *obj, int *w, int *h)
115 sd = evas_object_smart_data_get(obj);
117 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
118 edje_object_size_min_get(sd->obj, &tw, &th);
120 evas_object_image_size_get(sd->obj, &tw, &th);
121 tw = ((double)tw) * sd->scale;
122 th = ((double)th) * sd->scale;
128 _els_smart_icon_fill_inside_set(Evas_Object *obj, int fill_inside)
132 sd = evas_object_smart_data_get(obj);
134 if (((sd->fill_inside) && (fill_inside)) ||
135 ((!sd->fill_inside) && (!fill_inside))) return;
136 sd->fill_inside = fill_inside;
137 _smart_reconfigure(sd);
141 _els_smart_icon_scale_up_set(Evas_Object *obj, int scale_up)
145 sd = evas_object_smart_data_get(obj);
147 if (((sd->scale_up) && (scale_up)) ||
148 ((!sd->scale_up) && (!scale_up))) return;
149 sd->scale_up = scale_up;
150 _smart_reconfigure(sd);
154 _els_smart_icon_scale_down_set(Evas_Object *obj, int scale_down)
158 sd = evas_object_smart_data_get(obj);
160 if (((sd->scale_down) && (scale_down)) ||
161 ((!sd->scale_down) && (!scale_down))) return;
162 sd->scale_down = scale_down;
163 _smart_reconfigure(sd);
167 _els_smart_icon_scale_size_set(Evas_Object *obj, int size)
171 sd = evas_object_smart_data_get(obj);
174 if (!sd->obj) return;
175 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
177 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
181 _els_smart_icon_scale_set(Evas_Object *obj, double scale)
185 sd = evas_object_smart_data_get(obj);
188 _smart_reconfigure(sd);
192 _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
196 unsigned int *data, *data2, *to, *from;
197 int x, y, w, hw, iw, ih;
198 const char *file, *key;
200 sd = evas_object_smart_data_get(obj);
202 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
207 case ELM_IMAGE_FLIP_HORIZONTAL:
208 _els_smart_icon_flip_horizontal(sd);
210 case ELM_IMAGE_FLIP_VERTICAL:
211 _els_smart_icon_flip_vertical(sd);
213 case ELM_IMAGE_ROTATE_180_CW:
214 _els_smart_icon_rotate_180(sd);
220 evas_object_image_size_get(sd->obj, &iw, &ih);
221 evas_object_image_file_get(sd->obj, &file, &key);
222 tmp = evas_object_image_add(evas_object_evas_get(sd->obj));
223 evas_object_image_file_set(tmp, file, key);
224 data2 = evas_object_image_data_get(tmp, 0);
231 evas_object_image_size_set(sd->obj, iw, ih);
232 data = evas_object_image_data_get(sd->obj, 1);
235 case ELM_IMAGE_FLIP_TRANSPOSE:
239 case ELM_IMAGE_FLIP_TRANSVERSE:
244 case ELM_IMAGE_ROTATE_90_CW:
248 case ELM_IMAGE_ROTATE_90_CCW:
254 ERR("unknown orient %d", orient);
255 evas_object_del(tmp);
256 evas_object_image_data_set(sd->obj, data); // give it back
260 for (x = iw; --x >= 0;)
262 for (y = ih; --y >= 0;)
270 evas_object_del(tmp);
271 evas_object_image_data_set(sd->obj, data);
272 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
273 _smart_reconfigure(sd);
276 /* local subsystem globals */
278 _smart_reconfigure(Smart_Data *sd)
281 Evas_Coord x, y, w, h;
283 if (!sd->obj) return;
284 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
290 evas_object_move(sd->obj, x, y);
291 evas_object_resize(sd->obj, w, h);
297 evas_object_image_size_get(sd->obj, &iw, &ih);
299 iw = ((double)iw) * sd->scale;
300 ih = ((double)ih) * sd->scale;
308 h = ((double)ih * w) / (double)iw;
312 w = ((double)iw * h) / (double)ih;
318 h = ((double)ih * w) / (double)iw;
322 w = ((double)iw * h) / (double)ih;
327 if ((w > iw) || (h > ih))
335 if ((w < iw) || (h < ih))
341 x = sd->x + ((sd->w - w) / 2);
342 y = sd->y + ((sd->h - h) / 2);
343 evas_object_move(sd->obj, x, y);
344 evas_object_image_fill_set(sd->obj, 0, 0, w, h);
345 evas_object_resize(sd->obj, w, h);
350 _preloaded(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
352 Smart_Data *sd = data;
356 evas_object_show(sd->obj);
362 if (_e_smart) return;
364 static const Evas_Smart_Class sc =
367 EVAS_SMART_CLASS_VERSION,
385 _e_smart = evas_smart_class_new(&sc);
390 _smart_add(Evas_Object *obj)
394 sd = calloc(1, sizeof(Smart_Data));
396 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
397 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
407 evas_object_smart_member_add(sd->obj, obj);
408 evas_object_smart_data_set(obj, sd);
409 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED, _preloaded, sd);
413 _smart_del(Evas_Object *obj)
417 sd = evas_object_smart_data_get(obj);
419 evas_object_del(sd->obj);
424 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
428 sd = evas_object_smart_data_get(obj);
430 if ((sd->x == x) && (sd->y == y)) return;
433 _smart_reconfigure(sd);
437 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
441 sd = evas_object_smart_data_get(obj);
443 if ((sd->w == w) && (sd->h == h)) return;
446 _smart_reconfigure(sd);
450 _smart_show(Evas_Object *obj)
454 sd = evas_object_smart_data_get(obj);
458 evas_object_show(sd->obj);
462 _smart_hide(Evas_Object *obj)
466 sd = evas_object_smart_data_get(obj);
469 evas_object_hide(sd->obj);
473 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
477 sd = evas_object_smart_data_get(obj);
479 evas_object_color_set(sd->obj, r, g, b, a);
483 _smart_clip_set(Evas_Object *obj, Evas_Object * clip)
487 sd = evas_object_smart_data_get(obj);
489 evas_object_clip_set(sd->obj, clip);
493 _smart_clip_unset(Evas_Object *obj)
497 sd = evas_object_smart_data_get(obj);
499 evas_object_clip_unset(sd->obj);
503 _els_smart_icon_flip_horizontal(Smart_Data *sd)
506 unsigned int *p1, *p2, tmp;
509 evas_object_image_size_get(sd->obj, &iw, &ih);
510 data = evas_object_image_data_get(sd->obj, 1);
512 for (y = 0; y < ih; y++)
514 p1 = data + (y * iw);
515 p2 = data + ((y + 1) * iw) - 1;
516 for (x = 0; x < (iw >> 1); x++)
526 evas_object_image_data_set(sd->obj, data);
527 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
528 _smart_reconfigure(sd);
532 _els_smart_icon_flip_vertical(Smart_Data *sd)
535 unsigned int *p1, *p2, tmp;
538 evas_object_image_size_get(sd->obj, &iw, &ih);
539 data = evas_object_image_data_get(sd->obj, 1);
541 for (y = 0; y < (ih >> 1); y++)
543 p1 = data + (y * iw);
544 p2 = data + ((ih - 1 - y) * iw);
545 for (x = 0; x < iw; x++)
555 evas_object_image_data_set(sd->obj, data);
556 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
557 _smart_reconfigure(sd);
561 _els_smart_icon_rotate_180(Smart_Data *sd)
564 unsigned int *p1, *p2, tmp;
567 evas_object_image_size_get(sd->obj, &iw, &ih);
568 data = evas_object_image_data_get(sd->obj, 1);
582 evas_object_image_data_set(sd->obj, data);
583 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
584 _smart_reconfigure(sd);