1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00

cpicker: cleanup

This commit is contained in:
Gabor Kiss-Vamosi 2019-10-02 08:28:24 +02:00
parent c03744a048
commit d6ae10473b

View File

@ -502,8 +502,6 @@ static bool lv_cpicker_design(lv_obj_t * cpicker, const lv_area_t * mask, lv_des
static void draw_disc_grad(lv_obj_t * cpicker, const lv_area_t * mask, lv_opa_t opa_scale)
{
int16_t start_angle = 0; /*Default*/
int16_t end_angle = 360 - LV_CPICKER_DEF_QF; /*Default*/
lv_coord_t w = lv_obj_get_width(cpicker);
lv_coord_t h = lv_obj_get_height(cpicker);
@ -511,120 +509,47 @@ static void draw_disc_grad(lv_obj_t * cpicker, const lv_area_t * mask, lv_opa_t
lv_coord_t cy = cpicker->coords.y1 + h / 2;
lv_coord_t r = w / 2;
/*if the mask does not include the center of the object
* redrawing all the wheel is not necessary;
* only a given angular range
*/
lv_point_t center = {cx, cy};
if(!lv_area_is_point_on(mask, &center))
{
/*get angle from center of object to each corners of the area*/
int16_t dr, ur, ul, dl;
dr = lv_atan2(mask->x2 - cx, mask->y2 - cy);
ur = lv_atan2(mask->x2 - cx, mask->y1 - cy);
ul = lv_atan2(mask->x1 - cx, mask->y1 - cy);
dl = lv_atan2(mask->x1 - cx, mask->y2 - cy);
/*check area position from object axis*/
bool left = (mask->x2 < cx && mask->x1 < cx) ? true : false;
bool onYaxis = (mask->x2 > cx && mask->x1 < cx) ? true : false;
bool right = (mask->x2 > cx && mask->x1 > cx) ? true : false;
bool top = (mask->y2 < cy && mask->y1 < cy) ? true : false;
bool onXaxis = (mask->y2 > cy && mask->y1 < cy) ? true : false;
bool bottom = (mask->y2 > cy && mask->y1 > cy) ? true : false;
/*store angular range*/
if(right && bottom) {
start_angle = dl;
end_angle = ur;
}
else if(right && onXaxis) {
start_angle = dl;
end_angle = ul;
}
else if(right && top) {
start_angle = dr;
end_angle = ul;
}
else if(onYaxis && top) {
start_angle = dr;
end_angle = dl;
}
else if(left && top) {
start_angle = ur;
end_angle = dl;
}
else if(left && onXaxis) {
start_angle = ur;
end_angle = dr;
}
else if(left && bottom) {
start_angle = ul;
end_angle = dr;
}
else if(onYaxis && bottom) {
start_angle = ul;
end_angle = ur;
}
/*rollover angle*/
if(start_angle > end_angle) end_angle += 360;
/*round to QF factor*/
start_angle = (start_angle/LV_CPICKER_DEF_QF) * LV_CPICKER_DEF_QF;
end_angle = (end_angle / LV_CPICKER_DEF_QF) * LV_CPICKER_DEF_QF;
/*shift angle if necessary before adding offset*/
if((start_angle - LV_CPICKER_DEF_QF) < 0)
{
start_angle += 360;
end_angle += 360;
}
/*ensure overlapping by adding offset*/
start_angle -= LV_CPICKER_DEF_QF;
end_angle += LV_CPICKER_DEF_QF;
}
lv_point_t triangle_points[3];
lv_style_t style;
lv_style_copy(&style, &lv_style_plain);
for(uint16_t i = start_angle; i <= end_angle; i+= LV_CPICKER_DEF_QF)
{
style.body.main_color = angle_to_mode_color(cpicker, i);
style.body.grad_color = style.body.main_color;
triangle_points[0].x = cx;
triangle_points[0].y = cy;
triangle_points[1].x = cx + (r * lv_trigo_sin(i) >> LV_TRIGO_SHIFT);
triangle_points[1].y = cy + (r * lv_trigo_sin(i + 90) >> LV_TRIGO_SHIFT);
if(i == end_angle || i == (360 - LV_CPICKER_DEF_QF)) {
/*the last triangle is drawn without additional overlapping pixels*/
triangle_points[2].x = cx + (r * lv_trigo_sin(i + LV_CPICKER_DEF_QF) >> LV_TRIGO_SHIFT);
triangle_points[2].y = cy + (r * lv_trigo_sin(i + LV_CPICKER_DEF_QF + 90) >> LV_TRIGO_SHIFT);
}
else {
triangle_points[2].x = cx + (r * lv_trigo_sin(i + LV_CPICKER_DEF_QF + TRI_OFFSET) >> LV_TRIGO_SHIFT);
triangle_points[2].y = cy + (r * lv_trigo_sin(i + LV_CPICKER_DEF_QF + TRI_OFFSET + 90) >> LV_TRIGO_SHIFT);
}
lv_draw_triangle(triangle_points, mask, &style, LV_OPA_COVER);
}
/*Mask out the center area*/
const lv_style_t * style_main = lv_cpicker_get_style(cpicker, LV_CPICKER_STYLE_MAIN);
lv_style_t style;
lv_style_copy(&style, style_main);
style.body.radius = LV_RADIUS_CIRCLE;
lv_area_t area_mid;
lv_area_copy(&area_mid, &cpicker->coords);
area_mid.x1 += style_main->line.width;
area_mid.y1 += style_main->line.width;
area_mid.x2 -= style_main->line.width;
area_mid.y2 -= style_main->line.width;
style.line.width = (r * 628 / (360 / LV_CPICKER_DEF_QF)) / 100;
style.line.width += 3;
lv_draw_rect(&area_mid, mask, &style, opa_scale);
lv_coord_t cir_w = style_main->line.width;
for(uint16_t i = 0; i <= 360; i+= LV_CPICKER_DEF_QF) {
style.line.color = angle_to_mode_color(cpicker, i);
lv_point_t p[2];
p[0].x = cx + (r * lv_trigo_sin(i) >> LV_TRIGO_SHIFT);
p[0].y = cy + (r * lv_trigo_sin(i+ 90) >> LV_TRIGO_SHIFT);
p[1].x = cx + ((r-cir_w) * lv_trigo_sin(i) >> LV_TRIGO_SHIFT);
p[1].y = cy + ((r-cir_w) * lv_trigo_sin(i+ 90) >> LV_TRIGO_SHIFT);
lv_area_t mask_sub;
mask_sub.x1 = LV_MATH_MIN(p[0].x, p[1].x) - style.line.width/2;
mask_sub.x2 = LV_MATH_MAX(p[0].x, p[1].x) + style.line.width/2;
mask_sub.y1 = LV_MATH_MIN(p[0].y, p[1].y) - style.line.width/2;
mask_sub.y2 = LV_MATH_MAX(p[0].y, p[1].y) + style.line.width/2;
if(lv_area_intersect(&mask_sub, mask, &mask_sub)) {
lv_draw_line(&p[0], &p[1], &mask_sub, &style, opa_scale);
}
}
// /*Mask out the center area*/
// const lv_style_t * style_main = lv_cpicker_get_style(cpicker, LV_CPICKER_STYLE_MAIN);
// lv_style_copy(&style, style_main);
// style.body.radius = LV_RADIUS_CIRCLE;
// lv_area_t area_mid;
// lv_area_copy(&area_mid, &cpicker->coords);
// area_mid.x1 += style_main->line.width;
// area_mid.y1 += style_main->line.width;
// area_mid.x2 -= style_main->line.width;
// area_mid.y2 -= style_main->line.width;
//
// lv_draw_rect(&area_mid, mask, &style, opa_scale);
}
static void draw_rect_grad(lv_obj_t * cpicker, const lv_area_t * mask, lv_opa_t opa_scale)
@ -854,9 +779,9 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p
r_in -= style_main->line.width;
if(r_in > LV_DPI / 2) {
r_in -= style_main->line.width; /* to let some sensitive space inside*/
r_in -= style_main->line.width; /* to let some sensitive space inside*/
if(r_in < LV_DPI / 2) r_in = LV_DPI / 2;
if(r_in < LV_DPI / 2) r_in = LV_DPI / 2;
}
/*If the inner area is being pressed, go to the next color mode on long press*/