This commit is contained in:
xianjimli 2018-04-30 12:14:21 +08:00
commit b3304e2ea7
9 changed files with 88 additions and 43 deletions

View File

@ -115,7 +115,7 @@ ret_t application_init() {
progress_bar = progress_bar_create(win, 10, 80, 168, 20); progress_bar = progress_bar_create(win, 10, 80, 168, 20);
widget_set_value(progress_bar, 40); widget_set_value(progress_bar, 40);
// timer_add(on_timer, progress_bar, 200); timer_add(on_timer, progress_bar, 200);
#ifndef WITH_STM32F103ZE_RAW #ifndef WITH_STM32F103ZE_RAW
progress_bar_set_show_text(progress_bar, TRUE); progress_bar_set_show_text(progress_bar, TRUE);

View File

@ -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); 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) { ret_t canvas_draw_image(canvas_t* c, bitmap_t* img, rect_t* src, rect_t* dst) {
rect_t d; rect_t d;
return_value_if_fail(c != NULL && img != NULL && src != NULL && dst != NULL, RET_BAD_PARAMS); 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); 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) { ret_t canvas_draw_image_ex(canvas_t* c, bitmap_t* img, image_draw_type_t draw_type, rect_t* dst) {
rect_t src; rect_t src;
return_value_if_fail(c != NULL && img != NULL && dst != NULL, RET_BAD_PARAMS); 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) { ret_t canvas_draw_icon(canvas_t* c, bitmap_t* img, xy_t cx, xy_t cy) {
rect_t src; rect_t src;
rect_t dst; rect_t dst;
vgcanvas_t* vg = NULL;
wh_t hw = 0; wh_t hw = 0;
wh_t hh = 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); rect_init(src, 0, 0, img->w, img->h);
vg = lcd_get_vgcanvas(c->lcd); if (ratio > 1) {
if (vg && vg->ratio > 1) { float_t w = (img->w / ratio);
float_t ratio = 1.0f / vg->ratio; float_t h = (img->h / ratio);
hw = img->w * ratio * 0.5; float_t hw = w * 0.5;
hh = img->h * ratio * 0.5; float_t hh = h * 0.5;
rect_init(dst, cx - hw, cy - hh, 2 * hw, 2 * hh);
rect_init(dst, cx - hw, cy - hh, w, h);
} else { } else {
hw = img->w >> 1; hw = img->w >> 1;
hh = img->h >> 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); 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);
}

View File

@ -200,6 +200,13 @@ struct _lcd_t {
*/ */
lcd_type_t type; lcd_type_t type;
/**
* @property {float_t} ratio
* @readonly
*
*/
float_t ratio;
rect_t* dirty_rect; rect_t* dirty_rect;
}; };

View File

@ -96,8 +96,18 @@ resource_info_t* resource_manager_load(resource_manager_t* rm, resource_type_t t
size = fs_file_size(path); size = fs_file_size(path);
if (size > 0) { if (size > 0) {
info = load_resource(type, RESOURCE_TYPE_IMAGE_PNG, size, path, name); info = load_resource(type, RESOURCE_TYPE_IMAGE_PNG, size, path, name);
break; /*not cache png file raw data*/
return info;
} }
snprintf(path, MAX_PATH, "%s/images/%s/%s.jpg", RES_ROOT, ratio, name);
size = fs_file_size(path);
if (size > 0) {
info = load_resource(type, RESOURCE_TYPE_IMAGE_JPG, size, path, name);
/*not cache png file jpg data*/
return info;
}
break; break;
} }
case RESOURCE_TYPE_UI: { case RESOURCE_TYPE_UI: {
@ -105,7 +115,8 @@ resource_info_t* resource_manager_load(resource_manager_t* rm, resource_type_t t
size = fs_file_size(path); size = fs_file_size(path);
if (size > 0) { if (size > 0) {
info = load_resource(type, RESOURCE_TYPE_UI_BIN, size, path, name); info = load_resource(type, RESOURCE_TYPE_UI_BIN, size, path, name);
break; /*not cache ui*/
return info;
} }
break; break;
} }
@ -114,7 +125,8 @@ resource_info_t* resource_manager_load(resource_manager_t* rm, resource_type_t t
size = fs_file_size(path); size = fs_file_size(path);
if (size > 0) { if (size > 0) {
info = load_resource(type, RESOURCE_TYPE_XML, size, path, name); info = load_resource(type, RESOURCE_TYPE_XML, size, path, name);
break; /*not cache xml*/
return info;
} }
break; break;
} }
@ -197,6 +209,11 @@ const resource_info_t* resource_manager_ref(resource_manager_t* rm, resource_typ
ret_t resource_manager_unref(resource_manager_t* rm, const resource_info_t* info) { ret_t resource_manager_unref(resource_manager_t* rm, const resource_info_t* info) {
return_value_if_fail(rm != NULL && info != NULL, RET_BAD_PARAMS); return_value_if_fail(rm != NULL && info != NULL, RET_BAD_PARAMS);
array_remove(&(rm->resources), NULL, info);
if(!(info->is_in_rom)) {
TKMEM_FREE((void*)info);
}
return RET_OK; return RET_OK;
} }

View File

@ -273,6 +273,7 @@ lcd_t* lcd_mem_create(wh_t w, wh_t h, bool_t alloc) {
base->w = w; base->w = w;
base->h = h; base->h = h;
base->ratio = 1;
base->type = LCD_FRAMEBUFFER; base->type = LCD_FRAMEBUFFER;
info->lcd_w = base->w; info->lcd_w = base->w;

View File

@ -31,9 +31,12 @@
lcd_t* lcd_nanovg_init(SDL_Window* sdl_window) { lcd_t* lcd_nanovg_init(SDL_Window* sdl_window) {
int w = 0; int w = 0;
int h = 0; int h = 0;
vgcanvas_t* vg = NULL;
return_value_if_fail(sdl_window != NULL, NULL); return_value_if_fail(sdl_window != NULL, NULL);
SDL_GetWindowSize(sdl_window, &w, &h); 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);
} }

View File

@ -181,6 +181,7 @@ lcd_t* lcd_reg_create(wh_t w, wh_t h) {
lcd->w = w; lcd->w = w;
lcd->h = h; lcd->h = h;
lcd->ratio = 1;
lcd->type = LCD_REGISTER; lcd->type = LCD_REGISTER;
info->lcd_w = lcd->w; info->lcd_w = lcd->w;
info->lcd_h = lcd->h; info->lcd_h = lcd->h;

View File

@ -211,6 +211,7 @@ lcd_t* lcd_vgcanvas_init(wh_t w, wh_t h, vgcanvas_t* canvas) {
base->w = (wh_t)w; base->w = (wh_t)w;
base->h = (wh_t)h; base->h = (wh_t)h;
base->ratio = canvas->ratio;
base->type = LCD_VGCANVAS; base->type = LCD_VGCANVAS;
info->lcd_w = base->w; info->lcd_w = base->w;

View File

@ -24,3 +24,15 @@ TEST(ResourceManager, basic) {
resource_manager_destroy(rm); resource_manager_destroy(rm);
} }
TEST(ResourceManager, file) {
const resource_info_t* r = NULL;
resource_manager_t* rm = resource_manager_create(10);
r = resource_manager_ref(rm, RESOURCE_TYPE_IMAGE, "earth");
ASSERT_EQ(r != NULL, true);
ASSERT_EQ(resource_manager_unref(rm, r), RET_OK);
resource_manager_destroy(rm);
}