early-access version 2202
This commit is contained in:
@@ -604,56 +604,56 @@ int GRenderWindow::QtKeyToSwitchKey(Qt::Key qt_key) {
|
||||
}
|
||||
}
|
||||
|
||||
int GRenderWindow::QtModifierToSwitchModdifier(quint32 qt_moddifiers) {
|
||||
int moddifier = 0;
|
||||
int GRenderWindow::QtModifierToSwitchModifier(quint32 qt_modifiers) {
|
||||
int modifier = 0;
|
||||
// The values are obtained through testing, Qt doesn't seem to provide a proper enum
|
||||
if ((qt_moddifiers & 0x1) != 0) {
|
||||
moddifier |= 1 << Settings::NativeKeyboard::LeftShift;
|
||||
if ((qt_modifiers & 0x1) != 0) {
|
||||
modifier |= 1 << Settings::NativeKeyboard::LeftShift;
|
||||
}
|
||||
if ((qt_moddifiers & 0x2) != 0) {
|
||||
moddifier |= 1 << Settings::NativeKeyboard::LeftControl;
|
||||
if ((qt_modifiers & 0x2) != 0) {
|
||||
modifier |= 1 << Settings::NativeKeyboard::LeftControl;
|
||||
}
|
||||
if ((qt_moddifiers & 0x4) != 0) {
|
||||
moddifier |= 1 << Settings::NativeKeyboard::LeftAlt;
|
||||
if ((qt_modifiers & 0x4) != 0) {
|
||||
modifier |= 1 << Settings::NativeKeyboard::LeftAlt;
|
||||
}
|
||||
if ((qt_moddifiers & 0x08) != 0) {
|
||||
moddifier |= 1 << Settings::NativeKeyboard::LeftMeta;
|
||||
if ((qt_modifiers & 0x08) != 0) {
|
||||
modifier |= 1 << Settings::NativeKeyboard::LeftMeta;
|
||||
}
|
||||
if ((qt_moddifiers & 0x10) != 0) {
|
||||
moddifier |= 1 << Settings::NativeKeyboard::RightShift;
|
||||
if ((qt_modifiers & 0x10) != 0) {
|
||||
modifier |= 1 << Settings::NativeKeyboard::RightShift;
|
||||
}
|
||||
if ((qt_moddifiers & 0x20) != 0) {
|
||||
moddifier |= 1 << Settings::NativeKeyboard::RightControl;
|
||||
if ((qt_modifiers & 0x20) != 0) {
|
||||
modifier |= 1 << Settings::NativeKeyboard::RightControl;
|
||||
}
|
||||
if ((qt_moddifiers & 0x40) != 0) {
|
||||
moddifier |= 1 << Settings::NativeKeyboard::RightAlt;
|
||||
if ((qt_modifiers & 0x40) != 0) {
|
||||
modifier |= 1 << Settings::NativeKeyboard::RightAlt;
|
||||
}
|
||||
if ((qt_moddifiers & 0x80) != 0) {
|
||||
moddifier |= 1 << Settings::NativeKeyboard::RightMeta;
|
||||
if ((qt_modifiers & 0x80) != 0) {
|
||||
modifier |= 1 << Settings::NativeKeyboard::RightMeta;
|
||||
}
|
||||
if ((qt_moddifiers & 0x100) != 0) {
|
||||
moddifier |= 1 << Settings::NativeKeyboard::CapsLock;
|
||||
if ((qt_modifiers & 0x100) != 0) {
|
||||
modifier |= 1 << Settings::NativeKeyboard::CapsLock;
|
||||
}
|
||||
if ((qt_moddifiers & 0x200) != 0) {
|
||||
moddifier |= 1 << Settings::NativeKeyboard::NumLock;
|
||||
if ((qt_modifiers & 0x200) != 0) {
|
||||
modifier |= 1 << Settings::NativeKeyboard::NumLock;
|
||||
}
|
||||
// Verify the last two keys
|
||||
if ((qt_moddifiers & 0x400) != 0) {
|
||||
moddifier |= 1 << Settings::NativeKeyboard::Katakana;
|
||||
if ((qt_modifiers & 0x400) != 0) {
|
||||
modifier |= 1 << Settings::NativeKeyboard::Katakana;
|
||||
}
|
||||
if ((qt_moddifiers & 0x800) != 0) {
|
||||
moddifier |= 1 << Settings::NativeKeyboard::Hiragana;
|
||||
if ((qt_modifiers & 0x800) != 0) {
|
||||
modifier |= 1 << Settings::NativeKeyboard::Hiragana;
|
||||
}
|
||||
return moddifier;
|
||||
return modifier;
|
||||
}
|
||||
|
||||
void GRenderWindow::keyPressEvent(QKeyEvent* event) {
|
||||
if (!event->isAutoRepeat()) {
|
||||
const auto moddifier = QtModifierToSwitchModdifier(event->nativeModifiers());
|
||||
const auto modifier = QtModifierToSwitchModifier(event->nativeModifiers());
|
||||
// Replace event->key() with event->nativeVirtualKey() since the second one provides raw key
|
||||
// buttons
|
||||
const auto key = QtKeyToSwitchKey(Qt::Key(event->key()));
|
||||
input_subsystem->GetKeyboard()->SetKeyboardModifiers(moddifier);
|
||||
input_subsystem->GetKeyboard()->SetKeyboardModifiers(modifier);
|
||||
input_subsystem->GetKeyboard()->PressKeyboardKey(key);
|
||||
// This is used for gamepads
|
||||
input_subsystem->GetKeyboard()->PressKey(event->key());
|
||||
@@ -662,9 +662,9 @@ void GRenderWindow::keyPressEvent(QKeyEvent* event) {
|
||||
|
||||
void GRenderWindow::keyReleaseEvent(QKeyEvent* event) {
|
||||
if (!event->isAutoRepeat()) {
|
||||
const auto moddifier = QtModifierToSwitchModdifier(event->nativeModifiers());
|
||||
const auto modifier = QtModifierToSwitchModifier(event->nativeModifiers());
|
||||
const auto key = QtKeyToSwitchKey(Qt::Key(event->key()));
|
||||
input_subsystem->GetKeyboard()->SetKeyboardModifiers(moddifier);
|
||||
input_subsystem->GetKeyboard()->SetKeyboardModifiers(modifier);
|
||||
input_subsystem->GetKeyboard()->ReleaseKeyboardKey(key);
|
||||
// This is used for gamepads
|
||||
input_subsystem->GetKeyboard()->ReleaseKey(event->key());
|
||||
@@ -720,7 +720,7 @@ void GRenderWindow::mouseMoveEvent(QMouseEvent* event) {
|
||||
const int center_y = height() / 2;
|
||||
input_subsystem->GetMouse()->MouseMove(x, y, touch_x, touch_y, center_x, center_y);
|
||||
|
||||
if (Settings::values.mouse_panning) {
|
||||
if (Settings::values.mouse_panning && !Settings::values.mouse_enabled) {
|
||||
QCursor::setPos(mapToGlobal({center_x, center_y}));
|
||||
}
|
||||
|
||||
@@ -738,8 +738,8 @@ void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) {
|
||||
}
|
||||
|
||||
void GRenderWindow::wheelEvent(QWheelEvent* event) {
|
||||
const int x = event->delta();
|
||||
const int y = 0;
|
||||
const int x = event->angleDelta().x();
|
||||
const int y = event->angleDelta().y();
|
||||
input_subsystem->GetMouse()->MouseWheelChange(x, y);
|
||||
}
|
||||
|
||||
@@ -1035,7 +1035,7 @@ void GRenderWindow::showEvent(QShowEvent* event) {
|
||||
|
||||
bool GRenderWindow::eventFilter(QObject* object, QEvent* event) {
|
||||
if (event->type() == QEvent::HoverMove) {
|
||||
if (Settings::values.mouse_panning) {
|
||||
if (Settings::values.mouse_panning || Settings::values.mouse_enabled) {
|
||||
auto* hover_event = static_cast<QMouseEvent*>(event);
|
||||
mouseMoveEvent(hover_event);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user