@@ -98,7 +98,7 @@ public void render(Scene scene) {
9898 for (int j = 0 ; j < numCmds ; j ++) {
9999 final int elemCount = drawData .getCmdListCmdBufferElemCount (i , j );
100100 final int idxBufferOffset = drawData .getCmdListCmdBufferIdxOffset (i , j );
101- final int indices = idxBufferOffset * ImDrawData .SIZEOF_IM_DRAW_IDX ;
101+ final int indices = idxBufferOffset * ImDrawData .sizeOfImDrawIdx () ;
102102
103103 texture .bind ();
104104 glDrawElements (GL_TRIANGLES , elemCount , GL_UNSIGNED_SHORT , indices );
@@ -116,49 +116,137 @@ public void resize(int width, int height) {
116116 }
117117
118118 private void setupKeyCallBack (Window window ) {
119- ImGuiIO io = ImGui .getIO ();
120- io .setKeyMap (ImGuiKey .Tab , GLFW_KEY_TAB );
121- io .setKeyMap (ImGuiKey .LeftArrow , GLFW_KEY_LEFT );
122- io .setKeyMap (ImGuiKey .RightArrow , GLFW_KEY_RIGHT );
123- io .setKeyMap (ImGuiKey .UpArrow , GLFW_KEY_UP );
124- io .setKeyMap (ImGuiKey .DownArrow , GLFW_KEY_DOWN );
125- io .setKeyMap (ImGuiKey .PageUp , GLFW_KEY_PAGE_UP );
126- io .setKeyMap (ImGuiKey .PageDown , GLFW_KEY_PAGE_DOWN );
127- io .setKeyMap (ImGuiKey .Home , GLFW_KEY_HOME );
128- io .setKeyMap (ImGuiKey .End , GLFW_KEY_END );
129- io .setKeyMap (ImGuiKey .Insert , GLFW_KEY_INSERT );
130- io .setKeyMap (ImGuiKey .Delete , GLFW_KEY_DELETE );
131- io .setKeyMap (ImGuiKey .Backspace , GLFW_KEY_BACKSPACE );
132- io .setKeyMap (ImGuiKey .Space , GLFW_KEY_SPACE );
133- io .setKeyMap (ImGuiKey .Enter , GLFW_KEY_ENTER );
134- io .setKeyMap (ImGuiKey .Escape , GLFW_KEY_ESCAPE );
135- io .setKeyMap (ImGuiKey .KeyPadEnter , GLFW_KEY_KP_ENTER );
136-
137119 prevKeyCallBack = glfwSetKeyCallback (window .getWindowHandle (), (handle , key , scancode , action , mods ) -> {
138- window .keyCallBack (key , action );
139- if (!io .getWantCaptureKeyboard ()) {
140- if (prevKeyCallBack != null ) {
141- prevKeyCallBack .invoke (handle , key , scancode , action , mods );
142- }
143- return ;
144- }
145- if (action == GLFW_PRESS ) {
146- io .setKeysDown (key , true );
147- } else if (action == GLFW_RELEASE ) {
148- io .setKeysDown (key , false );
149- }
150- io .setKeyCtrl (io .getKeysDown (GLFW_KEY_LEFT_CONTROL ) || io .getKeysDown (GLFW_KEY_RIGHT_CONTROL ));
151- io .setKeyShift (io .getKeysDown (GLFW_KEY_LEFT_SHIFT ) || io .getKeysDown (GLFW_KEY_RIGHT_SHIFT ));
152- io .setKeyAlt (io .getKeysDown (GLFW_KEY_LEFT_ALT ) || io .getKeysDown (GLFW_KEY_RIGHT_ALT ));
153- io .setKeySuper (io .getKeysDown (GLFW_KEY_LEFT_SUPER ) || io .getKeysDown (GLFW_KEY_RIGHT_SUPER ));
154- }
120+ window .keyCallBack (key , action );
121+ ImGuiIO io = ImGui .getIO ();
122+ if (!io .getWantCaptureKeyboard ()) {
123+ return ;
124+ }
125+ if (action == GLFW_PRESS ) {
126+ io .addKeyEvent (getImKey (key ), true );
127+ } else if (action == GLFW_RELEASE ) {
128+ io .addKeyEvent (getImKey (key ), false );
129+ }
130+ }
155131 );
156132
157133 glfwSetCharCallback (window .getWindowHandle (), (handle , c ) -> {
134+ ImGuiIO io = ImGui .getIO ();
158135 if (!io .getWantCaptureKeyboard ()) {
159136 return ;
160137 }
161138 io .addInputCharacter (c );
162139 });
163140 }
141+
142+ private static int getImKey (int key ) {
143+ return switch (key ) {
144+ case GLFW_KEY_TAB -> ImGuiKey .Tab ;
145+ case GLFW_KEY_LEFT -> ImGuiKey .LeftArrow ;
146+ case GLFW_KEY_RIGHT -> ImGuiKey .RightArrow ;
147+ case GLFW_KEY_UP -> ImGuiKey .UpArrow ;
148+ case GLFW_KEY_DOWN -> ImGuiKey .DownArrow ;
149+ case GLFW_KEY_PAGE_UP -> ImGuiKey .PageUp ;
150+ case GLFW_KEY_PAGE_DOWN -> ImGuiKey .PageDown ;
151+ case GLFW_KEY_HOME -> ImGuiKey .Home ;
152+ case GLFW_KEY_END -> ImGuiKey .End ;
153+ case GLFW_KEY_INSERT -> ImGuiKey .Insert ;
154+ case GLFW_KEY_DELETE -> ImGuiKey .Delete ;
155+ case GLFW_KEY_BACKSPACE -> ImGuiKey .Backspace ;
156+ case GLFW_KEY_SPACE -> ImGuiKey .Space ;
157+ case GLFW_KEY_ENTER -> ImGuiKey .Enter ;
158+ case GLFW_KEY_ESCAPE -> ImGuiKey .Escape ;
159+ case GLFW_KEY_APOSTROPHE -> ImGuiKey .Apostrophe ;
160+ case GLFW_KEY_COMMA -> ImGuiKey .Comma ;
161+ case GLFW_KEY_MINUS -> ImGuiKey .Minus ;
162+ case GLFW_KEY_PERIOD -> ImGuiKey .Period ;
163+ case GLFW_KEY_SLASH -> ImGuiKey .Slash ;
164+ case GLFW_KEY_SEMICOLON -> ImGuiKey .Semicolon ;
165+ case GLFW_KEY_EQUAL -> ImGuiKey .Equal ;
166+ case GLFW_KEY_LEFT_BRACKET -> ImGuiKey .LeftBracket ;
167+ case GLFW_KEY_BACKSLASH -> ImGuiKey .Backslash ;
168+ case GLFW_KEY_RIGHT_BRACKET -> ImGuiKey .RightBracket ;
169+ case GLFW_KEY_GRAVE_ACCENT -> ImGuiKey .GraveAccent ;
170+ case GLFW_KEY_CAPS_LOCK -> ImGuiKey .CapsLock ;
171+ case GLFW_KEY_SCROLL_LOCK -> ImGuiKey .ScrollLock ;
172+ case GLFW_KEY_NUM_LOCK -> ImGuiKey .NumLock ;
173+ case GLFW_KEY_PRINT_SCREEN -> ImGuiKey .PrintScreen ;
174+ case GLFW_KEY_PAUSE -> ImGuiKey .Pause ;
175+ case GLFW_KEY_KP_0 -> ImGuiKey .Keypad0 ;
176+ case GLFW_KEY_KP_1 -> ImGuiKey .Keypad1 ;
177+ case GLFW_KEY_KP_2 -> ImGuiKey .Keypad2 ;
178+ case GLFW_KEY_KP_3 -> ImGuiKey .Keypad3 ;
179+ case GLFW_KEY_KP_4 -> ImGuiKey .Keypad4 ;
180+ case GLFW_KEY_KP_5 -> ImGuiKey .Keypad5 ;
181+ case GLFW_KEY_KP_6 -> ImGuiKey .Keypad6 ;
182+ case GLFW_KEY_KP_7 -> ImGuiKey .Keypad7 ;
183+ case GLFW_KEY_KP_8 -> ImGuiKey .Keypad8 ;
184+ case GLFW_KEY_KP_9 -> ImGuiKey .Keypad9 ;
185+ case GLFW_KEY_KP_DECIMAL -> ImGuiKey .KeypadDecimal ;
186+ case GLFW_KEY_KP_DIVIDE -> ImGuiKey .KeypadDivide ;
187+ case GLFW_KEY_KP_MULTIPLY -> ImGuiKey .KeypadMultiply ;
188+ case GLFW_KEY_KP_SUBTRACT -> ImGuiKey .KeypadSubtract ;
189+ case GLFW_KEY_KP_ADD -> ImGuiKey .KeypadAdd ;
190+ case GLFW_KEY_KP_ENTER -> ImGuiKey .KeypadEnter ;
191+ case GLFW_KEY_KP_EQUAL -> ImGuiKey .KeypadEqual ;
192+ case GLFW_KEY_LEFT_SHIFT -> ImGuiKey .LeftShift ;
193+ case GLFW_KEY_LEFT_CONTROL -> ImGuiKey .LeftCtrl ;
194+ case GLFW_KEY_LEFT_ALT -> ImGuiKey .LeftAlt ;
195+ case GLFW_KEY_LEFT_SUPER -> ImGuiKey .LeftSuper ;
196+ case GLFW_KEY_RIGHT_SHIFT -> ImGuiKey .RightShift ;
197+ case GLFW_KEY_RIGHT_CONTROL -> ImGuiKey .RightCtrl ;
198+ case GLFW_KEY_RIGHT_ALT -> ImGuiKey .RightAlt ;
199+ case GLFW_KEY_RIGHT_SUPER -> ImGuiKey .RightSuper ;
200+ case GLFW_KEY_MENU -> ImGuiKey .Menu ;
201+ case GLFW_KEY_0 -> ImGuiKey ._0 ;
202+ case GLFW_KEY_1 -> ImGuiKey ._1 ;
203+ case GLFW_KEY_2 -> ImGuiKey ._2 ;
204+ case GLFW_KEY_3 -> ImGuiKey ._3 ;
205+ case GLFW_KEY_4 -> ImGuiKey ._4 ;
206+ case GLFW_KEY_5 -> ImGuiKey ._5 ;
207+ case GLFW_KEY_6 -> ImGuiKey ._6 ;
208+ case GLFW_KEY_7 -> ImGuiKey ._7 ;
209+ case GLFW_KEY_8 -> ImGuiKey ._8 ;
210+ case GLFW_KEY_9 -> ImGuiKey ._9 ;
211+ case GLFW_KEY_A -> ImGuiKey .A ;
212+ case GLFW_KEY_B -> ImGuiKey .B ;
213+ case GLFW_KEY_C -> ImGuiKey .C ;
214+ case GLFW_KEY_D -> ImGuiKey .D ;
215+ case GLFW_KEY_E -> ImGuiKey .E ;
216+ case GLFW_KEY_F -> ImGuiKey .F ;
217+ case GLFW_KEY_G -> ImGuiKey .G ;
218+ case GLFW_KEY_H -> ImGuiKey .H ;
219+ case GLFW_KEY_I -> ImGuiKey .I ;
220+ case GLFW_KEY_J -> ImGuiKey .J ;
221+ case GLFW_KEY_K -> ImGuiKey .K ;
222+ case GLFW_KEY_L -> ImGuiKey .L ;
223+ case GLFW_KEY_M -> ImGuiKey .M ;
224+ case GLFW_KEY_N -> ImGuiKey .N ;
225+ case GLFW_KEY_O -> ImGuiKey .O ;
226+ case GLFW_KEY_P -> ImGuiKey .P ;
227+ case GLFW_KEY_Q -> ImGuiKey .Q ;
228+ case GLFW_KEY_R -> ImGuiKey .R ;
229+ case GLFW_KEY_S -> ImGuiKey .S ;
230+ case GLFW_KEY_T -> ImGuiKey .T ;
231+ case GLFW_KEY_U -> ImGuiKey .U ;
232+ case GLFW_KEY_V -> ImGuiKey .V ;
233+ case GLFW_KEY_W -> ImGuiKey .W ;
234+ case GLFW_KEY_X -> ImGuiKey .X ;
235+ case GLFW_KEY_Y -> ImGuiKey .Y ;
236+ case GLFW_KEY_Z -> ImGuiKey .Z ;
237+ case GLFW_KEY_F1 -> ImGuiKey .F1 ;
238+ case GLFW_KEY_F2 -> ImGuiKey .F2 ;
239+ case GLFW_KEY_F3 -> ImGuiKey .F3 ;
240+ case GLFW_KEY_F4 -> ImGuiKey .F4 ;
241+ case GLFW_KEY_F5 -> ImGuiKey .F5 ;
242+ case GLFW_KEY_F6 -> ImGuiKey .F6 ;
243+ case GLFW_KEY_F7 -> ImGuiKey .F7 ;
244+ case GLFW_KEY_F8 -> ImGuiKey .F8 ;
245+ case GLFW_KEY_F9 -> ImGuiKey .F9 ;
246+ case GLFW_KEY_F10 -> ImGuiKey .F10 ;
247+ case GLFW_KEY_F11 -> ImGuiKey .F11 ;
248+ case GLFW_KEY_F12 -> ImGuiKey .F12 ;
249+ default -> ImGuiKey .None ;
250+ };
251+ }
164252}
0 commit comments