diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1a86e85 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +end_of_line = lf +indent_style = space +insert_final_newline = true + +[*.{groovy,java}] +indent_size = 4 +max_line_length = 160 +trim_trailing_whitespace = true diff --git a/build.gradle b/build.gradle index a25963a..6cd5d2b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,8 @@ -plugins { - id 'java' -} - -group 'imgui' -version '1.0' - -sourceCompatibility = 1.8 - -repositories { - jcenter() - mavenCentral() -} - -dependencies { +allprojects { + group 'imgui-java' + version property('version') + repositories { + jcenter() + mavenCentral() + } } diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 0000000..4484164 --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'groovy' +} + +repositories { + jcenter() + mavenCentral() +} + +ext { + jnigenVersion = '1.9.10' +} + +dependencies { + implementation gradleApi() + implementation localGroovy() + + implementation "com.badlogicgames.gdx:gdx-jnigen:$jnigenVersion" +} diff --git a/buildSrc/src/main/groovy/imgui/generate/GenerateLibs.groovy b/buildSrc/src/main/groovy/imgui/generate/GenerateLibs.groovy new file mode 100644 index 0000000..a35236b --- /dev/null +++ b/buildSrc/src/main/groovy/imgui/generate/GenerateLibs.groovy @@ -0,0 +1,43 @@ +package imgui.generate + +import com.badlogic.gdx.jnigen.* +import groovy.transform.CompileStatic +import org.gradle.api.DefaultTask +import org.gradle.api.file.CopySpec +import org.gradle.api.tasks.TaskAction + +@CompileStatic +class GenerateLibs extends DefaultTask { + String description = 'Generates native libraries using classes under ":imgui-binding" and Dear-ImGui itself from "imgui" submodule.' + + private final String sourceDir = project.file('src/main/java') + private final String classpath = project.file('build/classes/java/main') + private final String jniDir = project.buildDir.path + '/jni' + private final String tmpFolder = project.buildDir.path + '/tmp' + private final String libsFolder = 'libsNative' + + @TaskAction + void generate() { + // Generate h/cpp files for JNI + new NativeCodeGenerator().generate(sourceDir, classpath, jniDir) + + // Copy ImGui h/cpp files + project.copy { CopySpec spec -> + spec.from(project.rootProject.file('imgui')) { CopySpec it -> it.include('*.h', '*.cpp') } + spec.from(project.file('src/main/native')) + spec.into(jniDir) + } + + // Generate platform dependant ant configs and header files + def buildConfig = new BuildConfig('imgui-java', tmpFolder, libsFolder, jniDir) + def win64 = BuildTarget.newDefaultTarget(BuildTarget.TargetOs.Windows, true) + new AntScriptGenerator().generate(buildConfig, win64) + + // Generate native libraries + BuildExecutor.executeAnt(jniDir + '/build-windows64.xml', '-v', '-Dhas-compiler=true', '-Drelease=true', 'clean', 'postcompile') + BuildExecutor.executeAnt(jniDir + '/build.xml', '-v', 'pack-natives') + + // Ant creates this folder in the root of the project. Since it will be empty we delete it + project.rootProject.file(libsFolder).deleteDir() + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..9759e31 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +version=0.0.1 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9a094fa..ae7cf7e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -#Sat Dec 14 21:13:09 MSK 2019 +#Sat Dec 14 22:33:02 MSK 2019 distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists diff --git a/imgui-binding/build.gradle b/imgui-binding/build.gradle new file mode 100644 index 0000000..137166c --- /dev/null +++ b/imgui-binding/build.gradle @@ -0,0 +1,10 @@ +import imgui.generate.GenerateLibs + +plugins { + id 'java' +} + +sourceCompatibility = 1.8 + +assemble.dependsOn clean +task generateLibs(type: GenerateLibs, dependsOn: assemble) diff --git a/imgui-binding/src/main/java/imgui/DrawData.java b/imgui-binding/src/main/java/imgui/DrawData.java new file mode 100644 index 0000000..fc17376 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/DrawData.java @@ -0,0 +1,38 @@ +package imgui; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public final class DrawData { + public final static int vBufferSize = (4 + 1) * 4; + public final static int iBufferSize = 2; + public final static int cmdBufferSize = (1 + 4 + 1) * 4; + public int cmdListsCount; // Number of ImDrawList* to render + public int totalIdxCount; // For convenience, sum of all ImDrawList's IdxBuffer.Size + public int totalVtxCount; + public int totalCmdCount; + public float displayPosX; + public float displayPosY; + public float displaySizeX; + public float displaySizeY; + public float framebufferScaleX; + public float framebufferScaleY; + public ByteBuffer vByteBuffer; + public ByteBuffer iByteBuffer; + public ByteBuffer cmdByteBuffer; + + public DrawData(ByteBuffer vByteBuffer, ByteBuffer iByteBuffer, ByteBuffer cmdByteBuffer) { + this.vByteBuffer = vByteBuffer; + this.iByteBuffer = iByteBuffer; + this.cmdByteBuffer = cmdByteBuffer; + } + + public DrawData(int maxVertice, int maxIndices, int maxCmd) { + this.vByteBuffer = ByteBuffer.allocateDirect(maxVertice * vBufferSize); + this.iByteBuffer = ByteBuffer.allocateDirect(maxIndices * iBufferSize); + this.cmdByteBuffer = ByteBuffer.allocateDirect(maxCmd * cmdBufferSize); + vByteBuffer.order(ByteOrder.nativeOrder()); + iByteBuffer.order(ByteOrder.nativeOrder()); + cmdByteBuffer.order(ByteOrder.nativeOrder()); + } +} diff --git a/imgui-binding/src/main/java/imgui/ImDrawList.java b/imgui-binding/src/main/java/imgui/ImDrawList.java new file mode 100644 index 0000000..f508d46 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/ImDrawList.java @@ -0,0 +1,128 @@ +package imgui; + +import imgui.enums.ImDrawCornerFlags; + +public class ImDrawList { + + public final static int TYPE_DEFAULT = 0; + public final static int TYPE_BACKGROUND = 1; + public final static int TYPE_FOREGROUND = 2; + + private int type = TYPE_DEFAULT; + + public ImDrawList(int type) { + this.type = type; + } + + public void AddLine(float a_x, float a_y, float b_x, float b_y, int col) { + Native.AddLine(type, a_x, a_y, b_x, b_y, col); + } + + public void AddLine(float a_x, float a_y, float b_x, float b_y, int col, float thinkness) { + Native.AddLine(type, a_x, a_y, b_x, b_y, col, thinkness); + } + + public void AddRect(float a_x, float a_y, float b_x, float b_y, int col) { + Native.AddRect(type, a_x, a_y, b_x, b_y, col); + } + + public void AddRect(float a_x, float a_y, float b_x, float b_y, int col, float rounding) { + Native.AddRect(type, a_x, a_y, b_x, b_y, col, rounding); + } + + public void AddRect(float a_x, float a_y, float b_x, float b_y, int col, float rounding, ImDrawCornerFlags rounding_corners_flags) { + Native.AddRect(type, a_x, a_y, b_x, b_y, col, rounding, rounding_corners_flags.getValue()); + } + + public void AddRect(float a_x, float a_y, float b_x, float b_y, int col, float rounding, ImDrawCornerFlags rounding_corners_flags, float thickness) { + Native.AddRect(type, a_x, a_y, b_x, b_y, col, rounding, rounding_corners_flags.getValue(), thickness); + } + + public void AddRectFilled(float a_x, float a_y, float b_x, float b_y, int col) { + Native.AddRectFilled(type, a_x, a_y, b_x, b_y, col); + } + + public void AddRectFilled(float a_x, float a_y, float b_x, float b_y, int col, float rounding) { + Native.AddRectFilled(type, a_x, a_y, b_x, b_y, col, rounding); + } + + public void AddRectFilled(float a_x, float a_y, float b_x, float b_y, int col, float rounding, ImDrawCornerFlags rounding_corners_flags) { + Native.AddRectFilled(type, a_x, a_y, b_x, b_y, col, rounding, rounding_corners_flags.getValue()); + } + + public void AddRectFilledMultiColor(float a_x, float a_y, float b_x, float b_y, int col_upr_left, float col_upr_right, int col_bot_right, int col_bot_left) { + Native.AddRectFilledMultiColor(type, a_x, a_y, b_x, b_y, col_upr_left, col_upr_right, col_bot_right, col_bot_left); + } + + public void AddQuad(float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, float d_x, float d_y, int col) { + Native.AddQuad(type, a_x, a_y, b_x, b_y, c_x, c_y, d_x, d_y, col); + } + + public void AddQuad(float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, float d_x, float d_y, int col, float thickness) { + Native.AddQuad(type, a_x, a_y, b_x, b_y, c_x, c_y, d_x, d_y, col, thickness); + } + + public void AddQuadFilled(float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, float d_x, float d_y, int col) { + Native.AddQuadFilled(type, a_x, a_y, b_x, b_y, c_x, c_y, d_x, d_y, col); + } + + public void AddTriangle(float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, int col) { + Native.AddTriangle(type, a_x, a_y, b_x, b_y, c_x, c_y, col); + } + + public void AddTriangle(float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, int col, float thickness) { + Native.AddTriangle(type, a_x, a_y, b_x, b_y, c_x, c_y, col, thickness); + } + + public void AddTriangleFilled(float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, int col) { + Native.AddTriangleFilled(type, a_x, a_y, b_x, b_y, c_x, c_y, col); + } + + public void AddCircle(float centre_x, float centre_y, float radius, float col, int num_segments, float thickness) { + Native.AddCircle(type, centre_x, centre_y, radius, col, num_segments, thickness); + } + + public void AddCircleFilled(float centre_x, float centre_y, float radius, float col) { + Native.AddCircleFilled(type, centre_x, centre_y, radius, col); + } + + public void AddCircleFilled(float centre_x, float centre_y, float radius, float col, int num_segments) { + Native.AddCircleFilled(type, centre_x, centre_y, radius, col, num_segments); + } + + public void AddText(float pos_x, float pos_y, int col, String text_begin) { + Native.AddText(type, pos_x, pos_y, col, text_begin); + } + + public void AddText(float pos_x, float pos_y, int col, String text_begin, String text_end) { + Native.AddText(type, pos_x, pos_y, col, text_begin, text_end); + } + + // TODO AddText + + public void AddImage(int textureID, float a_x, float a_y, float b_x, float b_y) { + Native.AddImage(type, textureID, a_x, a_y, b_x, b_y); + } + + public void AddImage(int textureID, float a_x, float a_y, float b_x, float b_y, float uv_a_x, float uv_a_y, float uv_b_x, float uv_b_y) { + Native.AddImage(type, textureID, a_x, a_y, b_x, b_y, uv_a_x, uv_a_y, uv_b_x, uv_b_y); + } + + //TODO AddImageQuad, AddImageRounded, AddPolyline, AddConvexPolyFilled + + public void AddBezierCurve(float pos0_x, float pos0_y, float cp0_x, float cp0_y, float cp1_x, float cp1_y, float pos1_x, float pos1_y, float col, float thickness) { + Native.AddBezierCurve(type, pos0_x, pos0_y, cp0_x, cp0_y, cp1_x, cp1_y, pos1_x, pos1_y, col, thickness); + } + + public void ChannelsSplit(int count) { + Native.ChannelsSplit(type, count); + } + + public void ChannelsMerge() { + Native.ChannelsMerge(type); + } + + public void ChannelsSetCurrent(int n) { + Native.ChannelsSetCurrent(type, n); + } +} diff --git a/imgui-binding/src/main/java/imgui/ImGui.java b/imgui-binding/src/main/java/imgui/ImGui.java new file mode 100644 index 0000000..e19a150 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/ImGui.java @@ -0,0 +1,1553 @@ +package imgui; + +import imgui.enums.*; + +import java.nio.Buffer; +import java.nio.ByteBuffer; + +//import com.badlogic.gdx.jnigen.JniGenSharedLibraryLoader; + +public class ImGui { + private static final String LIB_NAME_PROP = "imgui.library.name"; + private static final String LIB_NAME_DEFAULT = "imgui-java"; + + public static boolean enableLogging = true; + public static String TAG = "ImGui"; + private static boolean IMGUIINIT = false; + private static DrawData drawData = new DrawData(100000, 100000, 1000); + private static ImGuiIO imguiIO = new ImGuiIO(); + private static ImGuiStyle imguiStyle = new ImGuiStyle(); + private static ImVec2 imVec2 = new ImVec2(); + private static ImVec4 imVec4 = new ImVec4(); + private static ImDrawList imDrawList = new ImDrawList(ImDrawList.TYPE_DEFAULT); + private static ImDrawList imDrawListBackground = new ImDrawList(ImDrawList.TYPE_BACKGROUND); + private static ImDrawList imDrawListForeground = new ImDrawList(ImDrawList.TYPE_FOREGROUND); + + protected ImGui() { + } + + public static void init() { + init(true); + } + + public static void init(boolean logging) { + if (ImGui.IMGUIINIT) + return; + System.loadLibrary(System.getProperty(LIB_NAME_PROP, LIB_NAME_DEFAULT)); + ImGui.IMGUIINIT = true; + ImGui.enableLogging = logging; + + Native.init(); + Native.CreateContext(); + } + + public static ImGuiIO GetIO() { + return imguiIO; + } + + public static ImGuiStyle GetStyle() { + return imguiStyle; + } + + public static void ShowStyleEditor() { + Native.ShowStyleEditor(); + } + + public static void ShowDemoWindow() { + Native.ShowDemoWindow(); + } + + public static void ShowDemoWindow(boolean open) { + Native.ShowDemoWindow(open); + } + + public static void ShowMetricsWindow() { + Native.ShowMetricsWindow(); + } + + public static void ShowMetricsWindow(boolean open) { + Native.ShowMetricsWindow(open); + } + + public static void UpdateDisplayAndInputAndFrame(float deltaTime, float w, float h, float backBufferWidth, float backBufferHeight, + int mouseX, int mouseY, boolean mouseDown0, boolean mouseDown1, boolean mouseDown2) { + Native.UpdateDisplayAndInputAndFrame(imguiIO, imguiStyle, deltaTime, w, h, backBufferWidth, backBufferHeight, + mouseX, mouseY, mouseDown0, mouseDown1, mouseDown2, false, false, false); + } + + public static void initKeyMap(int[] keys) { + Native.initKeyMap(keys); + } + + public static void UpdateKey(int key, boolean pressed, boolean released, boolean ctrlKey, boolean shiftKey, boolean altKey, boolean superKey) { + Native.updateKey(key, pressed, released, ctrlKey, shiftKey, altKey, superKey); + } + + public static void UpdateScroll(float amountX, float amountY) { + Native.updateScroll(amountX, amountY); + } + + public static void UpdateKeyTyped(int c) { + Native.updateKeyTyped(c); + } + + public static void Render() { + Native.Render(); + } + + public static DrawData GetDrawData() { + ByteBuffer cmdByteBuffer = drawData.cmdByteBuffer; + ByteBuffer vByteBuffer = drawData.vByteBuffer; + ByteBuffer iByteBuffer = drawData.iByteBuffer; + vByteBuffer.position(0); + iByteBuffer.position(0); + cmdByteBuffer.position(0); + Native.GetDrawData(drawData, iByteBuffer, vByteBuffer, cmdByteBuffer); + return drawData; + } + + public static void GetTexDataAsRGBA32(TexDataRGBA32 jTexData, Buffer pixelBuffer) { + Native.GetTexDataAsRGBA32(jTexData, pixelBuffer); + } + + public static void SetFontTexID(int id) { + Native.SetFontTexID(id); + } + + public static void StyleColorsDark() { + Native.StyleColorsDark(); + } + + public static void StyleColorsClassic() { + Native.StyleColorsClassic(); + } + + public static void StyleColorsLight() { + Native.StyleColorsLight(); + } + + public static boolean Begin(String title) { + return Native.Begin(title); + } + + public static boolean Begin(String title, ImGuiBoolean p_open, ImGuiWindowFlags flags) { + return Native.Begin(title, p_open.data, flags.getValue()); + } + + public static void End() { + Native.End(); + } + + // Child Windows + // - Use child windows to begin into a self-contained independent scrolling/clipping regions within a host window. Child windows can embed their own child. + // - For each independent axis of 'size': ==0.0f: use remaining host window size / >0.0f: fixed size / <0.0f: use remaining window size minus abs(size) / Each axis can use a different mode, e.g. ImVec2(0,400). + // - BeginChild() returns false to indicate the window is collapsed or fully clipped, so you may early out and omit submitting anything to the window. + // Always call a matching EndChild() for each BeginChild() call, regardless of its return value [this is due to legacy reason and is inconsistent with most other functions such as BeginMenu/EndMenu, BeginPopup/EndPopup, etc. where the EndXXX call should only be called if the corresponding BeginXXX function returned true.] + + + public static boolean BeginChild(String str_id) { + return Native.BeginChild(str_id); + } + + public static boolean BeginChild(String str_id, float width, float height) { + return Native.BeginChild(str_id, width, height); + } + + public static boolean BeginChild(String str_id, float width, float height, boolean border) { + return Native.BeginChild(str_id, width, height, border); + } + + public static boolean BeginChild(String str_id, float width, float height, boolean border, ImGuiWindowFlags flags) { + return Native.BeginChild(str_id, width, height, border, flags.getValue()); + } + + public static boolean BeginChild(int imGuiID) { + return Native.BeginChild(imGuiID); + } + + public static boolean BeginChild(int imGuiID, float width, float height, boolean border) { + return Native.BeginChild(imGuiID, width, height, border); + } + + public static boolean BeginChild(int imGuiID, float width, float height, boolean border, ImGuiWindowFlags flags) { + return Native.BeginChild(imGuiID, width, height, border, flags.getValue()); + } + + public static void EndChild() { + Native.EndChild(); + } + + // Windows Utilities + // - "current window" = the window we are appending into while inside a Begin()/End() block. "next window" = next window we will Begin() into. + + public static boolean IsWindowAppearing() { + return Native.IsWindowAppearing(); + } + + public static boolean IsWindowCollapsed() { + return Native.IsWindowCollapsed(); + } + + public static boolean IsWindowFocused() { + return Native.IsWindowFocused(); + } + + public static boolean IsWindowFocused(ImGuiFocusedFlags flags) { + return Native.IsWindowFocused(flags.getValue()); + } + + public static boolean IsWindowHovered() { + return Native.IsWindowHovered(); + } + + public static boolean IsWindowHovered(ImGuiHoveredFlags flags) { + return Native.IsWindowHovered(flags.getValue()); + } + + public static ImDrawList GetWindowDrawList() { + return imDrawList; + } + + public static ImDrawList GetBackgroundDrawList() { + return imDrawListBackground; + } + + public static ImDrawList GetForegroundDrawList() { + return imDrawListForeground; + } + + public static ImVec2 GetWindowPos() { + Native.GetWindowPos(imVec2); + return imVec2; + } + + public static float GetWindowPosX() { + return Native.GetWindowPosX(); + } + + public static float GetWindowPosY() { + return Native.GetWindowPosY(); + } + + public static ImVec2 GetWindowSize() { + Native.GetWindowSize(imVec2); + return imVec2; + } + + public static float GetWindowWidth() { + return Native.GetWindowWidth(); + } + + public static float GetWindowHeight() { + return Native.GetWindowHeight(); + } + + // Prefer using SetNextXXX functions (before Begin) rather that SetXXX functions (after Begin). + + public static void SetNextWindowPos(float x, float y) { + Native.SetNextWindowPos(x, y); + } + + public static void SetNextWindowPos(float x, float y, ImGuiCond cond, float pivotX, float pivotY) { + Native.SetNextWindowPos(x, y, cond.getValue(), pivotX, pivotY); + } + + public static void SetNextWindowSize(int width, int height) { + Native.SetNextWindowSize(width, height); + } + + public static void SetNextWindowSize(int width, int height, ImGuiCond cond) { + Native.SetNextWindowSize(width, height, cond.getValue()); + } + + public static void SetNextWindowSizeConstraints(float minWidth, float minHeight, float maxWidth, float maxHeight) { + Native.SetNextWindowSizeConstraints(minWidth, minHeight, maxWidth, maxHeight); + } + + public static void SetNextWindowContentSize(float sizeX, float sizeY) { + Native.SetNextWindowContentSize(sizeX, sizeY); + } + + public static void SetNextWindowCollapsed(boolean flag) { + Native.SetNextWindowCollapsed(flag); + } + + public static void SetNextWindowFocus() { + Native.SetNextWindowFocus(); + } + + public static void SetNextWindowBgAlpha(float alpha) { + Native.SetNextWindowBgAlpha(alpha); + } + + //TODO add more methods + + public static void SetWindowFocus() { + Native.SetWindowFocus(); + } + + public static void SetWindowFocus(String name) { + if (name == null) + Native.RemoveWindowFocus(); + else + Native.SetWindowFocus(name); + } + + // Content region + // - Those functions are bound to be redesigned soon (they are confusing, incomplete and return values in local window coordinates which increases confusion) + + public static ImVec2 GetContentRegionMax() { + Native.GetContentRegionMax(imVec2); + return imVec2; + } + + public static ImVec2 GetContentRegionAvail() { + Native.GetContentRegionAvail(imVec2); + return imVec2; + } + + public static float GetContentRegionAvailWidth() { + return Native.GetContentRegionAvailWidth(); + } + + public static ImVec2 GetWindowContentRegionMin() { + Native.GetWindowContentRegionMin(imVec2); + return imVec2; + } + + public static ImVec2 GetWindowContentRegionMax() { + Native.GetWindowContentRegionMax(imVec2); + return imVec2; + } + + public static float GetWindowContentRegionWidth() { + return Native.GetWindowContentRegionWidth(); + } + + // Windows Scrolling + + public static float GetScrollX() { + return Native.GetScrollX(); + } + + public static float GetScrollY() { + return Native.GetScrollY(); + } + + public static float GetScrollMaxX() { + return Native.GetScrollMaxX(); + } + + public static float GetScrollMaxY() { + return Native.GetScrollMaxY(); + } + + public static void SetScrollX(float scroll_x) { + Native.SetScrollX(scroll_x); + } + + public static void SetScrollY(float scroll_y) { + Native.SetScrollY(scroll_y); + } + + public static void SetScrollHereY() { + Native.SetScrollHereY(); + } + + public static void SetScrollHereY(float center_y_ratio) { + Native.SetScrollHereY(center_y_ratio); + } + + public static void SetScrollFromPosY(float local_y) { + Native.SetScrollFromPosY(local_y); + } + + public static void SetScrollFromPosY(float local_y, float center_y_ratio) { + Native.SetScrollFromPosY(local_y, center_y_ratio); + } + + // Parameters stacks (shared) + + public static void PushStyleColor(ImGuiCol idx, int col) { + Native.PushStyleColor(idx.getValue(), col); + } + + public static void PushStyleColor(ImGuiCol idx, float r, float g, float b, float a) { + Native.PushStyleColor(idx.getValue(), r, g, b, a); + } + + public static void PopStyleColor() { + Native.PopStyleColor(); + } + + public static void PopStyleColor(int count) { + Native.PopStyleColor(count); + } + + public static void PushStyleVar(ImGuiStyleVar idx, float val) { + Native.PushStyleVar(idx.getValue(), val); + } + + public static void PushStyleVar(ImGuiStyleVar idx, float valX, float valY) { + Native.PushStyleVar(idx.getValue(), valX, valY); + } + + public static void PopStyleVar() { + Native.PopStyleVar(); + } + + public static void PopStyleVar(int count) { + Native.PopStyleVar(count); + } + + // Parameters stacks (current window) + + public static void PushItemWidth(float item_width) { + Native.PushItemWidth(item_width); + } + + public static void PopItemWidth() { + Native.PopItemWidth(); + } + + public static void SetNextItemWidth(float item_width) { + Native.SetNextItemWidth(item_width); + } + + public static float CalcItemWidth() { + return Native.CalcItemWidth(); + } + + public static void PushTextWrapPos() { + Native.PushTextWrapPos(); + } + + public static void PushTextWrapPos(float wrap_local_pos_x) { + Native.PushTextWrapPos(wrap_local_pos_x); + } + + public static void PopTextWrapPos() { + Native.PopTextWrapPos(); + } + + public static void PushAllowKeyboardFocus(boolean allow_keyboard_focus) { + Native.PushAllowKeyboardFocus(allow_keyboard_focus); + } + + public static void PushButtonRepeat() { + Native.PopAllowKeyboardFocus(); + } + + public static void PushButtonRepeat(boolean repeat) { + Native.PushButtonRepeat(repeat); + } + + public static void PopButtonRepeat() { + Native.PopButtonRepeat(); + } + + // Cursor / Layout + // - By "cursor" we mean the current output position. + // - The typical widget behavior is to output themselves at the current cursor position, then move the cursor one line down. + + public static void Separator() { + Native.Separator(); + } + + public static void SameLine() { + Native.SameLine(); + } + + public static void SameLine(float offsetFromStartX) { + Native.SameLine(offsetFromStartX); + } + + public static void SameLine(float offsetFromStartX, float spacing) { + Native.SameLine(offsetFromStartX, spacing); + } + + public static void NewLine() { + Native.NewLine(); + } + + public static void Spacing() { + Native.Spacing(); + } + + public static void Dummy(float width, float height) { + Native.Dummy(width, height); + } + + public static void Indent() { + Native.Indent(); + } + + public static void Indent(float indentW) { + Native.Indent(indentW); + } + + public static void Unindent() { + Native.Unindent(); + } + + public static void Unindent(float indentW) { + Native.Unindent(indentW); + } + + public static void BeginGroup() { + Native.BeginGroup(); + } + + public static void EndGroup() { + Native.EndGroup(); + } + + public static void GetCursorPos() { + //TODO impl + } + + public static float GetCursorPosX() { + return Native.GetCursorPosX(); + } + + public static float GetCursorPosY() { + return Native.GetCursorPosY(); + } + + public static void SetCursorPos(float x, float y) { + Native.SetCursorPos(x, y); + } + + public static void SetCursorPosX(float x) { + Native.SetCursorPosX(x); + } + + public static void SetCursorPosY(float y) { + Native.SetCursorPosY(y); + } + + public static ImVec2 GetCursorStartPos() { + Native.GetCursorStartPos(imVec2); + return imVec2; + } + + public static ImVec2 GetCursorScreenPos() { + Native.GetCursorScreenPos(imVec2); + return imVec2; + } + + public static void SetCursorScreenPos(float x, float y) { + Native.SetCursorScreenPos(x, y); + } + + public static void AlignTextToFramePadding() { + Native.AlignTextToFramePadding(); + } + + public static float GetTextLineHeight() { + return Native.GetTextLineHeight(); + } + + public static float GetTextLineHeightWithSpacing() { + return Native.GetTextLineHeightWithSpacing(); + } + + public static float GetFrameHeight() { + return Native.GetFrameHeight(); + } + + public static float GetFrameHeightWithSpacing() { + return Native.GetFrameHeightWithSpacing(); + } + + // ID stack/scopes + // - Read the FAQ for more details about how ID are handled in dear imgui. If you are creating widgets in a loop you most + // likely want to push a unique identifier (e.g. object pointer, loop index) to uniquely differentiate them. + // - The resulting ID are hashes of the entire stack. + // - You can also use the "Label##foobar" syntax within widget label to distinguish them from each others. + // - In this header file we use the "label"/"name" terminology to denote a string that will be displayed and used as an ID, + // whereas "str_id" denote a string that is only used as an ID and not normally displayed. + + public static void PushID(String str_id) { + Native.PushID(str_id); + } + + public static void PushID(String str_id_begin, String str_id_end) { + Native.PushID(str_id_begin, str_id_end); + } + + public static void PushID(int int_id) { + Native.PushID(int_id); + } + + public static void PopID() { + Native.PopID(); + } + + public static int GetID(String str_id) { + return Native.GetID(str_id); + } + + public static int GetID(String str_id_begin, String str_id_end) { + return Native.GetID(str_id_begin, str_id_end); + } + + // TODO GetID ptr_id + + // Widgets: Text + + public static void TextUnformatted(String text) { + Native.TextUnformatted(text); + } + + public static void TextUnformatted(String text, String text_end) { + Native.TextUnformatted(text, text_end); + } + + public static void Text(String text) { + Native.Text(text); + } + + public static void TextColored(float r, float g, float b, float a, String text) { + Native.TextColored(r, g, b, a, text); + } + + public static void TextDisabled(String text) { + Native.TextDisabled(text); + } + + public static void TextWrapped(String text) { + Native.TextWrapped(text); + } + + public static void LabelText(String label, String text) { + Native.LabelText(label, text); + } + + public static void BulletText(String text) { + Native.BulletText(text); + } + + // Widgets: Main + // - Most widgets return true when the value has been changed or when pressed/selected + + /** + * button + */ + public static boolean Button(String label) { + return Native.Button(label); + } + + /** + * button + */ + public static boolean Button(String label, float width, float height) { + return Native.Button(label, width, height); + } + + /** + * button with FramePadding=(0,0) to easily embed within text + */ + public static boolean SmallButton(String label) { + return Native.SmallButton(label); + } + + /** + * button behavior without the visuals, frequently useful to build custom behaviors using the public api (along with IsItemActive, IsItemHovered, etc.) + */ + public static boolean InvisibleButton(String strId, float width, float height) { + return Native.InvisibleButton(strId, width, height); + } + + /** + * square button with an arrow shape + */ + public static boolean ArrowButton(String strId, ImGuiDir dir) { + return Native.ArrowButton(strId, dir.toInt()); + } + + public static void Image(int textureID, float sizeX, float sizeY) { + Native.Image(textureID, sizeX, sizeY); + } + + public static void Image(int textureID, float sizeX, float sizeY, float uv0_x, float uv0_y, float uv1_x, float uv1_y) { + Native.Image(textureID, sizeX, sizeY, uv0_x, uv0_y, uv1_x, uv1_y); + } + + public static boolean ImageButton(int textureID, float sizeX, float sizeY) { + return Native.ImageButton(textureID, sizeX, sizeY); + } + + public static boolean ImageButton(int textureID, float sizeX, float sizeY, float uv0_x, float uv0_y, float uv1_x, float uv1_y, int frame_padding) { + return Native.ImageButton(textureID, sizeX, sizeY, uv0_x, uv0_y, uv1_x, uv1_y, frame_padding); + } + + public static boolean Checkbox(String label, ImGuiBoolean value) { + return Native.Checkbox(label, value.data); + } + + public static boolean CheckboxFlags(String label, ImGuiInt flags, ImGuiTabBarFlags flagsValues) { + return Native.CheckboxFlags(label, flags.data, flagsValues.getValue()); + } + + public static boolean RadioButton(String label, boolean active) { + return Native.RadioButton(label, active); + } + + public static boolean RadioButton(String label, ImGuiInt value, int v_button) { + return Native.RadioButton(label, value.data, v_button); + } + + public static void ProgressBar(float fraction) { + Native.ProgressBar(fraction); + } + + public static void ProgressBar(float fraction, float size_arg_x, float size_arg_y) { + Native.ProgressBar(fraction, size_arg_x, size_arg_y); + } + + public static void Bullet() { + Native.Bullet(); + } + + // Widgets: Combo Box + // - The new BeginCombo()/EndCombo() api allows you to manage your contents and selection state however you want it, by creating e.g. Selectable() items. + // - The old Combo() api are helpers over BeginCombo()/EndCombo() which are kept available for convenience purpose. + + public static boolean BeginCombo(String label, String preview_value) { + return Native.BeginCombo(label, preview_value); + } + + public static boolean BeginCombo(String label, String preview_value, ImGuiComboFlags flags) { + return Native.BeginCombo(label, preview_value, flags.getValue()); + } + + public static void EndCombo() { + Native.EndCombo(); + } + + public static boolean Combo(String label, ImGuiInt current_item, String[] items, int items_count) { + return Native.Combo(label, current_item.data, items, items_count); + } + + public static boolean Combo(String label, ImGuiInt current_item, String[] items, int items_count, int popup_max_height_in_items) { + return Native.Combo(label, current_item.data, items, items_count, popup_max_height_in_items); + } + + public static boolean Combo(String label, ImGuiInt current_item, String items_separated_by_zeros) { + return Native.Combo(label, current_item.data, items_separated_by_zeros); + } + + public static boolean Combo(String label, ImGuiInt current_item, String items_separated_by_zeros, int popup_max_height_in_items) { + return Native.Combo(label, current_item.data, items_separated_by_zeros, popup_max_height_in_items); + } + + // Widgets: Drags + // - CTRL+Click on any drag box to turn them into an input box. Manually input values aren't clamped and can go off-bounds. + // - For all the Float2/Float3/Float4/Int2/Int3/Int4 versions of every functions, note that a 'float v[X]' function argument is the same as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible. You can pass address of your first element out of a contiguous set, e.g. &myvector.x + // - Adjust format string to decorate the value with a prefix, a suffix, or adapt the editing and display precision e.g. "%.3f" -> 1.234; "%5.2f secs" -> 01.23 secs; "Biscuit: %.0f" -> Biscuit: 1; etc. + // - Speed are per-pixel of mouse movement (v_speed=0.2f: mouse needs to move by 5 pixels to increase value by 1). For gamepad/keyboard navigation, minimum speed is Max(v_speed, minimum_step_at_given_precision). + + public static boolean DragFloat(String label, ImGuiFloat v) { + return Native.DragFloat(label, v.data); + } + + public static boolean DragFloat(String label, ImGuiFloat v, float v_speed) { + return Native.DragFloat(label, v.data, v_speed); + } + + public static boolean DragFloat(String label, ImGuiFloat v, float v_speed, float v_min, float v_max, String format) { + return Native.DragFloat(label, v.data, v_speed, v_min, v_max, format); + } + + public static boolean DragFloat(String label, ImGuiFloat v, float v_speed, float v_min, float v_max, String format, float power) { + return Native.DragFloat(label, v.data, v_speed, v_min, v_max, format, power); + } + + public static boolean DragFloat2(String label, float[] v) { + return Native.DragFloat2(label, v); + } + + public static boolean DragFloat2(String label, float[] v, float v_speed, float v_min, float v_max, String format, float power) { + return Native.DragFloat2(label, v, v_speed, v_min, v_max, format, power); + } + + public static boolean DragFloat3(String label, float[] v) { + return Native.DragFloat3(label, v); + } + + public static boolean DragFloat3(String label, float[] v, float v_speed, float v_min, float v_max, String format, float power) { + return Native.DragFloat3(label, v, v_speed, v_min, v_max, format, power); + } + + public static boolean DragFloat4(String label, float[] v) { + return Native.DragFloat4(label, v); + } + + public static boolean DragFloat4(String label, float[] v, float v_speed, float v_min, float v_max, String format, float power) { + return Native.DragFloat4(label, v, v_speed, v_min, v_max, format, power); + } + + public static boolean DragFloatRange2(String label, ImGuiFloat v_current_min, ImGuiFloat v_current_max) { + return Native.DragFloatRange2(label, v_current_min.data, v_current_max.data); + } + + public static boolean DragFloatRange2(String label, ImGuiFloat v_current_min, ImGuiFloat v_current_max, float v_speed, float v_min, float v_max, String format, String format_max, float power) { + return Native.DragFloatRange2(label, v_current_min.data, v_current_max.data, v_speed, v_min, v_max, format, format_max, power); + } + + public static boolean DragInt(String label, ImGuiInt v) { + return Native.DragInt(label, v.data); + } + + public static boolean DragInt(String label, ImGuiInt v, float v_speed) { + return Native.DragInt(label, v.data, v_speed); + } + + public static boolean DragInt(String label, ImGuiInt v, float v_speed, float v_min, float v_max, String format) { + return Native.DragInt(label, v.data, v_speed, v_min, v_max, format); + } + + public static boolean DragInt2(String label, int[] v) { + return Native.DragInt2(label, v); + } + + public static boolean DragInt2(String label, int[] v, float v_speed, float v_min, float v_max, String format) { + return Native.DragInt2(label, v, v_speed, v_min, v_max, format); + } + + public static boolean DragInt3(String label, int[] v) { + return Native.DragInt3(label, v); + } + + public static boolean DragInt3(String label, int[] v, float v_speed, float v_min, float v_max, String format) { + return Native.DragInt3(label, v, v_speed, v_min, v_max, format); + } + + public static boolean DragInt4(String label, int[] v) { + return Native.DragInt4(label, v); + } + + public static boolean DragInt4(String label, int[] v, float v_speed, float v_min, float v_max, String format) { + return Native.DragInt4(label, v, v_speed, v_min, v_max, format); + } + + public static boolean DragIntRange2(String label, ImGuiInt v_current_min, ImGuiInt v_current_max) { + return Native.DragIntRange2(label, v_current_min.data, v_current_max.data); + } + + public static boolean DragIntRange2(String label, ImGuiInt v_current_min, ImGuiInt v_current_max, float v_speed, float v_min, float v_max, String format, String format_max) { + return Native.DragIntRange2(label, v_current_min.data, v_current_max.data, v_speed, v_min, v_max, format, format_max); + } + + //TODO impl +// public static boolean DragScalar(String label, ImGuiDataType_ data_type, ImGuiInt v, ImGuiInt v_current_max, float v_speed, float v_min, float v_max, String format, String format_max) { +// return ImGuiNative.DragScalar(label, data_type.getValue(), v.data, v_current_max.data, v_speed, v_min, v_max, format, format_max); +// } + + + // Widgets: Sliders + // - CTRL+Click on any slider to turn them into an input box. Manually input values aren't clamped and can go off-bounds. + // - Adjust format string to decorate the value with a prefix, a suffix, or adapt the editing and display precision e.g. "%.3f" -> 1.234; "%5.2f secs" -> 01.23 secs; "Biscuit: %.0f" -> Biscuit: 1; etc. + + public static boolean SliderFloat(String label, ImGuiFloat v, float v_min, float v_max) { + return Native.SliderFloat(label, v.data, v_min, v_max); + } + + public static boolean SliderFloat(String label, ImGuiFloat v, float v_min, float v_max, String format) { + return Native.SliderFloat(label, v.data, v_min, v_max, format); + } + + public static boolean SliderFloat(String label, ImGuiFloat v, float v_min, float v_max, String format, float power) { + return Native.SliderFloat(label, v.data, v_min, v_max, format, power); + } + + public static boolean SliderFloat2(String label, float[] v, float v_min, float v_max) { + return Native.SliderFloat2(label, v, v_min, v_max); + } + + public static boolean SliderFloat2(String label, float[] v, float v_min, float v_max, String format, float power) { + return Native.SliderFloat2(label, v, v_min, v_max, format, power); + } + + public static boolean SliderFloat3(String label, float[] v, float v_min, float v_max) { + return Native.SliderFloat3(label, v, v_min, v_max); + } + + public static boolean SliderFloat3(String label, float[] v, float v_min, float v_max, String format, float power) { + return Native.SliderFloat3(label, v, v_min, v_max, format, power); + } + + public static boolean SliderFloat4(String label, float[] v, float v_min, float v_max) { + return Native.SliderFloat4(label, v, v_min, v_max); + } + + public static boolean SliderFloat4(String label, float[] v, float v_min, float v_max, String format, float power) { + return Native.SliderFloat4(label, v, v_min, v_max, format, power); + } + + public static boolean SliderAngle(String label, ImGuiFloat v) { + return Native.SliderAngle(label, v.data); + } + + public static boolean SliderAngle(String label, ImGuiFloat v, float v_degrees_min, float v_degrees_max, String format) { + return Native.SliderAngle(label, v.data, v_degrees_min, v_degrees_max, format); + } + + public static boolean SliderInt(String label, ImGuiInt v, int v_min, int v_max) { + return Native.SliderInt(label, v.data, v_min, v_max); + } + + public static boolean SliderInt(String label, ImGuiInt v, int v_min, int v_max, String format) { + return Native.SliderInt(label, v.data, v_min, v_max, format); + } + + public static boolean SliderInt2(String label, int[] v, int v_min, int v_max) { + return Native.SliderInt2(label, v, v_min, v_max); + } + + public static boolean SliderInt2(String label, int[] v, int v_min, int v_max, String format) { + return Native.SliderInt2(label, v, v_min, v_max, format); + } + + public static boolean SliderInt3(String label, int[] v, int v_min, int v_max) { + return Native.SliderInt3(label, v, v_min, v_max); + } + + public static boolean SliderInt3(String label, int[] v, int v_min, int v_max, String format) { + return Native.SliderInt3(label, v, v_min, v_max, format); + } + + public static boolean SliderInt4(String label, int[] v, int v_min, int v_max) { + return Native.SliderInt4(label, v, v_min, v_max); + } + + public static boolean SliderInt4(String label, int[] v, int v_min, int v_max, String format) { + return Native.SliderInt4(label, v, v_min, v_max, format); + } + + public static boolean SliderScalar(String label, ImGuiDataType data_type, ImGuiInt v, int v_min, int v_max) { + return Native.SliderScalar(label, data_type.getValue(), v.data, v_min, v_max); + } + + public static boolean SliderScalar(String label, ImGuiDataType data_type, ImGuiInt v, int v_min, int v_max, String format, float power) { + return Native.SliderScalar(label, data_type.getValue(), v.data, v_min, v_max, format, power); + } + + public static boolean SliderScalar(String label, ImGuiDataType data_type, ImGuiFloat v, float v_min, float v_max) { + return Native.SliderScalar(label, data_type.getValue(), v.data, v_min, v_max); + } + + public static boolean SliderScalar(String label, ImGuiDataType data_type, ImGuiFloat v, float v_min, float v_max, String format, float power) { + return Native.SliderScalar(label, data_type.getValue(), v.data, v_min, v_max, format, power); + } + + public static boolean VSliderFloat(String label, float sizeX, float sizeY, ImGuiFloat v, float v_min, float v_max) { + return Native.VSliderFloat(label, sizeX, sizeY, v.data, v_min, v_max); + } + + public static boolean VSliderFloat(String label, float sizeX, float sizeY, ImGuiFloat v, float v_min, float v_max, String format, float power) { + return Native.VSliderFloat(label, sizeX, sizeY, v.data, v_min, v_max, format, power); + } + + public static boolean VSliderInt(String label, float sizeX, float sizeY, ImGuiInt v, int v_min, int v_max) { + return Native.VSliderInt(label, sizeX, sizeY, v.data, v_min, v_max); + } + + public static boolean VSliderInt(String label, float sizeX, float sizeY, ImGuiInt v, int v_min, int v_max, String format) { + return Native.VSliderInt(label, sizeX, sizeY, v.data, v_min, v_max, format); + } + + public static boolean VSliderScalar(String label, float sizeX, float sizeY, ImGuiDataType data_type, ImGuiFloat v, float v_min, float v_max) { + return Native.VSliderScalar(label, sizeX, sizeY, data_type.getValue(), v.data, v_min, v_max); + } + + public static boolean VSliderScalar(String label, float sizeX, float sizeY, ImGuiDataType data_type, ImGuiFloat v, float v_min, float v_max, String format, float power) { + return Native.VSliderScalar(label, sizeX, sizeY, data_type.getValue(), v.data, v_min, v_max, format, power); + } + + public static boolean VSliderScalar(String label, float sizeX, float sizeY, ImGuiDataType data_type, ImGuiInt v, int v_min, int v_max) { + return Native.VSliderScalar(label, sizeX, sizeY, data_type.getValue(), v.data, v_min, v_max); + } + + public static boolean VSliderScalar(String label, float sizeX, float sizeY, ImGuiDataType data_type, ImGuiInt v, int v_min, int v_max, String format, float power) { + return Native.VSliderScalar(label, sizeX, sizeY, data_type.getValue(), v.data, v_min, v_max, format, power); + } + + // Widgets: Input with Keyboard + // - If you want to use InputText() with a dynamic string type such as std::string or your own, see misc/cpp/imgui_stdlib.h + // - Most of the ImGuiInputTextFlags flags are only useful for InputText() and not for InputFloatX, InputIntX, InputDouble etc. + + public static boolean InputText(String label, ImGuiString text) { + return Native.InputText(label, text.data, text.data.length, 0, text.inputData, text.inputData.maxChar, text.inputData.allowedChar, text.inputData.allowedChar.length()); + } + + public static boolean InputText(String label, ImGuiString text, ImGuiInputTextFlags flags) { + return Native.InputText(label, text.data, text.data.length, flags.getValue(), text.inputData, text.inputData.maxChar, text.inputData.allowedChar, text.inputData.allowedChar.length()); + } + + public static boolean InputFloat(String label, ImGuiFloat v) { + return Native.InputFloat(label, v.data); + } + + public static boolean InputFloat(String label, ImGuiFloat v, float step, float step_fast, String format) { + return Native.InputFloat(label, v.data, step, step_fast, format); + } + + public static boolean InputFloat(String label, ImGuiFloat v, float step, float step_fast, String format, ImGuiInputTextFlags flags) { + return Native.InputFloat(label, v.data, step, step_fast, format, flags.getValue()); + } + + public static boolean InputInt(String label, ImGuiInt v) { + return Native.InputInt(label, v.data); + } + + public static boolean InputInt(String label, ImGuiInt v, float step, float step_fast) { + return Native.InputInt(label, v.data, step, step_fast); + } + + public static boolean InputInt(String label, ImGuiInt v, float step, float step_fast, ImGuiInputTextFlags flags) { + return Native.InputInt(label, v.data, step, step_fast, flags.getValue()); + } + + public static boolean InputDouble(String label, ImGuiDouble v) { + return Native.InputDouble(label, v.data); + } + + public static boolean InputDouble(String label, ImGuiDouble v, float step, float step_fast, String format) { + return Native.InputDouble(label, v.data, step, step_fast, format); + } + + public static boolean InputDouble(String label, ImGuiDouble v, float step, float step_fast, String format, ImGuiInputTextFlags flags) { + return Native.InputDouble(label, v.data, step, step_fast, format, flags.getValue()); + } + + // Widgets: Trees + // - TreeNode functions return true when the node is open, in which case you need to also call TreePop() when you are finished displaying the tree node contents. + + public static boolean TreeNode(String label) { + return Native.TreeNode(label); + } + + public static boolean TreeNode(String str_id, String label) { + return Native.TreeNode(str_id, label); + } + + public static boolean TreeNode(int ptr_id, String label) { + return Native.TreeNode(ptr_id, label); + } + + public static boolean TreeNodeEx(String label) { + return Native.TreeNodeEx(label); + } + + public static boolean TreeNodeEx(String label, ImGuiTreeNodeFlags flags) { + return Native.TreeNodeEx(label, flags.getValue()); + } + + public static boolean TreeNodeEx(String str_id, ImGuiTreeNodeFlags flags, String label) { + return Native.TreeNodeEx(str_id, flags.getValue(), label); + } + + public static boolean TreeNodeEx(int ptr_id, ImGuiTreeNodeFlags flags, String label) { + return Native.TreeNodeEx(ptr_id, flags.getValue(), label); + } + + public static void TreePush() { + Native.TreePush(); + } + + public static void TreePush(String str_id) { + Native.TreePush(str_id); + } + + public static void TreePush(int ptr_id) { + Native.TreePush(ptr_id); + } + + public static void TreePop() { + Native.TreePop(); + } + + public static void TreeAdvanceToLabelPos() { + Native.TreeAdvanceToLabelPos(); + } + + public static float GetTreeNodeToLabelSpacing() { + return Native.GetTreeNodeToLabelSpacing(); + } + + public static void SetNextTreeNodeOpen(boolean is_open) { + Native.SetNextTreeNodeOpen(is_open); + } + + public static void SetNextTreeNodeOpen(boolean is_open, ImGuiCond cond) { + Native.SetNextTreeNodeOpen(is_open, cond.getValue()); + } + + public static boolean CollapsingHeader(String label) { + return Native.CollapsingHeader(label); + } + + public static boolean CollapsingHeader(String label, ImGuiTreeNodeFlags flags) { + return Native.CollapsingHeader(label, flags.getValue()); + } + + public static boolean CollapsingHeader(String label, ImGuiBoolean p_open) { + return Native.CollapsingHeader(label, p_open.data); + } + + public static boolean CollapsingHeader(String label, ImGuiBoolean p_open, ImGuiTreeNodeFlags flags) { + return Native.CollapsingHeader(label, p_open.data, flags.getValue()); + } + + + // Widgets: Selectables + // - A selectable highlights when hovered, and can display another color when selected. + // - Neighbors selectable extend their highlight bounds in order to leave no gap between them. + + public static boolean Selectable(String label) { + return Native.Selectable(label); + } + + public static boolean Selectable(String label, boolean selected) { + return Native.Selectable(label, selected); + } + + public static boolean Selectable(String label, boolean selected, int flags, float sizeX, float sizeY) { + return Native.Selectable(label, selected, flags, sizeX, sizeY); + } + + public static boolean Selectable(String label, ImGuiBoolean selected) { + return Native.Selectable(label, selected.data); + } + + public static boolean Selectable(String label, ImGuiBoolean selected, int flags, float sizeX, float sizeY) { + return Native.Selectable(label, selected.data, flags, sizeX, sizeY); + } + + // Widgets: List Boxes + // - FIXME: To be consistent with all the newer API, ListBoxHeader/ListBoxFooter should in reality be called BeginListBox/EndListBox. Will rename them. + + public static void ListBox(String label, ImGuiInt current_item, String[] items, int items_count) { + Native.ListBox(label, current_item.data, items, items_count); + } + + public static void ListBoxHeader(String label) { + Native.ListBoxHeader(label); + } + + public static void ListBoxHeader(String label, float sizeX, float sizeY) { + Native.ListBoxHeader(label, sizeX, sizeY); + } + + public static void ListBoxHeader(String label, int items_count) { + Native.ListBoxHeader(label, items_count); + } + + public static void ListBoxHeader(String label, int items_count, int height_in_items) { + Native.ListBoxHeader(label, items_count, height_in_items); + } + + // Widgets: Menus + + public static boolean BeginMainMenuBar() { + return Native.BeginMainMenuBar(); + } + + public static void EndMainMenuBar() { + Native.EndMainMenuBar(); + } + + public static boolean BeginMenuBar() { + return Native.BeginMenuBar(); + } + + public static void EndMenuBar() { + Native.EndMenuBar(); + } + + public static boolean BeginMenu(String label) { + return Native.BeginMenu(label); + } + + public static boolean BeginMenu(String label, boolean enabled) { + return Native.BeginMenu(label, enabled); + } + + public static void EndMenu() { + Native.EndMenu(); + } + + public static boolean MenuItem(String label) { + return Native.MenuItem(label); + } + + public static boolean MenuItem(String label, String shortcut, boolean selected, boolean enabled) { + return Native.MenuItem(label, shortcut, selected, enabled); + } + + public static boolean MenuItem(String label, String shortcut, ImGuiBoolean p_selected) { + return Native.MenuItem(label, shortcut, p_selected.data); + } + + public static boolean MenuItem(String label, String shortcut, ImGuiBoolean p_selected, boolean enabled) { + return Native.MenuItem(label, shortcut, p_selected.data, enabled); + } + + // Tooltips + + public static void BeginTooltip() { + Native.BeginTooltip(); + } + + public static void EndTooltip() { + Native.EndTooltip(); + } + + public static void SetTooltip(String text) { + Native.SetTooltip(text); + } + + // Popups, Modals + // The properties of popups windows are: + // - They block normal mouse hovering detection outside them. (*) + // - Unless modal, they can be closed by clicking anywhere outside them, or by pressing ESCAPE. + // - Their visibility state (~bool) is held internally by imgui instead of being held by the programmer as we are used to with regular Begin() calls. + // User can manipulate the visibility state by calling OpenPopup(). + // (*) One can use IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup) to bypass it and detect hovering even when normally blocked by a popup. + // Those three properties are connected. The library needs to hold their visibility state because it can close popups at any time. + + public static void OpenPopup(String str_id) { + Native.OpenPopup(str_id); + } + + public static boolean BeginPopup(String str_id) { + return Native.BeginPopup(str_id); + } + + public static boolean BeginPopup(String str_id, ImGuiWindowFlags flags) { + return Native.BeginPopup(str_id, flags.getValue()); + } + + public static boolean BeginPopupContextItem() { + return Native.BeginPopupContextItem(); + } + + public static boolean BeginPopupContextItem(String str_id, int mouse_button) { + return Native.BeginPopupContextItem(str_id, mouse_button); + } + + public static boolean BeginPopupContextWindow() { + return Native.BeginPopupContextWindow(); + } + + public static boolean BeginPopupContextWindow(String str_id, int mouse_button, boolean also_over_items) { + return Native.BeginPopupContextWindow(str_id, mouse_button, also_over_items); + } + + public static boolean BeginPopupContextVoid() { + return Native.BeginPopupContextVoid(); + } + + public static boolean BeginPopupContextVoid(String str_id, int mouse_button) { + return Native.BeginPopupContextVoid(str_id, mouse_button); + } + + public static boolean BeginPopupModal(String name) { + return Native.BeginPopupModal(name); + } + + public static boolean BeginPopupModal(String name, ImGuiBoolean p_open, ImGuiWindowFlags flags) { + return Native.BeginPopupModal(name, p_open.data, flags.getValue()); + } + + public static void EndPopup() { + Native.EndPopup(); + } + + public static boolean OpenPopupOnItemClick() { + return Native.OpenPopupOnItemClick(); + } + + public static boolean OpenPopupOnItemClick(String str_id, int mouse_button) { + return Native.OpenPopupOnItemClick(str_id, mouse_button); + } + + public static boolean IsPopupOpen(String str_id) { + return Native.IsPopupOpen(str_id); + } + + public static void CloseCurrentPopup() { + Native.CloseCurrentPopup(); + } + + // Columns + // - You can also use SameLine(pos_x) to mimic simplified columns. + // - The columns API is work-in-progress and rather lacking (columns are arguably the worst part of dear imgui at the moment!) + + public static void Columns() { + Native.Columns(); + } + + public static void Columns(int count) { + Native.Columns(count); + } + + public static void Columns(int count, String id) { + Native.Columns(count, id); + } + + public static void Columns(int count, String id, boolean border) { + Native.Columns(count, id, border); + } + + public static void NextColumn() { + Native.NextColumn(); + } + + public static int GetColumnIndex() { + return Native.GetColumnIndex(); + } + + public static float GetColumnWidth() { + return Native.GetColumnWidth(); + } + + public static float GetColumnWidth(int column_index) { + return Native.GetColumnWidth(column_index); + } + + public static void SetColumnWidth(int column_index, float width) { + Native.SetColumnWidth(column_index, width); + } + + public static float GetColumnOffset() { + return Native.GetColumnOffset(); + } + + public static float GetColumnOffset(int column_index) { + return Native.GetColumnOffset(column_index); + } + + public static void SetColumnOffset(int column_index, float offset_x) { + Native.SetColumnOffset(column_index, offset_x); + } + + public static int GetColumnsCount() { + return Native.GetColumnsCount(); + } + + // Tab Bars, Tabs + // [BETA API] API may evolve! + + public static boolean BeginTabBar(String str_id) { + return Native.BeginTabBar(str_id); + } + + public static boolean BeginTabBar(String str_id, ImGuiTabBarFlags flags) { + return Native.BeginTabBar(str_id, flags.getValue()); + } + + public static void EndTabBar() { + Native.EndTabBar(); + } + + public static boolean BeginTabItem(String label) { + return Native.BeginTabItem(label); + } + + public static boolean BeginTabItem(String label, ImGuiBoolean p_open, ImGuiTabItemFlags flags) { + return Native.BeginTabItem(label, p_open.data, flags.getValue()); + } + + public static void EndTabItem() { + Native.EndTabItem(); + } + + public static void SetTabItemClosed(String tab_or_docked_window_label) { + Native.SetTabItemClosed(tab_or_docked_window_label); + } + + // Docking + // [BETA API] Enable with io.ConfigFlags |= ImGuiConfigFlags_DockingEnable. + // Note: you DO NOT need to call DockSpace() to use most Docking facilities! + // To dock windows: if io.ConfigDockingWithShift == false: drag window from their title bar. + // To dock windows: if io.ConfigDockingWithShift == true: hold SHIFT anywhere while moving windows. + // Use DockSpace() to create an explicit dock node _within_ an existing window. See Docking demo for details. + + // TODO: Available after docking comes from BETA +// public static void DockSpace(int id) { +// Native.DockSpace(id); +// } + + // TODO: Available after docking comes from BETA +// public static void DockSpace(int id, float sizeX, float sizeY) { +// Native.DockSpace(id, sizeX, sizeY); +// } + + // TODO: Available after docking comes from BETA +// public static void DockSpace(int id, float sizeX, float sizeY, ImGuiDockNodeFlags flags) { +// Native.DockSpace(id, sizeX, sizeY, flags.getValue()); +// } + + // Focus, Activation + // - Prefer using "SetItemDefaultFocus()" over "if (IsWindowAppearing()) SetScrollHereY()" when applicable to signify "this is the default item" + + public static void SetItemDefaultFocus() { + Native.SetItemDefaultFocus(); + } + + public static void SetKeyboardFocusHere() { + Native.SetKeyboardFocusHere(); + } + + public static void SetKeyboardFocusHere(int offset) { + Native.SetKeyboardFocusHere(offset); + } + + // Item/Widgets Utilities + // - Most of the functions are referring to the last/previous item we submitted. + // - See Demo Window under "Widgets->Querying Status" for an interactive visualization of most of those functions. + + public static boolean IsItemHovered() { + return Native.IsItemHovered(); + } + + public static boolean IsItemHovered(ImGuiHoveredFlags flags) { + return Native.IsItemHovered(flags.getValue()); + } + + public static boolean IsItemActive() { + return Native.IsItemActive(); + } + + public static boolean IsItemFocused() { + return Native.IsItemFocused(); + } + + public static boolean IsItemClicked() { + return Native.IsItemClicked(); + } + + public static boolean IsItemClicked(int mouse_button) { + return Native.IsItemClicked(mouse_button); + } + + public static boolean IsItemVisible() { + return Native.IsItemVisible(); + } + + public static boolean IsItemEdited() { + return Native.IsItemEdited(); + } + + public static boolean IsItemActivated() { + return Native.IsItemActivated(); + } + + public static boolean IsItemDeactivated() { + return Native.IsItemDeactivated(); + } + + public static boolean IsItemDeactivatedAfterEdit() { + return Native.IsItemDeactivatedAfterEdit(); + } + + public static boolean IsAnyItemHovered() { + return Native.IsAnyItemHovered(); + } + + public static boolean IsAnyItemActive() { + return Native.IsAnyItemActive(); + } + + public static boolean IsAnyItemFocused() { + return Native.IsAnyItemFocused(); + } + + public static ImVec2 GetItemRectMin() { + Native.GetItemRectMin(imVec2); + return imVec2; + } + + public static ImVec2 GetItemRectMax() { + Native.GetItemRectMax(imVec2); + return imVec2; + } + + public static ImVec2 GetItemRectSize() { + Native.GetItemRectSize(imVec2); + return imVec2; + } + + public static void SetItemAllowOverlap() { + Native.SetItemAllowOverlap(); + } + + // Miscellaneous Utilities + + public static boolean BeginChildFrame(int id, float width, float height) { + return Native.BeginChildFrame(id, width, height); + } + + public static boolean BeginChildFrame(int id, float width, float height, ImGuiWindowFlags flags) { + return Native.BeginChildFrame(id, width, height, flags.getValue()); + } + + public static void EndChildFrame() { + Native.EndChildFrame(); + } + + // Inputs Utilities + + public static boolean IsMouseDown(int button) { + return Native.IsMouseDown(button); + } + + public static boolean IsMouseClicked(int button) { + return Native.IsMouseClicked(button); + } + + public static boolean IsMouseClicked(int button, boolean repeat) { + return Native.IsMouseClicked(button, repeat); + } + + public static boolean IsMouseReleased(int button) { + return Native.IsMouseReleased(button); + } + + public static boolean IsMouseDragging() { + return Native.IsMouseDragging(); + } + + public static boolean IsMouseDragging(int button) { + return Native.IsMouseDragging(button); + } + + public static boolean IsMouseDragging(int button, float lock_threshold) { + return Native.IsMouseDragging(button, lock_threshold); + } + + public static boolean IsMouseHoveringRect(float minX, float minY, float maxX, float maxY) { + return Native.IsMouseHoveringRect(minX, minY, maxX, maxY); + } + + public static boolean IsMouseHoveringRect(float minX, float minY, float maxX, float maxY, boolean clip) { + return Native.IsMouseHoveringRect(minX, minY, maxX, maxY, clip); + } + + // Internal methods + + public static void PushMultiItemsWidths(int components, float w_full) { + NativeInternal.PushMultiItemsWidths(components, w_full); + } + + public static void ItemAdd(float x1, float y1, float x2, float y2, String id) { + NativeInternal.ItemAdd(x1, y1, x2, y2, id); + } + + public static void ItemSize(float x1, float y1, float x2, float y2, float text_offset_y) { + NativeInternal.ItemSize(x1, y1, x2, y2, text_offset_y); + } +} diff --git a/imgui-binding/src/main/java/imgui/ImGuiBoolean.java b/imgui-binding/src/main/java/imgui/ImGuiBoolean.java new file mode 100644 index 0000000..72d405a --- /dev/null +++ b/imgui-binding/src/main/java/imgui/ImGuiBoolean.java @@ -0,0 +1,27 @@ +package imgui; + +public class ImGuiBoolean { + public static ImGuiBoolean TMP = new ImGuiBoolean(); + + boolean[] data = new boolean[]{false}; + + public ImGuiBoolean() { + } + + public ImGuiBoolean(boolean value) { + setValue(value); + } + + public boolean getValue() { + return this.data[0]; + } + + public void setValue(boolean value) { + this.data[0] = value; + } + + @Override + public String toString() { + return String.valueOf(getValue()); + } +} diff --git a/imgui-binding/src/main/java/imgui/ImGuiDouble.java b/imgui-binding/src/main/java/imgui/ImGuiDouble.java new file mode 100644 index 0000000..ede7da2 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/ImGuiDouble.java @@ -0,0 +1,27 @@ +package imgui; + +public class ImGuiDouble { + public static ImGuiDouble TMP = new ImGuiDouble(); + + double[] data = new double[]{0.0d}; + + public ImGuiDouble() { + } + + public ImGuiDouble(double value) { + setValue(value); + } + + public double getValue() { + return this.data[0]; + } + + public void setValue(double value) { + this.data[0] = value; + } + + @Override + public String toString() { + return String.valueOf(getValue()); + } +} diff --git a/imgui-binding/src/main/java/imgui/ImGuiEx.java b/imgui-binding/src/main/java/imgui/ImGuiEx.java new file mode 100644 index 0000000..5d89842 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/ImGuiEx.java @@ -0,0 +1,103 @@ +package imgui; + +import imgui.NativeCustomWidget.ImGuiCollapseLayoutOptions; + +public class ImGuiEx { + + protected ImGuiEx() { + } + + public static void ShowLayoutDebug() { + NativeCustomWidget.ShowLayoutDebug(); + } + + public static void BeginLayout(String id, float sizeX, float sizeY) { + NativeCustomWidget.BeginLayout(id, sizeX, sizeY); + } + + public static void BeginLayout(String id, float sizeX, float sizeY, float paddingLeft, float paddingRight, float paddingTop, float paddingBottom) { + NativeCustomWidget.BeginLayout(id, sizeX, sizeY, paddingLeft, paddingRight, paddingTop, paddingBottom); + } + + public static void EndLayout() { + NativeCustomWidget.EndLayout(); + } + + public static boolean BeginCollapseLayoutEx(String title, float sizeX, float sizeY) { + return NativeCustomWidget.BeginCollapseLayoutEx2(title, sizeX, sizeY, NativeCustomWidget.defaultOptions); + } + + public static boolean BeginCollapseLayoutEx(String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) { + return NativeCustomWidget.BeginCollapseLayoutEx2(title, sizeX, sizeY, options); + } + + public static void BeginCollapseLayoutEx(ImGuiBoolean isOpen, String title, float sizeX, float sizeY) { + NativeCustomWidget.BeginCollapseLayoutEx(isOpen.data, title, sizeX, sizeY, NativeCustomWidget.defaultOptions); + } + + public static void BeginCollapseLayoutEx(ImGuiBoolean isOpen, String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) { + NativeCustomWidget.BeginCollapseLayoutEx(isOpen.data, title, sizeX, sizeY, options); + } + + public static boolean BeginCollapseLayout(String title, float sizeX, float sizeY) { + return NativeCustomWidget.BeginCollapseLayout2(title, sizeX, sizeY, NativeCustomWidget.defaultOptions); + } + + public static boolean BeginCollapseLayout(String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) { + return NativeCustomWidget.BeginCollapseLayout2(title, sizeX, sizeY, options); + } + + public static void BeginCollapseLayout(ImGuiBoolean isOpen, String title, float sizeX, float sizeY) { + NativeCustomWidget.BeginCollapseLayout(isOpen.data, title, sizeX, sizeY, NativeCustomWidget.defaultOptions); + } + + public static void BeginCollapseLayout(ImGuiBoolean isOpen, String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) { + NativeCustomWidget.BeginCollapseLayout(isOpen.data, title, sizeX, sizeY, options); + } + + public static void EndCollapseFrameLayout() { + NativeCustomWidget.EndCollapseFrameLayout(); + } + + public static void EndCollapseLayout() { + NativeCustomWidget.EndCollapseLayout(); + } + + public static void BeginAlign(String id, float sizeX, float sizeY, float alignX, float alignY) { + NativeCustomWidget.BeginAlign(id, sizeX, sizeY, alignX, alignY); + } + + public static void BeginAlign(String id, float sizeX, float sizeY, float alignX, float alignY, float offsetX, float offsetY) { + NativeCustomWidget.BeginAlign(id, sizeX, sizeY, alignX, alignY, offsetX, offsetY); + } + + public static void EndAlign() { + NativeCustomWidget.EndAlign(); + } + + public static void AlignLayout(float alignX, float alignY) { + NativeCustomWidget.AlignLayout(alignX, alignY); + } + + public static void AlignLayout(float alignX, float alignY, float offsetX, float offsetY) { + NativeCustomWidget.AlignLayout(alignX, alignY, offsetX, offsetY); + } + + + // Helper methods + + /** + * Packs the color components into a 32-bit integer with the format ABGR. Note that no range checking is performed for higher + * performance. + * + * @param r the red component, 0 - 255 + * @param g the green component, 0 - 255 + * @param b the blue component, 0 - 255 + * @param a the alpha component, 0 - 255 + * @return the packed color as a 32-bit int + */ + public static int colorToIntBits(int r, int g, int b, int a) { + return (a << 24) | (b << 16) | (g << 8) | r; + } + +} diff --git a/imgui-binding/src/main/java/imgui/ImGuiFloat.java b/imgui-binding/src/main/java/imgui/ImGuiFloat.java new file mode 100644 index 0000000..36a25a5 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/ImGuiFloat.java @@ -0,0 +1,27 @@ +package imgui; + +public class ImGuiFloat { + public static ImGuiFloat TMP = new ImGuiFloat(); + + float[] data = new float[]{0.0f}; + + public ImGuiFloat() { + } + + public ImGuiFloat(float value) { + setValue(value); + } + + public float getValue() { + return this.data[0]; + } + + public void setValue(float value) { + this.data[0] = value; + } + + @Override + public String toString() { + return String.valueOf(getValue()); + } +} diff --git a/imgui-binding/src/main/java/imgui/ImGuiIO.java b/imgui-binding/src/main/java/imgui/ImGuiIO.java new file mode 100644 index 0000000..c0de172 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/ImGuiIO.java @@ -0,0 +1,35 @@ +package imgui; + +import imgui.enums.ImGuiConfigFlags; + +public class ImGuiIO { + + //------------------------------------------------------------------ + // Output - Retrieve after calling NewFrame() + //------------------------------------------------------------------ + + public boolean WantCaptureMouse; // When io.WantCaptureMouse is true, imgui will use the mouse inputs, do not dispatch them to your main game/application (in both cases, always pass on mouse inputs to imgui). (e.g. unclicked mouse is hovering over an imgui window, widget is active, mouse was clicked over an imgui window, etc.). + public boolean WantCaptureKeyboard; // When io.WantCaptureKeyboard is true, imgui will use the keyboard inputs, do not dispatch them to your main game/application (in both cases, always pass keyboard inputs to imgui). (e.g. InputText active, or an imgui window is focused and navigation is enabled, etc.). + public boolean WantTextInput; // Mobile/console: when io.WantTextInput is true, you may display an on-screen keyboard. This is set by ImGui when it wants textual keyboard input to happen (e.g. when a InputText widget is active). + public boolean WantSetMousePos; // MousePos has been altered, back-end should reposition mouse on next frame. Set only when ImGuiConfigFlags_NavEnableSetMousePos flag is enabled. + public boolean WantSaveIniSettings; // When manual .ini load/save is active (io.IniFilename == NULL), this will be set to notify your application that you can call SaveIniSettingsToMemory() and save yourself. IMPORTANT: You need to clear io.WantSaveIniSettings yourself. + public boolean NavActive; // Directional navigation is currently allowed (will handle ImGuiKey_NavXXX events) = a window is focused and it doesn't use the ImGuiWindowFlags_NoNavInputs flag. + public boolean NavVisible; // Directional navigation is visible and allowed (will handle ImGuiKey_NavXXX events). + public float Framerate; // Application framerate estimation, in frame per second. Solely for convenience. Rolling average estimation based on IO.DeltaTime over 120 frames + public int MetricsRenderVertices; // Vertices output during last call to Render() + public int MetricsRenderIndices; // Indices output during last call to Render() = number of triangles * 3 + public int MetricsRenderWindows; // Number of visible windows + public int MetricsActiveWindows; // Number of active windows + public int MetricsActiveAllocations; // Number of active allocations, updated by MemAlloc/MemFree based on current context. May be off if you have multiple imgui contexts. + public float MouseDeltaX; // Mouse delta. Note that this is zero if either current or previous position are invalid (-FLT_MAX,-FLT_MAX), so a disappearing/reappearing mouse won't have a huge delta. + public float MouseDeltaY; + + public void SetConfigFlags(ImGuiConfigFlags flags) { + Native.SetConfigFlags(flags.getValue()); + } + + // TODO: Available after docking comes from BETA +// public void SetDockingFlags(boolean ConfigDockingNoSplit, boolean ConfigDockingWithShift, boolean ConfigDockingAlwaysTabBar, boolean ConfigDockingTransparentPayload) { +// Native.SetDockingFlags(ConfigDockingNoSplit, ConfigDockingWithShift, ConfigDockingAlwaysTabBar, ConfigDockingTransparentPayload); +// } +} diff --git a/imgui-binding/src/main/java/imgui/ImGuiInputTextData.java b/imgui-binding/src/main/java/imgui/ImGuiInputTextData.java new file mode 100644 index 0000000..97f7f21 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/ImGuiInputTextData.java @@ -0,0 +1,8 @@ +package imgui; + +public class ImGuiInputTextData { + public int size; + public int maxChar = -1; + public String allowedChar = ""; + boolean isDirty; +} diff --git a/imgui-binding/src/main/java/imgui/ImGuiInt.java b/imgui-binding/src/main/java/imgui/ImGuiInt.java new file mode 100644 index 0000000..40e1e0f --- /dev/null +++ b/imgui-binding/src/main/java/imgui/ImGuiInt.java @@ -0,0 +1,27 @@ +package imgui; + +public class ImGuiInt { + public static ImGuiInt TMP = new ImGuiInt(); + + int[] data = new int[]{0}; + + public ImGuiInt() { + } + + public ImGuiInt(int value) { + setValue(value); + } + + public int getValue() { + return this.data[0]; + } + + public void setValue(int value) { + this.data[0] = value; + } + + @Override + public String toString() { + return String.valueOf(getValue()); + } +} diff --git a/imgui-binding/src/main/java/imgui/ImGuiString.java b/imgui-binding/src/main/java/imgui/ImGuiString.java new file mode 100644 index 0000000..faff22e --- /dev/null +++ b/imgui-binding/src/main/java/imgui/ImGuiString.java @@ -0,0 +1,42 @@ +package imgui; + +public class ImGuiString { + public static ImGuiString TMP = new ImGuiString(); + final ImGuiInputTextData inputData = new ImGuiInputTextData(); + byte[] data; + private String text; + + public ImGuiString() { + this(100); + } + + public ImGuiString(int size) { + data = new byte[size]; + } + + public ImGuiString(String text) { + this(100); + setValue(text); + } + + public String getValue() { + if (inputData.isDirty) { + inputData.isDirty = false; + text = new String(data, 0, inputData.size); + } + return text; + } + + public void setValue(String value) { + inputData.size = value.length(); + text = value; + for (int i = 0; i < inputData.size; i++) { + data[i] = (byte) value.charAt(i); + } + } + + @Override + public String toString() { + return getValue(); + } +} diff --git a/imgui-binding/src/main/java/imgui/ImGuiStyle.java b/imgui-binding/src/main/java/imgui/ImGuiStyle.java new file mode 100644 index 0000000..f66466d --- /dev/null +++ b/imgui-binding/src/main/java/imgui/ImGuiStyle.java @@ -0,0 +1,7 @@ +package imgui; + +public class ImGuiStyle { + + public float ItemInnerSpacingX; + public float ItemInnerSpacingY; +} diff --git a/imgui-binding/src/main/java/imgui/ImVec2.java b/imgui-binding/src/main/java/imgui/ImVec2.java new file mode 100644 index 0000000..fb3b049 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/ImVec2.java @@ -0,0 +1,15 @@ +package imgui; + +public class ImVec2 { + public static ImVec2 TMP = new ImVec2(); + public float x; + public float y; + + public ImVec2() { + } + + public ImVec2(float x, float y) { + this.x = x; + this.y = y; + } +} diff --git a/imgui-binding/src/main/java/imgui/ImVec4.java b/imgui-binding/src/main/java/imgui/ImVec4.java new file mode 100644 index 0000000..ad156aa --- /dev/null +++ b/imgui-binding/src/main/java/imgui/ImVec4.java @@ -0,0 +1,8 @@ +package imgui; + +public class ImVec4 extends ImVec2 { + public static ImVec4 TMP = new ImVec4(); + + public float z; + public float w; +} diff --git a/imgui-binding/src/main/java/imgui/Native.java b/imgui-binding/src/main/java/imgui/Native.java new file mode 100644 index 0000000..7ea9aff --- /dev/null +++ b/imgui-binding/src/main/java/imgui/Native.java @@ -0,0 +1,2126 @@ +package imgui; + +import java.nio.Buffer; + +/** + * The bridge between Java and native APIs. + * Class itself used by "gdx-jnigen" util to generate JNI headers. + */ +class Native { + // @formatter:off + + /*JNI + #include + #include + + jfieldID totalVtxCountID; + jfieldID totalIdxCountID; + jfieldID totalCmdCountID; + jfieldID CmdListsCountID; + jfieldID displayPosXID; + jfieldID displayPosYID; + jfieldID displaySizeXID; + jfieldID displaySizeYID; + jfieldID framebufferScaleXID; + jfieldID framebufferScaleYID; + + // ImGuiIO + + jfieldID WantCaptureMouseID; + jfieldID WantCaptureKeyboardID; + jfieldID WantTextInputID; + jfieldID WantSetMousePosID; + jfieldID WantSaveIniSettingsID; + jfieldID NavActiveID; + jfieldID NavVisibleID; + jfieldID FramerateID; + jfieldID MetricsRenderVerticesID; + jfieldID MetricsRenderIndicesID; + jfieldID MetricsRenderWindowsID; + jfieldID MetricsActiveWindowsID; + jfieldID MetricsActiveAllocationsID; + jfieldID MouseDeltaXID; + jfieldID MouseDeltaYID; + + // ImGuiStyle + + jfieldID ItemInnerSpacingXID; + jfieldID ItemInnerSpacingYID; + + jfieldID imVec2XID; + jfieldID imVec2YID; + jfieldID imVec4ZID; + jfieldID imVec4WID; + + jfieldID imTextInputDataSizeID; + jfieldID imTextInputDataIsDirtyID; + + static int DRAWLIST_TYPE_DEFAULT = 0; + static int DRAWLIST_TYPE_BACKGROUND = 1; + static int DRAWLIST_TYPE_FOREGROUND = 2; + */ + + private Native() {} + + static native void init() /*-{ }-*/; /* + jclass jDrawDataClass = env->FindClass("imgui/DrawData"); + jclass jImGuiIOClass = env->FindClass("imgui/ImGuiIO"); + jclass jImGuiStyleClass = env->FindClass("imgui/ImGuiStyle"); + jclass jImVec2Class = env->FindClass("imgui/ImVec2"); + jclass jImVec4Class = env->FindClass("imgui/ImVec4"); + jclass jImInputTextDataClass = env->FindClass("imgui/ImGuiInputTextData"); + + // DrawData Prepare IDs + totalVtxCountID = env->GetFieldID(jDrawDataClass, "totalVtxCount", "I"); + totalIdxCountID = env->GetFieldID(jDrawDataClass, "totalIdxCount", "I"); + totalCmdCountID = env->GetFieldID(jDrawDataClass, "totalCmdCount", "I"); + CmdListsCountID = env->GetFieldID(jDrawDataClass, "cmdListsCount", "I"); + displayPosXID = env->GetFieldID(jDrawDataClass, "displayPosX", "F"); + displayPosYID = env->GetFieldID(jDrawDataClass, "displayPosY", "F"); + displaySizeXID = env->GetFieldID(jDrawDataClass, "displaySizeX", "F"); + displaySizeYID = env->GetFieldID(jDrawDataClass, "displaySizeY", "F"); + framebufferScaleXID = env->GetFieldID(jDrawDataClass, "framebufferScaleX", "F"); + framebufferScaleYID = env->GetFieldID(jDrawDataClass, "framebufferScaleY", "F"); + + // ImGuiIO Prepare IDs + + WantCaptureMouseID = env->GetFieldID(jImGuiIOClass, "WantCaptureMouse", "Z"); + WantCaptureKeyboardID = env->GetFieldID(jImGuiIOClass, "WantCaptureKeyboard", "Z"); + WantTextInputID = env->GetFieldID(jImGuiIOClass, "WantTextInput", "Z"); + WantSetMousePosID = env->GetFieldID(jImGuiIOClass, "WantSetMousePos", "Z"); + WantSaveIniSettingsID = env->GetFieldID(jImGuiIOClass, "WantSaveIniSettings", "Z"); + NavActiveID = env->GetFieldID(jImGuiIOClass, "NavActive", "Z"); + NavVisibleID = env->GetFieldID(jImGuiIOClass, "NavVisible", "Z"); + FramerateID = env->GetFieldID(jImGuiIOClass, "Framerate", "F"); + MetricsRenderVerticesID = env->GetFieldID(jImGuiIOClass, "MetricsRenderVertices", "I"); + MetricsRenderIndicesID = env->GetFieldID(jImGuiIOClass, "MetricsRenderIndices", "I"); + MetricsRenderWindowsID = env->GetFieldID(jImGuiIOClass, "MetricsRenderWindows", "I"); + MetricsActiveWindowsID = env->GetFieldID(jImGuiIOClass, "MetricsActiveWindows", "I"); + MetricsActiveAllocationsID = env->GetFieldID(jImGuiIOClass, "MetricsActiveAllocations", "I"); + MouseDeltaXID = env->GetFieldID(jImGuiIOClass, "MouseDeltaX", "F"); + MouseDeltaYID = env->GetFieldID(jImGuiIOClass, "MouseDeltaY", "F"); + + // ImGuiStyle Prepare IDs + + ItemInnerSpacingXID = env->GetFieldID(jImGuiStyleClass, "ItemInnerSpacingX", "F"); + ItemInnerSpacingYID = env->GetFieldID(jImGuiStyleClass, "ItemInnerSpacingY", "F"); + + //ImVec2 Prepare IDs + + imVec2XID = env->GetFieldID(jImVec2Class, "x", "F"); + imVec2YID = env->GetFieldID(jImVec2Class, "y", "F"); + + //ImVec4 Prepare IDs + + imVec4ZID = env->GetFieldID(jImVec4Class, "z", "F"); + imVec4WID = env->GetFieldID(jImVec4Class, "w", "F"); + + imTextInputDataSizeID = env->GetFieldID(jImInputTextDataClass, "size", "I"); + imTextInputDataIsDirtyID = env->GetFieldID(jImInputTextDataClass, "isDirty", "Z"); + */ + + static native void CreateContext() /*-{ }-*/; /* + ImGui::CreateContext(); + ImGui::GetIO().IniFilename = NULL; + ImGui::GetIO().BackendFlags |= ImGuiBackendFlags_HasMouseCursors; + */ + + static native void initKeyMap(int [] keys) /*-{ }-*/; /* + ImGuiIO& io = ImGui::GetIO(); + + for(int i = 0; i < ImGuiKey_COUNT; i++) { + io.KeyMap[i] = keys[i]; + } + */ + + static native void SetConfigFlags(int flag) /*-{ }-*/; /* + ImGuiIO& io = ImGui::GetIO(); + io.ConfigFlags = flag; + */ + + // TODO: Available after docking comes from BETA +// static native void SetDockingFlags(boolean ConfigDockingNoSplit, boolean ConfigDockingWithShift, boolean ConfigDockingAlwaysTabBar, boolean ConfigDockingTransparentPayload) /*-{ }-*/; /* +// ImGuiIO& io = ImGui::GetIO(); +// io.ConfigDockingNoSplit = ConfigDockingNoSplit; +// io.ConfigDockingWithShift = ConfigDockingWithShift; +// io.ConfigDockingAlwaysTabBar = ConfigDockingAlwaysTabBar; +// io.ConfigDockingTransparentPayload = ConfigDockingTransparentPayload; +// */ + + static native void UpdateDisplayAndInputAndFrame(ImGuiIO jImguiIO, ImGuiStyle jImguiStyle, float deltaTime, float w, float h, float display_w, float display_h, + float mouseX, float mouseY, boolean mouseDown0, boolean mouseDown1, boolean mouseDown2, boolean mouseDown3, boolean mouseDown4, boolean mouseDown5) /*-{ }-*/; /* + ImGuiIO& io = ImGui::GetIO(); + + io.DisplaySize = ImVec2(w, h); + if (w > 0 && h > 0) + io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h); + io.DeltaTime = deltaTime; + + bool m0 = mouseDown0; + bool m1 = mouseDown1; + bool m2 = mouseDown2; + bool m3 = mouseDown3; + bool m4 = mouseDown4; + bool m5 = mouseDown5; + + io.MouseDown[0] = m0; + io.MouseDown[1] = m1; + io.MouseDown[2] = m2; + io.MouseDown[3] = m3; + io.MouseDown[4] = m4; + io.MouseDown[5] = m5; + + if (io.WantSetMousePos) { + } + else { + io.MousePos = ImVec2(mouseX, mouseY); + } + + ImGui::NewFrame(); + + // Update ImGuiIO + env->SetBooleanField (jImguiIO, WantCaptureMouseID, io.WantCaptureMouse); + env->SetBooleanField (jImguiIO, WantCaptureKeyboardID, io.WantCaptureKeyboard); + env->SetBooleanField (jImguiIO, WantTextInputID, io.WantTextInput); + env->SetBooleanField (jImguiIO, WantSetMousePosID, io.WantSetMousePos); + env->SetBooleanField (jImguiIO, WantSaveIniSettingsID, io.WantSaveIniSettings); + env->SetBooleanField (jImguiIO, NavActiveID, io.NavActive); + env->SetBooleanField (jImguiIO, NavVisibleID, io.NavVisible); + env->SetBooleanField (jImguiIO, FramerateID, io.Framerate); + env->SetBooleanField (jImguiIO, MetricsRenderVerticesID, io.MetricsRenderVertices); + env->SetBooleanField (jImguiIO, MetricsRenderIndicesID, io.MetricsRenderIndices); + env->SetBooleanField (jImguiIO, MetricsRenderWindowsID, io.MetricsRenderWindows); + env->SetBooleanField (jImguiIO, MetricsActiveWindowsID, io.MetricsActiveWindows); + env->SetBooleanField (jImguiIO, MetricsActiveAllocationsID, io.MetricsActiveAllocations); + env->SetBooleanField (jImguiIO, MouseDeltaXID, io.MouseDelta.x); + + // Update ImGuiStyle + + ImGuiStyle & style = ImGui::GetStyle(); + + env->SetFloatField (jImguiStyle, ItemInnerSpacingXID, style.ItemInnerSpacing.x); + env->SetFloatField (jImguiStyle, ItemInnerSpacingYID, style.ItemInnerSpacing.y); + */ + + static native void updateKey(int key, boolean pressed, boolean released, boolean ctrlKey, boolean shiftKey, boolean altKey, boolean superKey) /*-{ }-*/; /* + ImGuiIO& io = ImGui::GetIO(); + if (pressed) + io.KeysDown[key] = true; + if (released) + io.KeysDown[key] = false; + io.KeyCtrl = ctrlKey; + io.KeyShift = shiftKey; + io.KeyAlt = altKey; + io.KeySuper = superKey; + */ + + static native void updateScroll(float amountX, float amountY) /*-{ }-*/; /* + ImGuiIO& io = ImGui::GetIO(); + io.MouseWheelH -= amountX; + io.MouseWheel -= amountY; + */ + + static native void updateKeyTyped(int c) /*-{ }-*/; /* + ImGuiIO& io = ImGui::GetIO(); + if (c > 0 && c < 0x10000) + io.AddInputCharacter((unsigned short)c); + */ + + static native void Render() /*-{ }-*/; /* + ImGui::Render(); + */ + + static native void ShowStyleEditor() /*-{ }-*/; /* + ImGui::ShowStyleEditor(); + */ + + static native void ShowDemoWindow() /*-{ }-*/; /* + ImGui::ShowDemoWindow(); + */ + + static native void ShowDemoWindow(boolean open) /*-{ }-*/; /* + bool toOpen = open; + ImGui::ShowDemoWindow(&toOpen); + */ + + static native void ShowMetricsWindow() /*-{ }-*/; /* + ImGui::ShowMetricsWindow(); + */ + + static native void ShowMetricsWindow(boolean open) /*-{ }-*/; /* + bool toOpen = open; + ImGui::ShowMetricsWindow(&toOpen); + */ + + static native void GetTexDataAsRGBA32(TexDataRGBA32 jTexData, Buffer pixelBuffer) /*-{ }-*/; /* + jclass jTexDataClass = env->GetObjectClass(jTexData); + if(jTexDataClass == NULL) + return; + + jfieldID widthID = env->GetFieldID(jTexDataClass, "width", "I"); + jfieldID heightID = env->GetFieldID(jTexDataClass, "height", "I"); + + unsigned char* pixels; + int width, height; + + ImGuiIO& io = ImGui::GetIO(); + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); + + env->SetIntField (jTexData, widthID, width); + env->SetIntField (jTexData, heightID, height); + + memcpy(pixelBuffer, pixels, width * height * 4); + */ + + static native void SetFontTexID(int id) /*-{ }-*/; /* + ImGuiIO& io = ImGui::GetIO(); + io.Fonts->TexID = (ImTextureID)id; + */ + + static native void GetDrawData(DrawData jDrawData, Buffer indexBuffer, Buffer vertexBuffer, Buffer cmdBuffer) /*-{ }-*/; /* + ImDrawData * drawData = ImGui::GetDrawData(); + + if(drawData != NULL) { + int cmdListsCount = drawData->CmdListsCount; + + // Set values + env->SetIntField (jDrawData, totalVtxCountID, drawData->TotalVtxCount); + env->SetIntField (jDrawData, totalIdxCountID, drawData->TotalIdxCount); + env->SetIntField (jDrawData, CmdListsCountID, cmdListsCount); + + env->SetFloatField (jDrawData, displayPosXID, drawData->DisplayPos.x); + env->SetFloatField (jDrawData, displayPosYID, drawData->DisplayPos.y); + + env->SetFloatField (jDrawData, displaySizeXID, drawData->DisplaySize.x); + env->SetFloatField (jDrawData, displaySizeYID, drawData->DisplaySize.y); + + env->SetFloatField (jDrawData, framebufferScaleXID, drawData->FramebufferScale.x); + env->SetFloatField (jDrawData, framebufferScaleYID, drawData->FramebufferScale.y); + + ImDrawList** drawLists = drawData->CmdLists; + + int verticeOffset = 0; + int indicesOffset = 0; + int cmdOffset = 0; + int cmdCount = 0; + + for(int i = 0; i < cmdListsCount; i++) { + ImDrawList & drawList = *drawLists[i]; + ImVector & imDrawCmdList = drawList.CmdBuffer; + ImVector & idxBuffer = drawList.IdxBuffer; + ImVector & vtxBuffer = drawList.VtxBuffer; + + int verticeSize = sizeof(ImDrawVert); + int indicesSize = sizeof(ImDrawIdx); + + float * vertexArraySource = (float *)vtxBuffer.Data; + short * indexArraySource = (short *)idxBuffer.Data; + float * vertexArrayDest = (float *)vertexBuffer; + short * indexArrayDest = (short *)indexBuffer; + + int colorSize = 1; + + int verticeItemSize = (4 + colorSize); + + vertexArrayDest[verticeOffset++] = vtxBuffer.Size; + // copy vertices to Destination buffer + for(int j = 0; j < vtxBuffer.Size; j++) { + ImDrawVert v = vtxBuffer[j]; + float posX = v.pos.x; + float posY = v.pos.y; + float uvX = v.uv.x; + float uvY = v.uv.y; + + int byteIndex = (j * verticeItemSize) + verticeOffset; + + float color = 0; + memcpy(&color, &v.col, 4); // move unsigned int color to float + + vertexArrayDest[byteIndex + 0] = posX; + vertexArrayDest[byteIndex + 1] = posY; + vertexArrayDest[byteIndex + 2] = uvX; + vertexArrayDest[byteIndex + 3] = uvY; + vertexArrayDest[byteIndex + 4] = color; + } + verticeOffset += vtxBuffer.Size * verticeItemSize; + + // copy index to destination buffer + indexArrayDest[indicesOffset++] = idxBuffer.Size; + for(int j = 0; j < idxBuffer.Size; j++) { + + indexArrayDest[j + indicesOffset] = idxBuffer[j]; + } + indicesOffset += idxBuffer.Size; + + float * cmdArrayDest = (float *)cmdBuffer; + + cmdArrayDest[cmdOffset++] = imDrawCmdList.Size; + int bytesOffset = 0; + int imDrawCmdSize = 1 + 4 + 1; + for (int cmd_i = 0; cmd_i < imDrawCmdList.Size; cmd_i++) { + const ImDrawCmd * pcmd = &imDrawCmdList[cmd_i]; + + float textureID = (float)(intptr_t)pcmd->TextureId; + float tempArray [6] = { + pcmd->ElemCount, + pcmd->ClipRect.x, + pcmd->ClipRect.y, + pcmd->ClipRect.z, + pcmd->ClipRect.w, + textureID + }; + + memcpy((cmdArrayDest + (cmd_i * imDrawCmdSize) + cmdOffset), tempArray, imDrawCmdSize * 4); + bytesOffset = bytesOffset + imDrawCmdSize; + } + cmdOffset += imDrawCmdList.Size * imDrawCmdSize; + cmdCount += imDrawCmdList.Size; + } + + env->SetIntField (jDrawData, totalCmdCountID, cmdCount); + } + */ + + static native void StyleColorsDark() /*-{ }-*/; /* + ImGui::StyleColorsDark(); + */ + + static native void StyleColorsClassic() /*-{ }-*/; /* + ImGui::StyleColorsClassic(); + */ + + static native void StyleColorsLight() /*-{ }-*/; /* + ImGui::StyleColorsLight(); + */ + + static native boolean Begin(String title) /*-{ }-*/; /* + return ImGui::Begin(title); + */ + + static native boolean Begin(String title, boolean [] p_open, int imGuiWindowFlags) /*-{ }-*/; /* + return ImGui::Begin(title, &p_open[0], imGuiWindowFlags); + */ + + static native void End() /*-{ }-*/; /* + ImGui::End(); + */ + + static native boolean BeginChild(String str_id) /*-{ }-*/; /* + return ImGui::BeginChild(str_id); + */ + + static native boolean BeginChild(String str_id, float width, float height) /*-{ }-*/; /* + return ImGui::BeginChild(str_id, ImVec2(width, height)); + */ + + static native boolean BeginChild(String str_id, float width, float height, boolean border) /*-{ }-*/; /* + return ImGui::BeginChild(str_id, ImVec2(width, height), border); + */ + + static native boolean BeginChild(String str_id, float width, float height, boolean border, int flags) /*-{ }-*/; /* + return ImGui::BeginChild(str_id, ImVec2(width, height), border, flags); + */ + + static native boolean BeginChild(int imGuiID) /*-{ }-*/; /* + return ImGui::BeginChild(imGuiID); + */ + + static native boolean BeginChild(int imGuiID, float width, float height, boolean border) /*-{ }-*/; /* + return ImGui::BeginChild(imGuiID, ImVec2(width, height), border); + */ + + static native boolean BeginChild(int imGuiID, float width, float height, boolean border, int flags) /*-{ }-*/; /* + return ImGui::BeginChild(imGuiID, ImVec2(width, height), border, flags); + */ + + static native void EndChild() /*-{ }-*/; /* + ImGui::EndChild(); + */ + + static native boolean IsWindowAppearing() /*-{ }-*/; /* + return ImGui::IsWindowAppearing(); + */ + + static native boolean IsWindowCollapsed() /*-{ }-*/; /* + return ImGui::IsWindowCollapsed(); + */ + + static native boolean IsWindowFocused() /*-{ }-*/; /* + return ImGui::IsWindowFocused(); + */ + + static native boolean IsWindowFocused(int flags) /*-{ }-*/; /* + return ImGui::IsWindowFocused(flags); + */ + + static native boolean IsWindowHovered() /*-{ }-*/; /* + return ImGui::IsWindowHovered(); + */ + + // DrawList + + /*JNI + ImDrawList * getDrawList(int type) { + ImDrawList* drawList = NULL; + if(type == DRAWLIST_TYPE_DEFAULT) + drawList = ImGui::GetWindowDrawList(); + else if(type == DRAWLIST_TYPE_BACKGROUND) + drawList = ImGui::GetBackgroundDrawList(); + else if(type == DRAWLIST_TYPE_FOREGROUND) + drawList = ImGui::GetForegroundDrawList(); + return drawList; + } + + */ + + static native boolean IsWindowHovered(int flags) /*-{ }-*/; /* + return ImGui::IsWindowHovered(flags); + */ + + static native boolean AddLine(int type, float a_x, float a_y, float b_x, float b_y, int col) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddLine(ImVec2(a_x, a_y), ImVec2(b_x, b_y), col); + */ + + static native boolean AddLine(int type, float a_x, float a_y, float b_x, float b_y, int col, float thinkness) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddLine(ImVec2(a_x, a_y), ImVec2(b_x, b_y), col, thinkness); + */ + + static native boolean AddRect(int type, float a_x, float a_y, float b_x, float b_y, int col) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddRect(ImVec2(a_x, a_y), ImVec2(b_x, b_y), col); + */ + + static native boolean AddRect(int type, float a_x, float a_y, float b_x, float b_y, int col, float rounding) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddRect(ImVec2(a_x, a_y), ImVec2(b_x, b_y), col, rounding); + */ + + static native boolean AddRect(int type, float a_x, float a_y, float b_x, float b_y, int col, float rounding, int rounding_corners_flags) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddRect(ImVec2(a_x, a_y), ImVec2(b_x, b_y), col, rounding, rounding_corners_flags); + */ + + static native boolean AddRect(int type, float a_x, float a_y, float b_x, float b_y, int col, float rounding, int rounding_corners_flags, float thickness) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddRect(ImVec2(a_x, a_y), ImVec2(b_x, b_y), col, rounding, rounding_corners_flags, thickness); + */ + + static native boolean AddRectFilled(int type, float a_x, float a_y, float b_x, float b_y, int col) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddRectFilled(ImVec2(a_x, a_y), ImVec2(b_x, b_y), col); + */ + + static native boolean AddRectFilled(int type, float a_x, float a_y, float b_x, float b_y, int col, float rounding) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddRectFilled(ImVec2(a_x, a_y), ImVec2(b_x, b_y), col, rounding); + */ + + static native boolean AddRectFilled(int type, float a_x, float a_y, float b_x, float b_y, int col, float rounding, int rounding_corners_flags) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddRectFilled(ImVec2(a_x, a_y), ImVec2(b_x, b_y), col, rounding, rounding_corners_flags); + */ + + static native boolean AddRectFilledMultiColor(int type, float a_x, float a_y, float b_x, float b_y, int col_upr_left, float col_upr_right, int col_bot_right, int col_bot_left) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddRectFilledMultiColor(ImVec2(a_x, a_y), ImVec2(b_x, b_y), col_upr_left, col_upr_right, col_bot_right, col_bot_left); + */ + + static native boolean AddQuad(int type, float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, float d_x, float d_y, int col) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddQuad(ImVec2(a_x, a_y), ImVec2(b_x, b_y), ImVec2(c_x, c_y), ImVec2(d_x, d_y), col); + */ + + static native boolean AddQuad(int type, float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, float d_x, float d_y, int col, float thickness) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddQuad(ImVec2(a_x, a_y), ImVec2(b_x, b_y), ImVec2(c_x, c_y), ImVec2(d_x, d_y), col, thickness); + */ + + static native boolean AddQuadFilled(int type, float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, float d_x, float d_y, int col) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddQuadFilled(ImVec2(a_x, a_y), ImVec2(b_x, b_y), ImVec2(c_x, c_y), ImVec2(d_x, d_y), col); + */ + + static native boolean AddTriangle(int type, float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, int col) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddTriangle(ImVec2(a_x, a_y), ImVec2(b_x, b_y), ImVec2(c_x, c_y), col); + */ + + static native boolean AddTriangle(int type, float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, int col, float thickness) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddTriangle(ImVec2(a_x, a_y), ImVec2(b_x, b_y), ImVec2(c_x, c_y), col, thickness); + */ + + static native boolean AddTriangleFilled(int type, float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, int col) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddTriangleFilled(ImVec2(a_x, a_y), ImVec2(b_x, b_y), ImVec2(c_x, c_y), col); + */ + + static native boolean AddCircle(int type, float centre_x, float centre_y, float radius, float col) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddCircle(ImVec2(centre_x, centre_y), radius, col); + */ + + static native boolean AddCircle(int type, float centre_x, float centre_y, float radius, float col, int num_segments, float thickness) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddCircle(ImVec2(centre_x, centre_y), radius, col, num_segments, thickness); + */ + + static native boolean AddCircleFilled(int type, float centre_x, float centre_y, float radius, float col) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddCircleFilled(ImVec2(centre_x, centre_y), radius, col); + */ + + static native boolean AddCircleFilled(int type, float centre_x, float centre_y, float radius, float col, int num_segments) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddCircleFilled(ImVec2(centre_x, centre_y), radius, col, num_segments); + */ + + static native boolean AddText(int type, float pos_x, float pos_y, int col, String text_begin) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddText(ImVec2(pos_x, pos_y), col, text_begin); + */ + + // TODO AddText + + static native boolean AddText(int type, float pos_x, float pos_y, int col, String text_begin, String text_end) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddText(ImVec2(pos_x, pos_y), col, text_begin, text_end); + */ + + static native boolean AddImage(int type, int textureID, float a_x, float a_y, float b_x, float b_y) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddImage((void *)textureID, ImVec2(a_x, a_y), ImVec2(b_x, b_y)); + */ + + //TODO AddImageQuad, AddImageRounded, AddPolyline, AddConvexPolyFilled + + static native boolean AddImage(int type, int textureID, float a_x, float a_y, float b_x, float b_y, float uv_a_x, float uv_a_y, float uv_b_x, float uv_b_y) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddImage((void *)textureID, ImVec2(a_x, a_y), ImVec2(b_x, b_y), ImVec2(uv_a_x, uv_a_y), ImVec2(uv_b_x, uv_b_y)); + */ + + static native boolean AddBezierCurve(int type, float pos0_x, float pos0_y, float cp0_x, float cp0_y, float cp1_x, float cp1_y, float pos1_x, float pos1_y, float col, float thickness) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddBezierCurve(ImVec2(pos0_x, pos0_y), ImVec2(cp0_x, cp0_y), ImVec2(cp1_x, cp1_y), ImVec2(pos1_x, pos1_y), col, thickness); + */ + + static native boolean AddBezierCurve(int type, float pos0_x, float pos0_y, float cp0_x, float cp0_y, float cp1_x, float cp1_y, float pos1_x, float pos1_y, float col, float thickness, int num_segments) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->AddBezierCurve(ImVec2(pos0_x, pos0_y), ImVec2(cp0_x, cp0_y), ImVec2(cp1_x, cp1_y), ImVec2(pos1_x, pos1_y), col, thickness, num_segments); + */ + + static native void ChannelsSplit(int type, int count) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->ChannelsSplit(count); + */ + + static native void ChannelsMerge(int type) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->ChannelsMerge(); + */ + + static native void ChannelsSetCurrent(int type, int n) /*-{ }-*/; /* + ImDrawList* drawList = getDrawList(type); + drawList->ChannelsSetCurrent(n); + */ + + static native void GetWindowPos(ImVec2 jImVec2) /*-{ }-*/; /* + ImVec2 vec = ImGui::GetWindowPos(); + env->SetFloatField (jImVec2, imVec2XID, vec.x); + env->SetFloatField (jImVec2, imVec2YID, vec.y); + */ + + static native float GetWindowPosX() /*-{ }-*/; /* + return ImGui::GetWindowPos().x; + */ + + static native float GetWindowPosY() /*-{ }-*/; /* + return ImGui::GetWindowPos().y; + */ + + static native void GetWindowSize(ImVec2 jImVec2) /*-{ }-*/; /* + ImVec2 vec = ImGui::GetWindowSize(); + env->SetFloatField (jImVec2, imVec2XID, vec.x); + env->SetFloatField (jImVec2, imVec2YID, vec.y); + */ + + static native float GetWindowWidth() /*-{ }-*/; /* + return ImGui::GetWindowWidth(); + */ + + // Prefer using SetNextXXX functions (before Begin) rather that SetXXX functions (after Begin). + + public static native float GetWindowHeight() /*-{ }-*/; /* + return ImGui::GetWindowHeight(); + */ + + static native void SetNextWindowPos(float x, float y) /*-{ }-*/; /* + ImGui::SetNextWindowPos(ImVec2(x, y)); + */ + + static native void SetNextWindowPos(float x, float y, int cond, float pivot_x, float pivot_y) /*-{ }-*/; /* + ImGui::SetNextWindowPos(ImVec2(x, y), cond, ImVec2(pivot_x, pivot_y)); + */ + + static native void SetNextWindowSize(float width, float height) /*-{ }-*/; /* + ImGui::SetNextWindowSize(ImVec2(width, height)); + */ + + static native void SetNextWindowSize(float width, float height, int cond) /*-{ }-*/; /* + ImGui::SetNextWindowSize(ImVec2(width, height), cond); + */ + + static native void SetNextWindowSizeConstraints(float min_width, float min_height, float max_width, float max_height) /*-{ }-*/; /* + ImGui::SetNextWindowSizeConstraints(ImVec2(min_width, min_height), ImVec2(max_width, max_height)); + */ + + static native void SetNextWindowContentSize(float width, float height) /*-{ }-*/; /* + ImGui::SetNextWindowContentSize(ImVec2(width, height)); + */ + + static native void SetNextWindowCollapsed(boolean collapsed) /*-{ }-*/; /* + ImGui::SetNextWindowCollapsed(collapsed); + */ + + static native void SetNextWindowCollapsed(boolean collapsed, int cond) /*-{ }-*/; /* + ImGui::SetNextWindowCollapsed(collapsed, cond); + */ + + static native void SetNextWindowFocus() /*-{ }-*/; /* + ImGui::SetNextWindowFocus(); + */ + + static native void SetNextWindowBgAlpha(float alpha) /*-{ }-*/; /* + ImGui::SetNextWindowBgAlpha(alpha); + */ + + static native void SetWindowPos(float x, float y) /*-{ }-*/; /* + ImGui::SetWindowPos(ImVec2(x, y)); + */ + + static native void SetWindowPos(float x, float y, int cond) /*-{ }-*/; /* + ImGui::SetWindowPos(ImVec2(x, y), cond); + */ + + static native void SetWindowSize(float width, float height) /*-{ }-*/; /* + ImGui::SetWindowSize(ImVec2(width, height)); + */ + + static native void SetWindowSize(float width, float height, int cond) /*-{ }-*/; /* + ImGui::SetWindowSize(ImVec2(width, height), cond); + */ + + static native void SetWindowCollapsed(boolean collapsed, int cond) /*-{ }-*/; /* + ImGui::SetWindowCollapsed(collapsed, cond); + */ + + static native void SetWindowFocus() /*-{ }-*/; /* + ImGui::SetWindowFocus(); + */ + + static native void SetWindowFocus(float scale) /*-{ }-*/; /* + ImGui::SetWindowFontScale(scale); + */ + + static native void SetWindowPos(String name, float x, float y) /*-{ }-*/; /* + ImGui::SetWindowPos(name, ImVec2(x, y)); + */ + + static native void SetWindowPos(String name, float x, float y, int cond) /*-{ }-*/; /* + ImGui::SetWindowPos(name, ImVec2(x, y), cond); + */ + + static native void SetWindowCollapsed(String name, boolean collapsed) /*-{ }-*/; /* + bool flag = collapsed; + ImGui::SetWindowCollapsed(name, flag); + */ + + static native void SetWindowCollapsed(String name, boolean collapsed, int cond) /*-{ }-*/; /* + ImGui::SetWindowCollapsed(name, collapsed, cond); + */ + + static native void SetWindowFocus(String name) /*-{ }-*/; /* + ImGui::SetWindowFocus(name); + */ + + // Content region + // - Those functions are bound to be redesigned soon (they are confusing, incomplete and return values in local window coordinates which increases confusion) + + static native void RemoveWindowFocus() /*-{ }-*/; /* + ImGui::SetWindowFocus(NULL); + */ + + static native void GetContentRegionMax(ImVec2 jImVec2) /*-{ }-*/; /* + ImVec2 vec = ImGui::GetContentRegionMax(); + env->SetFloatField (jImVec2, imVec2XID, vec.x); + env->SetFloatField (jImVec2, imVec2YID, vec.y); + */ + + static native void GetContentRegionAvail(ImVec2 jImVec2) /*-{ }-*/; /* + ImVec2 vec = ImGui::GetContentRegionAvail(); + env->SetFloatField (jImVec2, imVec2XID, vec.x); + env->SetFloatField (jImVec2, imVec2YID, vec.y); + */ + + static native float GetContentRegionAvailWidth() /*-{ }-*/; /* + return ImGui::GetContentRegionAvailWidth(); + */ + + static native void GetWindowContentRegionMin(ImVec2 jImVec2) /*-{ }-*/; /* + ImVec2 vec = ImGui::GetWindowContentRegionMin(); + env->SetFloatField (jImVec2, imVec2XID, vec.x); + env->SetFloatField (jImVec2, imVec2YID, vec.y); + */ + + static native void GetWindowContentRegionMax(ImVec2 jImVec2) /*-{ }-*/; /* + ImVec2 vec = ImGui::GetWindowContentRegionMax(); + env->SetFloatField (jImVec2, imVec2XID, vec.x); + env->SetFloatField (jImVec2, imVec2YID, vec.y); + */ + + // Windows Scrolling + + static native float GetWindowContentRegionWidth() /*-{ }-*/; /* + return ImGui::GetWindowContentRegionWidth(); + */ + + static native float GetScrollX() /*-{ }-*/; /* + return ImGui::GetScrollX(); + */ + + static native float GetScrollY() /*-{ }-*/; /* + return ImGui::GetScrollY(); + */ + + static native float GetScrollMaxX() /*-{ }-*/; /* + return ImGui::GetScrollMaxX(); + */ + + static native float GetScrollMaxY() /*-{ }-*/; /* + return ImGui::GetScrollMaxY(); + */ + + static native void SetScrollX(float scroll_x) /*-{ }-*/; /* + ImGui::SetScrollX(scroll_x); + */ + + static native void SetScrollY(float scroll_y) /*-{ }-*/; /* + ImGui::SetScrollY(scroll_y); + */ + + static native void SetScrollHereY() /*-{ }-*/; /* + ImGui::SetScrollHereY(); + */ + + static native void SetScrollHereY(float center_y_ratio) /*-{ }-*/; /* + ImGui::SetScrollHereY(center_y_ratio); + */ + + static native void SetScrollFromPosY(float local_y) /*-{ }-*/; /* + ImGui::SetScrollFromPosY(local_y); + */ + + // Parameters stacks (shared) + + static native void SetScrollFromPosY(float local_y, float center_y_ratio) /*-{ }-*/; /* + ImGui::SetScrollFromPosY(local_y, center_y_ratio); + */ + + //TODO impl + static native void PushFont(int index) /*-{ }-*/; /* + ImGuiIO& io = ImGui::GetIO(); + ImFontAtlas* atlas = io.Fonts; + ImFont* font = atlas->Fonts[index]; + ImGui::PushFont(font); + */ + + static native void PopFont() /*-{ }-*/; /* + ImGui::PopFont(); + */ + + static native void PushStyleColor(int idx, int col) /*-{ }-*/; /* + ImGui::PushStyleColor(idx, col); + */ + + static native void PushStyleColor(int idx, float r, float g, float b, float a) /*-{ }-*/; /* + ImGui::PushStyleColor(idx, ImVec4(r, g, b, a)); + */ + + static native void PopStyleColor() /*-{ }-*/; /* + ImGui::PopStyleColor(); + */ + + static native void PopStyleColor(int count) /*-{ }-*/; /* + ImGui::PopStyleColor(count); + */ + + static native void PushStyleVar(int idx, float val) /*-{ }-*/; /* + ImGui::PushStyleVar(idx, val); + */ + + static native void PushStyleVar(int idx, float val_x, float val_y) /*-{ }-*/; /* + ImGui::PushStyleVar(idx, ImVec2(val_x, val_y)); + */ + + static native void PopStyleVar() /*-{ }-*/; /* + ImGui::PopStyleVar(); + */ + + static native void PopStyleVar(int count) /*-{ }-*/; /* + ImGui::PopStyleVar(count); + */ + + static native void GetStyleColorVec4(int idx, float [] value) /*-{ }-*/; /* + ImVec4 val = ImGui::GetStyleColorVec4(idx); + value[0] = val.x; + value[1] = val.y; + value[2] = val.z; + value[3] = val.w; + */ + + //TODO impl + static native void GetFont() /*-{ }-*/; /* + ImFont * font = ImGui::GetFont(); + */ + + static native int GetFontSize() /*-{ }-*/; /* + return ImGui::GetFontSize(); + */ + + static native void GetFontTexUvWhitePixel(float [] value) /*-{ }-*/; /* + ImVec2 val = ImGui::GetFontTexUvWhitePixel(); + value[0] = val.x; + value[1] = val.y; + */ + + static native int GetColorU32(int idx) /*-{ }-*/; /* + return ImGui::GetColorU32((ImGuiCol)idx); + */ + + static native int GetColorU32(int idx, float alpha_mul) /*-{ }-*/; /* + return ImGui::GetColorU32(idx, alpha_mul); + */ + + // Parameters stacks (current window) + + static native int GetColorU32(float col_x, float col_y, float col_z, float col_w) /*-{ }-*/; /* + return ImGui::GetColorU32(ImVec4(col_x, col_y, col_z, col_w)); + */ + + static native void PushItemWidth(float item_width) /*-{ }-*/; /* + ImGui::PushItemWidth(item_width); + */ + + static native void PopItemWidth() /*-{ }-*/; /* + ImGui::PopItemWidth(); + */ + + static native void SetNextItemWidth(float item_width) /*-{ }-*/; /* + ImGui::SetNextItemWidth(item_width); + */ + + static native float CalcItemWidth() /*-{ }-*/; /* + return ImGui::CalcItemWidth(); + */ + + static native void PushTextWrapPos(float wrap_local_pos_x) /*-{ }-*/; /* + ImGui::PushTextWrapPos(wrap_local_pos_x); + */ + + static native void PushTextWrapPos() /*-{ }-*/; /* + ImGui::PushTextWrapPos(); + */ + + static native void PopTextWrapPos() /*-{ }-*/; /* + ImGui::PopTextWrapPos(); + */ + + static native void PushAllowKeyboardFocus(boolean allow_keyboard_focus) /*-{ }-*/; /* + ImGui::PushAllowKeyboardFocus(allow_keyboard_focus); + */ + + static native void PopAllowKeyboardFocus() /*-{ }-*/; /* + ImGui::PopAllowKeyboardFocus(); + */ + + static native void PushButtonRepeat(boolean repeat) /*-{ }-*/; /* + ImGui::PushButtonRepeat(repeat); + */ + + // Cursor / Layout + // - By "cursor" we mean the current output position. + // - The typical widget behavior is to output themselves at the current cursor position, then move the cursor one line down. + + static native void PopButtonRepeat() /*-{ }-*/; /* + ImGui::PopButtonRepeat(); + */ + + static native void Separator() /*-{ }-*/; /* + ImGui::Separator(); + */ + + static native void SameLine() /*-{ }-*/; /* + ImGui::SameLine(); + */ + + static native void SameLine(float offsetFromStartX) /*-{ }-*/; /* + ImGui::SameLine(offsetFromStartX); + */ + + static native void SameLine(float offsetFromStartX, float spacing) /*-{ }-*/; /* + ImGui::SameLine(offsetFromStartX, spacing); + */ + + static native void NewLine() /*-{ }-*/; /* + ImGui::NewLine(); + */ + + static native void Spacing() /*-{ }-*/; /* + ImGui::Spacing(); + */ + + static native void Dummy(float width, float height) /*-{ }-*/; /* + ImGui::Dummy(ImVec2(width, height)); + */ + + static native void Indent() /*-{ }-*/; /* + ImGui::Indent(); + */ + + static native void Indent(float indentW) /*-{ }-*/; /* + ImGui::Indent(indentW); + */ + + static native void Unindent() /*-{ }-*/; /* + ImGui::Unindent(); + */ + + static native void Unindent(float indentW) /*-{ }-*/; /* + ImGui::Unindent(indentW); + */ + + static native void BeginGroup() /*-{ }-*/; /* + ImGui::BeginGroup(); + */ + + static native void EndGroup() /*-{ }-*/; /* + ImGui::EndGroup(); + */ + + static native void GetCursorPos(float [] vec2) /*-{ }-*/; /* + ImVec2 vec = ImGui::GetCursorPos(); + vec2[0] = vec.x; + vec2[1] = vec.y; + */ + + static native float GetCursorPosX() /*-{ }-*/; /* + return ImGui::GetCursorPosX(); + */ + + static native float GetCursorPosY() /*-{ }-*/; /* + return ImGui::GetCursorPosY(); + */ + + static native void SetCursorPos(float x, float y) /*-{ }-*/; /* + ImGui::SetCursorPos(ImVec2(x, y)); + */ + + static native void SetCursorPosX(float x) /*-{ }-*/; /* + ImGui::SetCursorPosX(x); + */ + + static native void SetCursorPosY(float y) /*-{ }-*/; /* + ImGui::SetCursorPosY(y); + */ + + static native void GetCursorStartPos(ImVec2 jImVec2) /*-{ }-*/; /* + ImVec2 vec = ImGui::GetCursorStartPos(); + env->SetFloatField (jImVec2, imVec2XID, vec.x); + env->SetFloatField (jImVec2, imVec2YID, vec.y); + */ + + static native void GetCursorScreenPos(ImVec2 jImVec2) /*-{ }-*/; /* + ImVec2 vec = ImGui::GetCursorScreenPos(); + env->SetFloatField (jImVec2, imVec2XID, vec.x); + env->SetFloatField (jImVec2, imVec2YID, vec.y); + */ + + static native void SetCursorScreenPos(float x, float y) /*-{ }-*/; /* + ImGui::SetCursorScreenPos(ImVec2(x, y)); + */ + + static native void AlignTextToFramePadding() /*-{ }-*/; /* + ImGui::AlignTextToFramePadding(); + */ + + static native float GetTextLineHeight() /*-{ }-*/; /* + return ImGui::GetTextLineHeight(); + */ + + static native float GetTextLineHeightWithSpacing() /*-{ }-*/; /* + return ImGui::GetTextLineHeightWithSpacing(); + */ + + static native float GetFrameHeight() /*-{ }-*/; /* + return ImGui::GetFrameHeight(); + */ + + // ID stack/scopes + // - Read the FAQ for more details about how ID are handled in dear imgui. If you are creating widgets in a loop you most + // likely want to push a unique identifier (e.g. object pointer, loop index) to uniquely differentiate them. + // - The resulting ID are hashes of the entire stack. + // - You can also use the "Label##foobar" syntax within widget label to distinguish them from each others. + // - In this header file we use the "label"/"name" terminology to denote a string that will be displayed and used as an ID, + // whereas "str_id" denote a string that is only used as an ID and not normally displayed. + + static native float GetFrameHeightWithSpacing() /*-{ }-*/; /* + return ImGui::GetFrameHeightWithSpacing(); + */ + + static native void PushID(String str_id) /*-{ }-*/; /* + ImGui::PushID(str_id); + */ + + static native void PushID(String str_id_begin, String str_id_end) /*-{ }-*/; /* + ImGui::PushID(str_id_begin, str_id_end); + */ + + static native void PushID(int int_id) /*-{ }-*/; /* + ImGui::PushID(int_id); + */ + + static native void PopID() /*-{ }-*/; /* + ImGui::PopID(); + */ + + static native int GetID(String str_id) /*-{ }-*/; /* + return ImGui::GetID(str_id); + */ + + // Widgets: Text + + static native int GetID(String str_id_begin, String str_id_end) /*-{ }-*/; /* + return ImGui::GetID(str_id_begin, str_id_end); + */ + + static native void TextUnformatted(String text) /*-{ }-*/; /* + ImGui::TextUnformatted(text); + */ + + static native void TextUnformatted(String text, String text_end) /*-{ }-*/; /* + ImGui::TextUnformatted(text, text_end); + */ + + static native void Text(String text) /*-{ }-*/; /* + ImGui::Text(text); + */ + + static native void TextColored(float r, float g, float b, float a, String text) /*-{ }-*/; /* + ImGui::TextColored(ImVec4(r, g, b, a), text); + */ + + static native void TextDisabled(String text) /*-{ }-*/; /* + ImGui::TextDisabled(text); + */ + + static native void TextWrapped(String text) /*-{ }-*/; /* + ImGui::TextWrapped(text); + */ + + static native void LabelText(String label, String text) /*-{ }-*/; /* + ImGui::LabelText(label, text); + */ + + // Widgets: Main + // - Most widgets return true when the value has been changed or when pressed/selected + + static native void BulletText(String text) /*-{ }-*/; /* + ImGui::BulletText(text); + */ + + static native boolean Button(String label) /*-{ }-*/; /* + return ImGui::Button(label); + */ + + static native boolean Button(String label, float width, float height) /*-{ }-*/; /* + return ImGui::Button(label, ImVec2(width, height)); + */ + + static native boolean SmallButton(String label) /*-{ }-*/; /* + return ImGui::SmallButton(label); + */ + + static native boolean InvisibleButton(String strId, float width, float height) /*-{ }-*/; /* + return ImGui::InvisibleButton(strId, ImVec2(width, height)); + */ + + static native boolean ArrowButton(String strId, int dir) /*-{ }-*/; /* + return ImGui::ArrowButton(strId, dir); + */ + + static native void Image(int textureID, float sizeX, float sizeY) /*-{ }-*/; /* + ImGui::Image((ImTextureID)textureID, ImVec2(sizeX, sizeY)); + */ + + static native void Image(int textureID, float sizeX, float sizeY, float uv0_x, float uv0_y, float uv1_x, float uv1_y) /*-{ }-*/; /* + ImGui::Image((ImTextureID)textureID, ImVec2(sizeX, sizeY), ImVec2(uv0_x, uv0_y), ImVec2(uv1_x, uv1_y)); + */ + + static native void Image(int textureID, float sizeX, float sizeY, float uv0_x, float uv0_y, float uv1_x, float uv1_y, float tint_color_r, float tint_color_g, float tint_color_b, float tint_color_a, float border_col_r, float border_col_g, float border_col_b, float border_col_a) /*-{ }-*/; /* + ImGui::Image((ImTextureID)textureID, ImVec2(sizeX, sizeY), ImVec2(uv0_x, uv0_y), ImVec2(uv1_x, uv1_y), ImVec4(tint_color_r, tint_color_g, tint_color_b, tint_color_a), ImVec4(border_col_r, border_col_g, border_col_b, border_col_a)); + */ + + static native boolean ImageButton(int textureID, float sizeX, float sizeY) /*-{ }-*/; /* + return ImGui::ImageButton((ImTextureID)textureID, ImVec2(sizeX, sizeY)); + */ + + static native boolean ImageButton(int textureID, float sizeX, float sizeY, float uv0_x, float uv0_y, float uv1_x, float uv1_y, int frame_padding) /*-{ }-*/; /* + return ImGui::ImageButton((ImTextureID)textureID, ImVec2(sizeX, sizeY), ImVec2(uv0_x, uv0_y), ImVec2(uv1_x, uv1_y), frame_padding); + */ + + static native boolean ImageButton(int textureID, float sizeX, float sizeY, float uv0_x, float uv0_y, float uv1_x, float uv1_y, int frame_padding, float bg_color_r, float bg_color_g, float bg_color_b, float bg_color_a, float tint_col_r, float tint_col_g, float tint_col_b, float tint_col_a) /*-{ }-*/; /* + return ImGui::ImageButton((ImTextureID)textureID, ImVec2(sizeX, sizeY), ImVec2(uv0_x, uv0_y), ImVec2(uv1_x, uv1_y), frame_padding, ImVec4(bg_color_r, bg_color_g, bg_color_b, bg_color_a), ImVec4(tint_col_r, tint_col_g, tint_col_b, tint_col_a)); + */ + + static native boolean Checkbox(String label, boolean [] data) /*-{ }-*/; /* + return ImGui::Checkbox(label, &data[0]); + */ + + //TODO check if its working + static native boolean CheckboxFlags(String label, int [] data, int flagsValue) /*-{ }-*/; /* + return ImGui::CheckboxFlags(label, (unsigned int*)&data[0], flagsValue); + */ + + static native boolean RadioButton(String label, boolean active) /*-{ }-*/; /* + return ImGui::RadioButton(label, active); + */ + + static native boolean RadioButton(String label, int [] data, int v_button) /*-{ }-*/; /* + return ImGui::RadioButton(label, &data[0], v_button); + */ + + static native void ProgressBar(float fraction) /*-{ }-*/; /* + ImGui::ProgressBar(fraction); + */ + + static native void ProgressBar(float fraction, float size_arg_x, float size_arg_y) /*-{ }-*/; /* + ImGui::ProgressBar(fraction, ImVec2(size_arg_x, size_arg_y)); + */ + + // Widgets: Combo Box + // - The new BeginCombo()/EndCombo() api allows you to manage your contents and selection state however you want it, by creating e.g. Selectable() items. + // - The old Combo() api are helpers over BeginCombo()/EndCombo() which are kept available for convenience purpose. + + static native void Bullet() /*-{ }-*/; /* + ImGui::Bullet(); + */ + + static native boolean BeginCombo(String label, String preview_value) /*-{ }-*/; /* + return ImGui::BeginCombo(label, preview_value); + */ + + static native boolean BeginCombo(String label, String preview_value, int flags) /*-{ }-*/; /* + return ImGui::BeginCombo(label, preview_value, flags); + */ + + static native void EndCombo() /*-{ }-*/; /* + ImGui::EndCombo(); + */ + + static native boolean Combo(String label, int [] current_item, String [] items, int items_count) /*-{ }-*/; /* + const char* listbox_items[items_count]; + for(int i = 0; i < items_count; i++) { + jstring string = (jstring) (env->GetObjectArrayElement(items, i)); + const char *rawString = env->GetStringUTFChars(string, 0); + listbox_items[i] = rawString; + } + return ImGui::Combo(label, ¤t_item[0], listbox_items, items_count); + */ + + static native boolean Combo(String label, int [] current_item, String [] items, int items_count, int popup_max_height_in_items) /*-{ }-*/; /* + const char* listbox_items[items_count]; + for(int i = 0; i < items_count; i++) { + jstring string = (jstring) (env->GetObjectArrayElement(items, i)); + const char *rawString = env->GetStringUTFChars(string, 0); + listbox_items[i] = rawString; + } + return ImGui::Combo(label, ¤t_item[0], listbox_items, items_count, popup_max_height_in_items); + */ + + static native boolean Combo(String label, int [] current_item, String items_separated_by_zeros) /*-{ }-*/; /* + return ImGui::Combo(label, ¤t_item[0], items_separated_by_zeros); + */ + + // Widgets: Drags + // - CTRL+Click on any drag box to turn them into an input box. Manually input values aren't clamped and can go off-bounds. + // - For all the Float2/Float3/Float4/Int2/Int3/Int4 versions of every functions, note that a 'float v[X]' function argument is the same as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible. You can pass address of your first element out of a contiguous set, e.g. &myvector.x + // - Adjust format string to decorate the value with a prefix, a suffix, or adapt the editing and display precision e.g. "%.3f" -> 1.234; "%5.2f secs" -> 01.23 secs; "Biscuit: %.0f" -> Biscuit: 1; etc. + // - Speed are per-pixel of mouse movement (v_speed=0.2f: mouse needs to move by 5 pixels to increase value by 1). For gamepad/keyboard navigation, minimum speed is Max(v_speed, minimum_step_at_given_precision). + + static native boolean Combo(String label, int [] current_item, String items_separated_by_zeros, int popup_max_height_in_items) /*-{ }-*/; /* + return ImGui::Combo(label, ¤t_item[0], items_separated_by_zeros, popup_max_height_in_items); + */ + + static native boolean DragFloat(String label, float [] v) /*-{ }-*/; /* + return ImGui::DragFloat(label, &v[0]); + */ + + static native boolean DragFloat(String label, float [] v, float v_speed) /*-{ }-*/; /* + return ImGui::DragFloat(label, &v[0], v_speed); + */ + + static native boolean DragFloat(String label, float [] v, float v_speed, float v_min, float v_max, String format) /*-{ }-*/; /* + return ImGui::DragFloat(label, &v[0], v_speed, v_min, v_max, format); + */ + + static native boolean DragFloat(String label, float [] v, float v_speed, float v_min, float v_max, String format, float power) /*-{ }-*/; /* + return ImGui::DragFloat(label, &v[0], v_speed, v_min, v_max, format, power); + */ + + static native boolean DragFloat2(String label, float [] v) /*-{ }-*/; /* + return ImGui::DragFloat2(label, v); + */ + + static native boolean DragFloat2(String label, float [] v, float v_speed, float v_min, float v_max, String format, float power) /*-{ }-*/; /* + return ImGui::DragFloat2(label, v, v_speed, v_min, v_max, format, power); + */ + + static native boolean DragFloat3(String label, float [] v) /*-{ }-*/; /* + return ImGui::DragFloat3(label, v); + */ + + static native boolean DragFloat3(String label, float [] v, float v_speed, float v_min, float v_max, String format, float power) /*-{ }-*/; /* + return ImGui::DragFloat3(label, v, v_speed, v_min, v_max, format, power); + */ + + static native boolean DragFloat4(String label, float [] v) /*-{ }-*/; /* + return ImGui::DragFloat4(label, v); + */ + + static native boolean DragFloat4(String label, float [] v, float v_speed, float v_min, float v_max, String format, float power) /*-{ }-*/; /* + return ImGui::DragFloat4(label, v, v_speed, v_min, v_max, format, power); + */ + + static native boolean DragFloatRange2(String label, float [] v_current_min, float [] v_current_max) /*-{ }-*/; /* + return ImGui::DragFloatRange2(label, &v_current_min[0], &v_current_max[0]); + */ + + static native boolean DragFloatRange2(String label, float [] v_current_min, float [] v_current_max, float v_speed, float v_min, float v_max, String format, String format_max, float power) /*-{ }-*/; /* + return ImGui::DragFloatRange2(label, &v_current_min[0], &v_current_max[0], v_speed, v_min, v_max, format, format_max, power); + */ + + static native boolean DragInt(String label, int [] v) /*-{ }-*/; /* + return ImGui::DragInt(label, &v[0]); + */ + + static native boolean DragInt(String label, int [] v, float v_speed) /*-{ }-*/; /* + return ImGui::DragInt(label, &v[0], v_speed); + */ + + static native boolean DragInt(String label, int [] v, float v_speed, float v_min, float v_max, String format) /*-{ }-*/; /* + return ImGui::DragInt(label, &v[0], v_speed, v_min, v_max, format); + */ + + static native boolean DragInt2(String label, int [] v) /*-{ }-*/; /* + return ImGui::DragInt2(label, v); + */ + + static native boolean DragInt2(String label, int [] v, float v_speed, float v_min, float v_max, String format) /*-{ }-*/; /* + return ImGui::DragInt2(label, v, v_speed, v_min, v_max, format); + */ + + static native boolean DragInt3(String label, int [] v) /*-{ }-*/; /* + return ImGui::DragInt2(label, v); + */ + + static native boolean DragInt3(String label, int [] v, float v_speed, float v_min, float v_max, String format) /*-{ }-*/; /* + return ImGui::DragInt2(label, v, v_speed, v_min, v_max, format); + */ + + static native boolean DragInt4(String label, int [] v) /*-{ }-*/; /* + return ImGui::DragInt4(label, v); + */ + + static native boolean DragInt4(String label, int [] v, float v_speed, float v_min, float v_max, String format) /*-{ }-*/; /* + return ImGui::DragInt4(label, v, v_speed, v_min, v_max, format); + */ + + static native boolean DragIntRange2(String label, int [] v_current_min, int [] v_current_max) /*-{ }-*/; /* + return ImGui::DragIntRange2(label, &v_current_min[0], &v_current_max[0]); + */ + + static native boolean DragIntRange2(String label, int [] v_current_min, int [] v_current_max, float v_speed, float v_min, float v_max, String format, String format_max) /*-{ }-*/; /* + return ImGui::DragIntRange2(label, &v_current_min[0], &v_current_max[0], v_speed, v_min, v_max, format, format_max); + */ + + //TODO impl other types + static native boolean DragScalar(String label, int data_type, int[] v, float v_speed) /*-{ }-*/; /* + return ImGui::DragScalar(label, data_type, &v[0], v_speed); + */ + + // Widgets: Sliders + // - CTRL+Click on any slider to turn them into an input box. Manually input values aren't clamped and can go off-bounds. + // - Adjust format string to decorate the value with a prefix, a suffix, or adapt the editing and display precision e.g. "%.3f" -> 1.234; "%5.2f secs" -> 01.23 secs; "Biscuit: %.0f" -> Biscuit: 1; etc. + + //TODO impl other types + static native boolean DragScalar(String label, int data_type, int[] v, float v_speed, float v_min, float v_max, String format, float power) /*-{ }-*/; /* + return ImGui::DragScalar(label, data_type, &v[0], v_speed, &v_min, &v_max, format, power); + */ + + static native boolean SliderFloat(String label, float [] v, float v_min, float v_max) /*-{ }-*/; /* + return ImGui::SliderFloat(label, &v[0],v_min, v_max); + */ + + static native boolean SliderFloat(String label, float [] v, float v_min, float v_max, String format) /*-{ }-*/; /* + return ImGui::SliderFloat(label, &v[0], v_min, v_max, format); + */ + + static native boolean SliderFloat(String label, float [] v, float v_min, float v_max, String format, float power) /*-{ }-*/; /* + return ImGui::SliderFloat(label, &v[0], v_min, v_max, format, power); + */ + + static native boolean SliderFloat2(String label, float [] v, float v_min, float v_max) /*-{ }-*/; /* + return ImGui::SliderFloat2(label, v, v_min, v_max); + */ + + static native boolean SliderFloat2(String label, float [] v, float v_min, float v_max, String format, float power) /*-{ }-*/; /* + return ImGui::SliderFloat2(label, v, v_min, v_max, format, power); + */ + + static native boolean SliderFloat3(String label, float [] v, float v_min, float v_max) /*-{ }-*/; /* + return ImGui::SliderFloat3(label, v, v_min, v_max); + */ + + static native boolean SliderFloat3(String label, float [] v, float v_min, float v_max, String format, float power) /*-{ }-*/; /* + return ImGui::SliderFloat3(label, v, v_min, v_max, format, power); + */ + + static native boolean SliderFloat4(String label, float [] v, float v_min, float v_max) /*-{ }-*/; /* + return ImGui::SliderFloat4(label, v, v_min, v_max); + */ + + static native boolean SliderFloat4(String label, float [] v, float v_min, float v_max, String format, float power) /*-{ }-*/; /* + return ImGui::SliderFloat4(label, v, v_min, v_max, format, power); + */ + + static native boolean SliderAngle(String label, float [] v_rad) /*-{ }-*/; /* + return ImGui::SliderAngle(label, &v_rad[0]); + */ + + static native boolean SliderAngle(String label, float [] v_rad, float v_degrees_min, float v_degrees_max, String format) /*-{ }-*/; /* + return ImGui::SliderAngle(label, &v_rad[0], v_degrees_min, v_degrees_max, format); + */ + + static native boolean SliderInt(String label, int [] v, int v_min, int v_max) /*-{ }-*/; /* + return ImGui::SliderInt(label, &v[0], v_min, v_max); + */ + + static native boolean SliderInt(String label, int [] v, int v_min, int v_max, String format) /*-{ }-*/; /* + return ImGui::SliderInt(label, &v[0], v_min, v_max, format); + */ + + static native boolean SliderInt2(String label, int [] v, int v_min, int v_max) /*-{ }-*/; /* + return ImGui::SliderInt2(label, v, v_min, v_max); + */ + + static native boolean SliderInt2(String label, int [] v, int v_min, int v_max, String format) /*-{ }-*/; /* + return ImGui::SliderInt2(label, v, v_min, v_max, format); + */ + + static native boolean SliderInt3(String label, int [] v, int v_min, int v_max) /*-{ }-*/; /* + return ImGui::SliderInt3(label, v, v_min, v_max); + */ + + static native boolean SliderInt3(String label, int [] v, int v_min, int v_max, String format) /*-{ }-*/; /* + return ImGui::SliderInt3(label, v, v_min, v_max, format); + */ + + static native boolean SliderInt4(String label, int [] v, int v_min, int v_max) /*-{ }-*/; /* + return ImGui::SliderInt4(label, v, v_min, v_max); + */ + + static native boolean SliderInt4(String label, int [] v, int v_min, int v_max, String format) /*-{ }-*/; /* + return ImGui::SliderInt4(label, v, v_min, v_max, format); + */ + + //TODO impl other types + static native boolean SliderScalar(String label, int data_type, int[] v, int v_min, int v_max) /*-{ }-*/; /* + return ImGui::SliderScalar(label, data_type, &v[0], &v_min, &v_max); + */ + + static native boolean SliderScalar(String label, int data_type, int[] v, float v_min, float v_max, String format, float power) /*-{ }-*/; /* + return ImGui::SliderScalar(label, data_type, &v[0], &v_min, &v_max, format, power); + */ + + static native boolean SliderScalar(String label, int data_type, float[] v, float v_min, float v_max) /*-{ }-*/; /* + return ImGui::SliderScalar(label, data_type, &v[0], &v_min, &v_max); + */ + + static native boolean SliderScalar(String label, int data_type, float[] v, float v_min, float v_max, String format, float power) /*-{ }-*/; /* + return ImGui::SliderScalar(label, data_type, &v[0], &v_min, &v_max, format, power); + */ + + static native boolean VSliderFloat(String label, float sizeX, float sizeY, float [] v, float v_min, float v_max) /*-{ }-*/; /* + return ImGui::VSliderFloat(label, ImVec2(sizeX, sizeY), &v[0], v_min, v_max); + */ + + static native boolean VSliderFloat(String label, float sizeX, float sizeY, float [] v, float v_min, float v_max, String format, float power) /*-{ }-*/; /* + return ImGui::VSliderFloat(label, ImVec2(sizeX, sizeY), &v[0], v_min, v_max, format, power); + */ + + static native boolean VSliderInt(String label, float sizeX, float sizeY, int [] v, int v_min, int v_max) /*-{ }-*/; /* + return ImGui::VSliderInt(label, ImVec2(sizeX, sizeY), &v[0], v_min, v_max); + */ + + static native boolean VSliderInt(String label, float sizeX, float sizeY, int [] v, int v_min, int v_max, String format) /*-{ }-*/; /* + return ImGui::VSliderInt(label, ImVec2(sizeX, sizeY), &v[0], v_min, v_max, format); + */ + + //TODO impl other types + static native boolean VSliderScalar(String label, float sizeX, float sizeY, int data_type, int [] v, int v_min, int v_max) /*-{ }-*/; /* + return ImGui::VSliderScalar(label, ImVec2(sizeX, sizeY), data_type, &v[0], &v_min, &v_max); + */ + + static native boolean VSliderScalar(String label, float sizeX, float sizeY, int data_type, int [] v, int v_min, int v_max, String format, float power) /*-{ }-*/; /* + return ImGui::VSliderScalar(label, ImVec2(sizeX, sizeY), data_type, &v[0], &v_min, &v_max, format, power); + */ + + static native boolean VSliderScalar(String label, float sizeX, float sizeY, int data_type, float [] v, float v_min, float v_max) /*-{ }-*/; /* + return ImGui::VSliderScalar(label, ImVec2(sizeX, sizeY), data_type, &v[0], &v_min, &v_max); + */ + + // Widgets: Input with Keyboard + // - If you want to use InputText() with a dynamic string type such as std::string or your own, see misc/cpp/imgui_stdlib.h + // - Most of the ImGuiInputTextFlags flags are only useful for InputText() and not for InputFloatX, InputIntX, InputDouble etc. + + /*JNI + + struct InputTextCallback_UserData { + jobject* textInputData; + JNIEnv* env; + int maxChar; + char * allowedChar; + int allowedCharLength; + int maxSize; + int curSize; + }; + + static int TextEditCallbackStub(ImGuiInputTextCallbackData* data) { + InputTextCallback_UserData* userData = (InputTextCallback_UserData*)data->UserData; + + if (data->EventFlag == ImGuiInputTextFlags_CallbackCharFilter) { + if(userData->allowedCharLength > 0) { + bool found = false; + for(int i = 0; i < userData->allowedCharLength; i++) { + if(userData->allowedChar[i] == data->EventChar) { + found = true; + break; + } + } + return found ? 0 : 1; + } + } + return 0; + } + */ + + static native boolean VSliderScalar(String label, float sizeX, float sizeY, int data_type, float [] v, float v_min, float v_max, String format, float power) /*-{ }-*/; /* + return ImGui::VSliderScalar(label, ImVec2(sizeX, sizeY), data_type, &v[0], &v_min, &v_max, format, power); + */ + + static native boolean InputText(String label, byte [] buff, int maxSize, int flags, ImGuiInputTextData textInputData, int maxChar, String allowedChar, int allowedCharLength) /*-{ }-*/; /* + + int size = (int)strlen(buff); + InputTextCallback_UserData cb_user_data; + cb_user_data.textInputData = &textInputData; + cb_user_data.env = env; + cb_user_data.curSize = size; + cb_user_data.maxSize = maxSize; + cb_user_data.maxChar = maxChar; + cb_user_data.allowedChar = allowedChar; + cb_user_data.allowedCharLength = allowedCharLength; + + char tempArray [maxSize]; + memset(tempArray, 0, sizeof(tempArray)); + memcpy(tempArray, buff, size); + if(maxChar >= 0 && maxChar < maxSize) + maxSize = maxChar; + bool flag = ImGui::InputText(label, tempArray, maxSize, flags | ImGuiInputTextFlags_CallbackCharFilter, &TextEditCallbackStub, &cb_user_data); + if(flag) { + size = (int)strlen(tempArray); + env->SetIntField (textInputData, imTextInputDataSizeID, size); + env->SetBooleanField (textInputData, imTextInputDataIsDirtyID, true); + memset(buff, 0, maxSize); + memcpy(buff, tempArray, size); + } + return flag; + */ + + static native boolean InputFloat(String label, float [] v) /*-{ }-*/; /* + ImGui::InputFloat(label, &v[0]); + */ + + static native boolean InputFloat(String label, float [] v, float step, float step_fast, String format) /*-{ }-*/; /* + ImGui::InputFloat(label, &v[0], step, step_fast, format); + */ + + static native boolean InputFloat(String label, float [] v, float step, float step_fast, String format, int flags) /*-{ }-*/; /* + ImGui::InputFloat(label, &v[0], step, step_fast, format, flags); + */ + + static native boolean InputInt(String label, int [] v) /*-{ }-*/; /* + ImGui::InputInt(label, &v[0]); + */ + + static native boolean InputInt(String label, int [] v, float step, float step_fast) /*-{ }-*/; /* + ImGui::InputInt(label, &v[0], step, step_fast); + */ + + static native boolean InputInt(String label, int [] v, float step, float step_fast, int flags) /*-{ }-*/; /* + ImGui::InputInt(label, &v[0], step, step_fast, flags); + */ + + static native boolean InputDouble(String label, double [] v) /*-{ }-*/; /* + ImGui::InputDouble(label, &v[0]); + */ + + static native boolean InputDouble(String label, double [] v, float step, float step_fast, String format) /*-{ }-*/; /* + ImGui::InputDouble(label, &v[0], step, step_fast, format); + */ + + + // Widgets: Trees + // - TreeNode functions return true when the node is open, in which case you need to also call TreePop() when you are finished displaying the tree node contents. + + static native boolean InputDouble(String label, double [] v, float step, float step_fast, String format, int flags) /*-{ }-*/; /* + ImGui::InputDouble(label, &v[0], step, step_fast, format, flags); + */ + + static native boolean TreeNode(String label) /*-{ }-*/; /* + return ImGui::TreeNode(label); + */ + + static native boolean TreeNode(String str_id, String label) /*-{ }-*/; /* + return ImGui::TreeNode(str_id, label); + */ + + static native boolean TreeNode(int ptr_id, String label) /*-{ }-*/; /* + return ImGui::TreeNode((void*)(intptr_t)ptr_id, label); + */ + + static native boolean TreeNodeEx(String label) /*-{ }-*/; /* + return ImGui::TreeNodeEx(label); + */ + + static native boolean TreeNodeEx(String label, int flags) /*-{ }-*/; /* + return ImGui::TreeNodeEx(label, flags); + */ + + static native boolean TreeNodeEx(String str_id, int flags, String label) /*-{ }-*/; /* + return ImGui::TreeNodeEx(str_id, flags, label); + */ + + static native boolean TreeNodeEx(int ptr_id, int flags, String label) /*-{ }-*/; /* + return ImGui::TreeNodeEx((void*)(intptr_t)ptr_id, flags, label); + */ + + static native void TreePush() /*-{ }-*/; /* + ImGui::TreePush(); + */ + + static native void TreePush(String str_id) /*-{ }-*/; /* + ImGui::TreePush(str_id); + */ + + static native void TreePush(int ptr_id) /*-{ }-*/; /* + ImGui::TreePush((void*)(intptr_t)ptr_id); + */ + + static native void TreePop() /*-{ }-*/; /* + ImGui::TreePop(); + */ + + static native void TreeAdvanceToLabelPos() /*-{ }-*/; /* + ImGui::TreeAdvanceToLabelPos(); + */ + + static native float GetTreeNodeToLabelSpacing() /*-{ }-*/; /* + return ImGui::GetTreeNodeToLabelSpacing(); + */ + + static native void SetNextTreeNodeOpen(boolean is_open) /*-{ }-*/; /* + ImGui::SetNextTreeNodeOpen(is_open); + */ + + static native void SetNextTreeNodeOpen(boolean is_open, int cond) /*-{ }-*/; /* + ImGui::SetNextTreeNodeOpen(is_open, cond); + */ + + static native boolean CollapsingHeader(String label) /*-{ }-*/; /* + return ImGui::CollapsingHeader(label); + */ + + static native boolean CollapsingHeader(String label, int flags) /*-{ }-*/; /* + return ImGui::CollapsingHeader(label, flags); + */ + + static native boolean CollapsingHeader(String label, boolean [] p_open) /*-{ }-*/; /* + return ImGui::CollapsingHeader(label, p_open); + */ + + // Widgets: Selectables + // - A selectable highlights when hovered, and can display another color when selected. + // - Neighbors selectable extend their highlight bounds in order to leave no gap between them. + + static native boolean CollapsingHeader(String label, boolean [] p_open, int flags) /*-{ }-*/; /* + return ImGui::CollapsingHeader(label, p_open, flags); + */ + + static native boolean Selectable(String label) /*-{ }-*/; /* + return ImGui::Selectable(label); + */ + + static native boolean Selectable(String label, boolean selected) /*-{ }-*/; /* + return ImGui::Selectable(label, selected); + */ + + static native boolean Selectable(String label, boolean selected, int flags, float sizeX, float sizeY) /*-{ }-*/; /* + return ImGui::Selectable(label, selected, flags, ImVec2(sizeX, sizeY)); + */ + + static native boolean Selectable(String label, boolean [] selected) /*-{ }-*/; /* + return ImGui::Selectable(label, &selected[0]); + */ + + // Widgets: List Boxes + // - FIXME: To be consistent with all the newer API, ListBoxHeader/ListBoxFooter should in reality be called BeginListBox/EndListBox. Will rename them. + + static native boolean Selectable(String label, boolean [] selected, int flags, float sizeX, float sizeY) /*-{ }-*/; /* + return ImGui::Selectable(label, &selected[0], flags, ImVec2(sizeX, sizeY)); + */ + + static native boolean ListBox(String label, int [] current_item, String [] items, int items_count) /*-{ }-*/; /* + const char* listbox_items[items_count]; + for(int i = 0; i < items_count; i++) { + jstring string = (jstring) (env->GetObjectArrayElement(items, i)); + const char *rawString = env->GetStringUTFChars(string, 0); + listbox_items[i] = rawString; + } + return ImGui::ListBox(label, ¤t_item[0], listbox_items, items_count); + */ + + static native boolean ListBoxHeader(String label) /*-{ }-*/; /* + return ImGui::ListBoxHeader(label); + */ + + static native boolean ListBoxHeader(String label, float sizeX, float sizeY) /*-{ }-*/; /* + return ImGui::ListBoxHeader(label, ImVec2(sizeX, sizeY)); + */ + + static native boolean ListBoxHeader(String label, int items_count) /*-{ }-*/; /* + return ImGui::ListBoxHeader(label, items_count); + */ + + static native boolean ListBoxHeader(String label, int items_count, int height_in_items) /*-{ }-*/; /* + return ImGui::ListBoxHeader(label, items_count, height_in_items); + */ + + // Widgets: Menus + + static native void ListBoxFooter() /*-{ }-*/; /* + ImGui::ListBoxFooter(); + */ + + static native boolean BeginMainMenuBar() /*-{ }-*/; /* + return ImGui::BeginMainMenuBar(); + */ + + static native void EndMainMenuBar() /*-{ }-*/; /* + ImGui::EndMainMenuBar(); + */ + + static native boolean BeginMenuBar() /*-{ }-*/; /* + return ImGui::BeginMenuBar(); + */ + + static native void EndMenuBar() /*-{ }-*/; /* + ImGui::EndMenuBar(); + */ + + static native boolean BeginMenu(String label) /*-{ }-*/; /* + return ImGui::BeginMenu(label); + */ + + static native boolean BeginMenu(String label, boolean enabled) /*-{ }-*/; /* + return ImGui::BeginMenu(label, enabled); + */ + + static native void EndMenu() /*-{ }-*/; /* + ImGui::EndMenu(); + */ + + static native boolean MenuItem(String label) /*-{ }-*/; /* + return ImGui::MenuItem(label); + */ + + static native boolean MenuItem(String label, String shortcut, boolean selected, boolean enabled) /*-{ }-*/; /* + return ImGui::MenuItem(label, shortcut, selected, enabled); + */ + + static native boolean MenuItem(String label, String shortcut, boolean [] p_selected) /*-{ }-*/; /* + return ImGui::MenuItem(label, shortcut, &p_selected[0]); + */ + + // Tooltips + + static native boolean MenuItem(String label, String shortcut, boolean [] p_selected, boolean enabled) /*-{ }-*/; /* + return ImGui::MenuItem(label, shortcut, &p_selected[0], enabled); + */ + + static native void BeginTooltip() /*-{ }-*/; /* + ImGui::BeginTooltip(); + */ + + static native void EndTooltip() /*-{ }-*/; /* + ImGui::EndTooltip(); + */ + + // Popups, Modals + // The properties of popups windows are: + // - They block normal mouse hovering detection outside them. (*) + // - Unless modal, they can be closed by clicking anywhere outside them, or by pressing ESCAPE. + // - Their visibility state (~bool) is held internally by imgui instead of being held by the programmer as we are used to with regular Begin() calls. + // User can manipulate the visibility state by calling OpenPopup(). + // (*) One can use IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup) to bypass it and detect hovering even when normally blocked by a popup. + // Those three properties are connected. The library needs to hold their visibility state because it can close popups at any time. + + static native void SetTooltip(String text) /*-{ }-*/; /* + ImGui::SetTooltip(text); + */ + + static native void OpenPopup(String str_id) /*-{ }-*/; /* + ImGui::OpenPopup(str_id); + */ + + static native boolean BeginPopup(String str_id) /*-{ }-*/; /* + return ImGui::BeginPopup(str_id); + */ + + static native boolean BeginPopup(String str_id, int flags) /*-{ }-*/; /* + return ImGui::BeginPopup(str_id, flags); + */ + + static native boolean BeginPopupContextItem() /*-{ }-*/; /* + return ImGui::BeginPopupContextItem(); + */ + + static native boolean BeginPopupContextItem(String str_id, int mouse_button) /*-{ }-*/; /* + return ImGui::BeginPopupContextItem(str_id, mouse_button); + */ + + static native boolean BeginPopupContextWindow() /*-{ }-*/; /* + return ImGui::BeginPopupContextWindow(); + */ + + static native boolean BeginPopupContextWindow(String str_id, int mouse_button, boolean also_over_items) /*-{ }-*/; /* + return ImGui::BeginPopupContextWindow(str_id, mouse_button, also_over_items); + */ + + static native boolean BeginPopupContextVoid() /*-{ }-*/; /* + return ImGui::BeginPopupContextVoid(); + */ + + static native boolean BeginPopupContextVoid(String str_id, int mouse_button) /*-{ }-*/; /* + return ImGui::BeginPopupContextVoid(str_id, mouse_button); + */ + + static native boolean BeginPopupModal(String name) /*-{ }-*/; /* + return ImGui::BeginPopupModal(name); + */ + + static native boolean BeginPopupModal(String name, boolean [] p_open, int flags) /*-{ }-*/; /* + return ImGui::BeginPopupModal(name, &p_open[0], flags); + */ + + static native void EndPopup() /*-{ }-*/; /* + ImGui::EndPopup(); + */ + + static native boolean OpenPopupOnItemClick() /*-{ }-*/; /* + return ImGui::OpenPopupOnItemClick(); + */ + + static native boolean OpenPopupOnItemClick(String str_id, int mouse_button) /*-{ }-*/; /* + return ImGui::OpenPopupOnItemClick(str_id, mouse_button); + */ + + static native boolean IsPopupOpen(String str_id) /*-{ }-*/; /* + return ImGui::IsPopupOpen(str_id); + */ + + // Columns + // - You can also use SameLine(pos_x) to mimic simplified columns. + // - The columns API is work-in-progress and rather lacking (columns are arguably the worst part of dear imgui at the moment!) + + static native void CloseCurrentPopup() /*-{ }-*/; /* + ImGui::CloseCurrentPopup(); + */ + + static native void Columns() /*-{ }-*/; /* + ImGui::Columns(); + */ + + static native void Columns(int count) /*-{ }-*/; /* + ImGui::Columns(count); + */ + + static native void Columns(int count, String id) /*-{ }-*/; /* + ImGui::Columns(count, id); + */ + + static native void Columns(int count, String id, boolean border) /*-{ }-*/; /* + ImGui::Columns(count, id, border); + */ + + static native void NextColumn() /*-{ }-*/; /* + ImGui::NextColumn(); + */ + + static native int GetColumnIndex() /*-{ }-*/; /* + return ImGui::GetColumnIndex(); + */ + + static native float GetColumnWidth() /*-{ }-*/; /* + return ImGui::GetColumnWidth(); + */ + + static native float GetColumnWidth(int column_index) /*-{ }-*/; /* + return ImGui::GetColumnWidth(column_index); + */ + + static native void SetColumnWidth(int column_index, float width) /*-{ }-*/; /* + ImGui::SetColumnWidth(column_index, width); + */ + + static native float GetColumnOffset() /*-{ }-*/; /* + return ImGui::GetColumnOffset(); + */ + + static native float GetColumnOffset(int column_index) /*-{ }-*/; /* + return ImGui::GetColumnOffset(column_index); + */ + + static native void SetColumnOffset(int column_index, float offset_x) /*-{ }-*/; /* + ImGui::SetColumnOffset(column_index, offset_x); + */ + + // Tab Bars, Tabs + // [BETA API] API may evolve! + + static native int GetColumnsCount() /*-{ }-*/; /* + return ImGui::GetColumnsCount(); + */ + + static native boolean BeginTabBar(String str_id) /*-{ }-*/; /* + return ImGui::BeginTabBar(str_id); + */ + + static native boolean BeginTabBar(String str_id, int flags) /*-{ }-*/; /* + return ImGui::BeginTabBar(str_id, flags); + */ + + static native void EndTabBar() /*-{ }-*/; /* + ImGui::EndTabBar(); + */ + + static native boolean BeginTabItem(String label) /*-{ }-*/; /* + return ImGui::BeginTabItem(label); + */ + + static native boolean BeginTabItem(String label, boolean [] p_open, int flags) /*-{ }-*/; /* + return ImGui::BeginTabItem(label, &p_open[0], flags); + */ + + static native void EndTabItem() /*-{ }-*/; /* + ImGui::EndTabItem(); + */ + + // Docking + // [BETA API] Enable with io.ConfigFlags |= ImGuiConfigFlags_DockingEnable. + // Note: you DO NOT need to call DockSpace() to use most Docking facilities! + // To dock windows: if io.ConfigDockingWithShift == false: drag window from their title bar. + // To dock windows: if io.ConfigDockingWithShift == true: hold SHIFT anywhere while moving windows. + // Use DockSpace() to create an explicit dock node _within_ an existing window. See Docking demo for details. + + static native void SetTabItemClosed(String tab_or_docked_window_label) /*-{ }-*/; /* + ImGui::SetTabItemClosed(tab_or_docked_window_label); + */ + + // TODO: Available after docking comes from BETA +// static native void DockSpace(int id) /*-{ }-*/; /* +// ImGui::DockSpace(id); +// */ + + // TODO: Available after docking comes from BETA +// static native void DockSpace(int id, float sizeX, float sizeY) /*-{ }-*/; /* +// ImGui::DockSpace(id, ImVec2(sizeX, sizeY)); +// */ + + // Focus, Activation + // - Prefer using "SetItemDefaultFocus()" over "if (IsWindowAppearing()) SetScrollHereY()" when applicable to signify "this is the default item" + + // TODO: Available after docking comes from BETA +// static native void DockSpace(int id, float sizeX, float sizeY, int flags) /*-{ }-*/; /* +// ImGui::DockSpace(id, ImVec2(sizeX, sizeY), flags); +// */ + + static native void SetItemDefaultFocus() /*-{ }-*/; /* + ImGui::SetItemDefaultFocus(); + */ + + static native boolean SetKeyboardFocusHere() /*-{ }-*/; /* + ImGui::SetKeyboardFocusHere(); + */ + + // Item/Widgets Utilities + // - Most of the functions are referring to the last/previous item we submitted. + // - See Demo Window under "Widgets->Querying Status" for an interactive visualization of most of those functions. + + static native boolean SetKeyboardFocusHere(int offset) /*-{ }-*/; /* + ImGui::SetKeyboardFocusHere(offset); + */ + + static native boolean IsItemHovered() /*-{ }-*/; /* + return ImGui::IsItemHovered(); + */ + + static native boolean IsItemHovered(int flags) /*-{ }-*/; /* + return ImGui::IsItemHovered(flags); + */ + + static native boolean IsItemActive() /*-{ }-*/; /* + return ImGui::IsItemActive(); + */ + + static native boolean IsItemFocused() /*-{ }-*/; /* + return ImGui::IsItemFocused(); + */ + + static native boolean IsItemClicked() /*-{ }-*/; /* + return ImGui::IsItemClicked(); + */ + + static native boolean IsItemClicked(int mouse_button) /*-{ }-*/; /* + return ImGui::IsItemClicked(mouse_button); + */ + + static native boolean IsItemVisible() /*-{ }-*/; /* + return ImGui::IsItemVisible(); + */ + + static native boolean IsItemEdited() /*-{ }-*/; /* + return ImGui::IsItemEdited(); + */ + + static native boolean IsItemActivated() /*-{ }-*/; /* + return ImGui::IsItemActivated(); + */ + + static native boolean IsItemDeactivated() /*-{ }-*/; /* + return ImGui::IsItemDeactivated(); + */ + + static native boolean IsItemDeactivatedAfterEdit() /*-{ }-*/; /* + return ImGui::IsItemDeactivatedAfterEdit(); + */ + + static native boolean IsAnyItemHovered() /*-{ }-*/; /* + return ImGui::IsAnyItemHovered(); + */ + + static native boolean IsAnyItemActive() /*-{ }-*/; /* + return ImGui::IsAnyItemActive(); + */ + + static native boolean IsAnyItemFocused() /*-{ }-*/; /* + return ImGui::IsAnyItemFocused(); + */ + + static native void GetItemRectMin(ImVec2 jImVec2) /*-{ }-*/; /* + ImVec2 vec = ImGui::GetItemRectMin(); + env->SetFloatField (jImVec2, imVec2XID, vec.x); + env->SetFloatField (jImVec2, imVec2YID, vec.y); + */ + + static native void GetItemRectMax(ImVec2 jImVec2) /*-{ }-*/; /* + ImVec2 vec = ImGui::GetItemRectMax(); + env->SetFloatField (jImVec2, imVec2XID, vec.x); + env->SetFloatField (jImVec2, imVec2YID, vec.y); + */ + + static native void GetItemRectSize(ImVec2 jImVec2) /*-{ }-*/; /* + ImVec2 vec = ImGui::GetItemRectSize(); + env->SetFloatField (jImVec2, imVec2XID, vec.x); + env->SetFloatField (jImVec2, imVec2YID, vec.y); + */ + + // Miscellaneous Utilities + + static native void SetItemAllowOverlap() /*-{ }-*/; /* + ImGui::SetItemAllowOverlap(); + */ + + static native boolean BeginChildFrame(int id, float width, float height) /*-{ }-*/; /* + return ImGui::BeginChildFrame(id, ImVec2(width, height)); + */ + + static native boolean BeginChildFrame(int id, float width, float height, int flags) /*-{ }-*/; /* + return ImGui::BeginChildFrame(id, ImVec2(width, height), flags); + */ + + // Inputs Utilities + + static native void EndChildFrame() /*-{ }-*/; /* + ImGui::EndChildFrame(); + */ + + static native boolean IsMouseDown(int button) /*-{ }-*/; /* + return ImGui::IsMouseDown(button); + */ + + static native boolean IsMouseClicked(int button) /*-{ }-*/; /* + return ImGui::IsMouseClicked(button); + */ + + static native boolean IsMouseClicked(int button, boolean repeat) /*-{ }-*/; /* + return ImGui::IsMouseClicked(button, repeat); + */ + + static native boolean IsMouseReleased(int button) /*-{ }-*/; /* + return ImGui::IsMouseReleased(button); + */ + + static native boolean IsMouseDragging() /*-{ }-*/; /* + return ImGui::IsMouseDragging(); + */ + + static native boolean IsMouseDragging(int button) /*-{ }-*/; /* + return ImGui::IsMouseDragging(button); + */ + + static native boolean IsMouseDragging(int button, float lock_threshold) /*-{ }-*/; /* + return ImGui::IsMouseDragging(button, lock_threshold); + */ + + static native boolean IsMouseHoveringRect(float minX, float minY, float maxX, float maxY) /*-{ }-*/; /* + return ImGui::IsMouseHoveringRect(ImVec2(minX, minY), ImVec2(maxX, maxY)); + */ + + static native boolean IsMouseHoveringRect(float minX, float minY, float maxX, float maxY, boolean clip) /*-{ }-*/; /* + return ImGui::IsMouseHoveringRect(ImVec2(minX, minY), ImVec2(maxX, maxY), clip); + */ + + // @formatter:on +} diff --git a/imgui-binding/src/main/java/imgui/NativeCustomWidget.java b/imgui-binding/src/main/java/imgui/NativeCustomWidget.java new file mode 100644 index 0000000..60fb6cb --- /dev/null +++ b/imgui-binding/src/main/java/imgui/NativeCustomWidget.java @@ -0,0 +1,168 @@ +package imgui; + +import imgui.enums.ImDrawCornerFlags; + +class NativeCustomWidget { + public static ImGuiCollapseLayoutOptions defaultOptions = new ImGuiCollapseLayoutOptions(); + + // @formatter:off + + /*JNI + #include + + jfieldID paddingLeftID; + jfieldID paddingRightID; + jfieldID paddingTopID; + jfieldID paddingBottomID; + jfieldID arrowColorID; + jfieldID arrowBackgroundHoveredColorID; + jfieldID arrowBackgroundClickedColorID; + jfieldID frameColorID; + jfieldID borderColorID; + jfieldID borderRoundID; + jfieldID roundingCornersID; + */ + + static native void init() /*-{ }-*/; /* + jclass jLayoutOptionsClass = env->FindClass("imgui/NativeCustomWidget"); + paddingLeftID = env->GetFieldID(jLayoutOptionsClass, "paddingLeft", "F"); + paddingRightID = env->GetFieldID(jLayoutOptionsClass, "paddingRight", "F"); + paddingTopID = env->GetFieldID(jLayoutOptionsClass, "paddingTop", "F"); + paddingBottomID = env->GetFieldID(jLayoutOptionsClass, "paddingBottom", "F"); + arrowColorID = env->GetFieldID(jLayoutOptionsClass, "arrowColor", "I"); + arrowBackgroundHoveredColorID = env->GetFieldID(jLayoutOptionsClass, "arrowBackgroundHoveredColor", "I"); + arrowBackgroundClickedColorID = env->GetFieldID(jLayoutOptionsClass, "arrowBackgroundClickedColor", "I"); + frameColorID = env->GetFieldID(jLayoutOptionsClass, "frameColor", "I"); + borderColorID = env->GetFieldID(jLayoutOptionsClass, "borderColor", "I"); + borderRoundID = env->GetFieldID(jLayoutOptionsClass, "borderRound", "I"); + roundingCornersID = env->GetFieldID(jLayoutOptionsClass, "roundingCorners", "I"); + */ + + static { + init(); + } + + static native void ShowLayoutDebug() /*-{ }-*/; /* + ImGuiEx::ShowLayoutDebug(); + */ + + static native void BeginLayout(String id, float sizeX, float sizeY); /*-{ }-*/; /* + ImGuiEx::BeginLayout(id, sizeX, sizeY); + */ + + static native void BeginLayout(String id, float sizeX, float sizeY, float paddingLeft, float paddingRight, float paddingTop, float paddingBottom); /*-{ }-*/; /* + ImGuiEx::BeginLayout(id, sizeX, sizeY, paddingLeft, paddingRight, paddingTop, paddingBottom); + */ + + static native void EndLayout(); /*-{ }-*/; /* + ImGuiEx::EndLayout(); + */ + + static native boolean BeginCollapseLayoutEx2(String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions jOptions); /*-{ }-*/; /* + ImGuiCollapseLayoutOptions options; + options.paddingLeft = env->GetFloatField (jOptions, paddingLeftID); + options.paddingRight = env->GetFloatField (jOptions, paddingRightID); + options.paddingTop = env->GetFloatField (jOptions, paddingTopID); + options.paddingBottom = env->GetFloatField (jOptions, paddingBottomID); + options.arrowColor = env->GetIntField (jOptions, arrowColorID); + options.arrowBackgroundHoveredColor = env->GetIntField (jOptions, arrowBackgroundHoveredColorID); + options.arrowBackgroundClickedColor = env->GetIntField (jOptions, arrowBackgroundClickedColorID); + options.frameColor = env->GetIntField (jOptions, frameColorID); + options.borderColor = env->GetIntField (jOptions, borderColorID); + options.borderRound = env->GetIntField (jOptions, borderRoundID); + options.roundingCorners = env->GetIntField (jOptions, roundingCornersID); + return ImGuiEx::BeginCollapseLayoutEx(title, sizeX, sizeY, options); + */ + + static native void BeginCollapseLayoutEx(boolean [] isOpen, String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions jOptions); /*-{ }-*/; /* + ImGuiCollapseLayoutOptions options; + options.paddingLeft = env->GetFloatField (jOptions, paddingLeftID); + options.paddingRight = env->GetFloatField (jOptions, paddingRightID); + options.paddingTop = env->GetFloatField (jOptions, paddingTopID); + options.paddingBottom = env->GetFloatField (jOptions, paddingBottomID); + options.arrowColor = env->GetIntField (jOptions, arrowColorID); + options.arrowBackgroundHoveredColor = env->GetIntField (jOptions, arrowBackgroundHoveredColorID); + options.arrowBackgroundClickedColor = env->GetIntField (jOptions, arrowBackgroundClickedColorID); + options.frameColor = env->GetIntField (jOptions, frameColorID); + options.borderColor = env->GetIntField (jOptions, borderColorID); + options.borderRound = env->GetIntField (jOptions, borderRoundID); + options.roundingCorners = env->GetIntField (jOptions, roundingCornersID); + ImGuiEx::BeginCollapseLayoutEx(&isOpen[0], title, sizeX, sizeY, options); + */ + + static native boolean BeginCollapseLayout2(String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions jOptions); /*-{ }-*/; /* + ImGuiCollapseLayoutOptions options; + options.paddingLeft = env->GetFloatField (jOptions, paddingLeftID); + options.paddingRight = env->GetFloatField (jOptions, paddingRightID); + options.paddingTop = env->GetFloatField (jOptions, paddingTopID); + options.paddingBottom = env->GetFloatField (jOptions, paddingBottomID); + options.arrowColor = env->GetIntField (jOptions, arrowColorID); + options.arrowBackgroundHoveredColor = env->GetIntField (jOptions, arrowBackgroundHoveredColorID); + options.arrowBackgroundClickedColor = env->GetIntField (jOptions, arrowBackgroundClickedColorID); + options.frameColor = env->GetIntField (jOptions, frameColorID); + options.borderColor = env->GetIntField (jOptions, borderColorID); + options.borderRound = env->GetIntField (jOptions, borderRoundID); + options.roundingCorners = env->GetIntField (jOptions, roundingCornersID); + return ImGuiEx::BeginCollapseLayout(title, sizeX, sizeY, options); + */ + + static native void BeginCollapseLayout(boolean [] isOpen, String title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions jOptions); /*-{ }-*/; /* + ImGuiCollapseLayoutOptions options; + options.paddingLeft = env->GetFloatField (jOptions, paddingLeftID); + options.paddingRight = env->GetFloatField (jOptions, paddingRightID); + options.paddingTop = env->GetFloatField (jOptions, paddingTopID); + options.paddingBottom = env->GetFloatField (jOptions, paddingBottomID); + options.arrowColor = env->GetIntField (jOptions, arrowColorID); + options.arrowBackgroundHoveredColor = env->GetIntField (jOptions, arrowBackgroundHoveredColorID); + options.arrowBackgroundClickedColor = env->GetIntField (jOptions, arrowBackgroundClickedColorID); + options.frameColor = env->GetIntField (jOptions, frameColorID); + options.borderColor = env->GetIntField (jOptions, borderColorID); + options.borderRound = env->GetIntField (jOptions, borderRoundID); + options.roundingCorners = env->GetIntField (jOptions, roundingCornersID); + ImGuiEx::BeginCollapseLayout(&isOpen[0], title, sizeX, sizeY, options); + */ + + static native void EndCollapseFrameLayout(); /*-{ }-*/; /* + ImGuiEx::EndCollapseFrameLayout(); + */ + + static native void EndCollapseLayout(); /*-{ }-*/; /* + ImGuiEx::EndCollapseLayout(); + */ + + static native void BeginAlign(String id, float sizeX, float sizeY, float alignX, float alignY) /*-{ }-*/; /* + ImGuiEx::BeginAlign(id, sizeX, sizeY, alignX, alignY); + */ + + static native void BeginAlign(String id, float sizeX, float sizeY, float alignX, float alignY, float offsetX, float offsetY) /*-{ }-*/; /* + ImGuiEx::BeginAlign(id, sizeX, sizeY, alignX, alignY, offsetX, offsetY); + */ + + static native void EndAlign() /*-{ }-*/; /* + ImGuiEx::EndAlign(); + */ + + static native void AlignLayout(float alignX, float alignY) /*-{ }-*/; /* + ImGuiEx::AlignLayout(alignX, alignY); + */ + + static native void AlignLayout(float alignX, float alignY, float offsetX, float offsetY) /*-{ }-*/; /* + ImGuiEx::AlignLayout(alignX, alignY, offsetX, offsetY); + */ + + // @formatter:on + + public static class ImGuiCollapseLayoutOptions { + public float paddingLeft = 2; + public float paddingRight = 2; + public float paddingTop = 2; + public float paddingBottom = 2; + public int arrowColor = ImGuiEx.colorToIntBits(0xFF, 0xFF, 0xFF, 0xFF); + public int arrowBackgroundHoveredColor = ImGuiEx.colorToIntBits(0x77, 0x77, 0x77, 0xFF); + public int arrowBackgroundClickedColor = ImGuiEx.colorToIntBits(0x55, 0x55, 0x55, 0xFF); + public int frameColor = ImGuiEx.colorToIntBits(0x24, 0x24, 0x24, 0xFF); + public int borderColor = ImGuiEx.colorToIntBits(0x40, 0x40, 0x49, 0xFF); + public int borderRound = 4; + public int roundingCorners = ImDrawCornerFlags.TopLeft.or(ImDrawCornerFlags.TopRight).getValue(); + } +} diff --git a/imgui-binding/src/main/java/imgui/NativeInternal.java b/imgui-binding/src/main/java/imgui/NativeInternal.java new file mode 100644 index 0000000..278c973 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/NativeInternal.java @@ -0,0 +1,28 @@ +package imgui; + +/** + * Same as {@link Native} but "imgui_internal.h" API. + */ +class NativeInternal { + // @formatter:off + + /*JNI + #include + #include + */ + + public static native void PushMultiItemsWidths(int components, float w_full) /*-{ }-*/; /* + ImGui::PushMultiItemsWidths(components, w_full); + */ + + public static native boolean ItemAdd(float x1, float y1, float x2, float y2, String id) /*-{ }-*/; /* + ImGuiID imGuiID = ImGui::GetID(id); + return ImGui::ItemAdd(ImRect(x1, y1, x2, y2), imGuiID); + */ + + public static native void ItemSize(float x1, float y1, float x2, float y2, float text_offset_y) /*-{ }-*/; /* + ImGui::ItemSize(ImRect(x1, y1, x2, y2), text_offset_y); + */ + + // @formatter:on +} diff --git a/imgui-binding/src/main/java/imgui/TexDataRGBA32.java b/imgui-binding/src/main/java/imgui/TexDataRGBA32.java new file mode 100644 index 0000000..63c15ae --- /dev/null +++ b/imgui-binding/src/main/java/imgui/TexDataRGBA32.java @@ -0,0 +1,18 @@ +package imgui; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class TexDataRGBA32 { + public int width; + public int height; + + public ByteBuffer pixelBuffer; + + public TexDataRGBA32() { + int pixelMax = 131072; + ByteBuffer buffer = ByteBuffer.allocateDirect(pixelMax); + buffer.order(ByteOrder.nativeOrder()); + pixelBuffer = buffer; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImDrawCornerFlags.java b/imgui-binding/src/main/java/imgui/enums/ImDrawCornerFlags.java new file mode 100644 index 0000000..3fb772a --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImDrawCornerFlags.java @@ -0,0 +1,28 @@ +package imgui.enums; + +public class ImDrawCornerFlags { + public static ImDrawCornerFlags TopLeft = new ImDrawCornerFlags(1 << 0); + public static ImDrawCornerFlags TopRight = new ImDrawCornerFlags(1 << 1); + public static ImDrawCornerFlags BotLeft = new ImDrawCornerFlags(1 << 2); + public static ImDrawCornerFlags BotRight = new ImDrawCornerFlags(1 << 3); + public static ImDrawCornerFlags Top = new ImDrawCornerFlags(TopLeft.getValue() | TopRight.getValue()); + public static ImDrawCornerFlags Bot = new ImDrawCornerFlags(BotLeft.getValue() | BotRight.getValue()); + public static ImDrawCornerFlags Left = new ImDrawCornerFlags(TopLeft.getValue() | BotLeft.getValue()); + public static ImDrawCornerFlags Right = new ImDrawCornerFlags(TopRight.getValue() | BotRight.getValue()); + public static ImDrawCornerFlags All = new ImDrawCornerFlags(0xF); + private static ImDrawCornerFlags Custom = new ImDrawCornerFlags(0); + int value; + + private ImDrawCornerFlags(int code) { + value = code; + } + + public ImDrawCornerFlags or(ImDrawCornerFlags otherEnum) { + ImDrawCornerFlags.Custom.value = value | otherEnum.value; + return ImDrawCornerFlags.Custom; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiBackendFlags.java b/imgui-binding/src/main/java/imgui/enums/ImGuiBackendFlags.java new file mode 100644 index 0000000..0941c14 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiBackendFlags.java @@ -0,0 +1,26 @@ +package imgui.enums; + +/** + * Back-end capabilities flags stored in io.BackendFlags. Set by imgui_impl_xxx or custom back-end. + */ +public class ImGuiBackendFlags { + public static ImGuiBackendFlags None = new ImGuiBackendFlags(0); + public static ImGuiBackendFlags HasGamepad = new ImGuiBackendFlags(1 << 0); + public static ImGuiBackendFlags HasMouseCursors = new ImGuiBackendFlags(1 << 1); + public static ImGuiBackendFlags HasSetMousePos = new ImGuiBackendFlags(1 << 2); + private static ImGuiBackendFlags Custom = new ImGuiBackendFlags(0); + int value; + + private ImGuiBackendFlags(int code) { + value = code; + } + + public ImGuiBackendFlags or(ImGuiBackendFlags otherEnum) { + ImGuiBackendFlags.Custom.value = value | otherEnum.value; + return ImGuiBackendFlags.Custom; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiCol.java b/imgui-binding/src/main/java/imgui/enums/ImGuiCol.java new file mode 100644 index 0000000..2c18d1e --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiCol.java @@ -0,0 +1,89 @@ +package imgui.enums; + +public enum ImGuiCol { + Text(0), + TextDisabled(1), + /** + * Background of normal windows + */ + WindowBg(2), + /** + * Background of child windows + */ + ChildBg(3), + /** + * Background of popups, menus, tooltips windows + */ + PopupBg(4), + Border(5), + BorderShadow(6), + /** + * Background of checkbox, radio button, plot, slider, text input + */ + FrameBg(7), + FrameBgHovered(8), + FrameBgActive(9), + TitleBg(10), + TitleBgActive(11), + TitleBgCollapsed(12), + MenuBarBg(13), + ScrollbarBg(14), + ScrollbarGrab(15), + ScrollbarGrabHovered(16), + ScrollbarGrabActive(17), + CheckMark(18), + SliderGrab(19), + SliderGrabActive(20), + Button(21), + ButtonHovered(22), + ButtonActive(23), + Header(24), + HeaderHovered(25), + HeaderActive(26), + Separator(27), + SeparatorHovered(28), + SeparatorActive(29), + ResizeGrip(30), + ResizeGripHovered(31), + ResizeGripActive(32), + Tab(33), + TabHovered(34), + TabActive(35), + TabUnfocused(36), + TabUnfocusedActive(37), + DockingPrevie(38), + DockingEmptyBg(39), + PlotLines(40), + PlotLinesHovered(41), + PlotHistogram(42), + PlotHistogramHovered(43), + TextSelectedBg(44), + DragDropTarget(45), + /** + * Gamepad/keyboard: current highlighted item + */ + NavHighlight(46), + /** + * Highlight window when using CTRL+TAB + */ + NavWindowingHighlight(47), + /** + * Darken/colorize entire screen behind the CTRL+TAB window list, when active + */ + NavWindowingDimBg(48), + /** + * Darken/colorize entire screen behind a modal window, when one is active + */ + ModalWindowDimBg(49), + COUNT(48); + + int value; + + ImGuiCol(int code) { + value = code; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiColorEditFlags.java b/imgui-binding/src/main/java/imgui/enums/ImGuiColorEditFlags.java new file mode 100644 index 0000000..5c7b8d7 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiColorEditFlags.java @@ -0,0 +1,47 @@ +package imgui.enums; + +/** + * Enumeration for GetMouseCursor() + * User code may request binding to display given cursor by calling SetMouseCursor(), which is why we have some cursors that are marked unused here + */ +public class ImGuiColorEditFlags { + public static ImGuiColorEditFlags None = new ImGuiColorEditFlags(0); + public static ImGuiColorEditFlags NoAlpha = new ImGuiColorEditFlags(1 << 1); + public static ImGuiColorEditFlags NoPicker = new ImGuiColorEditFlags(1 << 2); + public static ImGuiColorEditFlags NoOptions = new ImGuiColorEditFlags(1 << 3); + public static ImGuiColorEditFlags NoSmallPreview = new ImGuiColorEditFlags(1 << 4); + public static ImGuiColorEditFlags NoInputs = new ImGuiColorEditFlags(1 << 5); + public static ImGuiColorEditFlags NoTooltip = new ImGuiColorEditFlags(1 << 6); + public static ImGuiColorEditFlags NoLabel = new ImGuiColorEditFlags(1 << 7); + public static ImGuiColorEditFlags NoSidePreview = new ImGuiColorEditFlags(1 << 8); + public static ImGuiColorEditFlags NoDragDrop = new ImGuiColorEditFlags(1 << 9); + public static ImGuiColorEditFlags AlphaBar = new ImGuiColorEditFlags(1 << 16); + public static ImGuiColorEditFlags AlphaPreview = new ImGuiColorEditFlags(1 << 17); + public static ImGuiColorEditFlags AlphaPreviewHalf = new ImGuiColorEditFlags(1 << 18); + public static ImGuiColorEditFlags HDR = new ImGuiColorEditFlags(1 << 19); + public static ImGuiColorEditFlags DisplayRGB = new ImGuiColorEditFlags(1 << 20); + public static ImGuiColorEditFlags DisplayHSV = new ImGuiColorEditFlags(1 << 21); + public static ImGuiColorEditFlags DisplayHex = new ImGuiColorEditFlags(1 << 22); + public static ImGuiColorEditFlags Uint8 = new ImGuiColorEditFlags(1 << 23); + public static ImGuiColorEditFlags Float = new ImGuiColorEditFlags(1 << 24); + public static ImGuiColorEditFlags PickerHueBar = new ImGuiColorEditFlags(1 << 25); + public static ImGuiColorEditFlags PickerHueWheel = new ImGuiColorEditFlags(1 << 26); + public static ImGuiColorEditFlags InputRGB = new ImGuiColorEditFlags(1 << 27); + public static ImGuiColorEditFlags InputHSV = new ImGuiColorEditFlags(1 << 28); + public static ImGuiColorEditFlags OptionsDefault = new ImGuiColorEditFlags(Uint8.getValue() | DisplayRGB.getValue() | InputRGB.getValue() | PickerHueBar.getValue()); + private static ImGuiColorEditFlags Custom = new ImGuiColorEditFlags(0); + int value; + + private ImGuiColorEditFlags(int code) { + value = code; + } + + public ImGuiColorEditFlags or(ImGuiColorEditFlags otherEnum) { + ImGuiColorEditFlags.Custom.value = value | otherEnum.value; + return ImGuiColorEditFlags.Custom; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiComboFlags.java b/imgui-binding/src/main/java/imgui/enums/ImGuiComboFlags.java new file mode 100644 index 0000000..be97ac5 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiComboFlags.java @@ -0,0 +1,31 @@ +package imgui.enums; + +/** + * Flags for ImGui::BeginCombo() + */ +public class ImGuiComboFlags { + public static ImGuiComboFlags None = new ImGuiComboFlags(0); + public static ImGuiComboFlags PopupAlignLeft = new ImGuiComboFlags(1 << 0); + public static ImGuiComboFlags HeightSmall = new ImGuiComboFlags(1 << 1); + public static ImGuiComboFlags HeightRegular = new ImGuiComboFlags(1 << 2); + public static ImGuiComboFlags HeightLarge = new ImGuiComboFlags(1 << 3); + public static ImGuiComboFlags HeightLargest = new ImGuiComboFlags(1 << 4); + public static ImGuiComboFlags NoArrowButton = new ImGuiComboFlags(1 << 5); + public static ImGuiComboFlags NoPreview = new ImGuiComboFlags(1 << 6); + public static ImGuiComboFlags HeightMask = new ImGuiComboFlags(HeightSmall.getValue() | HeightRegular.getValue() | HeightLarge.getValue() | HeightLargest.getValue()); + private static ImGuiComboFlags Custom = new ImGuiComboFlags(0); + int value; + + private ImGuiComboFlags(int code) { + value = code; + } + + public ImGuiComboFlags or(ImGuiComboFlags otherEnum) { + ImGuiComboFlags.Custom.value = value | otherEnum.value; + return ImGuiComboFlags.Custom; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiCond.java b/imgui-binding/src/main/java/imgui/enums/ImGuiCond.java new file mode 100644 index 0000000..85d6405 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiCond.java @@ -0,0 +1,28 @@ +package imgui.enums; + +/** + * Enumateration for ImGui::SetWindow***(), SetNextWindow***(), SetNextTreeNode***() functions + * Represent a condition. + * Important: Treat as a regular enum! Do NOT combine multiple values using binary operators! All the functions above treat 0 as a shortcut to ImGuiCond_Always. + */ +public class ImGuiCond { + public static ImGuiCond Always = new ImGuiCond(1 << 0); + public static ImGuiCond Once = new ImGuiCond(1 << 1); + public static ImGuiCond FirstUseEver = new ImGuiCond(1 << 2); + public static ImGuiCond Appearing = new ImGuiCond(1 << 3); + private static ImGuiCond Custom = new ImGuiCond(0); + int value; + + private ImGuiCond(int code) { + value = code; + } + + public ImGuiCond or(ImGuiCond otherEnum) { + ImGuiCond.Custom.value = value | otherEnum.value; + return ImGuiCond.Custom; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiConfigFlags.java b/imgui-binding/src/main/java/imgui/enums/ImGuiConfigFlags.java new file mode 100644 index 0000000..0796c2d --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiConfigFlags.java @@ -0,0 +1,32 @@ +package imgui.enums; + +/** + * Configuration flags stored in io.ConfigFlags. Set by user/application. + */ +public class ImGuiConfigFlags { + public static ImGuiConfigFlags None = new ImGuiConfigFlags(0); + public static ImGuiConfigFlags NavEnableKeyboard = new ImGuiConfigFlags(1 << 0); + public static ImGuiConfigFlags NavEnableGamepad = new ImGuiConfigFlags(1 << 1); + public static ImGuiConfigFlags NavEnableSetMousePos = new ImGuiConfigFlags(1 << 2); + public static ImGuiConfigFlags NavNoCaptureKeyboard = new ImGuiConfigFlags(1 << 3); + public static ImGuiConfigFlags NoMouse = new ImGuiConfigFlags(1 << 4); + public static ImGuiConfigFlags NoMouseCursorChange = new ImGuiConfigFlags(1 << 5); + public static ImGuiConfigFlags DockingEnable = new ImGuiConfigFlags(1 << 6); + public static ImGuiConfigFlags IsSRGB = new ImGuiConfigFlags(1 << 20); + public static ImGuiConfigFlags IsTouchScreen = new ImGuiConfigFlags(1 << 21); + private static ImGuiConfigFlags Custom = new ImGuiConfigFlags(0); + int value; + + private ImGuiConfigFlags(int code) { + value = code; + } + + public ImGuiConfigFlags or(ImGuiConfigFlags otherEnum) { + ImGuiConfigFlags.Custom.value = value | otherEnum.value; + return ImGuiConfigFlags.Custom; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiDataType.java b/imgui-binding/src/main/java/imgui/enums/ImGuiDataType.java new file mode 100644 index 0000000..f4083e3 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiDataType.java @@ -0,0 +1,28 @@ +package imgui.enums; + +/** + * A primary data type + */ +public enum ImGuiDataType { + S8(0), + U8(1), + S16(2), + U16(3), + S32(4), + U32(5), + S64(6), + U64(7), + Float(8), + Double(9), + COUNT(10); + + int value; + + ImGuiDataType(int code) { + value = code; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiDir.java b/imgui-binding/src/main/java/imgui/enums/ImGuiDir.java new file mode 100644 index 0000000..d639acf --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiDir.java @@ -0,0 +1,20 @@ +package imgui.enums; + +public enum ImGuiDir { + None(-1), + Left(0), + Right(1), + Up(2), + Down(3), + COUNT(4); + + private final int code; + + ImGuiDir(int code) { + this.code = code; + } + + public int toInt() { + return code; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiDockNodeFlags.java b/imgui-binding/src/main/java/imgui/enums/ImGuiDockNodeFlags.java new file mode 100644 index 0000000..c14384f --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiDockNodeFlags.java @@ -0,0 +1,25 @@ +package imgui.enums; + +public class ImGuiDockNodeFlags { + public static ImGuiDockNodeFlags KeepAliveOnly = new ImGuiDockNodeFlags(1 << 0); + public static ImGuiDockNodeFlags NoDockingInCentralNode = new ImGuiDockNodeFlags(1 << 2); + public static ImGuiDockNodeFlags PassthruCentralNode = new ImGuiDockNodeFlags(1 << 3); + public static ImGuiDockNodeFlags NoSplit = new ImGuiDockNodeFlags(1 << 4); + public static ImGuiDockNodeFlags NoResize = new ImGuiDockNodeFlags(1 << 5); + public static ImGuiDockNodeFlags AutoHideTabBar = new ImGuiDockNodeFlags(1 << 6); + private static ImGuiDockNodeFlags Custom = new ImGuiDockNodeFlags(0); + int value; + + private ImGuiDockNodeFlags(int code) { + value = code; + } + + public ImGuiDockNodeFlags or(ImGuiDockNodeFlags otherEnum) { + ImGuiDockNodeFlags.Custom.value = value | otherEnum.value; + return ImGuiDockNodeFlags.Custom; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiDragDropFlags.java b/imgui-binding/src/main/java/imgui/enums/ImGuiDragDropFlags.java new file mode 100644 index 0000000..fb797af --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiDragDropFlags.java @@ -0,0 +1,37 @@ +package imgui.enums; + +/** + * Flags for ImGui::IsItemHovered(), ImGui::IsWindowHovered() + * Note: if you are trying to check whether your mouse should be dispatched to imgui or to your app, you should use the 'io.WantCaptureMouse' boolean for that. Please read the FAQ! + * Note: windows with the ImGuiWindowFlags_NoInputs flag are ignored by IsWindowHovered() calls. + */ +public class ImGuiDragDropFlags { + public static ImGuiDragDropFlags None = new ImGuiDragDropFlags(0); + // BeginDragDropSource() flags + public static ImGuiDragDropFlags SourceNoPreviewTooltip = new ImGuiDragDropFlags(1 << 0); + public static ImGuiDragDropFlags SourceNoDisableHover = new ImGuiDragDropFlags(1 << 1); + public static ImGuiDragDropFlags SourceNoHoldToOpenOthers = new ImGuiDragDropFlags(1 << 2); + public static ImGuiDragDropFlags SourceAllowNullID = new ImGuiDragDropFlags(1 << 3); + public static ImGuiDragDropFlags SourceExtern = new ImGuiDragDropFlags(1 << 4); + public static ImGuiDragDropFlags SourceAutoExpirePayload = new ImGuiDragDropFlags(1 << 5); + // AcceptDragDropPayload() flags + public static ImGuiDragDropFlags AcceptBeforeDelivery = new ImGuiDragDropFlags(1 << 10); + public static ImGuiDragDropFlags AcceptNoDrawDefaultRect = new ImGuiDragDropFlags(1 << 11); + public static ImGuiDragDropFlags AcceptNoPreviewTooltip = new ImGuiDragDropFlags(1 << 12); + public static ImGuiDragDropFlags AcceptPeekOnly = new ImGuiDragDropFlags(AcceptBeforeDelivery.getValue() | AcceptNoDrawDefaultRect.getValue()); + private static ImGuiDragDropFlags Custom = new ImGuiDragDropFlags(0); + int value; + + private ImGuiDragDropFlags(int code) { + value = code; + } + + public ImGuiDragDropFlags or(ImGuiDragDropFlags otherEnum) { + ImGuiDragDropFlags.Custom.value = value | otherEnum.value; + return ImGuiDragDropFlags.Custom; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiFocusedFlags.java b/imgui-binding/src/main/java/imgui/enums/ImGuiFocusedFlags.java new file mode 100644 index 0000000..101e498 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiFocusedFlags.java @@ -0,0 +1,27 @@ +package imgui.enums; + +/** + * Flags for ImGui::IsWindowFocused() + */ +public class ImGuiFocusedFlags { + public static ImGuiFocusedFlags None = new ImGuiFocusedFlags(0); + public static ImGuiFocusedFlags ChildWindows = new ImGuiFocusedFlags(1 << 0); + public static ImGuiFocusedFlags RootWindow = new ImGuiFocusedFlags(1 << 1); + public static ImGuiFocusedFlags AnyWindow = new ImGuiFocusedFlags(1 << 2); + public static ImGuiFocusedFlags RootAndChildWindows = new ImGuiFocusedFlags(RootWindow.getValue() | ChildWindows.getValue()); + private static ImGuiFocusedFlags Custom = new ImGuiFocusedFlags(0); + int value; + + private ImGuiFocusedFlags(int code) { + value = code; + } + + public ImGuiFocusedFlags or(ImGuiFocusedFlags otherEnum) { + ImGuiFocusedFlags.Custom.value = value | otherEnum.value; + return ImGuiFocusedFlags.Custom; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiHoveredFlags.java b/imgui-binding/src/main/java/imgui/enums/ImGuiHoveredFlags.java new file mode 100644 index 0000000..27f4b15 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiHoveredFlags.java @@ -0,0 +1,35 @@ +package imgui.enums; + +/** + * Flags for ImGui::IsItemHovered(), ImGui::IsWindowHovered() + * Note: if you are trying to check whether your mouse should be dispatched to imgui or to your app, you should use the 'io.WantCaptureMouse' boolean for that. Please read the FAQ! + * Note: windows with the ImGuiWindowFlags_NoInputs flag are ignored by IsWindowHovered() calls. + */ +public class ImGuiHoveredFlags { + public static ImGuiHoveredFlags None = new ImGuiHoveredFlags(0); + public static ImGuiHoveredFlags ChildWindows = new ImGuiHoveredFlags(1 << 0); + public static ImGuiHoveredFlags RootWindow = new ImGuiHoveredFlags(1 << 1); + public static ImGuiHoveredFlags AnyWindow = new ImGuiHoveredFlags(1 << 2); + public static ImGuiHoveredFlags AllowWhenBlockedByPopup = new ImGuiHoveredFlags(1 << 3); + // public static ImGuiHoveredFlags AllowWhenBlockedByModal = new ImGuiHoveredFlags(1 << 4); + public static ImGuiHoveredFlags AllowWhenBlockedByActiveItem = new ImGuiHoveredFlags(1 << 5); + public static ImGuiHoveredFlags AllowWhenOverlapped = new ImGuiHoveredFlags(1 << 6); + public static ImGuiHoveredFlags AllowWhenDisabled = new ImGuiHoveredFlags(1 << 7); + public static ImGuiHoveredFlags RectOnly = new ImGuiHoveredFlags(AllowWhenBlockedByPopup.getValue() | AllowWhenBlockedByActiveItem.getValue() | AllowWhenOverlapped.getValue()); + public static ImGuiHoveredFlags RootAndChildWindows = new ImGuiHoveredFlags(RootWindow.getValue() | ChildWindows.getValue()); + private static ImGuiHoveredFlags Custom = new ImGuiHoveredFlags(0); + int value; + + private ImGuiHoveredFlags(int code) { + value = code; + } + + public ImGuiHoveredFlags or(ImGuiHoveredFlags otherEnum) { + ImGuiHoveredFlags.Custom.value = value | otherEnum.value; + return ImGuiHoveredFlags.Custom; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiInputTextFlags.java b/imgui-binding/src/main/java/imgui/enums/ImGuiInputTextFlags.java new file mode 100644 index 0000000..18c04bd --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiInputTextFlags.java @@ -0,0 +1,99 @@ +package imgui.enums; + +/** + * Flags for ImGui::InputText() + */ +public class ImGuiInputTextFlags { + public static ImGuiInputTextFlags None = new ImGuiInputTextFlags(0); + /** + * Allow 0123456789.+-* + */ + public static ImGuiInputTextFlags CharsDecimal = new ImGuiInputTextFlags(1 << 0); + /** + * Allow 0123456789ABCDEFabcdef + */ + public static ImGuiInputTextFlags CharsHexadecimal = new ImGuiInputTextFlags(1 << 1); + /** + * Turn a..z into A..Z + */ + public static ImGuiInputTextFlags CharsUppercase = new ImGuiInputTextFlags(1 << 2); + /** + * Filter out spaces, tabs + */ + public static ImGuiInputTextFlags CharsNoBlank = new ImGuiInputTextFlags(1 << 3); + /** + * Select entire text when first taking mouse focus + */ + public static ImGuiInputTextFlags AutoSelectAll = new ImGuiInputTextFlags(1 << 4); + /** + * Return 'true' when Enter is pressed (as opposed to every time the value was modified). Consider looking at the IsItemDeactivatedAfterEdit() function. + */ + public static ImGuiInputTextFlags EnterReturnsTrue = new ImGuiInputTextFlags(1 << 5); + /** + * Callback on pressing TAB (for completion handling) + */ + public static ImGuiInputTextFlags CallbackCompletion = new ImGuiInputTextFlags(1 << 6); + /** + * Callback on pressing Up/Down arrows (for history handling) + */ + public static ImGuiInputTextFlags CallbackHistory = new ImGuiInputTextFlags(1 << 7); + /** + * Callback on each iteration. User code may query cursor position, modify text buffer. + */ + public static ImGuiInputTextFlags CallbackAlways = new ImGuiInputTextFlags(1 << 8); + /** + * Callback on character inputs to replace or discard them. Modify 'EventChar' to replace or discard, or return 1 in callback to discard. + */ + public static ImGuiInputTextFlags CallbackCharFilter = new ImGuiInputTextFlags(1 << 9); + /** + * Pressing TAB input a '\t' character into the text field + */ + public static ImGuiInputTextFlags AllowTabInput = new ImGuiInputTextFlags(1 << 10); + /** + * In multi-line mode, unfocus with Enter, add new line with Ctrl+Enter (default is opposite: unfocus with Ctrl+Enter, add line with Enter). + */ + public static ImGuiInputTextFlags CtrlEnterForNewLine = new ImGuiInputTextFlags(1 << 11); + /** + * Disable following the cursor horizontally + */ + public static ImGuiInputTextFlags NoHorizontalScroll = new ImGuiInputTextFlags(1 << 12); + /** + * Insert mode + */ + public static ImGuiInputTextFlags AlwaysInsertMode = new ImGuiInputTextFlags(1 << 13); + /** + * Read-only mode + */ + public static ImGuiInputTextFlags ReadOnly = new ImGuiInputTextFlags(1 << 14); + /** + * Password mode, display all characters as '*' + */ + public static ImGuiInputTextFlags Password = new ImGuiInputTextFlags(1 << 15); + /** + * Disable undo/redo. Note that input text owns the text data while active, if you want to provide your own undo/redo stack you need e.g. to call ClearActiveID(). + */ + public static ImGuiInputTextFlags NoUndoRedo = new ImGuiInputTextFlags(1 << 16); + /** + * Allow 0123456789.+-*\\/eE (Scientific notation input) + */ + public static ImGuiInputTextFlags CharsScientific = new ImGuiInputTextFlags(1 << 17); + /** + * Callback on buffer capacity changes request (beyond 'buf_size' parameter value), allowing the string to grow. Notify when the string wants to be resized (for string types which hold a cache of their Size). You will be provided a new BufSize in the callback and NEED to honor it. (see misc/cpp/imgui_stdlib.h for an example of using this) + */ + public static ImGuiInputTextFlags CallbackResize = new ImGuiInputTextFlags(1 << 18); + private static ImGuiInputTextFlags Custom = new ImGuiInputTextFlags(0); + public int data; + + private ImGuiInputTextFlags(int code) { + data = code; + } + + public ImGuiInputTextFlags or(ImGuiInputTextFlags otherEnum) { + ImGuiInputTextFlags.Custom.data = data | otherEnum.data; + return ImGuiInputTextFlags.Custom; + } + + public int getValue() { + return data; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiKey.java b/imgui-binding/src/main/java/imgui/enums/ImGuiKey.java new file mode 100644 index 0000000..06b43d9 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiKey.java @@ -0,0 +1,39 @@ +package imgui.enums; + +/** + * User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array + */ +public enum ImGuiKey { + Tab(0), + LeftArrow(1), + RightArrow(2), + UpArrow(3), + DownArrow(4), + PageUp(5), + PageDown(6), + Home(7), + End(8), + Insert(9), + Delete(10), + Backspace(11), + Space(12), + Enter(13), + Escape(14), + A(15), + C(16), + V(17), + X(18), + Y(19), + Z(20), + COUNT(21); + + private final int code; + + ImGuiKey(int code) { + this.code = code; + } + + public int getValue() { + return code; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiMouseCursor.java b/imgui-binding/src/main/java/imgui/enums/ImGuiMouseCursor.java new file mode 100644 index 0000000..0c94608 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiMouseCursor.java @@ -0,0 +1,28 @@ +package imgui.enums; + +/** + * Enumeration for GetMouseCursor() + * User code may request binding to display given cursor by calling SetMouseCursor(), which is why we have some cursors that are marked unused here + */ +public enum ImGuiMouseCursor { + None(-1), + Arrow(0), + TextInput(1), + ResizeAll(2), + ResizeNS(3), + ResizeEW(4), + ResizeNESW(5), + ResizeNWSE(6), + Hand(7), + COUNT(8); + + int value; + + ImGuiMouseCursor(int code) { + value = code; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiNavInput.java b/imgui-binding/src/main/java/imgui/enums/ImGuiNavInput.java new file mode 100644 index 0000000..d60b8f5 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiNavInput.java @@ -0,0 +1,36 @@ +package imgui.enums; + +/** + * Gamepad/Keyboard directional navigation + * Keyboard: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable. NewFrame() will automatically fill io.NavInputs[] based on your io.KeysDown[] + io.KeyMap[] arrays. + * Gamepad: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad to enable. Back-end: set ImGuiBackendFlags_HasGamepad and fill the io.NavInputs[] fields before calling NewFrame(). Note that io.NavInputs[] is cleared by EndFrame(). + * Read instructions in imgui.cpp for more details. Download PNG/PSD at http://goo.gl/9LgVZW. + **/ +public enum ImGuiNavInput { + Activate(0), + Cancel(1), + Input(2), + Menu(3), + DpadLeft(4), + DpadRight(5), + DpadUp(6), + DpadDown(7), + LStickLeft(8), + LStickRight(9), + LStickUp(10), + LStickDown(11), + FocusPrev(12), + FocusNext(13), + TweakSlow(14), + TweakFast(15); + + private final int code; + + ImGuiNavInput(int code) { + this.code = code; + } + + public int toInt() { + return code; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiSelectableFlags.java b/imgui-binding/src/main/java/imgui/enums/ImGuiSelectableFlags.java new file mode 100644 index 0000000..2e3623a --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiSelectableFlags.java @@ -0,0 +1,27 @@ +package imgui.enums; + +/** + * Flags for ImGui::Selectable() + */ +public class ImGuiSelectableFlags { + public static ImGuiSelectableFlags None = new ImGuiSelectableFlags(0); + public static ImGuiSelectableFlags DontClosePopups = new ImGuiSelectableFlags(1 << 0); + public static ImGuiSelectableFlags SpanAllColumns = new ImGuiSelectableFlags(1 << 1); + public static ImGuiSelectableFlags AllowDoubleClick = new ImGuiSelectableFlags(1 << 2); + public static ImGuiSelectableFlags Disabled = new ImGuiSelectableFlags(1 << 3); + private static ImGuiSelectableFlags Custom = new ImGuiSelectableFlags(0); + int value; + + private ImGuiSelectableFlags(int code) { + value = code; + } + + public ImGuiSelectableFlags or(ImGuiSelectableFlags otherEnum) { + ImGuiSelectableFlags.Custom.value = value | otherEnum.value; + return ImGuiSelectableFlags.Custom; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiStyleVar.java b/imgui-binding/src/main/java/imgui/enums/ImGuiStyleVar.java new file mode 100644 index 0000000..4f60eb1 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiStyleVar.java @@ -0,0 +1,38 @@ +package imgui.enums; + +public enum ImGuiStyleVar { + Alpha(0), + WindowPadding(1), + WindowRounding(2), + WindowBorderSize(3), + WindowMinSize(4), + WindowTitleAlign(5), + ChildRounding(6), + ChildBorderSize(7), + PopupRounding(8), + PopupBorderSize(9), + FramePadding(10), + FrameRounding(11), + ImGuiStyleVar_FrameBorderSize(12), + ItemSpacing(13), + ItemInnerSpacing(14), + IndentSpacing(15), + ScrollbarSize(16), + ScrollbarRounding(17), + GrabMinSize(18), + GrabRounding(19), + TabRounding(20), + ButtonTextAlign(21), + SelectableTextAlign(22), + COUNT(23); + + int value; + + ImGuiStyleVar(int code) { + value = code; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiTabBarFlags.java b/imgui-binding/src/main/java/imgui/enums/ImGuiTabBarFlags.java new file mode 100644 index 0000000..4ccd908 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiTabBarFlags.java @@ -0,0 +1,33 @@ +package imgui.enums; + +/** + * Flags for ImGui::BeginTabBar() + */ +public class ImGuiTabBarFlags { + public static ImGuiTabBarFlags None = new ImGuiTabBarFlags(0); + public static ImGuiTabBarFlags Reorderable = new ImGuiTabBarFlags(1 << 0); + public static ImGuiTabBarFlags AutoSelectNewTabs = new ImGuiTabBarFlags(1 << 1); + public static ImGuiTabBarFlags TabListPopupButton = new ImGuiTabBarFlags(1 << 2); + public static ImGuiTabBarFlags NoCloseWithMiddleMouseButton = new ImGuiTabBarFlags(1 << 3); + public static ImGuiTabBarFlags NoTabListScrollingButtons = new ImGuiTabBarFlags(1 << 4); + public static ImGuiTabBarFlags NoTooltip = new ImGuiTabBarFlags(1 << 5); + public static ImGuiTabBarFlags FittingPolicyResizeDown = new ImGuiTabBarFlags(1 << 6); + public static ImGuiTabBarFlags FittingPolicyScroll = new ImGuiTabBarFlags(1 << 7); + public static ImGuiTabBarFlags FittingPolicyMask = new ImGuiTabBarFlags(FittingPolicyResizeDown.getValue() | FittingPolicyScroll.getValue()); + public static ImGuiTabBarFlags FittingPolicyDefault = new ImGuiTabBarFlags(FittingPolicyResizeDown.getValue()); + private static ImGuiTabBarFlags Custom = new ImGuiTabBarFlags(0); + int value; + + private ImGuiTabBarFlags(int code) { + value = code; + } + + public ImGuiTabBarFlags or(ImGuiTabBarFlags otherEnum) { + ImGuiTabBarFlags.Custom.value = value | otherEnum.value; + return ImGuiTabBarFlags.Custom; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiTabItemFlags.java b/imgui-binding/src/main/java/imgui/enums/ImGuiTabItemFlags.java new file mode 100644 index 0000000..c9fe2cd --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiTabItemFlags.java @@ -0,0 +1,27 @@ +package imgui.enums; + +/** + * Flags for ImGui::BeginTabItem() + */ +public class ImGuiTabItemFlags { + public static ImGuiTabItemFlags None = new ImGuiTabItemFlags(0); + public static ImGuiTabItemFlags UnsavedDocument = new ImGuiTabItemFlags(1 << 0); + public static ImGuiTabItemFlags SetSelected = new ImGuiTabItemFlags(1 << 1); + public static ImGuiTabItemFlags NoCloseWithMiddleMouseButton = new ImGuiTabItemFlags(1 << 2); + public static ImGuiTabItemFlags NoPushId = new ImGuiTabItemFlags(1 << 3); + private static ImGuiTabItemFlags Custom = new ImGuiTabItemFlags(0); + int value; + + private ImGuiTabItemFlags(int code) { + value = code; + } + + public ImGuiTabItemFlags or(ImGuiTabItemFlags otherEnum) { + ImGuiTabItemFlags.Custom.value = value | otherEnum.value; + return ImGuiTabItemFlags.Custom; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiTreeNodeFlags.java b/imgui-binding/src/main/java/imgui/enums/ImGuiTreeNodeFlags.java new file mode 100644 index 0000000..7695ae4 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiTreeNodeFlags.java @@ -0,0 +1,38 @@ +package imgui.enums; + +/** + * Flags for ImGui::TreeNodeEx(), ImGui::CollapsingHeader*() + */ +public class ImGuiTreeNodeFlags { + public static ImGuiTreeNodeFlags None = new ImGuiTreeNodeFlags(0); + public static ImGuiTreeNodeFlags Selected = new ImGuiTreeNodeFlags(1 << 0); + public static ImGuiTreeNodeFlags Framed = new ImGuiTreeNodeFlags(1 << 1); + public static ImGuiTreeNodeFlags AllowItemOverlap = new ImGuiTreeNodeFlags(1 << 2); + public static ImGuiTreeNodeFlags NoTreePushOnOpen = new ImGuiTreeNodeFlags(1 << 3); + public static ImGuiTreeNodeFlags NoAutoOpenOnLog = new ImGuiTreeNodeFlags(1 << 4); + public static ImGuiTreeNodeFlags DefaultOpen = new ImGuiTreeNodeFlags(1 << 5); + public static ImGuiTreeNodeFlags OpenOnDoubleClick = new ImGuiTreeNodeFlags(1 << 6); + public static ImGuiTreeNodeFlags OpenOnArrow = new ImGuiTreeNodeFlags(1 << 7); + public static ImGuiTreeNodeFlags Leaf = new ImGuiTreeNodeFlags(1 << 8); + public static ImGuiTreeNodeFlags Bullet = new ImGuiTreeNodeFlags(1 << 9); + public static ImGuiTreeNodeFlags FramePadding = new ImGuiTreeNodeFlags(1 << 10); + // public static ImGuiTreeNodeFlags SpanAllAvailWidth = new ImGuiTreeNodeFlags(1 << 11); +// public static ImGuiTreeNodeFlags NoScrollOnOpen = new ImGuiTreeNodeFlags(1 << 12); + public static ImGuiTreeNodeFlags NavLeftJumpsBackHere = new ImGuiTreeNodeFlags(1 << 13); + public static ImGuiTreeNodeFlags CollapsingHeader = new ImGuiTreeNodeFlags(Framed.getValue() | NoTreePushOnOpen.getValue() | NoAutoOpenOnLog.getValue()); + private static ImGuiTreeNodeFlags Custom = new ImGuiTreeNodeFlags(0); + int value; + + private ImGuiTreeNodeFlags(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + public ImGuiTreeNodeFlags or(ImGuiTreeNodeFlags otherEnum) { + ImGuiTreeNodeFlags.Custom.value = value | otherEnum.value; + return ImGuiTreeNodeFlags.Custom; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiWindowFlags.java b/imgui-binding/src/main/java/imgui/enums/ImGuiWindowFlags.java new file mode 100644 index 0000000..fca7312 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiWindowFlags.java @@ -0,0 +1,47 @@ +package imgui.enums; + +/** + * Flags for ImGui::Begin() + */ +public class ImGuiWindowFlags { + public static ImGuiWindowFlags None = new ImGuiWindowFlags(0); + public static ImGuiWindowFlags NoTitleBar = new ImGuiWindowFlags(1 << 0); + public static ImGuiWindowFlags NoResize = new ImGuiWindowFlags(1 << 1); + public static ImGuiWindowFlags NoMove = new ImGuiWindowFlags(1 << 2); + public static ImGuiWindowFlags NoScrollbar = new ImGuiWindowFlags(1 << 3); + public static ImGuiWindowFlags NoScrollWithMouse = new ImGuiWindowFlags(1 << 4); + public static ImGuiWindowFlags NoCollapse = new ImGuiWindowFlags(1 << 5); + public static ImGuiWindowFlags AlwaysAutoResize = new ImGuiWindowFlags(1 << 6); + public static ImGuiWindowFlags NoBackground = new ImGuiWindowFlags(1 << 7); + public static ImGuiWindowFlags NoSavedSettings = new ImGuiWindowFlags(1 << 8); + public static ImGuiWindowFlags NoMouseInputs = new ImGuiWindowFlags(1 << 9); + public static ImGuiWindowFlags MenuBar = new ImGuiWindowFlags(1 << 10); + public static ImGuiWindowFlags HorizontalScrollbar = new ImGuiWindowFlags(1 << 11); + public static ImGuiWindowFlags NoFocusOnAppearing = new ImGuiWindowFlags(1 << 12); + public static ImGuiWindowFlags NoBringToFrontOnFocus = new ImGuiWindowFlags(1 << 13); + public static ImGuiWindowFlags AlwaysVerticalScrollbar = new ImGuiWindowFlags(1 << 14); + public static ImGuiWindowFlags AlwaysHorizontalScrollbar = new ImGuiWindowFlags(1 << 15); + public static ImGuiWindowFlags AlwaysUseWindowPadding = new ImGuiWindowFlags(1 << 16); + public static ImGuiWindowFlags NoNavInputs = new ImGuiWindowFlags(1 << 18); + public static ImGuiWindowFlags NoNavFocus = new ImGuiWindowFlags(1 << 19); + public static ImGuiWindowFlags UnsavedDocument = new ImGuiWindowFlags(1 << 20); + public static ImGuiWindowFlags NoDocking = new ImGuiWindowFlags(1 << 21); + public static ImGuiWindowFlags NoNav = new ImGuiWindowFlags(NoNavInputs.getValue() | NoNavFocus.getValue()); + public static ImGuiWindowFlags NoDecoration = new ImGuiWindowFlags(NoTitleBar.getValue() | NoResize.getValue() | NoScrollbar.getValue() | NoCollapse.getValue()); + public static ImGuiWindowFlags NoInputs = new ImGuiWindowFlags(NoMouseInputs.getValue() | NoNavInputs.getValue() | NoNavFocus.getValue()); + private static ImGuiWindowFlags Custom = new ImGuiWindowFlags(0); + int value; + + private ImGuiWindowFlags(int code) { + value = code; + } + + public ImGuiWindowFlags or(ImGuiWindowFlags otherEnum) { + ImGuiWindowFlags.Custom.value = value | otherEnum.value; + return ImGuiWindowFlags.Custom; + } + + public int getValue() { + return value; + } +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImLayout.java b/imgui-binding/src/main/java/imgui/enums/ImLayout.java new file mode 100644 index 0000000..a787fbf --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImLayout.java @@ -0,0 +1,6 @@ +package imgui.enums; + +public class ImLayout { + public static float MATCH_PARENT = -0.1f; + public static float WRAP_PARENT = 0.0f; +} diff --git a/imgui-binding/src/main/native/imgui_layout_widget.cpp b/imgui-binding/src/main/native/imgui_layout_widget.cpp new file mode 100644 index 0000000..c5d9532 --- /dev/null +++ b/imgui-binding/src/main/native/imgui_layout_widget.cpp @@ -0,0 +1,512 @@ +#include "imgui.h" +#include "imgui_internal.h" +#include "imgui_layout_widget.h" + +static ImVector layoutStack; + +static ImGuiLayout *createOrFind(const char *id) +{ + ImGuiContext &g = *GImGui; + ImGuiLayout *childLayout = NULL; + ImGuiID hashID = ImHashStr(id); + childLayout = (ImGuiLayout *)g.WindowsById.GetVoidPtr(hashID); + if (childLayout == NULL) + { + childLayout = IM_NEW(ImGuiLayout)(id); + g.WindowsById.SetVoidPtr(childLayout->id, childLayout); + } + return childLayout; +} + +static ImGuiLayout *pushLayout(const char *id) +{ + ImGuiLayout *parentLayout = NULL; + if (!layoutStack.empty()) + parentLayout = layoutStack.back(); + ImGuiLayout *childLayout = createOrFind(id); + childLayout->parentLayout = parentLayout; + layoutStack.push_back(childLayout); + return childLayout; +} + +ImGuiLayout *ImGuiEx::GetCurrentLayout() +{ + if (layoutStack.empty()) + return NULL; + return layoutStack.back(); +} + +static void popLayout() +{ + layoutStack.pop_back(); +} + +void ImGuiEx::ShowLayoutDebug() +{ + ImGuiLayout *curLayout = ImGuiEx::GetCurrentLayout(); + if (curLayout != NULL) + { + curLayout->debug = true; + } +} + +void ImGuiEx::BeginLayoutEx(const char *strID) +{ + ImGuiLayout *parentLayout = ImGuiEx::GetCurrentLayout(); + ImGuiID id = ImHashStr(strID); + char title[256]; + if (parentLayout) + ImFormatString(title, IM_ARRAYSIZE(title), "%s/%s_%08X", parentLayout->idStr, strID, id); + else + ImFormatString(title, IM_ARRAYSIZE(title), "%s/%08X", strID, id); + + pushLayout(title); +} + +bool ImGuiEx::PrepareLayout(float sizeX, float sizeY, float paddingLeft, float paddingRight, float paddingTop, float paddingBottom) +{ + ImGuiContext &g = *GImGui; + ImGuiWindow *window = g.CurrentWindow; + + ImGuiLayout *curLayout = ImGuiEx::GetCurrentLayout(); + bool ret = true; + // Update layout + + // Backup windows data + curLayout->DC = window->DC; + curLayout->WorkRect = window->WorkRect; + curLayout->skipping = window->SkipItems; + curLayout->AutoFitChildAxises = window->AutoFitChildAxises; + curLayout->Pos = window->Pos; + curLayout->ContentRegionRect = window->ContentRegionRect; + // ******** End Backup windows data + + curLayout->sizeParam.x = sizeX; + curLayout->sizeParam.y = sizeY; + + curLayout->paddingLeft = paddingLeft; + curLayout->paddingRight = paddingRight; + curLayout->paddingTop = paddingTop; + curLayout->paddingBottom = paddingBottom; + + curLayout->position = window->DC.CursorPos; + + ImVec2 contentPosition = curLayout->getPositionPadding(); + + curLayout->positionContents = curLayout->position; + + const ImVec2 content_avail = ImGui::GetContentRegionAvail(); + + ImVec2 sizeItem = ImFloor(curLayout->sizeParam); + + if (curLayout->sizeParam.x < 0.0f) + { + float sizeX = ImMax(content_avail.x + sizeItem.x, 4.0f); + curLayout->size.x = sizeX; + } + if (curLayout->sizeParam.y < 0.0f) + { + float sizeY = ImMax(content_avail.y + sizeItem.y, 4.0f); + curLayout->size.y = sizeY; + } + + // ***** End Update Layout + + // Write to window object + + window->Pos.x = contentPosition.x; + window->Pos.y = contentPosition.y; + window->DC.Indent.x = 0; + + //window->DC.CursorMaxPos.x = contentPosition.x + curLayout->size.x - curLayout->paddingLeft - curLayout->paddingRight; + //window->DC.CursorMaxPos.y = contentPosition.y + curLayout->size.y - curLayout->paddingTop - curLayout->paddingBottom; + window->DC.CursorMaxPos.x = contentPosition.x; + window->DC.CursorMaxPos.y = contentPosition.y; + + window->DC.CursorStartPos.x = contentPosition.x; + window->DC.CursorStartPos.y = contentPosition.y; + + window->DC.CurrLineSize.y = 0; // necessary to keep position inside layout + window->DC.CurrLineTextBaseOffset = 0; + + window->DC.CursorPos.x = contentPosition.x; + window->DC.CursorPos.y = contentPosition.y; + + window->WorkRect.Min.x = contentPosition.x; + window->WorkRect.Min.y = contentPosition.y; + window->WorkRect.Max.x = contentPosition.x + curLayout->size.x - curLayout->paddingLeft - curLayout->paddingRight; + window->WorkRect.Max.y = contentPosition.y + curLayout->size.y - curLayout->paddingTop - curLayout->paddingBottom; + + window->ContentRegionRect.Min.x = contentPosition.x; + window->ContentRegionRect.Min.y = contentPosition.y; + window->ContentRegionRect.Max.x = contentPosition.x + curLayout->size.x - curLayout->paddingLeft - curLayout->paddingRight; + window->ContentRegionRect.Max.y = contentPosition.y + curLayout->size.y - curLayout->paddingTop - curLayout->paddingBottom; + + // ***** End Write to window object + + if (curLayout->clipping) + { + ImVec2 min = curLayout->getPositionPadding(); + ImVec2 max = curLayout->getAbsoluteSizePadding(); + //ImGui::drawBoundingBox(min, max, 255, 0, 0); + ImGui::PushClipRect(min, max, true); + } + + bool skip_items = false; + if (window->Collapsed || !window->Active || window->Hidden) + /* if (window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && window->HiddenFramesCannotSkipItems <= 0)*/ + skip_items = true; + window->SkipItems = skip_items; + ret = !skip_items; + return true; +} + +bool ImGuiEx::BeginLayout(const char *strID, float sizeX, float sizeY, float paddingLeft, float paddingRight, float paddingTop, float paddingBottom) +{ + BeginLayoutEx(strID); + return PrepareLayout(sizeX, sizeY, paddingLeft, paddingRight, paddingTop, paddingBottom); +} + +void ImGuiEx::EndLayout() +{ + ImGuiContext &g = *GImGui; + ImGuiWindow *window = g.CurrentWindow; + ImGuiLayout *curLayout = ImGuiEx::GetCurrentLayout(); + if (curLayout == NULL) + return; + + if (curLayout->clipping) + ImGui::PopClipRect(); + + float x = window->DC.CursorPos.x; + float y = window->DC.CursorPos.y; + + curLayout->sizeContents.x = window->DC.CursorMaxPos.x - x; + //curLayout->sizeContents.y = y - curLayout->position.y - g.Style.ItemSpacing.y; + + //curLayout->sizeContents.x = window->DC.CursorMaxPos.x - curLayout->positionContents.x; + curLayout->sizeContents.y = y - curLayout->positionContents.y - g.Style.ItemSpacing.y; + + // Restore windows data + window->DC = curLayout->DC; + window->WorkRect = curLayout->WorkRect; + window->SkipItems = curLayout->skipping; + window->AutoFitChildAxises = curLayout->AutoFitChildAxises; + window->Pos = curLayout->Pos; + window->ContentRegionRect = curLayout->ContentRegionRect; + // ******************** + + //const ImVec2 content_avail = GetContentRegionAvail(); + ImVec2 sizeItem = curLayout->sizeParam; + + if (sizeItem.x < 0.0f) + { + sizeItem.x = curLayout->size.x; + if (curLayout->size.x < curLayout->sizeContents.x || curLayout->size.x > curLayout->sizeContents.x) + { + //special case where dev used MATCH_CONTENT and WRAP_CONTENT wrong. The parent have a WRAP_CONTENT y size and the child have MATCH_CONTENT y size. + /* curLayout->error = true; + sizeItem.x = 10;*/ + } + } + else if (sizeItem.x == 0.0f) + sizeItem.x = curLayout->sizeContents.x + curLayout->paddingLeft + curLayout->paddingRight; + + if (sizeItem.y < 0.0f) + { + sizeItem.y = curLayout->size.y; + if (curLayout->size.y < curLayout->sizeContents.y) + { + //special case where dev used MATCH_CONTENT and WRAP_CONTENT wrong. The parent have a WRAP_CONTENT y size and the child have MATCH_CONTENT y size. + //curLayout->error = true; + //sizeItem.y = curLayout->sizeContents.y; + } + } + else if (sizeItem.y == 0.0f) + sizeItem.y = curLayout->sizeContents.y + curLayout->paddingBottom; + + curLayout->size = sizeItem; + + ImGui::ItemSize(sizeItem); + + if (curLayout->debug) + { + curLayout->drawContentDebug(); + curLayout->drawPaddingAreaDebug(); + curLayout->drawSizeDebug(); + curLayout->debug = false; + } + + if (curLayout->error) + { + curLayout->error = false; + curLayout->drawError(); + } + + popLayout(); +} + +static bool renderFrameArrow(bool *value, int arrowColor, int arrowBackgroundHoveredColor, int arrowBackgroundClickedColor) +{ + ImGuiContext &g = *GImGui; + ImGuiWindow *window = g.CurrentWindow; + + ImDrawList *drawList = ImGui::GetWindowDrawList(); + float getFrameHeight = ImGui::GetFrameHeight(); + float removedSize = 5.5f; // reduce few pixels + float halfSize = (getFrameHeight) / 2.0f - removedSize; + + ImVec2 vec = ImGui::GetCursorScreenPos(); + + float screenPosX = vec.x; + float screenPosY = vec.y; + float arrowPaddingLeft = 6; + + float x = screenPosX + halfSize + arrowPaddingLeft; + float y = screenPosY + getFrameHeight / 2.0f; + + bool hovered = ImGui::IsMouseHoveringRect(ImVec2(x - halfSize - removedSize, y - halfSize - removedSize), ImVec2(x + halfSize + removedSize, y + halfSize + removedSize)); + ImU32 hoveredColor = arrowBackgroundHoveredColor; + bool isWindowHovered = ImGui::IsWindowHovered(); + + if (isWindowHovered) + { + if (hovered) + { + if (ImGui::IsMouseDown(0)) + hoveredColor = arrowBackgroundClickedColor; + if (ImGui::IsMouseReleased(0)) + *value = !*value; + } + + if (hovered) + drawList->AddCircleFilled(ImVec2(x, y), halfSize * 2, hoveredColor); + } + + float triA_X = 0; + float triA_Y = 0; + float triB_X = 0; + float triB_Y = 0; + float triC_X = 0; + float triC_Y = 0; + + if (*value) + { + // arrow down + float offset = -0.5f; + triA_X = x - halfSize + offset; + triA_Y = y - halfSize; + triB_X = x + halfSize + offset; + triB_Y = y - halfSize; + triC_X = x + offset; + triC_Y = y + halfSize; + } + else + { + // arrow right + triA_X = x - halfSize; + triA_Y = y - halfSize; + triB_X = x + halfSize; + triB_Y = y; + triC_X = x - halfSize; + triC_Y = y + halfSize; + } + + drawList->AddTriangleFilled(ImVec2(triA_X, triA_Y), ImVec2(triB_X, triB_Y), ImVec2(triC_X, triC_Y), arrowColor); + + float bk = g.Style.ItemSpacing.y; + g.Style.ItemSpacing.y = 0; + ImGui::ItemSize(ImVec2(halfSize * 2 + 3, getFrameHeight)); + g.Style.ItemSpacing.y = bk; + + return *value; +} + +static int OPEN_KEY = 13213; + +bool ImGuiEx::PrepareCollapseLayout(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) +{ + ImGuiContext &g = *GImGui; + ImGuiWindow *window = g.CurrentWindow; + ImDrawList *drawList = window->DrawList; + ImGuiLayout *rootLayout = ImGuiEx::GetCurrentLayout(); + + float frameHeight = ImGui::GetFrameHeight(); + + bool flag = rootLayout->map.GetBool(OPEN_KEY, false); + bool *isOpen = &flag; + + sizeY = *isOpen ? sizeY : ImLayout::WRAP_PARENT; + + ImGuiEx::PrepareLayout(sizeX, sizeY, 1, 1, 1, 1); + + rootLayout->map.SetFloat(120, options.paddingLeft); + rootLayout->map.SetFloat(121, options.paddingRight); + rootLayout->map.SetFloat(122, options.paddingTop); + rootLayout->map.SetFloat(123, options.paddingBottom); + + ImGuiEx::BeginLayout("frame", ImLayout::MATCH_PARENT, frameHeight, 0, 0, 0, 0); + ImGuiLayout *frameLayout = ImGuiEx::GetCurrentLayout(); + + ImVec2 mousePos = ImGui::GetMousePos(); + + drawList->AddRectFilled(rootLayout->position, ImVec2(rootLayout->getAbsoluteSize().x, frameLayout->getAbsoluteSize().y), options.frameColor, options.borderRound, options.roundingCorners); + + renderFrameArrow(isOpen, options.arrowColor, options.arrowBackgroundHoveredColor, options.arrowBackgroundClickedColor); + + rootLayout->map.SetBool(OPEN_KEY, *isOpen); + + ImGui::SameLine(); + + ImGuiEx::BeginAlign("align", ImLayout::WRAP_PARENT, ImLayout::MATCH_PARENT, 0, 0.5f, 0, 0); + + ImGui::Text(title); + + ImGuiEx::EndAlign(); + + ImGui::SameLine(); + + return *isOpen; +} + +void ImGuiEx::BeginCollapseLayoutEx(bool *isOpen, const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) +{ + ImGuiEx::BeginLayoutEx(title); + ImGuiLayout *rootLayout = ImGuiEx::GetCurrentLayout(); + rootLayout->map.SetBool(OPEN_KEY, *isOpen); + bool flag = ImGuiEx::PrepareCollapseLayout(title, sizeX, sizeY, options); + *isOpen = flag; +} + +bool ImGuiEx::BeginCollapseLayoutEx(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) +{ + ImGuiEx::BeginLayoutEx(title); + return ImGuiEx::PrepareCollapseLayout(title, sizeX, sizeY, options); +} + +bool ImGuiEx::BeginCollapseLayout(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) +{ + bool flag = ImGuiEx::BeginCollapseLayoutEx(title, sizeX, sizeY, options); + ImGuiEx::EndCollapseFrameLayout(); + return flag; +} + +void ImGuiEx::BeginCollapseLayout(bool *isOpen, const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options) +{ + ImGuiEx::BeginCollapseLayoutEx(isOpen, title, sizeX, sizeY, options); + ImGuiEx::EndCollapseFrameLayout(); +} + +void ImGuiEx::EndCollapseFrameLayout() +{ + ImGuiContext &g = *GImGui; + float bk = g.Style.ItemSpacing.y; + + g.Style.ItemSpacing.y = 0; + ImGuiEx::EndLayout(); // end frame + g.Style.ItemSpacing.y = bk; + ImGuiLayout *rootLayout = ImGuiEx::GetCurrentLayout(); + + float paddingLeft = rootLayout->map.GetFloat(120, 0.0f); + float paddingRight = rootLayout->map.GetFloat(121, 0.0f); + float paddingTop = rootLayout->map.GetFloat(122, 0.0f); + float paddingBottom = rootLayout->map.GetFloat(123, 0.0f); + + ImGuiEx::BeginLayout("content", ImLayout::MATCH_PARENT, ImLayout::WRAP_PARENT, paddingLeft, paddingRight, paddingTop, paddingBottom); + ImGuiLayout *collapseLayout = ImGuiEx::GetCurrentLayout(); +} + +void ImGuiEx::EndCollapseLayout() +{ + ImGuiContext &g = *GImGui; + ImGuiWindow *window = g.CurrentWindow; + ImDrawList *drawList = window->DrawList; + + ImU32 borderColor = ImGui::GetColorU32(ImVec4(0x40 / 255.0f, 0x40 / 255.0f, 0x49 / 255.0f, 255 / 255.0f)); + int borderRound = 4; + int roundingCorners = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_TopRight; + + ImGuiEx::EndLayout(); // end content + + ImGuiLayout *rootLayout = ImGuiEx::GetCurrentLayout(); + + ImGuiEx::EndLayout(); // end root + + ImVec2 borderPosition = rootLayout->position; + ImVec2 borderSize = rootLayout->getAbsoluteSize(); + + drawList->AddRect(borderPosition, borderSize, borderColor, borderRound, roundingCorners, 1.0f); +} + +void ImGuiEx::BeginAlign(const char *strID, float sizeX, float sizeY, float alignX, float alignY, float offsetX, float offsetY) +{ + ImGuiEx::BeginLayout(strID, sizeX, sizeY); + ImGuiEx::AlignLayout(alignX, alignY, offsetX, offsetY); +} + +void ImGuiEx::AlignLayout(float alignX, float alignY, float offsetX, float offsetY) +{ + ImGuiContext &g = *GImGui; + ImGuiWindow *window = g.CurrentWindow; + ImGuiLayout *curLayout = ImGuiEx::GetCurrentLayout(); + if (curLayout == NULL) + return; + + ImVec2 regionAvail = ImGui::GetContentRegionAvail(); + float totalX = regionAvail.x; + float totalY = regionAvail.y; + + ImVec2 posPad = curLayout->getPositionPadding(); + ImVec2 absSizePad = curLayout->getAbsoluteSizePadding(); + + if (alignX >= 0.0f && curLayout->sizeParam.x != ImLayout::WRAP_PARENT) + { + + float addX = ImFloor((totalX - curLayout->sizeContents.x) * alignX); + float newX = posPad.x + addX + offsetX; + if (newX < posPad.x) + { + curLayout->error = true; + newX = posPad.x; + } + else if (newX + curLayout->sizeContents.x > absSizePad.x) + { + curLayout->error = true; + newX = absSizePad.x - curLayout->sizeContents.x; + } + curLayout->positionContents.x = newX; + } + + if (alignY >= 0.0f && curLayout->sizeParam.y != ImLayout::WRAP_PARENT) + { + float addY = ImFloor((totalY - curLayout->sizeContents.y) * alignY); + float newY = posPad.y + addY + offsetY; + if (newY < posPad.y) + { + curLayout->error = true; + newY = posPad.y; + } + else if (newY + curLayout->sizeContents.y > absSizePad.y) + { + curLayout->error = true; + newY = absSizePad.y - curLayout->sizeContents.y; + } + curLayout->positionContents.y = newY; + } + window->DC.CursorMaxPos.x = curLayout->positionContents.x; + window->DC.CursorMaxPos.y = curLayout->positionContents.y; + + window->DC.CursorStartPos.x = curLayout->positionContents.x; + window->DC.CursorStartPos.y = curLayout->positionContents.y; + + window->Pos.x = curLayout->positionContents.x; + window->Pos.y = curLayout->positionContents.y; + + window->DC.CursorPos.x = curLayout->positionContents.x; + window->DC.CursorPos.y = curLayout->positionContents.y; +} + +void ImGuiEx::EndAlign() +{ + ImGuiEx::EndLayout(); +} \ No newline at end of file diff --git a/imgui-binding/src/main/native/imgui_layout_widget.h b/imgui-binding/src/main/native/imgui_layout_widget.h new file mode 100644 index 0000000..3a449b7 --- /dev/null +++ b/imgui-binding/src/main/native/imgui_layout_widget.h @@ -0,0 +1,182 @@ +#pragma once + +#include "imgui.h" +#include "imgui_internal.h" + +namespace ImGuiEx +{ +inline void drawBoundingBox(float x1, float y1, float x2, float y2, int r, int g, int b, bool clipping = false) +{ + ImDrawList *drawList = clipping ? ImGui::GetWindowDrawList() : ImGui::GetForegroundDrawList(); + + float rounding = 0; + int color = ImGui::GetColorU32(ImVec4(r / 255.0f, g / 255.0f, b / 255.0f, 205.0f / 255.0f)); + drawList->AddRect(ImVec2(x1, y1), ImVec2(x2, y2), color, rounding); +} + +inline void drawBoundingBox(ImVec2 min, ImVec2 max, int r, int g, int b, bool clipping = false) +{ + ImGuiEx::drawBoundingBox(min.x, min.y, max.x, max.y, r, g, b, clipping); +} +}; // namespace ImGuiEx + +struct ImGuiLayout +{ + +public: + char *idStr; + ImGuiID id; + ImGuiLayout *parentLayout; + + bool clipping; + bool debug; + + ImGuiStorage map; + + ImVec2 position; // Position of the layout + ImVec2 size; // Size of the layout + ImVec2 sizeParam; // Size parameter used when calling beginLayout + float paddingLeft; + float paddingRight; + float paddingTop; + float paddingBottom; + ImVec2 positionContents; // Position of contents. + ImVec2 sizeContents; // Size of contents. calculated after the first frame + + bool error; + + // Window Backup data + ImGuiWindowTempData DC; + ImRect WorkRect; + bool skipping; + int AutoFitChildAxises; + ImVec2 Pos; + ImRect ContentRegionRect; + + ImGuiLayout(const char *idStr) + { + this->idStr = ImStrdup(idStr); + this->id = ImHashStr(idStr); + paddingLeft = 0; + paddingRight = 0; + paddingTop = 0; + paddingBottom = 0; + clipping = true; + debug = false; + error = false; + skipping = false; + } + + bool haveParent() { return parentLayout != NULL; } + + ImVec2 getAbsoluteSize() + { + return ImVec2(position.x + size.x, position.y + size.y); + } + + ImVec2 getContentSize() + { + return ImVec2(position.x + sizeContents.x, position.y + sizeContents.y); + } + + ImVec2 getAbsoluteSizePadding() + { + return ImVec2(position.x + size.x - paddingRight, position.y + size.y - paddingBottom); + } + + ImVec2 getContentSizePadding() + { + return ImVec2(position.x + sizeContents.x + paddingLeft, position.y + sizeContents.y); + } + + ImVec2 getPositionPadding() + { + return ImVec2(position.x + paddingLeft, position.y + paddingTop); + } + + void drawSizeDebug() + { + // Render layout space + //Green + ImGuiEx::drawBoundingBox(position, getAbsoluteSize(), 0, 255, 0); + } + + inline void drawContentDebug() + { + // Render content space + // Blue + ImVec2 max = ImVec2(positionContents.x + sizeContents.x, positionContents.y + sizeContents.y); + ImGuiEx::drawBoundingBox(positionContents, max, 0, 0, 255); + } + + void drawPaddingAreaDebug() + { + // Render size with padding + ImGuiEx::drawBoundingBox(getPositionPadding(), getAbsoluteSizePadding(), 255, 255, 255); + } + + void drawError() + { + ImGuiEx::drawBoundingBox(position, getAbsoluteSize(), 255, 0, 0, true); + } +}; + +struct ImGuiCollapseLayoutOptions +{ +public: + float paddingLeft; + float paddingRight; + float paddingTop; + float paddingBottom; + ImU32 arrowColor; + ImU32 arrowBackgroundHoveredColor; + ImU32 arrowBackgroundClickedColor; + ImU32 frameColor; + ImU32 borderColor; + int borderRound; + int roundingCorners; + + ImGuiCollapseLayoutOptions() + { + paddingLeft = 2; + paddingRight = 2; + paddingTop = 2; + paddingBottom = 2; + arrowColor = ImGui::GetColorU32(ImVec4(0xFF / 255.0f, 0xFF / 255.0f, 0xFF / 255.0f, 0xFF / 255.0f)); + arrowBackgroundHoveredColor = ImGui::GetColorU32(ImVec4(0x77 / 255.0f, 0x77 / 255.0f, 0x77 / 255.0f, 0xFF / 255.0f)); + arrowBackgroundClickedColor = ImGui::GetColorU32(ImVec4(0x55 / 255.0f, 0x55 / 255.0f, 0x55 / 255.0f, 0xFF / 255.0f)); + frameColor = ImGui::GetColorU32(ImVec4(0x24 / 255.0f, 0x24 / 255.0f, 0x24 / 255.0f, 255 / 255.0f)); + borderColor = ImGui::GetColorU32(ImVec4(0x40 / 255.0f, 0x40 / 255.0f, 0x49 / 255.0f, 255 / 255.0f)); + borderRound = 4; + roundingCorners = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_TopRight; + } +}; + +namespace ImGuiEx +{ +void ShowLayoutDebug(); + +void BeginLayoutEx(const char *id); +bool PrepareLayout(float sizeX, float sizeY, float paddingLeft = 0, float paddingRight = 0, float paddingTop = 0, float paddingBottom = 0); +bool BeginLayout(const char *id, float sizeX, float sizeY, float paddingLeft = 0, float paddingRight = 0, float paddingTop = 0, float paddingBottom = 0); +void EndLayout(); +ImGuiLayout *GetCurrentLayout(); + +bool BeginCollapseLayoutEx(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options = ImGuiCollapseLayoutOptions()); +void BeginCollapseLayoutEx(bool *isOpen, const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options = ImGuiCollapseLayoutOptions()); +bool PrepareCollapseLayout(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options = ImGuiCollapseLayoutOptions()); +bool BeginCollapseLayout(const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options = ImGuiCollapseLayoutOptions()); +void BeginCollapseLayout(bool *isOpen, const char *title, float sizeX, float sizeY, ImGuiCollapseLayoutOptions options = ImGuiCollapseLayoutOptions()); +void EndCollapseFrameLayout(); +void EndCollapseLayout(); + +void BeginAlign(const char *id, float sizeX, float sizeY, float alignX = 0.0f, float alignY = 0.0f, float offsetX = 0, float offsetY = 0); +void AlignLayout(float alignX = 0.0f, float alignY = 0.0f, float offsetX = 0, float offsetY = 0); +void EndAlign(); +}; // namespace ImGuiEx + +namespace ImLayout +{ +static float WRAP_PARENT = 0; +static float MATCH_PARENT = -0.1f; +} // namespace ImLayout \ No newline at end of file diff --git a/imgui-lwjgl3/build.gradle b/imgui-lwjgl3/build.gradle new file mode 100644 index 0000000..ff98a83 --- /dev/null +++ b/imgui-lwjgl3/build.gradle @@ -0,0 +1,33 @@ +import org.gradle.internal.os.OperatingSystem + +plugins { + id 'java' +} + +sourceCompatibility = 1.8 + +ext { + lwjglVersion = '3.2.3' +} + +switch (OperatingSystem.current()) { + case OperatingSystem.LINUX: + project.ext.lwjglNatives = 'natives-linux' + break + case OperatingSystem.WINDOWS: + project.ext.lwjglNatives = System.getProperty('os.arch').contains('64') ? 'natives-windows' : 'natives-windows-x86' + break +} + +dependencies { + implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion") + + implementation 'org.lwjgl:lwjgl' + implementation 'org.lwjgl:lwjgl-glfw' + implementation 'org.lwjgl:lwjgl-opengl' + runtimeOnly "org.lwjgl:lwjgl::$lwjglNatives" + runtimeOnly "org.lwjgl:lwjgl-glfw::$lwjglNatives" + runtimeOnly "org.lwjgl:lwjgl-opengl::$lwjglNatives" + + implementation project(':imgui-binding') +} diff --git a/imgui-lwjgl3/src/main/java/InputHandler.java b/imgui-lwjgl3/src/main/java/InputHandler.java new file mode 100644 index 0000000..b6e8c76 --- /dev/null +++ b/imgui-lwjgl3/src/main/java/InputHandler.java @@ -0,0 +1,125 @@ +import org.lwjgl.glfw.GLFWKeyCallback; +import org.lwjgl.glfw.GLFWMouseButtonCallback; + +import static org.lwjgl.glfw.GLFW.*; + +public class InputHandler { + private static long window; + private static final int KEYBOARD_SIZE = 512; + private static final int MOUSE_SIZE = 16; + + private static int[] keyStates = new int[KEYBOARD_SIZE]; + private static boolean[] activeKeys = new boolean[KEYBOARD_SIZE]; + + private static int[] mouseButtonStates = new int[MOUSE_SIZE]; + private static boolean[] activeMouseButtons = new boolean[MOUSE_SIZE]; + private static long lastMouseNS = 0; + private static long mouseDoubleClickPeriodNS = 1000000000 / 5; //5th of a second for double click. + + private static int NO_STATE = -1; + + protected static GLFWKeyCallback keyboard = new GLFWKeyCallback() + { + @Override + public void invoke(long window, int key, int scancode, int action, int mods) + { + activeKeys[key] = action != GLFW_RELEASE; + keyStates[key] = action; + } + }; + + protected static GLFWMouseButtonCallback mouse = new GLFWMouseButtonCallback() + { + @Override + public void invoke(long window, int button, int action, int mods) + { + activeMouseButtons[button] = action != GLFW_RELEASE; + mouseButtonStates[button] = action; + } + }; + + protected static void init(long window) + { + InputHandler.window = window; + resetKeyboard(); + resetMouse(); + } + + protected static void update() + { + resetKeyboard(); + resetMouse(); + } + + private static void resetKeyboard() + { + for (int i = 0; i < keyStates.length; i++) + { + keyStates[i] = NO_STATE; + } + } + + private static void resetMouse() + { + for (int i = 0; i < mouseButtonStates.length; i++) + { + mouseButtonStates[i] = NO_STATE; + } + + long now = System.nanoTime(); + + if (now - lastMouseNS > mouseDoubleClickPeriodNS) + lastMouseNS = 0; + } + + public static boolean keyDown(int key) + { + return activeKeys[key]; + } + + public static boolean keyPressed(int key) + { + return keyStates[key] == GLFW_PRESS; + } + + public static boolean keyReleased(int key) + { + return keyStates[key] == GLFW_RELEASE; + } + + public static boolean mouseButtonDown(int button) + { + return activeMouseButtons[button]; + } + + public static boolean mouseButtonPressed(int button) + { + return mouseButtonStates[button] == GLFW_RELEASE; + } + + public static boolean mouseButtonReleased(int button) + { + boolean flag = mouseButtonStates[button] == GLFW_RELEASE; + + if (flag) + lastMouseNS = System.nanoTime(); + + return flag; + } + + public static boolean mouseButtonDoubleClicked(int button) + { + long last = lastMouseNS; + boolean flag = mouseButtonReleased(button); + + long now = System.nanoTime(); + + if (flag && now - last < mouseDoubleClickPeriodNS) + { + lastMouseNS = 0; + return true; + } + + return false; + } +} diff --git a/imgui-lwjgl3/src/main/java/Main.java b/imgui-lwjgl3/src/main/java/Main.java new file mode 100644 index 0000000..8b0142c --- /dev/null +++ b/imgui-lwjgl3/src/main/java/Main.java @@ -0,0 +1,156 @@ +import imgui.DrawData; +import imgui.ImGui; +import imgui.gl3.ImGuiImplGl3; +import org.lwjgl.BufferUtils; +import org.lwjgl.Version; +import org.lwjgl.glfw.GLFWErrorCallback; +import org.lwjgl.glfw.GLFWVidMode; +import org.lwjgl.opengl.GL; +import org.lwjgl.system.MemoryStack; + +import java.nio.DoubleBuffer; +import java.nio.IntBuffer; + +import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks; +import static org.lwjgl.glfw.GLFW.*; +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.system.MemoryStack.stackPush; +import static org.lwjgl.system.MemoryUtil.NULL; + +public class Main { + // The window handle + private long window; + private ImGuiImplGl3 imGuiGl = new ImGuiImplGl3(); + + public void run() { + System.out.println("Hello LWJGL " + Version.getVersion() + "!"); + + init(); + loop(); + + // Free the window callbacks and destroy the window + glfwFreeCallbacks(window); + glfwDestroyWindow(window); + + // Terminate GLFW and free the error callback + glfwTerminate(); + glfwSetErrorCallback(null).free(); + } + + private void init() { + // Setup an error callback. The default implementation + // will print the error message in System.err. + GLFWErrorCallback.createPrint(System.err).set(); + + // Initialize GLFW. Most GLFW functions will not work before doing this. + if (!glfwInit()) + throw new IllegalStateException("Unable to initialize GLFW"); + + // Configure GLFW + glfwDefaultWindowHints(); // optional, the current window hints are already the default + glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // the window will stay hidden after creation + glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // the window will be resizable + + // Create the window + window = glfwCreateWindow(1024, 768, "Hello World!", NULL, NULL); + if (window == NULL) + throw new RuntimeException("Failed to create the GLFW window"); + + // Setup a key callback. It will be called every time a key is pressed, repeated or released. + glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> { + if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) + glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop + }); + + glfwSetMouseButtonCallback(window, InputHandler.mouse); + + // Get the thread stack and push a new frame + try (MemoryStack stack = stackPush()) { + IntBuffer pWidth = stack.mallocInt(1); // int* + IntBuffer pHeight = stack.mallocInt(1); // int* + + // Get the window size passed to glfwCreateWindow + glfwGetWindowSize(window, pWidth, pHeight); + + // Get the resolution of the primary monitor + GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); + + // Center the window + glfwSetWindowPos( + window, + (vidmode.width() - pWidth.get(0)) / 2, + (vidmode.height() - pHeight.get(0)) / 2 + ); + } // the stack frame is popped automatically + + // Make the OpenGL context current + glfwMakeContextCurrent(window); + // Enable v-sync + glfwSwapInterval(1); + InputHandler.init(window); + // Make the window visible + glfwShowWindow(window); + } + + long lastFrame = System.nanoTime(); + + public float getDelta() { + long time = System.nanoTime(); + int delta_time = (int) ((time - lastFrame) / 1000000); + lastFrame = time; + return delta_time; + } + + private void loop() { + // This line is critical for LWJGL's interoperation with GLFW's + // OpenGL context, or any context that is managed externally. + // LWJGL detects the context that is current in the current thread, + // creates the GLCapabilities instance and makes the OpenGL + // bindings available for use. + GL.createCapabilities(); + + ImGui.init(); + imGuiGl.init(); + + // Set the clear color + glClearColor(.5f, 0.0f, 0f, 0.0f); + + int[] win_width = new int[1], win_height = new int[1]; + int[] width = new int[1], height = new int[1]; + DoubleBuffer xBuffer = BufferUtils.createDoubleBuffer(1); + DoubleBuffer yBuffer = BufferUtils.createDoubleBuffer(1); + + // Run the rendering loop until the user has attempted to close + // the window or has pressed the ESCAPE key. + while (!glfwWindowShouldClose(window)) { + xBuffer.clear(); + yBuffer.clear(); + + InputHandler.update(); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer + + glfwGetWindowSize(window, win_width, win_height); + glfwGetFramebufferSize(window, width, height); + glfwGetCursorPos(window, xBuffer, yBuffer); + + int mX = (int) xBuffer.get(); + int mY = (int) yBuffer.get(); + + ImGui.UpdateDisplayAndInputAndFrame(getDelta(), win_width[0], win_height[0], width[0], height[0], mX, mY, InputHandler.mouseButtonDown(0), false, false); + ImGui.ShowDemoWindow(); + ImGui.Render(); + imGuiGl.render(ImGui.GetDrawData()); + + glfwSwapBuffers(window); // swap the color buffers + + // Poll for window events. The key callback above will only be + // invoked during this call. + glfwPollEvents(); + } + } + + public static void main(String[] args) { + new Main().run(); + } +} diff --git a/imgui-lwjgl3/src/main/java/imgui/gl3/ImGuiImplGl3.java b/imgui-lwjgl3/src/main/java/imgui/gl3/ImGuiImplGl3.java new file mode 100644 index 0000000..730d7da --- /dev/null +++ b/imgui-lwjgl3/src/main/java/imgui/gl3/ImGuiImplGl3.java @@ -0,0 +1,341 @@ +package imgui.gl3; + +import imgui.DrawData; +import imgui.ImGui; +import imgui.TexDataRGBA32; + +import java.io.*; +import java.util.Objects; + +import static org.lwjgl.opengl.GL30.*; + +/** + * This class mostly a straightforward port of the https://raw.githubusercontent.com/ocornut/imgui/v1.74/examples/imgui_impl_opengl3.cpp adapted to Java and LWJGL realms. + *

+ * It do support a backup of the current GL state before rendering and restoring of its initial state after. + * But some specific state variables may be missed (all which are hidden under '#ifdef' macros in the original imgui file). + *

+ * By default this implementation uses shaders with 130 version of GLSL (OpenGL 3.0). + * You can provide your own shaders into the {@link ImGuiImplGl3#init(CharSequence, CharSequence)} method. + */ +public class ImGuiImplGl3 { + private int vBufferHandle = 0; + private int iBufferHandle = 0; + + private boolean isFontInitialized = false; + + // Shader stuff + private int programId = 0; + private int fragmentShaderId = 0; + private int vertexShaderId = 0; + + // Texture used by fonts + private int gFontTexture = 0; + + // Projection matrix for ImGui + private final float[] projMatrix = new float[4 * 4]; + + // Variables used to backup GL state before and after rendering of ImGui + private final int[] lastActiveTexture = new int[1]; + private final int[] lastProgram = new int[1]; + private final int[] lastTexture = new int[1]; + private final int[] lastArrayBuffer = new int[1]; + private final int[] lastViewport = new int[4]; + private final int[] lastScissorBox = new int[4]; + private final int[] lastBlendSrcRgb = new int[1]; + private final int[] lastBlendDstRgb = new int[1]; + private final int[] lastBlendSrcAlpha = new int[1]; + private final int[] lastBlendDstAlpha = new int[1]; + private final int[] lastBlendEquationRgb = new int[1]; + private final int[] lastBlendEquationAlpha = new int[1]; + private boolean lastEnableBlend = false; + private boolean lastEnableCullFace = false; + private boolean lastEnableDepthTest = false; + private boolean lastEnableScissorTest = false; + + /** + * This method SHOULD be called before calling of {@link ImGuiImplGl3#render(DrawData)} method. + * By using this method shaders with 130 version of GLSL will be used for render. + */ + public void init() { + final CharSequence fragShaderSource = readFromResources("default.frag"); + final CharSequence vertShaderSource = readFromResources("default.vert"); + prepareShader(fragShaderSource, vertShaderSource); + prepareFont(); + } + + /** + * This method SHOULD be called before calling of {@link ImGuiImplGl3#render(DrawData)} method. + * + * @param fragShaderSource fragment shader to use for render + * @param vertShaderSource vertex shader to use for render + */ + public void init(final CharSequence fragShaderSource, final CharSequence vertShaderSource) { + prepareShader(fragShaderSource, vertShaderSource); + prepareFont(); + } + + /** + * Method which renders {@link DrawData} from ImGui. + * + * @param drawData data used to draw ImGui interface to your current OpenGL context + */ + public void render(final DrawData drawData) { + if (drawData.cmdListsCount <= 0) { + return; + } + + // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) + int fbWidth = (int) (drawData.displaySizeX * drawData.framebufferScaleX); + int fbHeight = (int) (drawData.displaySizeY * drawData.framebufferScaleY); + + if (fbWidth <= 0 || fbHeight <= 0) { + return; + } + + if (!isFontInitialized) { + isFontInitialized = true; + vBufferHandle = glGenBuffers(); + iBufferHandle = glGenBuffers(); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iBufferHandle); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, drawData.iByteBuffer.capacity(), GL_STATIC_DRAW); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + } + + backupGlState(); + bind(drawData); + + int verticesOffset = 0; + int indexOffset = 0; + + for (int i = 0; i < drawData.cmdListsCount; i++) { + drawData.vByteBuffer.limit(verticesOffset + 4); + final int verticesSize = (int) drawData.vByteBuffer.getFloat(verticesOffset); + + drawData.iByteBuffer.limit(indexOffset + 2); + final short indexSize = drawData.iByteBuffer.getShort(indexOffset); + final int cmdSize = (int) drawData.cmdByteBuffer.getFloat(); + + final int verticesStartOffset = verticesOffset + 4; + final int indexStartOffset = indexOffset + 2; + + drawData.vByteBuffer.position(verticesStartOffset); + drawData.iByteBuffer.position(indexStartOffset); + + final int newVlimit = verticesStartOffset + verticesSize * DrawData.vBufferSize; + final int newIlimit = indexStartOffset + indexSize * DrawData.iBufferSize; + + drawData.vByteBuffer.limit(newVlimit); + drawData.iByteBuffer.limit(newIlimit); + + glBufferData(GL_ARRAY_BUFFER, drawData.vByteBuffer, GL_STATIC_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, drawData.iByteBuffer, GL_STATIC_DRAW); + + verticesOffset += ((verticesSize) * DrawData.vBufferSize) + 4; + indexOffset += ((indexSize) * DrawData.iBufferSize) + 2; + + final float clipOffX = drawData.displayPosX; // (0,0) unless using multi-viewports + final float clipOffY = drawData.displayPosY; + final float clipScaleX = drawData.framebufferScaleX; // (1,1) unless using retina display which are often (2,2) + final float clipScaleY = drawData.framebufferScaleY; + + int idxBufferOffset = 0; + + for (int j = 0; j < cmdSize; j++) { + final int elemCount = (int) drawData.cmdByteBuffer.getFloat(); + float clipRectX = drawData.cmdByteBuffer.getFloat(); + float clipRectY = drawData.cmdByteBuffer.getFloat(); + float clipRectZ = drawData.cmdByteBuffer.getFloat(); + float clipRectW = drawData.cmdByteBuffer.getFloat(); + final int textureID = (int) drawData.cmdByteBuffer.getFloat(); + + clipRectX = (clipRectX - clipOffX) * clipScaleX; + clipRectY = (clipRectY - clipOffY) * clipScaleY; + clipRectZ = (clipRectZ - clipOffX) * clipScaleX; + clipRectW = (clipRectW - clipOffY) * clipScaleY; + + if (clipRectX < fbWidth && clipRectY < fbHeight && clipRectZ >= 0.0f && clipRectW >= 0.0f) { + glScissor((int) clipRectX, (int) (fbHeight - clipRectW), (int) (clipRectZ - clipRectX), (int) (clipRectW - clipRectY)); + glBindTexture(GL_TEXTURE_2D, textureID); + glDrawElements(GL_TRIANGLES, elemCount, GL_UNSIGNED_SHORT, idxBufferOffset); + } + + idxBufferOffset += elemCount * 2; + } + } + + unbind(); + restoreModifiedGlState(); + } + + /** + * Call this method in the end of your app working state to clear used resources. + */ + public void dispose() { + glDeleteTextures(gFontTexture); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glDeleteBuffers(iBufferHandle); + glDeleteBuffers(vBufferHandle); + glDetachShader(programId, vertexShaderId); + glDetachShader(programId, fragmentShaderId); + glDeleteProgram(programId); + } + + private void prepareShader(final CharSequence fragShaderSource, final CharSequence vertShaderSource) { + fragmentShaderId = loadAndCompileShader(GL_FRAGMENT_SHADER, fragShaderSource); + vertexShaderId = loadAndCompileShader(GL_VERTEX_SHADER, vertShaderSource); + + programId = glCreateProgram(); + glAttachShader(programId, fragmentShaderId); + glAttachShader(programId, vertexShaderId); + glLinkProgram(programId); + + if (glGetProgrami(programId, GL_LINK_STATUS) != GL_TRUE) { + throw new IllegalStateException(glGetProgramInfoLog(programId)); + } + } + + private void prepareFont() { + TexDataRGBA32 texData = new TexDataRGBA32(); + ImGui.GetTexDataAsRGBA32(texData, texData.pixelBuffer); + + gFontTexture = glGenTextures(); + + glBindTexture(GL_TEXTURE_2D, gFontTexture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texData.width, texData.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData.pixelBuffer); + + ImGui.SetFontTexID(gFontTexture); + } + + private void backupGlState() { + glGetIntegerv(GL_ACTIVE_TEXTURE, lastActiveTexture); + glGetIntegerv(GL_CURRENT_PROGRAM, lastProgram); + glGetIntegerv(GL_TEXTURE_BINDING_2D, lastTexture); + // int[] last_sampler; glGetIntegerv(GL_SAMPLER_BINDING, &last_sampler); // do it by yourself if needed + glGetIntegerv(GL_ARRAY_BUFFER_BINDING, lastArrayBuffer); + // int[] last_vertex_array_object; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array_object); // do it by yourself if needed + // int[] last_polygon_mode; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode); // do it by yourself if needed + glGetIntegerv(GL_VIEWPORT, lastViewport); + glGetIntegerv(GL_SCISSOR_BOX, lastScissorBox); + glGetIntegerv(GL_BLEND_SRC_RGB, lastBlendSrcRgb); + glGetIntegerv(GL_BLEND_DST_RGB, lastBlendDstRgb); + glGetIntegerv(GL_BLEND_SRC_ALPHA, lastBlendSrcAlpha); + glGetIntegerv(GL_BLEND_DST_ALPHA, lastBlendDstAlpha); + glGetIntegerv(GL_BLEND_EQUATION_RGB, lastBlendEquationRgb); + glGetIntegerv(GL_BLEND_EQUATION_ALPHA, lastBlendEquationAlpha); + lastEnableBlend = glIsEnabled(GL_BLEND); + lastEnableCullFace = glIsEnabled(GL_CULL_FACE); + lastEnableDepthTest = glIsEnabled(GL_DEPTH_TEST); + lastEnableScissorTest = glIsEnabled(GL_SCISSOR_TEST); + } + + private void restoreModifiedGlState() { + glUseProgram(lastProgram[0]); + glBindTexture(GL_TEXTURE_2D, lastTexture[0]); + glActiveTexture(lastActiveTexture[0]); + glBindBuffer(GL_ARRAY_BUFFER, lastArrayBuffer[0]); + glBlendEquationSeparate(lastBlendEquationRgb[0], lastBlendEquationAlpha[0]); + glBlendFuncSeparate(lastBlendSrcRgb[0], lastBlendDstRgb[0], lastBlendSrcAlpha[0], lastBlendDstAlpha[0]); + // @formatter:off + if (lastEnableBlend) glEnable(GL_BLEND); else glDisable(GL_BLEND); + if (lastEnableCullFace) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE); + if (lastEnableDepthTest) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); + if (lastEnableScissorTest) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST); + // @formatter:on + glViewport(lastViewport[0], lastViewport[1], lastViewport[2], lastViewport[3]); + glScissor(lastScissorBox[0], lastScissorBox[1], lastScissorBox[2], lastScissorBox[3]); + } + + private void bind(final DrawData drawData) { + glViewport(0, 0, (int) drawData.displaySizeX, (int) drawData.displaySizeY); + glActiveTexture(GL_TEXTURE0); + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glEnable(GL_SCISSOR_TEST); + + final float L = drawData.displayPosX; + final float R = drawData.displayPosX + drawData.displaySizeX; + final float T = drawData.displayPosY; + final float B = drawData.displayPosY + drawData.displaySizeY; + + // Orthographic matrix projection + projMatrix[0] = 2.0f / (R - L); + projMatrix[5] = 2.0f / (T - B); + projMatrix[10] = -1.0f; + projMatrix[12] = (R + L) / (L - R); + projMatrix[13] = (T + B) / (B - T); + projMatrix[15] = 1.0f; + + // Bind vertices + glBindBuffer(GL_ARRAY_BUFFER, vBufferHandle); + + int location = glGetAttribLocation(programId, "Position"); + glEnableVertexAttribArray(location); + glVertexAttribPointer(location, 2, GL_FLOAT, false, 20, 0); + + location = glGetAttribLocation(programId, "UV"); + glEnableVertexAttribArray(location); + glVertexAttribPointer(location, 2, GL_FLOAT, false, 20, 8); + + location = glGetAttribLocation(programId, "Color"); + glEnableVertexAttribArray(location); + glVertexAttribPointer(location, 4, GL_UNSIGNED_BYTE, true, 20, 16); + + //Bind index + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iBufferHandle); + + // Bind shader + glUseProgram(programId); + glUniformMatrix4fv(glGetUniformLocation(programId, "ProjMtx"), false, projMatrix); + glUniform1i(glGetUniformLocation(programId, "Texture"), 0); + } + + private void unbind() { + // Unbind vertices + glBindBuffer(GL_ARRAY_BUFFER, 0); + + glDisableVertexAttribArray(glGetAttribLocation(programId, "Position")); + glDisableVertexAttribArray(glGetAttribLocation(programId, "UV")); + glDisableVertexAttribArray(glGetAttribLocation(programId, "Color")); + + // Unbind index + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glFlush(); + + // Unbind shader + glUseProgram(0); + } + + private int loadAndCompileShader(final int type, final CharSequence source) { + int id = glCreateShader(type); + glShaderSource(id, source); + glCompileShader(id); + if (glGetShaderi(id, GL_COMPILE_STATUS) != GL_TRUE) { + throw new IllegalStateException(glGetShaderInfoLog(id)); + } + return id; + } + + private CharSequence readFromResources(final String path) { + StringBuilder builder = new StringBuilder(); + + try (InputStream in = getClass().getClassLoader().getResourceAsStream(path); + BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(in)))) { + String line; + while ((line = reader.readLine()) != null) { + builder.append(line).append('\n'); + } + } catch (IOException ex) { + throw new UncheckedIOException("Failed to read from resources!", ex); + } + + return builder.toString(); + } +} diff --git a/imgui-lwjgl3/src/main/resources/default.frag b/imgui-lwjgl3/src/main/resources/default.frag new file mode 100644 index 0000000..a0da87a --- /dev/null +++ b/imgui-lwjgl3/src/main/resources/default.frag @@ -0,0 +1,14 @@ +#version 130 + +#ifdef GL_ES +precision mediump float; +#endif + +uniform sampler2D Texture; +in vec2 Frag_UV; +in vec4 Frag_Color; + +void main() +{ + gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st); +} diff --git a/imgui-lwjgl3/src/main/resources/default.vert b/imgui-lwjgl3/src/main/resources/default.vert new file mode 100644 index 0000000..7d7b8a8 --- /dev/null +++ b/imgui-lwjgl3/src/main/resources/default.vert @@ -0,0 +1,15 @@ +#version 130 + +uniform mat4 ProjMtx; +in vec2 Position; +in vec2 UV; +in vec4 Color; +out vec2 Frag_UV; +out vec4 Frag_Color; + +void main() +{ + Frag_UV = UV; + Frag_Color = Color; + gl_Position = ProjMtx * vec4(Position.xy, 0, 1); +} diff --git a/libs/imgui-java.dll b/libs/imgui-java.dll new file mode 100644 index 0000000..e2efa05 Binary files /dev/null and b/libs/imgui-java.dll differ diff --git a/settings.gradle b/settings.gradle index d992339..d000615 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,4 @@ rootProject.name = 'imgui-java' +include 'imgui-binding' +include 'imgui-lwjgl3'