fix dirty rect when show_fps

This commit is contained in:
xianjimli 2018-11-21 18:13:41 +08:00
parent 36f7726894
commit 094e823e0a
3 changed files with 24 additions and 21 deletions

View File

@ -281,7 +281,7 @@
#include "assets/inc/images/3.data"
#include "assets/inc/images/arrow_left_n.data"
#include "assets/inc/images/edit_clear_p.data"
#endif/*WITH_STB_IMAGE*/
#endif /*WITH_STB_IMAGE*/
#ifdef WITH_VGCANVAS
#include "assets/inc/images/pointer_4.bsvg"
#include "assets/inc/images/pointer_2.bsvg"
@ -294,17 +294,17 @@
#include "assets/inc/images/pointer_red.bsvg"
#include "assets/inc/images/pointer_big.bsvg"
#include "assets/inc/images/girl.bsvg"
#endif/*WITH_VGCANVAS*/
#endif /*WITH_VGCANVAS*/
#ifdef WITH_STB_FONT
#ifdef WITH_MINI_FONT
#include "assets/inc/fonts/default.mini.res"
#else/*WITH_MINI_FONT*/
#else /*WITH_MINI_FONT*/
#include "assets/inc/fonts/default.res"
#endif/*WITH_MINI_FONT*/
#else/*WITH_STB_FONT*/
#endif /*WITH_MINI_FONT*/
#else /*WITH_STB_FONT*/
#include "assets/inc/fonts/default.data"
#endif/*WITH_STB_FONT*/
#endif/*WITH_FS_RES*/
#endif /*WITH_STB_FONT*/
#endif /*WITH_FS_RES*/
ret_t assets_init(void) {
assets_manager_t* rm = assets_manager();
@ -508,7 +508,7 @@ ret_t assets_init(void) {
assets_manager_add(rm, image_pointer_red);
assets_manager_add(rm, image_pointer_big);
assets_manager_add(rm, image_girl);
#endif/*WITH_VGCANVAS*/
#endif /*WITH_VGCANVAS*/
#endif
tk_init_assets();

View File

@ -1152,21 +1152,20 @@ ret_t canvas_set_fps(canvas_t* c, bool_t show_fps, uint32_t fps) {
static ret_t canvas_draw_fps(canvas_t* c) {
lcd_t* lcd = c->lcd;
if (c->show_fps && c->lcd->draw_mode != LCD_DRAW_OFFLINE) {
if (c->show_fps && c->lcd->draw_mode == LCD_DRAW_NORMAL) {
rect_t r;
char fps[20];
wchar_t wfps[20];
r = rect_init(0, 0, 60, 30);
canvas_set_font(c, NULL, 16);
canvas_set_clip_rect(c, NULL);
canvas_set_text_color(c, color_init(0xf0, 0xf0, 0xf0, 0xff));
canvas_set_fill_color(c, color_init(0x20, 0x20, 0x20, 0xff));
lcd->fps_rect = r;
tk_snprintf(fps, sizeof(fps), "%dfps", (int)(c->fps));
utf8_to_utf16(fps, wfps, strlen(fps) + 1);
utf8_to_utf16(fps, wfps, strlen(fps) + 1);
canvas_fill_rect(c, r.x, r.y, r.w, r.h);
canvas_draw_text(c, wfps, wcslen(wfps), r.x + 8, r.y + 8);
} else {

View File

@ -272,10 +272,11 @@ static ret_t window_manager_paint_cursor(widget_t* widget, canvas_t* c) {
bitmap_t bitmap;
window_manager_t* wm = WINDOW_MANAGER(widget);
return_value_if_fail(image_manager_load(image_manager(), wm->cursor, &bitmap) == RET_OK,
RET_BAD_PARAMS);
canvas_draw_icon(c, &bitmap, wm->r_cursor.x, wm->r_cursor.y);
if (wm->cursor != NULL) {
return_value_if_fail(image_manager_load(image_manager(), wm->cursor, &bitmap) == RET_OK,
RET_BAD_PARAMS);
canvas_draw_icon(c, &bitmap, wm->r_cursor.x, wm->r_cursor.y);
}
return RET_OK;
}
@ -313,23 +314,26 @@ static ret_t window_manager_paint_normal(widget_t* widget, canvas_t* c) {
window_manager_inc_fps(widget);
if ((dr->w && dr->h) || wm->show_fps) {
if (wm->show_fps) {
rect_t fps_rect = rect_init(0, 0, 60, 30);
widget_invalidate(widget, &fps_rect);
}
if (dr->w && dr->h) {
uint32_t start_time = time_now_ms();
rect_t r = window_manager_calc_dirty_rect(wm);
if ((r.w > 0 && r.h > 0) || wm->show_fps) {
if (r.w > 0 && r.h > 0) {
ENSURE(canvas_begin_frame(c, &r, LCD_DRAW_NORMAL) == RET_OK);
ENSURE(widget_paint(WIDGET(wm), c) == RET_OK);
if (wm->cursor != NULL) {
window_manager_paint_cursor(widget, c);
}
window_manager_paint_cursor(widget, c);
ENSURE(canvas_end_frame(c) == RET_OK);
wm->last_paint_cost = time_now_ms() - start_time;
wm->last_dirty_rect = wm->dirty_rect;
/*
log_debug("%s x=%d y=%d w=%d h=%d cost=%d\n", __FUNCTION__, (int)(r.x), (int)(r.y),
(int)(r.w), (int)(r.h), (int)wm->last_paint_cost);
*/
wm->last_dirty_rect = wm->dirty_rect;
}
}