1 #include <Elementary.h>
5 * @defgroup Image Image
8 * A standard image that may be provided by the theme (delete, edit,
9 * arrows etc.) or a custom file (PNG, JPG, EDJE etc.) used for an
10 * icon. The Icon may scale or not and of course... support alpha
13 * Signals that you can add callbacks for are:
15 * clicked - This is called when a user has clicked the image
19 typedef struct _Widget_Data Widget_Data;
24 Eina_Bool scale_up : 1;
25 Eina_Bool scale_down : 1;
27 Eina_Bool fill_outside : 1;
28 Eina_Bool no_scale : 1;
31 static const char *widtype = NULL;
32 static void _del_hook(Evas_Object *obj);
33 static void _theme_hook(Evas_Object *obj);
34 static void _sizing_eval(Evas_Object *obj);
35 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
38 _del_hook(Evas_Object *obj)
40 Widget_Data *wd = elm_widget_data_get(obj);
47 _del_pre_hook(Evas_Object *obj)
49 Widget_Data *wd = elm_widget_data_get(obj);
52 evas_object_del(wd->img);
56 _theme_hook(Evas_Object *obj)
58 Widget_Data *wd = elm_widget_data_get(obj);
65 _sizing_eval(Evas_Object *obj)
67 Widget_Data *wd = elm_widget_data_get(obj);
68 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
72 _els_smart_icon_size_get(wd->img, &w, &h);
73 _els_smart_icon_scale_up_set(wd->img, wd->scale_up);
74 _els_smart_icon_scale_down_set(wd->img, wd->scale_down);
75 _els_smart_icon_smooth_scale_set(wd->img, wd->smooth);
76 _els_smart_icon_fill_inside_set(wd->img, !(wd->fill_outside));
77 if (wd->no_scale) _els_smart_icon_scale_set(wd->img, 1.0);
80 _els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) * _elm_config->scale);
81 _els_smart_icon_size_get(wd->img, &w, &h);
93 evas_object_size_hint_min_set(obj, minw, minh);
94 evas_object_size_hint_max_set(obj, maxw, maxh);
98 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
100 evas_object_smart_callback_call(data, "clicked", NULL);
104 * Add a new image to the parent
106 * @param parent The parent object
107 * @return The new object or NULL if it cannot be created
112 elm_image_add(Evas_Object *parent)
118 wd = ELM_NEW(Widget_Data);
119 e = evas_object_evas_get(parent);
120 obj = elm_widget_add(e);
121 ELM_SET_WIDTYPE(widtype, "image");
122 elm_widget_type_set(obj, "image");
123 elm_widget_sub_object_add(parent, obj);
124 elm_widget_data_set(obj, wd);
125 elm_widget_del_hook_set(obj, _del_hook);
126 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
127 elm_widget_theme_hook_set(obj, _theme_hook);
128 elm_widget_can_focus_set(obj, 0);
130 wd->img = _els_smart_icon_add(e);
131 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
133 evas_object_repeat_events_set(wd->img, 1);
134 elm_widget_resize_object_set(obj, wd->img);
136 wd->smooth = EINA_TRUE;
137 wd->scale_up = EINA_TRUE;
138 wd->scale_down = EINA_TRUE;
140 _els_smart_icon_scale_size_set(wd->img, 0);
147 * Set the file that will be used as image
149 * @param obj The image object
150 * @param file The path to file that will be used as image
151 * @param group The group that the image belongs in edje file
153 * @return (1 = sucess, 0 = error)
158 elm_image_file_set(Evas_Object *obj, const char *file, const char *group)
160 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
161 Widget_Data *wd = elm_widget_data_get(obj);
165 if ((!wd) || (!file)) return EINA_FALSE;
166 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
167 ret = _els_smart_icon_file_edje_set(wd->img, file, group);
169 ret = _els_smart_icon_file_key_set(wd->img, file, group);
175 * Set the smooth effect for a image
177 * @param obj The image object
178 * @param smooth A bool to set (or no) smooth effect
179 * (1 = smooth, 0 = not smooth)
184 elm_image_smooth_set(Evas_Object *obj, Eina_Bool smooth)
186 ELM_CHECK_WIDTYPE(obj, widtype);
187 Widget_Data *wd = elm_widget_data_get(obj);
195 elm_image_object_size_get(const Evas_Object *obj, int *w, int *h)
197 ELM_CHECK_WIDTYPE(obj, widtype);
198 Widget_Data *wd = elm_widget_data_get(obj);
201 _els_smart_icon_size_get(wd->img, w, h);
205 * Set if the object are scalable
207 * @param obj The image object.
208 * @param no_scale A bool to set scale (or no).
209 * (1 = no_scale, 0 = scale)
214 elm_image_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
216 ELM_CHECK_WIDTYPE(obj, widtype);
217 Widget_Data *wd = elm_widget_data_get(obj);
220 wd->no_scale = no_scale;
226 * Set if the object is (up/down) scalable
228 * @param obj The image object
229 * @param scale_up A bool to set if the object is scalable up
230 * @param scale_down A bool to set if the object is scalable down
235 elm_image_scale_set(Evas_Object *obj, Eina_Bool scale_up, Eina_Bool scale_down)
237 ELM_CHECK_WIDTYPE(obj, widtype);
238 Widget_Data *wd = elm_widget_data_get(obj);
241 wd->scale_up = scale_up;
242 wd->scale_down = scale_down;
247 * Set if the object is filled outside
249 * @param obj The image object
250 * @param fill_outside A bool to set if the object is filled outside
251 * (1 = filled, 0 = no filled)
256 elm_image_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
258 ELM_CHECK_WIDTYPE(obj, widtype);
259 Widget_Data *wd = elm_widget_data_get(obj);
262 wd->fill_outside = fill_outside;
267 * Set the prescale size for the image
269 * @param obj The image object
270 * @param size The prescale size
275 elm_image_prescale_set(Evas_Object *obj, int size)
277 ELM_CHECK_WIDTYPE(obj, widtype);
278 Widget_Data *wd = elm_widget_data_get(obj);
281 _els_smart_icon_scale_size_set(wd->img, size);
285 * Set the image orient
287 * @param obj The image object
288 * @param orient The image orient
289 * (ELM_IMAGE_ORIENT_NONE, ELM_IMAGE_ROTATE_90_CW,
290 * ELM_IMAGE_ROTATE_180_CW, ELM_IMAGE_ROTATE_90_CCW,
291 * ELM_IMAGE_FLIP_HORIZONTAL,ELM_IMAGE_FLIP_VERTICAL,
292 * ELM_IMAGE_FLIP_TRANSPOSE, ELM_IMAGE_FLIP_TRANSVERSE)
297 elm_image_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
299 ELM_CHECK_WIDTYPE(obj, widtype);
300 Widget_Data *wd = elm_widget_data_get(obj);
303 _els_smart_icon_orient_set(wd->img, orient);