summaryrefslogtreecommitdiff
path: root/src/lib/elementary/efl_ui_bg_widget.c
diff options
context:
space:
mode:
authorSungtaek Hong <sth253.hong@samsung.com>2017-12-18 13:55:25 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-12-18 20:49:45 +0900
commit25136ddf8ccbf384b21d89a7ce3939c1d4db00a6 (patch)
tree4d467b7a2abcfc727e5dbb288c77218178530e9f /src/lib/elementary/efl_ui_bg_widget.c
parent147ef4f91deb99d44c67cbb37fa737d42d8a1792 (diff)
efl_ui_bg: add Efl.Ui.Bg interface
Summary: - Previous class efl_ui_bg moved to efl_ui_bg_widget. - Scale_type moved to efl_image from efl_ui_image. - Previous enum Efl_Ui_Image_Scale_Type moved to Efl_Image_Scale_Type. Test Plan: Run elementary_test 1.Image Scale Type 2.Efl.Ui.Bg 3.Efl.Ui.Win 4.Part Background Reviewers: jpeg, woohyun, cedric Differential Revision: https://phab.enlightenment.org/D5616
Diffstat (limited to 'src/lib/elementary/efl_ui_bg_widget.c')
-rw-r--r--src/lib/elementary/efl_ui_bg_widget.c347
1 files changed, 347 insertions, 0 deletions
diff --git a/src/lib/elementary/efl_ui_bg_widget.c b/src/lib/elementary/efl_ui_bg_widget.c
new file mode 100644
index 0000000..d1e1c73
--- /dev/null
+++ b/src/lib/elementary/efl_ui_bg_widget.c
@@ -0,0 +1,347 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#define EFL_ACCESS_PROTECTED
6#define ELM_LAYOUT_PROTECTED
7
8#include <Elementary.h>
9#include "elm_priv.h"
10#include "efl_ui_bg_widget_private.h"
11
12#define MY_CLASS EFL_UI_BG_WIDGET_CLASS
13#define MY_CLASS_PFX efl_ui_bg_widget
14
15#define MY_CLASS_NAME "Efl.Ui.Bg_Widget"
16#define MY_CLASS_NAME_LEGACY "elm_bg"
17
18static const Elm_Layout_Part_Alias_Description _content_aliases[] =
19{
20 {"overlay", "elm.swallow.content"},
21 {NULL, NULL}
22};
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 *
97elm_bg_add(Evas_Object *parent)
98{
99 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
100 return elm_legacy_add(MY_CLASS, parent);
101}
102
103EOLIAN static Eo *
104_efl_ui_bg_widget_efl_object_constructor(Eo *obj, Efl_Ui_Bg_Widget_Data *pd)
105{
106 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, NULL);
107
108 if (!elm_widget_theme_klass_get(obj))
109 elm_widget_theme_klass_set(obj, "bg");
110
111 obj = efl_constructor(efl_super(obj, MY_CLASS));
112 elm_widget_sub_object_parent_add(obj);
113 elm_widget_can_focus_set(obj, EINA_FALSE);
114 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _on_resize, obj);
115
116 if (!elm_widget_theme_object_set(obj, wd->resize_obj,
117 elm_widget_theme_klass_get(obj),
118 elm_widget_theme_element_get(obj),
119 elm_widget_theme_style_get(obj)))
120 CRI("Failed to set layout!");
121
122 pd->scale_type = EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE;
123 pd->rect = efl_add(EFL_CANVAS_RECTANGLE_CLASS, obj,
124 efl_gfx_color_set(efl_added, 0, 0, 0, 0),
125 efl_content_set(efl_part(obj, "elm.swallow.rectangle"), efl_added));
126
127 efl_canvas_object_type_set(obj, MY_CLASS_NAME_LEGACY);
128 efl_access_type_set(obj, EFL_ACCESS_TYPE_DISABLED);
129
130 efl_ui_widget_focus_allow_set(obj, EINA_FALSE);
131
132 return obj;
133}
134
135EOLIAN static Eina_Bool
136_efl_ui_bg_widget_efl_file_file_set(Eo *obj, Efl_Ui_Bg_Widget_Data *sd, const char *file, const char *group)
137{
138 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE);
139
140 const char *p;
141 Eina_Bool int_ret;
142
143 ELM_SAFE_FREE(sd->img, evas_object_del);
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 {
154 sd->img = edje_object_add
155 (evas_object_evas_get(wd->resize_obj));
156 int_ret = edje_object_file_set(sd->img, file, group);
157 }
158 else
159 {
160 int err;
161
162 sd->img = evas_object_image_add
163 (evas_object_evas_get(wd->resize_obj));
164 evas_object_image_load_orientation_set(sd->img, EINA_TRUE);
165 if ((sd->load_opts.w > 0) && (sd->load_opts.h > 0))
166 evas_object_image_load_size_set
167 (sd->img, sd->load_opts.w, sd->load_opts.h);
168 evas_object_image_file_set(sd->img, file, group);
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 }
180
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}
189
190EOLIAN static void
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)
192{
193 if (file) *file = sd->file;
194 if (group) *group = sd->group;
195}
196
197EAPI void
198elm_bg_option_set(Evas_Object *obj, Elm_Bg_Option option)
199{
200 EFL_UI_BG_WIDGET_DATA_GET(obj, sd);
201 switch (option)
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;
212 case ELM_BG_OPTION_STRETCH:
213 sd->scale_type = EFL_IMAGE_SCALE_TYPE_FILL;
214 break;
215 case ELM_BG_OPTION_LAST:
216 default:
217 sd->scale_type = EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE;
218 }
219
220 elm_layout_sizing_eval(obj);
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}
250
251EOLIAN 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)
253{
254 sd->scale_type = scale_type;
255
256 elm_layout_sizing_eval(obj);
257}
258
259EOLIAN 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)
261{
262 return sd->scale_type;
263}
264
265EAPI void
266elm_bg_color_set(Evas_Object *obj,
267 int r,
268 int g,
269 int b)
270{
271 int a = 255;
272 EFL_UI_BG_WIDGET_CHECK(obj);
273
274 // reset color
275 if ((r == -1) && (g == -1) && (b == -1))
276 {
277 r = g = b = a = 0;
278 }
279 efl_gfx_color_set(obj, r, g, b, a);
280}
281
282EOLIAN static void
283_efl_ui_bg_widget_efl_gfx_color_set(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd, int r, int g, int b, int a)
284{
285 efl_gfx_color_set(sd->rect, r, g, b, a);
286}
287
288EAPI void
289elm_bg_color_get(const Evas_Object *obj,
290 int *r,
291 int *g,
292 int *b)
293{
294 EFL_UI_BG_WIDGET_CHECK(obj);
295 efl_gfx_color_get((Eo *) obj, r, g, b, NULL);
296}
297
298EOLIAN static void
299_efl_ui_bg_widget_efl_gfx_color_get(Eo *obj, Efl_Ui_Bg_Widget_Data *sd, int *r, int *g, int *b, int *a)
300{
301 if (!sd->rect)
302 efl_gfx_color_get(efl_super(obj, MY_CLASS), r, g, b, a);
303 else
304 efl_gfx_color_get(sd->rect, r, g, b, a);
305}
306
307EAPI void
308elm_bg_load_size_set(Evas_Object *obj, int w, int h)
309{
310 const char *p;
311 EFL_UI_BG_WIDGET_DATA_GET(obj, sd);
312
313 sd->load_opts.w = w;
314 sd->load_opts.h = h;
315 if (!sd->img) return;
316
317 if (!(((p = strrchr(sd->file, '.'))) && (!strcasecmp(p, ".edj"))))
318 evas_object_image_load_size_set(sd->img, w, h);
319}
320
321static void
322_efl_ui_bg_widget_class_constructor(Efl_Class *klass)
323{
324 evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
325}
326
327EAPI Eina_Bool
328elm_bg_file_set(Eo *obj, const char *file, const char *group)
329{
330 return efl_file_set((Eo *) obj, file, group);
331}
332
333EAPI void
334elm_bg_file_get(const Eo *obj, const char **file, const char **group)
335{
336 efl_file_get((Eo *) obj, file, group);
337}
338
339/* Internal EO APIs and hidden overrides */
340
341ELM_LAYOUT_CONTENT_ALIASES_IMPLEMENT(MY_CLASS_PFX)
342
343#define EFL_UI_BG_WIDGET_EXTRA_OPS \
344 ELM_LAYOUT_CONTENT_ALIASES_OPS(MY_CLASS_PFX), \
345 ELM_LAYOUT_SIZING_EVAL_OPS(efl_ui_bg_widget)
346
347#include "efl_ui_bg_widget.eo.c"