Skip to content

Commit e328d73

Browse files
committed
[WIP] Viewports backend
1 parent 8494bd8 commit e328d73

File tree

16 files changed

+678
-179
lines changed

16 files changed

+678
-179
lines changed

bin/imgui-java.dll

24.5 KB
Binary file not shown.

bin/imgui-java64.dll

27.5 KB
Binary file not shown.

bin/libimgui-java.so

36.1 KB
Binary file not shown.

bin/libimgui-java64.so

36.2 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
BASEDIR=$(dirname "$0")
4+
cd $BASEDIR/../../imgui-binding || exit
5+
6+
rm -frd /tmp/imgui
7+
../gradlew clean generateLibs -Denvs=win64

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5439,7 +5439,7 @@ public static ImGuiPlatformIO getPlatformIO() {
54395439
}
54405440

54415441
private static native long nGetPlatformIO(); /*
5442-
return (intptr_t)ImGui::GetMainViewport();
5442+
return (intptr_t)&ImGui::GetPlatformIO();
54435443
*/
54445444

54455445
/**
@@ -5491,4 +5491,16 @@ public static ImGuiViewport findViewportByID(int imGuiID) {
54915491
private static native long nFindViewportByID(int imGuiID); /*
54925492
return (intptr_t)ImGui::FindViewportByID(imGuiID);
54935493
*/
5494+
5495+
/**
5496+
* This is a helper for back-ends. The type platform_handle is decided by the back-end (e.g. HWND, MyWindow*, GLFWwindow* etc.)
5497+
*/
5498+
public static ImGuiViewport findViewportByPlatformHandle(long platformHandle) {
5499+
FIND_VIEWPORT.ptr = nFindViewportByPlatformHandle(platformHandle);
5500+
return FIND_VIEWPORT;
5501+
}
5502+
5503+
private static native long nFindViewportByPlatformHandle(long platformHandle); /*
5504+
return (intptr_t)ImGui::FindViewportByPlatformHandle((void*)platformHandle);
5505+
*/
54945506
}

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ public void setFontDefault(final ImFont fontDefault) {
390390
* Optional: Platform back-end name (informational only! will be displayed in About Window) + User data for back-end/wrappers to store their own stuff.
391391
*/
392392
public native String getBackendPlatformName(); /*
393-
return env -> NewStringUTF(ImGui::GetIO().BackendPlatformName);
393+
return env->NewStringUTF(ImGui::GetIO().BackendPlatformName);
394394
*/
395395

396396
/**
@@ -404,7 +404,7 @@ public void setFontDefault(final ImFont fontDefault) {
404404
* Optional: Renderer back-end name (informational only! will be displayed in About Window) + User data for back-end/wrappers to store their own stuff.
405405
*/
406406
public native String getBackendRendererName(); /*
407-
return env -> NewStringUTF(ImGui::GetIO().BackendRendererName);
407+
return env->NewStringUTF(ImGui::GetIO().BackendRendererName);
408408
*/
409409

410410
/**
@@ -699,6 +699,24 @@ void setClipboardTextStub(void* userData, const char* text) {
699699
ImGui::GetIO().MouseWheelH = mouseDeltaX;
700700
*/
701701

702+
/**
703+
* (Optional) When using multiple viewports: viewport the OS mouse cursor is hovering _IGNORING_ viewports with the ImGuiViewportFlags_NoInputs flag,
704+
* and _REGARDLESS_ of whether another viewport is focused. Set io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport if you can provide this info.
705+
* If you don't imgui will infer the value using the rectangles and last focused time of the viewports it knows about (ignoring other OS windows).
706+
*/
707+
public native float getMouseHoveredViewport(); /*
708+
return ImGui::GetIO().MouseHoveredViewport;
709+
*/
710+
711+
/**
712+
* (Optional) When using multiple viewports: viewport the OS mouse cursor is hovering _IGNORING_ viewports with the ImGuiViewportFlags_NoInputs flag,
713+
* and _REGARDLESS_ of whether another viewport is focused. Set io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport if you can provide this info.
714+
* If you don't imgui will infer the value using the rectangles and last focused time of the viewports it knows about (ignoring other OS windows).
715+
*/
716+
public native void setMouseHoveredViewport(int imGuiId); /*
717+
ImGui::GetIO().MouseHoveredViewport = imGuiId;
718+
*/
719+
702720
/**
703721
* Keyboard modifier pressed: Control
704722
*/

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

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
* Platform functions are typically called before their Renderer counterpart, apart from Destroy which are called the other way.
7171
*/
7272
public final class ImGuiPlatformIO extends ImGuiStruct {
73+
private static final ImGuiViewport MAIN_VIEWPORT = new ImGuiViewport(0);
7374
private static final ImGuiViewport TMP_VIEWPORT = new ImGuiViewport(0);
7475
private static final ImVec2 TMP_IM_VEC2 = new ImVec2();
7576

@@ -307,7 +308,7 @@ void PlatformStubSetWindowTitle(ImGuiViewport* vp, const char* str) {
307308
IMGUI_PLATFORM_IO->Platform_SetWindowTitle = PlatformStubSetWindowTitle;
308309
*/
309310

310-
/*JNI
311+
/*JNI
311312
jobject platformCallbackSetWindowAlpha = NULL;
312313
void PlatformStubSetWindowAlpha(ImGuiViewport* vp, float alpha) {
313314
if (platformCallbackSetWindowAlpha != NULL) {
@@ -485,4 +486,62 @@ void RendererStubSetWindowSize(ImGuiViewport* vp, ImVec2 pos) {
485486
public native void setRendererSwapBuffers(ImPlatformFuncViewport func); /*
486487
IM_RENDERER_FUNC_VIEWPORT_METHOD_TMPL(SwapBuffers)
487488
*/
489+
490+
// (Optional) Monitor list
491+
// - Updated by: app/back-end. Update every frame to dynamically support changing monitor or DPI configuration.
492+
// - Used by: dear imgui to query DPI info, clamp popups/tooltips within same monitor and not have them straddle monitors.
493+
494+
//------------------------------------------------------------------
495+
// Output - List of viewports to render into platform windows
496+
//------------------------------------------------------------------
497+
498+
public native void resizeMonitors(int size); /*
499+
IMGUI_PLATFORM_IO->Monitors.resize(0);
500+
*/
501+
502+
public native int getMonitorsSize(); /*
503+
return IMGUI_PLATFORM_IO->Monitors.Size;
504+
*/
505+
506+
public native void pushMonitors(float mainPosX, float mainPosY, float mainSizeX, float mainSizeY, float workPosX, float workPosY, float workSizeX, float workSizeY, float dpiScale); /*
507+
ImGuiPlatformMonitor monitor;
508+
509+
monitor.MainPos = ImVec2(mainPosX, mainPosY);
510+
monitor.MainSize = ImVec2(mainSizeX, mainSizeY);
511+
512+
monitor.WorkPos = ImVec2(workPosX, workPosY);
513+
monitor.WorkSize = ImVec2(workSizeX, workSizeY);
514+
515+
monitor.DpiScale = dpiScale;
516+
517+
IMGUI_PLATFORM_IO->Monitors.push_back(monitor);
518+
*/
519+
520+
// Viewports list (the list is updated by calling ImGui::EndFrame or ImGui::Render)
521+
// (in the future we will attempt to organize this feature to remove the need for a "main viewport")
522+
523+
/**
524+
* Guaranteed to be == Viewports[0]
525+
*/
526+
public ImGuiViewport getMainViewport() {
527+
MAIN_VIEWPORT.ptr = nGetMainViewport();
528+
return MAIN_VIEWPORT;
529+
}
530+
531+
private native long nGetMainViewport(); /*
532+
return (intptr_t)IMGUI_PLATFORM_IO->MainViewport;
533+
*/
534+
535+
public native int getViewportsSize(); /*
536+
return IMGUI_PLATFORM_IO->Viewports.Size;
537+
*/
538+
539+
public ImGuiViewport getViewports(final int idx) {
540+
TMP_VIEWPORT.ptr = nGetViewports(idx);
541+
return TMP_VIEWPORT;
542+
}
543+
544+
private native long nGetViewports(int idx); /*
545+
return (intptr_t)IMGUI_PLATFORM_IO->Viewports[idx];
546+
*/
488547
}

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

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,67 @@ public ImDrawData getDrawData() {
212212
// by the same system and you may not need to use all the UserData/Handle fields.
213213
// The library never uses those fields, they are merely storage to facilitate back-end implementation.
214214

215-
// TODO: PlatformUserData, PlatformHandle, PlatformHandleRaw
215+
/**
216+
* void* to hold custom data structure for the renderer (e.g. swap chain, framebuffers etc.). generally set by your Renderer_CreateWindow function.
217+
*/
218+
public native void setRendererUserData(Object data); /*
219+
if (IMGUI_VIEWPORT->RendererUserData != NULL) {
220+
env->DeleteGlobalRef((jobject)IMGUI_VIEWPORT->RendererUserData);
221+
}
222+
IMGUI_VIEWPORT->RendererUserData = (data == NULL ? NULL : (void*)env->NewGlobalRef(data));
223+
*/
224+
225+
/**
226+
* void* to hold custom data structure for the renderer (e.g. swap chain, framebuffers etc.). generally set by your Renderer_CreateWindow function.
227+
*/
228+
public native Object getRendererUserData(); /*
229+
return (jobject)IMGUI_VIEWPORT->RendererUserData;
230+
*/
231+
232+
/**
233+
* void* to hold custom data structure for the OS / platform (e.g. windowing info, render context). generally set by your Platform_CreateWindow function.
234+
*/
235+
public native void setPlatformUserData(Object data); /*
236+
if (IMGUI_VIEWPORT->PlatformUserData != NULL) {
237+
env->DeleteGlobalRef((jobject)IMGUI_VIEWPORT->PlatformUserData);
238+
}
239+
IMGUI_VIEWPORT->PlatformUserData = (data == NULL ? NULL : (void*)env->NewGlobalRef(data));
240+
*/
241+
242+
/**
243+
* void* to hold custom data structure for the OS / platform (e.g. windowing info, render context). generally set by your Platform_CreateWindow function.
244+
*/
245+
public native Object getPlatformUserData(); /*
246+
return (jobject)IMGUI_VIEWPORT->PlatformUserData;
247+
*/
248+
249+
/**
250+
* void* for FindViewportByPlatformHandle(). (e.g. suggested to use natural platform handle such as HWND, GLFWWindow*, SDL_Window*)
251+
*/
252+
public native void setPlatformHandle(long data); /*
253+
IMGUI_VIEWPORT->PlatformHandle = (void*)data;
254+
*/
255+
256+
/**
257+
* void* for FindViewportByPlatformHandle(). (e.g. suggested to use natural platform handle such as HWND, GLFWWindow*, SDL_Window*)
258+
*/
259+
public native long getPlatformHandle(); /*
260+
return (intptr_t)IMGUI_VIEWPORT->PlatformHandle;
261+
*/
262+
263+
/**
264+
* void* to hold lower-level, platform-native window handle (e.g. the HWND) when using an abstraction layer like GLFW or SDL (where PlatformHandle would be a SDL_Window*)
265+
*/
266+
public native void setPlatformHandleRaw(long data); /*
267+
IMGUI_VIEWPORT->PlatformHandleRaw = (void*)data;
268+
*/
269+
270+
/**
271+
* void* to hold lower-level, platform-native window handle (e.g. the HWND) when using an abstraction layer like GLFW or SDL (where PlatformHandle would be a SDL_Window*)
272+
*/
273+
public native long getPlatformHandleRaw(); /*
274+
return (intptr_t)IMGUI_VIEWPORT->PlatformHandleRaw;
275+
*/
216276

217277
/**
218278
* Platform window requested move (e.g. window was moved by the OS / host window manager, authoritative position will be OS window position).

imgui-binding/src/main/java/imgui/callback/ImPlatformFuncViewportFloat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
* Callback to represent ImGuiPlatformIO function with args: (ImGuiViewport*, String)
77
*/
88
public abstract class ImPlatformFuncViewportFloat {
9-
public abstract void accept(ImGuiViewport vp, Float f);
9+
public abstract void accept(ImGuiViewport vp, float f);
1010
}

0 commit comments

Comments
 (0)