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

Revert "Merge pull request #83 from kkaja123/thumbstick_switch" #152

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions Windows/Gopher/ConfigFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,10 @@ void ConfigFile::ExtractKeys()
outfile << "GAMEPAD_TRIGGER_LEFT = 0" << std::endl;
outfile << "GAMEPAD_TRIGGER_RIGHT = 0" << std::endl;
outfile << "\n" << std::endl;
outfile << "# ADVANCED CONFIGURATION SETTINGS" << std::endl;
outfile << "# ALLOWED CURSOR SPEEDS, FIRST WILL BE CHOSEN BY DEFAULT. VALUES > 1.0 WILL BE IGNORED. NO SPACES." << std::endl;
outfile << "CURSOR_SPEED = ULTRALOW=0.005,LOW=0.015,MED=0.025,HIGH=0.04" << std::endl;
outfile << "# SET ACCELERATION FACTOR FOR NON-LINEAR CURSOR SPEED" << std::endl;
outfile << "# ACCELERATION_FACTOR = 3" << std::endl;
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;
outfile << "SWAP_THUMBSTICKS = 0" << std::endl;
// End config dump

outfile.close();
Expand Down
37 changes: 4 additions & 33 deletions Windows/Gopher/Gopher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ void Gopher::loadConfigFile()
}
speed = speeds[0]; // Initialize the speed to the first speed stored. TODO: Set the speed to a saved speed that was last used when the application was closed last.

// Swap stick functions
SWAP_THUMBSTICKS = strtol(cfg.getValueOfKey<std::string>("SWAP_THUMBSTICKS").c_str(), 0, 0);

// Set the initial window visibility
setWindowVisibility(_hidden);
}
Expand Down Expand Up @@ -499,21 +496,8 @@ void Gopher::handleMouseMovement()
POINT cursor;
GetCursorPos(&cursor);

short tx;
short ty;

if (SWAP_THUMBSTICKS == 0)
{
// Use left stick
tx = _currentState.Gamepad.sThumbLX;
ty = _currentState.Gamepad.sThumbLY;
}
else
{
// Use right stick
tx = _currentState.Gamepad.sThumbRX;
ty = _currentState.Gamepad.sThumbRY;
}
short tx = _currentState.Gamepad.sThumbLX;
short ty = _currentState.Gamepad.sThumbLY;

float x = cursor.x + _xRest;
float y = cursor.y + _yRest;
Expand Down Expand Up @@ -544,22 +528,9 @@ void Gopher::handleMouseMovement()
// Controls the scroll wheel movement by reading the right thumbstick.
void Gopher::handleScrolling()
{
float tx;
float ty;
float tx = getDelta(_currentState.Gamepad.sThumbRX);
float ty = getDelta(_currentState.Gamepad.sThumbRY);

if (SWAP_THUMBSTICKS == 0)
{
// Use right stick
tx = getDelta(_currentState.Gamepad.sThumbRX);
ty = getDelta(_currentState.Gamepad.sThumbRY);
}
else
{
// Use left stick
tx = getDelta(_currentState.Gamepad.sThumbLX);
ty = getDelta(_currentState.Gamepad.sThumbLY);
}

// Handle dead zone
float magnitude = sqrt(tx * tx + ty * ty);

Expand Down
1 change: 0 additions & 1 deletion Windows/Gopher/Gopher.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Gopher
float SCROLL_SPEED = 0.1f; // Speed at which you scroll.
const int FPS = 150; // Update rate of the main Gopher loop. Interpreted as cycles-per-second.
const int SLEEP_AMOUNT = 1000 / FPS; // Number of milliseconds to sleep per iteration.
int SWAP_THUMBSTICKS = 0; // Swaps the function of the thumbsticks when not equal to 0.

XINPUT_STATE _currentState;

Expand Down
37 changes: 37 additions & 0 deletions Windows/Gopher/Gopher/CXBOXController.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "CXBOXController.h"

CXBOXController::CXBOXController(int playerNumber)
{
_controllerNum = playerNumber - 1; //set number
}

XINPUT_STATE CXBOXController::GetState()
{
ZeroMemory(&this->_controllerState, sizeof(XINPUT_STATE));
XInputGetState(_controllerNum, &this->_controllerState);
return _controllerState;
}

bool CXBOXController::IsConnected()
{
ZeroMemory(&this->_controllerState, sizeof(XINPUT_STATE));
DWORD Result = XInputGetState(_controllerNum, &this->_controllerState);

return (Result == ERROR_SUCCESS);
}

void CXBOXController::Vibrate(int leftVal, int rightVal)
{
// Create a Vibraton State
XINPUT_VIBRATION Vibration;

// Zeroise the Vibration
ZeroMemory(&Vibration, sizeof(XINPUT_VIBRATION));

// Set the Vibration Values
Vibration.wLeftMotorSpeed = leftVal;
Vibration.wRightMotorSpeed = rightVal;

// Vibrate the controller
XInputSetState(_controllerNum, &Vibration);
}
16 changes: 16 additions & 0 deletions Windows/Gopher/Gopher/CXBOXController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <Windows.h>
#include <Xinput.h>

class CXBOXController
{
private:
XINPUT_STATE _controllerState;
int _controllerNum;
public:
CXBOXController(int playerNumber);
XINPUT_STATE GetState();
bool IsConnected();
void CXBOXController::Vibrate(int leftVal, int rightVal);
};
Loading