diff --git a/client/eventsSDL/GameControllerConfig.cpp b/client/eventsSDL/GameControllerConfig.cpp index d323d776b..33f799577 100644 --- a/client/eventsSDL/GameControllerConfig.cpp +++ b/client/eventsSDL/GameControllerConfig.cpp @@ -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 operations = getOperations(key, value); - SDL_GameControllerAxis triggerAxis = key == "lefttrigger" ? - SDL_CONTROLLER_AXIS_TRIGGERLEFT : SDL_CONTROLLER_AXIS_TRIGGERRIGHT; - std::vector 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 operations = getOperations(key, value); + SDL_GameControllerAxis triggerAxis = key == "lefttrigger" ? + SDL_CONTROLLER_AXIS_TRIGGERLEFT : SDL_CONTROLLER_AXIS_TRIGGERRIGHT; + std::vector 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 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 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 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 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 GameControllerConfig::getOperations(const std::string & key, const JsonNode & value) { - std::vector 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 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(buttonValue); - return leftClickButtonSet.find(button) != leftClickButtonSet.end(); + SDL_GameControllerButton button = static_cast(buttonValue); + return leftClickButtonSet.find(button) != leftClickButtonSet.end(); } bool GameControllerConfig::isRightClickButton(int buttonValue) { - SDL_GameControllerButton button = static_cast(buttonValue); - return rightClickButtonSet.find(button) != rightClickButtonSet.end(); + SDL_GameControllerButton button = static_cast(buttonValue); + return rightClickButtonSet.find(button) != rightClickButtonSet.end(); } bool GameControllerConfig::isShortcutsButton(int buttonValue) { - SDL_GameControllerButton button = static_cast(buttonValue); - return buttonShortcutsMap.find(button) != buttonShortcutsMap.end(); + SDL_GameControllerButton button = static_cast(buttonValue); + return buttonShortcutsMap.find(button) != buttonShortcutsMap.end(); } const std::vector & GameControllerConfig::getButtonShortcuts(int buttonValue) { - SDL_GameControllerButton button = static_cast(buttonValue); - auto it = buttonShortcutsMap.find(button); - if(it != buttonShortcutsMap.end()) - return it->second; - static std::vector emptyVec; - return emptyVec; + SDL_GameControllerButton button = static_cast(buttonValue); + auto it = buttonShortcutsMap.find(button); + if(it != buttonShortcutsMap.end()) + return it->second; + static std::vector emptyVec; + return emptyVec; } bool GameControllerConfig::isLeftClickTrigger(int axisValue) { - SDL_GameControllerAxis axis = static_cast(axisValue); - return leftClickTriggerSet.find(axis) != leftClickTriggerSet.end(); + SDL_GameControllerAxis axis = static_cast(axisValue); + return leftClickTriggerSet.find(axis) != leftClickTriggerSet.end(); } bool GameControllerConfig::isRightClickTrigger(int axisValue) { - SDL_GameControllerAxis axis = static_cast(axisValue); - return rightClickTriggerSet.find(axis) != rightClickTriggerSet.end(); + SDL_GameControllerAxis axis = static_cast(axisValue); + return rightClickTriggerSet.find(axis) != rightClickTriggerSet.end(); } bool GameControllerConfig::isShortcutsTrigger(int axisValue) { - SDL_GameControllerAxis axis = static_cast(axisValue); - return triggerShortcutsMap.find(axis) != triggerShortcutsMap.end(); + SDL_GameControllerAxis axis = static_cast(axisValue); + return triggerShortcutsMap.find(axis) != triggerShortcutsMap.end(); } const std::vector & GameControllerConfig::getTriggerShortcuts(int axisValue) { - SDL_GameControllerAxis axis = static_cast(axisValue); - auto it = triggerShortcutsMap.find(axis); - if(it != triggerShortcutsMap.end()) - return it->second; - static std::vector emptyVec; - return emptyVec; + SDL_GameControllerAxis axis = static_cast(axisValue); + auto it = triggerShortcutsMap.find(axis); + if(it != triggerShortcutsMap.end()) + return it->second; + static std::vector emptyVec; + return emptyVec; } diff --git a/client/eventsSDL/GameControllerConfig.h b/client/eventsSDL/GameControllerConfig.h index 13fdc1637..76169a2a5 100644 --- a/client/eventsSDL/GameControllerConfig.h +++ b/client/eventsSDL/GameControllerConfig.h @@ -17,43 +17,43 @@ enum AxisType { - CURSOR_MOTION, - MAP_SCROLL, - NONE + CURSOR_MOTION, + MAP_SCROLL, + NONE }; class GameControllerConfig { - using ButtonShortcutsMap = std::map >; - using TriggerShortcutsMap = std::map >; - ButtonShortcutsMap buttonShortcutsMap; - TriggerShortcutsMap triggerShortcutsMap; - std::set leftClickButtonSet; - std::set rightClickButtonSet; - std::set leftClickTriggerSet; - std::set rightClickTriggerSet; - AxisType leftAxisType; - AxisType rightAxisType; + using ButtonShortcutsMap = std::map >; + using TriggerShortcutsMap = std::map >; + ButtonShortcutsMap buttonShortcutsMap; + TriggerShortcutsMap triggerShortcutsMap; + std::set leftClickButtonSet; + std::set rightClickButtonSet; + std::set leftClickTriggerSet; + std::set rightClickTriggerSet; + AxisType leftAxisType; + AxisType rightAxisType; - void load(); - std::vector 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 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 & getButtonShortcuts(int buttonValue); + bool isLeftClickButton(int buttonValue); + bool isRightClickButton(int buttonValue); + bool isShortcutsButton(int buttonValue); + const std::vector & getButtonShortcuts(int buttonValue); - bool isLeftClickTrigger(int axisValue); - bool isRightClickTrigger(int axisValue); - bool isShortcutsTrigger(int axisValue); - const std::vector & getTriggerShortcuts(int axisValue); + bool isLeftClickTrigger(int axisValue); + bool isRightClickTrigger(int axisValue); + bool isShortcutsTrigger(int axisValue); + const std::vector & getTriggerShortcuts(int axisValue); }; diff --git a/client/eventsSDL/InputHandler.cpp b/client/eventsSDL/InputHandler.cpp index ccb4cabb6..fcfcb2886 100644 --- a/client/eventsSDL/InputHandler.cpp +++ b/client/eventsSDL/InputHandler.cpp @@ -37,7 +37,7 @@ InputHandler::InputHandler() , keyboardHandler(std::make_unique()) , fingerHandler(std::make_unique()) , textHandler(std::make_unique()) - , gameControllerHandler(std::make_unique()) + , gameControllerHandler(std::make_unique()) { } @@ -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) diff --git a/client/eventsSDL/InputHandler.h b/client/eventsSDL/InputHandler.h index b1fbf312e..4892f70b7 100644 --- a/client/eventsSDL/InputHandler.h +++ b/client/eventsSDL/InputHandler.h @@ -40,7 +40,7 @@ class InputHandler std::unique_ptr keyboardHandler; std::unique_ptr fingerHandler; std::unique_ptr textHandler; - std::unique_ptr gameControllerHandler; + std::unique_ptr gameControllerHandler; public: InputHandler(); @@ -86,5 +86,4 @@ public: bool isKeyboardAltDown() const; bool isKeyboardCtrlDown() const; bool isKeyboardShiftDown() const; - }; diff --git a/client/eventsSDL/InputSourceGameController.cpp b/client/eventsSDL/InputSourceGameController.cpp index 2f6a5991c..619d92f29 100644 --- a/client/eventsSDL/InputSourceGameController.cpp +++ b/client/eventsSDL/InputSourceGameController.cpp @@ -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 & 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(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(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; } diff --git a/client/eventsSDL/InputSourceGameController.h b/client/eventsSDL/InputSourceGameController.h index 18ad372ce..b70d87afe 100644 --- a/client/eventsSDL/InputSourceGameController.h +++ b/client/eventsSDL/InputSourceGameController.h @@ -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; + static void gameControllerDeleter(SDL_GameController * gameController); + using GameControllerPtr = std::unique_ptr; - std::map gameControllerMap; - GameControllerConfig config; - long long lastCheckTime; - int cursorAxisValueX; - int cursorAxisValueY; - float cursorPlanDisX; - float cursorPlanDisY; + std::map 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 & 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 & 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(); }; diff --git a/client/gui/CursorHandler.cpp b/client/gui/CursorHandler.cpp index 2d529e2cf..6f264f89b 100644 --- a/client/gui/CursorHandler.cpp +++ b/client/gui/CursorHandler.cpp @@ -57,7 +57,7 @@ CursorHandler::CursorHandler() cursor->preload(); set(Cursor::Map::POINTER); - showType = dynamic_cast(cursor.get()) ? Cursor::ShowType::SOFTWARE : Cursor::ShowType::HARDWARE; + showType = dynamic_cast(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(); } diff --git a/client/gui/CursorHandler.h b/client/gui/CursorHandler.h index 2ff7790c1..2c8528e91 100644 --- a/client/gui/CursorHandler.h +++ b/client/gui/CursorHandler.h @@ -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; diff --git a/client/gui/ShortcutHandler.cpp b/client/gui/ShortcutHandler.cpp index cf9825916..3d9738d71 100644 --- a/client/gui/ShortcutHandler.cpp +++ b/client/gui/ShortcutHandler.cpp @@ -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 }, diff --git a/client/render/ICursor.h b/client/render/ICursor.h index 8076c984e..fab509240 100644 --- a/client/render/ICursor.h +++ b/client/render/ICursor.h @@ -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; }; diff --git a/client/render/IScreenHandler.h b/client/render/IScreenHandler.h index 3c2d99357..96381b298 100644 --- a/client/render/IScreenHandler.h +++ b/client/render/IScreenHandler.h @@ -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; }; diff --git a/client/renderSDL/CursorHardware.cpp b/client/renderSDL/CursorHardware.cpp index 8ace8b458..e86a16e38 100644 --- a/client/renderSDL/CursorHardware.cpp +++ b/client/renderSDL/CursorHardware.cpp @@ -69,13 +69,13 @@ void CursorHardware::setImage(std::shared_ptr 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 ) diff --git a/client/renderSDL/CursorHardware.h b/client/renderSDL/CursorHardware.h index 77ae179a4..eac1acf4b 100644 --- a/client/renderSDL/CursorHardware.h +++ b/client/renderSDL/CursorHardware.h @@ -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; }; diff --git a/client/renderSDL/CursorSoftware.cpp b/client/renderSDL/CursorSoftware.cpp index 3647b1dda..a35786759 100644 --- a/client/renderSDL/CursorSoftware.cpp +++ b/client/renderSDL/CursorSoftware.cpp @@ -83,7 +83,7 @@ void CursorSoftware::setVisible(bool on) const Point & CursorSoftware::getCursorPosition() { - return pos; + return pos; } CursorSoftware::CursorSoftware(): diff --git a/client/renderSDL/CursorSoftware.h b/client/renderSDL/CursorSoftware.h index 7af503d33..18bc59f25 100644 --- a/client/renderSDL/CursorSoftware.h +++ b/client/renderSDL/CursorSoftware.h @@ -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; }; diff --git a/client/renderSDL/ScreenHandler.cpp b/client/renderSDL/ScreenHandler.cpp index fa77f8f43..f197d9061 100644 --- a/client/renderSDL/ScreenHandler.cpp +++ b/client/renderSDL/ScreenHandler.cpp @@ -585,5 +585,5 @@ bool ScreenHandler::hasFocus() void ScreenHandler::getRenderScale(float & scaleX, float & scaleY) { - SDL_RenderGetScale(mainRenderer, &scaleX, &scaleY); -} \ No newline at end of file + SDL_RenderGetScale(mainRenderer, &scaleX, &scaleY); +} diff --git a/client/renderSDL/ScreenHandler.h b/client/renderSDL/ScreenHandler.h index ab0ff8894..b1428842c 100644 --- a/client/renderSDL/ScreenHandler.h +++ b/client/renderSDL/ScreenHandler.h @@ -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 getSupportedResolutions() const final; std::vector getSupportedResolutions(int displayIndex) const; diff --git a/config/shortcutsConfig.json b/config/shortcutsConfig.json index 205d7b495..bbaf10567 100644 --- a/config/shortcutsConfig.json +++ b/config/shortcutsConfig.json @@ -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"],