Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlays: Improve Analog Recentering #17505

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions input/input_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -2371,27 +2371,31 @@ static void input_overlay_get_analog_state(

if (first_touch)
{
unsigned recenter_zone =
unsigned recenter_zone = /* [0,100] */
config_get_ptr()->uints.input_overlay_analog_recenter_zone;

/* Reset analog center */
x_center[b] = desc->x_shift;
y_center[b] = desc->y_shift;

if (recenter_zone != 0)
{
/* Get analog state without adjusting center or saturation */
x_val = (x - desc->x_shift) / desc->range_x;
y_val = (y - desc->y_shift) / desc->range_y;

/* Recenter if within zone */
if ( (x_val * x_val + y_val * y_val) * 1e4
< (recenter_zone * recenter_zone)
|| recenter_zone >= 100)
{
x_center[b] = x;
y_center[b] = y;
}
float touch_dist, w;

x_val = (x - desc->x_shift) / desc->range_x;
y_val = (y - desc->y_shift) / desc->range_y;
touch_dist = sqrt((x_val * x_val + y_val * y_val) * 1e4);

/* Inside zone, recenter to first touch.
* Outside zone, recenter to zone perimeter. */
if (touch_dist <= recenter_zone || recenter_zone >= 100)
w = 0.0f;
else
w = (touch_dist - recenter_zone) / touch_dist;

x_center[b] = x * (1.0f - w) + desc->x_shift * w;
y_center[b] = y * (1.0f - w) + desc->y_shift * w;
}
else
{
x_center[b] = desc->x_shift;
y_center[b] = desc->y_shift;
}
}

Expand Down
Loading