mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-02 03:58:33 +08:00
draw image support device pixel ratio
This commit is contained in:
parent
ecbff59603
commit
285e3bfccb
@ -115,7 +115,7 @@ ret_t application_init() {
|
||||
|
||||
progress_bar = progress_bar_create(win, 10, 80, 168, 20);
|
||||
widget_set_value(progress_bar, 40);
|
||||
// timer_add(on_timer, progress_bar, 200);
|
||||
timer_add(on_timer, progress_bar, 200);
|
||||
|
||||
#ifndef WITH_STM32F103ZE_RAW
|
||||
progress_bar_set_show_text(progress_bar, TRUE);
|
||||
|
@ -478,17 +478,6 @@ static ret_t canvas_do_draw_image(canvas_t* c, bitmap_t* img, rect_t* s, rect_t*
|
||||
return lcd_draw_image(c->lcd, img, &src, &dst);
|
||||
}
|
||||
|
||||
ret_t canvas_draw_image_at(canvas_t* c, bitmap_t* img, xy_t x, xy_t y) {
|
||||
rect_t src;
|
||||
rect_t dst;
|
||||
return_value_if_fail(c != NULL && img != NULL, RET_BAD_PARAMS);
|
||||
|
||||
rect_init(src, 0, 0, img->w, img->h);
|
||||
rect_init(dst, x, y, img->w, img->h);
|
||||
|
||||
return canvas_do_draw_image(c, img, &src, &dst);
|
||||
}
|
||||
|
||||
ret_t canvas_draw_image(canvas_t* c, bitmap_t* img, rect_t* src, rect_t* dst) {
|
||||
rect_t d;
|
||||
return_value_if_fail(c != NULL && img != NULL && src != NULL && dst != NULL, RET_BAD_PARAMS);
|
||||
@ -959,25 +948,6 @@ ret_t canvas_draw_image_scale(canvas_t* c, bitmap_t* img, rect_t* dst) {
|
||||
return canvas_draw_image(c, img, &s, &d);
|
||||
}
|
||||
|
||||
ret_t canvas_draw_image_center(canvas_t* c, bitmap_t* img, rect_t* dst) {
|
||||
rect_t s;
|
||||
rect_t d;
|
||||
return_value_if_fail(c != NULL && img != NULL && dst != NULL, RET_BAD_PARAMS);
|
||||
|
||||
s.x = 0;
|
||||
s.y = 0;
|
||||
s.h = img->h;
|
||||
s.w = img->w;
|
||||
|
||||
d = *dst;
|
||||
d.x = dst->x + ((dst->w - s.w) >> 1);
|
||||
d.y = dst->y + ((dst->h - s.h) >> 1);
|
||||
d.w = s.w;
|
||||
d.h = s.h;
|
||||
|
||||
return canvas_draw_image(c, img, &s, &d);
|
||||
}
|
||||
|
||||
ret_t canvas_draw_image_ex(canvas_t* c, bitmap_t* img, image_draw_type_t draw_type, rect_t* dst) {
|
||||
rect_t src;
|
||||
return_value_if_fail(c != NULL && img != NULL && dst != NULL, RET_BAD_PARAMS);
|
||||
@ -1019,18 +989,20 @@ ret_t canvas_draw_image_ex(canvas_t* c, bitmap_t* img, image_draw_type_t draw_ty
|
||||
ret_t canvas_draw_icon(canvas_t* c, bitmap_t* img, xy_t cx, xy_t cy) {
|
||||
rect_t src;
|
||||
rect_t dst;
|
||||
vgcanvas_t* vg = NULL;
|
||||
wh_t hw = 0;
|
||||
wh_t hh = 0;
|
||||
return_value_if_fail(c != NULL && img != NULL, RET_BAD_PARAMS);
|
||||
float_t ratio = 0;
|
||||
return_value_if_fail(c != NULL && c->lcd != NULL && img != NULL, RET_BAD_PARAMS);
|
||||
|
||||
ratio = c->lcd->ratio;
|
||||
rect_init(src, 0, 0, img->w, img->h);
|
||||
vg = lcd_get_vgcanvas(c->lcd);
|
||||
if (vg && vg->ratio > 1) {
|
||||
float_t ratio = 1.0f / vg->ratio;
|
||||
hw = img->w * ratio * 0.5;
|
||||
hh = img->h * ratio * 0.5;
|
||||
rect_init(dst, cx - hw, cy - hh, 2 * hw, 2 * hh);
|
||||
if (ratio > 1) {
|
||||
float_t w = (img->w / ratio);
|
||||
float_t h = (img->h / ratio);
|
||||
float_t hw = w * 0.5;
|
||||
float_t hh = h * 0.5;
|
||||
|
||||
rect_init(dst, cx - hw, cy - hh, w, h);
|
||||
} else {
|
||||
hw = img->w >> 1;
|
||||
hh = img->h >> 1;
|
||||
@ -1039,3 +1011,34 @@ ret_t canvas_draw_icon(canvas_t* c, bitmap_t* img, xy_t cx, xy_t cy) {
|
||||
|
||||
return canvas_draw_image(c, img, &src, &dst);
|
||||
}
|
||||
|
||||
ret_t canvas_draw_image_center(canvas_t* c, bitmap_t* img, rect_t* dst) {
|
||||
xy_t cx = 0;
|
||||
xy_t cy = 0;
|
||||
return_value_if_fail(c != NULL && img != NULL && dst != NULL, RET_BAD_PARAMS);
|
||||
|
||||
cx = dst->x + (dst->w >> 1);
|
||||
cy = dst->y + (dst->h >> 1);
|
||||
|
||||
return canvas_draw_icon(c, img, cx, cy);
|
||||
}
|
||||
|
||||
|
||||
ret_t canvas_draw_image_at(canvas_t* c, bitmap_t* img, xy_t x, xy_t y) {
|
||||
rect_t src;
|
||||
rect_t dst;
|
||||
float_t ratio = 0;
|
||||
return_value_if_fail(c != NULL && c->lcd != NULL && img != NULL, RET_BAD_PARAMS);
|
||||
|
||||
ratio = c->lcd->ratio;
|
||||
rect_init(src, 0, 0, img->w, img->h);
|
||||
|
||||
if (ratio > 1) {
|
||||
rect_init(dst, x, y, img->w / ratio, img->h / ratio);
|
||||
} else {
|
||||
rect_init(dst, x, y, img->w, img->h);
|
||||
}
|
||||
|
||||
return canvas_do_draw_image(c, img, &src, &dst);
|
||||
}
|
||||
|
||||
|
@ -200,6 +200,13 @@ struct _lcd_t {
|
||||
*/
|
||||
lcd_type_t type;
|
||||
|
||||
/**
|
||||
* @property {float_t} ratio
|
||||
* @readonly
|
||||
* 屏幕密度。
|
||||
*/
|
||||
float_t ratio;
|
||||
|
||||
rect_t* dirty_rect;
|
||||
};
|
||||
|
||||
|
@ -273,6 +273,7 @@ lcd_t* lcd_mem_create(wh_t w, wh_t h, bool_t alloc) {
|
||||
|
||||
base->w = w;
|
||||
base->h = h;
|
||||
base->ratio = 1;
|
||||
base->type = LCD_FRAMEBUFFER;
|
||||
|
||||
info->lcd_w = base->w;
|
||||
|
@ -31,9 +31,12 @@
|
||||
lcd_t* lcd_nanovg_init(SDL_Window* sdl_window) {
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
vgcanvas_t* vg = NULL;
|
||||
return_value_if_fail(sdl_window != NULL, NULL);
|
||||
|
||||
SDL_GetWindowSize(sdl_window, &w, &h);
|
||||
vg = vgcanvas_create(w, h, sdl_window);
|
||||
return_value_if_fail(vg != NULL, NULL);
|
||||
|
||||
return lcd_vgcanvas_init(w, h, vgcanvas_create(w, h, sdl_window));
|
||||
return lcd_vgcanvas_init(w, h, vg);
|
||||
}
|
||||
|
@ -181,6 +181,7 @@ lcd_t* lcd_reg_create(wh_t w, wh_t h) {
|
||||
|
||||
lcd->w = w;
|
||||
lcd->h = h;
|
||||
lcd->ratio = 1;
|
||||
lcd->type = LCD_REGISTER;
|
||||
info->lcd_w = lcd->w;
|
||||
info->lcd_h = lcd->h;
|
||||
|
@ -211,6 +211,7 @@ lcd_t* lcd_vgcanvas_init(wh_t w, wh_t h, vgcanvas_t* canvas) {
|
||||
|
||||
base->w = (wh_t)w;
|
||||
base->h = (wh_t)h;
|
||||
base->ratio = canvas->ratio;
|
||||
base->type = LCD_VGCANVAS;
|
||||
|
||||
info->lcd_w = base->w;
|
||||
|
Loading…
Reference in New Issue
Block a user