[WIP] Viewports backend, 2
This commit is contained in:
1 parent
c1632cfd3e
commit
e9cfd62137
13 files changed
+126
-12
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -590,6 +590,75 @@ public final class ImGuiIO {
|
|||||||
ImGui::GetIO().ConfigDockingTransparentPayload = value;
|
ImGui::GetIO().ConfigDockingTransparentPayload = value;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Viewport options (when ImGuiConfigFlags_ViewportsEnable is set)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to make all floating imgui windows always create their own viewport.
|
||||||
|
* Otherwise, they are merged into the main host viewports when overlapping it. May also set ImGuiViewportFlags_NoAutoMerge on individual viewport.
|
||||||
|
*/
|
||||||
|
public native boolean getConfigViewportsNoAutoMerge(); /*
|
||||||
|
return ImGui::GetIO().ConfigViewportsNoAutoMerge;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to make all floating imgui windows always create their own viewport.
|
||||||
|
* Otherwise, they are merged into the main host viewports when overlapping it. May also set ImGuiViewportFlags_NoAutoMerge on individual viewport.
|
||||||
|
*/
|
||||||
|
public native void setConfigViewportsNoAutoMerge(boolean value); /*
|
||||||
|
ImGui::GetIO().ConfigViewportsNoAutoMerge = value;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable default OS task bar icon flag for secondary viewports. When a viewport doesn't want a task bar icon, ImGuiViewportFlags_NoTaskBarIcon will be set on it.
|
||||||
|
*/
|
||||||
|
public native boolean getConfigViewportsNoTaskBarIcon(); /*
|
||||||
|
return ImGui::GetIO().ConfigViewportsNoTaskBarIcon;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable default OS task bar icon flag for secondary viewports. When a viewport doesn't want a task bar icon, ImGuiViewportFlags_NoTaskBarIcon will be set on it.
|
||||||
|
*/
|
||||||
|
public native void setConfigViewportsNoTaskBarIcon(boolean value); /*
|
||||||
|
ImGui::GetIO().ConfigViewportsNoTaskBarIcon = value;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [BETA] Disable default OS window decoration flag for secondary viewports. When a viewport doesn't want window decorations,
|
||||||
|
* ImGuiViewportFlags_NoDecoration will be set on it. Enabling decoration can create subsequent issues at OS levels (e.g. minimum window size).
|
||||||
|
*/
|
||||||
|
public native boolean getConfigViewportsNoDecoration(); /*
|
||||||
|
return ImGui::GetIO().ConfigViewportsNoDecoration;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [BETA] Disable default OS window decoration flag for secondary viewports. When a viewport doesn't want window decorations,
|
||||||
|
* ImGuiViewportFlags_NoDecoration will be set on it. Enabling decoration can create subsequent issues at OS levels (e.g. minimum window size).
|
||||||
|
*/
|
||||||
|
public native void setConfigViewportsNoDecoration(boolean value); /*
|
||||||
|
ImGui::GetIO().ConfigViewportsNoDecoration = value;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable default OS parenting to main viewport for secondary viewports.
|
||||||
|
* By default, viewports are marked with ParentViewportId = <main_viewport>,
|
||||||
|
* expecting the platform back-end to setup a parent/child relationship between the OS windows (some back-end may ignore this).
|
||||||
|
* Set to true if you want the default to be 0, then all viewports will be top-level OS windows.
|
||||||
|
*/
|
||||||
|
public native boolean getConfigViewportsNoDefaultParent(); /*
|
||||||
|
return ImGui::GetIO().ConfigViewportsNoDefaultParent;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable default OS parenting to main viewport for secondary viewports.
|
||||||
|
* By default, viewports are marked with ParentViewportId = <main_viewport>,
|
||||||
|
* expecting the platform back-end to setup a parent/child relationship between the OS windows (some back-end may ignore this).
|
||||||
|
* Set to true if you want the default to be 0, then all viewports will be top-level OS windows.
|
||||||
|
*/
|
||||||
|
public native void setConfigViewportsNoDefaultParent(boolean value); /*
|
||||||
|
ImGui::GetIO().ConfigViewportsNoDefaultParent = value;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Time elapsed since last frame, in seconds.
|
* Time elapsed since last frame, in seconds.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ public final class ImGuiPlatformIO extends ImGuiStruct {
|
|||||||
JNIEnv* env = Jni::GetEnv();\
|
JNIEnv* env = Jni::GetEnv();\
|
||||||
env->SetLongField(jTmpViewport, Jni::GetBindingStructPtrID(), (intptr_t)vp);\
|
env->SetLongField(jTmpViewport, Jni::GetBindingStructPtrID(), (intptr_t)vp);\
|
||||||
Jni::CallImPlatformFuncViewportSuppImVec2(env, platformCallback##name, jTmpViewport, jTmpImVec2);\
|
Jni::CallImPlatformFuncViewportSuppImVec2(env, platformCallback##name, jTmpViewport, jTmpImVec2);\
|
||||||
Jni::ImVec2Cpy(env, jTmpImVec2, dst);\
|
Jni::ImVec2Cpy(env, jTmpImVec2, &dst);\
|
||||||
}\
|
}\
|
||||||
return dst;\
|
return dst;\
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,14 +38,14 @@ public final class ImGuiViewport extends ImGuiStruct {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See ImGuiViewportFlags_.
|
* See {@link imgui.flag.ImGuiViewportFlags}.
|
||||||
*/
|
*/
|
||||||
public native int getFlags(); /*
|
public native int getFlags(); /*
|
||||||
return IMGUI_VIEWPORT->Flags;
|
return IMGUI_VIEWPORT->Flags;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See ImGuiViewportFlags_.
|
* See {@link imgui.flag.ImGuiViewportFlags}.
|
||||||
*/
|
*/
|
||||||
public native void setFlags(int flags); /*
|
public native void setFlags(int flags); /*
|
||||||
IMGUI_VIEWPORT->Flags = flags;
|
IMGUI_VIEWPORT->Flags = flags;
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package imgui.glfw;
|
||||||
|
|
||||||
|
final class ImGuiImplGlfwNative {
|
||||||
|
private ImGuiImplGlfwNative() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/*JNI
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
// GLFW hack: Hide icon from task bar
|
||||||
|
// Applied only for windows
|
||||||
|
static native void win32hideFromTaskBar(long hwndPtr); /*
|
||||||
|
#if defined(_WIN32)
|
||||||
|
HWND hwnd = (HWND)hwndPtr;
|
||||||
|
LONG ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE);
|
||||||
|
ex_style &= ~WS_EX_APPWINDOW;
|
||||||
|
ex_style |= WS_EX_TOOLWINDOW;
|
||||||
|
::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
}
|
||||||
@@ -48,11 +48,6 @@ namespace Jni
|
|||||||
dst->y = env->GetFloatField(src, imVec2YID);
|
dst->y = env->GetFloatField(src, imVec2YID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImVec2Cpy(JNIEnv* env, jobject src, ImVec2 dst) {
|
|
||||||
dst.x = env->GetFloatField(src, imVec2XID);
|
|
||||||
dst.y = env->GetFloatField(src, imVec2YID);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImVec4Cpy(JNIEnv* env, ImVec4* src, jobject dst) {
|
void ImVec4Cpy(JNIEnv* env, ImVec4* src, jobject dst) {
|
||||||
env->SetFloatField(dst, imVec4XID, src->x);
|
env->SetFloatField(dst, imVec4XID, src->x);
|
||||||
env->SetFloatField(dst, imVec4YID, src->y);
|
env->SetFloatField(dst, imVec4YID, src->y);
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ namespace Jni
|
|||||||
void ImVec2Cpy(JNIEnv* env, ImVec2 src, jobject dst);
|
void ImVec2Cpy(JNIEnv* env, ImVec2 src, jobject dst);
|
||||||
|
|
||||||
void ImVec2Cpy(JNIEnv* env, jobject src, ImVec2* dst);
|
void ImVec2Cpy(JNIEnv* env, jobject src, ImVec2* dst);
|
||||||
void ImVec2Cpy(JNIEnv* env, jobject src, ImVec2 dst);
|
|
||||||
|
|
||||||
void ImVec4Cpy(JNIEnv* env, ImVec4* src, jobject dst);
|
void ImVec4Cpy(JNIEnv* env, ImVec4* src, jobject dst);
|
||||||
void ImVec4Cpy(JNIEnv* env, ImVec4 src, jobject dst);
|
void ImVec4Cpy(JNIEnv* env, ImVec4 src, jobject dst);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.lwjgl.glfw.GLFWErrorCallback;
|
|||||||
import org.lwjgl.glfw.GLFWKeyCallback;
|
import org.lwjgl.glfw.GLFWKeyCallback;
|
||||||
import org.lwjgl.glfw.GLFWMonitorCallback;
|
import org.lwjgl.glfw.GLFWMonitorCallback;
|
||||||
import org.lwjgl.glfw.GLFWMouseButtonCallback;
|
import org.lwjgl.glfw.GLFWMouseButtonCallback;
|
||||||
|
import org.lwjgl.glfw.GLFWNativeWin32;
|
||||||
import org.lwjgl.glfw.GLFWScrollCallback;
|
import org.lwjgl.glfw.GLFWScrollCallback;
|
||||||
import org.lwjgl.glfw.GLFWVidMode;
|
import org.lwjgl.glfw.GLFWVidMode;
|
||||||
|
|
||||||
@@ -43,6 +44,8 @@ import static org.lwjgl.system.MemoryUtil.NULL;
|
|||||||
* modify the rendering routine in the way you'd like.
|
* modify the rendering routine in the way you'd like.
|
||||||
*/
|
*/
|
||||||
public class ImGuiImplGlfw {
|
public class ImGuiImplGlfw {
|
||||||
|
protected static final boolean IS_WINDOWS = System.getProperty("os.name", "generic").toLowerCase().contains("win");
|
||||||
|
|
||||||
// Pointer of the current GLFW window
|
// Pointer of the current GLFW window
|
||||||
private long windowPtr;
|
private long windowPtr;
|
||||||
|
|
||||||
@@ -239,6 +242,10 @@ public class ImGuiImplGlfw {
|
|||||||
final ImGuiViewport mainViewport = ImGui.getMainViewport();
|
final ImGuiViewport mainViewport = ImGui.getMainViewport();
|
||||||
mainViewport.setPlatformHandle(windowPtr);
|
mainViewport.setPlatformHandle(windowPtr);
|
||||||
|
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
mainViewport.setPlatformHandleRaw(GLFWNativeWin32.glfwGetWin32Window(windowId));
|
||||||
|
}
|
||||||
|
|
||||||
if ((io.getConfigFlags() & ImGuiConfigFlags.ViewportsEnable) != 0) {
|
if ((io.getConfigFlags() & ImGuiConfigFlags.ViewportsEnable) != 0) {
|
||||||
initPlatformInterface();
|
initPlatformInterface();
|
||||||
}
|
}
|
||||||
@@ -528,6 +535,10 @@ public class ImGuiImplGlfw {
|
|||||||
|
|
||||||
vp.setPlatformHandle(data.window);
|
vp.setPlatformHandle(data.window);
|
||||||
|
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
vp.setPlatformHandleRaw(GLFWNativeWin32.glfwGetWin32Window(data.window));
|
||||||
|
}
|
||||||
|
|
||||||
glfwSetWindowPos(data.window, (int) vp.getPosX(), (int) vp.getPosY());
|
glfwSetWindowPos(data.window, (int) vp.getPosX(), (int) vp.getPosY());
|
||||||
|
|
||||||
// Install GLFW callbacks for secondary viewports
|
// Install GLFW callbacks for secondary viewports
|
||||||
@@ -562,6 +573,11 @@ public class ImGuiImplGlfw {
|
|||||||
@Override
|
@Override
|
||||||
public void accept(final ImGuiViewport vp) {
|
public void accept(final ImGuiViewport vp) {
|
||||||
final ImGuiViewportDataGlfw data = (ImGuiViewportDataGlfw) vp.getPlatformUserData();
|
final ImGuiViewportDataGlfw data = (ImGuiViewportDataGlfw) vp.getPlatformUserData();
|
||||||
|
|
||||||
|
if (IS_WINDOWS && (vp.getFlags() & ImGuiViewportFlags.NoTaskBarIcon) != 0) {
|
||||||
|
ImGuiImplGlfwNative.win32hideFromTaskBar(vp.getPlatformHandleRaw());
|
||||||
|
}
|
||||||
|
|
||||||
glfwShowWindow(data.window);
|
glfwShowWindow(data.window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -606,7 +622,7 @@ public class ImGuiImplGlfw {
|
|||||||
public void accept(final ImGuiViewport vp, final ImVec2 imVec2) {
|
public void accept(final ImGuiViewport vp, final ImVec2 imVec2) {
|
||||||
final ImGuiViewportDataGlfw data = (ImGuiViewportDataGlfw) vp.getPlatformUserData();
|
final ImGuiViewportDataGlfw data = (ImGuiViewportDataGlfw) vp.getPlatformUserData();
|
||||||
data.ignoreWindowSizeEventFrame = ImGui.getFrameCount();
|
data.ignoreWindowSizeEventFrame = ImGui.getFrameCount();
|
||||||
glfwSetWindowSize(data.window, (int) imVec2.y, (int) imVec2.y);
|
glfwSetWindowSize(data.window, (int) imVec2.x, (int) imVec2.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import imgui.ImGuiViewport;
|
||||||
import imgui.type.ImBoolean;
|
import imgui.type.ImBoolean;
|
||||||
import imgui.ImColor;
|
import imgui.ImColor;
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
@@ -40,8 +41,10 @@ final class ExampleUi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void render() {
|
void render() {
|
||||||
|
final ImGuiViewport mainViewport = ImGui.getMainViewport();
|
||||||
|
|
||||||
ImGui.setNextWindowSize(600, 300, ImGuiCond.Once);
|
ImGui.setNextWindowSize(600, 300, ImGuiCond.Once);
|
||||||
ImGui.setNextWindowPos(10, 10, ImGuiCond.Once);
|
ImGui.setNextWindowPos(mainViewport.getWorkPosX() + 10, mainViewport.getWorkPosY() + 10, ImGuiCond.Once);
|
||||||
|
|
||||||
ImGui.begin("Custom window"); // Start Custom window
|
ImGui.begin("Custom window"); // Start Custom window
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import imgui.ImFontConfig;
|
|||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import imgui.ImGuiFreeType;
|
import imgui.ImGuiFreeType;
|
||||||
import imgui.ImGuiIO;
|
import imgui.ImGuiIO;
|
||||||
|
import imgui.ImGuiStyle;
|
||||||
|
import imgui.flag.ImGuiCol;
|
||||||
import imgui.flag.ImGuiConfigFlags;
|
import imgui.flag.ImGuiConfigFlags;
|
||||||
import imgui.gl3.ImGuiImplGl3;
|
import imgui.gl3.ImGuiImplGl3;
|
||||||
import imgui.glfw.ImGuiImplGlfw;
|
import imgui.glfw.ImGuiImplGlfw;
|
||||||
@@ -143,7 +145,6 @@ public final class ImGuiGlfwExample {
|
|||||||
// Initialize ImGuiIO config
|
// Initialize ImGuiIO config
|
||||||
final ImGuiIO io = ImGui.getIO();
|
final ImGuiIO io = ImGui.getIO();
|
||||||
|
|
||||||
io.setMouseDrawCursor(true);
|
|
||||||
io.setIniFilename(null); // We don't want to save .ini file
|
io.setIniFilename(null); // We don't want to save .ini file
|
||||||
io.addConfigFlags(ImGuiConfigFlags.NavEnableKeyboard | ImGuiConfigFlags.DockingEnable | ImGuiConfigFlags.ViewportsEnable);
|
io.addConfigFlags(ImGuiConfigFlags.NavEnableKeyboard | ImGuiConfigFlags.DockingEnable | ImGuiConfigFlags.ViewportsEnable);
|
||||||
|
|
||||||
@@ -185,6 +186,13 @@ public final class ImGuiGlfwExample {
|
|||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
// Use freetype instead of stb_truetype to build a fonts texture
|
// Use freetype instead of stb_truetype to build a fonts texture
|
||||||
ImGuiFreeType.buildFontAtlas(fontAtlas, ImGuiFreeType.RasterizerFlags.LightHinting);
|
ImGuiFreeType.buildFontAtlas(fontAtlas, ImGuiFreeType.RasterizerFlags.LightHinting);
|
||||||
|
|
||||||
|
// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
|
||||||
|
if ((io.getConfigFlags() & ImGuiConfigFlags.ViewportsEnable) != 0) {
|
||||||
|
final ImGuiStyle style = ImGui.getStyle();
|
||||||
|
style.setWindowRounding(0.0f);
|
||||||
|
style.setColor(ImGuiCol.WindowBg, ImGui.getColorU32(ImGuiCol.WindowBg, 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main application loop
|
// Main application loop
|
||||||
|
|||||||
Reference in new issue
Block a user