66#include " platform.hpp"
77
88using namespace cocos2d ;
9+ using namespace geode ;
10+
11+ ImGuiKey keyFromGLFW (int key) {
12+ if (key >= GLFW_KEY_0 && key <= GLFW_KEY_9) {
13+ return static_cast <ImGuiKey>(ImGuiKey_0 + (key - GLFW_KEY_0));
14+ } else if (key >= GLFW_KEY_A && key <= GLFW_KEY_Z) {
15+ return static_cast <ImGuiKey>(ImGuiKey_A + (key - GLFW_KEY_A));
16+ }
17+ switch (key) {
18+ case GLFW_KEY_SPACE: return ImGuiKey_Space;
19+ case GLFW_KEY_BACKSPACE: return ImGuiKey_Backspace;
20+ case GLFW_KEY_COMMA: return ImGuiKey_Comma;
21+ case GLFW_KEY_LEFT: return ImGuiKey_LeftArrow;
22+ case GLFW_KEY_RIGHT: return ImGuiKey_RightArrow;
23+ case GLFW_KEY_UP: return ImGuiKey_UpArrow;
24+ case GLFW_KEY_DOWN: return ImGuiKey_DownArrow;
25+ case GLFW_KEY_ESCAPE: return ImGuiKey_Escape;
26+ case GLFW_KEY_LEFT_SHIFT: return ImGuiKey_LeftShift;
27+ case GLFW_KEY_RIGHT_SHIFT: return ImGuiKey_RightShift;
28+ case GLFW_KEY_LEFT_CONTROL: return ImGuiKey_LeftCtrl;
29+ case GLFW_KEY_LEFT_ALT: return ImGuiKey_LeftAlt;
30+ // TODO: rest :-)
31+ }
32+ return ImGuiKey_None;
33+ }
934
1035class $modify(CCEGLView) {
1136 void updateWindow (int width, int height) {
1237 shouldUpdateGDRenderBuffer () = true ;
1338 CCEGLView::updateWindow (width, height);
1439 }
40+
41+ void onGLFWKeyCallback (GLFWwindow* window, int key, int scancode, int action, int mods) {
42+ auto & io = ImGui::GetIO ();
43+ CCEGLView::onGLFWKeyCallback (window, key, scancode, action, mods);
44+ // in practice this is only used for arrow keys
45+ io.AddKeyEvent (keyFromGLFW (key), action != GLFW_RELEASE);
46+ }
1547};
1648
1749#endif
0 commit comments