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;
17 unsigned char edit : 1;
20 /* local subsystem functions */
21 static void _smart_reconfigure(Smart_Data *sd);
22 static void _smart_init(void);
23 static void _smart_add(Evas_Object *obj);
24 static void _smart_del(Evas_Object *obj);
25 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
26 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
27 static void _smart_show(Evas_Object *obj);
28 static void _smart_hide(Evas_Object *obj);
29 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
30 static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
31 static void _smart_clip_unset(Evas_Object *obj);
33 static void _els_smart_icon_flip_horizontal(Smart_Data *sd);
34 static void _els_smart_icon_flip_vertical(Smart_Data *sd);
35 static void _els_smart_icon_rotate_180(Smart_Data *sd);
36 static Eina_Bool _els_smart_icon_dropcb(void *,Evas_Object *, Elm_Selection_Data *);
38 /* local subsystem globals */
39 static Evas_Smart *_e_smart = NULL;
41 /* externally accessible functions */
43 _els_smart_icon_add(Evas *evas)
46 return evas_object_smart_add(evas, _e_smart);
50 _els_smart_icon_file_key_set(Evas_Object *obj, const char *file, const char *key)
54 sd = evas_object_smart_data_get(obj);
55 if (!sd) return EINA_FALSE;
58 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
59 evas_object_image_file_set(sd->obj, file, key);
60 /* by default preload off by seok.j.jeong */
64 evas_object_image_preload(sd->obj, EINA_FALSE);
66 evas_object_hide(sd->obj);
67 if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
69 _smart_reconfigure(sd);
74 _els_smart_icon_file_edje_set(Evas_Object *obj, const char *file, const char *part)
78 sd = evas_object_smart_data_get(obj);
79 if (!sd) return EINA_FALSE;
81 if (sd->obj) evas_object_del(sd->obj);
82 sd->obj = edje_object_add(evas_object_evas_get(obj));
83 evas_object_smart_member_add(sd->obj, obj);
84 if (!edje_object_file_set(sd->obj, file, part))
86 _smart_reconfigure(sd);
91 _els_smart_icon_smooth_scale_set(Evas_Object *obj, int smooth)
95 sd = evas_object_smart_data_get(obj);
97 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
99 evas_object_image_smooth_scale_set(sd->obj, smooth);
103 _els_smart_icon_object_get(Evas_Object *obj)
107 sd = evas_object_smart_data_get(obj);
108 if (!sd) return NULL;
113 _els_smart_icon_size_get(Evas_Object *obj, int *w, int *h)
118 sd = evas_object_smart_data_get(obj);
120 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
121 edje_object_size_min_get(sd->obj, &tw, &th);
123 evas_object_image_size_get(sd->obj, &tw, &th);
124 tw = ((double)tw) * sd->scale;
125 th = ((double)th) * sd->scale;
131 _els_smart_icon_fill_inside_set(Evas_Object *obj, int fill_inside)
135 sd = evas_object_smart_data_get(obj);
137 if (((sd->fill_inside) && (fill_inside)) ||
138 ((!sd->fill_inside) && (!fill_inside))) return;
139 sd->fill_inside = fill_inside;
140 _smart_reconfigure(sd);
144 _els_smart_icon_scale_up_set(Evas_Object *obj, int scale_up)
148 sd = evas_object_smart_data_get(obj);
150 if (((sd->scale_up) && (scale_up)) ||
151 ((!sd->scale_up) && (!scale_up))) return;
152 sd->scale_up = scale_up;
153 _smart_reconfigure(sd);
157 _els_smart_icon_scale_down_set(Evas_Object *obj, int scale_down)
161 sd = evas_object_smart_data_get(obj);
163 if (((sd->scale_down) && (scale_down)) ||
164 ((!sd->scale_down) && (!scale_down))) return;
165 sd->scale_down = scale_down;
166 _smart_reconfigure(sd);
170 _els_smart_icon_scale_size_set(Evas_Object *obj, int size)
174 sd = evas_object_smart_data_get(obj);
177 if (!sd->obj) return;
178 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
180 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
184 _els_smart_icon_scale_set(Evas_Object *obj, double scale)
188 sd = evas_object_smart_data_get(obj);
191 _smart_reconfigure(sd);
195 _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
199 unsigned int *data, *data2, *to, *from;
200 int x, y, w, hw, iw, ih;
201 const char *file, *key;
203 sd = evas_object_smart_data_get(obj);
205 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
210 case ELM_IMAGE_FLIP_HORIZONTAL:
211 _els_smart_icon_flip_horizontal(sd);
213 case ELM_IMAGE_FLIP_VERTICAL:
214 _els_smart_icon_flip_vertical(sd);
216 case ELM_IMAGE_ROTATE_180_CW:
217 _els_smart_icon_rotate_180(sd);
223 evas_object_image_size_get(sd->obj, &iw, &ih);
224 evas_object_image_file_get(sd->obj, &file, &key);
225 tmp = evas_object_image_add(evas_object_evas_get(sd->obj));
226 evas_object_image_file_set(tmp, file, key);
227 data2 = evas_object_image_data_get(tmp, 0);
234 evas_object_image_size_set(sd->obj, iw, ih);
235 data = evas_object_image_data_get(sd->obj, 1);
238 case ELM_IMAGE_FLIP_TRANSPOSE:
242 case ELM_IMAGE_FLIP_TRANSVERSE:
247 case ELM_IMAGE_ROTATE_90_CW:
251 case ELM_IMAGE_ROTATE_90_CCW:
257 ERR("unknown orient %d", orient);
258 evas_object_del(tmp);
259 evas_object_image_data_set(sd->obj, data); // give it back
263 for (x = iw; --x >= 0;)
265 for (y = ih; --y >= 0;)
273 evas_object_del(tmp);
274 evas_object_image_data_set(sd->obj, data);
275 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
276 _smart_reconfigure(sd);
280 * Turns on editing through drag and drop and copy and paste.
283 _els_smart_icon_edit_set(Evas_Object *obj, Eina_Bool edit, Evas_Object *parent)
287 sd = evas_object_smart_data_get(obj);
290 if (strcmp(evas_object_type_get(sd->obj), "edje")== 0)
292 printf("No editing edje objects yet (ever)\n");
296 /* Unfortunately eina bool is not a bool, but a char */
298 if (edit == sd->edit) return;
304 elm_drop_target_add(obj, ELM_SEL_FORMAT_IMAGE, _els_smart_icon_dropcb,
309 elm_drop_target_del(obj);
314 /* local subsystem globals */
316 _smart_reconfigure(Smart_Data *sd)
318 Evas_Coord x, y, w, h;
320 if (!sd->obj) return;
321 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
327 evas_object_move(sd->obj, x, y);
328 evas_object_resize(sd->obj, w, h);
334 evas_object_image_size_get(sd->obj, &iw, &ih);
336 iw = ((double)iw) * sd->scale;
337 ih = ((double)ih) * sd->scale;
345 h = ((double)ih * w) / (double)iw;
349 w = ((double)iw * h) / (double)ih;
355 h = ((double)ih * w) / (double)iw;
359 w = ((double)iw * h) / (double)ih;
364 if ((w > iw) || (h > ih))
372 if ((w < iw) || (h < ih))
378 x = sd->x + ((sd->w - w) / 2);
379 y = sd->y + ((sd->h - h) / 2);
380 evas_object_move(sd->obj, x, y);
381 evas_object_image_fill_set(sd->obj, 0, 0, w, h);
382 evas_object_resize(sd->obj, w, h);
387 _preloaded(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
389 Smart_Data *sd = data;
393 evas_object_show(sd->obj);
399 if (_e_smart) return;
401 static const Evas_Smart_Class sc =
404 EVAS_SMART_CLASS_VERSION,
422 _e_smart = evas_smart_class_new(&sc);
427 _smart_add(Evas_Object *obj)
431 sd = calloc(1, sizeof(Smart_Data));
433 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
434 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
444 evas_object_smart_member_add(sd->obj, obj);
445 evas_object_smart_data_set(obj, sd);
446 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
451 _smart_del(Evas_Object *obj)
455 sd = evas_object_smart_data_get(obj);
457 evas_object_del(sd->obj);
462 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
466 sd = evas_object_smart_data_get(obj);
468 if ((sd->x == x) && (sd->y == y)) return;
471 _smart_reconfigure(sd);
475 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
479 sd = evas_object_smart_data_get(obj);
481 if ((sd->w == w) && (sd->h == h)) return;
484 _smart_reconfigure(sd);
488 _smart_show(Evas_Object *obj)
492 sd = evas_object_smart_data_get(obj);
496 evas_object_show(sd->obj);
500 _smart_hide(Evas_Object *obj)
504 sd = evas_object_smart_data_get(obj);
507 evas_object_hide(sd->obj);
511 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
515 sd = evas_object_smart_data_get(obj);
517 evas_object_color_set(sd->obj, r, g, b, a);
521 _smart_clip_set(Evas_Object *obj, Evas_Object * clip)
525 sd = evas_object_smart_data_get(obj);
527 evas_object_clip_set(sd->obj, clip);
531 _smart_clip_unset(Evas_Object *obj)
535 sd = evas_object_smart_data_get(obj);
537 evas_object_clip_unset(sd->obj);
541 _els_smart_icon_flip_horizontal(Smart_Data *sd)
544 unsigned int *p1, *p2, tmp;
547 evas_object_image_size_get(sd->obj, &iw, &ih);
548 data = evas_object_image_data_get(sd->obj, 1);
550 for (y = 0; y < ih; y++)
552 p1 = data + (y * iw);
553 p2 = data + ((y + 1) * iw) - 1;
554 for (x = 0; x < (iw >> 1); x++)
564 evas_object_image_data_set(sd->obj, data);
565 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
566 _smart_reconfigure(sd);
570 _els_smart_icon_flip_vertical(Smart_Data *sd)
573 unsigned int *p1, *p2, tmp;
576 evas_object_image_size_get(sd->obj, &iw, &ih);
577 data = evas_object_image_data_get(sd->obj, 1);
579 for (y = 0; y < (ih >> 1); y++)
581 p1 = data + (y * iw);
582 p2 = data + ((ih - 1 - y) * iw);
583 for (x = 0; x < iw; x++)
593 evas_object_image_data_set(sd->obj, data);
594 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
595 _smart_reconfigure(sd);
599 _els_smart_icon_rotate_180(Smart_Data *sd)
602 unsigned int *p1, *p2, tmp;
605 evas_object_image_size_get(sd->obj, &iw, &ih);
606 data = evas_object_image_data_get(sd->obj, 1);
620 evas_object_image_data_set(sd->obj, data);
621 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
622 _smart_reconfigure(sd);
626 _els_smart_icon_dropcb(void *elmobj,Evas_Object *obj, Elm_Selection_Data *drop)
628 _els_smart_icon_file_key_set(obj, drop->data, NULL);
629 evas_object_smart_callback_call(elmobj, "drop", drop->data);
633 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/