Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] Add ImGuiContext #65

Merged
merged 2 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions imgui-binding/src/main/java/imgui/ImGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import imgui.flag.ImGuiCond;
import imgui.flag.ImGuiDragDropFlags;
import imgui.flag.ImGuiInputTextFlags;
import imgui.internal.ImGuiContext;
import imgui.type.ImBoolean;
import imgui.type.ImDouble;
import imgui.type.ImFloat;
Expand All @@ -26,6 +27,7 @@ public class ImGui {
private static final String LIB_NAME_DEFAULT = System.getProperty("os.arch").contains("64") ? "imgui-java64" : "imgui-java";
private static final String LIB_TMP_DIR_PREFIX = "imgui-java-natives_" + System.currentTimeMillis();

private static final ImGuiContext IMGUI_CONTEXT;
private static final ImGuiIO IMGUI_IO;
private static final ImDrawList WINDOW_DRAW_LIST;
private static final ImDrawList BACKGROUND_DRAW_LIST;
Expand Down Expand Up @@ -55,6 +57,7 @@ public class ImGui {
System.loadLibrary(libName);
}

IMGUI_CONTEXT = new ImGuiContext(0);
IMGUI_IO = new ImGuiIO(0);
WINDOW_DRAW_LIST = new ImDrawList(0);
BACKGROUND_DRAW_LIST = new ImDrawList(0);
Expand Down Expand Up @@ -140,22 +143,53 @@ public static void init() {
//
// BINDING NOTICE: Getting of the current context is not implemented since it's a part of internal API which is not exposed here.

public static native void createContext(); /*
ImGui::CreateContext();
public static ImGuiContext createContext() {
IMGUI_CONTEXT.ptr = nCreateContext();
return IMGUI_CONTEXT;
}

private static native long nCreateContext(); /*
return (intptr_t)ImGui::CreateContext();
*/

public static void createContext(ImFontAtlas sharedFontAtlas) {
nCreateContext(sharedFontAtlas.ptr);
public static ImGuiContext createContext(ImFontAtlas sharedFontAtlas) {
IMGUI_CONTEXT.ptr = nCreateContext(sharedFontAtlas.ptr);
return IMGUI_CONTEXT;
}

private static native void nCreateContext(long sharedFontAtlasPtr); /*
ImGui::CreateContext((ImFontAtlas*)sharedFontAtlasPtr);
private static native long nCreateContext(long sharedFontAtlasPtr); /*
return (intptr_t)ImGui::CreateContext((ImFontAtlas*)sharedFontAtlasPtr);
*/

public static native void destroyContext(); /*
ImGui::DestroyContext();
*/

public static void destroyContext(ImGuiContext ctx) {
nDestroyContext(ctx.ptr);
}

private static native void nDestroyContext(long ptr); /*
ImGui::DestroyContext((ImGuiContext*) ptr);
*/

public static ImGuiContext getCurrentContext() {
IMGUI_CONTEXT.ptr = nGetCurrentContext();
return IMGUI_CONTEXT;
}

private static native long nGetCurrentContext(); /*
return (intptr_t)ImGui::GetCurrentContext();
*/

public static void setCurrentContext(ImGuiContext ctx) {
nSetCurrentContext(ctx.ptr);
}

private static native void nSetCurrentContext(long ptr); /*
ImGui::SetCurrentContext((ImGuiContext*) ptr);
*/

// Main

/**
Expand Down
9 changes: 9 additions & 0 deletions imgui-binding/src/main/java/imgui/internal/ImGuiContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package imgui.internal;

import imgui.binding.ImGuiStruct;

public class ImGuiContext extends ImGuiStruct {
public ImGuiContext(final long ptr) {
super(ptr);
}
}