improve arc draw accuracy
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
*********************/
|
*********************/
|
||||||
#include "lv_draw_arc.h"
|
#include "lv_draw_arc.h"
|
||||||
#include "lv_draw_mask.h"
|
#include "lv_draw_mask.h"
|
||||||
#include "../lv_misc/lv_math.h" // LV_TRIGO_SHIFT
|
#include "../lv_misc/lv_math.h"
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
/**********************
|
/**********************
|
||||||
* STATIC PROTOTYPES
|
* STATIC PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
|
static void get_rounded_area(int16_t angle, lv_coord_t radius, uint8_t tickness, lv_area_t * res_area);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
@@ -64,8 +65,8 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, cons
|
|||||||
lv_area_t area;
|
lv_area_t area;
|
||||||
area.x1 = center_x - radius;
|
area.x1 = center_x - radius;
|
||||||
area.y1 = center_y - radius;
|
area.y1 = center_y - radius;
|
||||||
area.x2 = center_x + radius;
|
area.x2 = center_x + radius - 1; /*-1 because the center already belongs to the left/bottom part*/
|
||||||
area.y2 = center_y + radius;
|
area.y2 = center_y + radius - 1;
|
||||||
|
|
||||||
lv_draw_rect(&area, clip_area, &circle_style, LV_OPA_COVER);
|
lv_draw_rect(&area, clip_area, &circle_style, LV_OPA_COVER);
|
||||||
|
|
||||||
@@ -77,27 +78,22 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, cons
|
|||||||
circle_style.body.opa = LV_OPA_COVER;
|
circle_style.body.opa = LV_OPA_COVER;
|
||||||
circle_style.body.border.width = 0;
|
circle_style.body.border.width = 0;
|
||||||
|
|
||||||
lv_coord_t thick_half = style->line.width / 2;
|
|
||||||
lv_coord_t cir_x = ((radius - thick_half + 1) * lv_trigo_sin(90 - start_angle) >> LV_TRIGO_SHIFT);
|
|
||||||
lv_coord_t cir_y = ((radius - thick_half + 1) * lv_trigo_sin(start_angle) >> LV_TRIGO_SHIFT);
|
|
||||||
|
|
||||||
lv_area_t round_area;
|
lv_area_t round_area;
|
||||||
round_area.x1 = cir_x + center_x - thick_half + 1;
|
get_rounded_area(start_angle, radius, style->line.width, &round_area);
|
||||||
round_area.y1 = cir_y + center_y - thick_half + 1;
|
round_area.x1 += center_x;
|
||||||
round_area.x2 = cir_x + center_x + thick_half;
|
round_area.x2 += center_x;
|
||||||
round_area.y2 = cir_y + center_y + thick_half;
|
round_area.y1 += center_y;
|
||||||
|
round_area.y2 += center_y;
|
||||||
|
|
||||||
lv_draw_rect(&round_area, clip_area, &circle_style, LV_OPA_COVER);
|
lv_draw_rect(&round_area, clip_area, &circle_style, opa_scale);
|
||||||
|
|
||||||
cir_x = ((radius - thick_half + 1) * lv_trigo_sin(90 - end_angle) >> LV_TRIGO_SHIFT);
|
get_rounded_area(end_angle, radius, style->line.width, &round_area);
|
||||||
cir_y = ((radius - thick_half + 1) * lv_trigo_sin(end_angle) >> LV_TRIGO_SHIFT);
|
round_area.x1 += center_x;
|
||||||
|
round_area.x2 += center_x;
|
||||||
|
round_area.y1 += center_y;
|
||||||
|
round_area.y2 += center_y;
|
||||||
|
|
||||||
round_area.x1 = cir_x + center_x - thick_half + 1;
|
lv_draw_rect(&round_area, clip_area, &circle_style, opa_scale);
|
||||||
round_area.y1 = cir_y + center_y - thick_half + 1;
|
|
||||||
round_area.x2 = cir_x + center_x + thick_half;
|
|
||||||
round_area.y2 = cir_y + center_y + thick_half;
|
|
||||||
|
|
||||||
lv_draw_rect(&round_area, clip_area, &circle_style, LV_OPA_COVER);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,3 +102,46 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, cons
|
|||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
|
static void get_rounded_area(int16_t angle, lv_coord_t radius, uint8_t tickness, lv_area_t * res_area)
|
||||||
|
{
|
||||||
|
lv_coord_t thick_half = tickness / 2;
|
||||||
|
lv_coord_t thick_corr = tickness & 0x01 ? 0 : 1;
|
||||||
|
|
||||||
|
lv_coord_t rx_corr;
|
||||||
|
lv_coord_t ry_corr;
|
||||||
|
|
||||||
|
if(angle > 90 && angle < 270) rx_corr = 0;
|
||||||
|
else rx_corr = 0;
|
||||||
|
|
||||||
|
if(angle > 0 && angle < 180) ry_corr = 0;
|
||||||
|
else ry_corr = 0;
|
||||||
|
|
||||||
|
lv_coord_t cir_x;
|
||||||
|
lv_coord_t cir_y;
|
||||||
|
|
||||||
|
cir_x = ((radius - rx_corr - thick_half) * lv_trigo_sin(90 - angle)) >> (LV_TRIGO_SHIFT - 4);
|
||||||
|
cir_y = ((radius - ry_corr - thick_half) * lv_trigo_sin(angle)) >> (LV_TRIGO_SHIFT - 4);
|
||||||
|
|
||||||
|
/* Actually the center of the pixel need to be calculated so apply 1/2 px offset*/
|
||||||
|
if(cir_x > 0) {
|
||||||
|
cir_x = (cir_x - 8) >> 4;
|
||||||
|
res_area->x1 = cir_x - thick_half + thick_corr;
|
||||||
|
res_area->x2 = cir_x + thick_half;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cir_x = (cir_x + 2) >> 4;
|
||||||
|
res_area->x1 = cir_x - thick_half;
|
||||||
|
res_area->x2 = cir_x + thick_half - thick_corr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cir_y > 0) {
|
||||||
|
cir_y = (cir_y - 8) >> 4;
|
||||||
|
res_area->y1 = cir_y - thick_half + thick_corr;
|
||||||
|
res_area->y2 = cir_y + thick_half;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cir_y = (cir_y + 8) >> 4;
|
||||||
|
res_area->y1 = cir_y - thick_half;
|
||||||
|
res_area->y2 = cir_y + thick_half - thick_corr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user