Skip to content

Commit 13c3a28

Browse files
committed
[API] Add ImGuiPlatformMonitor
1 parent b065d00 commit 13c3a28

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed

imgui-binding/src/main/java/imgui/ImGuiPlatformIO.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
public final class ImGuiPlatformIO extends ImGuiStruct {
7373
private static final ImGuiViewport MAIN_VIEWPORT = new ImGuiViewport(0);
7474
private static final ImGuiViewport TMP_VIEWPORT = new ImGuiViewport(0);
75+
private static final ImGuiPlatformMonitor TMP_MONITOR = new ImGuiPlatformMonitor(0);
7576
private static final ImVec2 TMP_IM_VEC2 = new ImVec2();
7677

7778
public ImGuiPlatformIO(final long ptr) {
@@ -517,6 +518,15 @@ void RendererStubSetWindowSize(ImGuiViewport* vp, ImVec2 pos) {
517518
IMGUI_PLATFORM_IO->Monitors.push_back(monitor);
518519
*/
519520

521+
public ImGuiPlatformMonitor getMonitors(final int idx) {
522+
TMP_MONITOR.ptr = nGetMonitors(idx);
523+
return TMP_MONITOR;
524+
}
525+
526+
private native long nGetMonitors(int idx); /*
527+
return (intptr_t)&IMGUI_PLATFORM_IO->Monitors[idx];
528+
*/
529+
520530
// Viewports list (the list is updated by calling ImGui::EndFrame or ImGui::Render)
521531
// (in the future we will attempt to organize this feature to remove the need for a "main viewport")
522532

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
package imgui;
2+
3+
import imgui.binding.ImGuiStruct;
4+
5+
/**
6+
* (Optional) This is required when enabling multi-viewport. Represent the bounds of each connected monitor/display and their DPI.
7+
* We use this information for multiple DPI support + clamping the position of popups and tooltips so they don't straddle multiple monitors.
8+
*/
9+
public final class ImGuiPlatformMonitor extends ImGuiStruct {
10+
public ImGuiPlatformMonitor(final long ptr) {
11+
super(ptr);
12+
}
13+
14+
/*JNI
15+
#include <stdint.h>
16+
#include <imgui.h>
17+
#include "jni_common.h"
18+
#include "jni_binding_struct.h"
19+
20+
#define IMGUI_PLATFORM_MONITOR ((ImGuiPlatformMonitor*)STRUCT_PTR)
21+
*/
22+
23+
/**
24+
* Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right)
25+
*/
26+
public native void getMainPos(ImVec2 dstImVec2); /*
27+
Jni::ImVec2Cpy(env, &IMGUI_PLATFORM_MONITOR->MainPos, dstImVec2);
28+
*/
29+
30+
/**
31+
* Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right)
32+
*/
33+
public native float getMainPosX(); /*
34+
return IMGUI_PLATFORM_MONITOR->MainPos.x;
35+
*/
36+
37+
/**
38+
* Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right)
39+
*/
40+
public native float getMainPosY(); /*
41+
return IMGUI_PLATFORM_MONITOR->MainPos.y;
42+
*/
43+
44+
public native void setMainPos(float x, float y); /*
45+
IMGUI_PLATFORM_MONITOR->MainPos = ImVec2(x, y);
46+
*/
47+
48+
/**
49+
* Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right)
50+
*/
51+
public native void getMainSize(ImVec2 dstImVec2); /*
52+
Jni::ImVec2Cpy(env, &IMGUI_PLATFORM_MONITOR->MainSize, dstImVec2);
53+
*/
54+
55+
/**
56+
* Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right)
57+
*/
58+
public native float getMainSizeX(); /*
59+
return IMGUI_PLATFORM_MONITOR->MainSize.x;
60+
*/
61+
62+
/**
63+
* Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right)
64+
*/
65+
public native float getMainSizeY(); /*
66+
return IMGUI_PLATFORM_MONITOR->MainSize.y;
67+
*/
68+
69+
/**
70+
* Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right)
71+
*/
72+
public native void setMainSize(float x, float y); /*
73+
IMGUI_PLATFORM_MONITOR->MainSize = ImVec2(x, y);
74+
*/
75+
76+
/**
77+
* Coordinates without task bars / side bars / menu bars.
78+
* Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize.
79+
*/
80+
public native void getWorkPos(ImVec2 dstImVec2); /*
81+
Jni::ImVec2Cpy(env, &IMGUI_PLATFORM_MONITOR->WorkPos, dstImVec2);
82+
*/
83+
84+
/**
85+
* Coordinates without task bars / side bars / menu bars.
86+
* Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize.
87+
*/
88+
public native float getWorkPosX(); /*
89+
return IMGUI_PLATFORM_MONITOR->WorkPos.x;
90+
*/
91+
92+
/**
93+
* Coordinates without task bars / side bars / menu bars.
94+
* Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize.
95+
*/
96+
public native float getWorkPosY(); /*
97+
return IMGUI_PLATFORM_MONITOR->WorkPos.y;
98+
*/
99+
100+
/**
101+
* Coordinates without task bars / side bars / menu bars.
102+
* Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize.
103+
*/
104+
public native void setWorkPos(float x, float y); /*
105+
IMGUI_PLATFORM_MONITOR->WorkPos = ImVec2(x, y);
106+
*/
107+
108+
/**
109+
* Coordinates without task bars / side bars / menu bars.
110+
* Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize.
111+
*/
112+
public native void getWorkSize(ImVec2 dstImVec2); /*
113+
Jni::ImVec2Cpy(env, &IMGUI_PLATFORM_MONITOR->WorkSize, dstImVec2);
114+
*/
115+
116+
/**
117+
* Coordinates without task bars / side bars / menu bars.
118+
* Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize.
119+
*/
120+
public native float getWorkSizeX(); /*
121+
return IMGUI_PLATFORM_MONITOR->WorkSize.x;
122+
*/
123+
124+
/**
125+
* Coordinates without task bars / side bars / menu bars.
126+
* Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize.
127+
*/
128+
public native float getWorkSizeY(); /*
129+
return IMGUI_PLATFORM_MONITOR->WorkSize.y;
130+
*/
131+
132+
/**
133+
* Coordinates without task bars / side bars / menu bars.
134+
* Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize.
135+
*/
136+
public native void setWorkSize(float x, float y); /*
137+
IMGUI_PLATFORM_MONITOR->WorkSize = ImVec2(x, y);
138+
*/
139+
140+
/**
141+
* 1.0f = 96 DPI
142+
*/
143+
public native float getDpiScale(); /*
144+
return IMGUI_PLATFORM_MONITOR->DpiScale;
145+
*/
146+
147+
/**
148+
* 1.0f = 96 DPI
149+
*/
150+
public native void setDpiScale(float dpiScale); /*
151+
IMGUI_PLATFORM_MONITOR->DpiScale = dpiScale;
152+
*/
153+
}

imgui-lwjgl3/src/main/java/imgui/glfw/ImGuiImplGlfw.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public class ImGuiImplGlfw {
7070
private final int[] windowX = new int[1];
7171
private final int[] windowY = new int[1];
7272

73+
// Monitor properties
7374
private final int[] monitorX = new int[1];
7475
private final int[] monitorY = new int[1];
7576
private final int[] monitorWorkAreaX = new int[1];
@@ -86,6 +87,7 @@ public class ImGuiImplGlfw {
8687
private GLFWCharCallback prevUserCallbackChar = null;
8788
private GLFWMonitorCallback prevUserCallbackMonitor = null;
8889

90+
// Internal data
8991
private boolean callbacksInstalled = false;
9092
private boolean wantUpdateMonitors = true;
9193
private double time = 0.0;

0 commit comments

Comments
 (0)