1 #include <Elementary.h>
5 * @defgroup Image Image
7 * A standard image that may be provided by the theme (delete, edit,
8 * arrows etc.) or a custom file (PNG, JPG, EDJE etc.) used for an
9 * icon. The Icon may scale or not and of course... support alpha
12 * Signals that you can add callbacks for are:
14 * clicked - This is called when a user has clicked the image
18 typedef struct _Widget_Data Widget_Data;
23 Eina_Bool scale_up : 1;
24 Eina_Bool scale_down : 1;
26 Eina_Bool fill_outside : 1;
27 Eina_Bool no_scale : 1;
30 static const char *widtype = NULL;
31 static void _del_hook(Evas_Object *obj);
32 static void _theme_hook(Evas_Object *obj);
33 static void _sizing_eval(Evas_Object *obj);
34 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
37 _del_hook(Evas_Object *obj)
39 Widget_Data *wd = elm_widget_data_get(obj);
46 _del_pre_hook(Evas_Object *obj)
48 Widget_Data *wd = elm_widget_data_get(obj);
51 evas_object_del(wd->img);
55 _theme_hook(Evas_Object *obj)
57 Widget_Data *wd = elm_widget_data_get(obj);
64 _sizing_eval(Evas_Object *obj)
66 Widget_Data *wd = elm_widget_data_get(obj);
67 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
71 _els_smart_icon_size_get(wd->img, &w, &h);
72 _els_smart_icon_scale_up_set(wd->img, wd->scale_up);
73 _els_smart_icon_scale_down_set(wd->img, wd->scale_down);
74 _els_smart_icon_smooth_scale_set(wd->img, wd->smooth);
75 _els_smart_icon_fill_inside_set(wd->img, !(wd->fill_outside));
76 if (wd->no_scale) _els_smart_icon_scale_set(wd->img, 1.0);
79 _els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) * _elm_config->scale);
80 _els_smart_icon_size_get(wd->img, &w, &h);
92 evas_object_size_hint_min_set(obj, minw, minh);
93 evas_object_size_hint_max_set(obj, maxw, maxh);
97 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
99 evas_object_smart_callback_call(data, "clicked", NULL);
103 * Add a new image to the parent
105 * @param parent The parent object
106 * @return The new object or NULL if it cannot be created
111 elm_image_add(Evas_Object *parent)
117 wd = ELM_NEW(Widget_Data);
118 e = evas_object_evas_get(parent);
119 obj = elm_widget_add(e);
120 ELM_SET_WIDTYPE(widtype, "image");
121 elm_widget_type_set(obj, "image");
122 elm_widget_sub_object_add(parent, obj);
123 elm_widget_data_set(obj, wd);
124 elm_widget_del_hook_set(obj, _del_hook);
125 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
126 elm_widget_theme_hook_set(obj, _theme_hook);
127 elm_widget_can_focus_set(obj, 0);
129 wd->img = _els_smart_icon_add(e);
130 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
132 evas_object_repeat_events_set(wd->img, 1);
133 elm_widget_resize_object_set(obj, wd->img);
135 wd->smooth = EINA_TRUE;
136 wd->scale_up = EINA_TRUE;
137 wd->scale_down = EINA_TRUE;
139 _els_smart_icon_scale_size_set(wd->img, 0);
146 * Set the file that will be used as image
148 * @param obj The image object
149 * @param file The path to file that will be used as image
150 * @param group The group that the image belongs in edje file
152 * @return (1 = sucess, 0 = error)
157 elm_image_file_set(Evas_Object *obj, const char *file, const char *group)
159 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
160 Widget_Data *wd = elm_widget_data_get(obj);
164 if ((!wd) || (!file)) return EINA_FALSE;
165 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
166 ret = _els_smart_icon_file_edje_set(wd->img, file, group);
168 ret = _els_smart_icon_file_key_set(wd->img, file, group);
174 * Set the smooth effect for a image
176 * @param obj The image object
177 * @param smooth A bool to set (or no) smooth effect
178 * (1 = smooth, 0 = not smooth)
183 elm_image_smooth_set(Evas_Object *obj, Eina_Bool smooth)
185 ELM_CHECK_WIDTYPE(obj, widtype);
186 Widget_Data *wd = elm_widget_data_get(obj);
194 elm_image_object_size_get(const Evas_Object *obj, int *w, int *h)
196 ELM_CHECK_WIDTYPE(obj, widtype);
197 Widget_Data *wd = elm_widget_data_get(obj);
200 _els_smart_icon_size_get(wd->img, w, h);
204 * Set if the object are scalable
206 * @param obj The image object.
207 * @param no_scale A bool to set scale (or no).
208 * (1 = no_scale, 0 = scale)
213 elm_image_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
215 ELM_CHECK_WIDTYPE(obj, widtype);
216 Widget_Data *wd = elm_widget_data_get(obj);
219 wd->no_scale = no_scale;
225 * Set if the object is (up/down) scalable
227 * @param obj The image object
228 * @param scale_up A bool to set if the object is scalable up
229 * @param scale_down A bool to set if the object is scalable down
234 elm_image_scale_set(Evas_Object *obj, Eina_Bool scale_up, Eina_Bool scale_down)
236 ELM_CHECK_WIDTYPE(obj, widtype);
237 Widget_Data *wd = elm_widget_data_get(obj);
240 wd->scale_up = scale_up;
241 wd->scale_down = scale_down;
246 * Set if the object is filled outside
248 * @param obj The image object
249 * @param fill_outside A bool to set if the object is filled outside
250 * (1 = filled, 0 = no filled)
255 elm_image_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
257 ELM_CHECK_WIDTYPE(obj, widtype);
258 Widget_Data *wd = elm_widget_data_get(obj);
261 wd->fill_outside = fill_outside;
266 * Set the prescale size for the image
268 * @param obj The image object
269 * @param size The prescale size
274 elm_image_prescale_set(Evas_Object *obj, int size)
276 ELM_CHECK_WIDTYPE(obj, widtype);
277 Widget_Data *wd = elm_widget_data_get(obj);
280 _els_smart_icon_scale_size_set(wd->img, size);
284 * Set the image orient
286 * @param obj The image object
287 * @param orient The image orient
288 * (ELM_IMAGE_ORIENT_NONE, ELM_IMAGE_ROTATE_90_CW,
289 * ELM_IMAGE_ROTATE_180_CW, ELM_IMAGE_ROTATE_90_CCW,
290 * ELM_IMAGE_FLIP_HORIZONTAL,ELM_IMAGE_FLIP_VERTICAL,
291 * ELM_IMAGE_FLIP_TRANSPOSE, ELM_IMAGE_FLIP_TRANSVERSE)
296 elm_image_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
298 ELM_CHECK_WIDTYPE(obj, widtype);
299 Widget_Data *wd = elm_widget_data_get(obj);
302 _els_smart_icon_orient_set(wd->img, orient);