diff --git a/src/imgui_impl.ts b/src/imgui_impl.ts index 96718c3..a5dad20 100644 --- a/src/imgui_impl.ts +++ b/src/imgui_impl.ts @@ -279,6 +279,11 @@ app.renderer.plugins.interaction.addListener("mousedown", this.mouseDown.bind(this)); app.renderer.plugins.interaction.addListener("mouseup", this.mouseUp.bind(this)); app.ticker.add(this.updateInternal.bind(this)); + + this.interactive = false; + this.interactiveChildren = true; + + this.surface.interactive = false; } withContext(cb: () => void) { @@ -287,13 +292,17 @@ } mouseDown(e: PIXI.interaction.InteractionEvent): void { - this.io.MouseDown[mouse_button_map[0]] = true; - console.log("DOWN"); + if (!this.io.WantCaptureMouse || app.renderer.plugins.interaction.hitTest(app.renderer.plugins.interaction.mouse.global) == this.surface) + { + this.io.MouseDown[mouse_button_map[0]] = true; + } } mouseUp(e: PIXI.interaction.InteractionEvent): void { - this.io.MouseDown[mouse_button_map[0]] = false; - console.log("UP"); + if (!this.io.WantCaptureMouse || app.renderer.plugins.interaction.hitTest(app.renderer.plugins.interaction.mouse.global) == this.surface) + { + this.io.MouseDown[mouse_button_map[0]] = false; + } } resize(sizeX: number, sizeY: number) { @@ -468,6 +477,8 @@ ImGui.Render(); app.renderer.render(this.imgui, this.tex); + + this.surface.interactive = this.io.WantCaptureMouse; } } diff --git a/src/imgui_impl.ts b/src/imgui_impl.ts index 96718c3..a5dad20 100644 --- a/src/imgui_impl.ts +++ b/src/imgui_impl.ts @@ -279,6 +279,11 @@ app.renderer.plugins.interaction.addListener("mousedown", this.mouseDown.bind(this)); app.renderer.plugins.interaction.addListener("mouseup", this.mouseUp.bind(this)); app.ticker.add(this.updateInternal.bind(this)); + + this.interactive = false; + this.interactiveChildren = true; + + this.surface.interactive = false; } withContext(cb: () => void) { @@ -287,13 +292,17 @@ } mouseDown(e: PIXI.interaction.InteractionEvent): void { - this.io.MouseDown[mouse_button_map[0]] = true; - console.log("DOWN"); + if (!this.io.WantCaptureMouse || app.renderer.plugins.interaction.hitTest(app.renderer.plugins.interaction.mouse.global) == this.surface) + { + this.io.MouseDown[mouse_button_map[0]] = true; + } } mouseUp(e: PIXI.interaction.InteractionEvent): void { - this.io.MouseDown[mouse_button_map[0]] = false; - console.log("UP"); + if (!this.io.WantCaptureMouse || app.renderer.plugins.interaction.hitTest(app.renderer.plugins.interaction.mouse.global) == this.surface) + { + this.io.MouseDown[mouse_button_map[0]] = false; + } } resize(sizeX: number, sizeY: number) { @@ -468,6 +477,8 @@ ImGui.Render(); app.renderer.render(this.imgui, this.tex); + + this.surface.interactive = this.io.WantCaptureMouse; } } diff --git a/src/main.ts b/src/main.ts index 61306c1..475cc3b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -61,8 +61,8 @@ let styleCb: () => void = () => { ImGui.StyleColorsLight(); }; - const imgui: ImGuiWindow = new ImGuiWindow(512, 512, update); - const imgui2: ImGuiWindow = new ImGuiWindow(512, 512, update); + const imgui: ImGuiWindow = new ImGuiWindow(512, 512, makeUpdate()); + const imgui2: ImGuiWindow = new ImGuiWindow(512, 512, makeUpdate2()); imgui2.x = 200; imgui2.y = 400; @@ -77,19 +77,35 @@ resizeFunc(); } -let windowOpen: boolean = true; -let text: string = "text"; -function update(timeElapsed: number): void +function makeUpdate(): (timeElapsed: number) => void { - //ImGui.SetNextWindowPos(new ImVec2(0, 0)); - ImGui.SetNextWindowSize(new ImVec2(500, 500), ImGui.ImGuiCond.Always); - ImGui.Begin("Test Window"); - if (ImGui.Button("Add Text")) + let text: string = "text"; + return (timeElapsed: number) => { - text += "A"; - } - ImGui.Text(text); - ImGui.End(); + ImGui.SetNextWindowPos(new ImVec2(0, 0)); + ImGui.SetNextWindowSize(new ImVec2(500, 500), ImGui.ImGuiCond.Always); + ImGui.Begin("Test Window"); + if (ImGui.Button("Add Text")) + { + text += "A"; + } + ImGui.Text(text); + ImGui.End(); + }; +} + +function makeUpdate2(): (timeElapsed: number) => void +{ + let text:string = ""; + return (timeElapsed: number) => + { + ImGui.SetNextWindowPos(new ImVec2(0, 0)); + ImGui.SetNextWindowSize(new ImVec2(500, 500), ImGui.ImGuiCond.Always); + ImGui.Begin("Test Window 2"); + ImGui.InputText("Input: ", (_ = text) => text = _); + ImGui.Text(text); + ImGui.End(); + }; } (function()