1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 19:13:07 +01:00

Refactor dead key handling

This commit is contained in:
Ted John
2021-02-17 22:53:13 +00:00
parent d5eb1cc036
commit cacfb8be07

View File

@@ -525,41 +525,20 @@ public:
}
#endif
case SDL_KEYDOWN:
{
_textComposition.HandleMessage(&e);
{
InputEvent ie;
ie.DeviceKind = InputDeviceKind::Keyboard;
ie.Modifiers = e.key.keysym.mod;
ie.Button = e.key.keysym.sym;
// Handle dead keys
if (ie.Button == SDLK_SCANCODE_MASK)
{
switch (e.key.keysym.scancode)
{
case SDL_SCANCODE_APOSTROPHE:
ie.Button = '\'';
break;
case SDL_SCANCODE_GRAVE:
ie.Button = '`';
break;
default:
break;
}
}
ie.State = InputEventState::Down;
_inputManager.QueueInputEvent(std::move(ie));
}
auto ie = GetInputEventFromSDLEvent(e);
ie.State = InputEventState::Down;
_inputManager.QueueInputEvent(std::move(ie));
break;
}
case SDL_KEYUP:
{
InputEvent ie;
ie.DeviceKind = InputDeviceKind::Keyboard;
ie.Modifiers = e.key.keysym.mod;
ie.Button = e.key.keysym.sym;
auto ie = GetInputEventFromSDLEvent(e);
ie.State = InputEventState::Release;
_inputManager.QueueInputEvent(std::move(ie));
break;
}
break;
case SDL_MULTIGESTURE:
if (e.mgesture.numFingers == 2)
{
@@ -963,6 +942,32 @@ private:
return;
}
}
InputEvent GetInputEventFromSDLEvent(SDL_Event& e)
{
InputEvent ie;
ie.DeviceKind = InputDeviceKind::Keyboard;
ie.Modifiers = e.key.keysym.mod;
ie.Button = e.key.keysym.sym;
// Handle dead keys
if (ie.Button == SDLK_SCANCODE_MASK)
{
switch (e.key.keysym.scancode)
{
case SDL_SCANCODE_APOSTROPHE:
ie.Button = '\'';
break;
case SDL_SCANCODE_GRAVE:
ie.Button = '`';
break;
default:
break;
}
}
return ie;
}
};
std::unique_ptr<IUiContext> OpenRCT2::Ui::CreateUiContext(const std::shared_ptr<IPlatformEnvironment>& env)