summaryrefslogtreecommitdiffhomepage
path: root/main/keyboard.cpp
blob: 66dafa7e266c7e8ab82f1e7135909f971647601c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "app.hpp"
#include <Magnum/ImGuiIntegration/Context.hpp>

namespace floormat {

void app::do_key(KeyEvent::Key k, KeyEvent::Modifiers m, bool pressed, bool repeated)
{
    //using Mods = KeyEvent::Modifiers;

    (void)m;
    (void)repeated;

    const key x = progn(switch (k) {
        using enum KeyEvent::Key;
        using enum key;

    case W:     return camera_up;
    case A:     return camera_left;
    case S:     return camera_down;
    case D:     return camera_right;
    case Home:  return camera_reset;
    case Esc:   return quit;
    default:    return MAX;
    });

    if (x != key::MAX)
        keys[x] = pressed;
}

app::~app()
{
    loader_::destroy();
}

void app::keyPressEvent(Platform::Sdl2Application::KeyEvent& event)
{
    if (_imgui.handleKeyPressEvent(event))
        return event.setAccepted();
    do_key(event.key(), event.modifiers(), true, event.isRepeated());
}

void app::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event)
{
    if (_imgui.handleKeyReleaseEvent(event))
        return keys = {}, event.setAccepted();
    do_key(event.key(), event.modifiers(), false, false);
}

} // namespace floormat