efl_ui_bg_widget: replace internal image to efl_ui_image
This commit is contained in:
parent
25136ddf8c
commit
81ba035f69
|
@ -21,78 +21,6 @@ static const Elm_Layout_Part_Alias_Description _content_aliases[] =
|
|||
{NULL, NULL}
|
||||
};
|
||||
|
||||
EOLIAN static void
|
||||
_efl_ui_bg_widget_elm_layout_sizing_eval(Eo *obj, Efl_Ui_Bg_Widget_Data *sd)
|
||||
{
|
||||
Evas_Coord iw = 0, ih = 0, mw = -1, mh = -1;
|
||||
Evas_Coord bx = 0, by = 0, bw = 0, bh = 0;
|
||||
Evas_Coord fx = 0, fy = 0, fw = 0, fh = 0;
|
||||
const char *p;
|
||||
|
||||
ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
|
||||
|
||||
if ((!sd->img) || (!sd->file)) return;
|
||||
if (((p = strrchr(sd->file, '.'))) && (!strcasecmp(p, ".edj"))) return;
|
||||
|
||||
/* grab image size */
|
||||
evas_object_image_size_get(sd->img, &iw, &ih);
|
||||
if ((iw < 1) || (ih < 1)) return;
|
||||
|
||||
/* grab base object dimensions */
|
||||
evas_object_geometry_get
|
||||
(wd->resize_obj, &bx, &by, &bw, &bh);
|
||||
|
||||
switch (sd->scale_type)
|
||||
{
|
||||
case EFL_IMAGE_SCALE_TYPE_NONE:
|
||||
fw = mw = iw;
|
||||
fh = mh = ih;
|
||||
break;
|
||||
case EFL_IMAGE_SCALE_TYPE_FILL:
|
||||
fw = bw;
|
||||
fh = bh;
|
||||
break;
|
||||
case EFL_IMAGE_SCALE_TYPE_FIT_INSIDE:
|
||||
mw = fw = bw;
|
||||
mh = fh = ((ih * fw) / iw);
|
||||
if (fh > bh)
|
||||
{
|
||||
mh = fh = bh;
|
||||
mw = fw = ((iw * fh) / ih);
|
||||
}
|
||||
break;
|
||||
case EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE:
|
||||
fw = bw;
|
||||
fh = ((ih * fw) / iw);
|
||||
if (fh < bh)
|
||||
{
|
||||
fh = bh;
|
||||
fw = ((iw * fh) / ih);
|
||||
}
|
||||
fx = ((bw - fw) / 2);
|
||||
fy = ((bh - fh) / 2);
|
||||
break;
|
||||
case EFL_IMAGE_SCALE_TYPE_TILE:
|
||||
fw = iw;
|
||||
fh = ih;
|
||||
break;
|
||||
}
|
||||
|
||||
evas_object_image_fill_set(sd->img, fx, fy, fw, fh);
|
||||
|
||||
evas_object_size_hint_min_set(sd->img, mw, mh);
|
||||
evas_object_size_hint_max_set(sd->img, mw, mh);
|
||||
}
|
||||
|
||||
static void
|
||||
_on_resize(void *data,
|
||||
Evas *e EINA_UNUSED,
|
||||
Evas_Object *obj EINA_UNUSED,
|
||||
void *event_info EINA_UNUSED)
|
||||
{
|
||||
elm_layout_sizing_eval(data);
|
||||
}
|
||||
|
||||
EAPI Evas_Object *
|
||||
elm_bg_add(Evas_Object *parent)
|
||||
{
|
||||
|
@ -111,7 +39,6 @@ _efl_ui_bg_widget_efl_object_constructor(Eo *obj, Efl_Ui_Bg_Widget_Data *pd)
|
|||
obj = efl_constructor(efl_super(obj, MY_CLASS));
|
||||
elm_widget_sub_object_parent_add(obj);
|
||||
elm_widget_can_focus_set(obj, EINA_FALSE);
|
||||
evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _on_resize, obj);
|
||||
|
||||
if (!elm_widget_theme_object_set(obj, wd->resize_obj,
|
||||
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)
|
|||
elm_widget_theme_style_get(obj)))
|
||||
CRI("Failed to set layout!");
|
||||
|
||||
pd->scale_type = EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE;
|
||||
pd->rect = efl_add(EFL_CANVAS_RECTANGLE_CLASS, obj,
|
||||
efl_gfx_color_set(efl_added, 0, 0, 0, 0),
|
||||
efl_content_set(efl_part(obj, "elm.swallow.rectangle"), efl_added));
|
||||
|
||||
pd->img = efl_add(EFL_UI_IMAGE_CLASS, obj,
|
||||
efl_image_scale_type_set(efl_added, EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE),
|
||||
efl_content_set(efl_part(obj, "elm.swallow.background"), efl_added));
|
||||
|
||||
efl_canvas_object_type_set(obj, MY_CLASS_NAME_LEGACY);
|
||||
efl_access_type_set(obj, EFL_ACCESS_TYPE_DISABLED);
|
||||
|
||||
|
@ -132,134 +62,72 @@ _efl_ui_bg_widget_efl_object_constructor(Eo *obj, Efl_Ui_Bg_Widget_Data *pd)
|
|||
return obj;
|
||||
}
|
||||
|
||||
EOLIAN static Eina_Bool
|
||||
_efl_ui_bg_widget_efl_file_file_set(Eo *obj, Efl_Ui_Bg_Widget_Data *sd, const char *file, const char *group)
|
||||
{
|
||||
ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE);
|
||||
|
||||
const char *p;
|
||||
Eina_Bool int_ret;
|
||||
|
||||
ELM_SAFE_FREE(sd->img, evas_object_del);
|
||||
if (!file)
|
||||
{
|
||||
ELM_SAFE_FREE(sd->file, eina_stringshare_del);
|
||||
ELM_SAFE_FREE(sd->group, eina_stringshare_del);
|
||||
return EINA_TRUE;
|
||||
}
|
||||
eina_stringshare_replace(&sd->file, file);
|
||||
eina_stringshare_replace(&sd->group, group);
|
||||
if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
|
||||
{
|
||||
sd->img = edje_object_add
|
||||
(evas_object_evas_get(wd->resize_obj));
|
||||
int_ret = edje_object_file_set(sd->img, file, group);
|
||||
}
|
||||
else
|
||||
{
|
||||
int err;
|
||||
|
||||
sd->img = evas_object_image_add
|
||||
(evas_object_evas_get(wd->resize_obj));
|
||||
evas_object_image_load_orientation_set(sd->img, EINA_TRUE);
|
||||
if ((sd->load_opts.w > 0) && (sd->load_opts.h > 0))
|
||||
evas_object_image_load_size_set
|
||||
(sd->img, sd->load_opts.w, sd->load_opts.h);
|
||||
evas_object_image_file_set(sd->img, file, group);
|
||||
|
||||
err = evas_object_image_load_error_get(sd->img);
|
||||
if (err != EVAS_LOAD_ERROR_NONE)
|
||||
{
|
||||
ERR("Could not load image '%s': %s",
|
||||
file, evas_load_error_str(err));
|
||||
int_ret = EINA_FALSE;
|
||||
}
|
||||
else
|
||||
int_ret = EINA_TRUE;
|
||||
}
|
||||
|
||||
evas_object_repeat_events_set(sd->img, EINA_TRUE);
|
||||
|
||||
int_ret &= elm_layout_content_set(obj, "elm.swallow.background", sd->img);
|
||||
|
||||
elm_layout_sizing_eval(obj);
|
||||
|
||||
return int_ret;
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_efl_ui_bg_widget_efl_file_file_get(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd, const char **file, const char **group)
|
||||
{
|
||||
if (file) *file = sd->file;
|
||||
if (group) *group = sd->group;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
elm_bg_option_set(Evas_Object *obj, Elm_Bg_Option option)
|
||||
{
|
||||
EFL_UI_BG_WIDGET_DATA_GET(obj, sd);
|
||||
switch (option)
|
||||
{
|
||||
case ELM_BG_OPTION_CENTER:
|
||||
sd->scale_type = EFL_IMAGE_SCALE_TYPE_NONE;
|
||||
break;
|
||||
case ELM_BG_OPTION_SCALE:
|
||||
sd->scale_type = EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE;
|
||||
break;
|
||||
case ELM_BG_OPTION_TILE:
|
||||
sd->scale_type = EFL_IMAGE_SCALE_TYPE_TILE;
|
||||
break;
|
||||
case ELM_BG_OPTION_STRETCH:
|
||||
sd->scale_type = EFL_IMAGE_SCALE_TYPE_FILL;
|
||||
break;
|
||||
case ELM_BG_OPTION_LAST:
|
||||
default:
|
||||
sd->scale_type = EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE;
|
||||
}
|
||||
Efl_Image_Scale_Type type;
|
||||
|
||||
elm_layout_sizing_eval(obj);
|
||||
switch (option)
|
||||
{
|
||||
case ELM_BG_OPTION_CENTER:
|
||||
type = EFL_IMAGE_SCALE_TYPE_NONE;
|
||||
break;
|
||||
case ELM_BG_OPTION_SCALE:
|
||||
type = EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE;
|
||||
break;
|
||||
case ELM_BG_OPTION_TILE:
|
||||
type = EFL_IMAGE_SCALE_TYPE_TILE;
|
||||
break;
|
||||
case ELM_BG_OPTION_STRETCH:
|
||||
type = EFL_IMAGE_SCALE_TYPE_FILL;
|
||||
break;
|
||||
case ELM_BG_OPTION_LAST:
|
||||
default:
|
||||
type = EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE;
|
||||
}
|
||||
efl_image_scale_type_set(obj, type);
|
||||
}
|
||||
|
||||
EAPI Elm_Bg_Option
|
||||
elm_bg_option_get(const Evas_Object *obj)
|
||||
{
|
||||
Elm_Bg_Option option = ELM_BG_OPTION_LAST;
|
||||
EFL_UI_BG_WIDGET_DATA_GET(obj, sd);
|
||||
Efl_Image_Scale_Type type;
|
||||
Elm_Bg_Option option = ELM_BG_OPTION_LAST;
|
||||
|
||||
switch (sd->scale_type)
|
||||
{
|
||||
case EFL_IMAGE_SCALE_TYPE_NONE:
|
||||
option = ELM_BG_OPTION_CENTER;
|
||||
break;
|
||||
case EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE:
|
||||
option = ELM_BG_OPTION_SCALE;
|
||||
break;
|
||||
case EFL_IMAGE_SCALE_TYPE_TILE:
|
||||
option = ELM_BG_OPTION_TILE;
|
||||
break;
|
||||
case EFL_IMAGE_SCALE_TYPE_FILL:
|
||||
option = ELM_BG_OPTION_STRETCH;
|
||||
break;
|
||||
case EFL_IMAGE_SCALE_TYPE_FIT_INSIDE:
|
||||
default:
|
||||
ERR("Scale type %d cannot be converted to Elm_Bg_Option", sd->scale_type);
|
||||
break;
|
||||
}
|
||||
return option;
|
||||
type = efl_image_scale_type_get(obj);
|
||||
switch (type)
|
||||
{
|
||||
case EFL_IMAGE_SCALE_TYPE_NONE:
|
||||
option = ELM_BG_OPTION_CENTER;
|
||||
break;
|
||||
case EFL_IMAGE_SCALE_TYPE_FIT_OUTSIDE:
|
||||
option = ELM_BG_OPTION_SCALE;
|
||||
break;
|
||||
case EFL_IMAGE_SCALE_TYPE_TILE:
|
||||
option = ELM_BG_OPTION_TILE;
|
||||
break;
|
||||
case EFL_IMAGE_SCALE_TYPE_FILL:
|
||||
option = ELM_BG_OPTION_STRETCH;
|
||||
break;
|
||||
case EFL_IMAGE_SCALE_TYPE_FIT_INSIDE:
|
||||
default:
|
||||
ERR("Scale type %d cannot be converted to Elm_Bg_Option", type);
|
||||
break;
|
||||
}
|
||||
|
||||
return option;
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_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)
|
||||
{
|
||||
sd->scale_type = scale_type;
|
||||
|
||||
elm_layout_sizing_eval(obj);
|
||||
efl_image_scale_type_set(sd->img, scale_type);
|
||||
}
|
||||
|
||||
EOLIAN static Efl_Image_Scale_Type
|
||||
_efl_ui_bg_widget_efl_image_scale_type_get(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd)
|
||||
{
|
||||
return sd->scale_type;
|
||||
return efl_image_scale_type_get(sd->img);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
|
@ -307,15 +175,20 @@ _efl_ui_bg_widget_efl_gfx_color_get(Eo *obj, Efl_Ui_Bg_Widget_Data *sd, int *r,
|
|||
EAPI void
|
||||
elm_bg_load_size_set(Evas_Object *obj, int w, int h)
|
||||
{
|
||||
const char *p;
|
||||
EFL_UI_BG_WIDGET_DATA_GET(obj, sd);
|
||||
EFL_UI_BG_WIDGET_DATA_GET_OR_RETURN(obj, sd);
|
||||
efl_image_load_size_set(sd->img, EINA_SIZE2D(w, h));
|
||||
}
|
||||
|
||||
sd->load_opts.w = w;
|
||||
sd->load_opts.h = h;
|
||||
if (!sd->img) return;
|
||||
EOLIAN static void
|
||||
_efl_ui_bg_widget_efl_image_load_load_size_set(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd, Eina_Size2D sz)
|
||||
{
|
||||
efl_image_load_size_set(sd->img, sz);
|
||||
}
|
||||
|
||||
if (!(((p = strrchr(sd->file, '.'))) && (!strcasecmp(p, ".edj"))))
|
||||
evas_object_image_load_size_set(sd->img, w, h);
|
||||
EOLIAN static Eina_Size2D
|
||||
_efl_ui_bg_widget_efl_image_load_load_size_get(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd)
|
||||
{
|
||||
return efl_image_load_size_get(sd->img);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -330,18 +203,42 @@ elm_bg_file_set(Eo *obj, const char *file, const char *group)
|
|||
return efl_file_set((Eo *) obj, file, group);
|
||||
}
|
||||
|
||||
EOLIAN static Eina_Bool
|
||||
_efl_ui_bg_widget_efl_file_file_set(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd, const char *file, const char *key)
|
||||
{
|
||||
return efl_file_set(sd->img, file, key);
|
||||
}
|
||||
EAPI void
|
||||
elm_bg_file_get(const Eo *obj, const char **file, const char **group)
|
||||
{
|
||||
efl_file_get((Eo *) obj, file, group);
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_efl_ui_bg_widget_efl_file_file_get(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd, const char **file, const char **key)
|
||||
{
|
||||
efl_file_get(sd->img, file, key);
|
||||
}
|
||||
|
||||
EOLIAN static Eina_Bool
|
||||
_efl_ui_bg_widget_efl_file_mmap_set(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd,
|
||||
const Eina_File *file, const char *key)
|
||||
{
|
||||
return efl_file_mmap_set(sd->img, file, key);
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_efl_ui_bg_widget_efl_file_mmap_get(Eo *obj EINA_UNUSED, Efl_Ui_Bg_Widget_Data *sd,
|
||||
const Eina_File **file, const char **key)
|
||||
{
|
||||
efl_file_mmap_get(sd->img, file, key);
|
||||
}
|
||||
|
||||
/* Internal EO APIs and hidden overrides */
|
||||
|
||||
ELM_LAYOUT_CONTENT_ALIASES_IMPLEMENT(MY_CLASS_PFX)
|
||||
|
||||
#define EFL_UI_BG_WIDGET_EXTRA_OPS \
|
||||
ELM_LAYOUT_CONTENT_ALIASES_OPS(MY_CLASS_PFX), \
|
||||
ELM_LAYOUT_SIZING_EVAL_OPS(efl_ui_bg_widget)
|
||||
ELM_LAYOUT_CONTENT_ALIASES_OPS(MY_CLASS_PFX)
|
||||
|
||||
#include "efl_ui_bg_widget.eo.c"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Efl.Ui.Bg_Widget (Efl.Ui.Layout, Efl.Ui.Bg)
|
||||
class Efl.Ui.Bg_Widget (Efl.Ui.Layout, Efl.Ui.Bg, Efl.Image.Load)
|
||||
{
|
||||
[[The bg (background) widget is used for setting (solid) background decorations
|
||||
|
||||
|
@ -11,8 +11,9 @@ class Efl.Ui.Bg_Widget (Efl.Ui.Layout, Efl.Ui.Bg)
|
|||
class.constructor;
|
||||
Efl.Object.constructor;
|
||||
Efl.File.file { get; set; }
|
||||
//Efl.File.mmap { get; set; }
|
||||
Efl.File.mmap { get; set; }
|
||||
Efl.Gfx.color { get; set; }
|
||||
Efl.Image.scale_type { get; set; }
|
||||
Efl.Image.Load.load_size { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,13 +28,6 @@ struct _Efl_Ui_Bg_Widget_Data
|
|||
{
|
||||
Evas_Object *rect; /*<< Used for elm_bg_color_set(): elm.swallow.rectangle */
|
||||
Evas_Object *img; /*<< Used for elm_bg_file_set(): elm.swallow.content */
|
||||
const char *file, *group; /*<< path to file and group name to give life to "img": elm.swallow.background */
|
||||
Efl_Image_Scale_Type scale_type;
|
||||
|
||||
struct
|
||||
{
|
||||
Evas_Coord w, h;
|
||||
} load_opts;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue