improve widget_take_snapshot_rect

This commit is contained in:
lixianjing 2022-07-20 16:26:00 +08:00
parent 8181260a34
commit d5806b61e2
2 changed files with 9 additions and 14 deletions

View File

@ -4,7 +4,8 @@
* 增加文件选择对话框的函数。 * 增加文件选择对话框的函数。
* 增加文件选择对话框的函数的fscript包装。 * 增加文件选择对话框的函数的fscript包装。
* 增加了dialog\_info/warn/confirm/toast等函数的fscript包装。 * 增加了dialog\_info/warn/confirm/toast等函数的fscript包装。
* 完善文档fscript\_widget.md * 完善文档 fscript\_widget.md
* 完善 widget\_take\_snapshot\_rect 支持控件内的偏移裁剪区(感谢雨欣提供补丁)
2022/07/19 2022/07/19
* 完善demoui的字符串(感谢兆坤提供补丁) * 完善demoui的字符串(感谢兆坤提供补丁)

View File

@ -4743,20 +4743,21 @@ bitmap_t* widget_take_snapshot_rect(widget_t* widget, const rect_t* r) {
vgcanvas_create_fbo(vg, vg->w, vg->h, FALSE, &fbo); vgcanvas_create_fbo(vg, vg->w, vg->h, FALSE, &fbo);
vgcanvas_bind_fbo(vg, &fbo); vgcanvas_bind_fbo(vg, &fbo);
canvas_set_clip_rect(c, r); canvas_set_clip_rect(c, r);
canvas_translate(c, -widget->x, -widget->y);
widget_paint(widget, c); widget_paint(widget, c);
canvas_translate(c, widget->x, widget->y);
vgcanvas_unbind_fbo(vg, &fbo); vgcanvas_unbind_fbo(vg, &fbo);
if (r != NULL) { if (r != NULL) {
w = r->w; w = r->w;
h = r->h; h = r->h;
} else { } else {
w = fbo.w; w = widget->w;
h = fbo.h; h = widget->h;
} }
img = bitmap_create_ex(w * fbo.ratio, h * fbo.ratio, 0, BITMAP_FMT_RGBA8888); img = bitmap_create_ex(w * fbo.ratio, h * fbo.ratio, 0, BITMAP_FMT_RGBA8888);
vgcanvas_fbo_to_bitmap(vg, &fbo, img, r); vgcanvas_fbo_to_bitmap(vg, &fbo, img, r);
vgcanvas_destroy_fbo(vg, &fbo); vgcanvas_destroy_fbo(vg, &fbo);
return img; return img;
@ -4769,20 +4770,11 @@ bitmap_t* widget_take_snapshot_rect(widget_t* widget, const rect_t* r) {
wh_t h = 0; wh_t h = 0;
canvas_t canvas; canvas_t canvas;
lcd_t* lcd = NULL; lcd_t* lcd = NULL;
canvas_t* c = NULL;
uint8_t* buff = NULL; uint8_t* buff = NULL;
bitmap_t* bitmap = NULL; bitmap_t* bitmap = NULL;
bitmap_t* bitmap_clip = NULL; bitmap_t* bitmap_clip = NULL;
native_window_t* native_window = NULL;
return_value_if_fail(widget != NULL && widget->vt != NULL, NULL); return_value_if_fail(widget != NULL && widget->vt != NULL, NULL);
native_window =
(native_window_t*)widget_get_prop_pointer(window_manager(), WIDGET_PROP_NATIVE_WINDOW);
return_value_if_fail(native_window != NULL, NULL);
c = native_window_get_canvas(native_window);
return_value_if_fail(c != NULL, NULL);
w = widget->w; w = widget->w;
h = widget->h; h = widget->h;
@ -4794,7 +4786,9 @@ bitmap_t* widget_take_snapshot_rect(widget_t* widget, const rect_t* r) {
if (lcd != NULL) { if (lcd != NULL) {
canvas_init(&canvas, lcd, font_manager()); canvas_init(&canvas, lcd, font_manager());
canvas_begin_frame(&canvas, NULL, LCD_DRAW_OFFLINE); canvas_begin_frame(&canvas, NULL, LCD_DRAW_OFFLINE);
widget_paint_with_clip(widget, (rect_t*)r, &canvas, widget_paint); canvas_translate(&canvas, -widget->x, -widget->y);
widget_paint(widget, &canvas);
canvas_translate(&canvas, widget->x, widget->y);
canvas_end_frame(&canvas); canvas_end_frame(&canvas);
canvas_reset(&canvas); canvas_reset(&canvas);
lcd_destroy(lcd); lcd_destroy(lcd);