From b2a64a7487cda8699af654f51d58eed2242be6d7 Mon Sep 17 00:00:00 2001 From: Mathias Gredal Date: Fri, 24 Mar 2023 05:43:33 +0100 Subject: [PATCH] Flip inheritance hierarchy between Application and Window --- example/src/main/java/Main.java | 4 ++-- imgui-app/src/main/java/imgui/app/Application.java | 14 +++++++++++--- imgui-app/src/main/java/imgui/app/BGFXWindow.java | 2 +- imgui-app/src/main/java/imgui/app/Window.java | 6 +++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/example/src/main/java/Main.java b/example/src/main/java/Main.java index 907f7dde..1f0a28f9 100644 --- a/example/src/main/java/Main.java +++ b/example/src/main/java/Main.java @@ -2,7 +2,7 @@ import imgui.ImFontGlyphRangesBuilder; import imgui.ImGui; import imgui.ImGuiIO; -import imgui.app.Application; +import imgui.app.BGFXWindow; import imgui.app.Configuration; import imgui.flag.ImGuiConfigFlags; import imgui.flag.ImGuiInputTextFlags; @@ -14,7 +14,7 @@ import java.nio.file.Files; import java.nio.file.Paths; -public class Main extends Application { +public class Main extends BGFXWindow { private final ImString str = new ImString(5); private final float[] flt = new float[1]; private int count = 0; diff --git a/imgui-app/src/main/java/imgui/app/Application.java b/imgui-app/src/main/java/imgui/app/Application.java index 37d641d3..4b6f91a1 100644 --- a/imgui-app/src/main/java/imgui/app/Application.java +++ b/imgui-app/src/main/java/imgui/app/Application.java @@ -52,14 +52,16 @@ * For example, large list of computations could be separated between application ticks. {@link #process()} method is called constantly. * Use that wisely and remember that all GUI should be in the main thread. */ -public abstract class Application extends Window { +public abstract class Application { + + protected abstract void init(Configuration config); + /** * Method called before window creation. Could be used to provide basic window information, like title name etc. * * @param config configuration object with basic window information */ - protected void configure(final Configuration config) { - } + protected abstract void configure(final Configuration config); /** * Method called once, before application run loop. @@ -67,12 +69,16 @@ protected void configure(final Configuration config) { protected void preRun() { } + protected abstract void run(); + /** * Method called once, after application run loop. */ protected void postRun() { } + protected abstract void dispose(); + /** * Entry point of any ImGui application. Use it to start the application loop. * @@ -91,4 +97,6 @@ private static void initialize(final Application app) { app.configure(config); app.init(config); } + + public abstract Color getColorBg(); } diff --git a/imgui-app/src/main/java/imgui/app/BGFXWindow.java b/imgui-app/src/main/java/imgui/app/BGFXWindow.java index c17a4350..a85881b1 100644 --- a/imgui-app/src/main/java/imgui/app/BGFXWindow.java +++ b/imgui-app/src/main/java/imgui/app/BGFXWindow.java @@ -20,7 +20,7 @@ import static org.lwjgl.system.Configuration.GLFW_LIBRARY_NAME; import static org.lwjgl.system.MemoryStack.stackPush; -public abstract class BGFXWindow { +public abstract class BGFXWindow extends Application { private final ImGuiImplBGFX imGuiBGFX = new ImGuiImplBGFX(); private final ImGuiImplGlfw imGuiGlfw = new ImGuiImplGlfw(); diff --git a/imgui-app/src/main/java/imgui/app/Window.java b/imgui-app/src/main/java/imgui/app/Window.java index b04f2bdd..4650c96d 100644 --- a/imgui-app/src/main/java/imgui/app/Window.java +++ b/imgui-app/src/main/java/imgui/app/Window.java @@ -22,7 +22,7 @@ * It's recommended to use {@link Application}, but this class could be extended directly as well. * When extended, life-cycle methods should be called manually. */ -public abstract class Window { +public abstract class Window extends Application { private final ImGuiImplGlfw imGuiGlfw = new ImGuiImplGlfw(); private final ImGuiImplGl3 imGuiGl3 = new ImGuiImplGl3(); @@ -44,7 +44,7 @@ public abstract class Window { * * @param config configuration object with basic window information */ - protected void init(final Configuration config) { + public final void init(final Configuration config) { initWindow(config); initImGui(config); imGuiGlfw.init(handle, true); @@ -54,7 +54,7 @@ protected void init(final Configuration config) { /** * Method to dispose all used application resources and destroy its window. */ - protected void dispose() { + public final void dispose() { imGuiGl3.dispose(); imGuiGlfw.dispose(); disposeImGui();