diff --git a/src/imgui_impl.ts b/src/imgui_impl.ts index 623d4a7..6189ac4 100644 --- a/src/imgui_impl.ts +++ b/src/imgui_impl.ts @@ -203,20 +203,16 @@ { super(); - if (isFirstWindow) - { - this.ctx = contexts[0]; - this.io = contextIOs[0]; - } - else - { - this.ctx = ImGui.CreateContext(contextIOs[0].Fonts); - ImGui.SetCurrentContext(this.ctx); - this.io = ImGui.GetIO(); - } + this.ctx = ImGui.CreateContext(contextIOs.length == 0 ? null : contextIOs[0].Fonts); + ImGui.SetCurrentContext(this.ctx); + this.io = ImGui.GetIO(); + contexts.push(this.ctx); + contextIOs.push(this.io); - isFirstWindow = false; + if (typeof(window) !== "undefined") { + ImGui.LoadIniSettingsFromMemory(window.localStorage.getItem("imgui.ini") || ""); + } if (typeof(navigator) !== "undefined") { this.io.ConfigMacOSXBehaviors = navigator.platform.match(/Mac/) !== null; @@ -271,7 +267,6 @@ this.io.KeyMap[ImGui.Key.Y] = 89; this.io.KeyMap[ImGui.Key.Z] = 90; - contextIOs.push(this.io); this.update = update; this.resize(sizeX, sizeY); this.imgui.pluginName = 'imgui_renderer'; @@ -280,6 +275,11 @@ app.renderer.plugins.interaction.addListener("mouseup", this.mouseUp.bind(this)); app.ticker.add(this.updateInternal.bind(this)); } + withContext(cb: () => void) + { + ImGui.SetCurrentContext(this.ctx); + cb(); + } mouseDown(e: PIXI.interaction.InteractionEvent): void { this.io.MouseDown[mouse_button_map[0]] = true; @@ -482,8 +482,6 @@ let g_ElementsHandle: WebGLBuffer | null = null; let g_FontTexture: WebGLTexture | null = null; -let prev_time: number = 0; - function document_on_copy(event: ClipboardEvent): void { if (event.clipboardData) { event.clipboardData.setData("text/plain", clipboard_text); @@ -620,16 +618,6 @@ export function Init(_app: PIXI.Application): void { // Setup Dear ImGui binding ImGui.IMGUI_CHECKVERSION(); - ImGui.CreateContext(); - - contexts.push(ImGui.GetCurrentContext()); - contextIOs.push(ImGui.GetIO()); - contextIOs[0].Fonts.AddFontDefault(); - - - if (typeof(window) !== "undefined") { - ImGui.LoadIniSettingsFromMemory(window.localStorage.getItem("imgui.ini") || ""); - } if (typeof(document) !== "undefined") { document.body.addEventListener("copy", document_on_copy); @@ -642,7 +630,6 @@ window.addEventListener("gamepaddisconnected", window_on_gamepaddisconnected); } - app = _app; gl = (app.renderer as any).gl; canvas = app.view;