efl/gfx: redo image scale_type enum
this is ideally a bit more clear and flexible than the previous enum names Reviewed-by: Cedric BAIL <cedric.bail@free.fr> Differential Revision: https://phab.enlightenment.org/D9691
This commit is contained in:
parent
81183e0423
commit
ad0c805545
|
@ -318,7 +318,7 @@ _image_cb(void *data, const Efl_Event *ev)
|
|||
{
|
||||
efl_file_simple_get(ev->object, &f, &k);
|
||||
o = efl_add(EFL_UI_IMAGE_CLASS, win,
|
||||
efl_gfx_image_scale_type_set(efl_added, EFL_GFX_IMAGE_SCALE_TYPE_FIT_OUTSIDE),
|
||||
efl_gfx_image_scale_type_set(efl_added, EFL_GFX_IMAGE_SCALE_TYPE_EXPAND),
|
||||
efl_file_set(efl_added, f),
|
||||
efl_file_key_set(efl_added, k)
|
||||
);
|
||||
|
@ -444,22 +444,29 @@ test_bg_scale_type(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *e
|
|||
efl_pack(hbox, rd);
|
||||
|
||||
rd = efl_add(EFL_UI_RADIO_CLASS, hbox);
|
||||
efl_ui_radio_state_value_set(rd, EFL_GFX_IMAGE_SCALE_TYPE_FIT_INSIDE);
|
||||
efl_text_set(rd, "Fit Inside");
|
||||
efl_ui_radio_state_value_set(rd, EFL_GFX_IMAGE_SCALE_TYPE_FIT);
|
||||
efl_text_set(rd, "Fit");
|
||||
efl_gfx_hint_weight_set(rd, EFL_GFX_HINT_EXPAND, 0.0);
|
||||
efl_event_callback_add(rd, EFL_UI_EVENT_SELECTED_CHANGED, _cb_radio_changed_scale_type, o_bg);
|
||||
efl_pack(hbox, rd);
|
||||
|
||||
rd = efl_add(EFL_UI_RADIO_CLASS, hbox);
|
||||
efl_ui_radio_state_value_set(rd, EFL_GFX_IMAGE_SCALE_TYPE_FIT_OUTSIDE);
|
||||
efl_text_set(rd, "Fit Outside");
|
||||
efl_ui_radio_state_value_set(rd, EFL_GFX_IMAGE_SCALE_TYPE_FIT_WIDTH);
|
||||
efl_text_set(rd, "Fit Horizontally");
|
||||
efl_gfx_hint_weight_set(rd, EFL_GFX_HINT_EXPAND, 0.0);
|
||||
efl_event_callback_add(rd, EFL_UI_EVENT_SELECTED_CHANGED, _cb_radio_changed_scale_type, o_bg);
|
||||
efl_pack(hbox, rd);
|
||||
|
||||
rd = efl_add(EFL_UI_RADIO_CLASS, hbox);
|
||||
efl_ui_radio_state_value_set(rd, EFL_GFX_IMAGE_SCALE_TYPE_NONE);
|
||||
efl_text_set(rd, "None");
|
||||
efl_ui_radio_state_value_set(rd, EFL_GFX_IMAGE_SCALE_TYPE_FIT_HEIGHT);
|
||||
efl_text_set(rd, "Fit Verically");
|
||||
efl_gfx_hint_weight_set(rd, EFL_GFX_HINT_EXPAND, 0.0);
|
||||
efl_event_callback_add(rd, EFL_UI_EVENT_SELECTED_CHANGED, _cb_radio_changed_scale_type, o_bg);
|
||||
efl_pack(hbox, rd);
|
||||
|
||||
rd = efl_add(EFL_UI_RADIO_CLASS, hbox);
|
||||
efl_ui_radio_state_value_set(rd, EFL_GFX_IMAGE_SCALE_TYPE_EXPAND);
|
||||
efl_text_set(rd, "Expand");
|
||||
efl_gfx_hint_weight_set(rd, EFL_GFX_HINT_EXPAND, 0.0);
|
||||
efl_event_callback_add(rd, EFL_UI_EVENT_SELECTED_CHANGED, _cb_radio_changed_scale_type, o_bg);
|
||||
efl_pack(hbox, rd);
|
||||
|
|
|
@ -105,8 +105,10 @@ static const struct {
|
|||
} images_scale_type[] = {
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_NONE, "None" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_FILL, "Fill" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_FIT_INSIDE, "Fit Inside" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_FIT_OUTSIDE, "Fit Outside" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_FIT, "Fit" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_FIT_WIDTH, "Fit Horizontally" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_FIT_HEIGHT, "Fit Vertically" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_EXPAND, "Expand" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_TILE, "Tile" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
|
|
@ -49,7 +49,7 @@ _scale_type_cb(void *data, const Efl_Event *ev EINA_UNUSED)
|
|||
snprintf(buf, sizeof(buf), "%s/images/plant_01.jpg", elm_app_data_dir_get());
|
||||
efl_file_simple_load(efl_part(target, "background"), buf, NULL);
|
||||
type = efl_gfx_image_scale_type_get(efl_part(target, "background"));
|
||||
type = (type + 1) % 5;
|
||||
type = (type + 1) % 6;
|
||||
efl_gfx_image_scale_type_set(efl_part(target, "background"), type);
|
||||
}
|
||||
|
||||
|
|
|
@ -112,8 +112,10 @@ static const struct {
|
|||
} images_scale_type[] = {
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_NONE, "None" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_FILL, "Fill" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_FIT_INSIDE, "Fit Inside" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_FIT_OUTSIDE, "Fit Outside" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_FIT, "Fit" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_FIT_WIDTH, "Fit Horizontally" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_FIT_HEIGHT, "Fit Vertically" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_EXPAND, "Expand" },
|
||||
{ EFL_GFX_IMAGE_SCALE_TYPE_TILE, "Tile" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
|
|
@ -200,7 +200,7 @@ elm_main(int argc EINA_UNUSED, char **argv)
|
|||
|
||||
case 40:
|
||||
efl_file_simple_load(efl_part(item, "background"), "./sky_01.jpg", NULL);
|
||||
efl_gfx_image_scale_type_set(efl_part(item, "background"), EFL_GFX_IMAGE_SCALE_TYPE_FIT_OUTSIDE);
|
||||
efl_gfx_image_scale_type_set(efl_part(item, "background"), EFL_GFX_IMAGE_SCALE_TYPE_EXPAND);
|
||||
efl_pack_at(list, item, 39);
|
||||
break;
|
||||
|
||||
|
|
|
@ -21,23 +21,33 @@ enum @beta Efl.Gfx.Image_Scale_Hint
|
|||
enum @beta Efl.Gfx.Image_Scale_Type
|
||||
{
|
||||
[[Enumeration that defines scale types of an image.]]
|
||||
none, [[Use the image's natural size.]]
|
||||
fill, [[Scale the image so that it matches
|
||||
the object's area exactly.
|
||||
The image's aspect ratio might be changed.]]
|
||||
fit_inside, [[Scale the image
|
||||
so that it fits inside the object's area
|
||||
fit, [[Scale the image
|
||||
so that it fits completely inside the object's area
|
||||
while maintaining the aspect ratio.
|
||||
At least one of the dimensions of the image
|
||||
should be equal to the corresponding dimension
|
||||
of the object.]]
|
||||
fit_outside, [[Scale the image
|
||||
so that it covers the entire object area
|
||||
fit_width, [[Scale the image
|
||||
so that it covers the entire object area horizontally
|
||||
while maintaining the aspect ratio.
|
||||
At least one of the dimensions of the image
|
||||
should be equal to the corresponding
|
||||
dimension of the object.]]
|
||||
The image may become larger than the object.
|
||||
]]
|
||||
fit_height, [[Scale the image
|
||||
so that it covers the entire object area vertically
|
||||
while maintaining the aspect ratio.
|
||||
The image may become larger than the object.
|
||||
]]
|
||||
expand, [[Scale the image
|
||||
so that it covers the entire object area on one axis
|
||||
while maintaining the aspect ratio, preferring whichever
|
||||
axis is largest.
|
||||
The image may become larger than the object.
|
||||
]]
|
||||
tile, [[Tile image at its original size.]]
|
||||
none [[Not scale the image]]
|
||||
}
|
||||
|
||||
struct Efl.Gfx.Image_Stretch_Region
|
||||
|
|
|
@ -44,7 +44,7 @@ _efl_ui_bg_efl_object_constructor(Eo *obj, Efl_Ui_Bg_Data *pd)
|
|||
efl_content_set(efl_part(obj, "elm.swallow.rectangle"), efl_added));
|
||||
|
||||
pd->img = efl_add(EFL_UI_IMAGE_CLASS, obj,
|
||||
efl_gfx_image_scale_type_set(efl_added, EFL_GFX_IMAGE_SCALE_TYPE_FIT_OUTSIDE),
|
||||
efl_gfx_image_scale_type_set(efl_added, EFL_GFX_IMAGE_SCALE_TYPE_EXPAND),
|
||||
efl_content_set(efl_part(obj, "elm.swallow.background"), efl_added));
|
||||
}
|
||||
else
|
||||
|
@ -54,7 +54,7 @@ _efl_ui_bg_efl_object_constructor(Eo *obj, Efl_Ui_Bg_Data *pd)
|
|||
efl_content_set(efl_part(obj, "efl.rectangle"), efl_added));
|
||||
|
||||
pd->img = efl_add(EFL_UI_IMAGE_CLASS, obj,
|
||||
efl_gfx_image_scale_type_set(efl_added, EFL_GFX_IMAGE_SCALE_TYPE_FIT_OUTSIDE),
|
||||
efl_gfx_image_scale_type_set(efl_added, EFL_GFX_IMAGE_SCALE_TYPE_EXPAND),
|
||||
efl_content_set(efl_part(obj, "efl.background"), efl_added));
|
||||
}
|
||||
pd->file = NULL;
|
||||
|
@ -87,7 +87,7 @@ elm_bg_option_set(Evas_Object *obj, Elm_Bg_Option option)
|
|||
type = EFL_GFX_IMAGE_SCALE_TYPE_NONE;
|
||||
break;
|
||||
case ELM_BG_OPTION_SCALE:
|
||||
type = EFL_GFX_IMAGE_SCALE_TYPE_FIT_OUTSIDE;
|
||||
type = EFL_GFX_IMAGE_SCALE_TYPE_EXPAND;
|
||||
break;
|
||||
case ELM_BG_OPTION_TILE:
|
||||
type = EFL_GFX_IMAGE_SCALE_TYPE_TILE;
|
||||
|
@ -97,7 +97,7 @@ elm_bg_option_set(Evas_Object *obj, Elm_Bg_Option option)
|
|||
break;
|
||||
case ELM_BG_OPTION_LAST:
|
||||
default:
|
||||
type = EFL_GFX_IMAGE_SCALE_TYPE_FIT_OUTSIDE;
|
||||
type = EFL_GFX_IMAGE_SCALE_TYPE_EXPAND;
|
||||
}
|
||||
efl_gfx_image_scale_type_set(obj, type);
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ elm_bg_option_get(const Evas_Object *obj)
|
|||
case EFL_GFX_IMAGE_SCALE_TYPE_NONE:
|
||||
option = ELM_BG_OPTION_CENTER;
|
||||
break;
|
||||
case EFL_GFX_IMAGE_SCALE_TYPE_FIT_OUTSIDE:
|
||||
case EFL_GFX_IMAGE_SCALE_TYPE_EXPAND:
|
||||
option = ELM_BG_OPTION_SCALE;
|
||||
break;
|
||||
case EFL_GFX_IMAGE_SCALE_TYPE_TILE:
|
||||
|
@ -123,7 +123,7 @@ elm_bg_option_get(const Evas_Object *obj)
|
|||
case EFL_GFX_IMAGE_SCALE_TYPE_FILL:
|
||||
option = ELM_BG_OPTION_STRETCH;
|
||||
break;
|
||||
case EFL_GFX_IMAGE_SCALE_TYPE_FIT_INSIDE:
|
||||
case EFL_GFX_IMAGE_SCALE_TYPE_FIT:
|
||||
default:
|
||||
ERR("Scale type %d cannot be converted to Elm_Bg_Option", type);
|
||||
break;
|
||||
|
|
|
@ -212,7 +212,7 @@ _image_sizing_eval(Eo *obj, Efl_Ui_Image_Data *sd, Evas_Object *img)
|
|||
w = ow;
|
||||
h = oh;
|
||||
break;
|
||||
case EFL_GFX_IMAGE_SCALE_TYPE_FIT_INSIDE:
|
||||
case EFL_GFX_IMAGE_SCALE_TYPE_FIT:
|
||||
w = ow;
|
||||
h = ((double)ih * w) / (double)iw;
|
||||
|
||||
|
@ -222,35 +222,45 @@ _image_sizing_eval(Eo *obj, Efl_Ui_Image_Data *sd, Evas_Object *img)
|
|||
w = ((double)iw * h) / (double)ih;
|
||||
}
|
||||
|
||||
if (((!sd->scale_up) && (w > iw))
|
||||
|| ((!sd->scale_down) && (w < iw)))
|
||||
{
|
||||
w = iw;
|
||||
h = ih;
|
||||
}
|
||||
|
||||
break;
|
||||
case EFL_GFX_IMAGE_SCALE_TYPE_FIT_OUTSIDE:
|
||||
case EFL_GFX_IMAGE_SCALE_TYPE_FIT_WIDTH:
|
||||
w = ow;
|
||||
h = ((double)ih * w) / (double)iw;
|
||||
if (h < oh)
|
||||
|
||||
break;
|
||||
case EFL_GFX_IMAGE_SCALE_TYPE_FIT_HEIGHT:
|
||||
h = oh;
|
||||
w = ((double)iw * h) / (double)ih;
|
||||
|
||||
break;
|
||||
case EFL_GFX_IMAGE_SCALE_TYPE_EXPAND:
|
||||
if (ow > oh)
|
||||
{
|
||||
w = ow;
|
||||
h = ((double)ih * w) / (double)iw;
|
||||
}
|
||||
else
|
||||
{
|
||||
h = oh;
|
||||
w = ((double)iw * h) / (double)ih;
|
||||
}
|
||||
|
||||
if (((!sd->scale_up) && (w > iw))
|
||||
|| ((!sd->scale_down) && (w < iw)))
|
||||
{
|
||||
w = iw;
|
||||
h = ih;
|
||||
}
|
||||
break;
|
||||
case EFL_GFX_IMAGE_SCALE_TYPE_TILE:
|
||||
evas_object_geometry_get(obj, &x, &y, &w, &h);
|
||||
evas_object_image_fill_set(img, x, y, iw, ih);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (((!sd->scale_up) && (w > iw))
|
||||
|| ((!sd->scale_down) && (w < iw)))
|
||||
{
|
||||
w = iw;
|
||||
}
|
||||
if (((!sd->scale_up) && (h > ih))
|
||||
|| ((!sd->scale_down) && (h < ih)))
|
||||
{
|
||||
h = ih;
|
||||
}
|
||||
//3. Calculate offset according to align value
|
||||
if (!elm_widget_is_legacy(sd->self))
|
||||
{
|
||||
|
@ -859,7 +869,7 @@ _efl_ui_image_efl_object_constructor(Eo *obj, Efl_Ui_Image_Data *pd)
|
|||
evas_object_smart_callbacks_descriptions_set(obj, _smart_callbacks);
|
||||
efl_access_object_role_set(obj, EFL_ACCESS_ROLE_IMAGE);
|
||||
|
||||
pd->scale_type = EFL_GFX_IMAGE_SCALE_TYPE_FIT_INSIDE;
|
||||
pd->scale_type = EFL_GFX_IMAGE_SCALE_TYPE_FIT;
|
||||
pd->self = obj;
|
||||
|
||||
return obj;
|
||||
|
@ -2077,8 +2087,8 @@ elm_image_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
|
|||
|
||||
if (sd->aspect_fixed)
|
||||
{
|
||||
if (sd->fill_inside) sd->scale_type = EFL_GFX_IMAGE_SCALE_TYPE_FIT_INSIDE;
|
||||
else sd->scale_type = EFL_GFX_IMAGE_SCALE_TYPE_FIT_OUTSIDE;
|
||||
if (sd->fill_inside) sd->scale_type = EFL_GFX_IMAGE_SCALE_TYPE_FIT;
|
||||
else sd->scale_type = EFL_GFX_IMAGE_SCALE_TYPE_EXPAND;
|
||||
}
|
||||
else
|
||||
sd->scale_type = EFL_GFX_IMAGE_SCALE_TYPE_FILL;
|
||||
|
@ -2222,8 +2232,8 @@ elm_image_aspect_fixed_set(Evas_Object *obj, Eina_Bool fixed)
|
|||
|
||||
if (sd->aspect_fixed)
|
||||
{
|
||||
if (sd->fill_inside) sd->scale_type = EFL_GFX_IMAGE_SCALE_TYPE_FIT_INSIDE;
|
||||
else sd->scale_type = EFL_GFX_IMAGE_SCALE_TYPE_FIT_OUTSIDE;
|
||||
if (sd->fill_inside) sd->scale_type = EFL_GFX_IMAGE_SCALE_TYPE_FIT;
|
||||
else sd->scale_type = EFL_GFX_IMAGE_SCALE_TYPE_EXPAND;
|
||||
}
|
||||
else
|
||||
sd->scale_type = EFL_GFX_IMAGE_SCALE_TYPE_FILL;
|
||||
|
|
|
@ -7723,7 +7723,7 @@ _efl_ui_win_part_file_load(Eo *obj, Efl_Ui_Win_Data *sd, Eo *part_obj, const cha
|
|||
if (file)
|
||||
{
|
||||
bg = efl_add(EFL_UI_IMAGE_CLASS, obj);
|
||||
efl_gfx_image_scale_type_set(bg, EFL_GFX_IMAGE_SCALE_TYPE_FIT_OUTSIDE);
|
||||
efl_gfx_image_scale_type_set(bg, EFL_GFX_IMAGE_SCALE_TYPE_EXPAND);
|
||||
ok = efl_file_simple_load(bg, file, key);
|
||||
if (!ok) ELM_SAFE_DEL(bg);
|
||||
_elm_win_bg_set(sd, bg);
|
||||
|
|
Loading…
Reference in New Issue