-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyactions.cpp
More file actions
39 lines (30 loc) · 1005 Bytes
/
Copy pathkeyactions.cpp
File metadata and controls
39 lines (30 loc) · 1005 Bytes
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
#include "../header/keyactions.h"
#include <unordered_map>
typedef void (*ActionFn)(UIState& st, int columnCount);
static void ActLeft(UIState& st, int columnCount) {
st.selectedIndex = (st.selectedIndex - 1 + columnCount) % columnCount;
}
static void ActRight(UIState& st, int columnCount) {
st.selectedIndex = (st.selectedIndex + 1) % columnCount;
}
static void ActToggleAsc(UIState& st, int) {
st.asc = !st.asc;
}
static void ActQuit(UIState& st, int) {
st.running = false;
}
static std::unordered_map<WORD, ActionFn> g_actions;
void InitKeyActions() {
g_actions[VK_LEFT] = &ActLeft;
g_actions[VK_RIGHT] = &ActRight;
g_actions[VK_UP] = &ActToggleAsc;
g_actions[VK_DOWN] = &ActToggleAsc;
g_actions['Q'] = &ActQuit;
}
void HandleKeyEvent(const KEY_EVENT_RECORD& key, UIState& st, int columnCount) {
if (!key.bKeyDown) return;
auto it = g_actions.find(key.wVirtualKeyCode);
if (it != g_actions.end()) {
it->second(st, columnCount);
}
}