From b00f572e1a278e4eadc7b0947fe867ebdf0658c5 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Mon, 2 Nov 2015 09:21:15 -0800 Subject: [PATCH 1/3] add mouseClicked inputs vs mouseButton inputs, make right-click work without right button drag --- .../resources/controllers/keyboardMouse.json | 19 +++++----- .../src/input-plugins/KeyboardMouseDevice.cpp | 37 +++++++++++++++---- .../src/input-plugins/KeyboardMouseDevice.h | 7 +++- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/interface/resources/controllers/keyboardMouse.json b/interface/resources/controllers/keyboardMouse.json index 8af6b1dc98..f99472b0e9 100644 --- a/interface/resources/controllers/keyboardMouse.json +++ b/interface/resources/controllers/keyboardMouse.json @@ -4,8 +4,8 @@ { "from": "Keyboard.A", "when": "Keyboard.Shift", "to": "Actions.LATERAL_LEFT" }, { "from": "Keyboard.D", "when": "Keyboard.Shift", "to": "Actions.LATERAL_RIGHT" }, - { "from": "Keyboard.A", "when": "Keyboard.RightMouseClick", "to": "Actions.LATERAL_LEFT" }, - { "from": "Keyboard.D", "when": "Keyboard.RightMouseClick", "to": "Actions.LATERAL_RIGHT" }, + { "from": "Keyboard.A", "when": "Keyboard.RightMouseButton", "to": "Actions.LATERAL_LEFT" }, + { "from": "Keyboard.D", "when": "Keyboard.RightMouseButton", "to": "Actions.LATERAL_RIGHT" }, { "from": "Keyboard.E", "when": "Keyboard.Shift", "to": "Actions.BOOM_IN", "filters": [ { "type": "scale", "scale": 0.05 } ] }, { "from": "Keyboard.C", "when": "Keyboard.Shift", "to": "Actions.BOOM_OUT", "filters": [ { "type": "scale", "scale": 0.05 } ] }, { "from": "Keyboard.S", "when": "Keyboard.Shift", "to": "Actions.PITCH_DOWN" }, @@ -13,7 +13,7 @@ { "from": { "makeAxis" : ["Keyboard.MouseMoveLeft", "Keyboard.MouseMoveRight"] }, - "when": [ "Application.InHMD", "Application.ComfortMode", "Keyboard.RightMouseClick" ], + "when": [ "Application.InHMD", "Application.ComfortMode", "Keyboard.RightMouseButton" ], "to": "Actions.StepYaw", "filters": [ @@ -46,7 +46,7 @@ }, { "from": { "makeAxis" : ["Keyboard.MouseMoveLeft", "Keyboard.MouseMoveRight"] }, - "when": "Keyboard.RightMouseClick", + "when": "Keyboard.RightMouseButton", "to": "Actions.Yaw" }, @@ -55,8 +55,8 @@ { "from": "Keyboard.C", "to": "Actions.VERTICAL_DOWN" }, { "from": "Keyboard.E", "to": "Actions.VERTICAL_UP" }, - { "from": "Keyboard.Left", "when": "Keyboard.RightMouseClick", "to": "Actions.LATERAL_LEFT" }, - { "from": "Keyboard.Right", "when": "Keyboard.RightMouseClick", "to": "Actions.LATERAL_RIGHT" }, + { "from": "Keyboard.Left", "when": "Keyboard.RightMouseButton", "to": "Actions.LATERAL_LEFT" }, + { "from": "Keyboard.Right", "when": "Keyboard.RightMouseButton", "to": "Actions.LATERAL_RIGHT" }, { "from": "Keyboard.Left", "when": "Keyboard.Shift", "to": "Actions.LATERAL_LEFT" }, { "from": "Keyboard.Right", "when": "Keyboard.Shift", "to": "Actions.LATERAL_RIGHT" }, { "from": "Keyboard.Down", "when": "Keyboard.Shift", "to": "Actions.PITCH_DOWN" }, @@ -68,8 +68,8 @@ { "from": "Keyboard.PgDown", "to": "Actions.VERTICAL_DOWN" }, { "from": "Keyboard.PgUp", "to": "Actions.VERTICAL_UP" }, - { "from": "Keyboard.MouseMoveUp", "when": "Keyboard.RightMouseClick", "to": "Actions.PITCH_UP" }, - { "from": "Keyboard.MouseMoveDown", "when": "Keyboard.RightMouseClick", "to": "Actions.PITCH_DOWN" }, + { "from": "Keyboard.MouseMoveUp", "when": "Keyboard.RightMouseButton", "to": "Actions.PITCH_UP" }, + { "from": "Keyboard.MouseMoveDown", "when": "Keyboard.RightMouseButton", "to": "Actions.PITCH_DOWN" }, { "from": "Keyboard.TouchpadDown", "to": "Actions.PITCH_DOWN" }, { "from": "Keyboard.TouchpadUp", "to": "Actions.PITCH_UP" }, @@ -81,6 +81,7 @@ { "from": "Keyboard.Space", "to": "Actions.SHIFT" }, { "from": "Keyboard.R", "to": "Actions.ACTION1" }, - { "from": "Keyboard.T", "to": "Actions.ACTION2" } + { "from": "Keyboard.T", "to": "Actions.ACTION2" }, + { "from": "Keyboard.RightMouseClicked", "to": "Actions.ContextMenu" } ] } diff --git a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp index 9cd510c521..42081aca30 100755 --- a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp @@ -59,11 +59,25 @@ void KeyboardMouseDevice::mousePressEvent(QMouseEvent* event, unsigned int devic // key pressed again ? without catching the release event ? } _lastCursor = event->pos(); + _mousePressAt = event->pos(); + + eraseMouseClicked(); } void KeyboardMouseDevice::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { auto input = makeInput((Qt::MouseButton) event->button()); _buttonPressedMap.erase(input.getChannel()); + + if (_mousePressAt == event->pos()) { + auto input = makeInput((Qt::MouseButton) event->button(), true); // clicked + auto result = _buttonPressedMap.insert(input.getChannel()); + } +} + +void KeyboardMouseDevice::eraseMouseClicked() { + _buttonPressedMap.erase(makeInput(Qt::LeftButton, true).getChannel()); + _buttonPressedMap.erase(makeInput(Qt::MiddleButton, true).getChannel()); + _buttonPressedMap.erase(makeInput(Qt::RightButton, true).getChannel()); } void KeyboardMouseDevice::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { @@ -77,6 +91,8 @@ void KeyboardMouseDevice::mouseMoveEvent(QMouseEvent* event, unsigned int device _axisStateMap[makeInput(MOUSE_AXIS_Y_NEG).getChannel()] = (currentMove.y() > 0 ? currentMove.y() : 0.0f); _lastCursor = currentPos; + + eraseMouseClicked(); } void KeyboardMouseDevice::wheelEvent(QWheelEvent* event) { @@ -138,14 +154,17 @@ controller::Input KeyboardMouseDevice::makeInput(Qt::Key code) const { return controller::Input(_deviceID, shortCode, controller::ChannelType::BUTTON); } -controller::Input KeyboardMouseDevice::makeInput(Qt::MouseButton code) const { +controller::Input KeyboardMouseDevice::makeInput(Qt::MouseButton code, bool quickClicked) const { switch (code) { case Qt::LeftButton: - return controller::Input(_deviceID, MOUSE_BUTTON_LEFT, controller::ChannelType::BUTTON); + return controller::Input(_deviceID, quickClicked ? MOUSE_BUTTON_LEFT_QUICK_CLICK : + MOUSE_BUTTON_LEFT, controller::ChannelType::BUTTON); case Qt::RightButton: - return controller::Input(_deviceID, MOUSE_BUTTON_RIGHT, controller::ChannelType::BUTTON); + return controller::Input(_deviceID, quickClicked ? MOUSE_BUTTON_RIGHT_QUICK_CLICK : + MOUSE_BUTTON_RIGHT, controller::ChannelType::BUTTON); case Qt::MiddleButton: - return controller::Input(_deviceID, MOUSE_BUTTON_MIDDLE, controller::ChannelType::BUTTON); + return controller::Input(_deviceID, quickClicked ? MOUSE_BUTTON_MIDDLE_QUICK_CLICK : + MOUSE_BUTTON_MIDDLE, controller::ChannelType::BUTTON); default: return controller::Input(); }; @@ -182,9 +201,13 @@ controller::Input::NamedVector KeyboardMouseDevice::getAvailableInputs() const { availableInputs.append(Input::NamedPair(makeInput(Qt::Key_PageUp), QKeySequence(Qt::Key_PageUp).toString())); availableInputs.append(Input::NamedPair(makeInput(Qt::Key_PageDown), QKeySequence(Qt::Key_PageDown).toString())); - availableInputs.append(Input::NamedPair(makeInput(Qt::LeftButton), "LeftMouseClick")); - availableInputs.append(Input::NamedPair(makeInput(Qt::MiddleButton), "MiddleMouseClick")); - availableInputs.append(Input::NamedPair(makeInput(Qt::RightButton), "RightMouseClick")); + availableInputs.append(Input::NamedPair(makeInput(Qt::LeftButton), "LeftMouseButton")); + availableInputs.append(Input::NamedPair(makeInput(Qt::MiddleButton), "MiddleMouseButton")); + availableInputs.append(Input::NamedPair(makeInput(Qt::RightButton), "RightMouseButton")); + + availableInputs.append(Input::NamedPair(makeInput(Qt::LeftButton, true), "LeftMouseClicked")); + availableInputs.append(Input::NamedPair(makeInput(Qt::MiddleButton, true), "MiddleMouseClicked")); + availableInputs.append(Input::NamedPair(makeInput(Qt::RightButton, true), "RightMouseClicked")); availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_X_POS), "MouseMoveRight")); availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_X_NEG), "MouseMoveLeft")); diff --git a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h index 1ff77d2dce..75a1159b92 100644 --- a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h +++ b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h @@ -37,6 +37,9 @@ public: MOUSE_BUTTON_LEFT = KEYBOARD_LAST + 1, MOUSE_BUTTON_RIGHT, MOUSE_BUTTON_MIDDLE, + MOUSE_BUTTON_LEFT_QUICK_CLICK, + MOUSE_BUTTON_RIGHT_QUICK_CLICK, + MOUSE_BUTTON_MIDDLE_QUICK_CLICK, }; enum MouseAxisChannel { @@ -83,6 +86,7 @@ public: void mouseMoveEvent(QMouseEvent* event, unsigned int deviceID = 0); void mousePressEvent(QMouseEvent* event, unsigned int deviceID = 0); void mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID = 0); + void eraseMouseClicked(); void touchBeginEvent(const QTouchEvent* event); void touchEndEvent(const QTouchEvent* event); @@ -92,7 +96,7 @@ public: // Let's make it easy for Qt because we assume we love Qt forever controller::Input makeInput(Qt::Key code) const; - controller::Input makeInput(Qt::MouseButton code) const; + controller::Input makeInput(Qt::MouseButton code, bool quickClicked = false) const; controller::Input makeInput(MouseAxisChannel axis) const; controller::Input makeInput(TouchAxisChannel axis) const; controller::Input makeInput(TouchButtonChannel button) const; @@ -101,6 +105,7 @@ public: protected: QPoint _lastCursor; + QPoint _mousePressAt; glm::vec2 _lastTouch; bool _isTouching = false; From c3a78ed151a60dd9530765e631f6270ca4e1b887 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Mon, 2 Nov 2015 09:27:35 -0800 Subject: [PATCH 2/3] cleanup --- .../src/input-plugins/KeyboardMouseDevice.cpp | 12 +++++++----- .../src/input-plugins/KeyboardMouseDevice.h | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp index 42081aca30..247e08ada1 100755 --- a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp @@ -68,9 +68,11 @@ void KeyboardMouseDevice::mouseReleaseEvent(QMouseEvent* event, unsigned int dev auto input = makeInput((Qt::MouseButton) event->button()); _buttonPressedMap.erase(input.getChannel()); + // if we pressed and released at the same location, then create a "_CLICKED" input for this button + // we might want to add some small tolerance to this so if you do a small drag it still counts as + // a clicked. if (_mousePressAt == event->pos()) { - auto input = makeInput((Qt::MouseButton) event->button(), true); // clicked - auto result = _buttonPressedMap.insert(input.getChannel()); + _buttonPressedMap.insert(makeInput((Qt::MouseButton) event->button(), true).getChannel()); } } @@ -157,13 +159,13 @@ controller::Input KeyboardMouseDevice::makeInput(Qt::Key code) const { controller::Input KeyboardMouseDevice::makeInput(Qt::MouseButton code, bool quickClicked) const { switch (code) { case Qt::LeftButton: - return controller::Input(_deviceID, quickClicked ? MOUSE_BUTTON_LEFT_QUICK_CLICK : + return controller::Input(_deviceID, quickClicked ? MOUSE_BUTTON_LEFT_CLICKED : MOUSE_BUTTON_LEFT, controller::ChannelType::BUTTON); case Qt::RightButton: - return controller::Input(_deviceID, quickClicked ? MOUSE_BUTTON_RIGHT_QUICK_CLICK : + return controller::Input(_deviceID, quickClicked ? MOUSE_BUTTON_RIGHT_CLICKED : MOUSE_BUTTON_RIGHT, controller::ChannelType::BUTTON); case Qt::MiddleButton: - return controller::Input(_deviceID, quickClicked ? MOUSE_BUTTON_MIDDLE_QUICK_CLICK : + return controller::Input(_deviceID, quickClicked ? MOUSE_BUTTON_MIDDLE_CLICKED : MOUSE_BUTTON_MIDDLE, controller::ChannelType::BUTTON); default: return controller::Input(); diff --git a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h index 75a1159b92..b6681e2ae0 100644 --- a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h +++ b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h @@ -37,9 +37,9 @@ public: MOUSE_BUTTON_LEFT = KEYBOARD_LAST + 1, MOUSE_BUTTON_RIGHT, MOUSE_BUTTON_MIDDLE, - MOUSE_BUTTON_LEFT_QUICK_CLICK, - MOUSE_BUTTON_RIGHT_QUICK_CLICK, - MOUSE_BUTTON_MIDDLE_QUICK_CLICK, + MOUSE_BUTTON_LEFT_CLICKED, + MOUSE_BUTTON_RIGHT_CLICKED, + MOUSE_BUTTON_MIDDLE_CLICKED, }; enum MouseAxisChannel { From d9dd045886fba3a416eda545a74a3be5bb5d55ad Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Mon, 2 Nov 2015 09:29:09 -0800 Subject: [PATCH 3/3] better parameter name --- .../src/input-plugins/KeyboardMouseDevice.cpp | 8 ++++---- .../input-plugins/src/input-plugins/KeyboardMouseDevice.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp index 247e08ada1..2157a3a010 100755 --- a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp @@ -156,16 +156,16 @@ controller::Input KeyboardMouseDevice::makeInput(Qt::Key code) const { return controller::Input(_deviceID, shortCode, controller::ChannelType::BUTTON); } -controller::Input KeyboardMouseDevice::makeInput(Qt::MouseButton code, bool quickClicked) const { +controller::Input KeyboardMouseDevice::makeInput(Qt::MouseButton code, bool clicked) const { switch (code) { case Qt::LeftButton: - return controller::Input(_deviceID, quickClicked ? MOUSE_BUTTON_LEFT_CLICKED : + return controller::Input(_deviceID, clicked ? MOUSE_BUTTON_LEFT_CLICKED : MOUSE_BUTTON_LEFT, controller::ChannelType::BUTTON); case Qt::RightButton: - return controller::Input(_deviceID, quickClicked ? MOUSE_BUTTON_RIGHT_CLICKED : + return controller::Input(_deviceID, clicked ? MOUSE_BUTTON_RIGHT_CLICKED : MOUSE_BUTTON_RIGHT, controller::ChannelType::BUTTON); case Qt::MiddleButton: - return controller::Input(_deviceID, quickClicked ? MOUSE_BUTTON_MIDDLE_CLICKED : + return controller::Input(_deviceID, clicked ? MOUSE_BUTTON_MIDDLE_CLICKED : MOUSE_BUTTON_MIDDLE, controller::ChannelType::BUTTON); default: return controller::Input(); diff --git a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h index b6681e2ae0..5d86821db1 100644 --- a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h +++ b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h @@ -96,7 +96,7 @@ public: // Let's make it easy for Qt because we assume we love Qt forever controller::Input makeInput(Qt::Key code) const; - controller::Input makeInput(Qt::MouseButton code, bool quickClicked = false) const; + controller::Input makeInput(Qt::MouseButton code, bool clicked = false) const; controller::Input makeInput(MouseAxisChannel axis) const; controller::Input makeInput(TouchAxisChannel axis) const; controller::Input makeInput(TouchButtonChannel button) const;