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;
17 /* local subsystem functions */
18 static void _smart_reconfigure(Smart_Data *sd);
19 static void _smart_init(void);
20 static void _smart_add(Evas_Object *obj);
21 static void _smart_del(Evas_Object *obj);
22 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
23 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
24 static void _smart_show(Evas_Object *obj);
25 static void _smart_hide(Evas_Object *obj);
26 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
27 static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
28 static void _smart_clip_unset(Evas_Object *obj);
30 static void _els_smart_icon_flip_horizontal(Smart_Data *sd);
31 static void _els_smart_icon_flip_vertical(Smart_Data *sd);
32 static void _els_smart_icon_rotate_180(Smart_Data *sd);
34 /* local subsystem globals */
35 static Evas_Smart *_e_smart = NULL;
37 /* externally accessible functions */
39 _els_smart_icon_add(Evas *evas)
42 return evas_object_smart_add(evas, _e_smart);
46 _els_smart_icon_file_key_set(Evas_Object *obj, const char *file, const char *key)
50 sd = evas_object_smart_data_get(obj);
51 if (!sd) return EINA_FALSE;
54 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
55 evas_object_image_file_set(sd->obj, file, key);
56 if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
58 _smart_reconfigure(sd);
63 _els_smart_icon_file_edje_set(Evas_Object *obj, const char *file, const char *part)
67 sd = evas_object_smart_data_get(obj);
68 if (!sd) return EINA_FALSE;
70 if (sd->obj) evas_object_del(sd->obj);
71 sd->obj = edje_object_add(evas_object_evas_get(obj));
72 evas_object_smart_member_add(sd->obj, obj);
73 if (!edje_object_file_set(sd->obj, file, part))
75 _smart_reconfigure(sd);
80 _els_smart_icon_smooth_scale_set(Evas_Object *obj, int smooth)
84 sd = evas_object_smart_data_get(obj);
86 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
88 evas_object_image_smooth_scale_set(sd->obj, smooth);
92 _els_smart_icon_size_get(Evas_Object *obj, int *w, int *h)
97 sd = evas_object_smart_data_get(obj);
99 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
100 edje_object_size_min_get(sd->obj, &tw, &th);
102 evas_object_image_size_get(sd->obj, &tw, &th);
103 tw = ((double)tw) * sd->scale;
104 th = ((double)th) * sd->scale;
110 _els_smart_icon_fill_inside_set(Evas_Object *obj, int fill_inside)
114 sd = evas_object_smart_data_get(obj);
116 if (((sd->fill_inside) && (fill_inside)) ||
117 ((!sd->fill_inside) && (!fill_inside))) return;
118 sd->fill_inside = fill_inside;
119 _smart_reconfigure(sd);
123 _els_smart_icon_scale_up_set(Evas_Object *obj, int scale_up)
127 sd = evas_object_smart_data_get(obj);
129 if (((sd->scale_up) && (scale_up)) ||
130 ((!sd->scale_up) && (!scale_up))) return;
131 sd->scale_up = scale_up;
132 _smart_reconfigure(sd);
136 _els_smart_icon_scale_down_set(Evas_Object *obj, int scale_down)
140 sd = evas_object_smart_data_get(obj);
142 if (((sd->scale_down) && (scale_down)) ||
143 ((!sd->scale_down) && (!scale_down))) return;
144 sd->scale_down = scale_down;
145 _smart_reconfigure(sd);
149 _els_smart_icon_scale_size_set(Evas_Object *obj, int size)
153 sd = evas_object_smart_data_get(obj);
156 if (!sd->obj) return;
157 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
159 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
163 _els_smart_icon_scale_set(Evas_Object *obj, double scale)
167 sd = evas_object_smart_data_get(obj);
170 _smart_reconfigure(sd);
174 _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
178 unsigned int *data, *data2, *to, *from;
179 int x, y, w, hw, iw, ih;
180 const char *file, *key;
182 sd = evas_object_smart_data_get(obj);
184 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
189 case ELM_IMAGE_FLIP_HORIZONTAL:
190 _els_smart_icon_flip_horizontal(sd);
192 case ELM_IMAGE_FLIP_VERTICAL:
193 _els_smart_icon_flip_vertical(sd);
195 case ELM_IMAGE_ROTATE_180_CW:
196 _els_smart_icon_rotate_180(sd);
202 evas_object_image_size_get(sd->obj, &iw, &ih);
203 evas_object_image_file_get(sd->obj, &file, &key);
204 tmp = evas_object_image_add(evas_object_evas_get(sd->obj));
205 evas_object_image_file_set(tmp, file, key);
206 data2 = evas_object_image_data_get(tmp, 0);
213 evas_object_image_size_set(sd->obj, iw, ih);
214 data = evas_object_image_data_get(sd->obj, 1);
217 case ELM_IMAGE_FLIP_TRANSPOSE:
221 case ELM_IMAGE_FLIP_TRANSVERSE:
226 case ELM_IMAGE_ROTATE_90_CW:
230 case ELM_IMAGE_ROTATE_90_CCW:
236 ERR("unknown orient %d", orient);
237 evas_object_del(tmp);
238 evas_object_image_data_set(sd->obj, data); // give it back
242 for (x = iw; --x >= 0;)
244 for (y = ih; --y >= 0;)
252 evas_object_del(tmp);
253 evas_object_image_data_set(sd->obj, data);
254 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
255 _smart_reconfigure(sd);
258 /* local subsystem globals */
260 _smart_reconfigure(Smart_Data *sd)
263 Evas_Coord x, y, w, h;
265 if (!sd->obj) return;
266 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
272 evas_object_move(sd->obj, x, y);
273 evas_object_resize(sd->obj, w, h);
279 evas_object_image_size_get(sd->obj, &iw, &ih);
281 iw = ((double)iw) * sd->scale;
282 ih = ((double)ih) * sd->scale;
290 h = ((double)ih * w) / (double)iw;
294 w = ((double)iw * h) / (double)ih;
300 h = ((double)ih * w) / (double)iw;
304 w = ((double)iw * h) / (double)ih;
309 if ((w > iw) || (h > ih))
317 if ((w < iw) || (h < ih))
323 x = sd->x + ((sd->w - w) / 2);
324 y = sd->y + ((sd->h - h) / 2);
325 evas_object_move(sd->obj, x, y);
326 evas_object_image_fill_set(sd->obj, 0, 0, w, h);
327 evas_object_resize(sd->obj, w, h);
334 if (_e_smart) return;
336 static const Evas_Smart_Class sc =
339 EVAS_SMART_CLASS_VERSION,
357 _e_smart = evas_smart_class_new(&sc);
362 _smart_add(Evas_Object *obj)
366 sd = calloc(1, sizeof(Smart_Data));
368 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
369 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
379 evas_object_smart_member_add(sd->obj, obj);
380 evas_object_smart_data_set(obj, sd);
384 _smart_del(Evas_Object *obj)
388 sd = evas_object_smart_data_get(obj);
390 evas_object_del(sd->obj);
395 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
399 sd = evas_object_smart_data_get(obj);
401 if ((sd->x == x) && (sd->y == y)) return;
404 _smart_reconfigure(sd);
408 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
412 sd = evas_object_smart_data_get(obj);
414 if ((sd->w == w) && (sd->h == h)) return;
417 _smart_reconfigure(sd);
421 _smart_show(Evas_Object *obj)
425 sd = evas_object_smart_data_get(obj);
427 evas_object_show(sd->obj);
431 _smart_hide(Evas_Object *obj)
435 sd = evas_object_smart_data_get(obj);
437 evas_object_hide(sd->obj);
441 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
445 sd = evas_object_smart_data_get(obj);
447 evas_object_color_set(sd->obj, r, g, b, a);
451 _smart_clip_set(Evas_Object *obj, Evas_Object * clip)
455 sd = evas_object_smart_data_get(obj);
457 evas_object_clip_set(sd->obj, clip);
461 _smart_clip_unset(Evas_Object *obj)
465 sd = evas_object_smart_data_get(obj);
467 evas_object_clip_unset(sd->obj);
471 _els_smart_icon_flip_horizontal(Smart_Data *sd)
474 unsigned int *p1, *p2, tmp;
477 evas_object_image_size_get(sd->obj, &iw, &ih);
478 data = evas_object_image_data_get(sd->obj, 1);
480 for (y = 0; y < ih; y++)
482 p1 = data + (y * iw);
483 p2 = data + ((y + 1) * iw) - 1;
484 for (x = 0; x < (iw >> 1); x++)
494 evas_object_image_data_set(sd->obj, data);
495 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
496 _smart_reconfigure(sd);
500 _els_smart_icon_flip_vertical(Smart_Data *sd)
503 unsigned int *p1, *p2, tmp;
506 evas_object_image_size_get(sd->obj, &iw, &ih);
507 data = evas_object_image_data_get(sd->obj, 1);
509 for (y = 0; y < (ih >> 1); y++)
511 p1 = data + (y * iw);
512 p2 = data + ((ih - 1 - y) * iw);
513 for (x = 0; x < iw; x++)
523 evas_object_image_data_set(sd->obj, data);
524 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
525 _smart_reconfigure(sd);
529 _els_smart_icon_rotate_180(Smart_Data *sd)
532 unsigned int *p1, *p2, tmp;
535 evas_object_image_size_get(sd->obj, &iw, &ih);
536 data = evas_object_image_data_get(sd->obj, 1);
550 evas_object_image_data_set(sd->obj, data);
551 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
552 _smart_reconfigure(sd);