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

608 lines
20 KiB
C
Raw Normal View History

2018-06-08 10:26:10 +02:00
/**
* @file lv_arc.c
2018-06-19 09:49:58 +02:00
*
2018-06-08 10:26:10 +02:00
*/
/*********************
* INCLUDES
*********************/
#include "lv_arc.h"
#if LV_USE_ARC != 0
2018-06-08 10:26:10 +02:00
2019-09-24 16:30:38 +02:00
#include "../lv_core/lv_debug.h"
2018-06-08 10:26:10 +02:00
#include "../lv_misc/lv_math.h"
#include "../lv_draw/lv_draw_arc.h"
2018-09-20 22:14:48 +02:00
#include "../lv_themes/lv_theme.h"
2018-06-08 10:26:10 +02:00
/*********************
* DEFINES
*********************/
#define LV_OBJX_NAME "lv_arc"
2018-06-08 10:26:10 +02:00
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
2019-09-06 19:53:39 +02:00
static lv_design_res_t lv_arc_design(lv_obj_t * arc, const lv_area_t * clip_area, lv_design_mode_t mode);
2018-06-08 10:26:10 +02:00
static lv_res_t lv_arc_signal(lv_obj_t * arc, lv_signal_t sign, void * param);
static lv_style_list_t * lv_arc_get_style(lv_obj_t * arc, uint8_t part);
2020-02-05 12:52:18 +01:00
static void inv_arc_area(lv_obj_t * arc, uint16_t start_angle, uint16_t end_angle);
2018-06-08 10:26:10 +02:00
/**********************
* STATIC VARIABLES
**********************/
static lv_signal_cb_t ancestor_signal;
static lv_design_cb_t ancestor_design;
2018-06-08 10:26:10 +02:00
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Create a arc object
* @param par pointer to an object, it will be the parent of the new arc
* @param copy pointer to a arc object, if not NULL then the new object will be copied from it
* @return pointer to the created arc
*/
lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy)
2018-06-08 10:26:10 +02:00
{
2018-07-25 17:57:08 +02:00
2018-10-05 17:22:49 +02:00
LV_LOG_TRACE("arc create started");
2018-07-25 17:57:08 +02:00
2018-06-08 10:26:10 +02:00
/*Create the ancestor of arc*/
lv_obj_t * arc = lv_obj_create(par, copy);
LV_ASSERT_MEM(arc);
if(arc == NULL) return NULL;
2018-06-19 09:49:58 +02:00
2018-06-08 10:26:10 +02:00
/*Allocate the arc type specific extended data*/
lv_arc_ext_t * ext = lv_obj_allocate_ext_attr(arc, sizeof(lv_arc_ext_t));
2019-09-24 23:14:17 +02:00
LV_ASSERT_MEM(ext);
if(ext == NULL) {
lv_obj_del(arc);
return NULL;
}
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(arc);
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(arc);
2018-06-08 10:26:10 +02:00
/*Initialize the allocated 'ext' */
2020-03-30 09:13:07 -07:00
ext->rotation_angle = 0;
ext->bg_angle_start = 135;
ext->bg_angle_end = 45;
ext->arc_angle_start = 135;
ext->arc_angle_end = 270;
lv_style_list_init(&ext->style_arc);
2018-06-08 10:26:10 +02:00
lv_obj_set_size(arc, LV_DPI, LV_DPI);
2020-01-10 11:10:07 +01:00
2018-06-08 10:26:10 +02:00
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_cb(arc, lv_arc_signal);
lv_obj_set_design_cb(arc, lv_arc_design);
2018-06-08 10:26:10 +02:00
/*Init the new arc arc*/
if(copy == NULL) {
lv_theme_apply(arc, LV_THEME_ARC);
2018-06-08 10:26:10 +02:00
}
/*Copy an existing arc*/
else {
2018-06-19 09:49:58 +02:00
lv_arc_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
2020-02-12 08:54:03 +01:00
ext->arc_angle_start = copy_ext->arc_angle_start;
ext->arc_angle_end = copy_ext->arc_angle_end;
ext->bg_angle_start = copy_ext->bg_angle_start;
ext->bg_angle_end = copy_ext->bg_angle_end;
lv_style_list_copy(&ext->style_arc, &copy_ext->style_arc);
2018-06-08 10:26:10 +02:00
2018-06-19 09:49:58 +02:00
/*Refresh the style with new signal function*/
2020-03-10 10:41:39 +01:00
lv_obj_refresh_style(arc, LV_STYLE_PROP_ALL);
2018-06-08 10:26:10 +02:00
}
2018-06-19 09:49:58 +02:00
2018-10-05 17:22:49 +02:00
LV_LOG_INFO("arc created");
2018-07-25 17:57:08 +02:00
return arc;
2018-06-08 10:26:10 +02:00
}
/*======================
* Add/remove functions
*=====================*/
/*
* New object specific "add" or "remove" functions come here
*/
/*=====================
* Setter functions
*====================*/
/**
2020-02-12 08:54:03 +01:00
* Set the start angle of an arc. 0 deg: right, 90 bottom, etc.
2018-06-08 10:26:10 +02:00
* @param arc pointer to an arc object
* @param start the start angle [0..360]
*/
2020-03-27 10:20:51 -07:00
void lv_arc_set_start_angle(lv_obj_t * arc, uint16_t start)
2018-06-08 10:26:10 +02:00
{
LV_ASSERT_OBJ(arc, LV_OBJX_NAME);
2018-06-19 09:49:58 +02:00
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
2018-06-08 10:26:10 +02:00
if(start > 360) start -= 360;
2018-06-08 10:26:10 +02:00
2020-02-05 14:49:02 +01:00
/*Too large move, the whole arc need to be invalidated anyway*/
2020-02-05 15:12:45 +01:00
if(LV_MATH_ABS(start - ext->arc_angle_start) >= 180) {
2020-02-05 14:49:02 +01:00
lv_obj_invalidate(arc);
}
/*Only a smaller incremental move*/
2020-02-05 15:12:45 +01:00
else if(ext->arc_angle_start > ext->arc_angle_end && start > ext->arc_angle_end) {
inv_arc_area(arc, LV_MATH_MIN(ext->arc_angle_start, start), LV_MATH_MAX(ext->arc_angle_start, start));
2020-02-05 14:49:02 +01:00
}
/*Only a smaller incremental move*/
2020-02-05 15:12:45 +01:00
else if(ext->arc_angle_start < ext->arc_angle_end && start < ext->arc_angle_end) {
inv_arc_area(arc, LV_MATH_MIN(ext->arc_angle_start, start), LV_MATH_MAX(ext->arc_angle_start, start));
2020-02-05 14:49:02 +01:00
}
/*Crossing the start angle makes the whole arc change*/
else {
lv_obj_invalidate(arc);
}
2020-02-05 15:12:45 +01:00
ext->arc_angle_start = start;
}
/**
2020-02-12 08:54:03 +01:00
* Set the start angle of an arc. 0 deg: right, 90 bottom, etc.
* @param arc pointer to an arc object
* @param start the start angle [0..360]
*/
2020-03-27 10:20:51 -07:00
void lv_arc_set_end_angle(lv_obj_t * arc, uint16_t end)
{
LV_ASSERT_OBJ(arc, LV_OBJX_NAME);
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
2020-02-05 14:49:02 +01:00
/*Too large move, the whole arc need to be invalidated anyway*/
2020-02-05 15:12:45 +01:00
if(LV_MATH_ABS(end - ext->arc_angle_end) >= 180) {
2020-02-05 14:49:02 +01:00
lv_obj_invalidate(arc);
}
/*Only a smaller incremental move*/
2020-02-26 19:48:27 +01:00
else if(ext->arc_angle_end > ext->arc_angle_start && end > ext->arc_angle_start) {
2020-02-05 15:12:45 +01:00
inv_arc_area(arc, LV_MATH_MIN(ext->arc_angle_end, end), LV_MATH_MAX(ext->arc_angle_end, end));
2020-02-05 14:49:02 +01:00
}
/*Only a smaller incremental move*/
2020-02-26 19:48:27 +01:00
else if(ext->arc_angle_end < ext->arc_angle_start && end < ext->arc_angle_start) {
2020-02-05 15:12:45 +01:00
inv_arc_area(arc, LV_MATH_MIN(ext->arc_angle_end, end), LV_MATH_MAX(ext->arc_angle_end, end));
2020-02-05 14:49:02 +01:00
}
/*Crossing the end angle makes the whole arc change*/
else {
lv_obj_invalidate(arc);
}
2020-02-26 19:48:27 +01:00
ext->arc_angle_end = end;
2018-06-08 10:26:10 +02:00
}
2020-02-05 10:40:50 +01:00
/**
* Set the start and end angles
* @param arc pointer to an arc object
* @param start the start angle
* @param end the end angle
*/
2020-03-27 10:20:51 -07:00
void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end)
2020-02-05 10:40:50 +01:00
{
LV_ASSERT_OBJ(arc, LV_OBJX_NAME);
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
if(start > 360) start -= 360;
2020-02-05 15:12:45 +01:00
inv_arc_area(arc, ext->arc_angle_start, ext->arc_angle_end);
2020-02-05 10:40:50 +01:00
ext->arc_angle_start = start;
ext->arc_angle_end = end;
2020-02-05 15:12:45 +01:00
inv_arc_area(arc, ext->arc_angle_start, ext->arc_angle_end);
2018-06-08 10:26:10 +02:00
}
2020-02-12 08:54:03 +01:00
/**
* Set the start angle of an arc background. 0 deg: right, 90 bottom, etc.
* @param arc pointer to an arc object
* @param start the start angle
*/
2020-03-27 10:20:51 -07:00
void lv_arc_set_bg_start_angle(lv_obj_t * arc, uint16_t start)
2020-02-12 08:54:03 +01:00
{
LV_ASSERT_OBJ(arc, LV_OBJX_NAME);
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
if(start > 360) start -= 360;
2020-02-12 08:54:03 +01:00
/*Too large move, the whole arc need to be invalidated anyway*/
if(LV_MATH_ABS(start - ext->bg_angle_start) >= 180) {
lv_obj_invalidate(arc);
}
/*Only a smaller incremental move*/
else if(ext->bg_angle_start > ext->bg_angle_end && start > ext->bg_angle_end) {
inv_arc_area(arc, LV_MATH_MIN(ext->bg_angle_start, start), LV_MATH_MAX(ext->bg_angle_start, start));
}
/*Only a smaller incremental move*/
2020-03-27 10:20:51 -07:00
else if(ext->bg_angle_start < ext->bg_angle_end && start < ext->bg_angle_end) {
inv_arc_area(arc, LV_MATH_MIN(ext->bg_angle_start, start), LV_MATH_MAX(ext->bg_angle_start, start));
2020-02-12 08:54:03 +01:00
}
/*Crossing the start angle makes the whole arc change*/
else {
lv_obj_invalidate(arc);
}
ext->bg_angle_start = start;
}
/**
* Set the start angle of an arc background. 0 deg: right, 90 bottom etc.
* @param arc pointer to an arc object
* @param end the end angle
*/
2020-03-27 10:20:51 -07:00
void lv_arc_set_bg_end_angle(lv_obj_t * arc, uint16_t end)
2020-02-12 08:54:03 +01:00
{
LV_ASSERT_OBJ(arc, LV_OBJX_NAME);
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
/*Too large move, the whole arc need to be invalidated anyway*/
if(LV_MATH_ABS(end - ext->bg_angle_end) >= 180) {
lv_obj_invalidate(arc);
}
/*Only a smaller incremental move*/
2020-02-26 19:48:27 +01:00
else if(ext->bg_angle_end > ext->bg_angle_start && end > ext->bg_angle_start) {
2020-02-12 08:54:03 +01:00
inv_arc_area(arc, LV_MATH_MIN(ext->bg_angle_end, end), LV_MATH_MAX(ext->bg_angle_end, end));
}
/*Only a smaller incremental move*/
2020-02-26 19:48:27 +01:00
else if(ext->bg_angle_end < ext->bg_angle_start && end < ext->bg_angle_start) {
2020-02-12 08:54:03 +01:00
inv_arc_area(arc, LV_MATH_MIN(ext->bg_angle_end, end), LV_MATH_MAX(ext->bg_angle_end, end));
}
/*Crossing the end angle makes the whole arc change*/
else {
lv_obj_invalidate(arc);
}
2020-02-26 19:48:27 +01:00
ext->bg_angle_end = end;
2020-02-12 08:54:03 +01:00
}
/**
* Set the start and end angles of the arc background
* @param arc pointer to an arc object
* @param start the start angle
* @param end the end angle
*/
2020-03-27 10:20:51 -07:00
void lv_arc_set_bg_angles(lv_obj_t * arc, uint16_t start, uint16_t end)
2020-02-12 08:54:03 +01:00
{
LV_ASSERT_OBJ(arc, LV_OBJX_NAME);
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
if(start > 360) start -= 360;
2020-02-12 08:54:03 +01:00
inv_arc_area(arc, ext->bg_angle_start, ext->bg_angle_end);
ext->bg_angle_start = start;
ext->bg_angle_end = end;
2020-02-12 08:54:03 +01:00
inv_arc_area(arc, ext->bg_angle_start, ext->bg_angle_end);
}
/**
* Set the rotation for the whole arc
* @param arc pointer to an arc object
* @param rotation_angle rotation angle
*/
void lv_arc_set_rotation(lv_obj_t * arc, uint16_t rotation_angle)
{
LV_ASSERT_OBJ(arc, LV_OBJX_NAME);
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
ext->rotation_angle = rotation_angle;
lv_obj_invalidate(arc);
}
2020-02-12 08:54:03 +01:00
2018-06-08 10:26:10 +02:00
/*=====================
* Getter functions
*====================*/
/**
* Get the start angle of an arc.
2018-06-08 10:26:10 +02:00
* @param arc pointer to an arc object
* @return the start angle [0..360]
*/
2018-06-09 08:45:38 +02:00
uint16_t lv_arc_get_angle_start(lv_obj_t * arc)
2018-06-08 10:26:10 +02:00
{
LV_ASSERT_OBJ(arc, LV_OBJX_NAME);
2018-06-19 09:49:58 +02:00
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
2018-06-08 10:26:10 +02:00
return ext->arc_angle_start;
2018-06-08 10:26:10 +02:00
}
/**
* Get the end angle of an arc.
2018-06-08 10:26:10 +02:00
* @param arc pointer to an arc object
* @return the end angle [0..360]
*/
2018-06-09 08:45:38 +02:00
uint16_t lv_arc_get_angle_end(lv_obj_t * arc)
2018-06-08 10:26:10 +02:00
{
LV_ASSERT_OBJ(arc, LV_OBJX_NAME);
2018-06-19 09:49:58 +02:00
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
2018-06-08 10:26:10 +02:00
return ext->arc_angle_end;
2018-06-08 10:26:10 +02:00
}
2020-03-24 13:42:27 -07:00
/**
* Get the start angle of an arc background.
* @param arc pointer to an arc object
* @return the start angle [0..360]
*/
uint16_t lv_arc_get_bg_angle_start(lv_obj_t * arc)
{
LV_ASSERT_OBJ(arc, LV_OBJX_NAME);
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
return ext->bg_angle_start;
}
/**
* Get the end angle of an arc background.
* @param arc pointer to an arc object
* @return the end angle [0..360]
*/
uint16_t lv_arc_get_bg_angle_end(lv_obj_t * arc)
{
LV_ASSERT_OBJ(arc, LV_OBJX_NAME);
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
return ext->bg_angle_end;
}
2018-06-08 10:26:10 +02:00
/*=====================
* Other functions
*====================*/
/*
* New object specific "other" functions come here
*/
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Handle the drawing related tasks of the arcs
* @param arc pointer to an object
2019-09-06 19:53:39 +02:00
* @param clip_area the object will be drawn only in this area
2018-06-08 10:26:10 +02:00
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
* (return 'true' if yes)
* LV_DESIGN_DRAW: draw the object (always return 'true')
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
2019-09-06 19:53:39 +02:00
* @param return an element of `lv_design_res_t`
2018-06-08 10:26:10 +02:00
*/
2019-09-06 19:53:39 +02:00
static lv_design_res_t lv_arc_design(lv_obj_t * arc, const lv_area_t * clip_area, lv_design_mode_t mode)
2018-06-08 10:26:10 +02:00
{
/*Return false if the object is not covers the mask_p area*/
if(mode == LV_DESIGN_COVER_CHK) {
2019-09-06 19:53:39 +02:00
return LV_DESIGN_RES_NOT_COVER;
2018-06-08 10:26:10 +02:00
}
/*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) {
2019-04-11 19:59:55 +08:00
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
2020-01-10 11:10:07 +01:00
2020-02-12 08:54:03 +01:00
lv_draw_rect_dsc_t bg_dsc;
lv_draw_rect_dsc_init(&bg_dsc);
lv_obj_init_draw_rect_dsc(arc, LV_ARC_PART_BG, &bg_dsc);
lv_draw_rect(&arc->coords, clip_area, &bg_dsc);
2020-03-04 16:29:21 +01:00
lv_coord_t left_bg = lv_obj_get_style_pad_left(arc, LV_ARC_PART_BG);
lv_coord_t right_bg = lv_obj_get_style_pad_right(arc, LV_ARC_PART_BG);
lv_coord_t top_bg = lv_obj_get_style_pad_top(arc, LV_ARC_PART_BG);
lv_coord_t bottom_bg = lv_obj_get_style_pad_bottom(arc, LV_ARC_PART_BG);
2020-03-24 10:13:52 +01:00
lv_coord_t r = (LV_MATH_MIN(lv_obj_get_width(arc) - left_bg - right_bg,
lv_obj_get_height(arc) - top_bg - bottom_bg)) / 2;
2020-03-04 16:29:21 +01:00
lv_coord_t x = arc->coords.x1 + r + left_bg;
lv_coord_t y = arc->coords.y1 + r + top_bg;
2020-01-10 11:10:07 +01:00
lv_draw_line_dsc_t arc_dsc;
lv_draw_line_dsc_init(&arc_dsc);
lv_obj_init_draw_line_dsc(arc, LV_ARC_PART_BG, &arc_dsc);
lv_draw_arc(x, y, r, ext->bg_angle_start + ext->rotation_angle, ext->bg_angle_end + ext->rotation_angle, clip_area, &arc_dsc);
lv_draw_line_dsc_init(&arc_dsc);
2020-03-04 16:29:21 +01:00
lv_obj_init_draw_line_dsc(arc, LV_ARC_PART_INDIC, &arc_dsc);
/*make the indicator arc smaller or larger according to its greatest padding value*/
lv_coord_t left_indic = lv_obj_get_style_pad_left(arc, LV_ARC_PART_INDIC);
lv_coord_t right_indic = lv_obj_get_style_pad_right(arc, LV_ARC_PART_INDIC);
lv_coord_t top_indic = lv_obj_get_style_pad_top(arc, LV_ARC_PART_INDIC);
lv_coord_t bottom_indic = lv_obj_get_style_pad_bottom(arc, LV_ARC_PART_INDIC);
2020-03-24 10:13:52 +01:00
r -= LV_MATH_MAX4(left_indic, right_indic, top_indic, bottom_indic);
2018-06-19 09:49:58 +02:00
lv_draw_arc(x, y, r, ext->arc_angle_start + ext->rotation_angle, ext->arc_angle_end + ext->rotation_angle, clip_area, &arc_dsc);
2018-06-08 10:26:10 +02:00
}
/*Post draw when the children are drawn*/
else if(mode == LV_DESIGN_DRAW_POST) {
}
2019-09-06 19:53:39 +02:00
return LV_DESIGN_RES_OK;
2018-06-08 10:26:10 +02:00
}
/**
* Signal function of the arc
* @param arc pointer to a arc object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t lv_arc_signal(lv_obj_t * arc, lv_signal_t sign, void * param)
{
lv_res_t res;
2020-01-10 11:10:07 +01:00
if(sign == LV_SIGNAL_GET_STYLE) {
lv_get_style_info_t * info = param;
info->result = lv_arc_get_style(arc, info->part);
if(info->result != NULL) return LV_RES_OK;
else return ancestor_signal(arc, sign, param);
}
2018-06-08 10:26:10 +02:00
/* Include the ancient signal function */
res = ancestor_signal(arc, sign, param);
if(res != LV_RES_OK) return res;
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
2018-06-08 10:26:10 +02:00
if(sign == LV_SIGNAL_CLEANUP) {
2020-03-04 16:29:21 +01:00
lv_obj_clean_style_list(arc, LV_ARC_PART_INDIC);
2018-06-08 10:26:10 +02:00
}
return res;
}
2020-01-10 11:10:07 +01:00
/**
* Get the style descriptor of a part of the object
* @param arc pointer the object
* @param part the part of the object. (LV_ARC_PART_...)
* @return pointer to the style descriptor of the specified part
*/
static lv_style_list_t * lv_arc_get_style(lv_obj_t * arc, uint8_t part)
2020-01-10 11:10:07 +01:00
{
LV_ASSERT_OBJ(arc, LV_OBJX_NAME);
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
lv_style_list_t * style_dsc_p;
2020-01-10 11:10:07 +01:00
switch(part) {
2020-02-26 19:48:27 +01:00
case LV_ARC_PART_BG:
style_dsc_p = &arc->style_list;
break;
2020-03-04 16:29:21 +01:00
case LV_ARC_PART_INDIC:
2020-02-26 19:48:27 +01:00
style_dsc_p = &ext->style_arc;
break;
default:
style_dsc_p = NULL;
2020-01-10 11:10:07 +01:00
}
return style_dsc_p;
}
2020-02-05 10:40:50 +01:00
static void inv_arc_area(lv_obj_t * arc, uint16_t start_angle, uint16_t end_angle)
{
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
start_angle += ext->rotation_angle;
end_angle += ext->rotation_angle;
2020-02-12 08:54:03 +01:00
if(start_angle >= 360) start_angle -= 360;
if(end_angle >= 360) end_angle -= 360;
2020-02-05 10:40:50 +01:00
uint8_t start_quarter = start_angle / 90;
uint8_t end_quarter = end_angle / 90;
2020-02-12 08:54:03 +01:00
lv_coord_t left = lv_obj_get_style_pad_left(arc, LV_ARC_PART_BG);
lv_coord_t right = lv_obj_get_style_pad_right(arc, LV_ARC_PART_BG);
lv_coord_t top = lv_obj_get_style_pad_top(arc, LV_ARC_PART_BG);
lv_coord_t bottom = lv_obj_get_style_pad_bottom(arc, LV_ARC_PART_BG);
lv_coord_t rout = (LV_MATH_MIN(lv_obj_get_width(arc) - left - right, lv_obj_get_height(arc) - top - bottom)) / 2;
lv_coord_t x = arc->coords.x1 + rout + left;
lv_coord_t y = arc->coords.y1 + rout + top;
2020-03-04 16:29:21 +01:00
lv_style_int_t w = lv_obj_get_style_line_width(arc, LV_ARC_PART_INDIC);
lv_style_int_t rounded = lv_obj_get_style_line_rounded(arc, LV_ARC_PART_INDIC);
2020-02-05 15:12:45 +01:00
lv_coord_t rin = rout - w;
2020-02-05 15:41:25 +01:00
lv_coord_t extra_area = rounded ? w / 2 + 2 : 0;
2020-02-05 12:52:18 +01:00
2020-02-05 10:40:50 +01:00
lv_area_t inv_area;
2020-02-05 14:49:02 +01:00
if(start_quarter == end_quarter && start_angle <= end_angle) {
2020-02-05 12:52:18 +01:00
if(start_quarter == 0) {
2020-02-05 15:32:14 +01:00
inv_area.y1 = y + ((lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) - extra_area;
inv_area.x2 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
2020-02-05 12:52:18 +01:00
2020-02-05 15:32:14 +01:00
inv_area.y2 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area;
inv_area.x1 = x + ((lv_trigo_sin(end_angle + 90) * rin) >> LV_TRIGO_SHIFT) - extra_area;
2020-02-05 12:52:18 +01:00
lv_obj_invalidate_area(arc, &inv_area);
}
else if(start_quarter == 1) {
2020-02-05 15:32:14 +01:00
inv_area.y2 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area;
inv_area.x2 = x + ((lv_trigo_sin(start_angle + 90) * rin) >> LV_TRIGO_SHIFT) + extra_area;
2020-02-05 12:52:18 +01:00
2020-02-05 15:32:14 +01:00
inv_area.y1 = y + ((lv_trigo_sin(end_angle) * rin) >> LV_TRIGO_SHIFT) - extra_area;
inv_area.x1 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
2020-02-05 12:52:18 +01:00
lv_obj_invalidate_area(arc, &inv_area);
}
else if(start_quarter == 2) {
2020-02-05 15:32:14 +01:00
inv_area.x1 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
inv_area.y2 = y + ((lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area;
2020-02-05 12:52:18 +01:00
2020-02-05 15:32:14 +01:00
inv_area.y1 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area;
inv_area.x2 = x + ((lv_trigo_sin(end_angle + 90) * rin) >> LV_TRIGO_SHIFT) + extra_area;
2020-02-05 12:52:18 +01:00
lv_obj_invalidate_area(arc, &inv_area);
}
else if(start_quarter == 3) {
2020-02-05 10:40:50 +01:00
/*Small arc here*/
2020-02-05 15:32:14 +01:00
inv_area.x1 = x + ((lv_trigo_sin(start_angle + 90) * rin) >> LV_TRIGO_SHIFT) - extra_area;
inv_area.y1 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area;
2020-02-05 10:40:50 +01:00
2020-02-05 15:32:14 +01:00
inv_area.x2 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
inv_area.y2 = y + ((lv_trigo_sin(end_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area;
2020-02-05 10:40:50 +01:00
2020-02-05 12:52:18 +01:00
lv_obj_invalidate_area(arc, &inv_area);
2020-02-05 10:40:50 +01:00
}
2020-02-26 19:48:27 +01:00
}
else if(start_quarter == 0 && end_quarter == 1) {
2020-02-05 15:32:14 +01:00
inv_area.x1 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
2020-02-26 19:48:27 +01:00
inv_area.y1 = y + ((LV_MATH_MIN(lv_trigo_sin(end_angle),
lv_trigo_sin(start_angle)) * rin) >> LV_TRIGO_SHIFT) - extra_area;
2020-02-05 15:32:14 +01:00
inv_area.x2 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
inv_area.y2 = y + rout + extra_area;
2020-02-05 12:52:18 +01:00
lv_obj_invalidate_area(arc, &inv_area);
2020-02-26 19:48:27 +01:00
}
else if(start_quarter == 1 && end_quarter == 2) {
2020-02-05 15:32:14 +01:00
inv_area.x1 = x - rout - extra_area;
inv_area.y1 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area;
2020-02-26 19:48:27 +01:00
inv_area.x2 = x + ((LV_MATH_MAX(lv_trigo_sin(start_angle + 90),
lv_trigo_sin(end_angle + 90)) * rin) >> LV_TRIGO_SHIFT) + extra_area;
2020-02-05 15:32:14 +01:00
inv_area.y2 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area;
2020-02-05 12:52:18 +01:00
lv_obj_invalidate_area(arc, &inv_area);
2020-02-26 19:48:27 +01:00
}
else if(start_quarter == 2 && end_quarter == 3) {
2020-02-05 15:32:14 +01:00
inv_area.x1 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
inv_area.y1 = y - rout - extra_area;
inv_area.x2 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
2020-02-26 19:48:27 +01:00
inv_area.y2 = y + (LV_MATH_MAX(lv_trigo_sin(end_angle) * rin,
lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area;
2020-02-05 12:52:18 +01:00
lv_obj_invalidate_area(arc, &inv_area);
2020-02-26 19:48:27 +01:00
}
else if(start_quarter == 3 && end_quarter == 0) {
inv_area.x1 = x + ((LV_MATH_MIN(lv_trigo_sin(end_angle + 90),
lv_trigo_sin(start_angle + 90)) * rin) >> LV_TRIGO_SHIFT) - extra_area;
2020-02-05 15:32:14 +01:00
inv_area.y1 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area;
inv_area.x2 = x + rout + extra_area;
inv_area.y2 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area;
2020-02-05 12:52:18 +01:00
lv_obj_invalidate_area(arc, &inv_area);
2020-02-26 19:48:27 +01:00
}
else {
2020-02-05 12:52:18 +01:00
lv_obj_invalidate(arc);
}
2020-02-05 10:40:50 +01:00
}
2018-06-08 10:26:10 +02:00
#endif