1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Spaces -> tabs

This commit is contained in:
Ivan Savenko 2024-04-30 11:38:13 +03:00
parent 62bb9fe4b7
commit 0d8d75afd4
18 changed files with 501 additions and 504 deletions

View File

@ -17,196 +17,196 @@
GameControllerConfig::GameControllerConfig(): leftAxisType(AxisType::NONE), rightAxisType(AxisType::NONE)
{
load();
load();
}
void GameControllerConfig::load()
{
const JsonNode config = JsonUtils::assembleFromFiles("config/shortcutsConfig");
for(auto const & entry : config["joystick"].Struct())
{
std::string configName = entry.first;
if(configName == "leftaxis")
leftAxisType = parseAxis(entry.first, entry.second);
else if (configName == "rightaxis")
rightAxisType = parseAxis(entry.first, entry.second);
else if (configName == "lefttrigger" || configName == "righttrigger")
parseTrigger(entry.first, entry.second);
else
parseButton(entry.first, entry.second);
}
const JsonNode config = JsonUtils::assembleFromFiles("config/shortcutsConfig");
for(auto const & entry : config["joystick"].Struct())
{
std::string configName = entry.first;
if(configName == "leftaxis")
leftAxisType = parseAxis(entry.first, entry.second);
else if (configName == "rightaxis")
rightAxisType = parseAxis(entry.first, entry.second);
else if (configName == "lefttrigger" || configName == "righttrigger")
parseTrigger(entry.first, entry.second);
else
parseButton(entry.first, entry.second);
}
}
AxisType GameControllerConfig::parseAxis(const std::string & key, const JsonNode & value)
{
if(!value.isString())
{
logGlobal->error("The value of joystick config key %s should be a string!", key);
return AxisType::NONE;
}
if(!value.isString())
{
logGlobal->error("The value of joystick config key %s should be a string!", key);
return AxisType::NONE;
}
std::string featureName = value.String();
if(featureName == "cursorMotion")
return AxisType::CURSOR_MOTION;
else if(featureName == "mapScroll")
return AxisType::MAP_SCROLL;
else if(featureName != "")
logGlobal->error("Unknown value %s of joystick config key %s!", featureName, key);
return AxisType::NONE;
std::string featureName = value.String();
if(featureName == "cursorMotion")
return AxisType::CURSOR_MOTION;
else if(featureName == "mapScroll")
return AxisType::MAP_SCROLL;
else if(featureName != "")
logGlobal->error("Unknown value %s of joystick config key %s!", featureName, key);
return AxisType::NONE;
}
void GameControllerConfig::parseTrigger(const std::string & key, const JsonNode & value)
{
std::vector<std::string> operations = getOperations(key, value);
SDL_GameControllerAxis triggerAxis = key == "lefttrigger" ?
SDL_CONTROLLER_AXIS_TRIGGERLEFT : SDL_CONTROLLER_AXIS_TRIGGERRIGHT;
std::vector<EShortcut> shortcuts;
for(const auto & operation : operations)
{
if(operation == "mouseLeftClick")
{
leftClickTriggerSet.insert(triggerAxis);
}
else if(operation == "mouseRightClick")
{
rightClickTriggerSet.insert(triggerAxis);
}
else
{
EShortcut shortcut = GH.shortcuts().findShortcut(operation);
if(shortcut == EShortcut::NONE)
logGlobal->error("Shortcut %s in joystick config key %s is invalid.", operation, key);
else
shortcuts.push_back(shortcut);
}
}
std::vector<std::string> operations = getOperations(key, value);
SDL_GameControllerAxis triggerAxis = key == "lefttrigger" ?
SDL_CONTROLLER_AXIS_TRIGGERLEFT : SDL_CONTROLLER_AXIS_TRIGGERRIGHT;
std::vector<EShortcut> shortcuts;
for(const auto & operation : operations)
{
if(operation == "mouseLeftClick")
{
leftClickTriggerSet.insert(triggerAxis);
}
else if(operation == "mouseRightClick")
{
rightClickTriggerSet.insert(triggerAxis);
}
else
{
EShortcut shortcut = GH.shortcuts().findShortcut(operation);
if(shortcut == EShortcut::NONE)
logGlobal->error("Shortcut %s in joystick config key %s is invalid.", operation, key);
else
shortcuts.push_back(shortcut);
}
}
if(!shortcuts.empty())
triggerShortcutsMap.emplace(triggerAxis, std::move(shortcuts));
if(!shortcuts.empty())
triggerShortcutsMap.emplace(triggerAxis, std::move(shortcuts));
}
void GameControllerConfig::parseButton(const std::string & key, const JsonNode & value)
{
std::vector<std::string> operations = getOperations(key, value);
SDL_GameControllerButton button = SDL_GameControllerGetButtonFromString(key.c_str());
if(button == SDL_CONTROLLER_BUTTON_INVALID)
{
logGlobal->error("Joystick config key %s is invalid.", key);
return;
}
std::vector<std::string> operations = getOperations(key, value);
SDL_GameControllerButton button = SDL_GameControllerGetButtonFromString(key.c_str());
if(button == SDL_CONTROLLER_BUTTON_INVALID)
{
logGlobal->error("Joystick config key %s is invalid.", key);
return;
}
std::vector<EShortcut> shortcuts;
for(const auto & operation : operations)
{
if(operation == "mouseLeftClick")
{
leftClickButtonSet.insert(button);
}
else if(operation == "mouseRightClick")
{
rightClickButtonSet.insert(button);
}
else
{
EShortcut shortcut = GH.shortcuts().findShortcut(operation);
if(shortcut == EShortcut::NONE)
logGlobal->error("Shortcut %s in joystick config key %s is invalid.", operation, key);
else
shortcuts.push_back(shortcut);
}
}
std::vector<EShortcut> shortcuts;
for(const auto & operation : operations)
{
if(operation == "mouseLeftClick")
{
leftClickButtonSet.insert(button);
}
else if(operation == "mouseRightClick")
{
rightClickButtonSet.insert(button);
}
else
{
EShortcut shortcut = GH.shortcuts().findShortcut(operation);
if(shortcut == EShortcut::NONE)
logGlobal->error("Shortcut %s in joystick config key %s is invalid.", operation, key);
else
shortcuts.push_back(shortcut);
}
}
if(!shortcuts.empty())
buttonShortcutsMap.emplace(button, std::move(shortcuts));
if(!shortcuts.empty())
buttonShortcutsMap.emplace(button, std::move(shortcuts));
}
const AxisType & GameControllerConfig::getLeftAxisType()
{
return leftAxisType;
return leftAxisType;
}
const AxisType & GameControllerConfig::getRightAxisType()
{
return rightAxisType;
return rightAxisType;
}
std::vector<std::string> GameControllerConfig::getOperations(const std::string & key, const JsonNode & value)
{
std::vector<std::string> operations;
if(value.isString())
{
operations.push_back(value.String());
}
else if(value.isVector())
{
for(auto const & entryVector : value.Vector())
{
if(!entryVector.isString())
logGlobal->error("The vector of joystick config key %s can not contain non-string element.", key);
else
operations.push_back(entryVector.String());
}
}
else
{
logGlobal->error("The value of joystick config key %s should be string or string vector.", key);
}
return operations;
std::vector<std::string> operations;
if(value.isString())
{
operations.push_back(value.String());
}
else if(value.isVector())
{
for(auto const & entryVector : value.Vector())
{
if(!entryVector.isString())
logGlobal->error("The vector of joystick config key %s can not contain non-string element.", key);
else
operations.push_back(entryVector.String());
}
}
else
{
logGlobal->error("The value of joystick config key %s should be string or string vector.", key);
}
return operations;
}
bool GameControllerConfig::isLeftClickButton(int buttonValue)
{
SDL_GameControllerButton button = static_cast<SDL_GameControllerButton>(buttonValue);
return leftClickButtonSet.find(button) != leftClickButtonSet.end();
SDL_GameControllerButton button = static_cast<SDL_GameControllerButton>(buttonValue);
return leftClickButtonSet.find(button) != leftClickButtonSet.end();
}
bool GameControllerConfig::isRightClickButton(int buttonValue)
{
SDL_GameControllerButton button = static_cast<SDL_GameControllerButton>(buttonValue);
return rightClickButtonSet.find(button) != rightClickButtonSet.end();
SDL_GameControllerButton button = static_cast<SDL_GameControllerButton>(buttonValue);
return rightClickButtonSet.find(button) != rightClickButtonSet.end();
}
bool GameControllerConfig::isShortcutsButton(int buttonValue)
{
SDL_GameControllerButton button = static_cast<SDL_GameControllerButton>(buttonValue);
return buttonShortcutsMap.find(button) != buttonShortcutsMap.end();
SDL_GameControllerButton button = static_cast<SDL_GameControllerButton>(buttonValue);
return buttonShortcutsMap.find(button) != buttonShortcutsMap.end();
}
const std::vector<EShortcut> & GameControllerConfig::getButtonShortcuts(int buttonValue)
{
SDL_GameControllerButton button = static_cast<SDL_GameControllerButton>(buttonValue);
auto it = buttonShortcutsMap.find(button);
if(it != buttonShortcutsMap.end())
return it->second;
static std::vector<EShortcut> emptyVec;
return emptyVec;
SDL_GameControllerButton button = static_cast<SDL_GameControllerButton>(buttonValue);
auto it = buttonShortcutsMap.find(button);
if(it != buttonShortcutsMap.end())
return it->second;
static std::vector<EShortcut> emptyVec;
return emptyVec;
}
bool GameControllerConfig::isLeftClickTrigger(int axisValue)
{
SDL_GameControllerAxis axis = static_cast<SDL_GameControllerAxis>(axisValue);
return leftClickTriggerSet.find(axis) != leftClickTriggerSet.end();
SDL_GameControllerAxis axis = static_cast<SDL_GameControllerAxis>(axisValue);
return leftClickTriggerSet.find(axis) != leftClickTriggerSet.end();
}
bool GameControllerConfig::isRightClickTrigger(int axisValue)
{
SDL_GameControllerAxis axis = static_cast<SDL_GameControllerAxis>(axisValue);
return rightClickTriggerSet.find(axis) != rightClickTriggerSet.end();
SDL_GameControllerAxis axis = static_cast<SDL_GameControllerAxis>(axisValue);
return rightClickTriggerSet.find(axis) != rightClickTriggerSet.end();
}
bool GameControllerConfig::isShortcutsTrigger(int axisValue)
{
SDL_GameControllerAxis axis = static_cast<SDL_GameControllerAxis>(axisValue);
return triggerShortcutsMap.find(axis) != triggerShortcutsMap.end();
SDL_GameControllerAxis axis = static_cast<SDL_GameControllerAxis>(axisValue);
return triggerShortcutsMap.find(axis) != triggerShortcutsMap.end();
}
const std::vector<EShortcut> & GameControllerConfig::getTriggerShortcuts(int axisValue)
{
SDL_GameControllerAxis axis = static_cast<SDL_GameControllerAxis>(axisValue);
auto it = triggerShortcutsMap.find(axis);
if(it != triggerShortcutsMap.end())
return it->second;
static std::vector<EShortcut> emptyVec;
return emptyVec;
SDL_GameControllerAxis axis = static_cast<SDL_GameControllerAxis>(axisValue);
auto it = triggerShortcutsMap.find(axis);
if(it != triggerShortcutsMap.end())
return it->second;
static std::vector<EShortcut> emptyVec;
return emptyVec;
}

View File

@ -17,43 +17,43 @@
enum AxisType
{
CURSOR_MOTION,
MAP_SCROLL,
NONE
CURSOR_MOTION,
MAP_SCROLL,
NONE
};
class GameControllerConfig {
using ButtonShortcutsMap = std::map<SDL_GameControllerButton, std::vector<EShortcut> >;
using TriggerShortcutsMap = std::map<SDL_GameControllerAxis, std::vector<EShortcut> >;
ButtonShortcutsMap buttonShortcutsMap;
TriggerShortcutsMap triggerShortcutsMap;
std::set<SDL_GameControllerButton> leftClickButtonSet;
std::set<SDL_GameControllerButton> rightClickButtonSet;
std::set<SDL_GameControllerAxis> leftClickTriggerSet;
std::set<SDL_GameControllerAxis> rightClickTriggerSet;
AxisType leftAxisType;
AxisType rightAxisType;
using ButtonShortcutsMap = std::map<SDL_GameControllerButton, std::vector<EShortcut> >;
using TriggerShortcutsMap = std::map<SDL_GameControllerAxis, std::vector<EShortcut> >;
ButtonShortcutsMap buttonShortcutsMap;
TriggerShortcutsMap triggerShortcutsMap;
std::set<SDL_GameControllerButton> leftClickButtonSet;
std::set<SDL_GameControllerButton> rightClickButtonSet;
std::set<SDL_GameControllerAxis> leftClickTriggerSet;
std::set<SDL_GameControllerAxis> rightClickTriggerSet;
AxisType leftAxisType;
AxisType rightAxisType;
void load();
std::vector<std::string> getOperations(const std::string & key, const JsonNode & value);
AxisType parseAxis(const std::string & key, const JsonNode & value);
void parseTrigger(const std::string & key, const JsonNode & value);
void parseButton(const std::string & key, const JsonNode & value);
void load();
std::vector<std::string> getOperations(const std::string & key, const JsonNode & value);
AxisType parseAxis(const std::string & key, const JsonNode & value);
void parseTrigger(const std::string & key, const JsonNode & value);
void parseButton(const std::string & key, const JsonNode & value);
public:
GameControllerConfig();
~GameControllerConfig() = default;
GameControllerConfig();
~GameControllerConfig() = default;
const AxisType & getLeftAxisType();
const AxisType & getRightAxisType();
const AxisType & getLeftAxisType();
const AxisType & getRightAxisType();
bool isLeftClickButton(int buttonValue);
bool isRightClickButton(int buttonValue);
bool isShortcutsButton(int buttonValue);
const std::vector<EShortcut> & getButtonShortcuts(int buttonValue);
bool isLeftClickButton(int buttonValue);
bool isRightClickButton(int buttonValue);
bool isShortcutsButton(int buttonValue);
const std::vector<EShortcut> & getButtonShortcuts(int buttonValue);
bool isLeftClickTrigger(int axisValue);
bool isRightClickTrigger(int axisValue);
bool isShortcutsTrigger(int axisValue);
const std::vector<EShortcut> & getTriggerShortcuts(int axisValue);
bool isLeftClickTrigger(int axisValue);
bool isRightClickTrigger(int axisValue);
bool isShortcutsTrigger(int axisValue);
const std::vector<EShortcut> & getTriggerShortcuts(int axisValue);
};

View File

@ -37,7 +37,7 @@ InputHandler::InputHandler()
, keyboardHandler(std::make_unique<InputSourceKeyboard>())
, fingerHandler(std::make_unique<InputSourceTouch>())
, textHandler(std::make_unique<InputSourceText>())
, gameControllerHandler(std::make_unique<InputSourceGameController>())
, gameControllerHandler(std::make_unique<InputSourceGameController>())
{
}
@ -71,12 +71,12 @@ void InputHandler::handleCurrentEvent(const SDL_Event & current)
return fingerHandler->handleEventFingerDown(current.tfinger);
case SDL_FINGERUP:
return fingerHandler->handleEventFingerUp(current.tfinger);
case SDL_CONTROLLERAXISMOTION:
return gameControllerHandler->handleEventAxisMotion(current.caxis);
case SDL_CONTROLLERBUTTONDOWN:
return gameControllerHandler->handleEventButtonDown(current.cbutton);
case SDL_CONTROLLERBUTTONUP:
return gameControllerHandler->handleEventButtonUp(current.cbutton);
case SDL_CONTROLLERAXISMOTION:
return gameControllerHandler->handleEventAxisMotion(current.caxis);
case SDL_CONTROLLERBUTTONDOWN:
return gameControllerHandler->handleEventButtonDown(current.cbutton);
case SDL_CONTROLLERBUTTONUP:
return gameControllerHandler->handleEventButtonUp(current.cbutton);
}
}
@ -96,7 +96,7 @@ void InputHandler::processEvents()
for(const auto & currentEvent : eventsToProcess)
handleCurrentEvent(currentEvent);
gameControllerHandler->handleUpdate();
gameControllerHandler->handleUpdate();
fingerHandler->handleUpdate();
}
@ -112,7 +112,7 @@ bool InputHandler::ignoreEventsUntilInput()
case SDL_MOUSEBUTTONDOWN:
case SDL_FINGERDOWN:
case SDL_KEYDOWN:
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONDOWN:
inputFound = true;
}
}
@ -169,15 +169,15 @@ void InputHandler::preprocessEvent(const SDL_Event & ev)
else if(ev.type == SDL_WINDOWEVENT)
{
switch (ev.window.event) {
case SDL_WINDOWEVENT_RESTORED:
case SDL_WINDOWEVENT_RESTORED:
#ifndef VCMI_IOS
{
boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
GH.onScreenResize(false);
}
#endif
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
{
boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
if(settings["general"]["audioMuteFocus"].Bool()) {
@ -185,8 +185,8 @@ void InputHandler::preprocessEvent(const SDL_Event & ev)
CCS->soundh->setVolume(settings["general"]["sound"].Integer());
}
}
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
{
boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
if(settings["general"]["audioMuteFocus"].Bool()) {
@ -194,7 +194,7 @@ void InputHandler::preprocessEvent(const SDL_Event & ev)
CCS->soundh->setVolume(0);
}
}
break;
break;
}
return;
}
@ -206,21 +206,21 @@ void InputHandler::preprocessEvent(const SDL_Event & ev)
NotificationHandler::handleSdlEvent(ev);
}
}
else if(ev.type == SDL_CONTROLLERDEVICEADDED)
{
gameControllerHandler->handleEventDeviceAdded(ev.cdevice);
return;
}
else if(ev.type == SDL_CONTROLLERDEVICEREMOVED)
{
gameControllerHandler->handleEventDeviceRemoved(ev.cdevice);
return;
}
else if(ev.type == SDL_CONTROLLERDEVICEREMAPPED)
{
gameControllerHandler->handleEventDeviceRemapped(ev.cdevice);
return;
}
else if(ev.type == SDL_CONTROLLERDEVICEADDED)
{
gameControllerHandler->handleEventDeviceAdded(ev.cdevice);
return;
}
else if(ev.type == SDL_CONTROLLERDEVICEREMOVED)
{
gameControllerHandler->handleEventDeviceRemoved(ev.cdevice);
return;
}
else if(ev.type == SDL_CONTROLLERDEVICEREMAPPED)
{
gameControllerHandler->handleEventDeviceRemapped(ev.cdevice);
return;
}
//preprocessing
if(ev.type == SDL_MOUSEMOTION)

View File

@ -40,7 +40,7 @@ class InputHandler
std::unique_ptr<InputSourceKeyboard> keyboardHandler;
std::unique_ptr<InputSourceTouch> fingerHandler;
std::unique_ptr<InputSourceText> textHandler;
std::unique_ptr<InputSourceGameController> gameControllerHandler;
std::unique_ptr<InputSourceGameController> gameControllerHandler;
public:
InputHandler();
@ -86,5 +86,4 @@ public:
bool isKeyboardAltDown() const;
bool isKeyboardCtrlDown() const;
bool isKeyboardShiftDown() const;
};

View File

@ -22,333 +22,333 @@
void InputSourceGameController::gameControllerDeleter(SDL_GameController * gameController)
{
if(gameController)
SDL_GameControllerClose(gameController);
if(gameController)
SDL_GameControllerClose(gameController);
}
InputSourceGameController::InputSourceGameController():
lastCheckTime(0),
cursorAxisValueX(0),
cursorAxisValueY(0),
cursorPlanDisX(0.0),
cursorPlanDisY(0.0),
scrollAxisMoved(false),
scrollStart(Point(0,0)),
scrollCurrent(Point(0,0)),
scrollAxisValueX(0),
scrollAxisValueY(0),
scrollPlanDisX(0.0),
scrollPlanDisY(0.0)
lastCheckTime(0),
cursorAxisValueX(0),
cursorAxisValueY(0),
cursorPlanDisX(0.0),
cursorPlanDisY(0.0),
scrollAxisMoved(false),
scrollStart(Point(0,0)),
scrollCurrent(Point(0,0)),
scrollAxisValueX(0),
scrollAxisValueY(0),
scrollPlanDisX(0.0),
scrollPlanDisY(0.0)
{
tryOpenAllGameControllers();
tryOpenAllGameControllers();
}
void InputSourceGameController::tryOpenAllGameControllers()
{
for(int i = 0; i < SDL_NumJoysticks(); ++i)
if(SDL_IsGameController(i))
openGameController(i);
else
logGlobal->warn("Joystick %d is an unsupported game controller!", i);
for(int i = 0; i < SDL_NumJoysticks(); ++i)
if(SDL_IsGameController(i))
openGameController(i);
else
logGlobal->warn("Joystick %d is an unsupported game controller!", i);
}
void InputSourceGameController::openGameController(int index)
{
SDL_GameController * controller = SDL_GameControllerOpen(index);
if(!controller)
{
logGlobal->error("Fail to open game controller %d!", index);
return;
}
GameControllerPtr controllerPtr(controller, gameControllerDeleter);
SDL_GameController * controller = SDL_GameControllerOpen(index);
if(!controller)
{
logGlobal->error("Fail to open game controller %d!", index);
return;
}
GameControllerPtr controllerPtr(controller, gameControllerDeleter);
// Need to save joystick index for event. Joystick index may not be equal to index sometimes.
int joystickIndex = getJoystickIndex(controllerPtr.get());
if(joystickIndex < 0)
{
logGlobal->error("Fail to get joystick index of game controller %d!", index);
return;
}
// Need to save joystick index for event. Joystick index may not be equal to index sometimes.
int joystickIndex = getJoystickIndex(controllerPtr.get());
if(joystickIndex < 0)
{
logGlobal->error("Fail to get joystick index of game controller %d!", index);
return;
}
if(gameControllerMap.find(joystickIndex) != gameControllerMap.end())
{
logGlobal->warn("Game controller with joystick index %d is already opened.", joystickIndex);
return;
}
if(gameControllerMap.find(joystickIndex) != gameControllerMap.end())
{
logGlobal->warn("Game controller with joystick index %d is already opened.", joystickIndex);
return;
}
gameControllerMap.emplace(joystickIndex, std::move(controllerPtr));
gameControllerMap.emplace(joystickIndex, std::move(controllerPtr));
}
int InputSourceGameController::getJoystickIndex(SDL_GameController * controller)
{
SDL_Joystick* joystick = SDL_GameControllerGetJoystick(controller);
if(!joystick)
return -1;
SDL_Joystick* joystick = SDL_GameControllerGetJoystick(controller);
if(!joystick)
return -1;
SDL_JoystickID instanceID = SDL_JoystickInstanceID(joystick);
if(instanceID < 0)
return -1;
return (int)instanceID;
SDL_JoystickID instanceID = SDL_JoystickInstanceID(joystick);
if(instanceID < 0)
return -1;
return (int)instanceID;
}
void InputSourceGameController::handleEventDeviceAdded(const SDL_ControllerDeviceEvent & device)
{
if(gameControllerMap.find(device.which) != gameControllerMap.end())
{
logGlobal->warn("Game controller %d is already opened.", device.which);
return;
}
openGameController(device.which);
if(gameControllerMap.find(device.which) != gameControllerMap.end())
{
logGlobal->warn("Game controller %d is already opened.", device.which);
return;
}
openGameController(device.which);
}
void InputSourceGameController::handleEventDeviceRemoved(const SDL_ControllerDeviceEvent & device)
{
if(gameControllerMap.find(device.which) == gameControllerMap.end())
{
logGlobal->warn("Game controller %d is not opened before.", device.which);
return;
}
gameControllerMap.erase(device.which);
if(gameControllerMap.find(device.which) == gameControllerMap.end())
{
logGlobal->warn("Game controller %d is not opened before.", device.which);
return;
}
gameControllerMap.erase(device.which);
}
void InputSourceGameController::handleEventDeviceRemapped(const SDL_ControllerDeviceEvent & device)
{
if(gameControllerMap.find(device.which) == gameControllerMap.end())
{
logGlobal->warn("Game controller %d is not opened.", device.which);
return;
}
gameControllerMap.erase(device.which);
openGameController(device.which);
if(gameControllerMap.find(device.which) == gameControllerMap.end())
{
logGlobal->warn("Game controller %d is not opened.", device.which);
return;
}
gameControllerMap.erase(device.which);
openGameController(device.which);
}
int InputSourceGameController::getRealAxisValue(int value)
{
if(value < AXIS_DEAD_ZOOM && value > -AXIS_DEAD_ZOOM)
return 0;
if(value > AXIS_MAX_ZOOM)
return AXIS_MAX_ZOOM;
if(value < -AXIS_MAX_ZOOM)
return -AXIS_MAX_ZOOM;
int base = value > 0 ? AXIS_DEAD_ZOOM: -AXIS_DEAD_ZOOM;
return (value - base) * AXIS_MAX_ZOOM / (AXIS_MAX_ZOOM - AXIS_DEAD_ZOOM);
if(value < AXIS_DEAD_ZOOM && value > -AXIS_DEAD_ZOOM)
return 0;
if(value > AXIS_MAX_ZOOM)
return AXIS_MAX_ZOOM;
if(value < -AXIS_MAX_ZOOM)
return -AXIS_MAX_ZOOM;
int base = value > 0 ? AXIS_DEAD_ZOOM: -AXIS_DEAD_ZOOM;
return (value - base) * AXIS_MAX_ZOOM / (AXIS_MAX_ZOOM - AXIS_DEAD_ZOOM);
}
void InputSourceGameController::dispatchTriggerShortcuts(const std::vector<EShortcut> & shortcutsVector, int axisValue)
{
if(axisValue >= TRIGGER_PRESS_THRESHOLD)
GH.events().dispatchShortcutPressed(shortcutsVector);
else
GH.events().dispatchShortcutReleased(shortcutsVector);
if(axisValue >= TRIGGER_PRESS_THRESHOLD)
GH.events().dispatchShortcutPressed(shortcutsVector);
else
GH.events().dispatchShortcutReleased(shortcutsVector);
}
void InputSourceGameController::dispatchTriggerLeftClick(int axisValue)
{
const Point & position = GH.input().getCursorPosition();
if(axisValue >= TRIGGER_PRESS_THRESHOLD)
GH.events().dispatchMouseLeftButtonPressed(position, 0);
else
GH.events().dispatchMouseLeftButtonReleased(position, 0);
const Point & position = GH.input().getCursorPosition();
if(axisValue >= TRIGGER_PRESS_THRESHOLD)
GH.events().dispatchMouseLeftButtonPressed(position, 0);
else
GH.events().dispatchMouseLeftButtonReleased(position, 0);
}
void InputSourceGameController::dispatchTriggerRightClick(int axisValue)
{
const Point & position = GH.input().getCursorPosition();
if(axisValue >= TRIGGER_PRESS_THRESHOLD)
GH.events().dispatchShowPopup(position, 0);
else
GH.events().dispatchClosePopup(position);
const Point & position = GH.input().getCursorPosition();
if(axisValue >= TRIGGER_PRESS_THRESHOLD)
GH.events().dispatchShowPopup(position, 0);
else
GH.events().dispatchClosePopup(position);
}
void InputSourceGameController::handleEventAxisMotion(const SDL_ControllerAxisEvent & axis)
{
tryToConvertCursor();
if(axis.axis == SDL_CONTROLLER_AXIS_LEFTX)
{
if(config.getLeftAxisType() == AxisType::CURSOR_MOTION)
cursorAxisValueX = getRealAxisValue(axis.value);
else if(config.getLeftAxisType() == AxisType::MAP_SCROLL)
scrollAxisValueX = getRealAxisValue(axis.value);
}
else if(axis.axis == SDL_CONTROLLER_AXIS_LEFTY)
{
if(config.getLeftAxisType() == AxisType::CURSOR_MOTION)
cursorAxisValueY = getRealAxisValue(axis.value);
else if(config.getLeftAxisType() == AxisType::MAP_SCROLL)
scrollAxisValueY = getRealAxisValue(axis.value);
}
if(axis.axis == SDL_CONTROLLER_AXIS_RIGHTX)
{
if(config.getRightAxisType() == AxisType::CURSOR_MOTION)
cursorAxisValueX = getRealAxisValue(axis.value);
else if(config.getRightAxisType() == AxisType::MAP_SCROLL)
scrollAxisValueX = getRealAxisValue(axis.value);
}
else if(axis.axis == SDL_CONTROLLER_AXIS_RIGHTY)
{
if(config.getRightAxisType() == AxisType::CURSOR_MOTION)
cursorAxisValueY = getRealAxisValue(axis.value);
else if(config.getRightAxisType() == AxisType::MAP_SCROLL)
scrollAxisValueY = getRealAxisValue(axis.value);
}
else if(config.isLeftClickTrigger(axis.axis))
{
dispatchTriggerLeftClick(axis.value);
}
else if(config.isRightClickTrigger(axis.axis))
{
dispatchTriggerRightClick(axis.value);
}
else if(config.isShortcutsTrigger(axis.axis))
{
const auto & shortcutsVector = config.getTriggerShortcuts(axis.axis);
dispatchTriggerShortcuts(shortcutsVector, axis.value);
}
tryToConvertCursor();
if(axis.axis == SDL_CONTROLLER_AXIS_LEFTX)
{
if(config.getLeftAxisType() == AxisType::CURSOR_MOTION)
cursorAxisValueX = getRealAxisValue(axis.value);
else if(config.getLeftAxisType() == AxisType::MAP_SCROLL)
scrollAxisValueX = getRealAxisValue(axis.value);
}
else if(axis.axis == SDL_CONTROLLER_AXIS_LEFTY)
{
if(config.getLeftAxisType() == AxisType::CURSOR_MOTION)
cursorAxisValueY = getRealAxisValue(axis.value);
else if(config.getLeftAxisType() == AxisType::MAP_SCROLL)
scrollAxisValueY = getRealAxisValue(axis.value);
}
if(axis.axis == SDL_CONTROLLER_AXIS_RIGHTX)
{
if(config.getRightAxisType() == AxisType::CURSOR_MOTION)
cursorAxisValueX = getRealAxisValue(axis.value);
else if(config.getRightAxisType() == AxisType::MAP_SCROLL)
scrollAxisValueX = getRealAxisValue(axis.value);
}
else if(axis.axis == SDL_CONTROLLER_AXIS_RIGHTY)
{
if(config.getRightAxisType() == AxisType::CURSOR_MOTION)
cursorAxisValueY = getRealAxisValue(axis.value);
else if(config.getRightAxisType() == AxisType::MAP_SCROLL)
scrollAxisValueY = getRealAxisValue(axis.value);
}
else if(config.isLeftClickTrigger(axis.axis))
{
dispatchTriggerLeftClick(axis.value);
}
else if(config.isRightClickTrigger(axis.axis))
{
dispatchTriggerRightClick(axis.value);
}
else if(config.isShortcutsTrigger(axis.axis))
{
const auto & shortcutsVector = config.getTriggerShortcuts(axis.axis);
dispatchTriggerShortcuts(shortcutsVector, axis.value);
}
}
void InputSourceGameController::tryToConvertCursor()
{
if(CCS && CCS->curh && CCS->curh->getShowType() == Cursor::ShowType::HARDWARE)
{
const Point & cursorPosition = CCS->curh->getCursorPosition();
CCS->curh->ChangeCursor(Cursor::ShowType::SOFTWARE);
CCS->curh->cursorMove(cursorPosition.x, cursorPosition.y);
GH.input().setCursorPosition(cursorPosition);
}
if(CCS && CCS->curh && CCS->curh->getShowType() == Cursor::ShowType::HARDWARE)
{
const Point & cursorPosition = CCS->curh->getCursorPosition();
CCS->curh->ChangeCursor(Cursor::ShowType::SOFTWARE);
CCS->curh->cursorMove(cursorPosition.x, cursorPosition.y);
GH.input().setCursorPosition(cursorPosition);
}
}
void InputSourceGameController::handleEventButtonDown(const SDL_ControllerButtonEvent & button)
{
const Point & position = GH.input().getCursorPosition();
const Point & position = GH.input().getCursorPosition();
if(config.isLeftClickButton(button.button))
{
GH.events().dispatchMouseLeftButtonPressed(position, 0);
}
if(config.isLeftClickButton(button.button))
{
GH.events().dispatchMouseLeftButtonPressed(position, 0);
}
if(config.isRightClickButton(button.button))
{
GH.events().dispatchShowPopup(position, 0);
}
if(config.isRightClickButton(button.button))
{
GH.events().dispatchShowPopup(position, 0);
}
if(config.isShortcutsButton(button.button))
{
const auto & shortcutsVector = config.getButtonShortcuts(button.button);
GH.events().dispatchShortcutPressed(shortcutsVector);
}
if(config.isShortcutsButton(button.button))
{
const auto & shortcutsVector = config.getButtonShortcuts(button.button);
GH.events().dispatchShortcutPressed(shortcutsVector);
}
}
void InputSourceGameController::handleEventButtonUp(const SDL_ControllerButtonEvent & button)
{
const Point & position = GH.input().getCursorPosition();
const Point & position = GH.input().getCursorPosition();
if(config.isLeftClickButton(button.button))
{
GH.events().dispatchMouseLeftButtonReleased(position, 0);
}
if(config.isRightClickButton(button.button))
{
GH.events().dispatchClosePopup(position);
}
if(config.isShortcutsButton(button.button))
{
const auto & shortcutsVector = config.getButtonShortcuts(button.button);
GH.events().dispatchShortcutReleased(shortcutsVector);
}
if(config.isLeftClickButton(button.button))
{
GH.events().dispatchMouseLeftButtonReleased(position, 0);
}
if(config.isRightClickButton(button.button))
{
GH.events().dispatchClosePopup(position);
}
if(config.isShortcutsButton(button.button))
{
const auto & shortcutsVector = config.getButtonShortcuts(button.button);
GH.events().dispatchShortcutReleased(shortcutsVector);
}
}
void InputSourceGameController::doCursorMove(int deltaX, int deltaY)
{
if(deltaX == 0 && deltaY == 0)
return;
const Point & screenSize = GH.screenDimensions();
const Point & cursorPosition = GH.getCursorPosition();
int newX = std::min(std::max(cursorPosition.x + deltaX, 0), screenSize.x);
int newY = std::min(std::max(cursorPosition.y + deltaY, 0), screenSize.y);
Point targetPosition{newX, newY};
GH.input().setCursorPosition(targetPosition);
if(CCS && CCS->curh)
CCS->curh->cursorMove(GH.getCursorPosition().x, GH.getCursorPosition().y);
if(deltaX == 0 && deltaY == 0)
return;
const Point & screenSize = GH.screenDimensions();
const Point & cursorPosition = GH.getCursorPosition();
int newX = std::min(std::max(cursorPosition.x + deltaX, 0), screenSize.x);
int newY = std::min(std::max(cursorPosition.y + deltaY, 0), screenSize.y);
Point targetPosition{newX, newY};
GH.input().setCursorPosition(targetPosition);
if(CCS && CCS->curh)
CCS->curh->cursorMove(GH.getCursorPosition().x, GH.getCursorPosition().y);
}
int InputSourceGameController::getMoveDis(float planDis)
{
if(planDis >= 0)
return std::floor(planDis);
else
return std::ceil(planDis);
if(planDis >= 0)
return std::floor(planDis);
else
return std::ceil(planDis);
}
void InputSourceGameController::handleUpdate()
{
auto now = std::chrono::high_resolution_clock::now();
auto nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
if (lastCheckTime == 0) {
lastCheckTime = nowMs;
return;
}
auto now = std::chrono::high_resolution_clock::now();
auto nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
if (lastCheckTime == 0) {
lastCheckTime = nowMs;
return;
}
long long deltaTime = nowMs - lastCheckTime;
handleCursorUpdate(deltaTime);
handleScrollUpdate(deltaTime);
lastCheckTime = nowMs;
long long deltaTime = nowMs - lastCheckTime;
handleCursorUpdate(deltaTime);
handleScrollUpdate(deltaTime);
lastCheckTime = nowMs;
}
void InputSourceGameController::handleCursorUpdate(long long deltaTime)
{
if(cursorAxisValueX == 0)
cursorPlanDisX = 0;
else
cursorPlanDisX += ((float)deltaTime / 1000) * ((float)cursorAxisValueX / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
if(cursorAxisValueX == 0)
cursorPlanDisX = 0;
else
cursorPlanDisX += ((float)deltaTime / 1000) * ((float)cursorAxisValueX / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
if(cursorAxisValueY == 0)
cursorPlanDisY = 0;
else
cursorPlanDisY += ((float)deltaTime / 1000) * ((float)cursorAxisValueY / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
if(cursorAxisValueY == 0)
cursorPlanDisY = 0;
else
cursorPlanDisY += ((float)deltaTime / 1000) * ((float)cursorAxisValueY / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
int moveDisX = getMoveDis(cursorPlanDisX);
int moveDisY = getMoveDis(cursorPlanDisY);
cursorPlanDisX -= moveDisX;
cursorPlanDisY -= moveDisY;
doCursorMove(moveDisX, moveDisY);
int moveDisX = getMoveDis(cursorPlanDisX);
int moveDisY = getMoveDis(cursorPlanDisY);
cursorPlanDisX -= moveDisX;
cursorPlanDisY -= moveDisY;
doCursorMove(moveDisX, moveDisY);
}
void InputSourceGameController::handleScrollUpdate(long long deltaTime)
{
if(!scrollAxisMoved && isScrollAxisReleased())
{
return;
}
else if(!scrollAxisMoved && !isScrollAxisReleased())
{
scrollAxisMoved = true;
scrollCurrent = scrollStart = GH.input().getCursorPosition();
GH.events().dispatchGesturePanningStarted(scrollStart);
}
else if(scrollAxisMoved && isScrollAxisReleased())
{
GH.events().dispatchGesturePanningEnded(scrollStart, scrollCurrent);
scrollAxisMoved = false;
scrollPlanDisX = scrollPlanDisY = 0;
return;
}
scrollPlanDisX += ((float)deltaTime / 1000) * ((float)scrollAxisValueX / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
scrollPlanDisY += ((float)deltaTime / 1000) * ((float)scrollAxisValueY / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
int moveDisX = getMoveDis(scrollPlanDisX);
int moveDisY = getMoveDis(scrollPlanDisY);
if(moveDisX != 0 || moveDisY != 0)
{
scrollPlanDisX -= moveDisX;
scrollPlanDisY -= moveDisY;
scrollCurrent.x += moveDisX;
scrollCurrent.y += moveDisY;
Point distance(moveDisX, moveDisY);
GH.events().dispatchGesturePanning(scrollStart, scrollCurrent, distance);
}
if(!scrollAxisMoved && isScrollAxisReleased())
{
return;
}
else if(!scrollAxisMoved && !isScrollAxisReleased())
{
scrollAxisMoved = true;
scrollCurrent = scrollStart = GH.input().getCursorPosition();
GH.events().dispatchGesturePanningStarted(scrollStart);
}
else if(scrollAxisMoved && isScrollAxisReleased())
{
GH.events().dispatchGesturePanningEnded(scrollStart, scrollCurrent);
scrollAxisMoved = false;
scrollPlanDisX = scrollPlanDisY = 0;
return;
}
scrollPlanDisX += ((float)deltaTime / 1000) * ((float)scrollAxisValueX / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
scrollPlanDisY += ((float)deltaTime / 1000) * ((float)scrollAxisValueY / AXIS_MAX_ZOOM) * AXIS_MOVE_SPEED;
int moveDisX = getMoveDis(scrollPlanDisX);
int moveDisY = getMoveDis(scrollPlanDisY);
if(moveDisX != 0 || moveDisY != 0)
{
scrollPlanDisX -= moveDisX;
scrollPlanDisY -= moveDisY;
scrollCurrent.x += moveDisX;
scrollCurrent.y += moveDisY;
Point distance(moveDisX, moveDisY);
GH.events().dispatchGesturePanning(scrollStart, scrollCurrent, distance);
}
}
bool InputSourceGameController::isScrollAxisReleased()
{
return scrollAxisValueX == 0 && scrollAxisValueY == 0;
return scrollAxisValueX == 0 && scrollAxisValueY == 0;
}

View File

@ -27,46 +27,46 @@ const int TRIGGER_PRESS_THRESHOLD = 8000;
/// Class that handles game controller input from SDL events
class InputSourceGameController
{
static void gameControllerDeleter(SDL_GameController * gameController);
using GameControllerPtr = std::unique_ptr<SDL_GameController, decltype(&gameControllerDeleter)>;
static void gameControllerDeleter(SDL_GameController * gameController);
using GameControllerPtr = std::unique_ptr<SDL_GameController, decltype(&gameControllerDeleter)>;
std::map<int, GameControllerPtr> gameControllerMap;
GameControllerConfig config;
long long lastCheckTime;
int cursorAxisValueX;
int cursorAxisValueY;
float cursorPlanDisX;
float cursorPlanDisY;
std::map<int, GameControllerPtr> gameControllerMap;
GameControllerConfig config;
long long lastCheckTime;
int cursorAxisValueX;
int cursorAxisValueY;
float cursorPlanDisX;
float cursorPlanDisY;
bool scrollAxisMoved;
Point scrollStart;
Point scrollCurrent;
int scrollAxisValueX;
int scrollAxisValueY;
float scrollPlanDisX;
float scrollPlanDisY;
bool scrollAxisMoved;
Point scrollStart;
Point scrollCurrent;
int scrollAxisValueX;
int scrollAxisValueY;
float scrollPlanDisX;
float scrollPlanDisY;
void openGameController(int index);
int getJoystickIndex(SDL_GameController * controller);
int getRealAxisValue(int value);
void dispatchTriggerShortcuts(const std::vector<EShortcut> & shortcutsVector, int axisValue);
void dispatchTriggerLeftClick(int axisValue);
void dispatchTriggerRightClick(int axisValue);
void tryToConvertCursor();
void doCursorMove(int deltaX, int deltaY);
int getMoveDis(float planDis);
void handleCursorUpdate(long long deltaTime);
void handleScrollUpdate(long long deltaTime);
bool isScrollAxisReleased();
void openGameController(int index);
int getJoystickIndex(SDL_GameController * controller);
int getRealAxisValue(int value);
void dispatchTriggerShortcuts(const std::vector<EShortcut> & shortcutsVector, int axisValue);
void dispatchTriggerLeftClick(int axisValue);
void dispatchTriggerRightClick(int axisValue);
void tryToConvertCursor();
void doCursorMove(int deltaX, int deltaY);
int getMoveDis(float planDis);
void handleCursorUpdate(long long deltaTime);
void handleScrollUpdate(long long deltaTime);
bool isScrollAxisReleased();
public:
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();
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();
};

View File

@ -57,7 +57,7 @@ CursorHandler::CursorHandler()
cursor->preload();
set(Cursor::Map::POINTER);
showType = dynamic_cast<CursorSoftware *>(cursor.get()) ? Cursor::ShowType::SOFTWARE : Cursor::ShowType::HARDWARE;
showType = dynamic_cast<CursorSoftware *>(cursor.get()) ? Cursor::ShowType::SOFTWARE : Cursor::ShowType::HARDWARE;
}
CursorHandler::~CursorHandler() = default;
@ -293,30 +293,30 @@ void CursorHandler::show()
Cursor::ShowType CursorHandler::getShowType()
{
return showType;
return showType;
}
void CursorHandler::ChangeCursor(Cursor::ShowType showType)
{
if(this->showType == showType)
return;
if(this->showType == showType)
return;
switch(showType)
{
case Cursor::ShowType::SOFTWARE:
cursor.reset(new CursorSoftware());
showType = Cursor::ShowType::SOFTWARE;
cursor->setImage(getCurrentImage(), getPivotOffset());
break;
case Cursor::ShowType::HARDWARE:
cursor.reset(new CursorHardware());
showType = Cursor::ShowType::HARDWARE;
cursor->setImage(getCurrentImage(), getPivotOffset());
break;
}
switch(showType)
{
case Cursor::ShowType::SOFTWARE:
cursor.reset(new CursorSoftware());
showType = Cursor::ShowType::SOFTWARE;
cursor->setImage(getCurrentImage(), getPivotOffset());
break;
case Cursor::ShowType::HARDWARE:
cursor.reset(new CursorHardware());
showType = Cursor::ShowType::HARDWARE;
cursor->setImage(getCurrentImage(), getPivotOffset());
break;
}
}
const Point & CursorHandler::getCursorPosition()
{
return cursor->getCursorPosition();
return cursor->getCursorPosition();
}

View File

@ -25,10 +25,10 @@ namespace Cursor
SPELLBOOK // animated cursor for spellcasting
};
enum class ShowType {
SOFTWARE,
HARDWARE
};
enum class ShowType {
SOFTWARE,
HARDWARE
};
enum class Default {
POINTER = 0,
@ -125,7 +125,7 @@ class CursorHandler final
/// Current cursor
Cursor::Type type;
Cursor::ShowType showType;
Cursor::ShowType showType;
size_t frame;
float frameTime;
Point pos;

View File

@ -153,7 +153,7 @@ EShortcut ShortcutHandler::findShortcut(const std::string & identifier ) const
{"adventureZoomIn", EShortcut::ADVENTURE_ZOOM_IN },
{"adventureZoomOut", EShortcut::ADVENTURE_ZOOM_OUT },
{"adventureZoomReset", EShortcut::ADVENTURE_ZOOM_RESET },
{"battleToggleHeroesStats", EShortcut::BATTLE_TOGGLE_HEROES_STATS},
{"battleToggleHeroesStats", EShortcut::BATTLE_TOGGLE_HEROES_STATS},
{"battleToggleQueue", EShortcut::BATTLE_TOGGLE_QUEUE },
{"battleUseCreatureSpell", EShortcut::BATTLE_USE_CREATURE_SPELL },
{"battleSurrender", EShortcut::BATTLE_SURRENDER },

View File

@ -24,6 +24,6 @@ public:
virtual void setCursorPosition( const Point & newPos ) = 0;
virtual void render() = 0;
virtual void setVisible( bool on) = 0;
virtual const Point & getCursorPosition() = 0;
virtual const Point & getCursorPosition() = 0;
};

View File

@ -44,6 +44,6 @@ public:
/// Window has focus
virtual bool hasFocus() = 0;
/// Get the scale value of screen
virtual void getRenderScale(float & scaleX, float & scaleY) = 0;
/// Get the scale value of screen
virtual void getRenderScale(float & scaleX, float & scaleY) = 0;
};

View File

@ -69,13 +69,13 @@ void CursorHardware::setImage(std::shared_ptr<IImage> image, const Point & pivot
const Point & CursorHardware::getCursorPosition()
{
int mouseX, mouseY;
SDL_GetMouseState(&mouseX, &mouseY);
float scaleX, scaleY;
GH.screenHandler().getRenderScale(scaleX, scaleY);
pos.x = int(mouseX / scaleX);
pos.y = int(mouseY / scaleY);
return pos;
int mouseX, mouseY;
SDL_GetMouseState(&mouseX, &mouseY);
float scaleX, scaleY;
GH.screenHandler().getRenderScale(scaleX, scaleY);
pos.x = int(mouseX / scaleX);
pos.y = int(mouseY / scaleY);
return pos;
}
void CursorHardware::setCursorPosition( const Point & newPos )

View File

@ -33,6 +33,6 @@ public:
void setCursorPosition( const Point & newPos ) override;
void render() override;
void setVisible( bool on) override;
const Point & getCursorPosition() override;
const Point & getCursorPosition() override;
};

View File

@ -83,7 +83,7 @@ void CursorSoftware::setVisible(bool on)
const Point & CursorSoftware::getCursorPosition()
{
return pos;
return pos;
}
CursorSoftware::CursorSoftware():

View File

@ -40,6 +40,6 @@ public:
void setCursorPosition( const Point & newPos ) override;
void render() override;
void setVisible( bool on) override;
const Point & getCursorPosition() override;
const Point & getCursorPosition() override;
};

View File

@ -585,5 +585,5 @@ bool ScreenHandler::hasFocus()
void ScreenHandler::getRenderScale(float & scaleX, float & scaleY)
{
SDL_RenderGetScale(mainRenderer, &scaleX, &scaleY);
SDL_RenderGetScale(mainRenderer, &scaleX, &scaleY);
}

View File

@ -89,8 +89,8 @@ public:
/// Window has focus
bool hasFocus() final;
/// Get the scale value of screen
void getRenderScale(float & scaleX, float & scaleY);
/// Get the scale value of screen
void getRenderScale(float & scaleX, float & scaleY);
std::vector<Point> getSupportedResolutions() const final;
std::vector<Point> getSupportedResolutions(int displayIndex) const;

View File

@ -140,8 +140,7 @@
"joystick": {
"leftaxis": "cursorMotion",
"rightaxis": "mapScroll",
"a": ["globalAccept", "globalReturn", "lobbyBeginStandardGame", "lobbyBeginCampaign", "lobbyLoadGame",
"lobbySaveGame", "adventureViewSelected", "adventureExitWorldView", "battleTacticsEnd"],
"a": ["globalAccept", "globalReturn", "lobbyBeginStandardGame", "lobbyBeginCampaign", "lobbyLoadGame", "lobbySaveGame", "adventureViewSelected", "adventureExitWorldView", "battleTacticsEnd"],
"b": ["globalCancel", "globalReturn", "adventureExitWorldView"],
"x": "mouseLeftClick",
"y": "mouseRightClick",
@ -151,8 +150,7 @@
"righttrigger": ["adventureCastSpell", "battleCastSpell"],
"back": ["gameEndTurn", "battleAutocombatEnd"],
"start": ["globalOptions", "adventureGameOptions"],
"dpup": ["moveUp", "adventureViewWorld", "recruitmentUpgrade", "recruitmentUpgradeAll",
"battleConsoleUp", "recruitmentMax"],
"dpup": ["moveUp", "adventureViewWorld", "recruitmentUpgrade", "recruitmentUpgradeAll", "battleConsoleUp", "recruitmentMax"],
"dpdown": ["moveDown", "adventureKingdomOverview", "battleConsoleDown","recruitmentMin"],
"dpleft": ["moveLeft", "adventureViewScenario"],
"dpright": ["moveRight", "adventureThievesGuild"],