mirror of
https://github.com/lvgl/lvgl.git
synced 2026-09-26 17:55:55 +08:00
refactor(arc) rename arc type to mode
This commit is contained in:
+40
-14
@@ -283,7 +283,7 @@ void lv_arc_set_rotation(lv_obj_t * obj, uint16_t rotation)
|
||||
* @param arc pointer to arc object
|
||||
* @param type arc type
|
||||
*/
|
||||
void lv_arc_set_type(lv_obj_t * obj, lv_arc_type_t type)
|
||||
void lv_arc_set_mode(lv_obj_t * obj, lv_arc_mode_t type)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_arc_t * arc = (lv_arc_t *)obj;
|
||||
@@ -297,12 +297,12 @@ void lv_arc_set_type(lv_obj_t * obj, lv_arc_type_t type)
|
||||
if(arc->bg_angle_end <arc->bg_angle_start) bg_end =arc->bg_angle_end + 360;
|
||||
|
||||
switch(arc->type) {
|
||||
case LV_ARC_TYPE_SYMMETRIC:
|
||||
case LV_ARC_MODE_SYMMETRICAL:
|
||||
bg_midpoint = (arc->bg_angle_start + bg_end) / 2;
|
||||
lv_arc_set_start_angle(obj, bg_midpoint);
|
||||
lv_arc_set_end_angle(obj, bg_midpoint);
|
||||
break;
|
||||
case LV_ARC_TYPE_REVERSE:
|
||||
case LV_ARC_MODE_REVERSE:
|
||||
lv_arc_set_end_angle(obj,arc->bg_angle_end);
|
||||
break;
|
||||
default: /** LV_ARC_TYPE_NORMAL*/
|
||||
@@ -366,7 +366,7 @@ void lv_arc_set_range(lv_obj_t * obj, int16_t min, int16_t max)
|
||||
* @param arc pointer to a arc object
|
||||
* @param threshold increment threshold
|
||||
*/
|
||||
void lv_arc_set_chg_rate(lv_obj_t * obj, uint16_t rate)
|
||||
void lv_arc_set_change_rate(lv_obj_t * obj, uint16_t rate)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_arc_t * arc = (lv_arc_t *)obj;
|
||||
@@ -461,7 +461,7 @@ int16_t lv_arc_get_max_value(const lv_obj_t * obj)
|
||||
* @param arc pointer to a arc object
|
||||
* @return arc type
|
||||
*/
|
||||
lv_arc_type_t lv_arc_get_type(const lv_obj_t * obj)
|
||||
lv_arc_mode_t lv_arc_get_mode(const lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
return ((lv_arc_t*) obj)->type;
|
||||
@@ -492,7 +492,7 @@ static void lv_arc_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
arc->bg_angle_end = 45;
|
||||
arc->indic_angle_start = 135;
|
||||
arc->indic_angle_end = 270;
|
||||
arc->type = LV_ARC_TYPE_NORMAL;
|
||||
arc->type = LV_ARC_MODE_NORMAL;
|
||||
arc->value = VALUE_UNSET;
|
||||
arc->min_close = 1;
|
||||
arc->min_value = 0;
|
||||
@@ -685,15 +685,26 @@ static void lv_arc_draw(lv_event_t * e)
|
||||
lv_coord_t arc_r;
|
||||
get_center(obj, ¢er, &arc_r);
|
||||
|
||||
lv_obj_draw_dsc_t obj_draw_dsc;
|
||||
lv_obj_draw_dsc_init(&obj_draw_dsc, clip_area);
|
||||
|
||||
/*Draw the background arc*/
|
||||
lv_draw_arc_dsc_t arc_dsc;
|
||||
if(arc_r > 0) {
|
||||
lv_draw_arc_dsc_init(&arc_dsc);
|
||||
lv_obj_init_draw_arc_dsc(obj, LV_PART_MAIN, &arc_dsc);
|
||||
|
||||
lv_draw_arc(center.x, center.y, arc_r,arc->bg_angle_start +arc->rotation,
|
||||
obj_draw_dsc.part = LV_PART_MAIN;
|
||||
obj_draw_dsc.p1 = center;
|
||||
obj_draw_dsc.radius = arc_r;
|
||||
obj_draw_dsc.arc_dsc = &arc_dsc;
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &obj_draw_dsc);
|
||||
|
||||
lv_draw_arc(center.x, center.y, arc_r, arc->bg_angle_start + arc->rotation,
|
||||
arc->bg_angle_end + arc->rotation, clip_area,
|
||||
&arc_dsc);
|
||||
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_END, &obj_draw_dsc);
|
||||
}
|
||||
|
||||
/*make the indicator arc smaller or larger according to its greatest padding value*/
|
||||
@@ -707,9 +718,17 @@ static void lv_arc_draw(lv_event_t * e)
|
||||
lv_draw_arc_dsc_init(&arc_dsc);
|
||||
lv_obj_init_draw_arc_dsc(obj, LV_PART_INDICATOR, &arc_dsc);
|
||||
|
||||
lv_draw_arc(center.x, center.y, indic_r,arc->indic_angle_start +arc->rotation,
|
||||
arc->indic_angle_end +arc->rotation, clip_area,
|
||||
obj_draw_dsc.part = LV_PART_INDICATOR;
|
||||
obj_draw_dsc.p1 = center;
|
||||
obj_draw_dsc.radius = indic_r;
|
||||
obj_draw_dsc.arc_dsc = &arc_dsc;
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &obj_draw_dsc);
|
||||
|
||||
lv_draw_arc(center.x, center.y, indic_r, arc->indic_angle_start +arc->rotation,
|
||||
arc->indic_angle_end + arc->rotation, clip_area,
|
||||
&arc_dsc);
|
||||
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_END, &obj_draw_dsc);
|
||||
}
|
||||
|
||||
lv_area_t knob_area;
|
||||
@@ -719,7 +738,14 @@ static void lv_arc_draw(lv_event_t * e)
|
||||
lv_draw_rect_dsc_init(&knob_rect_dsc);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_KNOB, &knob_rect_dsc);
|
||||
|
||||
obj_draw_dsc.part = LV_PART_KNOB;
|
||||
obj_draw_dsc.draw_area = &knob_area;
|
||||
obj_draw_dsc.arc_dsc = &knob_rect_dsc;
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &obj_draw_dsc);
|
||||
|
||||
lv_draw_rect(&knob_area, clip_area, &knob_rect_dsc);
|
||||
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_END, &obj_draw_dsc);
|
||||
}
|
||||
|
||||
static void inv_arc_area(lv_obj_t * obj, uint16_t start_angle, uint16_t end_angle, lv_part_t part)
|
||||
@@ -873,13 +899,13 @@ static void get_knob_area(lv_obj_t * obj, const lv_point_t * center, lv_coord_t
|
||||
r -= indic_width_half;
|
||||
|
||||
uint16_t angle =arc->rotation;
|
||||
if(arc->type == LV_ARC_TYPE_NORMAL) {
|
||||
if(arc->type == LV_ARC_MODE_NORMAL) {
|
||||
angle +=arc->indic_angle_end;
|
||||
}
|
||||
else if(arc->type == LV_ARC_TYPE_REVERSE) {
|
||||
else if(arc->type == LV_ARC_MODE_REVERSE) {
|
||||
angle +=arc->indic_angle_start;
|
||||
}
|
||||
else if(arc->type == LV_ARC_TYPE_SYMMETRIC) {
|
||||
else if(arc->type == LV_ARC_MODE_SYMMETRICAL) {
|
||||
int32_t range_midpoint = (int32_t)(arc->min_value +arc->max_value) / 2;
|
||||
if(arc->value < range_midpoint) angle +=arc->indic_angle_start;
|
||||
else angle +=arc->indic_angle_end;
|
||||
@@ -915,7 +941,7 @@ static void value_update(lv_obj_t * obj)
|
||||
|
||||
int16_t angle;
|
||||
switch(arc->type) {
|
||||
case LV_ARC_TYPE_SYMMETRIC:
|
||||
case LV_ARC_MODE_SYMMETRICAL:
|
||||
bg_midpoint = (arc->bg_angle_start + bg_end) / 2;
|
||||
range_midpoint = (int32_t)(arc->min_value +arc->max_value) / 2;
|
||||
|
||||
@@ -930,7 +956,7 @@ static void value_update(lv_obj_t * obj)
|
||||
lv_arc_set_end_angle(obj, angle);
|
||||
}
|
||||
break;
|
||||
case LV_ARC_TYPE_REVERSE:
|
||||
case LV_ARC_MODE_REVERSE:
|
||||
angle = lv_map(arc->value,arc->min_value,arc->max_value,arc->bg_angle_start, bg_end);
|
||||
lv_arc_set_start_angle(obj, angle);
|
||||
break;
|
||||
|
||||
+51
-52
@@ -28,11 +28,11 @@ extern "C" {
|
||||
**********************/
|
||||
|
||||
enum {
|
||||
LV_ARC_TYPE_NORMAL,
|
||||
LV_ARC_TYPE_SYMMETRIC,
|
||||
LV_ARC_TYPE_REVERSE
|
||||
LV_ARC_MODE_NORMAL,
|
||||
LV_ARC_MODE_SYMMETRICAL,
|
||||
LV_ARC_MODE_REVERSE
|
||||
};
|
||||
typedef uint8_t lv_arc_type_t;
|
||||
typedef uint8_t lv_arc_mode_t;
|
||||
|
||||
typedef struct {
|
||||
lv_obj_t obj;
|
||||
@@ -41,15 +41,15 @@ typedef struct {
|
||||
uint16_t indic_angle_end;
|
||||
uint16_t bg_angle_start;
|
||||
uint16_t bg_angle_end;
|
||||
int16_t value; /*Current value of the arc*/
|
||||
int16_t min_value; /*Minimum value of the arc*/
|
||||
int16_t max_value; /*Maximum value of the arc*/
|
||||
int16_t value; /*Current value of the arc*/
|
||||
int16_t min_value; /*Minimum value of the arc*/
|
||||
int16_t max_value; /*Maximum value of the arc*/
|
||||
uint16_t dragging : 1;
|
||||
uint16_t type : 2;
|
||||
uint16_t min_close : 1; /*1: the last pressed angle was closer to minimum end*/
|
||||
uint16_t chg_rate; /*Drag angle rate of change of the arc (degrees/sec)*/
|
||||
uint32_t last_tick; /*Last dragging event timestamp of the arc*/
|
||||
int16_t last_angle; /*Last dragging angle of the arc*/
|
||||
uint16_t min_close : 1; /*1: the last pressed angle was closer to minimum end*/
|
||||
uint16_t chg_rate; /*Drag angle rate of change of the arc (degrees/sec)*/
|
||||
uint32_t last_tick; /*Last dragging event timestamp of the arc*/
|
||||
int16_t last_angle; /*Last dragging angle of the arc*/
|
||||
}lv_arc_t;
|
||||
|
||||
extern const lv_obj_class_t lv_arc_class;
|
||||
@@ -75,84 +75,83 @@ lv_obj_t * lv_arc_create(lv_obj_t * parent);
|
||||
|
||||
/**
|
||||
* Set the start angle of an arc. 0 deg: right, 90 bottom, etc.
|
||||
* @param arc pointer to an arc object
|
||||
* @param arc pointer to an arc object
|
||||
* @param start the start angle
|
||||
*/
|
||||
void lv_arc_set_start_angle(lv_obj_t * arc, uint16_t start);
|
||||
|
||||
/**
|
||||
* Set the end angle of an arc. 0 deg: right, 90 bottom, etc.
|
||||
* @param arc pointer to an arc object
|
||||
* @param end the end angle
|
||||
* @param arc pointer to an arc object
|
||||
* @param end the end angle
|
||||
*/
|
||||
void lv_arc_set_end_angle(lv_obj_t * arc, uint16_t end);
|
||||
|
||||
/**
|
||||
* Set the start and end angles
|
||||
* @param arc pointer to an arc object
|
||||
* @param arc pointer to an arc object
|
||||
* @param start the start angle
|
||||
* @param end the end angle
|
||||
* @param end the end angle
|
||||
*/
|
||||
void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end);
|
||||
|
||||
/**
|
||||
* Set the start angle of an arc background. 0 deg: right, 90 bottom, etc.
|
||||
* @param arc pointer to an arc object
|
||||
* @param arc pointer to an arc object
|
||||
* @param start the start angle
|
||||
*/
|
||||
void lv_arc_set_bg_start_angle(lv_obj_t * arc, uint16_t 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
|
||||
* @param arc pointer to an arc object
|
||||
* @param end the end angle
|
||||
*/
|
||||
void lv_arc_set_bg_end_angle(lv_obj_t * arc, uint16_t end);
|
||||
|
||||
/**
|
||||
* Set the start and end angles of the arc background
|
||||
* @param arc pointer to an arc object
|
||||
* @param arc pointer to an arc object
|
||||
* @param start the start angle
|
||||
* @param end the end angle
|
||||
* @param end the end angle
|
||||
*/
|
||||
void lv_arc_set_bg_angles(lv_obj_t * arc, uint16_t start, uint16_t end);
|
||||
|
||||
/**
|
||||
* Set the rotation for the whole arc
|
||||
* @param arc pointer to an arc object
|
||||
* @param rotation_angle rotation angle
|
||||
* @param arc pointer to an arc object
|
||||
* @param rotation rotation angle
|
||||
*/
|
||||
void lv_arc_set_rotation(lv_obj_t * arc, uint16_t rotation);
|
||||
|
||||
/**
|
||||
* Set the type of arc.
|
||||
* @param arc pointer to arc object
|
||||
* @param type arc type
|
||||
* @param arc pointer to arc object
|
||||
* @param mode arc's mode
|
||||
*/
|
||||
void lv_arc_set_type(lv_obj_t * arc, lv_arc_type_t type);
|
||||
void lv_arc_set_mode(lv_obj_t * arc, lv_arc_mode_t type);
|
||||
|
||||
/**
|
||||
* Set a new value on the arc
|
||||
* @param arc pointer to a arc object
|
||||
* @param arc pointer to a arc object
|
||||
* @param value new value
|
||||
*/
|
||||
void lv_arc_set_value(lv_obj_t * arc, int16_t value);
|
||||
|
||||
/**
|
||||
* Set minimum and the maximum values of a arc
|
||||
* @param arc pointer to the arc object
|
||||
* @param min minimum value
|
||||
* @param max maximum value
|
||||
* @param arc pointer to the arc object
|
||||
* @param min minimum value
|
||||
* @param max maximum value
|
||||
*/
|
||||
void lv_arc_set_range(lv_obj_t * arc, int16_t min, int16_t max);
|
||||
|
||||
/**
|
||||
* Set the threshold of arc knob increments
|
||||
* position.
|
||||
* @param arc pointer to a arc object
|
||||
* @param threshold increment threshold
|
||||
* Set a change rate to limit the speed how fast the arc should reache the pressed point.
|
||||
* @param arc pointer to a arc object
|
||||
* @param rate the change rate
|
||||
*/
|
||||
void lv_arc_set_chg_rate(lv_obj_t * arc, uint16_t threshold);
|
||||
void lv_arc_set_change_rate(lv_obj_t * arc, uint16_t rate);
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
@@ -160,59 +159,59 @@ void lv_arc_set_chg_rate(lv_obj_t * arc, uint16_t threshold);
|
||||
|
||||
/**
|
||||
* Get the start angle of an arc.
|
||||
* @param arc pointer to an arc object
|
||||
* @return the start angle [0..360]
|
||||
* @param arc pointer to an arc object
|
||||
* @return the start angle [0..360]
|
||||
*/
|
||||
uint16_t lv_arc_get_angle_start(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the end angle of an arc.
|
||||
* @param arc pointer to an arc object
|
||||
* @return the end angle [0..360]
|
||||
* @param arc pointer to an arc object
|
||||
* @return the end angle [0..360]
|
||||
*/
|
||||
uint16_t lv_arc_get_angle_end(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the start angle of an arc background.
|
||||
* @param arc pointer to an arc object
|
||||
* @return the start angle [0..360]
|
||||
* @param arc pointer to an arc object
|
||||
* @return the start angle [0..360]
|
||||
*/
|
||||
uint16_t lv_arc_get_bg_angle_start(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the end angle of an arc background.
|
||||
* @param arc pointer to an arc object
|
||||
* @return the end angle [0..360]
|
||||
* @param arc pointer to an arc object
|
||||
* @return the end angle [0..360]
|
||||
*/
|
||||
uint16_t lv_arc_get_bg_angle_end(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the value of a arc
|
||||
* @param arc pointer to a arc object
|
||||
* @return the value of the arc
|
||||
* @param arc pointer to a arc object
|
||||
* @return the value of the arc
|
||||
*/
|
||||
int16_t lv_arc_get_value(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the minimum value of a arc
|
||||
* @param arc pointer to a arc object
|
||||
* @return the minimum value of the arc
|
||||
* @param arc pointer to a arc object
|
||||
* @return the minimum value of the arc
|
||||
*/
|
||||
int16_t lv_arc_get_min_value(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the maximum value of a arc
|
||||
* @param arc pointer to a arc object
|
||||
* @return the maximum value of the arc
|
||||
* @param arc pointer to a arc object
|
||||
* @return the maximum value of the arc
|
||||
*/
|
||||
int16_t lv_arc_get_max_value(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get whether the arc is type or not.
|
||||
* @param arc pointer to a arc object
|
||||
* @return arc type
|
||||
* @param arc pointer to a arc object
|
||||
* @return arc's mode
|
||||
*/
|
||||
lv_arc_type_t lv_arc_get_type(const lv_obj_t * obj);
|
||||
lv_arc_mode_t lv_arc_get_mode(const lv_obj_t * obj);
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
|
||||
Reference in New Issue
Block a user