Skip to content

Commit 8494bd8

Browse files
committed
Add ImPlatformIO, ImGuiViewport
1 parent dce574e commit 8494bd8

14 files changed

+773
-5
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public final class ImDrawData extends ImGuiStruct {
2121

2222
private static ByteBuffer dataBuffer = ByteBuffer.allocateDirect(25_000).order(ByteOrder.nativeOrder());
2323

24+
private static final ImGuiViewport OWNER_VIEWPORT = new ImGuiViewport(0);
25+
2426
public ImDrawData(final long ptr) {
2527
super(ptr);
2628
}
@@ -229,6 +231,18 @@ public ByteBuffer getCmdListVtxBufferData(final int cmdListIdx) {
229231
return IM_DRAW_DATA->FramebufferScale.y;
230232
*/
231233

234+
/**
235+
* Viewport carrying the ImDrawData instance, might be of use to the renderer (generally not).
236+
*/
237+
public ImGuiViewport getOwnerViewport() {
238+
OWNER_VIEWPORT.ptr = nGetOwnerViewport();
239+
return OWNER_VIEWPORT;
240+
}
241+
242+
private native long nGetOwnerViewport(); /*
243+
return (intptr_t)IM_DRAW_DATA->OwnerViewport;
244+
*/
245+
232246
// Functions
233247

234248
/**

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

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ public final class ImGui {
2929
private static final ImDrawList BACKGROUND_DRAW_LIST;
3030
private static final ImDrawList FOREGROUND_DRAW_LIST;
3131
private static final ImGuiStorage IMGUI_STORAGE;
32+
private static final ImGuiViewport WINDOW_VIEWPORT;
33+
private static final ImGuiViewport FIND_VIEWPORT;
3234

3335
private static ImDrawData drawData;
3436
private static ImFont font;
3537
private static ImGuiStyle style;
38+
private static ImGuiViewport mainViewport;
39+
private static ImGuiPlatformIO platformIO;
3640

3741
static {
3842
final String libPath = System.getProperty(LIB_PATH_PROP);
@@ -54,9 +58,12 @@ public final class ImGui {
5458
BACKGROUND_DRAW_LIST = new ImDrawList(0);
5559
FOREGROUND_DRAW_LIST = new ImDrawList(0);
5660
IMGUI_STORAGE = new ImGuiStorage(0);
61+
WINDOW_VIEWPORT = new ImGuiViewport(0);
62+
FIND_VIEWPORT = new ImGuiViewport(0);
5763

5864
nInitJni();
5965
ImFontAtlas.nInit();
66+
ImGuiPlatformIO.init();
6067
nInitInputTextData();
6168
}
6269

@@ -494,6 +501,18 @@ public static ImDrawList getWindowDrawList() {
494501
return ImGui::GetWindowDpiScale();
495502
*/
496503

504+
/**
505+
* Get viewport currently associated to the current window.
506+
*/
507+
public static ImGuiViewport getWindowViewport() {
508+
WINDOW_VIEWPORT.ptr = nGetWindowViewport();
509+
return WINDOW_VIEWPORT;
510+
}
511+
512+
private static native long nGetWindowViewport(); /*
513+
return (intptr_t)ImGui::GetWindowViewport();
514+
*/
515+
497516
/**
498517
* Get current window position in screen space (useful if you want to do your own drawing via the DrawList API)
499518
*/
@@ -4918,6 +4937,32 @@ public static ImDrawList getForegroundDrawList() {
49184937
return (intptr_t)ImGui::GetForegroundDrawList();
49194938
*/
49204939

4940+
/**
4941+
* Get background draw list for the given viewport.
4942+
* This draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents.
4943+
*/
4944+
public static ImDrawList getBackgroundDrawList(ImGuiViewport viewport) {
4945+
BACKGROUND_DRAW_LIST.ptr = nGetBackgroundDrawList(viewport.ptr);
4946+
return BACKGROUND_DRAW_LIST;
4947+
}
4948+
4949+
private static native long nGetBackgroundDrawList(long viewportPtr); /*
4950+
return (intptr_t)ImGui::GetBackgroundDrawList((ImGuiViewport*)viewportPtr);
4951+
*/
4952+
4953+
/**
4954+
* Get foreground draw list for the given viewport.
4955+
* This draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents.
4956+
*/
4957+
public static ImDrawList getForegroundDrawList(ImGuiViewport viewport) {
4958+
BACKGROUND_DRAW_LIST.ptr = nGetForegroundDrawList(viewport.ptr);
4959+
return BACKGROUND_DRAW_LIST;
4960+
}
4961+
4962+
private static native long nGetForegroundDrawList(long viewportPtr); /*
4963+
return (intptr_t)ImGui::GetBackgroundDrawList((ImGuiViewport*)viewportPtr);
4964+
*/
4965+
49214966
// TODO GetDrawListSharedData
49224967

49234968
/**
@@ -5378,4 +5423,72 @@ public static ImGuiStorage getStateStorage() {
53785423
public static native String saveIniSettingsToMemory(long outIniSize); /*
53795424
return env->NewStringUTF(ImGui::SaveIniSettingsToMemory((size_t*)&outIniSize));
53805425
*/
5426+
5427+
// (Optional) Platform/OS interface for multi-viewport support
5428+
// Read comments around the ImGuiPlatformIO structure for more details.
5429+
// Note: You may use GetWindowViewport() to get the current viewport of the current window.
5430+
5431+
/**
5432+
* Platform/renderer functions, for back-end to setup + viewports list.
5433+
*/
5434+
public static ImGuiPlatformIO getPlatformIO() {
5435+
if (platformIO == null) {
5436+
platformIO = new ImGuiPlatformIO(nGetPlatformIO());
5437+
}
5438+
return platformIO;
5439+
}
5440+
5441+
private static native long nGetPlatformIO(); /*
5442+
return (intptr_t)ImGui::GetMainViewport();
5443+
*/
5444+
5445+
/**
5446+
* Main viewport. Same as GetPlatformIO().MainViewport == GetPlatformIO().Viewports[0].
5447+
*/
5448+
public static ImGuiViewport getMainViewport() {
5449+
if (mainViewport == null) {
5450+
mainViewport = new ImGuiViewport(nGetMainViewport());
5451+
}
5452+
return mainViewport;
5453+
}
5454+
5455+
private static native long nGetMainViewport(); /*
5456+
return (intptr_t)ImGui::GetMainViewport();
5457+
*/
5458+
5459+
/**
5460+
* Call in main loop. Will call CreateWindow/ResizeWindow/etc. Platform functions for each secondary viewport, and DestroyWindow for each inactive viewport.
5461+
*/
5462+
public static native void updatePlatformWindows(); /*
5463+
ImGui::UpdatePlatformWindows();
5464+
*/
5465+
5466+
/**
5467+
* Call in main loop. will call RenderWindow/SwapBuffers platform functions for each secondary viewport which doesn't have the ImGuiViewportFlags_Minimized flag set.
5468+
* May be reimplemented by user for custom rendering needs.
5469+
*/
5470+
public static native void renderPlatformWindowsDefault(); /*
5471+
ImGui::RenderPlatformWindowsDefault();
5472+
*/
5473+
5474+
/**
5475+
* Call DestroyWindow platform functions for all viewports.
5476+
* Call from back-end Shutdown() if you need to close platform windows before imgui shutdown.
5477+
* Otherwise will be called by DestroyContext().
5478+
*/
5479+
public static native void destroyPlatformWindows(); /*
5480+
ImGui::DestroyPlatformWindows();
5481+
*/
5482+
5483+
/**
5484+
* This is a helper for back-ends.
5485+
*/
5486+
public static ImGuiViewport findViewportByID(int imGuiID) {
5487+
FIND_VIEWPORT.ptr = nFindViewportByID(imGuiID);
5488+
return FIND_VIEWPORT;
5489+
}
5490+
5491+
private static native long nFindViewportByID(int imGuiID); /*
5492+
return (intptr_t)ImGui::FindViewportByID(imGuiID);
5493+
*/
53815494
}

0 commit comments

Comments
 (0)