[nostalgia/core/glfw] Cleanup key input system
This commit is contained in:
parent
b4a7b7690e
commit
6e742e5d45
@ -29,31 +29,28 @@ static auto setKeyDownStatus(GlfwImplData *id, Key key, bool down) noexcept {
|
||||
}
|
||||
|
||||
static void handleKeyPress(Context *ctx, int key, bool down) noexcept {
|
||||
static constexpr auto keyMap = [] {
|
||||
ox::Array<Key, GLFW_KEY_LAST> map = {};
|
||||
for (auto i = 0u; i < 26; ++i) {
|
||||
map[GLFW_KEY_A + i] = static_cast<Key>(static_cast<unsigned>(Key::Alpha_A) + i);
|
||||
}
|
||||
for (auto i = 0u; i < 10; ++i) {
|
||||
map[GLFW_KEY_0 + i] = static_cast<Key>(static_cast<unsigned>(Key::Num_0) + i);
|
||||
}
|
||||
map[GLFW_KEY_LEFT_ALT] = Key::Mod_Alt;
|
||||
map[GLFW_KEY_RIGHT_ALT] = Key::Mod_Alt;
|
||||
map[GLFW_KEY_LEFT_CONTROL] = Key::Mod_Ctrl;
|
||||
map[GLFW_KEY_RIGHT_CONTROL] = Key::Mod_Ctrl;
|
||||
map[GLFW_KEY_LEFT_SUPER] = Key::Mod_Super;
|
||||
map[GLFW_KEY_RIGHT_SUPER] = Key::Mod_Super;
|
||||
return map;
|
||||
}();
|
||||
const auto eventHandler = keyEventHandler(ctx);
|
||||
const auto id = ctx->windowerData<GlfwImplData>();
|
||||
const auto k = keyMap[static_cast<std::size_t>(key)];
|
||||
setKeyDownStatus(id, k, down);
|
||||
if (eventHandler) {
|
||||
if (key >= GLFW_KEY_A && key <= GLFW_KEY_Z) {
|
||||
const auto k = static_cast<Key>(Key::Alpha_A + (key - GLFW_KEY_A));
|
||||
setKeyDownStatus(id, k, down);
|
||||
eventHandler(ctx, k, down);
|
||||
} else if (key >= GLFW_KEY_0 && key <= GLFW_KEY_9) {
|
||||
const auto k = static_cast<Key>(Key::Num_0 + (key - GLFW_KEY_0));
|
||||
setKeyDownStatus(id, k, down);
|
||||
eventHandler(ctx, k, down);
|
||||
} else {
|
||||
switch (key) {
|
||||
case GLFW_KEY_LEFT_SHIFT:
|
||||
case GLFW_KEY_RIGHT_SHIFT:
|
||||
setKeyDownStatus(id, Key::Mod_Shift, down);
|
||||
eventHandler(ctx, Key::Mod_Shift, down);
|
||||
break;
|
||||
case GLFW_KEY_LEFT_CONTROL:
|
||||
case GLFW_KEY_RIGHT_CONTROL:
|
||||
setKeyDownStatus(id, Key::Mod_Ctrl, down);
|
||||
eventHandler(ctx, Key::Mod_Ctrl, down);
|
||||
break;
|
||||
}
|
||||
}
|
||||
eventHandler(ctx, k, down);
|
||||
}
|
||||
//if constexpr(ox::defines::Debug) {
|
||||
// switch (key) {
|
||||
|
Loading…
Reference in New Issue
Block a user