Skip to content

Commit 9f720e5

Browse files
committed
Added additional config settings to default config and applied scrolling changes from Tylemagne#143
1 parent ef18c40 commit 9f720e5

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

Windows/Gopher/ConfigFile.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ void ConfigFile::ExtractKeys()
142142
outfile << "# ACCELERATION_FACTOR = 3" << std::endl;
143143
outfile << "# Swaps the function of the thumbsticks. Set to 0 for default behavior or set to 1 to have the mouse movement on the right stick and scrolling on the left stick." << std::endl;
144144
outfile << "SWAP_THUMBSTICKS = 0" << std::endl;
145+
outfile << "DEAD_ZONE = 6000 # Thumbstick dead zone to use for mouse movement. Absolute maximum thumbstick value is 32768." << std::endl;
146+
outfile << "SCROLL_DEAD_ZONE = 5000 # Thumbstick dead zone to use for scroll wheel movement. Absolute maximum thumbstick value is 32768." << std::endl;
147+
outfile << "TRIGGER_DEAD_ZONE = 0 # Dead zone for the left and right triggers to detect a trigger press. Range from 0 (accept all input) to 255 (ignore all input)." << std::endl;
148+
outfile << "SCROLL_SPEED = 0.1 # Speed at which you scroll (scalar)" << std::endl;
145149
// End config dump
146150

147151
outfile.close();

Windows/Gopher/Gopher.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -473,16 +473,18 @@ float Gopher::getDelta(short t)
473473
// Calculates a multiplier for an analog thumbstick based on the update rate.
474474
//
475475
// Params:
476-
// tValue The thumbstick value
476+
// magnitude The thumbstick magnitude in XY-plane, which is sqrt(deltaX*deltaX + deltaY*deltaY). Must be larger than deadzone.
477477
// deadzone The dead zone to use for this thumbstick
478478
// accel An exponent to use to create an input curve (Optional). 0 to use a linear input
479479
//
480480
// Returns:
481481
// Multiplier used to properly scale the given thumbstick value.
482-
float Gopher::getMult(float lengthsq, float deadzone, float accel = 0.0f)
482+
float Gopher::getMult(float magnitude, float deadzone, float accel = 0.0f)
483483
{
484-
// Normalize the thumbstick value.
485-
float mult = (sqrt(lengthsq) - deadzone) / (MAXSHORT - deadzone);
484+
// Normalize the thumbstick value (result is in range 0 to 1).
485+
// Note that the smallest accepted thumbstick distance is deadzone.
486+
// Thus, 0% would be deadzone (and below) and 100% would be (MAXSHORT - deadzone)
487+
float mult = (magnitude - deadzone) / (MAXSHORT - deadzone);
486488

487489
// Apply a curve to the normalized thumbstick value.
488490
if (accel > 0.0001f)
@@ -504,15 +506,15 @@ void Gopher::handleMouseMovement()
504506

505507
if (SWAP_THUMBSTICKS == 0)
506508
{
507-
// Use left stick
508-
tx = _currentState.Gamepad.sThumbLX;
509-
ty = _currentState.Gamepad.sThumbLY;
509+
// Use left stick
510+
tx = getDelta(_currentState.Gamepad.sThumbLX);
511+
ty = getDelta(_currentState.Gamepad.sThumbLY);
510512
}
511513
else
512514
{
513-
// Use right stick
514-
tx = _currentState.Gamepad.sThumbRX;
515-
ty = _currentState.Gamepad.sThumbRY;
515+
// Use right stick
516+
tx = getDelta(_currentState.Gamepad.sThumbRX);
517+
ty = getDelta(_currentState.Gamepad.sThumbRY);
516518
}
517519

518520
float x = cursor.x + _xRest;
@@ -525,10 +527,10 @@ void Gopher::handleMouseMovement()
525527
float lengthsq = unsigned int(tx * tx + ty * ty);
526528
if (lengthsq > DEAD_ZONE * DEAD_ZONE)
527529
{
528-
float mult = speed * getMult(lengthsq, DEAD_ZONE, acceleration_factor);
530+
float mult = speed * getMult(sqrt(lengthsq), DEAD_ZONE, acceleration_factor);
529531

530-
dx = getDelta(tx) * mult;
531-
dy = getDelta(ty) * mult;
532+
dx = tx * mult;
533+
dy = ty * mult;
532534
}
533535

534536
x += dx;
@@ -561,12 +563,17 @@ void Gopher::handleScrolling()
561563
}
562564

563565
// Handle dead zone
564-
float magnitude = sqrt(tx * tx + ty * ty);
565-
566-
if (magnitude > SCROLL_DEAD_ZONE)
566+
float magnitudeX = abs(tx);
567+
float magnitudeY = abs(ty);
568+
if (magnitudeX > SCROLL_DEAD_ZONE)
569+
{
570+
int scrollX = tx * getMult(magnitudeX, SCROLL_DEAD_ZONE) * SCROLL_SPEED;
571+
mouseEvent(MOUSEEVENTF_HWHEEL, scrollX);
572+
}
573+
if (magnitudeY > SCROLL_DEAD_ZONE)
567574
{
568-
mouseEvent(MOUSEEVENTF_HWHEEL, tx * getMult(tx * tx, SCROLL_DEAD_ZONE) * SCROLL_SPEED);
569-
mouseEvent(MOUSEEVENTF_WHEEL, ty * getMult(ty * ty, SCROLL_DEAD_ZONE) * SCROLL_SPEED);
575+
int scrollY = ty * getMult(magnitudeY, SCROLL_DEAD_ZONE) * SCROLL_SPEED;
576+
mouseEvent(MOUSEEVENTF_WHEEL, scrollY);
570577
}
571578
}
572579

0 commit comments

Comments
 (0)