1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/client/eventsSDL/InputSourceGameController.h

70 lines
2.2 KiB
C++
Raw Normal View History

2024-04-03 14:34:22 +02:00
/*
* InputSourceGameController.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include <SDL_events.h>
#include <SDL_gamecontroller.h>
2024-04-03 14:34:22 +02:00
2024-04-28 14:06:47 +02:00
#include "../../lib/Point.h"
2024-04-30 14:23:19 +02:00
#include "../gui/Shortcut.h"
2024-04-03 14:34:22 +02:00
/// Class that handles game controller input from SDL events
class InputSourceGameController
{
2024-04-30 10:38:13 +02:00
static void gameControllerDeleter(SDL_GameController * gameController);
using GameControllerPtr = std::unique_ptr<SDL_GameController, decltype(&gameControllerDeleter)>;
2024-04-03 14:34:22 +02:00
2024-04-30 10:38:13 +02:00
std::map<int, GameControllerPtr> gameControllerMap;
std::set<SDL_GameControllerAxis> pressedAxes;
2024-04-30 14:31:35 +02:00
std::chrono::steady_clock::time_point lastCheckTime;
double cursorAxisValueX;
double cursorAxisValueY;
double cursorPlanDisX;
double cursorPlanDisY;
2024-04-28 14:06:47 +02:00
2024-04-30 10:38:13 +02:00
bool scrollAxisMoved;
Point scrollStart;
Point scrollCurrent;
double scrollAxisValueX;
double scrollAxisValueY;
double scrollPlanDisX;
double scrollPlanDisY;
2024-04-03 14:34:22 +02:00
const double configTriggerThreshold;
const double configAxisDeadZone;
const double configAxisFullZone;
const double configAxisSpeed;
const double configAxisScale;
2024-04-30 10:38:13 +02:00
void openGameController(int index);
int getJoystickIndex(SDL_GameController * controller);
double getRealAxisValue(int value) const;
void dispatchAxisShortcuts(const std::vector<EShortcut> & shortcutsVector, SDL_GameControllerAxis axisID, int axisValue);
2024-04-30 10:38:13 +02:00
void tryToConvertCursor();
void doCursorMove(int deltaX, int deltaY);
int getMoveDis(float planDis);
2024-04-30 14:31:35 +02:00
void handleCursorUpdate(int32_t deltaTimeMs);
void handleScrollUpdate(int32_t deltaTimeMs);
bool isScrollAxisReleased() const;
2024-04-03 14:34:22 +02:00
public:
2024-04-30 10:38:13 +02:00
InputSourceGameController();
void tryOpenAllGameControllers();
void handleEventDeviceAdded(const SDL_ControllerDeviceEvent & device);
void handleEventDeviceRemoved(const SDL_ControllerDeviceEvent & device);
void handleEventDeviceRemapped(const SDL_ControllerDeviceEvent & device);
void handleEventAxisMotion(const SDL_ControllerAxisEvent & axis);
void handleEventButtonDown(const SDL_ControllerButtonEvent & button);
void handleEventButtonUp(const SDL_ControllerButtonEvent & button);
void handleUpdate();
2024-04-03 14:34:22 +02:00
};