2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2,t0,(0
4 #include <Elementary.h>
8 * @defgroup Image Image
11 * A standard image that may be provided by the theme (delete, edit,
12 * arrows etc.) or a custom file (PNG, JPG, EDJE etc.) used for an
13 * icon. The Icon may scale or not and of course... support alpha
16 * Signals that you can add callbacks for are:
18 * clicked - This is called when a user has clicked the image
22 typedef struct _Widget_Data Widget_Data;
27 Eina_Bool scale_up : 1;
28 Eina_Bool scale_down : 1;
30 Eina_Bool fill_outside : 1;
31 Eina_Bool no_scale : 1;
34 static const char *widtype = NULL;
35 static void _del_hook(Evas_Object *obj);
36 static void _theme_hook(Evas_Object *obj);
37 static void _sizing_eval(Evas_Object *obj);
38 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
41 _del_hook(Evas_Object *obj)
43 Widget_Data *wd = elm_widget_data_get(obj);
50 _del_pre_hook(Evas_Object *obj)
52 Widget_Data *wd = elm_widget_data_get(obj);
55 evas_object_del(wd->img);
59 _theme_hook(Evas_Object *obj)
61 Widget_Data *wd = elm_widget_data_get(obj);
68 _sizing_eval(Evas_Object *obj)
70 Widget_Data *wd = elm_widget_data_get(obj);
71 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
75 _els_smart_icon_size_get(wd->img, &w, &h);
76 _els_smart_icon_scale_up_set(wd->img, wd->scale_up);
77 _els_smart_icon_scale_down_set(wd->img, wd->scale_down);
78 _els_smart_icon_smooth_scale_set(wd->img, wd->smooth);
79 _els_smart_icon_fill_inside_set(wd->img, !(wd->fill_outside));
80 if (wd->no_scale) _els_smart_icon_scale_set(wd->img, 1.0);
83 _els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) * _elm_config->scale);
84 _els_smart_icon_size_get(wd->img, &w, &h);
96 evas_object_size_hint_min_set(obj, minw, minh);
97 evas_object_size_hint_max_set(obj, maxw, maxh);
101 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
103 evas_object_smart_callback_call(data, "clicked", NULL);
107 * Add a new image to the parent
109 * @param parent The parent object
110 * @return The new object or NULL if it cannot be created
115 elm_image_add(Evas_Object *parent)
121 wd = ELM_NEW(Widget_Data);
122 e = evas_object_evas_get(parent);
123 obj = elm_widget_add(e);
124 ELM_SET_WIDTYPE(widtype, "image");
125 elm_widget_type_set(obj, "image");
126 elm_widget_sub_object_add(parent, obj);
127 elm_widget_data_set(obj, wd);
128 elm_widget_del_hook_set(obj, _del_hook);
129 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
130 elm_widget_theme_hook_set(obj, _theme_hook);
131 elm_widget_can_focus_set(obj, 0);
133 wd->img = _els_smart_icon_add(e);
134 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
136 evas_object_repeat_events_set(wd->img, 1);
137 elm_widget_resize_object_set(obj, wd->img);
139 wd->smooth = EINA_TRUE;
140 wd->scale_up = EINA_TRUE;
141 wd->scale_down = EINA_TRUE;
143 _els_smart_icon_scale_size_set(wd->img, 0);
150 * Set the file that will be used as image
152 * @param obj The image object
153 * @param file The path to file that will be used as image
154 * @param group The group that the image belongs in edje file
156 * @return (1 = sucess, 0 = error)
161 elm_image_file_set(Evas_Object *obj, const char *file, const char *group)
163 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
164 Widget_Data *wd = elm_widget_data_get(obj);
168 if ((!wd) || (!file)) return EINA_FALSE;
169 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
170 ret = _els_smart_icon_file_edje_set(wd->img, file, group);
172 ret = _els_smart_icon_file_key_set(wd->img, file, group);
178 * Set the smooth effect for a image
180 * @param obj The image object
181 * @param smooth A bool to set (or no) smooth effect
182 * (1 = smooth, 0 = not smooth)
187 elm_image_smooth_set(Evas_Object *obj, Eina_Bool smooth)
189 ELM_CHECK_WIDTYPE(obj, widtype);
190 Widget_Data *wd = elm_widget_data_get(obj);
198 elm_image_object_size_get(const Evas_Object *obj, int *w, int *h)
200 ELM_CHECK_WIDTYPE(obj, widtype);
201 Widget_Data *wd = elm_widget_data_get(obj);
204 _els_smart_icon_size_get(wd->img, w, h);
208 * Set if the object are scalable
210 * @param obj The image object.
211 * @param no_scale A bool to set scale (or no).
212 * (1 = no_scale, 0 = scale)
217 elm_image_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
219 ELM_CHECK_WIDTYPE(obj, widtype);
220 Widget_Data *wd = elm_widget_data_get(obj);
223 wd->no_scale = no_scale;
229 * Set if the object is (up/down) scalable
231 * @param obj The image object
232 * @param scale_up A bool to set if the object is scalable up
233 * @param scale_down A bool to set if the object is scalable down
238 elm_image_scale_set(Evas_Object *obj, Eina_Bool scale_up, Eina_Bool scale_down)
240 ELM_CHECK_WIDTYPE(obj, widtype);
241 Widget_Data *wd = elm_widget_data_get(obj);
244 wd->scale_up = scale_up;
245 wd->scale_down = scale_down;
250 * Set if the object is filled outside
252 * @param obj The image object
253 * @param fill_outside A bool to set if the object is filled outside
254 * (1 = filled, 0 = no filled)
259 elm_image_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
261 ELM_CHECK_WIDTYPE(obj, widtype);
262 Widget_Data *wd = elm_widget_data_get(obj);
265 wd->fill_outside = fill_outside;
270 * Set the prescale size for the image
272 * @param obj The image object
273 * @param size The prescale size
278 elm_image_prescale_set(Evas_Object *obj, int size)
280 ELM_CHECK_WIDTYPE(obj, widtype);
281 Widget_Data *wd = elm_widget_data_get(obj);
284 _els_smart_icon_scale_size_set(wd->img, size);
288 * Set the image orient
290 * @param obj The image object
291 * @param orient The image orient
292 * (ELM_IMAGE_ORIENT_NONE, ELM_IMAGE_ROTATE_90_CW,
293 * ELM_IMAGE_ROTATE_180_CW, ELM_IMAGE_ROTATE_90_CCW,
294 * ELM_IMAGE_FLIP_HORIZONTAL,ELM_IMAGE_FLIP_VERTICAL,
295 * ELM_IMAGE_FLIP_TRANSPOSE, ELM_IMAGE_FLIP_TRANSVERSE)
300 elm_image_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
302 ELM_CHECK_WIDTYPE(obj, widtype);
303 Widget_Data *wd = elm_widget_data_get(obj);
306 _els_smart_icon_orient_set(wd->img, orient);