From 6424af40ec4d5920d25b64971b3992453630390d Mon Sep 17 00:00:00 2001 From: Sven Eden Date: Mon, 1 Feb 2021 19:10:46 +0100 Subject: [PATCH] Enhance speedRatio settings (#270 #290) This commit changes the way the mouse sensitivity works as follows: 1. Turn speedRatio into a QPointF, so we have two floats instead of one integer. 2. Default the y-speedRatio to be x-speedRatio / 2.25, which takes the ultra-wideness of modern phone screens into account. 3. Add new configuration value speedRatioX to allow users to configure an individual X-ratio 4. Add new configuration value speedRatioY to allow users to configure an individual Y-ratio 5. Optimze distance-translation a bit. 6. Add keymaps/FRAG.json using new speedRatioX/speedRatioY for the game "FRAG! Pro Shooter" Bug: #270 Bug: #290 Signed-off-by: Sven Eden --- .../inputconvert/inputconvertgame.cpp | 5 +- .../controller/inputconvert/keymap/keymap.cpp | 33 ++++- .../controller/inputconvert/keymap/keymap.h | 4 +- keymap/FRAG.json | 119 ++++++++++++++++++ 4 files changed, 154 insertions(+), 7 deletions(-) create mode 100644 keymap/FRAG.json diff --git a/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp b/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp index 0624462..5278cfb 100644 --- a/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp +++ b/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp @@ -395,8 +395,9 @@ bool InputConvertGame::processMouseMove(const QMouseEvent *from) } if (!m_ctrlMouseMove.lastPos.isNull() && m_processMouseMove) { - QPointF distance = from->localPos() - m_ctrlMouseMove.lastPos; - distance /= m_keyMap.getMouseMoveMap().data.mouseMove.speedRatio; + QPointF distance_raw{from->localPos() - m_ctrlMouseMove.lastPos}; + QPointF speedRatio {m_keyMap.getMouseMoveMap().data.mouseMove.speedRatio}; + QPointF distance {distance_raw.x() / speedRatio.x(), distance_raw.y() / speedRatio.y()}; mouseMoveStartTouch(from); startMouseMoveTimer(); diff --git a/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp b/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp index 7190901..c33ee01 100644 --- a/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp +++ b/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp @@ -64,11 +64,38 @@ void KeyMap::loadKeyMap(const QString &json) KeyMapNode keyMapNode; keyMapNode.type = KMT_MOUSE_MOVE; - if (!checkItemDouble(mouseMoveMap, "speedRatio")) { - errorString = QString("json error: mouseMoveMap on find speedRatio"); + bool have_speedRatio = false; + + // General speedRatio (for backwards compatibility) + if (checkItemDouble(mouseMoveMap, "speedRatio")) { + float ratio = static_cast(getItemDouble(mouseMoveMap, "speedRatio")); + keyMapNode.data.mouseMove.speedRatio.setX(ratio); + keyMapNode.data.mouseMove.speedRatio.setY(ratio / 2.25f); // Phone screens are often FHD+ + have_speedRatio = true; + } + + // Individual X Ratio + if (checkItemDouble(mouseMoveMap, "speedRatioX")) { + keyMapNode.data.mouseMove.speedRatio.setX(static_cast(getItemDouble(mouseMoveMap, "speedRatioX"))); + have_speedRatio = true; + } + + // Individual Y Ratio + if (checkItemDouble(mouseMoveMap, "speedRatioY")) { + keyMapNode.data.mouseMove.speedRatio.setY(static_cast(getItemDouble(mouseMoveMap, "speedRatioY"))); + have_speedRatio = true; + } + + if (!have_speedRatio) { + errorString = QString("json error: speedRatio setting is missing in mouseMoveMap!"); + goto parseError; + } + + // Sanity check: No ratio must be lower than 0.001 + if ( ( keyMapNode.data.mouseMove.speedRatio.x() < 0.001f ) || ( keyMapNode.data.mouseMove.speedRatio.x() < 0.001f ) ) { + errorString = QString("json error: Minimum speedRatio is 0.001"); goto parseError; } - keyMapNode.data.mouseMove.speedRatio = static_cast(getItemDouble(mouseMoveMap, "speedRatio")); if (!checkItemObject(mouseMoveMap, "startPos")) { errorString = QString("json error: mouseMoveMap on find startPos"); diff --git a/QtScrcpy/device/controller/inputconvert/keymap/keymap.h b/QtScrcpy/device/controller/inputconvert/keymap/keymap.h index 8cf92b7..6b88732 100644 --- a/QtScrcpy/device/controller/inputconvert/keymap/keymap.h +++ b/QtScrcpy/device/controller/inputconvert/keymap/keymap.h @@ -91,8 +91,8 @@ public: } drag; struct { - QPointF startPos = { 0.0, 0.0 }; - int speedRatio = 1; + QPointF startPos = { 0.0, 0.0 }; + QPointF speedRatio = { 1.0, 1.0 }; KeyNode smallEyes; } mouseMove; DATA() {} diff --git a/keymap/FRAG.json b/keymap/FRAG.json new file mode 100644 index 0000000..1150af3 --- /dev/null +++ b/keymap/FRAG.json @@ -0,0 +1,119 @@ +{ + "old-switchKey": "Key_QuoteLeft", + "switchKey": "RightButton", + "mouseMoveMap": { + "startPos": { + "x": 0.5, + "y": 0.5 + }, + "speedRatioX": 3.25, + "speedRatioY": 1.25 + }, + "keyMapNodes": [{ + "comment": "Steering Wheel", + "type": "KMT_STEER_WHEEL", + "centerPos": { + "x": 0.194792, + "y": 0.716484 + }, + "leftOffset": 0.15, + "rightOffset": 0.15, + "upOffset": 0.15, + "downOffset": 0.15, + "leftKey": "Key_A", + "rightKey": "Key_D", + "upKey": "Key_W", + "downKey": "Key_S" + }, + { + "comment": "Activate item under crosshair", + "type": "KMT_CLICK", + "key": "LeftButton", + "pos": { + "x": 0.51875, + "y": 0.496703 + }, + "switchMap": false + }, + { + "comment": "Activate first special skill", + "type": "KMT_CLICK", + "key": "Key_E", + "pos": { + "x": 0.909375, + "y": 0.542857 + }, + "switchMap": false + }, + { + "comment": "Activate Chat", + "type": "KMT_CLICK", + "key": "Key_C", + "pos": { + "x": 0.905208, + "y": 0.254945 + }, + "switchMap": false + }, + { + "comment": "Chat option 1", + "type": "KMT_CLICK", + "key": "Key_1", + "pos": { + "x": 0.875, + "y": 0.523077 + }, + "switchMap": false + }, + { + "comment": "Chat option 2", + "type": "KMT_CLICK", + "key": "Key_2", + "pos": { + "x": 0.875, + "y": 0.606593 + }, + "switchMap": false + }, + { + "comment": "Chat option 3", + "type": "KMT_CLICK", + "key": "Key_3", + "pos": { + "x": 0.875, + "y": 0.685714 + }, + "switchMap": false + }, + { + "comment": "Chat option 4", + "type": "KMT_CLICK", + "key": "Key_4", + "pos": { + "x": 0.875, + "y": 0.756044 + }, + "switchMap": false + }, + { + "comment": "Chat option 5", + "type": "KMT_CLICK", + "key": "Key_5", + "pos": { + "x": 0.875, + "y": 0.832967 + }, + "switchMap": false + }, + { + "comment": "Chat option 6", + "type": "KMT_CLICK", + "key": "Key_6", + "pos": { + "x": 0.875, + "y": 0.911273 + }, + "switchMap": false + } + ] +}