From 13c3a28f09f486ac4bd92bd43649d89e152a154e Mon Sep 17 00:00:00 2001 From: SpaiR Date: Sun, 30 Aug 2020 22:07:09 +0300 Subject: [PATCH] [API] Add ImGuiPlatformMonitor --- .../src/main/java/imgui/ImGuiPlatformIO.java | 10 ++ .../main/java/imgui/ImGuiPlatformMonitor.java | 153 ++++++++++++++++++ .../main/java/imgui/glfw/ImGuiImplGlfw.java | 2 + 3 files changed, 165 insertions(+) create mode 100644 imgui-binding/src/main/java/imgui/ImGuiPlatformMonitor.java diff --git a/imgui-binding/src/main/java/imgui/ImGuiPlatformIO.java b/imgui-binding/src/main/java/imgui/ImGuiPlatformIO.java index f3edc9f..fd42d08 100644 --- a/imgui-binding/src/main/java/imgui/ImGuiPlatformIO.java +++ b/imgui-binding/src/main/java/imgui/ImGuiPlatformIO.java @@ -72,6 +72,7 @@ import imgui.callback.ImPlatformFuncViewportSuppImVec2; public final class ImGuiPlatformIO extends ImGuiStruct { private static final ImGuiViewport MAIN_VIEWPORT = new ImGuiViewport(0); private static final ImGuiViewport TMP_VIEWPORT = new ImGuiViewport(0); + private static final ImGuiPlatformMonitor TMP_MONITOR = new ImGuiPlatformMonitor(0); private static final ImVec2 TMP_IM_VEC2 = new ImVec2(); public ImGuiPlatformIO(final long ptr) { @@ -517,6 +518,15 @@ public final class ImGuiPlatformIO extends ImGuiStruct { IMGUI_PLATFORM_IO->Monitors.push_back(monitor); */ + public ImGuiPlatformMonitor getMonitors(final int idx) { + TMP_MONITOR.ptr = nGetMonitors(idx); + return TMP_MONITOR; + } + + private native long nGetMonitors(int idx); /* + return (intptr_t)&IMGUI_PLATFORM_IO->Monitors[idx]; + */ + // Viewports list (the list is updated by calling ImGui::EndFrame or ImGui::Render) // (in the future we will attempt to organize this feature to remove the need for a "main viewport") diff --git a/imgui-binding/src/main/java/imgui/ImGuiPlatformMonitor.java b/imgui-binding/src/main/java/imgui/ImGuiPlatformMonitor.java new file mode 100644 index 0000000..95f9f7b --- /dev/null +++ b/imgui-binding/src/main/java/imgui/ImGuiPlatformMonitor.java @@ -0,0 +1,153 @@ +package imgui; + +import imgui.binding.ImGuiStruct; + +/** + * (Optional) This is required when enabling multi-viewport. Represent the bounds of each connected monitor/display and their DPI. + * We use this information for multiple DPI support + clamping the position of popups and tooltips so they don't straddle multiple monitors. + */ +public final class ImGuiPlatformMonitor extends ImGuiStruct { + public ImGuiPlatformMonitor(final long ptr) { + super(ptr); + } + + /*JNI + #include + #include + #include "jni_common.h" + #include "jni_binding_struct.h" + + #define IMGUI_PLATFORM_MONITOR ((ImGuiPlatformMonitor*)STRUCT_PTR) + */ + + /** + * Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right) + */ + public native void getMainPos(ImVec2 dstImVec2); /* + Jni::ImVec2Cpy(env, &IMGUI_PLATFORM_MONITOR->MainPos, dstImVec2); + */ + + /** + * Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right) + */ + public native float getMainPosX(); /* + return IMGUI_PLATFORM_MONITOR->MainPos.x; + */ + + /** + * Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right) + */ + public native float getMainPosY(); /* + return IMGUI_PLATFORM_MONITOR->MainPos.y; + */ + + public native void setMainPos(float x, float y); /* + IMGUI_PLATFORM_MONITOR->MainPos = ImVec2(x, y); + */ + + /** + * Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right) + */ + public native void getMainSize(ImVec2 dstImVec2); /* + Jni::ImVec2Cpy(env, &IMGUI_PLATFORM_MONITOR->MainSize, dstImVec2); + */ + + /** + * Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right) + */ + public native float getMainSizeX(); /* + return IMGUI_PLATFORM_MONITOR->MainSize.x; + */ + + /** + * Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right) + */ + public native float getMainSizeY(); /* + return IMGUI_PLATFORM_MONITOR->MainSize.y; + */ + + /** + * Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right) + */ + public native void setMainSize(float x, float y); /* + IMGUI_PLATFORM_MONITOR->MainSize = ImVec2(x, y); + */ + + /** + * Coordinates without task bars / side bars / menu bars. + * Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize. + */ + public native void getWorkPos(ImVec2 dstImVec2); /* + Jni::ImVec2Cpy(env, &IMGUI_PLATFORM_MONITOR->WorkPos, dstImVec2); + */ + + /** + * Coordinates without task bars / side bars / menu bars. + * Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize. + */ + public native float getWorkPosX(); /* + return IMGUI_PLATFORM_MONITOR->WorkPos.x; + */ + + /** + * Coordinates without task bars / side bars / menu bars. + * Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize. + */ + public native float getWorkPosY(); /* + return IMGUI_PLATFORM_MONITOR->WorkPos.y; + */ + + /** + * Coordinates without task bars / side bars / menu bars. + * Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize. + */ + public native void setWorkPos(float x, float y); /* + IMGUI_PLATFORM_MONITOR->WorkPos = ImVec2(x, y); + */ + + /** + * Coordinates without task bars / side bars / menu bars. + * Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize. + */ + public native void getWorkSize(ImVec2 dstImVec2); /* + Jni::ImVec2Cpy(env, &IMGUI_PLATFORM_MONITOR->WorkSize, dstImVec2); + */ + + /** + * Coordinates without task bars / side bars / menu bars. + * Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize. + */ + public native float getWorkSizeX(); /* + return IMGUI_PLATFORM_MONITOR->WorkSize.x; + */ + + /** + * Coordinates without task bars / side bars / menu bars. + * Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize. + */ + public native float getWorkSizeY(); /* + return IMGUI_PLATFORM_MONITOR->WorkSize.y; + */ + + /** + * Coordinates without task bars / side bars / menu bars. + * Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize. + */ + public native void setWorkSize(float x, float y); /* + IMGUI_PLATFORM_MONITOR->WorkSize = ImVec2(x, y); + */ + + /** + * 1.0f = 96 DPI + */ + public native float getDpiScale(); /* + return IMGUI_PLATFORM_MONITOR->DpiScale; + */ + + /** + * 1.0f = 96 DPI + */ + public native void setDpiScale(float dpiScale); /* + IMGUI_PLATFORM_MONITOR->DpiScale = dpiScale; + */ +} diff --git a/imgui-lwjgl3/src/main/java/imgui/glfw/ImGuiImplGlfw.java b/imgui-lwjgl3/src/main/java/imgui/glfw/ImGuiImplGlfw.java index 9faed6f..d3c6e4c 100644 --- a/imgui-lwjgl3/src/main/java/imgui/glfw/ImGuiImplGlfw.java +++ b/imgui-lwjgl3/src/main/java/imgui/glfw/ImGuiImplGlfw.java @@ -70,6 +70,7 @@ public class ImGuiImplGlfw { private final int[] windowX = new int[1]; private final int[] windowY = new int[1]; + // Monitor properties private final int[] monitorX = new int[1]; private final int[] monitorY = new int[1]; private final int[] monitorWorkAreaX = new int[1]; @@ -86,6 +87,7 @@ public class ImGuiImplGlfw { private GLFWCharCallback prevUserCallbackChar = null; private GLFWMonitorCallback prevUserCallbackMonitor = null; + // Internal data private boolean callbacksInstalled = false; private boolean wantUpdateMonitors = true; private double time = 0.0;