Add ImPlatformIO, ImGuiViewport

This commit is contained in:
SpaiR committed 2020-08-29 15:33:15 +03:00
1 parent dce574ef76
commit 8494bd8361
14 files changed
+773 -5

No files matched your search

@@ -21,6 +21,8 @@ public final class ImDrawData extends ImGuiStruct {
private static ByteBuffer dataBuffer = ByteBuffer.allocateDirect(25_000).order(ByteOrder.nativeOrder());
private static final ImGuiViewport OWNER_VIEWPORT = new ImGuiViewport(0);
public ImDrawData(final long ptr) {
super(ptr);
}
@@ -229,6 +231,18 @@ public final class ImDrawData extends ImGuiStruct {
return IM_DRAW_DATA->FramebufferScale.y;
*/
/**
* Viewport carrying the ImDrawData instance, might be of use to the renderer (generally not).
*/
public ImGuiViewport getOwnerViewport() {
OWNER_VIEWPORT.ptr = nGetOwnerViewport();
return OWNER_VIEWPORT;
}
private native long nGetOwnerViewport(); /*
return (intptr_t)IM_DRAW_DATA->OwnerViewport;
*/
// Functions
/**
@@ -29,10 +29,14 @@ public final class ImGui {
private static final ImDrawList BACKGROUND_DRAW_LIST;
private static final ImDrawList FOREGROUND_DRAW_LIST;
private static final ImGuiStorage IMGUI_STORAGE;
private static final ImGuiViewport WINDOW_VIEWPORT;
private static final ImGuiViewport FIND_VIEWPORT;
private static ImDrawData drawData;
private static ImFont font;
private static ImGuiStyle style;
private static ImGuiViewport mainViewport;
private static ImGuiPlatformIO platformIO;
static {
final String libPath = System.getProperty(LIB_PATH_PROP);
@@ -54,9 +58,12 @@ public final class ImGui {
BACKGROUND_DRAW_LIST = new ImDrawList(0);
FOREGROUND_DRAW_LIST = new ImDrawList(0);
IMGUI_STORAGE = new ImGuiStorage(0);
WINDOW_VIEWPORT = new ImGuiViewport(0);
FIND_VIEWPORT = new ImGuiViewport(0);
nInitJni();
ImFontAtlas.nInit();
ImGuiPlatformIO.init();
nInitInputTextData();
}
@@ -494,6 +501,18 @@ public final class ImGui {
return ImGui::GetWindowDpiScale();
*/
/**
* Get viewport currently associated to the current window.
*/
public static ImGuiViewport getWindowViewport() {
WINDOW_VIEWPORT.ptr = nGetWindowViewport();
return WINDOW_VIEWPORT;
}
private static native long nGetWindowViewport(); /*
return (intptr_t)ImGui::GetWindowViewport();
*/
/**
* Get current window position in screen space (useful if you want to do your own drawing via the DrawList API)
*/
@@ -4918,6 +4937,32 @@ public final class ImGui {
return (intptr_t)ImGui::GetForegroundDrawList();
*/
/**
* Get background draw list for the given viewport.
* This draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents.
*/
public static ImDrawList getBackgroundDrawList(ImGuiViewport viewport) {
BACKGROUND_DRAW_LIST.ptr = nGetBackgroundDrawList(viewport.ptr);
return BACKGROUND_DRAW_LIST;
}
private static native long nGetBackgroundDrawList(long viewportPtr); /*
return (intptr_t)ImGui::GetBackgroundDrawList((ImGuiViewport*)viewportPtr);
*/
/**
* Get foreground draw list for the given viewport.
* This draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents.
*/
public static ImDrawList getForegroundDrawList(ImGuiViewport viewport) {
BACKGROUND_DRAW_LIST.ptr = nGetForegroundDrawList(viewport.ptr);
return BACKGROUND_DRAW_LIST;
}
private static native long nGetForegroundDrawList(long viewportPtr); /*
return (intptr_t)ImGui::GetBackgroundDrawList((ImGuiViewport*)viewportPtr);
*/
// TODO GetDrawListSharedData
/**
@@ -5378,4 +5423,72 @@ public final class ImGui {
public static native String saveIniSettingsToMemory(long outIniSize); /*
return env->NewStringUTF(ImGui::SaveIniSettingsToMemory((size_t*)&outIniSize));
*/
// (Optional) Platform/OS interface for multi-viewport support
// Read comments around the ImGuiPlatformIO structure for more details.
// Note: You may use GetWindowViewport() to get the current viewport of the current window.
/**
* Platform/renderer functions, for back-end to setup + viewports list.
*/
public static ImGuiPlatformIO getPlatformIO() {
if (platformIO == null) {
platformIO = new ImGuiPlatformIO(nGetPlatformIO());
}
return platformIO;
}
private static native long nGetPlatformIO(); /*
return (intptr_t)ImGui::GetMainViewport();
*/
/**
* Main viewport. Same as GetPlatformIO().MainViewport == GetPlatformIO().Viewports[0].
*/
public static ImGuiViewport getMainViewport() {
if (mainViewport == null) {
mainViewport = new ImGuiViewport(nGetMainViewport());
}
return mainViewport;
}
private static native long nGetMainViewport(); /*
return (intptr_t)ImGui::GetMainViewport();
*/
/**
* Call in main loop. Will call CreateWindow/ResizeWindow/etc. Platform functions for each secondary viewport, and DestroyWindow for each inactive viewport.
*/
public static native void updatePlatformWindows(); /*
ImGui::UpdatePlatformWindows();
*/
/**
* Call in main loop. will call RenderWindow/SwapBuffers platform functions for each secondary viewport which doesn't have the ImGuiViewportFlags_Minimized flag set.
* May be reimplemented by user for custom rendering needs.
*/
public static native void renderPlatformWindowsDefault(); /*
ImGui::RenderPlatformWindowsDefault();
*/
/**
* Call DestroyWindow platform functions for all viewports.
* Call from back-end Shutdown() if you need to close platform windows before imgui shutdown.
* Otherwise will be called by DestroyContext().
*/
public static native void destroyPlatformWindows(); /*
ImGui::DestroyPlatformWindows();
*/
/**
* This is a helper for back-ends.
*/
public static ImGuiViewport findViewportByID(int imGuiID) {
FIND_VIEWPORT.ptr = nFindViewportByID(imGuiID);
return FIND_VIEWPORT;
}
private static native long nFindViewportByID(int imGuiID); /*
return (intptr_t)ImGui::FindViewportByID(imGuiID);
*/
}
@@ -0,0 +1,488 @@
package imgui;
import imgui.binding.ImGuiStruct;
import imgui.callback.ImPlatformFuncViewport;
import imgui.callback.ImPlatformFuncViewportFloat;
import imgui.callback.ImPlatformFuncViewportImVec2;
import imgui.callback.ImPlatformFuncViewportString;
import imgui.callback.ImPlatformFuncViewportSuppBoolean;
import imgui.callback.ImPlatformFuncViewportSuppFloat;
import imgui.callback.ImPlatformFuncViewportSuppImVec2;
/**
* -----------------------------------------------------------------------------
* [BETA] Platform interface for multi-viewport support
* -----------------------------------------------------------------------------
* (Optional) This is completely optional, for advanced users!
* If you are new to Dear ImGui and trying to integrate it into your engine, you can probably ignore this for now.
* This feature allows you to seamlessly drag Dear ImGui windows outside of your application viewport.
* This is achieved by creating new Platform/OS windows on the fly, and rendering into them.
* Dear ImGui manages the viewport structures, and the back-end create and maintain one Platform/OS window for each of those viewports.
* See Glossary https://github.com/ocornut/imgui/wiki/Glossary for details about some of the terminology.
* See Thread https://github.com/ocornut/imgui/issues/1542 for gifs, news and questions about this evolving feature.
* About the coordinates system:
* - When multi-viewports are enabled, all Dear ImGui coordinates become absolute coordinates (same as OS coordinates!)
* - So e.g. ImGui::SetNextWindowPos(ImVec2(0,0)) will position a window relative to your primary monitor!
* - If you want to position windows relative to your main application viewport, use ImGui::GetMainViewport()->Pos as a base position.
* Steps to use multi-viewports in your application, when using a default back-end from the examples/ folder:
* - Application: Enable feature with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
* - Back-end: The back-end initialization will setup all necessary ImGuiPlatformIO's functions and update monitors info every frame.
* - Application: In your main loop, call ImGui::UpdatePlatformWindows(), ImGui::RenderPlatformWindowsDefault() after EndFrame() or Render().
* - Application: Fix absolute coordinates used in ImGui::SetWindowPos() or ImGui::SetNextWindowPos() calls.
* Steps to use multi-viewports in your application, when using a custom back-end:
* - Important: THIS IS NOT EASY TO DO and comes with many subtleties not described here!
* It's also an experimental feature, so some of the requirements may evolve.
* Consider using default back-ends if you can. Either way, carefully follow and refer to examples/ back-ends for details.
* - Application: Enable feature with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
* - Back-end: Hook ImGuiPlatformIO's Platform_* and Renderer_* callbacks (see below).
* Set 'io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports' and 'io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports'.
* Update ImGuiPlatformIO's Monitors list every frame.
* Update MousePos every frame, in absolute coordinates.
* - Application: In your main loop, call ImGui::UpdatePlatformWindows(), ImGui::RenderPlatformWindowsDefault() after EndFrame() or Render().
* You may skip calling RenderPlatformWindowsDefault() if its API is not convenient for your needs. Read comments below.
* - Application: Fix absolute coordinates used in ImGui::SetWindowPos() or ImGui::SetNextWindowPos() calls.
* About ImGui::RenderPlatformWindowsDefault():
* - This function is a mostly a _helper_ for the common-most cases, and to facilitate using default back-ends.
* - You can check its simple source code to understand what it does.
* It basically iterates secondary viewports and call 4 functions that are setup in ImGuiPlatformIO, if available:
* Platform_RenderWindow(), Renderer_RenderWindow(), Platform_SwapBuffers(), Renderer_SwapBuffers()
* Those functions pointers exists only for the benefit of RenderPlatformWindowsDefault().
* - If you have very specific rendering needs (e.g. flipping multiple swap-chain simultaneously, unusual sync/threading issues, etc.),
* you may be tempted to ignore RenderPlatformWindowsDefault() and write customized code to perform your renderingg.
* You may decide to setup the platform_io's *RenderWindow and *SwapBuffers pointers and call your functions through those pointers,
* or you may decide to never setup those pointers and call your code directly. They are a convenience, not an obligatory interface.
* -----------------------------------------------------------------------------
* (Optional) Access via ImGui::GetPlatformIO()
*
* ------------------------------------------------------------------
* Input - Back-end interface/functions + Monitor List
* ------------------------------------------------------------------
* (Optional) Platform functions (e.g. Win32, GLFW, SDL2)
* For reference, the second column shows which function are generally calling the Platform Functions:
* N = ImGui::NewFrame() ~ beginning of the dear imgui frame: read info from platform/OS windows (latest size/position)
* F = ImGui::Begin(), ImGui::EndFrame() ~ during the dear imgui frame
* U = ImGui::UpdatePlatformWindows() ~ after the dear imgui frame: create and update all platform/OS windows
* R = ImGui::RenderPlatformWindowsDefault() ~ render
* D = ImGui::DestroyPlatformWindows() ~ shutdown
* The general idea is that NewFrame() we will read the current Platform/OS state, and UpdatePlatformWindows() will write to it.
* The functions are designed so we can mix and match 2 imgui_impl_xxxx files, one for the Platform (~window/input handling), one for Renderer.
* Custom engine back-ends will often provide both Platform and Renderer interfaces and so may not need to use all functions.
* 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 TMP_VIEWPORT = new ImGuiViewport(0);
private static final ImVec2 TMP_IM_VEC2 = new ImVec2();
public ImGuiPlatformIO(final long ptr) {
super(ptr);
}
/*JNI
#include <stdint.h>
#include <imgui.h>
#include "jni_common.h"
#include "jni_callbacks.h"
#include "jni_binding_struct.h"
#define IMGUI_PLATFORM_IO ((ImGuiPlatformIO*)STRUCT_PTR)
jobject jTmpViewport = NULL;
jobject jTmpImVec2 = NULL;
*/
static void init() {
nInit(TMP_VIEWPORT, TMP_IM_VEC2);
}
private static native void nInit(ImGuiViewport tmpViewport, ImVec2 tmpImVec2); /*
jTmpViewport = env->NewGlobalRef(tmpViewport);
jTmpImVec2 = env->NewGlobalRef(tmpImVec2);
*/
/*JNI
#define IM_PLATFORM_FUNC_VIEWPORT_TMPL(name)\
jobject platformCallback##name = NULL;\
void PlatformStub##name(ImGuiViewport* vp) {\
if (platformCallback##name != NULL) {\
JNIEnv* env = Jni::GetEnv();\
env->SetLongField(jTmpViewport, Jni::GetBindingStructPtrID(), (intptr_t)vp);\
Jni::CallImPlatformFuncViewport(env, platformCallback##name, jTmpViewport);\
}\
}\
void PlatformStub##name(ImGuiViewport* vp, void*) {\
PlatformStub##name(vp);\
}
IM_PLATFORM_FUNC_VIEWPORT_TMPL(CreateWindow)
#define IM_PLATFORM_FUNC_VIEWPORT_METHOD_TMPL(name)\
if (platformCallback##name != NULL) {\
env->DeleteGlobalRef(platformCallback##name);\
}\
platformCallback##name = env->NewGlobalRef(func);\
IMGUI_PLATFORM_IO->Platform_##name = PlatformStub##name;
*/
/**
* // . . U . . // Create a new platform window for the given viewport.
*/
public native void setPlatformCreateWindow(ImPlatformFuncViewport func); /*
IM_PLATFORM_FUNC_VIEWPORT_METHOD_TMPL(CreateWindow)
*/
/*JNI
IM_PLATFORM_FUNC_VIEWPORT_TMPL(DestroyWindow)
*/
/**
* // N . U . D //
*/
public native void setPlatformDestroyWindow(ImPlatformFuncViewport func); /*
IM_PLATFORM_FUNC_VIEWPORT_METHOD_TMPL(DestroyWindow)
*/
/*JNI
IM_PLATFORM_FUNC_VIEWPORT_TMPL(ShowWindow)
*/
/**
* // . . U . . // Newly created windows are initially hidden so SetWindowPos/Size/Title can be called on them before showing the window.
*/
public native void setPlatformShowWindow(ImPlatformFuncViewport func); /*
IM_PLATFORM_FUNC_VIEWPORT_METHOD_TMPL(ShowWindow)
*/
/*JNI
#define IM_PLATFORM_FUNC_VIEWPORT_IM_VEC2_TMPL(name)\
jobject platformCallback##name = NULL;\
void PlatformStub##name(ImGuiViewport* vp, ImVec2 pos) {\
if (platformCallback##name != NULL) {\
JNIEnv* env = Jni::GetEnv();\
env->SetLongField(jTmpViewport, Jni::GetBindingStructPtrID(), (intptr_t)vp);\
Jni::ImVec2Cpy(env, pos, jTmpImVec2);\
Jni::CallImPlatformFuncViewportImVec2(env, platformCallback##name, jTmpViewport, jTmpImVec2);\
}\
}
IM_PLATFORM_FUNC_VIEWPORT_IM_VEC2_TMPL(SetWindowPos)
#define IM_PLATFORM_FUNC_VIEWPORT_IM_VEC2_METHOD_TMPL(name)\
if (platformCallback##name != NULL) {\
env->DeleteGlobalRef(platformCallback##name);\
}\
platformCallback##name = env->NewGlobalRef(func);\
IMGUI_PLATFORM_IO->Platform_##name = PlatformStub##name;
*/
/**
* // . . U . . // Set platform window position (given the upper-left corner of client area).
*/
public native void setPlatformSetWindowPos(ImPlatformFuncViewportImVec2 func); /*
IM_PLATFORM_FUNC_VIEWPORT_IM_VEC2_METHOD_TMPL(SetWindowPos)
*/
/*JNI
#define IM_PLATFORM_FUNC_VIEWPORT_SUPP_IM_VEC2_TMPL(name)\
jobject platformCallback##name = NULL;\
ImVec2 PlatformStub##name(ImGuiViewport* vp) {\
ImVec2 dst;\
if (platformCallback##name != NULL) {\
JNIEnv* env = Jni::GetEnv();\
env->SetLongField(jTmpViewport, Jni::GetBindingStructPtrID(), (intptr_t)vp);\
Jni::CallImPlatformFuncViewportSuppImVec2(env, platformCallback##name, jTmpViewport, jTmpImVec2);\
Jni::ImVec2Cpy(env, jTmpImVec2, dst);\
}\
return dst;\
}
IM_PLATFORM_FUNC_VIEWPORT_SUPP_IM_VEC2_TMPL(GetWindowPos)
#define IM_PLATFORM_FUNC_VIEWPORT_SUPP_IM_VEC2_METHOD_TMPL(name)\
if (platformCallback##name != NULL) {\
env->DeleteGlobalRef(platformCallback##name);\
}\
platformCallback##name = env->NewGlobalRef(func);\
IMGUI_PLATFORM_IO->Platform_##name = PlatformStub##name;
*/
/**
* // N . . . . //
*/
public native void setPlatformGetWindowPos(ImPlatformFuncViewportSuppImVec2 func); /*
IM_PLATFORM_FUNC_VIEWPORT_SUPP_IM_VEC2_METHOD_TMPL(GetWindowPos)
*/
/*JNI
IM_PLATFORM_FUNC_VIEWPORT_IM_VEC2_TMPL(SetWindowSize)
*/
/**
* // . . U . . // Set platform window client area size (ignoring OS decorations such as OS title bar etc.)
*/
public native void setPlatformSetWindowSize(ImPlatformFuncViewportImVec2 func); /*
IM_PLATFORM_FUNC_VIEWPORT_IM_VEC2_METHOD_TMPL(SetWindowSize)
*/
/*JNI
IM_PLATFORM_FUNC_VIEWPORT_SUPP_IM_VEC2_TMPL(GetWindowSize)
*/
/**
* // N . . . . // Get platform window client area size
*/
public native void setPlatformGetWindowSize(ImPlatformFuncViewportSuppImVec2 func); /*
IM_PLATFORM_FUNC_VIEWPORT_SUPP_IM_VEC2_METHOD_TMPL(GetWindowSize)
*/
/*JNI
IM_PLATFORM_FUNC_VIEWPORT_TMPL(SetWindowFocus)
*/
/**
* // N . . . . // Move window to front and set input focus.
*/
public native void setPlatformSetWindowFocus(ImPlatformFuncViewport func); /*
IM_PLATFORM_FUNC_VIEWPORT_METHOD_TMPL(SetWindowFocus)
*/
/*JNI
#define IM_PLATFORM_FUNC_VIEWPORT_SUPP_BOOLEAN_TMPL(name)\
jobject platformCallback##name = NULL;\
bool PlatformStub##name(ImGuiViewport* vp) {\
if (platformCallback##name != NULL) {\
JNIEnv* env = Jni::GetEnv();\
env->SetLongField(jTmpViewport, Jni::GetBindingStructPtrID(), (intptr_t)vp);\
return Jni::CallImPlatformFuncViewportSuppBoolean(env, platformCallback##name, jTmpViewport);\
}\
return false;\
}
IM_PLATFORM_FUNC_VIEWPORT_SUPP_BOOLEAN_TMPL(GetWindowFocus)
#define IM_PLATFORM_FUNC_VIEWPORT_SUPP_BOOLEAN_METHOD_TMPL(name)\
if (platformCallback##name != NULL) {\
env->DeleteGlobalRef(platformCallback##name);\
}\
platformCallback##name = env->NewGlobalRef(func);\
IMGUI_PLATFORM_IO->Platform_##name = PlatformStub##name;
*/
/**
* // . . U . . //
*/
public native void setPlatformGetWindowFocus(ImPlatformFuncViewportSuppBoolean func); /*
IM_PLATFORM_FUNC_VIEWPORT_SUPP_BOOLEAN_METHOD_TMPL(GetWindowFocus)
*/
/*JNI
IM_PLATFORM_FUNC_VIEWPORT_SUPP_BOOLEAN_TMPL(GetWindowMinimized)
*/
/**
* // N . . . . // Get platform window minimized state. When minimized, we generally won't attempt to get/set size and contents will be culled more easily.
*/
public native void setPlatformGetWindowMinimized(ImPlatformFuncViewportSuppBoolean func); /*
IM_PLATFORM_FUNC_VIEWPORT_SUPP_BOOLEAN_METHOD_TMPL(GetWindowMinimized)
*/
/*JNI
jobject platformCallbackSetWindowTitle = NULL;
void PlatformStubSetWindowTitle(ImGuiViewport* vp, const char* str) {
if (platformCallbackSetWindowTitle != NULL) {
JNIEnv* env = Jni::GetEnv();
env->SetLongField(jTmpViewport, Jni::GetBindingStructPtrID(), (intptr_t)vp);
Jni::CallImPlatformFuncViewportString(env, platformCallbackSetWindowTitle, jTmpViewport, str);
}
}
*/
/**
* // . . U . . // Set platform window title (given an UTF-8 string)
*/
public native void setPlatformSetWindowTitle(ImPlatformFuncViewportString func); /*
if (platformCallbackSetWindowTitle != NULL) {
env->DeleteGlobalRef(platformCallbackSetWindowTitle);
}
platformCallbackSetWindowTitle = env->NewGlobalRef(func);
IMGUI_PLATFORM_IO->Platform_SetWindowTitle = PlatformStubSetWindowTitle;
*/
/*JNI
jobject platformCallbackSetWindowAlpha = NULL;
void PlatformStubSetWindowAlpha(ImGuiViewport* vp, float alpha) {
if (platformCallbackSetWindowAlpha != NULL) {
JNIEnv* env = Jni::GetEnv();
env->SetLongField(jTmpViewport, Jni::GetBindingStructPtrID(), (intptr_t)vp);
Jni::CallImPlatformFuncViewportFloat(env, platformCallbackSetWindowAlpha, jTmpViewport, alpha);
}
}
*/
/**
* // . . U . . // (Optional) Setup window transparency
*/
public native void setPlatformSetWindowAlpha(ImPlatformFuncViewportFloat func); /*
if (platformCallbackSetWindowAlpha != NULL) {
env->DeleteGlobalRef(platformCallbackSetWindowAlpha);
}
platformCallbackSetWindowAlpha = env->NewGlobalRef(func);
IMGUI_PLATFORM_IO->Platform_SetWindowAlpha = PlatformStubSetWindowAlpha;
*/
/*JNI
IM_PLATFORM_FUNC_VIEWPORT_TMPL(UpdateWindow)
*/
/**
* // . . U . . // (Optional) Called by UpdatePlatformWindows(). Optional hook to allow the platform back-end from doing general book-keeping every frame.
*/
public native void setPlatformUpdateWindow(ImPlatformFuncViewport func); /*
IM_PLATFORM_FUNC_VIEWPORT_METHOD_TMPL(UpdateWindow)
*/
/*JNI
IM_PLATFORM_FUNC_VIEWPORT_TMPL(RenderWindow)
*/
/**
* // . . . R . // (Optional) Main rendering (platform side! This is often unused, or just setting a "current" context for OpenGL bindings).
*/
public native void setPlatformRenderWindow(ImPlatformFuncViewport func); /*
IM_PLATFORM_FUNC_VIEWPORT_METHOD_TMPL(RenderWindow)
*/
/*JNI
IM_PLATFORM_FUNC_VIEWPORT_TMPL(SwapBuffers)
*/
/**
* // . . . R . // (Optional) Call Present/SwapBuffers (platform side! This is often unused!).
*/
public native void setPlatformSwapBuffers(ImPlatformFuncViewport func); /*
IM_PLATFORM_FUNC_VIEWPORT_METHOD_TMPL(SwapBuffers)
*/
/*JNI
jobject platformCallbackGetWindowDpiScale = NULL;
float PlatformStubGetWindowDpiScale(ImGuiViewport* vp) {
if (platformCallbackGetWindowDpiScale != NULL) {
JNIEnv* env = Jni::GetEnv();
env->SetLongField(jTmpViewport, Jni::GetBindingStructPtrID(), (intptr_t)vp);
return Jni::CallImPlatformFuncViewportSuppFloat(env, platformCallbackGetWindowDpiScale, jTmpViewport);
}
return false;
}
*/
/**
* // N . . . . // (Optional) [BETA] FIXME-DPI: DPI handling: Return DPI scale for this viewport. 1.0f = 96 DPI.
*/
public native void setPlatformGetWindowDpiScale(ImPlatformFuncViewportSuppFloat func); /*
if (platformCallbackGetWindowDpiScale != NULL) {
env->DeleteGlobalRef(platformCallbackGetWindowDpiScale);
}
platformCallbackGetWindowDpiScale = env->NewGlobalRef(func);
IMGUI_PLATFORM_IO->Platform_GetWindowDpiScale = PlatformStubGetWindowDpiScale;
*/
/*JNI
IM_PLATFORM_FUNC_VIEWPORT_TMPL(OnChangedViewport)
*/
/**
* // (Optional) [BETA] FIXME-DPI: DPI handling: Called during Begin() every time the viewport we are outputting into changes, so back-end has a chance to swap fonts to adjust style.
*/
public native void setPlatformOnChangedViewport(ImPlatformFuncViewport func); /*
IM_PLATFORM_FUNC_VIEWPORT_METHOD_TMPL(OnChangedViewport)
*/
// (Optional) Renderer functions (e.g. DirectX, OpenGL, Vulkan)
/*JNI
#define IM_RENDERER_FUNC_VIEWPORT_TMPL(name)\
jobject rendererCallback##name = NULL;\
void RendererStub##name(ImGuiViewport* vp) {\
if (rendererCallback##name != NULL) {\
JNIEnv* env = Jni::GetEnv();\
env->SetLongField(jTmpViewport, Jni::GetBindingStructPtrID(), (intptr_t)vp);\
Jni::CallImPlatformFuncViewport(env, rendererCallback##name, jTmpViewport);\
}\
}\
void RendererStub##name(ImGuiViewport* vp, void*) {\
RendererStub##name(vp);\
}
IM_RENDERER_FUNC_VIEWPORT_TMPL(CreateWindow)
#define IM_RENDERER_FUNC_VIEWPORT_METHOD_TMPL(name)\
if (rendererCallback##name != NULL) {\
env->DeleteGlobalRef(rendererCallback##name);\
}\
rendererCallback##name = env->NewGlobalRef(func);\
IMGUI_PLATFORM_IO->Renderer_##name = RendererStub##name;
*/
/**
* // . . U . . // Create swap chain, frame buffers etc. (called after Platform_CreateWindow)
*/
public native void setRendererCreateWindow(ImPlatformFuncViewport func); /*
IM_RENDERER_FUNC_VIEWPORT_METHOD_TMPL(CreateWindow)
*/
/*JNI
IM_RENDERER_FUNC_VIEWPORT_TMPL(DestroyWindow)
*/
/**
* // N . U . D // Destroy swap chain, frame buffers etc. (called before Platform_DestroyWindow)
*/
public native void setRendererDestroyWindow(ImPlatformFuncViewport func); /*
IM_RENDERER_FUNC_VIEWPORT_METHOD_TMPL(DestroyWindow)
*/
/*JNI
jobject rendererCallbackSetWindowSize = NULL;
void RendererStubSetWindowSize(ImGuiViewport* vp, ImVec2 pos) {
if (rendererCallbackSetWindowSize != NULL) {
JNIEnv* env = Jni::GetEnv();
env->SetLongField(jTmpViewport, Jni::GetBindingStructPtrID(), (intptr_t)vp);
Jni::ImVec2Cpy(env, pos, jTmpImVec2);
Jni::CallImPlatformFuncViewportImVec2(env, rendererCallbackSetWindowSize, jTmpViewport, jTmpImVec2);
}
}
*/
/**
* // . . U . . // Resize swap chain, frame buffers etc. (called after Platform_SetWindowSize)
*/
public native void setRendererSetWindowPos(ImPlatformFuncViewportImVec2 func); /*
if (rendererCallbackSetWindowSize != NULL) {
env->DeleteGlobalRef(rendererCallbackSetWindowSize);
}
rendererCallbackSetWindowSize = env->NewGlobalRef(func);
IMGUI_PLATFORM_IO->Renderer_SetWindowSize = RendererStubSetWindowSize;
*/
/*JNI
IM_RENDERER_FUNC_VIEWPORT_TMPL(RenderWindow)
*/
/**
* // . . . R . // (Optional) Clear framebuffer, setup render target,
* then render the viewport->DrawData. 'render_arg' is the value passed to RenderPlatformWindowsDefault().
*/
public native void setRendererRenderWindow(ImPlatformFuncViewport func); /*
IM_RENDERER_FUNC_VIEWPORT_METHOD_TMPL(RenderWindow)
*/
/*JNI
IM_RENDERER_FUNC_VIEWPORT_TMPL(SwapBuffers)
*/
/**
* // . . . R . // (Optional) Call Present/SwapBuffers. 'render_arg' is the value passed to RenderPlatformWindowsDefault().
*/
public native void setRendererSwapBuffers(ImPlatformFuncViewport func); /*
IM_RENDERER_FUNC_VIEWPORT_METHOD_TMPL(SwapBuffers)
*/
}
@@ -8,6 +8,8 @@ import imgui.binding.ImGuiStruct;
* - Work Area = entire viewport minus sections optionally used by menu bars, status bars. Some positioning code will prefer to use this. Window are also trying to stay within this area.
*/
public final class ImGuiViewport extends ImGuiStruct {
private static final ImDrawData DRAW_DATA = new ImDrawData(0);
public ImGuiViewport(final long ptr) {
super(ptr);
}
@@ -179,7 +181,17 @@ public final class ImGuiViewport extends ImGuiStruct {
IMGUI_VIEWPORT->DpiScale = dpiScale;
*/
// TODO: DrawData
/**
* The ImDrawData corresponding to this viewport. Valid after Render() and until the next call to NewFrame().
*/
public ImDrawData getDrawData() {
DRAW_DATA.ptr = nGetDrawData();
return DRAW_DATA;
}
private native long nGetDrawData(); /*
return (intptr_t)IMGUI_VIEWPORT->DrawData;
*/
/**
* (Advanced) 0: no parent. Instruct the platform back-end to setup a parent/child relationship between platform windows.
@@ -0,0 +1,10 @@
package imgui.callback;
import imgui.ImGuiViewport;
/**
* Callback to represent ImGuiPlatformIO function with args: (ImGuiViewport*)
*/
public abstract class ImPlatformFuncViewport {
public abstract void accept(ImGuiViewport vp);
}
@@ -0,0 +1,10 @@
package imgui.callback;
import imgui.ImGuiViewport;
/**
* Callback to represent ImGuiPlatformIO function with args: (ImGuiViewport*, String)
*/
public abstract class ImPlatformFuncViewportFloat {
public abstract void accept(ImGuiViewport vp, Float f);
}
@@ -0,0 +1,11 @@
package imgui.callback;
import imgui.ImGuiViewport;
import imgui.ImVec2;
/**
* Callback to represent ImGuiPlatformIO function with args: (ImGuiViewport*, ImVec2)
*/
public abstract class ImPlatformFuncViewportImVec2 {
public abstract void accept(ImGuiViewport vp, ImVec2 imVec2);
}
@@ -0,0 +1,10 @@
package imgui.callback;
import imgui.ImGuiViewport;
/**
* Callback to represent ImGuiPlatformIO function with args: (ImGuiViewport*, String)
*/
public abstract class ImPlatformFuncViewportString {
public abstract void accept(ImGuiViewport vp, String str);
}
@@ -0,0 +1,10 @@
package imgui.callback;
import imgui.ImGuiViewport;
/**
* Callback to represent ImGuiPlatformIO function with args: (ImGuiViewport*) -> Boolean
*/
public abstract class ImPlatformFuncViewportSuppBoolean {
public abstract boolean get(ImGuiViewport vp);
}
@@ -0,0 +1,10 @@
package imgui.callback;
import imgui.ImGuiViewport;
/**
* Callback to represent ImGuiPlatformIO function with args: (ImGuiViewport*) -> Boolean
*/
public abstract class ImPlatformFuncViewportSuppFloat {
public abstract float get(ImGuiViewport vp);
}
@@ -0,0 +1,11 @@
package imgui.callback;
import imgui.ImGuiViewport;
import imgui.ImVec2;
/**
* Callback to represent ImGuiPlatformIO function with args: (ImGuiViewport*) -> ImVec2
*/
public abstract class ImPlatformFuncViewportSuppImVec2 {
public abstract void get(ImGuiViewport vp, ImVec2 dstImVec2);
}
@@ -4,14 +4,12 @@ jfieldID imGuiStructPtrID;
namespace Jni
{
void InitBindingStruct(JNIEnv* env)
{
void InitBindingStruct(JNIEnv* env) {
jclass jImGuiStructClass = env->FindClass("imgui/binding/ImGuiStruct");
imGuiStructPtrID = env->GetFieldID(jImGuiStructClass, "ptr", "J");
}
jfieldID GetBindingStructPtrID()
{
jfieldID GetBindingStructPtrID() {
return imGuiStructPtrID;
}
}
@@ -5,6 +5,14 @@ jmethodID jImListClipperCallbackAcceptMID;
jmethodID jImStrConsumerAcceptMID;
jmethodID jImStrSupplierGetMID;
jmethodID jImPlatformFuncViewportAcceptMID;
jmethodID jImPlatformFuncViewportFloatAcceptMID;
jmethodID jImPlatformFuncViewportImVec2AcceptMID;
jmethodID jImPlatformFuncViewportStringAcceptMID;
jmethodID jImPlatformFuncViewportSuppImVec2GetMID;
jmethodID jImPlatformFuncViewportSuppBooleanGetMID;
jmethodID jImPlatformFuncViewportSuppFloatGetMID;
namespace Jni
{
void InitCallbacks(JNIEnv* env) {
@@ -16,6 +24,27 @@ namespace Jni
jclass jImStrSupplier = env->FindClass("imgui/callback/ImStrSupplier");
jImStrSupplierGetMID = env->GetMethodID(jImStrSupplier, "get", "()Ljava/lang/String;");
jclass jImPlatformFuncViewport = env->FindClass("imgui/callback/ImPlatformFuncViewport");
jImPlatformFuncViewportAcceptMID = env->GetMethodID(jImPlatformFuncViewport, "accept", "(Limgui/ImGuiViewport;)V");
jclass jImPlatformFuncViewportFloat = env->FindClass("imgui/callback/ImPlatformFuncViewportFloat");
jImPlatformFuncViewportFloatAcceptMID = env->GetMethodID(jImPlatformFuncViewportFloat, "accept", "(Limgui/ImGuiViewport;F)V");
jclass jImPlatformFuncViewportImVec2 = env->FindClass("imgui/callback/ImPlatformFuncViewportImVec2");
jImPlatformFuncViewportImVec2AcceptMID = env->GetMethodID(jImPlatformFuncViewportImVec2, "accept", "(Limgui/ImGuiViewport;Limgui/ImVec2;)V");
jclass jImPlatformFuncViewportString = env->FindClass("imgui/callback/ImPlatformFuncViewportString");
jImPlatformFuncViewportStringAcceptMID = env->GetMethodID(jImPlatformFuncViewportString, "accept", "(Limgui/ImGuiViewport;Ljava/lang/String;)V");
jclass jImPlatformFuncViewportSuppImVec2 = env->FindClass("imgui/callback/ImPlatformFuncViewportSuppImVec2");
jImPlatformFuncViewportSuppImVec2GetMID = env->GetMethodID(jImPlatformFuncViewportSuppImVec2, "get", "(Limgui/ImGuiViewport;Limgui/ImVec2;)V");
jclass jImPlatformFuncViewportSuppBoolean = env->FindClass("imgui/callback/ImPlatformFuncViewportSuppBoolean");
jImPlatformFuncViewportSuppBooleanGetMID = env->GetMethodID(jImPlatformFuncViewportSuppBoolean, "get", "(Limgui/ImGuiViewport;)Z");
jclass jImPlatformFuncViewportSuppFloat = env->FindClass("imgui/callback/ImPlatformFuncViewportSuppFloat");
jImPlatformFuncViewportSuppFloatGetMID = env->GetMethodID(jImPlatformFuncViewportSuppFloat, "get", "(Limgui/ImGuiViewport;)F");
}
void CallImListClipperCallback(JNIEnv* env, jobject consumer, int index) {
@@ -29,4 +58,32 @@ namespace Jni
jstring CallImStrSupplier(JNIEnv* env, jobject supplier) {
return (jstring)env->CallObjectMethod(supplier, jImStrSupplierGetMID);
}
void CallImPlatformFuncViewport(JNIEnv* env, jobject func, jobject vp) {
env->CallVoidMethod(func, jImPlatformFuncViewportAcceptMID, vp);
}
void CallImPlatformFuncViewportFloat(JNIEnv* env, jobject func, jobject vp, float f) {
env->CallVoidMethod(func, jImPlatformFuncViewportFloatAcceptMID, vp, f);
}
void CallImPlatformFuncViewportImVec2(JNIEnv* env, jobject func, jobject vp, jobject imVec2) {
env->CallVoidMethod(func, jImPlatformFuncViewportImVec2AcceptMID, vp, imVec2);
}
void CallImPlatformFuncViewportString(JNIEnv* env, jobject func, jobject vp, const char* str) {
env->CallVoidMethod(func, jImPlatformFuncViewportStringAcceptMID, env->NewStringUTF(str));
}
void CallImPlatformFuncViewportSuppImVec2(JNIEnv* env, jobject func, jobject vp, jobject imVec2) {
env->CallVoidMethod(func, jImPlatformFuncViewportSuppImVec2GetMID, vp, imVec2);
}
jboolean CallImPlatformFuncViewportSuppBoolean(JNIEnv* env, jobject func, jobject vp) {
return (jboolean)env->CallBooleanMethod(func, jImPlatformFuncViewportSuppBooleanGetMID, vp);
}
jfloat CallImPlatformFuncViewportSuppFloat(JNIEnv* env, jobject func, jobject vp) {
return (jfloat)env->CallFloatMethod(func, jImPlatformFuncViewportSuppFloatGetMID, vp);
}
}
@@ -12,6 +12,20 @@ namespace Jni
void CallImStrConsumer(JNIEnv* env, jobject consumer, const char* str);
jstring CallImStrSupplier(JNIEnv* env, jobject supplier);
void CallImPlatformFuncViewport(JNIEnv* env, jobject func, jobject vp);
void CallImPlatformFuncViewportFloat(JNIEnv* env, jobject func, jobject vp, float f);
void CallImPlatformFuncViewportImVec2(JNIEnv* env, jobject func, jobject vp, jobject imVec2);
void CallImPlatformFuncViewportString(JNIEnv* env, jobject func, jobject vp, const char* str);
void CallImPlatformFuncViewportSuppImVec2(JNIEnv* env, jobject func, jobject vp, jobject imVec2);
jboolean CallImPlatformFuncViewportSuppBoolean(JNIEnv* env, jobject func, jobject vp);
jfloat CallImPlatformFuncViewportSuppFloat(JNIEnv* env, jobject func, jobject vp);
}
#endif