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"
|
2019-03-07 00:05:16 +01:00
|
|
|
#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
|
|
|
|
*********************/
|
2019-09-26 10:51:54 +02:00
|
|
|
#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);
|
2020-01-16 14:26:36 +01:00
|
|
|
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
|
|
|
|
**********************/
|
2019-02-26 09:25:46 +01:00
|
|
|
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
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
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*/
|
2020-02-01 15:02:29 +01:00
|
|
|
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*/
|
2020-02-01 15:02:29 +01:00
|
|
|
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);
|
2019-12-03 18:16:14 +01:00
|
|
|
if(ext == NULL) {
|
2020-02-01 15:02:29 +01:00
|
|
|
lv_obj_del(arc);
|
2019-12-03 18:16:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-25 13:33:53 +02:00
|
|
|
|
2020-02-01 15:02:29 +01:00
|
|
|
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-02-03 16:18:53 +01:00
|
|
|
ext->bg_angle_start = 135;
|
|
|
|
ext->bg_angle_end = 45;
|
|
|
|
ext->arc_angle_start = 135;
|
|
|
|
ext->arc_angle_end = 270;
|
2020-02-01 15:02:29 +01:00
|
|
|
lv_style_list_init(&ext->style_arc);
|
2018-06-08 10:26:10 +02:00
|
|
|
|
2020-02-01 15:02:29 +01: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*/
|
2020-02-01 15:02:29 +01:00
|
|
|
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) {
|
2020-02-01 15:02:29 +01:00
|
|
|
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-03 16:18:53 +01:00
|
|
|
ext->arc_angle_start = copy_ext->arc_angle_start;
|
|
|
|
ext->arc_angle_end = copy_ext->arc_angle_end;
|
2018-06-08 10:26:10 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Refresh the style with new signal function*/
|
2020-02-01 15:02:29 +01:00
|
|
|
lv_obj_refresh_style(arc);
|
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
|
|
|
|
2020-02-01 15:02:29 +01: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
|
|
|
|
*====================*/
|
|
|
|
|
|
|
|
/**
|
2019-11-26 13:22:03 +01:00
|
|
|
* Set the start angle of an arc. 0 deg: right, 90 bottom: right etc.
|
2018-06-08 10:26:10 +02:00
|
|
|
* @param arc pointer to an arc object
|
|
|
|
* @param start the start angle [0..360]
|
|
|
|
*/
|
2019-11-26 13:22:03 +01:00
|
|
|
void lv_arc_set_start_angle(lv_obj_t * arc, int16_t start)
|
2018-06-08 10:26:10 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +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
|
|
|
|
2019-11-26 13:22:03 +01: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);
|
|
|
|
}
|
2019-11-26 13:22:03 +01:00
|
|
|
|
2020-02-05 15:12:45 +01:00
|
|
|
ext->arc_angle_start = start;
|
2019-11-26 13:22:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the start angle of an arc. 0 deg: right, 90 bottom: right etc.
|
|
|
|
* @param arc pointer to an arc object
|
|
|
|
* @param start the start angle [0..360]
|
|
|
|
*/
|
|
|
|
void lv_arc_set_end_angle(lv_obj_t * arc, int16_t end)
|
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(arc, LV_OBJX_NAME);
|
|
|
|
|
|
|
|
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
|
|
|
|
|
|
|
|
if(end > 360) end -= 360;
|
|
|
|
|
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-05 15:12:45 +01:00
|
|
|
else if(ext->arc_angle_end > ext->arc_angle_start && end > ext->arc_angle_start ) {
|
|
|
|
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-05 15:12:45 +01:00
|
|
|
else if(ext->arc_angle_end < ext->arc_angle_start && end < ext->arc_angle_start ) {
|
|
|
|
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);
|
|
|
|
}
|
2019-11-26 13:22:03 +01:00
|
|
|
|
2020-02-03 16:18:53 +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
|
|
|
|
*/
|
|
|
|
void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end)
|
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(arc, LV_OBJX_NAME);
|
|
|
|
|
|
|
|
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
|
|
|
|
|
|
|
|
if(end > 360) end -= 360;
|
|
|
|
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
|
|
|
|
2020-02-05 15:12:45 +01:00
|
|
|
ext->arc_angle_start = start;
|
|
|
|
ext->arc_angle_end = end;
|
2019-09-26 12:54:40 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
|
|
|
|
|
|
|
/**
|
2018-12-23 06:38:54 -05:00
|
|
|
* 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
|
|
|
{
|
2019-09-26 12:54:40 +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
|
|
|
|
2020-02-03 16:18:53 +01:00
|
|
|
return ext->arc_angle_start;
|
2018-06-08 10:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-12-23 06:38:54 -05: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
|
|
|
{
|
2019-09-26 12:54:40 +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
|
|
|
|
2020-02-03 16:18:53 +01:00
|
|
|
return ext->arc_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-03 16:18:53 +01:00
|
|
|
lv_coord_t r = (LV_MATH_MIN(lv_obj_get_width(arc), lv_obj_get_height(arc))) / 2;
|
|
|
|
lv_coord_t x = arc->coords.x1 + lv_obj_get_width(arc) / 2;
|
|
|
|
lv_coord_t y = arc->coords.y1 + lv_obj_get_height(arc) / 2;
|
2020-01-10 11:10:07 +01:00
|
|
|
|
2020-01-07 23:43:57 +01:00
|
|
|
lv_draw_line_dsc_t arc_dsc;
|
2020-02-03 16:18:53 +01:00
|
|
|
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->bg_angle_end, clip_area, &arc_dsc);
|
|
|
|
|
2020-01-07 23:43:57 +01:00
|
|
|
lv_draw_line_dsc_init(&arc_dsc);
|
2020-01-10 11:10:07 +01:00
|
|
|
lv_obj_init_draw_line_dsc(arc, LV_ARC_PART_ARC, &arc_dsc);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2020-02-03 16:18:53 +01:00
|
|
|
lv_draw_arc(x, y, r, ext->arc_angle_start, ext->arc_angle_end, 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;
|
|
|
|
|
2019-09-26 12:54:40 +02:00
|
|
|
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
|
2019-09-26 10:51:54 +02:00
|
|
|
|
2018-06-08 10:26:10 +02:00
|
|
|
if(sign == LV_SIGNAL_CLEANUP) {
|
|
|
|
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2020-01-16 14:26:36 +01:00
|
|
|
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);
|
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
lv_style_list_t * style_dsc_p;
|
2020-01-10 11:10:07 +01:00
|
|
|
|
|
|
|
switch(part) {
|
|
|
|
case LV_ARC_PART_BG:
|
2020-01-16 21:25:11 +01:00
|
|
|
style_dsc_p = &arc->style_list;
|
2020-01-10 11:10:07 +01:00
|
|
|
break;
|
|
|
|
case LV_ARC_PART_ARC:
|
|
|
|
style_dsc_p = &ext->style_arc;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
style_dsc_p = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
uint8_t start_quarter = start_angle / 90;
|
|
|
|
uint8_t end_quarter = end_angle / 90;
|
|
|
|
lv_coord_t x = arc->coords.x1 + lv_obj_get_width(arc) / 2;
|
|
|
|
lv_coord_t y = arc->coords.y1 + lv_obj_get_height(arc) / 2;
|
2020-02-05 12:52:18 +01:00
|
|
|
lv_coord_t rout = (LV_MATH_MIN(lv_obj_get_width(arc), lv_obj_get_height(arc))) / 2;
|
2020-02-05 15:12:45 +01:00
|
|
|
lv_style_int_t w = lv_obj_get_style_line_width(arc, LV_ARC_PART_ARC);
|
2020-02-05 15:35:53 +01:00
|
|
|
lv_style_int_t rounded = lv_obj_get_style_line_rounded(arc, LV_ARC_PART_ARC);
|
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-05 12:52:18 +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;
|
|
|
|
inv_area.y1 = y + ((LV_MATH_MIN(lv_trigo_sin(end_angle), 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;
|
|
|
|
inv_area.y2 = y + rout + extra_area;
|
2020-02-05 12:52:18 +01:00
|
|
|
lv_obj_invalidate_area(arc, &inv_area);
|
|
|
|
} 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;
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
} 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;
|
|
|
|
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);
|
|
|
|
} else if(start_quarter == 3 && end_quarter == 0) {
|
2020-02-05 15:32:14 +01:00
|
|
|
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;
|
|
|
|
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);
|
|
|
|
} else {
|
|
|
|
lv_obj_invalidate(arc);
|
|
|
|
}
|
2020-02-05 10:40:50 +01:00
|
|
|
}
|
2018-06-08 10:26:10 +02:00
|
|
|
#endif
|