Showing the changes to interface/src/ui/UserInputMapper.cpp (1 of 3 files). Show all
Unified · Split
| @@ -27,6 +27,10 @@ void KeyboardMouseDevice::update() { · 26 unmodified lines | ||
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | +void KeyboardMouseDevice::focusOutEvent(QFocusEvent* event) { | |
| 31 | + _buttonPressedMap.clear(); | |
| 32 | +}; | |
| 33 | + | |
| 30 | 34 | void KeyboardMouseDevice::keyPressEvent(QKeyEvent* event) { |
| 31 | 35 | auto input = makeInput((Qt::Key) event->key()); |
| 32 | 36 | auto result = _buttonPressedMap.insert(input.getChannel()); |
| @@ -114,35 +118,38 @@ void KeyboardMouseDevice::touchUpdateEvent(const QTouchEvent* event) { · 81 unmodified lines | ||
| 114 | 118 | } |
| 115 | 119 | |
| 116 | 120 | UserInputMapper::Input KeyboardMouseDevice::makeInput(Qt::Key code) { |
| 117 | − return UserInputMapper::Input(DEFAULT_DESKTOP_DEVICE, code & KEYBOARD_MASK, UserInputMapper::ChannelType::BUTTON); | |
| 121 | + return UserInputMapper::Input(_deviceID, code & KEYBOARD_MASK, UserInputMapper::ChannelType::BUTTON); | |
| 118 | 122 | } |
| 119 | 123 | UserInputMapper::Input KeyboardMouseDevice::makeInput(Qt::MouseButton code) { |
| 120 | 124 | switch (code) { |
| 121 | 125 | case Qt::LeftButton: |
| 122 | − return UserInputMapper::Input(DEFAULT_DESKTOP_DEVICE, MOUSE_BUTTON_LEFT, UserInputMapper::ChannelType::BUTTON); | |
| 126 | + return UserInputMapper::Input(_deviceID, MOUSE_BUTTON_LEFT, UserInputMapper::ChannelType::BUTTON); | |
| 123 | 127 | case Qt::RightButton: |
| 124 | − return UserInputMapper::Input(DEFAULT_DESKTOP_DEVICE, MOUSE_BUTTON_RIGHT, UserInputMapper::ChannelType::BUTTON); | |
| 128 | + return UserInputMapper::Input(_deviceID, MOUSE_BUTTON_RIGHT, UserInputMapper::ChannelType::BUTTON); | |
| 125 | 129 | case Qt::MiddleButton: |
| 126 | − return UserInputMapper::Input(DEFAULT_DESKTOP_DEVICE, MOUSE_BUTTON_MIDDLE, UserInputMapper::ChannelType::BUTTON); | |
| 130 | + return UserInputMapper::Input(_deviceID, MOUSE_BUTTON_MIDDLE, UserInputMapper::ChannelType::BUTTON); | |
| 127 | 131 | default: |
| 128 | 132 | return UserInputMapper::Input(); |
| 129 | 133 | }; |
| 130 | 134 | } |
| 131 | 135 | UserInputMapper::Input KeyboardMouseDevice::makeInput(KeyboardMouseDevice::MouseAxisChannel axis) { |
| 132 | − return UserInputMapper::Input(DEFAULT_DESKTOP_DEVICE, axis, UserInputMapper::ChannelType::AXIS); | |
| 136 | + return UserInputMapper::Input(_deviceID, axis, UserInputMapper::ChannelType::AXIS); | |
| 133 | 137 | } |
| 134 | 138 | UserInputMapper::Input KeyboardMouseDevice::makeInput(KeyboardMouseDevice::TouchAxisChannel axis) { |
| 135 | − return UserInputMapper::Input(DEFAULT_DESKTOP_DEVICE, axis, UserInputMapper::ChannelType::AXIS); | |
| 139 | + return UserInputMapper::Input(_deviceID, axis, UserInputMapper::ChannelType::AXIS); | |
| 136 | 140 | } |
| 137 | 141 | UserInputMapper::Input KeyboardMouseDevice::makeInput(KeyboardMouseDevice::TouchButtonChannel button) { |
| 138 | − return UserInputMapper::Input(DEFAULT_DESKTOP_DEVICE, button, UserInputMapper::ChannelType::BUTTON); | |
| 142 | + return UserInputMapper::Input(_deviceID, button, UserInputMapper::ChannelType::BUTTON); | |
| 139 | 143 | } |
| 140 | 144 | |
| 141 | 145 | void KeyboardMouseDevice::registerToUserInputMapper(UserInputMapper& mapper) { |
| 146 | + // Grab the current free device ID | |
| 147 | + _deviceID = mapper.getFreeDeviceID(); | |
| 148 | + | |
| 142 | 149 | auto proxy = UserInputMapper::DeviceProxy::Pointer(new UserInputMapper::DeviceProxy()); |
| 143 | 150 | proxy->getButton = [this] (const UserInputMapper::Input& input, int timestamp) -> bool { return this->getButton(input._channel); }; |
| 144 | 151 | proxy->getAxis = [this] (const UserInputMapper::Input& input, int timestamp) -> float { return this->getAxis(input._channel); }; |
| 145 | − mapper.registerDevice(DEFAULT_DESKTOP_DEVICE, proxy); // HARDCODED!, the KeyboardMouseDevice always take the DeviceID = 1 | |
| 152 | + mapper.registerDevice(_deviceID, proxy); | |
| 146 | 153 | } |
| 147 | 154 | |
| 148 | 155 | void KeyboardMouseDevice::assignDefaultInputMapping(UserInputMapper& mapper) { |
| @@ -206,8 +213,8 @@ void KeyboardMouseDevice::assignDefaultInputMapping(UserInputMapper& mapper) { · 57 unmodified lines | ||
| 206 | 213 | mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(TOUCH_AXIS_X_POS), TOUCH_YAW_SPEED); |
| 207 | 214 | |
| 208 | 215 | // Wheel move |
| 209 | − mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(MOUSE_AXIS_WHEEL_Y_NEG), BUTTON_BOOM_SPEED); | |
| 210 | − mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(MOUSE_AXIS_WHEEL_Y_POS), BUTTON_BOOM_SPEED); | |
| 216 | + //mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(MOUSE_AXIS_WHEEL_Y_NEG), BUTTON_BOOM_SPEED); | |
| 217 | + //mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(MOUSE_AXIS_WHEEL_Y_POS), BUTTON_BOOM_SPEED); | |
| 211 | 218 | mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(MOUSE_AXIS_WHEEL_X_NEG), BUTTON_YAW_SPEED); |
| 212 | 219 | mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(MOUSE_AXIS_WHEEL_X_POS), BUTTON_YAW_SPEED); |
| 213 | 220 | |