FlixelImGuiDebugOverlay
View sourceclass
org.flixelgdx.backend.lwjgl3.debug.FlixelImGuiDebugOverlay
Dear ImGui based debug overlay for the LWJGL3 backend.
Wiring
FlixelLwjgl3Launcher registers this class as the default debug overlay factory when launching in DEBUG mode. You can also register it manually with Flixel.setDebugOverlay(...) before Flixel.initialize.
Initialization (creating the imgui context, hooking GLFW, and uploading the OpenGL resources) happens lazily on the first FlixelImGuiDebugOverlay.draw() call. That keeps construction cheap and only pays the cost when debug mode actually activates.
Once you move or resize a window, Dear ImGui remembers the change until the next forced layout. Window positions are not persisted across runs because we explicitly disable imgui's imgui.ini file (the framework does not own a writable directory on every platform).
Input behavior
The imgui-java GLFW backend installs callbacks that chain with the existing libGDX callbacks (using installCallbacks=true). Both libGDX and imgui see every key, mouse, and scroll event, so F2, F3, and F4 keep working even when an imgui window has focus. Keys that normally type into the command InputText (letters, punctuation such as backslash, arrows, Enter, Tab, Backspace, and so on) do not trigger debug bindings while that field is focused, so they do not fight the text box. Function keys, Escape, modifiers, and similar non-text keys still toggle the overlay and other debug actions. When the cursor is hovering an imgui window we suppress the camera pan/zoom and the sprite picker (via FlixelImGuiDebugOverlay.isMouseCapturedByUI()) so scrolling inside an imgui list does not also zoom the inspected camera or grab a sprite by accident.
Constructors
FlixelImGuiDebugOverlay()
Methods
draw()
resize(int, int)
destroy()
Tears down the Dear ImGui resources in the safe order: GL3 renderer first (which detaches GL state), then the GLFW backend (which removes its callback chain), and finally the imgui context itself. Each call is wrapped in its own try/catch because the LWJGL window is already partway through its own destruction by the time libGDX invokes ApplicationListener.dispose(), and a stray crash here was triggering the framework's uncaught-exception handler with the audio system still alive (the symptom: "OK" closes the alert but music keeps playing).
setVisible(boolean)
toggleVisible()
isMouseCapturedByUI()
isKeyboardCapturedByUI()
Reports keyboard capture by routing through Dear ImGui's WantCaptureKeyboard flag. Imgui sets this flag whenever any of its widgets has keyboard focus (text input, modal popup, drag spinner, etc.), so returning that value here prevents a game's input from capturing and processing input while the user is typing in the command console or interacting with another widget.
While the overlay is hidden, this always returns false. ImGui is not framed in that state, so the previous frame's WantCaptureKeyboard would otherwise stay stale and suppress gameplay input.
Note that the debug overlay's own toggle keys (F2 by default, etc.) read raw input from FlixelKeyInputManager.rawJustPressed(...), so they continue to work while a text field is focused except for keys that are suppressed as typable command-line input (see FlixelImGuiDebugOverlay.shouldSuppressDebugRawKeybind(int) on this class).
drawUI()
shouldSuppressDebugRawKeybind(int)
While the command line field is focused, blocks debug hotkeys for keys that normally type or edit text in that field. Function keys (F1-F24), Escape, modifiers, lock keys, Pause, Print Screen, and similar system keys still run debug bindings.
onWatchEntriesRefreshed()
onTrackerBlocksRebuilt()
onLogEntryAppended(BufferedLogLine)
onDrawImGui()
Hook for subclasses that want to add custom Dear ImGui content to the overlay.
Called once per frame from FlixelImGuiDebugOverlay.drawUI() after all built-in panels have been submitted but before ImGui.render() is called. The Dear ImGui frame is fully open, so any standard Dear ImGui call is valid here.
Because Dear ImGui is an immediate-mode API, a second ImGui.begin() call with the same window title as an existing panel appends content to that panel rather than creating a new one. This means a single override can both add new windows and inject content into any built-in window without needing a separate hook for each one:
public class MyOverlay extends FlixelImGuiDebugOverlay {
protected void onDrawImGui() {
// New standalone window.
if (ImGui.begin("My Panel")) {
ImGui.textUnformatted("Custom content here.");
}
ImGui.end();
// Append extra rows to the built-in Stats panel.
if (ImGui.begin("Stats")) {
ImGui.separator();
ImGui.textUnformatted("My stat: " + myValue);
}
ImGui.end();
// Add a menu to the main menu bar.
if (ImGui.beginMainMenuBar()) {
if (ImGui.beginMenu("My Tools")) {
if (ImGui.menuItem("Spawn enemy")) { spawnEnemy(); }
ImGui.endMenu();
}
ImGui.endMainMenuBar();
}
}
}