fix(snapshot) snapshot is affected by parent's style because of wrong coords (#2579)

* fix(snapshot) image is affected by parent's style because of wrong coordinates

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>

* fix(snapshot): take ext_draw_size into account and set disp res to obj size.

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
Change-Id: Iae0d37fa1b2cdf20220087ced51857a36e83bb6d
This commit is contained in:
Neo 2021-09-24 00:28:28 +08:00 committed by GitHub
parent a3952fcd0a
commit 5f75a3b406
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 5 deletions

View File

@ -33,6 +33,7 @@
- feat(msgbox): omit title label unless needed
- feat(msgbox): add function to get selected button index
- fix(btnmatrix): make ORed values work correctly with lv_btnmatrix_has_btn_ctrl
- fix(snapshot): snapshot is affected by parent's style because of wrong coordinates.
## v8.0.2 (16.07.2021)
- fix(theme) improve button focus of keyboard

View File

@ -61,6 +61,9 @@ uint32_t lv_snapshot_buf_size_needed(lv_obj_t * obj, lv_img_cf_t cf)
/*Width and height determine snapshot image size.*/
lv_coord_t w = lv_obj_get_width(obj);
lv_coord_t h = lv_obj_get_height(obj);
lv_coord_t ext_size = _lv_obj_get_ext_draw_size(obj);
w += ext_size * 2;
h += ext_size * 2;
uint8_t px_size = lv_img_cf_get_px_size(cf);
return w * h * ((px_size + 7) >> 3);
@ -98,10 +101,14 @@ lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t *
/*Width and height determine snapshot image size.*/
lv_coord_t w = lv_obj_get_width(obj);
lv_coord_t h = lv_obj_get_height(obj);
lv_coord_t ext_size = _lv_obj_get_ext_draw_size(obj);
w += ext_size * 2;
h += ext_size * 2;
/*Backup obj original info.*/
lv_disp_t * disp_old = lv_obj_get_disp(obj);
lv_obj_t * parent_old = lv_obj_get_parent(obj);
lv_area_t coords_bkp;
lv_area_copy(&coords_bkp, &obj->coords);
lv_memset(buf, 0x00, buff_size);
lv_memset_00(dsc, sizeof(lv_img_dsc_t));
@ -116,8 +123,8 @@ lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t *
lv_disp_drv_init(&driver);
driver.draw_buf = &draw_buf;
driver.hor_res = lv_disp_get_hor_res(disp_old);
driver.ver_res = lv_disp_get_ver_res(disp_old);
driver.hor_res = w;
driver.ver_res = h;
lv_disp_drv_use_generic_set_px_cb(&driver, cf);
disp = lv_disp_drv_register(&driver);
@ -138,6 +145,12 @@ lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t *
obj->parent = screen;
disp->inv_p = 0;
obj->coords.x2 = w - ext_size - 1;
obj->coords.x1 = ext_size;
obj->coords.y2 = h - ext_size - 1;
obj->coords.y1 = ext_size;
lv_obj_invalidate(obj);
/*Don't call lv_refr_now to avoid animation disruption */
@ -150,9 +163,11 @@ lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t *
lv_disp_remove(disp);
lv_area_copy(&obj->coords, &coords_bkp);
dsc->data = buf;
dsc->header.w = w;
dsc->header.h = h;
dsc->header.w = lv_area_get_width(&draw_buf.area);
dsc->header.h = lv_area_get_height(&draw_buf.area);
dsc->header.cf = cf;
return LV_RES_OK;
}