summaryrefslogtreecommitdiff
path: root/src/lib/elementary/efl_ui_bg_widget.c
diff options
context:
space:
mode:
authorSungtaek Hong <sth253.hong@samsung.com>2017-12-12 20:05:55 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-12-18 20:49:45 +0900
commit81ba035f6935128b2c025c88de05cf2b8f2c0ead (patch)
tree88723c9159619125da71b8a8ad9089e53c41cb7d /src/lib/elementary/efl_ui_bg_widget.c
parent25136ddf8ccbf384b21d89a7ce3939c1d4db00a6 (diff)
efl_ui_bg_widget: replace internal image to efl_ui_image
Diffstat (limited to 'src/lib/elementary/efl_ui_bg_widget.c')
-rw-r--r--src/lib/elementary/efl_ui_bg_widget.c277
1 files changed, 87 insertions, 190 deletions
diff --git a/src/lib/elementary/efl_ui_bg_widget.c b/src/lib/elementary/efl_ui_bg_widget.c
index d1e1c73..5c39790 100644
--- a/src/lib/elementary/efl_ui_bg_widget.c
+++ b/src/lib/elementary/efl_ui_bg_widget.c
@@ -21,78 +21,6 @@ static const Elm_Layout_Part_Alias_Description _content_aliases[] =
21 {NULL, NULL} 21 {NULL, NULL}
22}; 22};
23 23
24EOLIAN static void
25_efl_ui_bg_widget_elm_layout_sizing_eval(Eo *obj, Efl_Ui_Bg_Widget_Data *sd)
26{
27 Evas_Coord iw = 0, ih = 0, mw = -1, mh = -1;
28 Evas_Coord bx = 0, by = 0, bw = 0, bh = 0;
29 Evas_Coord fx = 0, fy = 0, fw = 0, fh = 0;
30 const char *p;
31
32 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
33
34 if ((!sd->img) || (!sd->file)) return;
35 if (((p = strrchr(sd->file, '.'))) && (!strcasecmp(p, ".edj"))) return;
36
37 /* grab image size */
38 evas_object_image_size_get(sd->img, &iw, &ih);
39 if ((iw < 1) || (ih < 1)) return;
40
41 /* grab base object dimensions */
42 evas_object_geometry_get
43 (wd->resize_obj, &bx, &by, &bw, &bh);
44
45 switch (sd->scale_type)
46 {
47 case EFL_IMAGE_SCALE_TYPE_NONE:
48 fw = mw = iw;
49 fh = mh = ih;
50 break;
51 case EFL_IMAGE_SCALE_TYPE_FILL:
52 fw = bw;
53 fh = bh;
54 break;
55 case EFL_IMAGE_SCALE_TYPE_FIT_INSIDE:
56 mw = fw = bw;
57 mh = fh = ((ih * fw) / iw);
58 if (fh > bh)
59 {
60 mh = fh = bh;
61 mw = fw = ((iw * fh) / ih);
62 }
63 break;
64 case EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE:
65 fw = bw;
66 fh = ((ih * fw) / iw);
67 if (fh < bh)
68 {
69 fh = bh;
70 fw = ((iw * fh) / ih);
71 }
72 fx = ((bw - fw) / 2);
73 fy = ((bh - fh) / 2);
74 break;
75 case EFL_IMAGE_SCALE_TYPE_TILE:
76 fw = iw;
77 fh = ih;
78 break;
79 }
80
81 evas_object_image_fill_set(sd->img, fx, fy, fw, fh);
82
83 evas_object_size_hint_min_set(sd->img, mw, mh);
84 evas_object_size_hint_max_set(sd->img, mw, mh);
85}
86
87static void
88_on_resize(void *data,
89 Evas *e EINA_UNUSED,
90 Evas_Object *obj EINA_UNUSED,
91 void *event_info EINA_UNUSED)
92{
93 elm_layout_sizing_eval(data);
94}
95
96EAPI Evas_Object * 24EAPI Evas_Object *
97elm_bg_add(Evas_Object *parent) 25elm_bg_add(Evas_Object *parent)
98{ 26{
@@ -111,7 +39,6 @@ _efl_ui_bg_widget_efl_object_constructor(Eo *obj, Efl_Ui_Bg_Widget_Data *pd)
111 obj = efl_constructor(efl_super(obj, MY_CLASS)); 39 obj = efl_constructor(efl_super(obj, MY_CLASS));
112 elm_widget_sub_object_parent_add(obj); 40 elm_widget_sub_object_parent_add(obj);
113 elm_widget_can_focus_set(obj, EINA_FALSE); 41 elm_widget_can_focus_set(obj, EINA_FALSE);
114 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _on_resize, obj);
115 42
116 if (!elm_widget_theme_object_set(obj, wd->resize_obj, 43 if (!elm_widget_theme_object_set(obj, wd->resize_obj,
117 elm_widget_theme_klass_get(obj), 44 elm_widget_theme_klass_get(obj),
@@ -119,11 +46,14 @@ _efl_ui_bg_widget_efl_object_constructor(Eo *obj, Efl_Ui_Bg_Widget_Data *pd)
119 elm_widget_theme_style_get(obj))) 46 elm_widget_theme_style_get(obj)))
120 CRI("Failed to set layout!"); 47 CRI("Failed to set layout!");
121 48
122 pd->scale_type = EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE;
123 pd->rect = efl_add(EFL_CANVAS_RECTANGLE_CLASS, obj, 49 pd->rect = efl_add(EFL_CANVAS_RECTANGLE_CLASS, obj,
124 efl_gfx_color_set(efl_added, 0, 0, 0, 0), 50 efl_gfx_color_set(efl_added, 0, 0, 0, 0),
125 efl_content_set(efl_part(obj, "elm.swallow.rectangle"), efl_added)); 51 efl_content_set(efl_part(obj, "elm.swallow.rectangle"), efl_added));
126 52
53 pd->img = efl_add(EFL_UI_IMAGE_CLASS, obj,
54 efl_image_scale_type_set(efl_added, EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE),
55 efl_content_set(efl_part(obj, "elm.swallow.background"), efl_added));
56
127 efl_canvas_object_type_set(obj, MY_CLASS_NAME_LEGACY); 57 efl_canvas_object_type_set(obj, MY_CLASS_NAME_LEGACY);
128 efl_access_type_set(obj, EFL_ACCESS_TYPE_DISABLED); 58 efl_access_type_set(obj, EFL_ACCESS_TYPE_DISABLED);
129 59
@@ -132,134 +62,72 @@ _efl_ui_bg_widget_efl_object_constructor(Eo *obj, Efl_Ui_Bg_Widget_Data *pd)
132 return obj; 62 return obj;
133} 63}
134 64
135EOLIAN static Eina_Bool 65EAPI void
136_efl_ui_bg_widget_efl_file_file_set(Eo *obj, Efl_Ui_Bg_Widget_Data *sd, const char *file, const char *group) 66elm_bg_option_set(Evas_Object *obj, Elm_Bg_Option option)
137{ 67{
138 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE); 68 Efl_Image_Scale_Type type;
139
140 const char *p;
141 Eina_Bool int_ret;
142 69
143 ELM_SAFE_FREE(sd->img, evas_object_del); 70 switch (option)
144 if (!file)
145 {
146 ELM_SAFE_FREE(sd->file, eina_stringshare_del);
147 ELM_SAFE_FREE(sd->group, eina_stringshare_del);
148 return EINA_TRUE;
149 }
150 eina_stringshare_replace(&sd->file, file);
151 eina_stringshare_replace(&sd->group, group);
152 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
153 { 71 {
154 sd->img = edje_object_add 72 case ELM_BG_OPTION_CENTER:
155 (evas_object_evas_get(wd->resize_obj)); 73 type = EFL_IMAGE_SCALE_TYPE_NONE;
156 int_ret = edje_object_file_set(sd->img, file, group); 74 break;
157 } 75 case ELM_BG_OPTION_SCALE:
158 else 76 type = EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE;
159 { 77 break;
160 int err; 78 case ELM_BG_OPTION_TILE:
161 79 type = EFL_IMAGE_SCALE_TYPE_TILE;
162 sd->img = evas_object_image_add 80 break;
163 (evas_object_evas_get(wd->resize_obj)); 81 case ELM_BG_OPTION_STRETCH:
164 evas_object_image_load_orientation_set(sd->img, EINA_TRUE); 82 type = EFL_IMAGE_SCALE_TYPE_FILL;
165 if ((sd->load_opts.w > 0) && (sd->load_opts.h > 0)) 83 break;
166 evas_object_image_load_size_set 84 case ELM_BG_OPTION_LAST:
167 (sd->img, sd->load_opts.w, sd->load_opts.h); 85 default:
168 evas_object_image_file_set(sd->img, file, group); 86 type = EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE;
169
170 err = evas_object_image_load_error_get(sd->img);
171 if (err != EVAS_LOAD_ERROR_NONE)
172 {
173 ERR("Could not load image '%s': %s",
174 file, evas_load_error_str(err));
175 int_ret = EINA_FALSE;
176 }
177 else
178 int_ret = EINA_TRUE;
179 } 87 }
180 88 efl_image_scale_type_set(obj, type);
181 evas_object_repeat_events_set(sd->img, EINA_TRUE);
182
183 int_ret &= elm_layout_content_set(obj, "elm.swallow.background", sd->img);
184
185 elm_layout_sizing_eval(obj);
186
187 return int_ret;
188} 89}
189 90
190EOLIAN static void 91EAPI Elm_Bg_Option
191_efl_ui_bg_widget_efl_file_file_get(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd, const char **file, const char **group) 92elm_bg_option_get(const Evas_Object *obj)
192{ 93{
193 if (file) *file = sd->file; 94 Efl_Image_Scale_Type type;
194 if (group) *group = sd->group; 95 Elm_Bg_Option option = ELM_BG_OPTION_LAST;
195}
196 96
197EAPI void 97 type = efl_image_scale_type_get(obj);
198elm_bg_option_set(Evas_Object *obj, Elm_Bg_Option option) 98 switch (type)
199{ 99 {
200 EFL_UI_BG_WIDGET_DATA_GET(obj, sd); 100 case EFL_IMAGE_SCALE_TYPE_NONE:
201 switch (option) 101 option = ELM_BG_OPTION_CENTER;
202 {
203 case ELM_BG_OPTION_CENTER:
204 sd->scale_type = EFL_IMAGE_SCALE_TYPE_NONE;
205 break;
206 case ELM_BG_OPTION_SCALE:
207 sd->scale_type = EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE;
208 break;
209 case ELM_BG_OPTION_TILE:
210 sd->scale_type = EFL_IMAGE_SCALE_TYPE_TILE;
211 break; 102 break;
212 case ELM_BG_OPTION_STRETCH: 103 case EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE:
213 sd->scale_type = EFL_IMAGE_SCALE_TYPE_FILL; 104 option = ELM_BG_OPTION_SCALE;
214 break; 105 break;
215 case ELM_BG_OPTION_LAST: 106 case EFL_IMAGE_SCALE_TYPE_TILE:
216 default: 107 option = ELM_BG_OPTION_TILE;
217 sd->scale_type = EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE; 108 break;
218 } 109 case EFL_IMAGE_SCALE_TYPE_FILL:
110 option = ELM_BG_OPTION_STRETCH;
111 break;
112 case EFL_IMAGE_SCALE_TYPE_FIT_INSIDE:
113 default:
114 ERR("Scale type %d cannot be converted to Elm_Bg_Option", type);
115 break;
116 }
219 117
220 elm_layout_sizing_eval(obj); 118 return option;
221}
222
223EAPI Elm_Bg_Option
224elm_bg_option_get(const Evas_Object *obj)
225{
226 Elm_Bg_Option option = ELM_BG_OPTION_LAST;
227 EFL_UI_BG_WIDGET_DATA_GET(obj, sd);
228
229 switch (sd->scale_type)
230 {
231 case EFL_IMAGE_SCALE_TYPE_NONE:
232 option = ELM_BG_OPTION_CENTER;
233 break;
234 case EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE:
235 option = ELM_BG_OPTION_SCALE;
236 break;
237 case EFL_IMAGE_SCALE_TYPE_TILE:
238 option = ELM_BG_OPTION_TILE;
239 break;
240 case EFL_IMAGE_SCALE_TYPE_FILL:
241 option = ELM_BG_OPTION_STRETCH;
242 break;
243 case EFL_IMAGE_SCALE_TYPE_FIT_INSIDE:
244 default:
245 ERR("Scale type %d cannot be converted to Elm_Bg_Option", sd->scale_type);
246 break;
247 }
248 return option;
249} 119}
250 120
251EOLIAN static void 121EOLIAN static void
252_efl_ui_bg_widget_efl_image_scale_type_set(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd, Efl_Image_Scale_Type scale_type) 122_efl_ui_bg_widget_efl_image_scale_type_set(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd, Efl_Image_Scale_Type scale_type)
253{ 123{
254 sd->scale_type = scale_type; 124 efl_image_scale_type_set(sd->img, scale_type);
255
256 elm_layout_sizing_eval(obj);
257} 125}
258 126
259EOLIAN static Efl_Image_Scale_Type 127EOLIAN static Efl_Image_Scale_Type
260_efl_ui_bg_widget_efl_image_scale_type_get(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd) 128_efl_ui_bg_widget_efl_image_scale_type_get(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd)
261{ 129{
262 return sd->scale_type; 130 return efl_image_scale_type_get(sd->img);
263} 131}
264 132
265EAPI void 133EAPI void
@@ -307,15 +175,20 @@ _efl_ui_bg_widget_efl_gfx_color_get(Eo *obj, Efl_Ui_Bg_Widget_Data *sd, int *r,
307EAPI void 175EAPI void
308elm_bg_load_size_set(Evas_Object *obj, int w, int h) 176elm_bg_load_size_set(Evas_Object *obj, int w, int h)
309{ 177{
310 const char *p; 178 EFL_UI_BG_WIDGET_DATA_GET_OR_RETURN(obj, sd);
311 EFL_UI_BG_WIDGET_DATA_GET(obj, sd); 179 efl_image_load_size_set(sd->img, EINA_SIZE2D(w, h));
180}
312 181
313 sd->load_opts.w = w; 182EOLIAN static void
314 sd->load_opts.h = h; 183_efl_ui_bg_widget_efl_image_load_load_size_set(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd, Eina_Size2D sz)
315 if (!sd->img) return; 184{
185 efl_image_load_size_set(sd->img, sz);
186}
316 187
317 if (!(((p = strrchr(sd->file, '.'))) && (!strcasecmp(p, ".edj")))) 188EOLIAN static Eina_Size2D
318 evas_object_image_load_size_set(sd->img, w, h); 189_efl_ui_bg_widget_efl_image_load_load_size_get(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd)
190{
191 return efl_image_load_size_get(sd->img);
319} 192}
320 193
321static void 194static void
@@ -330,18 +203,42 @@ elm_bg_file_set(Eo *obj, const char *file, const char *group)
330 return efl_file_set((Eo *) obj, file, group); 203 return efl_file_set((Eo *) obj, file, group);
331} 204}
332 205
206EOLIAN static Eina_Bool
207_efl_ui_bg_widget_efl_file_file_set(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd, const char *file, const char *key)
208{
209 return efl_file_set(sd->img, file, key);
210}
333EAPI void 211EAPI void
334elm_bg_file_get(const Eo *obj, const char **file, const char **group) 212elm_bg_file_get(const Eo *obj, const char **file, const char **group)
335{ 213{
336 efl_file_get((Eo *) obj, file, group); 214 efl_file_get((Eo *) obj, file, group);
337} 215}
338 216
217EOLIAN static void
218_efl_ui_bg_widget_efl_file_file_get(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd, const char **file, const char **key)
219{
220 efl_file_get(sd->img, file, key);
221}
222
223EOLIAN static Eina_Bool
224_efl_ui_bg_widget_efl_file_mmap_set(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd,
225 const Eina_File *file, const char *key)
226{
227 return efl_file_mmap_set(sd->img, file, key);
228}
229
230EOLIAN static void
231_efl_ui_bg_widget_efl_file_mmap_get(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd,
232 const Eina_File **file, const char **key)
233{
234 efl_file_mmap_get(sd->img, file, key);
235}
236
339/* Internal EO APIs and hidden overrides */ 237/* Internal EO APIs and hidden overrides */
340 238
341ELM_LAYOUT_CONTENT_ALIASES_IMPLEMENT(MY_CLASS_PFX) 239ELM_LAYOUT_CONTENT_ALIASES_IMPLEMENT(MY_CLASS_PFX)
342 240
343#define EFL_UI_BG_WIDGET_EXTRA_OPS \ 241#define EFL_UI_BG_WIDGET_EXTRA_OPS \
344 ELM_LAYOUT_CONTENT_ALIASES_OPS(MY_CLASS_PFX), \ 242 ELM_LAYOUT_CONTENT_ALIASES_OPS(MY_CLASS_PFX)
345 ELM_LAYOUT_SIZING_EVAL_OPS(efl_ui_bg_widget)
346 243
347#include "efl_ui_bg_widget.eo.c" 244#include "efl_ui_bg_widget.eo.c"