{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreiemhfqvkqbrxl2d5lo6fbechmsnhwqauipix3fhzhfhhwr3ciu2au",
"uri": "at://did:plc:dxjzgxe7cvirxkwfjr2tjspt/app.bsky.feed.post/3mnvlub7qh6n2"
},
"path": "/t/vlog-03-integrating-dear-imgui-1-92-0-with-latest-jme3-initial-findings-traps-and-architecture-choices/49616#post_2",
"publishedAt": "2026-06-09T22:06:44.000Z",
"site": "https://hub.jmonkeyengine.org",
"tags": [
"@Override"
],
"textContent": "\n package com.jme3.imgui;\n\n import com.jme3.input.RawInputListener;\n import com.jme3.input.event.JoyAxisEvent;\n import com.jme3.input.event.JoyButtonEvent;\n import com.jme3.input.event.KeyInputEvent;\n import com.jme3.input.event.MouseButtonEvent;\n import com.jme3.input.event.MouseMotionEvent;\n import com.jme3.input.event.TouchEvent;\n import imgui.ImGui;\n import imgui.ImGuiIO;\n import imgui.flag.ImGuiKey;\n\n public class JmeImGuiInput implements RawInputListener {\n\n @Override\n public void beginInput() {\n }\n\n @Override\n public void endInput() {\n }\n\n @Override\n public void onJoyAxisEvent(JoyAxisEvent evt) {\n }\n\n @Override\n public void onJoyButtonEvent(JoyButtonEvent evt) {\n }\n\n @Override\n public void onTouchEvent(TouchEvent evt) {\n }\n\n @Override\n public void onMouseMotionEvent(MouseMotionEvent evt) {\n ImGuiIO io = ImGui.getIO();\n io.addMousePosEvent(evt.getX(), io.getDisplaySizeY() - evt.getY());\n\n if (evt.getDeltaWheel() != 0) {\n io.addMouseWheelEvent(0.0f, evt.getDeltaWheel());\n }\n\n if (io.getWantCaptureMouse()) {\n evt.setConsumed();\n }\n }\n\n @Override\n public void onMouseButtonEvent(MouseButtonEvent evt) {\n ImGuiIO io = ImGui.getIO();\n io.addMouseButtonEvent(evt.getButtonIndex(), evt.isPressed());\n\n if (io.getWantCaptureMouse()) {\n evt.setConsumed();\n }\n }\n\n @Override\n public void onKeyEvent(KeyInputEvent evt) {\n ImGuiIO io = ImGui.getIO();\n\n int imguiKey = mapKey(evt.getKeyCode());\n\n if (imguiKey != ImGuiKey.None) {\n io.addKeyEvent(imguiKey, evt.isPressed());\n }\n\n if (evt.isPressed()) {\n char c = evt.getKeyChar();\n\n if (c > 0 && c != 65535) {\n io.addInputCharacter(c);\n }\n }\n\n // updateModifiers(io); // FIXME\n\n if (io.getWantCaptureKeyboard()) {\n evt.setConsumed();\n }\n }\n\n // private static void updateModifiers(ImGuiIO io) {\n // io.addKeyEvent(\n // ImGuiKey.ImGuiMod_Ctrl,\n // io.getKeysDown(ImGuiKey.LeftCtrl)\n // || io.getKeysDown(ImGuiKey.RightCtrl)\n // );\n //\n // io.addKeyEvent(\n // ImGuiKey.ImGuiMod_Shift,\n // io.getKeysDown(ImGuiKey.LeftShift)\n // || io.getKeysDown(ImGuiKey.RightShift)\n // );\n //\n // io.addKeyEvent(\n // ImGuiKey.ImGuiMod_Alt,\n // io.getKeysDown(ImGuiKey.LeftAlt)\n // || io.getKeysDown(ImGuiKey.RightAlt)\n // );\n //\n // io.addKeyEvent(\n // ImGuiKey.ImGuiMod_Super,\n // io.getKeysDown(ImGuiKey.LeftSuper)\n // || io.getKeysDown(ImGuiKey.RightSuper)\n // );\n // }\n\n private static int mapKey(int key) {\n\n switch (key) {\n\n case com.jme3.input.KeyInput.KEY_TAB:\n return ImGuiKey.Tab;\n\n case com.jme3.input.KeyInput.KEY_LEFT:\n return ImGuiKey.LeftArrow;\n\n case com.jme3.input.KeyInput.KEY_RIGHT:\n return ImGuiKey.RightArrow;\n\n case com.jme3.input.KeyInput.KEY_UP:\n return ImGuiKey.UpArrow;\n\n case com.jme3.input.KeyInput.KEY_DOWN:\n return ImGuiKey.DownArrow;\n\n case com.jme3.input.KeyInput.KEY_PGUP:\n return ImGuiKey.PageUp;\n\n case com.jme3.input.KeyInput.KEY_PGDN:\n return ImGuiKey.PageDown;\n\n case com.jme3.input.KeyInput.KEY_HOME:\n return ImGuiKey.Home;\n\n case com.jme3.input.KeyInput.KEY_END:\n return ImGuiKey.End;\n\n case com.jme3.input.KeyInput.KEY_INSERT:\n return ImGuiKey.Insert;\n\n case com.jme3.input.KeyInput.KEY_DELETE:\n return ImGuiKey.Delete;\n\n case com.jme3.input.KeyInput.KEY_BACK:\n return ImGuiKey.Backspace;\n\n case com.jme3.input.KeyInput.KEY_SPACE:\n return ImGuiKey.Space;\n\n case com.jme3.input.KeyInput.KEY_RETURN:\n return ImGuiKey.Enter;\n\n case com.jme3.input.KeyInput.KEY_ESCAPE:\n return ImGuiKey.Escape;\n\n case com.jme3.input.KeyInput.KEY_LCONTROL:\n return ImGuiKey.LeftCtrl;\n\n case com.jme3.input.KeyInput.KEY_RCONTROL:\n return ImGuiKey.RightCtrl;\n\n case com.jme3.input.KeyInput.KEY_LSHIFT:\n return ImGuiKey.LeftShift;\n\n case com.jme3.input.KeyInput.KEY_RSHIFT:\n return ImGuiKey.RightShift;\n\n case com.jme3.input.KeyInput.KEY_LMENU:\n return ImGuiKey.LeftAlt;\n\n case com.jme3.input.KeyInput.KEY_RMENU:\n return ImGuiKey.RightAlt;\n\n case com.jme3.input.KeyInput.KEY_LMETA:\n return ImGuiKey.LeftSuper;\n\n case com.jme3.input.KeyInput.KEY_RMETA:\n return ImGuiKey.RightSuper;\n }\n\n if (key >= com.jme3.input.KeyInput.KEY_A\n && key <= com.jme3.input.KeyInput.KEY_Z) {\n\n return ImGuiKey.A + (key - com.jme3.input.KeyInput.KEY_A);\n }\n\n if (key >= com.jme3.input.KeyInput.KEY_0\n && key <= com.jme3.input.KeyInput.KEY_9) {\n\n return ImGuiKey._0 + (key - com.jme3.input.KeyInput.KEY_0);\n }\n\n return ImGuiKey.None;\n }\n\n public void setFocused(boolean focused) {\n ImGui.getIO().addFocusEvent(focused);\n }\n }\n",
"title": "Vlog 03: Integrating Dear ImGui (1.92.0+) with latest jME3: Initial Findings, Traps, and Architecture Choices"
}