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

Revert arc tracking

This commit is contained in:
Adam Martini 2020-06-25 21:39:19 -07:00
parent a73b316681
commit 6d07effbc3
2 changed files with 25 additions and 45 deletions

View File

@ -403,60 +403,39 @@ static lv_res_t lv_rotary_signal(lv_obj_t * rotary, lv_signal_t sign, void * par
if(sign == LV_SIGNAL_PRESSED) { if(sign == LV_SIGNAL_PRESSED) {
lv_indev_get_point(param, &p); lv_indev_get_point(param, &p);
lv_indev_get_point(lv_indev_get_act(), &ext->last_press_point);
ext->last_drag_x = p.x;
ext->dragging = true; ext->dragging = true;
} }
else if(sign == LV_SIGNAL_PRESSING) { else if(sign == LV_SIGNAL_PRESSING) {
lv_indev_t * indev = lv_indev_get_act(); lv_indev_get_point(param, &p);
if(indev == NULL) return res; lv_coord_t drag_x_diff = p.x -ext->last_drag_x;
lv_indev_type_t indev_type = lv_indev_get_type(indev); if (LV_MATH_ABS(drag_x_diff) > ext->threshold) {
lv_point_t p; if (drag_x_diff > 0) drag_x_diff = ext->threshold;
if(indev_type == LV_INDEV_TYPE_ENCODER || indev_type == LV_INDEV_TYPE_KEYPAD) { else drag_x_diff = -ext->threshold;
p.x = rotary->coords.x1 + lv_obj_get_width(rotary) / 2;
p.y = rotary->coords.y1 + lv_obj_get_height(rotary) / 2;
} }
else { ext->last_drag_x = p.x;
lv_indev_get_point(indev, &p);
if (ext->knob_area.y1 < p.y && p.y < ext->knob_area.y2) {
if (drag_x_diff > 0 && p.x < ext->knob_area.x2) {
lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + drag_x_diff * ext->sensitivity, LV_ANIM_ON);
res = lv_event_send(rotary, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RES_OK) return res;
}
else if (drag_x_diff < 0 && p.x > ext->knob_area.x1) {
ext->last_drag_x = p.x;
lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + drag_x_diff * ext->sensitivity, LV_ANIM_ON);
res = lv_event_send(rotary, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RES_OK) return res;
}
} }
if((LV_MATH_ABS(p.x - ext->last_press_point.x) > indev->driver.drag_limit / 2) ||
(LV_MATH_ABS(p.y - ext->last_press_point.y) > indev->driver.drag_limit / 2)) {
ext->last_press_point.x = p.x;
ext->last_press_point.y = p.y;
}
/*Make point 0 relative to the rotary*/
p.x -= rotary->coords.x1;
p.y -= rotary->coords.y1;
/*Ignore pressing in the inner area*/
int16_t angle;
lv_coord_t r_in = lv_area_get_width(&ext->knob_area) / 2;
p.x -= r_in;
p.y -= r_in;
bool on_ring = true;
if(p.x * p.x + p.y * p.y < r_in * r_in) {
return res; /*Set the angle only if pressed on the ring*/
}
angle = _lv_atan2(p.x, p.y) % 360;
int16_t bg_end = ext->arc.bg_angle_end;
if (ext->arc.bg_angle_end < ext->arc.bg_angle_start) {
bg_end = ext->arc.bg_angle_end + 360;
if (angle < ext->arc.bg_angle_start) angle += 360;
}
lv_rotary_set_value(
rotary,
_lv_map(angle, ext->arc.bg_angle_start, bg_end,
ext->min_value, ext->max_value),
LV_ANIM_OFF
);
} }
else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
ext->dragging = false; ext->dragging = false;
#if LV_USE_GROUP #if LV_USE_GROUP
/*Leave edit mode if released. (No need to wait for LONG_PRESS) */ /*Leave edit mode if released. (No need to wait for LONG_PRESS) */
lv_group_t * g = lv_obj_get_group(rotary); lv_group_t * g = lv_obj_get_group(rotary);
@ -466,6 +445,7 @@ static lv_res_t lv_rotary_signal(lv_obj_t * rotary, lv_signal_t sign, void * par
if(editing) lv_group_set_editing(g, false); if(editing) lv_group_set_editing(g, false);
} }
#endif #endif
} }
else if(sign == LV_SIGNAL_CONTROL) { else if(sign == LV_SIGNAL_CONTROL) {
char c = *((char *)param); char c = *((char *)param);

View File

@ -72,7 +72,7 @@ typedef struct {
int16_t max_value; /*Maximum value of the rotary*/ int16_t max_value; /*Maximum value of the rotary*/
int16_t sensitivity; /*Increment multiplier of the rotary*/ int16_t sensitivity; /*Increment multiplier of the rotary*/
int16_t threshold; /*Increment threshold of the rotary*/ int16_t threshold; /*Increment threshold of the rotary*/
lv_point_t last_press_point; /*Last drag x coordintate of the rotary*/ lv_coord_t last_drag_x; /*Last drag x coordintate of the rotary*/
uint16_t dragging :1; uint16_t dragging :1;
} lv_rotary_ext_t; } lv_rotary_ext_t;