From 5fedbdf4143c8f6eb90ac0e94aef206f82ad61d7 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 16 May 2018 22:35:19 +0200 Subject: [PATCH] fix drawing of 1px border with zero radius and AA --- lv_draw/lv_draw.c | 82 ++++++++++++++++++++++------------------- lv_misc/lv_font.c | 2 +- lv_misc/lv_txt.c | 2 +- lv_misc/lv_txt.h | 8 ++-- lv_objx/lv_objx_templ.h | 2 +- lvgl.h | 1 + 6 files changed, 52 insertions(+), 45 deletions(-) diff --git a/lv_draw/lv_draw.c b/lv_draw/lv_draw.c index 186d82edfb..430c7721b3 100644 --- a/lv_draw/lv_draw.c +++ b/lv_draw/lv_draw.c @@ -1179,6 +1179,48 @@ static void lv_draw_rect_border_straight(const lv_area_t * coords, const lv_area /* Modify the corner_size if corner is drawn */ corner_size ++; + /*If radius == 0 is a special case*/ + if(style->body.radius == 0) { + /*Left top corner*/ + if(part & LV_BORDER_TOP) { + work_area.x1 = coords->x1; + work_area.x2 = coords->x2; + work_area.y1 = coords->y1; + work_area.y2 = coords->y1 + bwidth; + fill_fp(&work_area, mask, color, opa); + } + + /*Right top corner*/ + if(part & LV_BORDER_RIGHT) { + work_area.x1 = coords->x2 - bwidth; + work_area.x2 = coords->x2; + work_area.y1 = coords->y1 + (part & LV_BORDER_TOP ? bwidth + 1 : 0); + work_area.y2 = coords->y2 - (part & LV_BORDER_BOTTOM ? bwidth + 1 : 0); + fill_fp(&work_area, mask, color, opa); + } + + /*Left bottom corner*/ + if(part & LV_BORDER_LEFT) { + work_area.x1 = coords->x1; + work_area.x2 = coords->x1 + bwidth; + work_area.y1 = coords->y1 + (part & LV_BORDER_TOP ? bwidth + 1 : 0); + work_area.y2 = coords->y2 - (part & LV_BORDER_BOTTOM ? bwidth + 1 : 0); + fill_fp(&work_area, mask, color, opa); + } + + /*Right bottom corner*/ + if(part & LV_BORDER_BOTTOM) { + work_area.x1 = coords->x1; + work_area.x2 = coords->x2; + work_area.y1 = coords->y2 - bwidth; + work_area.y2 = coords->y2; + fill_fp(&work_area, mask, color, opa); + } + return; + } + + + /*Depending one which part's are drawn modify the area lengths */ if(part & LV_BORDER_TOP) work_area.y1 = coords->y1 + corner_size; else work_area.y1 = coords->y1 + radius; @@ -1217,6 +1259,8 @@ static void lv_draw_rect_border_straight(const lv_area_t * coords, const lv_area fill_fp(&work_area, mask, color, opa); } + color.full += 0x123456; + /*Draw the a remaining rectangles if the radius is smaller then bwidth */ if(length_corr != 0) { /*Left top correction*/ @@ -1256,44 +1300,6 @@ static void lv_draw_rect_border_straight(const lv_area_t * coords, const lv_area } } - /*If radius == 0 one px on the corners are not drawn by main drawer*/ - if(style->body.radius == 0) { - /*Left top corner*/ - if(part & (LV_BORDER_TOP | LV_BORDER_LEFT)) { - work_area.x1 = coords->x1; - work_area.x2 = coords->x1 + LV_ANTIALIAS; - work_area.y1 = coords->y1; - work_area.y2 = coords->y1 + LV_ANTIALIAS; - fill_fp(&work_area, mask, color, opa); - } - - /*Right top corner*/ - if(part & (LV_BORDER_TOP | LV_BORDER_RIGHT)) { - work_area.x1 = coords->x2 - LV_ANTIALIAS; - work_area.x2 = coords->x2; - work_area.y1 = coords->y1; - work_area.y2 = coords->y1 + LV_ANTIALIAS; - fill_fp(&work_area, mask, color, opa); - } - - /*Left bottom corner*/ - if(part & (LV_BORDER_BOTTOM | LV_BORDER_LEFT)) { - work_area.x1 = coords->x1; - work_area.x2 = coords->x1 + LV_ANTIALIAS; - work_area.y1 = coords->y2 - LV_ANTIALIAS; - work_area.y2 = coords->y2; - fill_fp(&work_area, mask, color, opa); - } - - /*Right bottom corner*/ - if(part & (LV_BORDER_BOTTOM | LV_BORDER_RIGHT)) { - work_area.x1 = coords->x2 - LV_ANTIALIAS; - work_area.x2 = coords->x2; - work_area.y1 = coords->y2 - LV_ANTIALIAS; - work_area.y2 = coords->y2; - fill_fp(&work_area, mask, color, opa); - } - } } diff --git a/lv_misc/lv_font.c b/lv_misc/lv_font.c index 8fedb11328..e6541452c5 100644 --- a/lv_misc/lv_font.c +++ b/lv_misc/lv_font.c @@ -213,7 +213,7 @@ const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter) /** * Get the width of a letter in a font * @param font_p pointer to a font - * @param letter a letter + * @param letter an UNICODE character code * @return the width of a letter */ uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter) diff --git a/lv_misc/lv_txt.c b/lv_misc/lv_txt.c index d19c6365df..5c8e869f30 100644 --- a/lv_misc/lv_txt.c +++ b/lv_misc/lv_txt.c @@ -170,7 +170,7 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font, /** * Give the length of a text with a given font * @param txt a '\0' terminate string - * @param length length of 'txt' in bytes + * @param length length of 'txt' in character count and not bytes(UTF-8 can be 1,2,3 or 4 bytes long) * @param font pointer to a font * @param letter_space letter space * @param flags settings for the text from 'txt_flag_t' enum diff --git a/lv_misc/lv_txt.h b/lv_misc/lv_txt.h index 3bb489621a..3f3219ba1a 100644 --- a/lv_misc/lv_txt.h +++ b/lv_misc/lv_txt.h @@ -74,14 +74,14 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font_p, /** * Give the length of a text with a given font * @param txt a '\0' terminate string - * @param char_num number of characters in 'txt' - * @param font_p pointer to a font + * @param length length of 'txt' in character count and not bytes(UTF-8 can be 1,2,3 or 4 bytes long) + * @param font pointer to a font * @param letter_space letter space * @param flags settings for the text from 'txt_flag_t' enum * @return length of a char_num long text */ -lv_coord_t lv_txt_get_width(const char * txt, uint16_t char_num, - const lv_font_t * font_p, lv_coord_t letter_space, lv_txt_flag_t flag); +lv_coord_t lv_txt_get_width(const char * txt, uint16_t length, + const lv_font_t * font, lv_coord_t letter_space, lv_txt_flag_t flag); /** * Check next character in a string and decide if te character is part of the command or not diff --git a/lv_objx/lv_objx_templ.h b/lv_objx/lv_objx_templ.h index 8a95c9e7e1..6c244c2f1c 100644 --- a/lv_objx/lv_objx_templ.h +++ b/lv_objx/lv_objx_templ.h @@ -86,7 +86,7 @@ void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, lv_style_t *sty * @param type which style should be get * @return style pointer to the style * */ -lv_style_t * lv_btn_get_style(lv_obj_t * templ, lv_templ_style_t type); +lv_style_t * lv_templ_get_style(lv_obj_t * templ, lv_templ_style_t type); /*===================== * Other functions diff --git a/lvgl.h b/lvgl.h index 13b1fc579b..46afb3a0c3 100644 --- a/lvgl.h +++ b/lvgl.h @@ -49,6 +49,7 @@ extern "C" { #include "lv_objx/lv_lmeter.h" #include "lv_objx/lv_sw.h" #include "lv_objx/lv_kb.h" +#include "lv_objx/lv_calendar.h" /********************* * DEFINES