X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Flib%2Fels_icon.c;h=f32ab4dd39e08fd7806c089310fa2a84cbd0ed59;hb=946051a5db20eca4d492bb1de4fb032a21772138;hp=9d44378ca8a0b4a6b37883b45273faa92be4461c;hpb=5e055f3da9418c3a3420f6ffd08f20b1b3eb8fe1;p=framework%2Fuifw%2Felementary.git diff --git a/src/lib/els_icon.c b/src/lib/els_icon.c old mode 100755 new mode 100644 index 9d44378..f32ab4d --- a/src/lib/els_icon.c +++ b/src/lib/els_icon.c @@ -1,5 +1,12 @@ #include #include "elm_priv.h" +#include "els_icon.h" + +#ifdef _WIN32 +# define FMT_SIZE_T "%Iu" +#else +# define FMT_SIZE_T "%zu" +#endif typedef struct _Smart_Data Smart_Data; @@ -17,7 +24,7 @@ struct _Smart_Data Eina_Bool show : 1; Eina_Bool edit : 1; Eina_Bool edje : 1; - Eina_Bool aspect_ratio_retained: 1; + Eina_Bool aspect_fixed: 1; Elm_Image_Orient orient; }; @@ -65,37 +72,69 @@ _preloaded(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event __UNUSE sd->prev = NULL; } -Eina_Bool -_els_smart_icon_file_key_set(Evas_Object *obj, const char *file, const char *key) +static void +_els_smart_icon_file_helper(Evas_Object *obj) { Smart_Data *sd; Evas_Object *pclip; sd = evas_object_smart_data_get(obj); - if (!sd) return EINA_FALSE; /* smart code here */ - /* NOTE: Do not merge upstream for the if (sd->edje) { } statements + /* NOTE: Do not merge upstream for the if (sd->edje) { } statements But wonder whether the edje resource icons have no problem. */ - if (sd->edje) - { - if (sd->prev) evas_object_del(sd->prev); - pclip = evas_object_clip_get(sd->obj); - if (sd->obj) sd->prev = sd->obj; - sd->obj = evas_object_image_add(evas_object_evas_get(obj)); - evas_object_event_callback_add(sd->obj, - EVAS_CALLBACK_IMAGE_PRELOADED, - _preloaded, sd); - evas_object_smart_member_add(sd->obj, obj); - if (sd->prev) evas_object_smart_member_add(sd->prev, obj); - evas_object_image_scale_hint_set(sd->obj, - EVAS_IMAGE_SCALE_HINT_STATIC); - evas_object_clip_set(sd->obj, pclip); + if (!sd->edje) goto out; - sd->edje = EINA_FALSE; - } + if (sd->prev) evas_object_del(sd->prev); + pclip = evas_object_clip_get(sd->obj); + if (sd->obj) sd->prev = sd->obj; + sd->obj = evas_object_image_add(evas_object_evas_get(obj)); + evas_object_image_load_orientation_set(sd->obj, EINA_TRUE); + evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED, + _preloaded, sd); + evas_object_smart_member_add(sd->obj, obj); + if (sd->prev) evas_object_smart_member_add(sd->prev, obj); + evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC); + evas_object_clip_set(sd->obj, pclip); + + sd->edje = EINA_FALSE; +out: if (!sd->size) evas_object_image_load_size_set(sd->obj, sd->size, sd->size); +} + +Eina_Bool +_els_smart_icon_memfile_set(Evas_Object *obj, const void *img, size_t size, const char *format, const char *key) +{ + Smart_Data *sd; + + sd = evas_object_smart_data_get(obj); + if (!sd) return EINA_FALSE; + _els_smart_icon_file_helper(obj); + + evas_object_image_memfile_set(sd->obj, (void*)img, size, (char*)format, (char*)key); + sd->preloading = EINA_TRUE; + sd->show = EINA_TRUE; + evas_object_hide(sd->obj); + evas_object_image_preload(sd->obj, EINA_FALSE); + if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE) + { + ERR("Things are going bad for some random " FMT_SIZE_T " byte chunk of memory (%p)", size, sd->obj); + return EINA_FALSE; + } + _smart_reconfigure(sd); + return EINA_TRUE; +} + +Eina_Bool +_els_smart_icon_file_key_set(Evas_Object *obj, const char *file, const char *key) +{ + Smart_Data *sd; + + sd = evas_object_smart_data_get(obj); + if (!sd) return EINA_FALSE; + _els_smart_icon_file_helper(obj); + evas_object_image_file_set(sd->obj, file, key); // NOTE: Do not merge upstream for sd->preloading. sd->preloading = EINA_FALSE; // by default preload off by seok.j.jeong @@ -115,6 +154,17 @@ _els_smart_icon_file_key_set(Evas_Object *obj, const char *file, const char *key return EINA_TRUE; } +void +_els_smart_icon_preload_set(Evas_Object *obj, Eina_Bool disable) +{ + Smart_Data *sd; + + sd = evas_object_smart_data_get(obj); + if ((!sd) || sd->edje) return; + evas_object_image_preload(sd->obj, disable); + sd->preloading = !disable; +} + Eina_Bool _els_smart_icon_file_edje_set(Evas_Object *obj, const char *file, const char *part) { @@ -188,10 +238,13 @@ _els_smart_icon_size_get(const Evas_Object *obj, int *w, int *h) Smart_Data *sd; int tw, th; int cw, ch; + const char *type; sd = evas_object_smart_data_get(obj); if (!sd) return; - if (!strcmp(evas_object_type_get(sd->obj), "edje")) + type = evas_object_type_get(sd->obj); + if (!type) return; + if (!strcmp(type, "edje")) edje_object_size_min_get(sd->obj, &tw, &th); else evas_object_image_size_get(sd->obj, &tw, &th); @@ -310,10 +363,8 @@ void _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient) { Smart_Data *sd; - Evas_Object *tmp; - unsigned int *data, *data2, *to, *from; + unsigned int *data, *data2 = NULL, *to, *from; int x, y, w, hw, iw, ih; - const char *file, *key; sd = evas_object_smart_data_get(obj); if (!sd) return; @@ -336,10 +387,9 @@ _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient) } evas_object_image_size_get(sd->obj, &iw, &ih); - evas_object_image_file_get(sd->obj, &file, &key); - tmp = evas_object_image_add(evas_object_evas_get(sd->obj)); - evas_object_image_file_set(tmp, file, key); - data2 = evas_object_image_data_get(tmp, EINA_FALSE); + /* we need separate destination memory if we want to rotate 90 or 270 degree */ + evas_object_image_data_copy_set(sd->obj, data2); + if (!data2) return; w = ih; ih = iw; @@ -348,6 +398,7 @@ _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient) evas_object_image_size_set(sd->obj, iw, ih); data = evas_object_image_data_get(sd->obj, EINA_TRUE); + switch (orient) { case ELM_IMAGE_FLIP_TRANSPOSE: @@ -370,8 +421,8 @@ _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient) break; default: ERR("unknown orient %d", orient); - evas_object_del(tmp); evas_object_image_data_set(sd->obj, data); // give it back + if (data2) free(data2); return; } from = data2; @@ -386,7 +437,7 @@ _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient) to += hw; } sd->orient = orient; - evas_object_del(tmp); + if (data2) free(data2); evas_object_image_data_set(sd->obj, data); evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih); _smart_reconfigure(sd); @@ -445,27 +496,27 @@ _els_smart_icon_edje_get(Evas_Object *obj) } void -_els_smart_icon_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained) +_els_smart_icon_aspect_fixed_set(Evas_Object *obj, Eina_Bool fixed) { Smart_Data *sd; sd = evas_object_smart_data_get(obj); if (!sd) return; - retained = !!retained; - if (sd->aspect_ratio_retained == retained) return; - sd->aspect_ratio_retained = retained; + fixed = !!fixed; + if (sd->aspect_fixed == fixed) return; + sd->aspect_fixed = fixed; _smart_reconfigure(sd); } Eina_Bool -_els_smart_icon_aspect_ratio_retained_get(const Evas_Object *obj) +_els_smart_icon_aspect_fixed_get(const Evas_Object *obj) { Smart_Data *sd; sd = evas_object_smart_data_get(obj); if (!sd) return EINA_FALSE; - return sd->aspect_ratio_retained; + return sd->aspect_fixed; } /* local subsystem globals */ @@ -473,13 +524,16 @@ static void _smart_reconfigure(Smart_Data *sd) { Evas_Coord x, y, w, h; + const char *type; if (!sd->obj) return; w = sd->w; h = sd->h; - if (!strcmp(evas_object_type_get(sd->obj), "edje")) + type = evas_object_type_get(sd->obj); + if (!type) return; + if (!strcmp(type, "edje")) { x = sd->x; y = sd->y; @@ -489,6 +543,8 @@ _smart_reconfigure(Smart_Data *sd) else { int iw = 0, ih = 0; + double alignh = 0.5, alignv = 0.5; + Evas_Object *parent; evas_object_image_size_get(sd->obj, &iw, &ih); @@ -498,7 +554,7 @@ _smart_reconfigure(Smart_Data *sd) if (iw < 1) iw = 1; if (ih < 1) ih = 1; - if (sd->aspect_ratio_retained) + if (sd->aspect_fixed) { h = ((double)ih * w) / (double)iw; if (sd->fill_inside) @@ -528,8 +584,13 @@ _smart_reconfigure(Smart_Data *sd) if (w < iw) w = iw; if (h < ih) h = ih; } - x = sd->x + ((sd->w - w) / 2); - y = sd->y + ((sd->h - h) / 2); + parent = elm_widget_parent_widget_get(sd->obj); + if (parent) + evas_object_size_hint_align_get(parent, &alignh, &alignv); + if (alignh == EVAS_HINT_FILL) alignh = 0.5; + if (alignv == EVAS_HINT_FILL) alignv = 0.5; + x = sd->x + ((sd->w - w) * alignh); + y = sd->y + ((sd->h - h) * alignv); evas_object_move(sd->obj, x, y); evas_object_image_fill_set(sd->obj, 0, 0, w, h); evas_object_resize(sd->obj, w, h); @@ -583,7 +644,7 @@ _smart_add(Evas_Object *obj) sd->fill_inside = EINA_TRUE; sd->scale_up = EINA_TRUE; sd->scale_down = EINA_TRUE; - sd->aspect_ratio_retained = EINA_TRUE; + sd->aspect_fixed = EINA_TRUE; sd->size = 64; sd->scale = 1.0; evas_object_smart_member_add(sd->obj, obj);