1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

Merge pull request #1290 from LanFengXiMenChuiXue/dev-7.0

1.add img center;2.modify tileview;
This commit is contained in:
Gabor Kiss-Vamosi 2019-11-30 10:49:18 +01:00 committed by GitHub
commit 5b7058ccf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 116 additions and 31 deletions

View File

@ -26,10 +26,10 @@
* STATIC PROTOTYPES
**********************/
static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, const void * src,
const lv_style_t * style, uint16_t angle, uint16_t zoom, bool antialaias, lv_opa_t opa_scale);
const lv_style_t * style, uint16_t angle, lv_point_t * pivot, uint16_t zoom, bool antialaias, lv_opa_t opa_scale);
static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, const uint8_t * map_p, lv_opa_t opa,
bool chroma_key, bool alpha_byte, const lv_style_t * style, uint16_t angle, uint16_t zoom, bool antialaias);
bool chroma_key, bool alpha_byte, const lv_style_t * style, uint16_t angle, lv_point_t * pivot, uint16_t zoom, bool antialaias);
/**********************
* STATIC VARIABLES
@ -49,11 +49,13 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area,
* @param mask the image will be drawn only in this area
* @param src pointer to a lv_color_t array which contains the pixels of the image
* @param style style of the image
* @param angle rotation angle of the image
* @param center rotation center of the image
* @param antialias anti-alias transformations (rotate, zoom) or not
* @param opa_scale scale down all opacities by the factor
*/
void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask, const void * src, const lv_style_t * style,
uint16_t angle, uint16_t zoom, bool antialias, lv_opa_t opa_scale)
uint16_t angle, lv_point_t * center, uint16_t zoom, bool antialias, lv_opa_t opa_scale)
{
if(src == NULL) {
LV_LOG_WARN("Image draw: src is NULL");
@ -63,7 +65,7 @@ void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask, const void *
}
lv_res_t res;
res = lv_img_draw_core(coords, mask, src, style, angle, zoom, antialias, opa_scale);
res = lv_img_draw_core(coords, mask, src, style, angle, center, zoom, antialias, opa_scale);
if(res == LV_RES_INV) {
LV_LOG_WARN("Image draw error");
@ -190,7 +192,7 @@ lv_img_src_t lv_img_src_get_type(const void * src)
**********************/
static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, const void * src,
const lv_style_t * style, uint16_t angle, uint16_t zoom, bool antialias, lv_opa_t opa_scale)
const lv_style_t * style, uint16_t angle, lv_point_t * pivot, uint16_t zoom, bool antialias, lv_opa_t opa_scale)
{
lv_opa_t opa =
opa_scale == LV_OPA_COVER ? style->image.opa : (uint16_t)((uint16_t)style->image.opa * opa_scale) >> 8;
@ -217,6 +219,10 @@ static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mas
lv_coord_t pivot_x = lv_area_get_width(coords) / 2 + coords->x1;
lv_coord_t pivot_y = lv_area_get_height(coords) / 2 + coords->y1;
if (pivot){
pivot_x = pivot->x + coords->x1;
pivot_y = pivot->y + coords->y1;
}
lv_coord_t w = lv_area_get_width(coords);
lv_coord_t w_zoom = (((w * zoom) >> 8) - w) / 2;
lv_coord_t h = lv_area_get_height(coords);
@ -228,8 +234,8 @@ static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mas
norm.x2 = coords->x2 - pivot_x + w_zoom;
norm.y2 = coords->y2 - pivot_y + h_zoom;
int16_t sinma = lv_trigo_sin(-angle);
int16_t cosma = lv_trigo_sin(-angle + 90);
int16_t sinma = lv_trigo_sin(angle);
int16_t cosma = lv_trigo_sin(angle + 90);
lv_point_t lt;
lv_point_t rt;
@ -261,7 +267,7 @@ static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mas
successfully.*/
}
lv_draw_map(coords, &mask_com, cdsc->dec_dsc.img_data, opa, chroma_keyed, alpha_byte, style, angle, zoom, antialias);
lv_draw_map(coords, &mask_com, cdsc->dec_dsc.img_data, opa, chroma_keyed, alpha_byte, style, angle, pivot, zoom, antialias);
}
/* The whole uncompressed image is not available. Try to read it line-by-line*/
else {
@ -298,7 +304,7 @@ static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mas
}
lv_draw_map(&line, &mask_line, buf, opa, chroma_keyed, alpha_byte, style, 0, LV_IMG_ZOOM_NONE, false);
lv_draw_map(&line, &mask_line, buf, opa, chroma_keyed, alpha_byte, style, 0, NULL, LV_IMG_ZOOM_NONE, false);
line.y1++;
line.y2++;
y++;
@ -319,11 +325,12 @@ static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mas
* @param alpha_byte true: extra alpha byte is inserted for every pixel
* @param style style of the image
* @param angle angle in degree
* @param pivot center of rotation
* @param zoom zoom factor
* @param antialias anti-alias transformations (rotate, zoom) or not
*/
static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, const uint8_t * map_p, lv_opa_t opa,
bool chroma_key, bool alpha_byte, const lv_style_t * style, uint16_t angle, uint16_t zoom, bool antialaias)
bool chroma_key, bool alpha_byte, const lv_style_t * style, uint16_t angle, lv_point_t * pivot, uint16_t zoom, bool antialaias)
{
if(opa < LV_OPA_MIN) return;
@ -405,13 +412,16 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area,
trans_dsc.cfg.cf = cf;
trans_dsc.cfg.pivot_x = map_w / 2;
trans_dsc.cfg.pivot_y = map_h / 2;
if (pivot){
trans_dsc.cfg.pivot_x = pivot->x;
trans_dsc.cfg.pivot_y = pivot->y;
}
trans_dsc.cfg.color = style->image.color;
trans_dsc.cfg.antialias = antialaias;
lv_img_buf_transform_init(&trans_dsc);
}
lv_draw_mask_res_t mask_res;
mask_res = (alpha_byte || chroma_key || angle) ? LV_DRAW_MASK_RES_CHANGED : LV_DRAW_MASK_RES_FULL_COVER;
lv_coord_t x;

View File

@ -40,11 +40,13 @@ extern "C" {
* @param mask the image will be drawn only in this area
* @param src pointer to a lv_color_t array which contains the pixels of the image
* @param style style of the image
* @param angle rotation angle of the image
* @param center rotation center of the image
* @param antialias anti-alias transformations (rotate, zoom) or not
* @param opa_scale scale down all opacities by the factor
*/
void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask, const void * src, const lv_style_t * style,
uint16_t angle, uint16_t zoom, bool antialaias, lv_opa_t opa_scale);
uint16_t angle, lv_point_t * center, uint16_t zoom, bool antialaias, lv_opa_t opa_scale);
/**
* Get the type of an image source

View File

@ -404,7 +404,6 @@ void lv_img_buf_transform_init(lv_img_transform_dsc_t * dsc)
dsc->tmp.img_dsc.header.w = dsc->cfg.src_w;
dsc->tmp.img_dsc.header.h = dsc->cfg.src_h;
dsc->tmp.zoom_inv = (256 * 256) / dsc->cfg.zoom;
dsc->res.opa = LV_OPA_COVER;

View File

@ -885,7 +885,7 @@ void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const voi
lv_disp_t * refr_ori = lv_refr_get_disp_refreshing();
lv_refr_set_disp_refreshing(&disp);
lv_draw_img(&coords, &mask, src, style, 0, LV_IMG_ZOOM_NONE, false, LV_OPA_COVER);
lv_draw_img(&coords, &mask, src, style, 0, NULL, LV_IMG_ZOOM_NONE, false, LV_OPA_COVER);
lv_refr_set_disp_refreshing(refr_ori);
}

View File

@ -85,6 +85,8 @@ lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy)
ext->auto_size = 1;
ext->offset.x = 0;
ext->offset.y = 0;
ext->pivot.x = 0;
ext->pivot.y = 0;
/*Init the new object*/
lv_obj_set_signal_cb(new_img, lv_img_signal);
@ -198,6 +200,8 @@ void lv_img_set_src(lv_obj_t * img, const void * src_img)
ext->w = header.w;
ext->h = header.h;
ext->cf = header.cf;
ext->pivot.x = header.w / 2;
ext->pivot.y = header.h / 2;
if(lv_img_get_auto_size(img) != false) {
lv_obj_set_size(img, ext->w, ext->h);
@ -260,6 +264,25 @@ void lv_img_set_offset_y(lv_obj_t * img, lv_coord_t y)
lv_obj_invalidate(img);
}
/**
* Set the rotation center of the image.
* The image will be rotated around this point
* @param img pointer to an image object
* @param pivot_x rotation center x of the image
* @param pivot_y rotation center y of the image
*/
void lv_img_set_pivot(lv_obj_t * img, lv_coord_t pivot_x, lv_coord_t pivot_y)
{
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
if (ext->pivot.x == pivot_x && ext->pivot.y == pivot_y) return;
lv_obj_invalidate(img);
ext->pivot.x = pivot_x;
ext->pivot.y = pivot_y;
lv_obj_refresh_ext_draw_pad(img);
lv_obj_invalidate(img);
}
/**
* Set the rotation angle of the image.
* The image will be rotated around its middle point
@ -393,6 +416,20 @@ lv_coord_t lv_img_get_offset_y(lv_obj_t * img)
return ext->offset.y;
}
/**
* Get the rotation center of the image.
* @param img pointer to an image object
* @param center rotation center of the image
*/
void lv_img_get_pivot(lv_obj_t * img, lv_point_t *pivot)
{
LV_ASSERT_OBJ(img, LV_OBJX_NAME);
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
*pivot = ext->pivot;
}
/**
* Get the rotation angle of the image.
* @param img pointer to an image object
@ -486,7 +523,7 @@ static lv_design_res_t lv_img_design(lv_obj_t * img, const lv_area_t * clip_area
cords_tmp.x1 = coords.x1;
cords_tmp.x2 = coords.x1 + ext->w - 1;
for(; cords_tmp.x1 <= coords.x2; cords_tmp.x1 += ext->w, cords_tmp.x2 += ext->w) {
lv_draw_img(&cords_tmp, clip_area, ext->src, style, ext->angle, ext->zoom, ext->antialias, opa_scale);
lv_draw_img(&cords_tmp, clip_area, ext->src, style, ext->angle, &ext->pivot, ext->zoom, ext->antialias, opa_scale);
}
}
} else if(ext->src_type == LV_IMG_SRC_SYMBOL) {
@ -498,7 +535,7 @@ static lv_design_res_t lv_img_design(lv_obj_t * img, const lv_area_t * clip_area
} else {
/*Trigger the error handler of image drawer*/
LV_LOG_WARN("lv_img_design: image source type is unknown");
lv_draw_img(&img->coords, clip_area, NULL, style, 0, LV_IMG_ZOOM_NONE, false, opa_scale);
lv_draw_img(&img->coords, clip_area, NULL, style, 0, NULL, LV_IMG_ZOOM_NONE, false, opa_scale);
}
}
@ -538,10 +575,13 @@ static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param)
/*If the image has angle provide enough room for the rotated corners */
if(ext->angle || ext->zoom != LV_IMG_ZOOM_NONE) {
lv_sqrt_res_t ds;
lv_sqrt(ext->w * ext->w + ext->h * ext->h, &ds);
ds.i = (ds.i * ext->zoom + 0) >> 8; /*+10 to be sure anything won't be clipped*/
lv_coord_t max_w = ext->w + LV_MATH_ABS(ext->pivot.x + ext->w / 2);
lv_coord_t max_h = ext->h + LV_MATH_ABS(ext->pivot.y + ext->h / 2);
lv_sqrt(max_w * max_w + max_h * max_h, &ds);/*Maximum diagonal length*/
lv_sqrt(ds.i * ds.i + ds.i * ds.i, &ds); /*Maximum side length of external rectangle*/
ds.i = (ds.i * ext->zoom ) >> 8; /*+10 to be sure anything won't be clipped*/
lv_coord_t d = (ds.i - LV_MATH_MIN(ext->w, ext->h)) / 2;
lv_coord_t d = ds.i / 2;
img->ext_draw_pad = LV_MATH_MAX(img->ext_draw_pad, d);
}
}

View File

@ -42,7 +42,8 @@ typedef struct
lv_point_t offset;
lv_coord_t w; /*Width of the image (Handled by the library)*/
lv_coord_t h; /*Height of the image (Handled by the library)*/
uint16_t angle;
uint16_t angle; /*rotation angle of the image*/
lv_point_t pivot; /*rotation center of the image*/
uint16_t zoom; /*256 means no zoom, 512 double size, 128 hasl size*/
uint8_t src_type : 2; /*See: lv_img_src_t*/
uint8_t auto_size : 1; /*1: automatically set the object size to the image size*/
@ -103,6 +104,15 @@ void lv_img_set_offset_x(lv_obj_t * img, lv_coord_t x);
*/
void lv_img_set_offset_y(lv_obj_t * img, lv_coord_t y);
/**
* Set the rotation center of the image.
* The image will be rotated around this point
* @param img pointer to an image object
* @param pivot_x rotation center x of the image
* @param pivot_y rotation center y of the image
*/
void lv_img_set_pivot(lv_obj_t * img, lv_coord_t pivot_x, lv_coord_t pivot_y);
/**
* Set the rotation angle of the image.
* The image will be rotated around its middle point
@ -188,6 +198,13 @@ lv_coord_t lv_img_get_offset_y(lv_obj_t * img);
*/
uint16_t lv_img_get_angle(lv_obj_t * img);
/**
* Get the rotation center of the image.
* @param img pointer to an image object
* @param center rotation center of the image
*/
void lv_img_get_pivot(lv_obj_t * img, lv_point_t *center);
/**
* Get the zoom factor of the image.
* @param img pointer to an image object

View File

@ -303,7 +303,7 @@ static lv_design_res_t lv_imgbtn_design(lv_obj_t * imgbtn, const lv_area_t * cli
if(lv_img_src_get_type(src) == LV_IMG_SRC_SYMBOL) {
lv_draw_label(&imgbtn->coords, clip_area, style, opa_scale, src, LV_TXT_FLAG_NONE, NULL, NULL, NULL, lv_obj_get_base_dir(imgbtn));
} else {
lv_draw_img(&imgbtn->coords, clip_area, src, style, 0, LV_IMG_ZOOM_NONE, false, opa_scale);
lv_draw_img(&imgbtn->coords, clip_area, src, style, 0, NULL, LV_IMG_ZOOM_NONE, false, opa_scale);
}
#else
const void * src = ext->img_src_left[state];

View File

@ -308,7 +308,7 @@ static lv_design_res_t lv_slider_design(lv_obj_t * slider, const lv_area_t * cli
a.x2 = info.w - 1 + x_ofs;
a.y2 = info.h - 1 + y_ofs;
lv_draw_img(&a, clip_area, ext->img_knob, style_knob, 0, LV_IMG_ZOOM_NONE, false, opa_scale);
lv_draw_img(&a, clip_area, ext->img_knob, style_knob, 0, NULL, LV_IMG_ZOOM_NONE, false, opa_scale);
} else {
LV_LOG_WARN("lv_slider_design: can't get knob image info")
}

View File

@ -366,7 +366,7 @@ static lv_design_res_t lv_sw_design(lv_obj_t * sw, const lv_area_t * clip_area,
a.x2 = info.w - 1 + x_ofs;
a.y2 = info.h - 1 + y_ofs;
lv_draw_img(&a, clip_area, img, style_knob, 0, LV_IMG_ZOOM_NONE, false, opa_scale);
lv_draw_img(&a, clip_area, img, style_knob, 0, NULL, LV_IMG_ZOOM_NONE, false, opa_scale);
} else {
LV_LOG_WARN("lv_slider_design: can't get knob image info")
}

View File

@ -11,6 +11,7 @@
#include <stdbool.h>
#include "lv_cont.h"
#include "../lv_misc/lv_math.h"
#include "../lv_core/lv_debug.h"
#include "../lv_themes/lv_theme.h"
@ -97,8 +98,8 @@ lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy)
* Don't use `par` directly because if the tileview is created on a page it is moved to the
* scrollable so the parent has changed */
lv_obj_set_size(new_tileview, lv_obj_get_width_fit(lv_obj_get_parent(new_tileview)),
lv_obj_get_height_fit(lv_obj_get_parent(new_tileview)));
lv_obj_get_height_fit(lv_obj_get_parent(new_tileview)));
lv_obj_set_drag_dir(lv_page_get_scrl(new_tileview), LV_DRAG_DIR_ONE);
lv_obj_set_drag_throw(lv_page_get_scrl(new_tileview), true);
lv_page_set_scrl_fit(new_tileview, LV_FIT_TIGHT);
/*Set the default styles*/
@ -281,6 +282,19 @@ void lv_tileview_set_style(lv_obj_t * tileview, lv_tileview_style_t type, const
/*
* New object specific "get" functions come here
*/
/**
* Get the tile to be shown
* @param tileview pointer to a tileview object
* @param x column id (0, 1, 2...)
* @param y line id (0, 1, 2...)
*/
void lv_tileview_get_tile_act(lv_obj_t * tileview, lv_coord_t *x, lv_coord_t *y)
{
lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
*x = ext->act_id.x;
*y = ext->act_id.y;
}
/**
* Get style of a tileview.
@ -358,9 +372,6 @@ static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void
if(sign == LV_SIGNAL_DRAG_BEGIN) {
set_valid_drag_dirs(tileview);
}
else if(sign == LV_SIGNAL_DRAG_END) {
// drag_end_handler(tileview);
}
else if(sign == LV_SIGNAL_DRAG_THROW_BEGIN) {
drag_end_handler(tileview);
@ -398,9 +409,9 @@ static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void
/*Apply the drag constraints*/
lv_drag_dir_t drag_dir = indev->proc.types.pointer.drag_dir;
if(drag_dir & LV_DRAG_DIR_HOR)
if(drag_dir == LV_DRAG_DIR_HOR)
lv_obj_set_y(scrl, -ext->act_id.y * lv_obj_get_height(tileview) + style_bg->body.padding.top);
if(drag_dir & LV_DRAG_DIR_VER)
else if(drag_dir == LV_DRAG_DIR_VER)
lv_obj_set_x(scrl, -ext->act_id.x * lv_obj_get_width(tileview) + style_bg->body.padding.left);
}
}

View File

@ -130,7 +130,13 @@ void lv_tileview_set_style(lv_obj_t * tileview, lv_tileview_style_t type, const
/*=====================
* Getter functions
*====================*/
/**
* Get the tile to be shown
* @param tileview pointer to a tileview object
* @param x column id (0, 1, 2...)
* @param y line id (0, 1, 2...)
*/
void lv_tileview_get_tile_act(lv_obj_t * tileview, lv_coord_t *x, lv_coord_t *y);
/**
* Get the scroll propagation property
* @param tileview pointer to a Tileview