mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
add arc drawing
This commit is contained in:
parent
63935d283d
commit
3d72e3915b
@ -7,7 +7,7 @@
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_draw_arc.h"
|
||||
#include "../lv_misc/lv_math.h"
|
||||
#include "lv_mask.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@ -20,13 +20,6 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static uint16_t fast_atan2(int x, int y);
|
||||
static void ver_line(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_coord_t len, lv_color_t color,
|
||||
lv_opa_t opa);
|
||||
static void hor_line(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_coord_t len, lv_color_t color,
|
||||
lv_opa_t opa);
|
||||
static bool deg_test_norm(uint16_t deg, uint16_t start, uint16_t end);
|
||||
static bool deg_test_inv(uint16_t deg, uint16_t start, uint16_t end);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -51,221 +44,41 @@ static bool deg_test_inv(uint16_t deg, uint16_t start, uint16_t end);
|
||||
* @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used)
|
||||
* @param opa_scale scale down all opacities by the factor
|
||||
*/
|
||||
void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, const lv_area_t * mask,
|
||||
void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, const lv_area_t * clip_area,
|
||||
uint16_t start_angle, uint16_t end_angle, const lv_style_t * style, lv_opa_t opa_scale)
|
||||
{
|
||||
lv_coord_t thickness = style->line.width;
|
||||
if(thickness > radius) thickness = radius;
|
||||
|
||||
lv_coord_t r_out = radius;
|
||||
lv_coord_t r_in = r_out - thickness;
|
||||
int16_t deg_base;
|
||||
int16_t deg;
|
||||
lv_coord_t x_start[4];
|
||||
lv_coord_t x_end[4];
|
||||
lv_style_t circle_style;
|
||||
lv_style_copy(&circle_style, style);
|
||||
circle_style.body.radius = LV_RADIUS_CIRCLE;
|
||||
circle_style.body.opa = LV_OPA_TRANSP;
|
||||
circle_style.body.border.width = style->line.width;
|
||||
circle_style.body.border.color = style->line.color;
|
||||
|
||||
lv_color_t color = style->line.color;
|
||||
lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->body.opa : (uint16_t)((uint16_t)style->body.opa * opa_scale) >> 8;
|
||||
|
||||
bool (*deg_test)(uint16_t, uint16_t, uint16_t);
|
||||
if(start_angle <= end_angle)
|
||||
deg_test = deg_test_norm;
|
||||
else
|
||||
deg_test = deg_test_inv;
|
||||
lv_mask_param_t mask_angle_param;
|
||||
lv_mask_angle_init(&mask_angle_param, center_x, center_y, start_angle, end_angle);
|
||||
|
||||
if(deg_test(270, start_angle, end_angle))
|
||||
hor_line(center_x - r_out + 1, center_y, mask, thickness - 1, color, opa); /*Left Middle*/
|
||||
if(deg_test(90, start_angle, end_angle))
|
||||
hor_line(center_x + r_in, center_y, mask, thickness - 1, color, opa); /*Right Middle*/
|
||||
if(deg_test(180, start_angle, end_angle))
|
||||
ver_line(center_x, center_y - r_out + 1, mask, thickness - 1, color, opa); /*Top Middle*/
|
||||
if(deg_test(0, start_angle, end_angle))
|
||||
ver_line(center_x, center_y + r_in, mask, thickness - 1, color, opa); /*Bottom middle*/
|
||||
int16_t mask_angle_id = lv_mask_add(lv_mask_angle, &mask_angle_param, NULL);
|
||||
|
||||
uint32_t r_out_sqr = r_out * r_out;
|
||||
uint32_t r_in_sqr = r_in * r_in;
|
||||
int16_t xi;
|
||||
int16_t yi;
|
||||
for(yi = -r_out; yi < 0; yi++) {
|
||||
x_start[0] = LV_COORD_MIN;
|
||||
x_start[1] = LV_COORD_MIN;
|
||||
x_start[2] = LV_COORD_MIN;
|
||||
x_start[3] = LV_COORD_MIN;
|
||||
x_end[0] = LV_COORD_MIN;
|
||||
x_end[1] = LV_COORD_MIN;
|
||||
x_end[2] = LV_COORD_MIN;
|
||||
x_end[3] = LV_COORD_MIN;
|
||||
for(xi = -r_out; xi < 0; xi++) {
|
||||
|
||||
uint32_t r_act_sqr = xi * xi + yi * yi;
|
||||
if(r_act_sqr > r_out_sqr) continue;
|
||||
printf("s:%d, e:%d\n", start_angle, end_angle);
|
||||
|
||||
deg_base = fast_atan2(xi, yi) - 180;
|
||||
|
||||
deg = 180 + deg_base;
|
||||
if(deg_test(deg, start_angle, end_angle)) {
|
||||
if(x_start[0] == LV_COORD_MIN) x_start[0] = xi;
|
||||
} else if(x_start[0] != LV_COORD_MIN && x_end[0] == LV_COORD_MIN) {
|
||||
x_end[0] = xi - 1;
|
||||
}
|
||||
lv_area_t area;
|
||||
area.x1 = center_x - radius;
|
||||
area.y1 = center_y - radius;
|
||||
area.x2 = center_x + radius;
|
||||
area.y2 = center_y + radius;
|
||||
|
||||
deg = 360 - deg_base;
|
||||
if(deg_test(deg, start_angle, end_angle)) {
|
||||
if(x_start[1] == LV_COORD_MIN) x_start[1] = xi;
|
||||
} else if(x_start[1] != LV_COORD_MIN && x_end[1] == LV_COORD_MIN) {
|
||||
x_end[1] = xi - 1;
|
||||
}
|
||||
lv_draw_rect(&area, clip_area, &circle_style, LV_OPA_COVER);
|
||||
|
||||
deg = 180 - deg_base;
|
||||
if(deg_test(deg, start_angle, end_angle)) {
|
||||
if(x_start[2] == LV_COORD_MIN) x_start[2] = xi;
|
||||
} else if(x_start[2] != LV_COORD_MIN && x_end[2] == LV_COORD_MIN) {
|
||||
x_end[2] = xi - 1;
|
||||
}
|
||||
lv_mask_remove_id(mask_angle_id);
|
||||
|
||||
deg = deg_base;
|
||||
if(deg_test(deg, start_angle, end_angle)) {
|
||||
if(x_start[3] == LV_COORD_MIN) x_start[3] = xi;
|
||||
} else if(x_start[3] != LV_COORD_MIN && x_end[3] == LV_COORD_MIN) {
|
||||
x_end[3] = xi - 1;
|
||||
}
|
||||
|
||||
if(r_act_sqr < r_in_sqr)
|
||||
break; /*No need to continue the iteration in x once we found the inner edge of the
|
||||
arc*/
|
||||
}
|
||||
|
||||
if(x_start[0] != LV_COORD_MIN) {
|
||||
if(x_end[0] == LV_COORD_MIN) x_end[0] = xi - 1;
|
||||
hor_line(center_x + x_start[0], center_y + yi, mask, x_end[0] - x_start[0], color, opa);
|
||||
}
|
||||
|
||||
if(x_start[1] != LV_COORD_MIN) {
|
||||
if(x_end[1] == LV_COORD_MIN) x_end[1] = xi - 1;
|
||||
hor_line(center_x + x_start[1], center_y - yi, mask, x_end[1] - x_start[1], color, opa);
|
||||
}
|
||||
|
||||
if(x_start[2] != LV_COORD_MIN) {
|
||||
if(x_end[2] == LV_COORD_MIN) x_end[2] = xi - 1;
|
||||
hor_line(center_x - x_end[2], center_y + yi, mask, LV_MATH_ABS(x_end[2] - x_start[2]), color, opa);
|
||||
}
|
||||
|
||||
if(x_start[3] != LV_COORD_MIN) {
|
||||
if(x_end[3] == LV_COORD_MIN) x_end[3] = xi - 1;
|
||||
hor_line(center_x - x_end[3], center_y - yi, mask, LV_MATH_ABS(x_end[3] - x_start[3]), color, opa);
|
||||
}
|
||||
|
||||
#if LV_ANTIALIAS
|
||||
/*TODO*/
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static uint16_t fast_atan2(int x, int y)
|
||||
{
|
||||
// Fast XY vector to integer degree algorithm - Jan 2011 www.RomanBlack.com
|
||||
// Converts any XY values including 0 to a degree value that should be
|
||||
// within +/- 1 degree of the accurate value without needing
|
||||
// large slow trig functions like ArcTan() or ArcCos().
|
||||
// NOTE! at least one of the X or Y values must be non-zero!
|
||||
// This is the full version, for all 4 quadrants and will generate
|
||||
// the angle in integer degrees from 0-360.
|
||||
// Any values of X and Y are usable including negative values provided
|
||||
// they are between -1456 and 1456 so the 16bit multiply does not overflow.
|
||||
|
||||
unsigned char negflag;
|
||||
unsigned char tempdegree;
|
||||
unsigned char comp;
|
||||
unsigned int degree; /*this will hold the result*/
|
||||
unsigned int ux;
|
||||
unsigned int uy;
|
||||
|
||||
/*Save the sign flags then remove signs and get XY as unsigned ints*/
|
||||
negflag = 0;
|
||||
if(x < 0) {
|
||||
negflag += 0x01; /*x flag bit*/
|
||||
x = (0 - x); /*is now +*/
|
||||
}
|
||||
ux = x; /*copy to unsigned var before multiply*/
|
||||
if(y < 0) {
|
||||
negflag += 0x02; /*y flag bit*/
|
||||
y = (0 - y); /*is now +*/
|
||||
}
|
||||
uy = y; /*copy to unsigned var before multiply*/
|
||||
|
||||
/*1. Calc the scaled "degrees"*/
|
||||
if(ux > uy) {
|
||||
degree = (uy * 45) / ux; /*degree result will be 0-45 range*/
|
||||
negflag += 0x10; /*octant flag bit*/
|
||||
} else {
|
||||
degree = (ux * 45) / uy; /*degree result will be 0-45 range*/
|
||||
}
|
||||
|
||||
/*2. Compensate for the 4 degree error curve*/
|
||||
comp = 0;
|
||||
tempdegree = degree; /*use an unsigned char for speed!*/
|
||||
if(tempdegree > 22) { /*if top half of range*/
|
||||
if(tempdegree <= 44) comp++;
|
||||
if(tempdegree <= 41) comp++;
|
||||
if(tempdegree <= 37) comp++;
|
||||
if(tempdegree <= 32) comp++; /*max is 4 degrees compensated*/
|
||||
} else { /*else is lower half of range*/
|
||||
if(tempdegree >= 2) comp++;
|
||||
if(tempdegree >= 6) comp++;
|
||||
if(tempdegree >= 10) comp++;
|
||||
if(tempdegree >= 15) comp++; /*max is 4 degrees compensated*/
|
||||
}
|
||||
degree += comp; /*degree is now accurate to +/- 1 degree!*/
|
||||
|
||||
/*Invert degree if it was X>Y octant, makes 0-45 into 90-45*/
|
||||
if(negflag & 0x10) degree = (90 - degree);
|
||||
|
||||
/*3. Degree is now 0-90 range for this quadrant,*/
|
||||
/*need to invert it for whichever quadrant it was in*/
|
||||
if(negflag & 0x02) { /*if -Y*/
|
||||
if(negflag & 0x01) /*if -Y -X*/
|
||||
degree = (180 + degree);
|
||||
else /*else is -Y +X*/
|
||||
degree = (180 - degree);
|
||||
} else { /*else is +Y*/
|
||||
if(negflag & 0x01) /*if +Y -X*/
|
||||
degree = (360 - degree);
|
||||
}
|
||||
return degree;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
static void ver_line(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_coord_t len, lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
lv_area_t area;
|
||||
lv_area_set(&area, x, y, x, y + len);
|
||||
|
||||
lv_draw_fill(&area, mask, color, opa);
|
||||
}
|
||||
|
||||
static void hor_line(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_coord_t len, lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
lv_area_t area;
|
||||
lv_area_set(&area, x, y, x + len, y);
|
||||
|
||||
lv_draw_fill(&area, mask, color, opa);
|
||||
}
|
||||
|
||||
static bool deg_test_norm(uint16_t deg, uint16_t start, uint16_t end)
|
||||
{
|
||||
if(deg >= start && deg <= end)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool deg_test_inv(uint16_t deg, uint16_t start, uint16_t end)
|
||||
{
|
||||
if(deg >= start || deg <= end) {
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
@ -393,7 +393,6 @@ void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * clip_area, const
|
||||
mask_p = 0;
|
||||
}
|
||||
|
||||
|
||||
col_bit += ((g.box_w - col_end) + col_start) * g.bpp;
|
||||
|
||||
map_p += (col_bit >> 3);
|
||||
@ -424,8 +423,6 @@ void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * clip_area, const
|
||||
void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, const uint8_t * map_p, lv_opa_t opa,
|
||||
bool chroma_key, bool alpha_byte, lv_color_t recolor, lv_opa_t recolor_opa)
|
||||
{
|
||||
|
||||
|
||||
if(opa < LV_OPA_MIN) return;
|
||||
if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;
|
||||
|
||||
|
@ -104,12 +104,12 @@ void lv_mask_remove_custom(void * custom_id)
|
||||
|
||||
uint8_t lv_mask_get_cnt(void)
|
||||
{
|
||||
uint8_t cnt = 0;
|
||||
uint8_t i;
|
||||
for(i = 0; i < LV_MASK_MAX_NUM; i++) {
|
||||
if(mask_list[i].cb) cnt++;
|
||||
}
|
||||
return cnt;
|
||||
uint8_t cnt = 0;
|
||||
uint8_t i;
|
||||
for(i = 0; i < LV_MASK_MAX_NUM; i++) {
|
||||
if(mask_list[i].cb) cnt++;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
void lv_mask_line_points_init(lv_mask_param_t * param, lv_coord_t p1x, lv_coord_t p1y, lv_coord_t p2x, lv_coord_t p2y, lv_line_mask_side_t side)
|
||||
@ -201,7 +201,7 @@ void lv_mask_line_angle_init(lv_mask_param_t * param, lv_coord_t p1x, lv_coord_t
|
||||
* Theoretically a line with `deg` or `deg+180` is the same only the points are swapped
|
||||
* Find the degree which keeps the origo in place */
|
||||
|
||||
// deg = 360-deg; /*To get clock-wise direction*/
|
||||
// deg = 360-deg; /*To get clock-wise direction*/
|
||||
if(deg > 180) deg -= 180; /*> 180 will swap the origo*/
|
||||
|
||||
|
||||
@ -249,7 +249,13 @@ lv_mask_res_t lv_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs
|
||||
}
|
||||
}
|
||||
else {
|
||||
return LV_MASK_RES_FULL_TRANSP;
|
||||
if(abs_x + len < 0) return LV_MASK_RES_FULL_TRANSP;
|
||||
else {
|
||||
int32_t k = - abs_x;
|
||||
if(k < 0) k = 0;
|
||||
if(k >= 0 && k < len) memset(&mask_buf[00], 0x00,k);
|
||||
return LV_MASK_RES_CHANGED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -272,27 +278,29 @@ void lv_mask_angle_init(lv_mask_param_t * param, lv_coord_t origo_x, lv_coord_t
|
||||
lv_line_mask_side_t start_side;
|
||||
lv_line_mask_side_t end_side;
|
||||
|
||||
p->delta_deg = LV_MATH_ABS(start_angle - end_angle);
|
||||
if(end_angle < start_angle) {
|
||||
p->delta_deg = 360 - start_angle + end_angle;
|
||||
} else {
|
||||
p->delta_deg = LV_MATH_ABS(end_angle - start_angle);
|
||||
}
|
||||
|
||||
p->start_angle = start_angle;
|
||||
p->end_angle = end_angle;
|
||||
p->origo.x = origo_x;
|
||||
p->origo.y = origo_y;
|
||||
|
||||
/*The most simple case the, */
|
||||
if(p->delta_deg <= 180) {
|
||||
if(start_angle > 0 && start_angle < 180) {
|
||||
start_side = LV_LINE_MASK_SIDE_LEFT;
|
||||
}
|
||||
else if(start_angle > 180 && start_angle < 360) {
|
||||
start_side = LV_LINE_MASK_SIDE_RIGHT;
|
||||
}
|
||||
if(start_angle > 0 && start_angle < 180) {
|
||||
start_side = LV_LINE_MASK_SIDE_LEFT;
|
||||
}
|
||||
else if(start_angle > 180 && start_angle < 360) {
|
||||
start_side = LV_LINE_MASK_SIDE_RIGHT;
|
||||
}
|
||||
|
||||
if(end_angle > 0 && end_angle < 180) {
|
||||
end_side = LV_LINE_MASK_SIDE_RIGHT;
|
||||
}
|
||||
else if(end_angle > 180 && end_angle < 360) {
|
||||
end_side = LV_LINE_MASK_SIDE_LEFT;
|
||||
}
|
||||
if(end_angle > 0 && end_angle < 180) {
|
||||
end_side = LV_LINE_MASK_SIDE_RIGHT;
|
||||
}
|
||||
else if(end_angle > 180 && end_angle < 360) {
|
||||
end_side = LV_LINE_MASK_SIDE_LEFT;
|
||||
}
|
||||
|
||||
lv_mask_line_angle_init((lv_mask_param_t*)&p->start_line, origo_x, origo_y, start_angle, start_side);
|
||||
@ -302,47 +310,129 @@ void lv_mask_angle_init(lv_mask_param_t * param, lv_coord_t origo_x, lv_coord_t
|
||||
|
||||
lv_mask_res_t lv_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_mask_param_t * param)
|
||||
{
|
||||
lv_mask_angle_param_t * p = ¶m->line;
|
||||
// if(p->delta_deg <= 180) {
|
||||
// if((p->start_angle <= 180 && abs_y >= p->origo.y) ||
|
||||
// (p->start_angle >= 180 && abs_y <= p->origo.y)) {
|
||||
// }
|
||||
|
||||
if(abs_y < p->origo.y) {
|
||||
// memset(mask_buf, 0x00, len);
|
||||
return LV_MASK_RES_FULL_COVER;
|
||||
}
|
||||
|
||||
lv_mask_angle_param_t * p = ¶m->angle;
|
||||
|
||||
lv_coord_t rel_y = abs_y - p->origo.y;
|
||||
lv_coord_t rel_x = abs_x - p->origo.x;
|
||||
|
||||
/*Start angle mask can work only from the end of end angle mask */
|
||||
lv_coord_t end_angle_first = (rel_y * p->end_line.xy_steep) >> 10;
|
||||
lv_coord_t start_angle_last= ((rel_y+1) * p->start_line.xy_steep) >> 10;
|
||||
|
||||
int32_t dist = (end_angle_first - start_angle_last) >> 1;
|
||||
if(p->start_angle < 180 && p->end_angle < 180 && p->start_angle != 0 && p->end_angle != 0 && p->start_angle > p->end_angle) {
|
||||
|
||||
lv_mask_res_t res1 = LV_MASK_RES_FULL_COVER;
|
||||
lv_mask_res_t res2 = LV_MASK_RES_FULL_COVER;
|
||||
|
||||
int32_t tmp = start_angle_last + dist - rel_x;
|
||||
if(tmp > len) tmp = len;
|
||||
if(tmp > 0) {
|
||||
res1 = lv_mask_line(&mask_buf[0], abs_x, abs_y, tmp, (lv_mask_param_t*)&p->start_line);
|
||||
if(res1 == LV_MASK_RES_FULL_TRANSP) {
|
||||
memset(&mask_buf[0], 0x00, tmp);
|
||||
if(abs_y < p->origo.y) {
|
||||
return LV_MASK_RES_FULL_COVER;
|
||||
}
|
||||
}
|
||||
|
||||
if(tmp > len) tmp = len;
|
||||
if(tmp < 0) tmp = 0;
|
||||
res2 = lv_mask_line(&mask_buf[tmp], abs_x+tmp, abs_y, len-tmp, (lv_mask_param_t*)&p->end_line);
|
||||
if(res2 == LV_MASK_RES_FULL_TRANSP) {
|
||||
memset(&mask_buf[tmp], 0x00, len-tmp);
|
||||
/*Start angle mask can work only from the end of end angle mask */
|
||||
lv_coord_t end_angle_first = (rel_y * p->end_line.xy_steep) >> 10;
|
||||
lv_coord_t start_angle_last= ((rel_y+1) * p->start_line.xy_steep) >> 10;
|
||||
|
||||
int32_t dist = (end_angle_first - start_angle_last) >> 1;
|
||||
|
||||
lv_mask_res_t res1 = LV_MASK_RES_FULL_COVER;
|
||||
lv_mask_res_t res2 = LV_MASK_RES_FULL_COVER;
|
||||
|
||||
int32_t tmp = start_angle_last + dist - rel_x;
|
||||
if(tmp > len) tmp = len;
|
||||
if(tmp > 0) {
|
||||
res1 = lv_mask_line(&mask_buf[0], abs_x, abs_y, tmp, (lv_mask_param_t*)&p->start_line);
|
||||
if(res1 == LV_MASK_RES_FULL_TRANSP) {
|
||||
memset(&mask_buf[0], 0x00, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
if(tmp > len) tmp = len;
|
||||
if(tmp < 0) tmp = 0;
|
||||
res2 = lv_mask_line(&mask_buf[tmp], abs_x+tmp, abs_y, len-tmp, (lv_mask_param_t*)&p->end_line);
|
||||
if(res2 == LV_MASK_RES_FULL_TRANSP) {
|
||||
memset(&mask_buf[tmp], 0x00, len-tmp);
|
||||
}
|
||||
if(res1 == res2) return res1;
|
||||
else return LV_MASK_RES_CHANGED;
|
||||
}
|
||||
else if(p->start_angle > 180 && p->end_angle > 180 && p->start_angle > p->end_angle) {
|
||||
|
||||
if(abs_y > p->origo.y) {
|
||||
return LV_MASK_RES_FULL_COVER;
|
||||
}
|
||||
|
||||
/*Start angle mask can work only from the end of end angle mask */
|
||||
lv_coord_t end_angle_first = (rel_y * p->end_line.xy_steep) >> 10;
|
||||
lv_coord_t start_angle_last= ((rel_y+1) * p->start_line.xy_steep) >> 10;
|
||||
|
||||
/*Do not let the line end cross the origo else it will affect the opposite part*/
|
||||
if(p->start_angle > 270 && p->start_angle <= 359 && start_angle_last < 0) start_angle_last = 0;
|
||||
else if(p->start_angle > 0 && p->start_angle <= 90 && start_angle_last < 0) start_angle_last = 0;
|
||||
else if(p->start_angle > 90 && p->start_angle < 270 && start_angle_last > 0) start_angle_last = 0;
|
||||
|
||||
if(p->end_angle > 270 && p->end_angle <= 359 && start_angle_last < 0) start_angle_last = 0;
|
||||
else if(p->end_angle > 0 && p->end_angle <= 90 && start_angle_last < 0) start_angle_last = 0;
|
||||
else if(p->end_angle > 90 && p->end_angle < 270 && start_angle_last > 0) start_angle_last = 0;
|
||||
|
||||
int32_t dist = (end_angle_first - start_angle_last) >> 1;
|
||||
|
||||
lv_mask_res_t res1 = LV_MASK_RES_FULL_COVER;
|
||||
lv_mask_res_t res2 = LV_MASK_RES_FULL_COVER;
|
||||
|
||||
int32_t tmp = start_angle_last + dist - rel_x;
|
||||
if(tmp > len) tmp = len;
|
||||
if(tmp > 0) {
|
||||
res1 = lv_mask_line(&mask_buf[0], abs_x, abs_y, tmp, (lv_mask_param_t*)&p->end_line);
|
||||
if(res1 == LV_MASK_RES_FULL_TRANSP) {
|
||||
memset(&mask_buf[0], 0x00, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
if(tmp > len) tmp = len;
|
||||
if(tmp < 0) tmp = 0;
|
||||
res2 = lv_mask_line(&mask_buf[tmp], abs_x+tmp, abs_y, len-tmp, (lv_mask_param_t*)&p->start_line);
|
||||
if(res2 == LV_MASK_RES_FULL_TRANSP) {
|
||||
memset(&mask_buf[tmp], 0x00, len-tmp);
|
||||
}
|
||||
if(res1 == res2) return res1;
|
||||
else return LV_MASK_RES_CHANGED;
|
||||
}
|
||||
else {
|
||||
|
||||
lv_mask_res_t res1 = LV_MASK_RES_FULL_COVER;
|
||||
lv_mask_res_t res2 = LV_MASK_RES_FULL_COVER;
|
||||
|
||||
if(p->start_angle == 180) {
|
||||
if(abs_y < p->origo.y) res1 = LV_MASK_RES_FULL_COVER;
|
||||
else res1 = LV_MASK_RES_UNKNOWN;
|
||||
}
|
||||
else if(p->start_angle == 0) {
|
||||
if(abs_y < p->origo.y) res1 = LV_MASK_RES_UNKNOWN;
|
||||
else res1 = LV_MASK_RES_FULL_COVER;
|
||||
}
|
||||
else if((p->start_angle < 180 && abs_y < p->origo.y) ||
|
||||
(p->start_angle > 180 && abs_y >= p->origo.y)) {
|
||||
res1 = LV_MASK_RES_UNKNOWN;
|
||||
}
|
||||
else {
|
||||
res1 = lv_mask_line(mask_buf, abs_x, abs_y, len, (lv_mask_param_t*)&p->start_line);
|
||||
}
|
||||
|
||||
if(p->end_angle == 180) {
|
||||
if(abs_y < p->origo.y) res2 = LV_MASK_RES_UNKNOWN;
|
||||
else res2 = LV_MASK_RES_FULL_COVER;
|
||||
}
|
||||
else if(p->end_angle == 0) {
|
||||
if(abs_y < p->origo.y) res2 = LV_MASK_RES_FULL_COVER;
|
||||
else res2 = LV_MASK_RES_UNKNOWN;
|
||||
}
|
||||
else if((p->end_angle < 180 && abs_y < p->origo.y) ||
|
||||
(p->end_angle > 180 && abs_y >= p->origo.y)) {
|
||||
res2 = LV_MASK_RES_UNKNOWN;
|
||||
}
|
||||
else {
|
||||
res2 = lv_mask_line(mask_buf, abs_x, abs_y, len, (lv_mask_param_t*)&p->end_line);
|
||||
}
|
||||
|
||||
if(res1 == LV_MASK_RES_FULL_TRANSP || res2 == LV_MASK_RES_FULL_TRANSP) return LV_MASK_RES_FULL_TRANSP;
|
||||
else if(res1 == LV_MASK_RES_UNKNOWN && res2 == LV_MASK_RES_UNKNOWN) return LV_MASK_RES_FULL_TRANSP;
|
||||
else if(res1 == LV_MASK_RES_FULL_COVER && res2 == LV_MASK_RES_FULL_COVER) return LV_MASK_RES_FULL_COVER;
|
||||
else return LV_MASK_RES_CHANGED;
|
||||
}
|
||||
if(res1 == res2) return res1;
|
||||
else return LV_MASK_RES_CHANGED;
|
||||
}
|
||||
|
||||
void lv_mask_radius_init(lv_mask_param_t * param, const lv_area_t * rect, lv_coord_t radius, bool inv)
|
||||
@ -369,7 +459,7 @@ lv_mask_res_t lv_mask_radius(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t a
|
||||
}
|
||||
|
||||
if((abs_x >= p->rect.x1 + p->radius && abs_x + len <= p->rect.x2 - p->radius) ||
|
||||
(abs_y >= p->rect.y1 + p->radius && abs_y <= p->rect.y2 - p->radius+1)) {
|
||||
(abs_y >= p->rect.y1 + p->radius && abs_y <= p->rect.y2 - p->radius+1)) {
|
||||
if(p->inv == 0) {
|
||||
/*Remove the edges*/
|
||||
int32_t last = p->rect.x1 - abs_x;
|
||||
@ -424,10 +514,10 @@ lv_mask_res_t lv_mask_radius(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t a
|
||||
|
||||
/* If x1 is on the next round coordinate (e.g. x0: 3.5, x1:4.0)
|
||||
* then treat x1 as x1: 3.99 to handle them as they were on the same pixel*/
|
||||
if(x0.i == x1.i - 1 && x1.f == 0) {
|
||||
x1.i--;
|
||||
x1.f = 0xFF;
|
||||
}
|
||||
if(x0.i == x1.i - 1 && x1.f == 0) {
|
||||
x1.i--;
|
||||
x1.f = 0xFF;
|
||||
}
|
||||
|
||||
/*If the two x intersections are on the same x then just get average of the fractionals*/
|
||||
if(x0.i == x1.i) {
|
||||
@ -471,7 +561,7 @@ lv_mask_res_t lv_mask_radius(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t a
|
||||
}
|
||||
}
|
||||
}
|
||||
/*Multiple pixels are affected. Get y intersection of the pixels*/
|
||||
/*Multiple pixels are affected. Get y intersection of the pixels*/
|
||||
else {
|
||||
int32_t ofs = p->radius - (x0.i + 1);
|
||||
int32_t kl = k + ofs;
|
||||
|
@ -27,9 +27,10 @@ extern "C" {
|
||||
**********************/
|
||||
|
||||
enum {
|
||||
LV_MASK_RES_FULL_COVER,
|
||||
LV_MASK_RES_FULL_TRANSP,
|
||||
LV_MASK_RES_FULL_COVER,
|
||||
LV_MASK_RES_CHANGED,
|
||||
LV_MASK_RES_UNKNOWN
|
||||
};
|
||||
|
||||
typedef uint8_t lv_mask_res_t;
|
||||
|
@ -181,11 +181,11 @@ void lv_preload_set_type(lv_obj_t * preload, lv_preload_type_t type)
|
||||
a.var = preload;
|
||||
if(ext->anim_dir == LV_PRELOAD_DIR_FORWARD) {
|
||||
/* Clockwise */
|
||||
a.start = 360;
|
||||
a.end = 0;
|
||||
} else {
|
||||
a.start = 0;
|
||||
a.end = 360;
|
||||
} else {
|
||||
a.start = 360;
|
||||
a.end = 0;
|
||||
}
|
||||
a.exec_cb = (lv_anim_exec_xcb_t)lv_preload_spinner_anim;
|
||||
a.path_cb = lv_anim_path_ease_in_out;
|
||||
@ -202,11 +202,11 @@ void lv_preload_set_type(lv_obj_t * preload, lv_preload_type_t type)
|
||||
b.var = preload;
|
||||
if(ext->anim_dir == LV_PRELOAD_DIR_FORWARD) {
|
||||
/* Clockwise */
|
||||
b.start = 360 - ext->arc_length;
|
||||
b.end = ext->arc_length;
|
||||
} else {
|
||||
b.start = ext->arc_length;
|
||||
b.end = 360 - ext->arc_length;
|
||||
} else {
|
||||
b.start = 360 - ext->arc_length;
|
||||
b.end = ext->arc_length;
|
||||
}
|
||||
b.exec_cb = (lv_anim_exec_xcb_t)lv_preload_set_arc_length;
|
||||
b.path_cb = lv_anim_path_ease_in_out;
|
||||
@ -227,11 +227,11 @@ void lv_preload_set_type(lv_obj_t * preload, lv_preload_type_t type)
|
||||
a.var = preload;
|
||||
if(ext->anim_dir == LV_PRELOAD_DIR_FORWARD) {
|
||||
/* Clockwise */
|
||||
a.start = 360;
|
||||
a.end = 0;
|
||||
} else {
|
||||
a.start = 0;
|
||||
a.end = 360;
|
||||
} else {
|
||||
a.start = 360;
|
||||
a.end = 0;
|
||||
}
|
||||
a.exec_cb = (lv_anim_exec_xcb_t)lv_preload_spinner_anim;
|
||||
a.path_cb = lv_anim_path_ease_in_out;
|
||||
|
Loading…
x
Reference in New Issue
Block a user