diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 2a6d3b43..8503961c 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -9,8 +9,8 @@ object LibExt { const val gdxVersion = "1.12.1" const val teaVMVersion = "0.10.0" - const val gdxImGuiVersion = "1.0.0-SNAPSHOT" - const val gdxMultiViewVersion = "1.0.0-SNAPSHOT" + const val gdxImGuiVersion = "-SNAPSHOT" + const val gdxMultiViewVersion = "-SNAPSHOT" const val reflectionVersion = "0.10.2" const val jettyVersion = "11.0.13" diff --git a/examples/gdx-tests/core/src/main/java/com/github/xpenatan/imgui/example/tests/imgui/ImGuiTestsApp.java b/examples/gdx-tests/core/src/main/java/com/github/xpenatan/imgui/example/tests/imgui/ImGuiTestsApp.java index 41a6746d..14208b24 100644 --- a/examples/gdx-tests/core/src/main/java/com/github/xpenatan/imgui/example/tests/imgui/ImGuiTestsApp.java +++ b/examples/gdx-tests/core/src/main/java/com/github/xpenatan/imgui/example/tests/imgui/ImGuiTestsApp.java @@ -1,17 +1,22 @@ package com.github.xpenatan.imgui.example.tests.imgui; +import com.badlogic.gdx.Application; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.glutils.HdpiUtils; +import com.badlogic.gdx.tests.AbstractTestWrapper; import com.badlogic.gdx.tests.InputTest; import com.badlogic.gdx.tests.utils.GdxTest; import com.badlogic.gdx.tests.TeaVMGdxTests; +import com.badlogic.gdx.utils.ScreenUtils; import com.github.xpenatan.gdx.multiview.EmuFrameBuffer; import com.github.xpenatan.imgui.example.tests.frame.GameFrame; import imgui.ImDrawData; import imgui.ImGui; +import imgui.ImGuiConfigFlags; import imgui.ImGuiIO; import imgui.ImVec2; import imgui.gdx.ImGuiGdxImpl; @@ -22,97 +27,132 @@ */ public class ImGuiTestsApp implements Screen { - ImGuiGdxImpl impl; + private GdxTest test; - boolean gdxTestInit = false; + private ImGuiGdxImpl impl; + private ImGuiGdxInputMultiplexer input; - int selected = -1; + private boolean gdxTestInit = false; - private GameFrame gameFrame; + private int selected = -1; - SpriteBatch batch; - private OrthographicCamera camera; + private TeaVMGdxTests.TeaVMInstancer[] testList; - TeaVMGdxTests.TeaVMInstancer[] testList; + private boolean dispose = false; @Override public void show() { - ImGui.CreateContext(true); - - camera = new OrthographicCamera(); - camera.setToOrtho(true); - batch = new SpriteBatch(); + testList = TeaVMGdxTests.getTestList(); + if(Gdx.app.getType() == Application.ApplicationType.WebGL) { + // Not possible to have ini filename with webgl + ImGui.CreateContext(false); + } + else { + ImGui.CreateContext(true); + } ImGuiIO io = ImGui.GetIO(); + io.ConfigFlags(ImGuiConfigFlags.ImGuiConfigFlags_DockingEnable); -// io.setIniFilename(null); -// io.SetConfigFlags(ImGuiConfigFlags.DockingEnable); - io.SetDockingFlags(false, false, false, false); - + input = new ImGuiGdxInputMultiplexer(); impl = new ImGuiGdxImpl(); - EmuFrameBuffer.setDefaultFramebufferHandleInitialized(false); - - gameFrame = new GameFrame(20, 20, 800, 400); - - testList = TeaVMGdxTests.getTestList(); - - gameFrame.emuWindow.setApplicationListener(new InputTest()); + Gdx.input = new TeaVMInputWrapper(Gdx.input) { + @Override + public boolean keyUp (int keycode) { + if (keycode == Keys.ESCAPE) { + if (test != null) { + Gdx.app.log("GdxTest", "Exiting current test."); + dispose = true; + } + } + return false; + } - ImGuiGdxInputMultiplexer multiplexer = new ImGuiGdxInputMultiplexer(); - multiplexer.addProcessor(gameFrame.emuWindow.getEmuInput()); - Gdx.input.setInputProcessor(multiplexer); + @Override + public boolean touchDown (int screenX, int screenY, int pointer, int button) { + if (screenX < Gdx.graphics.getWidth() / 10.0 && screenY < Gdx.graphics.getHeight() / 10.0) { + if (test != null) { + dispose = true; + } + } + return false; + } + }; + ((TeaVMInputWrapper)Gdx.input).multiplexer.addProcessor(input); } private void drawTestListWindow() { if(!gdxTestInit) { gdxTestInit = true; - ImGui.SetNextWindowSize(ImVec2.TMP_1.set(200, 500)); - ImGui.SetNextWindowPos(ImVec2.TMP_1.set(900, 20)); + ImGui.SetNextWindowSize(ImVec2.TMP_1.set(250, 500)); + ImGui.SetNextWindowPos(ImVec2.TMP_1.set(20, 20)); } ImGui.Begin("GdxTests"); - ImGui.BeginChildFrame(313, ImVec2.TMP_1.set(0f, 0f)); + if(ImGui.Button("Start Test")) { + if(selected >= 0 && selected < testList.length) { + ((TeaVMInputWrapper)Gdx.input).multiplexer.removeProcessor(input); + test = testList[selected].instance(); + Gdx.app.log("GdxTest", "Clicked on " + test.getClass().getName()); + test.create(); + test.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + } + } + ImGui.Separator(); + ImGui.BeginChild("List", ImVec2.TMP_1.set(0, 0)); for(int i = 0; i < testList.length; i++) { String testName = testList[i].getSimpleName(); boolean isSelected = selected == i; if(ImGui.Selectable(testName, isSelected)) { if(selected != i) { selected = i; - GdxTest newTest = testList[i].instance(); - gameFrame.emuWindow.setApplicationListener(newTest); } } } - ImGui.EndChildFrame(); + ImGui.EndChild(); ImGui.End(); } @Override public void render(float delta) { - Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - - camera.update(); - gameFrame.update(); - - impl.update(); - drawTestListWindow(); - ImGui.Render(); - ImDrawData drawData = ImGui.GetDrawData(); - impl.render(drawData); - - batch.setProjectionMatrix(camera.combined); - batch.begin(); - gameFrame.draw(batch); - batch.end(); + if (test == null) { + Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + + impl.update(); + + drawTestListWindow(); + + ImGui.Render(); + ImDrawData drawData = ImGui.GetDrawData(); + impl.render(drawData); + } + else { + if (dispose) { + test.pause(); + test.dispose(); + test = null; + Gdx.graphics.setVSync(true); + TeaVMInputWrapper wrapper = ((TeaVMInputWrapper)Gdx.input); + wrapper.multiplexer.addProcessor(input); + wrapper.multiplexer.removeProcessor(wrapper.lastProcessor); + wrapper.lastProcessor = null; + dispose = false; + HdpiUtils.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + } else { + test.render(); + } + } } @Override public void resize(int width, int height) { -// gameFrame.windowX = 0; -// gameFrame.windowY = 0; -// gameFrame.windowWidth = width; -// gameFrame.windowHeight = height; + if (test != null) { + test.resize(width, height); + } + else { + HdpiUtils.glViewport(0, 0, width, height); + } } @Override @@ -132,6 +172,6 @@ public void hide() { public void dispose() { impl.dispose(); ImGui.disposeStatic(); - batch.dispose(); + ImGui.DestroyContext(); } } diff --git a/examples/gdx-tests/core/src/main/java/com/github/xpenatan/imgui/example/tests/imgui/TeaVMInputWrapper.java b/examples/gdx-tests/core/src/main/java/com/github/xpenatan/imgui/example/tests/imgui/TeaVMInputWrapper.java new file mode 100644 index 00000000..8ea7af73 --- /dev/null +++ b/examples/gdx-tests/core/src/main/java/com/github/xpenatan/imgui/example/tests/imgui/TeaVMInputWrapper.java @@ -0,0 +1,276 @@ +package com.github.xpenatan.imgui.example.tests.imgui; + +import com.badlogic.gdx.Input; +import com.badlogic.gdx.InputAdapter; +import com.badlogic.gdx.InputMultiplexer; +import com.badlogic.gdx.InputProcessor; + +public class TeaVMInputWrapper extends InputAdapter implements Input { + Input input; + InputProcessor lastProcessor; + public InputMultiplexer multiplexer; + + public TeaVMInputWrapper(Input input) { + this.input = input; + this.multiplexer = new InputMultiplexer(); + this.multiplexer.addProcessor(this); + input.setInputProcessor(multiplexer); + } + + @Override + public float getAccelerometerX() { + return input.getAccelerometerX(); + } + + @Override + public float getAccelerometerY() { + return input.getAccelerometerY(); + } + + @Override + public float getAccelerometerZ() { + return input.getAccelerometerZ(); + } + + @Override + public float getGyroscopeX() { + return input.getGyroscopeX(); + } + + @Override + public float getGyroscopeY() { + return input.getGyroscopeY(); + } + + @Override + public float getGyroscopeZ() { + return input.getGyroscopeZ(); + } + + @Override + public int getMaxPointers() { + return input.getMaxPointers(); + } + + @Override + public int getX() { + return input.getX(); + } + + @Override + public int getX(int pointer) { + return input.getX(pointer); + } + + @Override + public int getDeltaX() { + return input.getDeltaX(); + } + + @Override + public int getDeltaX(int pointer) { + return input.getDeltaX(pointer); + } + + @Override + public int getY() { + return input.getY(); + } + + @Override + public int getY(int pointer) { + return input.getY(pointer); + } + + @Override + public int getDeltaY() { + return input.getDeltaY(); + } + + @Override + public int getDeltaY(int pointer) { + return input.getDeltaY(pointer); + } + + @Override + public boolean isTouched() { + return input.isTouched(); + } + + @Override + public boolean justTouched() { + return input.justTouched(); + } + + @Override + public boolean isTouched(int pointer) { + return input.isTouched(pointer); + } + + @Override + public float getPressure() { + return input.getPressure(); + } + + @Override + public float getPressure(int pointer) { + return input.getPressure(pointer); + } + + @Override + public boolean isButtonPressed(int button) { + return input.isButtonPressed(button); + } + + @Override + public boolean isKeyPressed(int key) { + return input.isKeyPressed(key); + } + + @Override + public boolean isKeyJustPressed(int key) { + return input.isKeyJustPressed(key); + } + + @Override + public boolean isButtonJustPressed(int button) { + return input.isButtonJustPressed(button); + } + + @Override + public void getTextInput(TextInputListener listener, String title, String text, String hint) { + input.getTextInput(listener, title, text, hint); + } + + @Override + public void getTextInput(TextInputListener listener, String title, String text, String hint, OnscreenKeyboardType type) { + input.getTextInput(listener, title, text, hint, type); + } + + @Override + public void setOnscreenKeyboardVisible(boolean visible) { + input.setOnscreenKeyboardVisible(visible); + } + + @Override + public void setOnscreenKeyboardVisible(boolean visible, OnscreenKeyboardType type) { + input.setOnscreenKeyboardVisible(visible, type); + } + + @Override + public void vibrate(int milliseconds) { + input.vibrate(milliseconds); + } + + @Override + public void vibrate(int milliseconds, boolean fallback) { + input.vibrate(milliseconds, fallback); + } + + @Override + public void vibrate(int milliseconds, int amplitude, boolean fallback) { + input.vibrate(milliseconds, amplitude, fallback); + } + + @Override + public void vibrate(VibrationType vibrationType) { + input.vibrate(vibrationType); + } + + @Override + public float getAzimuth() { + return input.getAzimuth(); + } + + @Override + public float getPitch() { + return input.getPitch(); + } + + @Override + public float getRoll() { + return input.getRoll(); + } + + @Override + public void getRotationMatrix(float[] matrix) { + input.getRotationMatrix(matrix); + } + + @Override + public long getCurrentEventTime() { + return input.getCurrentEventTime(); + } + + @Override + public void setCatchBackKey(boolean catchBack) { + input.setCatchBackKey(catchBack); + } + + @Override + public boolean isCatchBackKey() { + return input.isCatchBackKey(); + } + + @Override + public void setCatchMenuKey(boolean catchMenu) { + input.setCatchMenuKey(catchMenu); + } + + @Override + public boolean isCatchMenuKey() { + return input.isCatchMenuKey(); + } + + @Override + public void setCatchKey(int keycode, boolean catchKey) { + input.setCatchKey(keycode, catchKey); + } + + @Override + public boolean isCatchKey(int keycode) { + return input.isCatchKey(keycode); + } + + @Override + public void setInputProcessor(InputProcessor processor) { + multiplexer.removeProcessor(lastProcessor); + multiplexer.addProcessor(processor); + lastProcessor = processor; + } + + @Override + public InputProcessor getInputProcessor() { + return input.getInputProcessor(); + } + + @Override + public boolean isPeripheralAvailable(Peripheral peripheral) { + return input.isPeripheralAvailable(peripheral); + } + + @Override + public int getRotation() { + return input.getRotation(); + } + + @Override + public Orientation getNativeOrientation() { + return input.getNativeOrientation(); + } + + @Override + public void setCursorCatched(boolean catched) { + input.setCursorCatched(catched); + } + + @Override + public boolean isCursorCatched() { + return input.isCursorCatched(); + } + + @Override + public void setCursorPosition(int x, int y) { + input.setCursorPosition(x, y); + } +} \ No newline at end of file diff --git a/examples/gdx-tests/desktop/src/main/java/com/github/xpenatan/imgui/example/tests/Main.java b/examples/gdx-tests/desktop/src/main/java/com/github/xpenatan/imgui/example/tests/Main.java index 5d459e79..9b8c2392 100644 --- a/examples/gdx-tests/desktop/src/main/java/com/github/xpenatan/imgui/example/tests/Main.java +++ b/examples/gdx-tests/desktop/src/main/java/com/github/xpenatan/imgui/example/tests/Main.java @@ -21,8 +21,7 @@ public static void main(String[] args) { config.gles30ContextMajorVersion = 4; config.gles30ContextMinorVersion = 3; config.useGL30 = true; -// new Lwjgl3Application(new MultipleRenderTargetTest(), config); -// new Lwjgl3Application(new FloatTextureTest(), config); - new LwjglApplication(new TeaVMTestWrapper(), config); +// new LwjglApplication(new TeaVMTestWrapper(), config); + new LwjglApplication(new ImGuiGame(), config); } } \ No newline at end of file diff --git a/examples/gdx-tests/teavm/src/main/java/com/github/xpenatan/gdx/examples/teavm/launcher/GdxTestLauncher.java b/examples/gdx-tests/teavm/src/main/java/com/github/xpenatan/gdx/examples/teavm/launcher/GdxTestLauncher.java index d4aca851..897ce88d 100644 --- a/examples/gdx-tests/teavm/src/main/java/com/github/xpenatan/gdx/examples/teavm/launcher/GdxTestLauncher.java +++ b/examples/gdx-tests/teavm/src/main/java/com/github/xpenatan/gdx/examples/teavm/launcher/GdxTestLauncher.java @@ -1,13 +1,5 @@ package com.github.xpenatan.gdx.examples.teavm.launcher; -import com.badlogic.gdx.tests.FloatTextureTest; -import com.badlogic.gdx.tests.SoundTest; -import com.badlogic.gdx.tests.TextureDataTest; -import com.badlogic.gdx.tests.g3d.MultipleRenderTargetTest; -import com.badlogic.gdx.tests.g3d.TextureArrayTest; -import com.badlogic.gdx.tests.g3d.TextureRegion3DTest; -import com.badlogic.gdx.tests.gles3.GL30Texture3DTest; -import com.badlogic.gdx.tests.gles3.InstancedRenderingTest; import com.github.xpenatan.gdx.backends.teavm.TeaApplicationConfiguration; import com.github.xpenatan.gdx.backends.teavm.TeaApplication; import com.github.xpenatan.imgui.example.tests.imgui.ImGuiGame; @@ -22,7 +14,7 @@ public static void main(String[] args) { config.showDownloadLogs = true; config.useGL30 = true; config.useGLArrayBuffer = true; -// new TeaApplication(new ImGuiGame(), config); - new TeaApplication(new TeaVMTestWrapper(), config); + new TeaApplication(new ImGuiGame(), config); +// new TeaApplication(new TeaVMTestWrapper(), config); } }