[WIP] Viewports backend

This commit is contained in:
SpaiR committed 2020-08-30 15:47:27 +03:00
1 parent 8494bd8361
commit e328d738ce
16 files changed
+676 -177

No files matched your search

+13 -1
View File
@@ -5439,7 +5439,7 @@ public final class ImGui {
}
private static native long nGetPlatformIO(); /*
return (intptr_t)ImGui::GetMainViewport();
return (intptr_t)&ImGui::GetPlatformIO();
*/
/**
@@ -5491,4 +5491,16 @@ public final class ImGui {
private static native long nFindViewportByID(int imGuiID); /*
return (intptr_t)ImGui::FindViewportByID(imGuiID);
*/
/**
* This is a helper for back-ends. The type platform_handle is decided by the back-end (e.g. HWND, MyWindow*, GLFWwindow* etc.)
*/
public static ImGuiViewport findViewportByPlatformHandle(long platformHandle) {
FIND_VIEWPORT.ptr = nFindViewportByPlatformHandle(platformHandle);
return FIND_VIEWPORT;
}
private static native long nFindViewportByPlatformHandle(long platformHandle); /*
return (intptr_t)ImGui::FindViewportByPlatformHandle((void*)platformHandle);
*/
}
+20 -2
View File
@@ -390,7 +390,7 @@ public final class ImGuiIO {
* Optional: Platform back-end name (informational only! will be displayed in About Window) + User data for back-end/wrappers to store their own stuff.
*/
public native String getBackendPlatformName(); /*
return env -> NewStringUTF(ImGui::GetIO().BackendPlatformName);
return env->NewStringUTF(ImGui::GetIO().BackendPlatformName);
*/
/**
@@ -404,7 +404,7 @@ public final class ImGuiIO {
* Optional: Renderer back-end name (informational only! will be displayed in About Window) + User data for back-end/wrappers to store their own stuff.
*/
public native String getBackendRendererName(); /*
return env -> NewStringUTF(ImGui::GetIO().BackendRendererName);
return env->NewStringUTF(ImGui::GetIO().BackendRendererName);
*/
/**
@@ -699,6 +699,24 @@ public final class ImGuiIO {
ImGui::GetIO().MouseWheelH = mouseDeltaX;
*/
/**
* (Optional) When using multiple viewports: viewport the OS mouse cursor is hovering _IGNORING_ viewports with the ImGuiViewportFlags_NoInputs flag,
* and _REGARDLESS_ of whether another viewport is focused. Set io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport if you can provide this info.
* 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).
*/
public native float getMouseHoveredViewport(); /*
return ImGui::GetIO().MouseHoveredViewport;
*/
/**
* (Optional) When using multiple viewports: viewport the OS mouse cursor is hovering _IGNORING_ viewports with the ImGuiViewportFlags_NoInputs flag,
* and _REGARDLESS_ of whether another viewport is focused. Set io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport if you can provide this info.
* 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).
*/
public native void setMouseHoveredViewport(int imGuiId); /*
ImGui::GetIO().MouseHoveredViewport = imGuiId;
*/
/**
* Keyboard modifier pressed: Control
*/
@@ -70,6 +70,7 @@ import imgui.callback.ImPlatformFuncViewportSuppImVec2;
* Platform functions are typically called before their Renderer counterpart, apart from Destroy which are called the other way.
*/
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 ImVec2 TMP_IM_VEC2 = new ImVec2();
@@ -307,7 +308,7 @@ public final class ImGuiPlatformIO extends ImGuiStruct {
IMGUI_PLATFORM_IO->Platform_SetWindowTitle = PlatformStubSetWindowTitle;
*/
/*JNI
/*JNI
jobject platformCallbackSetWindowAlpha = NULL;
void PlatformStubSetWindowAlpha(ImGuiViewport* vp, float alpha) {
if (platformCallbackSetWindowAlpha != NULL) {
@@ -485,4 +486,62 @@ public final class ImGuiPlatformIO extends ImGuiStruct {
public native void setRendererSwapBuffers(ImPlatformFuncViewport func); /*
IM_RENDERER_FUNC_VIEWPORT_METHOD_TMPL(SwapBuffers)
*/
// (Optional) Monitor list
// - Updated by: app/back-end. Update every frame to dynamically support changing monitor or DPI configuration.
// - Used by: dear imgui to query DPI info, clamp popups/tooltips within same monitor and not have them straddle monitors.
//------------------------------------------------------------------
// Output - List of viewports to render into platform windows
//------------------------------------------------------------------
public native void resizeMonitors(int size); /*
IMGUI_PLATFORM_IO->Monitors.resize(0);
*/
public native int getMonitorsSize(); /*
return IMGUI_PLATFORM_IO->Monitors.Size;
*/
public native void pushMonitors(float mainPosX, float mainPosY, float mainSizeX, float mainSizeY, float workPosX, float workPosY, float workSizeX, float workSizeY, float dpiScale); /*
ImGuiPlatformMonitor monitor;
monitor.MainPos = ImVec2(mainPosX, mainPosY);
monitor.MainSize = ImVec2(mainSizeX, mainSizeY);
monitor.WorkPos = ImVec2(workPosX, workPosY);
monitor.WorkSize = ImVec2(workSizeX, workSizeY);
monitor.DpiScale = dpiScale;
IMGUI_PLATFORM_IO->Monitors.push_back(monitor);
*/
// 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")
/**
* Guaranteed to be == Viewports[0]
*/
public ImGuiViewport getMainViewport() {
MAIN_VIEWPORT.ptr = nGetMainViewport();
return MAIN_VIEWPORT;
}
private native long nGetMainViewport(); /*
return (intptr_t)IMGUI_PLATFORM_IO->MainViewport;
*/
public native int getViewportsSize(); /*
return IMGUI_PLATFORM_IO->Viewports.Size;
*/
public ImGuiViewport getViewports(final int idx) {
TMP_VIEWPORT.ptr = nGetViewports(idx);
return TMP_VIEWPORT;
}
private native long nGetViewports(int idx); /*
return (intptr_t)IMGUI_PLATFORM_IO->Viewports[idx];
*/
}
@@ -212,7 +212,67 @@ public final class ImGuiViewport extends ImGuiStruct {
// by the same system and you may not need to use all the UserData/Handle fields.
// The library never uses those fields, they are merely storage to facilitate back-end implementation.
// TODO: PlatformUserData, PlatformHandle, PlatformHandleRaw
/**
* void* to hold custom data structure for the renderer (e.g. swap chain, framebuffers etc.). generally set by your Renderer_CreateWindow function.
*/
public native void setRendererUserData(Object data); /*
if (IMGUI_VIEWPORT->RendererUserData != NULL) {
env->DeleteGlobalRef((jobject)IMGUI_VIEWPORT->RendererUserData);
}
IMGUI_VIEWPORT->RendererUserData = (data == NULL ? NULL : (void*)env->NewGlobalRef(data));
*/
/**
* void* to hold custom data structure for the renderer (e.g. swap chain, framebuffers etc.). generally set by your Renderer_CreateWindow function.
*/
public native Object getRendererUserData(); /*
return (jobject)IMGUI_VIEWPORT->RendererUserData;
*/
/**
* void* to hold custom data structure for the OS / platform (e.g. windowing info, render context). generally set by your Platform_CreateWindow function.
*/
public native void setPlatformUserData(Object data); /*
if (IMGUI_VIEWPORT->PlatformUserData != NULL) {
env->DeleteGlobalRef((jobject)IMGUI_VIEWPORT->PlatformUserData);
}
IMGUI_VIEWPORT->PlatformUserData = (data == NULL ? NULL : (void*)env->NewGlobalRef(data));
*/
/**
* void* to hold custom data structure for the OS / platform (e.g. windowing info, render context). generally set by your Platform_CreateWindow function.
*/
public native Object getPlatformUserData(); /*
return (jobject)IMGUI_VIEWPORT->PlatformUserData;
*/
/**
* void* for FindViewportByPlatformHandle(). (e.g. suggested to use natural platform handle such as HWND, GLFWWindow*, SDL_Window*)
*/
public native void setPlatformHandle(long data); /*
IMGUI_VIEWPORT->PlatformHandle = (void*)data;
*/
/**
* void* for FindViewportByPlatformHandle(). (e.g. suggested to use natural platform handle such as HWND, GLFWWindow*, SDL_Window*)
*/
public native long getPlatformHandle(); /*
return (intptr_t)IMGUI_VIEWPORT->PlatformHandle;
*/
/**
* 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*)
*/
public native void setPlatformHandleRaw(long data); /*
IMGUI_VIEWPORT->PlatformHandleRaw = (void*)data;
*/
/**
* 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*)
*/
public native long getPlatformHandleRaw(); /*
return (intptr_t)IMGUI_VIEWPORT->PlatformHandleRaw;
*/
/**
* Platform window requested move (e.g. window was moved by the OS / host window manager, authoritative position will be OS window position).
@@ -6,5 +6,5 @@ import imgui.ImGuiViewport;
* Callback to represent ImGuiPlatformIO function with args: (ImGuiViewport*, String)
*/
public abstract class ImPlatformFuncViewportFloat {
public abstract void accept(ImGuiViewport vp, Float f);
public abstract void accept(ImGuiViewport vp, float f);
}
@@ -24,4 +24,21 @@ public final class ImGuiBackendFlags {
* Back-end Renderer supports ImDrawCmd::VtxOffset. This enables output of large meshes (64K+ vertices) while still using 16-bit indices.
*/
public static final int RendererHasVtxOffset = 1 << 3;
// [BETA] Viewports
/**
* Back-end Platform supports multiple viewports.
*/
public static final int PlatformHasViewports = 1 << 10;
/**
* Back-end Platform supports setting io.MouseHoveredViewport to the viewport directly under the mouse _IGNORING_ viewports
* with the ImGuiViewportFlags_NoInputs flag and _REGARDLESS_ of whether another viewport is focused and may be capturing the mouse.
* This information is _NOT EASY_ to provide correctly with most high-level engines! Don't set this without studying how the examples/ back-end handle it!
*/
public static final int HasMouseHoveredViewport = 1 << 11;
/**
* Back-end Renderer supports multiple viewports.
*/
public static final int RendererHasViewports = 1 << 12;
}
@@ -43,6 +43,24 @@ public final class ImGuiConfigFlags {
*/
public static final int DockingEnable = 1 << 6;
// [BETA] Viewports
// When using viewports it is recommended that your default value for ImGuiCol_WindowBg is opaque (Alpha=1.0) so transition to a viewport won't be noticeable.
/**
* Viewport enable flags (require both ImGuiConfigFlags_PlatformHasViewports + ImGuiConfigFlags_RendererHasViewports set by the respective back-ends)
*/
public static final int ViewportsEnable = 1 << 10;
/**
* [BETA: Don't use] FIXME-DPI: Reposition and resize imgui windows when the DpiScale of a viewport changed (mostly useful for the main viewport hosting other window).
* Note that resizing the main window itself is up to your application.
*/
public static final int DpiEnableScaleViewports = 1 << 14;
/**
* [BETA: Don't use] FIXME-DPI: Request bitmap-scaled fonts to match DpiScale. This is a very low-quality workaround.
* The correct way to handle DPI is _currently_ to replace the atlas and/or fonts in the Platform_OnChangedViewport callback, but this is all early work in progress.
*/
public static final int DpiEnableScaleFonts = 1 << 15;
// User storage (to allow your back-end/engine to communicate to code that may be shared between multiple projects. Those flags are not used by core Dear ImGui)
/**