From 08bf84ad64b5ea3bbf29483de589032f8490d8d3 Mon Sep 17 00:00:00 2001 From: SpaiR Date: Sat, 20 Feb 2021 11:16:44 +0200 Subject: [PATCH] [API] Dear ImGui v1.81 --- .../groovy/imgui/generate/GenerateLibs.groovy | 31 ++- .../src/main/java/imgui/ImFontConfig.java | 18 +- .../src/main/java/imgui/ImFontGlyph.java | 42 ++-- imgui-binding/src/main/java/imgui/ImGui.java | 182 ++++++++++-------- .../src/main/java/imgui/ImGuiFreeType.java | 74 ------- .../src/main/java/imgui/ImGuiPlatformIO.java | 13 -- .../src/main/java/imgui/ImGuiViewport.java | 102 +++++----- .../imgui/flag/ImGuiFreeTypeBuilderFlags.java | 45 +++++ .../java/imgui/flag/ImGuiViewportFlags.java | 42 ++-- imgui-binding/src/main/native/imconfig.h | 108 ----------- 10 files changed, 270 insertions(+), 387 deletions(-) delete mode 100644 imgui-binding/src/main/java/imgui/ImGuiFreeType.java create mode 100644 imgui-binding/src/main/java/imgui/flag/ImGuiFreeTypeBuilderFlags.java delete mode 100644 imgui-binding/src/main/native/imconfig.h diff --git a/buildSrc/src/main/groovy/imgui/generate/GenerateLibs.groovy b/buildSrc/src/main/groovy/imgui/generate/GenerateLibs.groovy index d8b9b39..d692909 100644 --- a/buildSrc/src/main/groovy/imgui/generate/GenerateLibs.groovy +++ b/buildSrc/src/main/groovy/imgui/generate/GenerateLibs.groovy @@ -18,7 +18,7 @@ class GenerateLibs extends DefaultTask { private final boolean forMac64 = buildEnvs?.contains('mac64') private final boolean isLocal = System.properties.containsKey("local") - private final boolean withFreeType = System.properties.containsKey("withFreeType") + private final boolean withFreeType = System.properties.containsKey("freetype") private final String sourceDir = project.file('src/main/java') private final String classpath = project.file('build/classes/java/main') @@ -42,16 +42,17 @@ class GenerateLibs extends DefaultTask { ['include/imgui', 'include/imnodes', 'include/imgui-node-editor'].each { spec.from(project.rootProject.file(it)) { CopySpec s -> s.include('*.h', '*.cpp', '*.inl') } } - - if (withFreeType) { - spec.from(project.rootProject.file('include/imgui/misc/freetype')) { CopySpec it -> it.include('*.h', '*.cpp') } - } - + spec.from(project.rootProject.file('imgui-binding/src/main/native')) spec.into(jniDir) } - project.copy {CopySpec spec -> - spec.from(project.rootProject.file('imgui-binding/src/main/native')).into(jniDir) + if (withFreeType) { + project.copy { CopySpec spec -> + spec.from(project.rootProject.file('include/imgui/misc/freetype')) { CopySpec it -> it.include('*.h', '*.cpp') } + spec.into("$jniDir/misc/freetype") + } + + enableDefine('IMGUI_ENABLE_FREETYPE') } // Generate platform dependant ant configs and header files @@ -104,8 +105,8 @@ class GenerateLibs extends DefaultTask { def minMacOsVersion = '10.15' def mac64 = BuildTarget.newDefaultTarget(BuildTarget.TargetOs.MacOsX, true) mac64.cppFlags += ' -std=c++14 -stdlib=libc++' - mac64.cppFlags = mac64.cppFlags.replace('10.5', minMacOsVersion).replace('10.7', minMacOsVersion) - mac64.linkerFlags = mac64.linkerFlags.replace('10.5', minMacOsVersion).replace('10.7', minMacOsVersion) + mac64.cppFlags = mac64.cppFlags.replace('10.7', minMacOsVersion) + mac64.linkerFlags = mac64.linkerFlags.replace('10.7', minMacOsVersion) if (withFreeType) { mac64.cppFlags += ' -I/usr/local/include/freetype2 -I/usr/local/include/libpng16 -I/usr/local/include/harfbuzz -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include' @@ -117,12 +118,6 @@ class GenerateLibs extends DefaultTask { new AntScriptGenerator().generate(buildConfig, buildTargets) - if (!withFreeType) { - project.delete { - it.delete("$jniDir/imgui_ImGuiFreeType.cpp", "$jniDir/imgui_ImGuiFreeType.h") - } - } - // Generate native libraries // Comment/uncomment lines with OS you need. @@ -139,4 +134,8 @@ class GenerateLibs extends DefaultTask { BuildExecutor.executeAnt(jniDir + '/build.xml', '-v', 'pack-natives') } + + void enableDefine(String define) { + project.file("$jniDir/imconfig.h").text += "#define $define" + } } diff --git a/imgui-binding/src/main/java/imgui/ImFontConfig.java b/imgui-binding/src/main/java/imgui/ImFontConfig.java index 58e65e5..4bef54a 100644 --- a/imgui-binding/src/main/java/imgui/ImFontConfig.java +++ b/imgui-binding/src/main/java/imgui/ImFontConfig.java @@ -116,6 +116,7 @@ public final class ImFontConfig extends ImGuiStructDestroyable { /** * Rasterize at higher quality for sub-pixel positioning. + * Note the difference between 2 and 3 is minimal so you can reduce this to 2 to save memory. * Read https://github.com/nothings/stb/blob/master/tests/oversample/README.md for details. */ public native int getOversampleH(); /* @@ -124,6 +125,7 @@ public final class ImFontConfig extends ImGuiStructDestroyable { /** * Rasterize at higher quality for sub-pixel positioning. + * Note the difference between 2 and 3 is minimal so you can reduce this to 2 to save memory. * Read https://github.com/nothings/stb/blob/master/tests/oversample/README.md for details. */ public native void setOversampleH(int oversampleH); /* @@ -132,7 +134,7 @@ public final class ImFontConfig extends ImGuiStructDestroyable { /** * Rasterize at higher quality for sub-pixel positioning. - * We don't use sub-pixel positions on the Y axis. + * This is not really useful as we don't use sub-pixel positions on the Y axis. */ public native int getOversampleV(); /* return IM_FONT_CONFIG->OversampleV; @@ -140,7 +142,7 @@ public final class ImFontConfig extends ImGuiStructDestroyable { /** * Rasterize at higher quality for sub-pixel positioning. - * We don't use sub-pixel positions on the Y axis. + * This is not really useful as we don't use sub-pixel positions on the Y axis. */ public native void setOversampleV(int oversampleV); /* IM_FONT_CONFIG->OversampleV = oversampleV; @@ -286,17 +288,17 @@ public final class ImFontConfig extends ImGuiStructDestroyable { */ /** - * Settings for custom font rasterizer (e.g. ImGuiFreeType). Leave as zero if you aren't using one. + * Settings for custom font builder. THIS IS BUILDER IMPLEMENTATION DEPENDENT. Leave as zero if unsure. */ - public native int getRasterizerFlags(); /* - return IM_FONT_CONFIG->RasterizerFlags; + public native int getFontBuilderFlags(); /* + return IM_FONT_CONFIG->FontBuilderFlags; */ /** - * Settings for custom font rasterizer (e.g. ImGuiFreeType). Leave as zero if you aren't using one. + * Settings for custom font builder. THIS IS BUILDER IMPLEMENTATION DEPENDENT. Leave as zero if unsure. */ - public native void setRasterizerFlags(int rasterizerFlags); /* - IM_FONT_CONFIG->RasterizerFlags = (unsigned int)rasterizerFlags; + public native void setFontBuilderFlags(int fontBuilderFlags); /* + IM_FONT_CONFIG->FontBuilderFlags = (unsigned int)fontBuilderFlags; */ /** diff --git a/imgui-binding/src/main/java/imgui/ImFontGlyph.java b/imgui-binding/src/main/java/imgui/ImFontGlyph.java index b501015..bbb3a06 100644 --- a/imgui-binding/src/main/java/imgui/ImFontGlyph.java +++ b/imgui-binding/src/main/java/imgui/ImFontGlyph.java @@ -31,6 +31,34 @@ public final class ImFontGlyph extends ImGuiStructDestroyable { return (intptr_t)(new ImFontGlyph()); */ + /** + * Flag to indicate glyph is colored and should generally ignore tinting (make it usable with no shift on little-endian as this is used in loops). + */ + public native int getColored(); /* + return (unsigned int)IM_FONT_GLYPH->Colored; + */ + + /** + * Flag to indicate glyph is colored and should generally ignore tinting (make it usable with no shift on little-endian as this is used in loops). + */ + public native void setColored(int colored); /* + IM_FONT_GLYPH->Colored = (unsigned int)colored; + */ + + /** + * Flag to indicate glyph has no visible pixels (e.g. space). Allow early out when rendering. + */ + public native int getVisible(); /* + return (unsigned int)IM_FONT_GLYPH->Visible; + */ + + /** + * Flag to indicate glyph has no visible pixels (e.g. space). Allow early out when rendering. + */ + public native void setVisible(int visible); /* + IM_FONT_GLYPH->Visible = (unsigned int)visible; + */ + /** * 0x0000..0xFFFF */ @@ -45,20 +73,6 @@ public final class ImFontGlyph extends ImGuiStructDestroyable { IM_FONT_GLYPH->Codepoint = (unsigned int)codepoint; */ - /** - * Flag to allow early out when rendering - */ - public native int getVisible(); /* - return (unsigned int)IM_FONT_GLYPH->Visible; - */ - - /** - * Flag to allow early out when rendering - */ - public native void setVisible(int visible); /* - IM_FONT_GLYPH->Visible = (unsigned int)visible; - */ - /** * Distance to next character (= data from font + ImFontConfig::GlyphExtraSpacing.x baked in) */ diff --git a/imgui-binding/src/main/java/imgui/ImGui.java b/imgui-binding/src/main/java/imgui/ImGui.java index 88f8220..1fa368a 100644 --- a/imgui-binding/src/main/java/imgui/ImGui.java +++ b/imgui-binding/src/main/java/imgui/ImGui.java @@ -496,18 +496,6 @@ public class ImGui { return ImGui::GetWindowDpiScale(); */ - /** - * Get viewport currently associated to the current window. - */ - public static ImGuiViewport getWindowViewport() { - WINDOW_VIEWPORT.ptr = nGetWindowViewport(); - return WINDOW_VIEWPORT; - } - - private static native long nGetWindowViewport(); /* - return (intptr_t)ImGui::GetWindowViewport(); - */ - /** * Get current window position in screen space (useful if you want to do your own drawing via the DrawList API) */ @@ -564,6 +552,18 @@ public class ImGui { return ImGui::GetWindowHeight(); */ + /** + * Get viewport currently associated to the current window. + */ + public static ImGuiViewport getWindowViewport() { + WINDOW_VIEWPORT.ptr = nGetWindowViewport(); + return WINDOW_VIEWPORT; + } + + private static native long nGetWindowViewport(); /* + return (intptr_t)ImGui::GetWindowViewport(); + */ + // Prefer using SetNextXXX functions (before Begin) rather that SetXXX functions (after Begin). /** @@ -1043,7 +1043,7 @@ public class ImGui { /** * Push width of items for common large "item+label" widgets. {@code > 0.0f}: width in pixels, - * {@code <0.0f} align xx pixels to the right of window (so -1.0f always align width to the right side). 0.0f = default to ~2/3 of windows width, + * {@code <0.0f} align xx pixels to the right of window (so -1.0f always align width to the right side). */ public static native void pushItemWidth(float itemWidth); /* ImGui::PushItemWidth(itemWidth); @@ -1338,30 +1338,35 @@ public class ImGui { */ /** - * Cursor position in absolute screen coordinates [0..io.DisplaySize] (useful to work with ImDrawList API) + * Cursor position in absolute coordinates (useful to work with ImDrawList API). + * Generally top-left == GetMainViewport().Pos == (0,0) in single viewport mode, + * and bottom-right == GetMainViewport().Pos+Size == io.DisplaySize in single-viewport mode. */ public static native void getCursorScreenPos(ImVec2 dstImVec2); /* Jni::ImVec2Cpy(env, ImGui::GetCursorScreenPos(), dstImVec2); */ /** - * Cursor position in absolute screen coordinates [0..io.DisplaySize] (useful to work with ImDrawList API) + * Cursor position in absolute coordinates (useful to work with ImDrawList API). + * Generally top-left == GetMainViewport().Pos == (0,0) in single viewport mode, + * and bottom-right == GetMainViewport().Pos+Size == io.DisplaySize in single-viewport mode. */ public static native float getCursorScreenPosX(); /* return ImGui::GetCursorScreenPos().x; */ /** - * Cursor position in absolute screen coordinates [0..io.DisplaySize] (useful to work with ImDrawList API) + * Cursor position in absolute coordinates (useful to work with ImDrawList API). + * Generally top-left == GetMainViewport().Pos == (0,0) in single viewport mode, + * and bottom-right == GetMainViewport().Pos+Size == io.DisplaySize in single-viewport mode. */ public static native float getCursorScreenPosY(); /* return ImGui::GetCursorScreenPos().y; */ /** - * Cursor position in absolute screen coordinates [0..io.DisplaySize] - */ - public static native void setCursorScreenPos(float x, float y); /* + * Cursor position in absolute coordinates. + */ public static native void setCursorScreenPos(float x, float y); /* ImGui::SetCursorScreenPos(ImVec2(x, y)); */ @@ -1720,22 +1725,31 @@ public class ImGui { ImGui::EndCombo(); */ - public static boolean combo(String label, ImInt currentItem, String[] items, int itemsCount) { - return nCombo(label, currentItem.getData(), items, itemsCount, -1); + public static boolean combo(String label, ImInt currentItem, String[] items) { + return nCombo(label, currentItem.getData(), items, items.length, -1); } - public static boolean combo(String label, ImInt currentItem, String[] items, int itemsCount, int popupMaxHeightInItems) { - return nCombo(label, currentItem.getData(), items, itemsCount, popupMaxHeightInItems); + public static boolean combo(String label, ImInt currentItem, String[] items, int popupMaxHeightInItems) { + return nCombo(label, currentItem.getData(), items, items.length, popupMaxHeightInItems); } private static native boolean nCombo(String label, int[] currentItem, String[] items, int itemsCount, int popupMaxHeightInItems); /* - const char* listbox_items[itemsCount]; - for(int i = 0; i < itemsCount; i++) { + const char* listboxItems[itemsCount]; + + for (int i = 0; i < itemsCount; i++) { jstring string = (jstring)env->GetObjectArrayElement(items, i); - const char* rawString = env->GetStringUTFChars(string, 0); - listbox_items[i] = rawString; + const char* rawString = env->GetStringUTFChars(string, JNI_FALSE); + listboxItems[i] = rawString; } - return ImGui::Combo(label, ¤tItem[0], listbox_items, itemsCount, popupMaxHeightInItems); + + bool flag = ImGui::Combo(label, ¤tItem[0], listboxItems, itemsCount, popupMaxHeightInItems); + + for (int i = 0; i< itemsCount; i++) { + jstring string = (jstring)env->GetObjectArrayElement(items, i); + env->ReleaseStringUTFChars(string, listboxItems[i]); + } + + return flag; */ /** @@ -3690,59 +3704,62 @@ public class ImGui { */ // Widgets: List Boxes + // - This is essentially a thin wrapper to using BeginChild/EndChild with some stylistic changes. + // - The BeginListBox()/EndListBox() api allows you to manage your contents and selection state however you want it, by creating e.g. Selectable() or any items. + // - The simplified/old ListBox() api are helpers over BeginListBox()/EndListBox() which are kept available for convenience purpose. This is analoguous to how Combos are created. + // - Choose frame width: size.x > 0.0f: custom / size.x < 0.0f or -FLT_MIN: right-align / size.x = 0.0f (default): use current ItemWidth + // - Choose frame height: size.y > 0.0f: custom / size.y < 0.0f or -FLT_MIN: bottom-align / size.y = 0.0f (default): arbitrary default height which can fit ~7 items - public static void listBox(String label, ImInt currentItem, String[] items, int itemsCount) { - nListBox(label, currentItem.getData(), items, itemsCount, -1); + /** + * Open a framed scrolling region. + */ + public static native boolean beginListBox(String label); /* + return ImGui::BeginListBox(label); + */ + + /** + * Open a framed scrolling region. + */ + public static native boolean beginListBox(String label, float sizeX, float sizeY); /* + return ImGui::BeginListBox(label, ImVec2(sizeX, sizeY)); + */ + + /** + * Only call EndListBox() if BeginListBox() returned true! + */ + public static native void endListBox(); /* + ImGui::EndListBox(); + */ + + public static void listBox(String label, ImInt currentItem, String[] items) { + nListBox(label, currentItem.getData(), items, items.length, -1); } - public static void listBox(String label, ImInt currentItem, String[] items, int itemsCount, int heightInItems) { - nListBox(label, currentItem.getData(), items, itemsCount, heightInItems); + public static void listBox(String label, ImInt currentItem, String[] items, int heightInItems) { + nListBox(label, currentItem.getData(), items, items.length, heightInItems); } private static native boolean nListBox(String label, int[] currentItem, String[] items, int itemsCount, int heightInItems); /* - const char* listbox_items[itemsCount]; + const char* listboxItems[itemsCount]; - for(int i = 0; i < itemsCount; i++) { + for (int i = 0; i < itemsCount; i++) { jstring string = (jstring)env->GetObjectArrayElement(items, i); - const char *rawString = env->GetStringUTFChars(string, 0); - listbox_items[i] = rawString; + const char* rawString = env->GetStringUTFChars(string, JNI_FALSE); + listboxItems[i] = rawString; } - return ImGui::ListBox(label, ¤tItem[0], listbox_items, itemsCount, heightInItems); - */ + bool flag = ImGui::ListBox(label, ¤tItem[0], listboxItems, itemsCount, heightInItems); - /** - * Use if you want to reimplement ListBox() will custom data or interactions. - * If the function return true, you can output elements then call ListBoxFooter() afterwards. - */ - public static native boolean listBoxHeader(String label); /* - return ImGui::ListBoxHeader(label); - */ + for (int i = 0; i< itemsCount; i++) { + jstring string = (jstring)env->GetObjectArrayElement(items, i); + env->ReleaseStringUTFChars(string, listboxItems[i]); + } - /** - * Use if you want to reimplement ListBox() will custom data or interactions. - * If the function return true, you can output elements then call ListBoxFooter() afterwards. - */ - public static native boolean listBoxHeader(String label, float sizeX, float sizeY); /* - return ImGui::ListBoxHeader(label, ImVec2(sizeX, sizeY)); - */ - - public static native boolean listBoxHeader(String label, int itemsCount); /* - return ImGui::ListBoxHeader(label, itemsCount); - */ - - public static native boolean listBoxHeader(String label, int itemsCount, int heightInItems); /* - return ImGui::ListBoxHeader(label, itemsCount, heightInItems); - */ - - /** - * Terminate the scrolling region. Only call ListBoxFooter() if ListBoxHeader() returned true! - */ - public static native void listBoxFooter(); /* - ImGui::ListBoxFooter(); + return flag; */ // Widgets: Data Plotting + // - Consider using ImPlot (https://github.com/epezent/implot) public static native void plotLines(String label, float[] values, int valuesCount); /* ImGui::PlotLines(label, &values[0], valuesCount); @@ -5095,6 +5112,25 @@ public class ImGui { ImGui::SetItemAllowOverlap(); */ + // Viewports + // - Currently represents the Platform Window created by the application which is hosting our Dear ImGui windows. + // - In 'docking' branch with multi-viewport enabled, we extend this concept to have multiple active viewports. + // - In the future we will extend this concept further to also represent Platform Monitor and support a "no main platform window" operation mode. + + /** + * Return primary/default viewport. + */ + public static ImGuiViewport getMainViewport() { + if (mainViewport == null) { + mainViewport = new ImGuiViewport(nGetMainViewport()); + } + return mainViewport; + } + + private static native long nGetMainViewport(); /* + return (intptr_t)ImGui::GetMainViewport(); + */ + // Miscellaneous Utilities /** @@ -5656,20 +5692,6 @@ public class ImGui { return (intptr_t)&ImGui::GetPlatformIO(); */ - /** - * Main viewport. Same as GetPlatformIO().MainViewport == GetPlatformIO().Viewports[0]. - */ - public static ImGuiViewport getMainViewport() { - if (mainViewport == null) { - mainViewport = new ImGuiViewport(nGetMainViewport()); - } - return mainViewport; - } - - private static native long nGetMainViewport(); /* - return (intptr_t)ImGui::GetMainViewport(); - */ - /** * Call in main loop. Will call CreateWindow/ResizeWindow/etc. Platform functions for each secondary viewport, and DestroyWindow for each inactive viewport. */ diff --git a/imgui-binding/src/main/java/imgui/ImGuiFreeType.java b/imgui-binding/src/main/java/imgui/ImGuiFreeType.java deleted file mode 100644 index 89617a8..0000000 --- a/imgui-binding/src/main/java/imgui/ImGuiFreeType.java +++ /dev/null @@ -1,74 +0,0 @@ -package imgui; - -/** - * Read: https://raw.githubusercontent.com/ocornut/imgui/v1.76/misc/freetype/README.md - */ -public final class ImGuiFreeType { - private ImGuiFreeType() { - } - - /*JNI - #include - #include - */ - - public static void buildFontAtlas(final ImFontAtlas atlas) { - nBuildFontAtlas(atlas.ptr, 0); - } - - public static void buildFontAtlas(final ImFontAtlas atlas, final int extraFlags) { - nBuildFontAtlas(atlas.ptr, extraFlags); - } - - private static native void nBuildFontAtlas(long atlasPtr, int extraFlags); /* - ImGuiFreeType::BuildFontAtlas((ImFontAtlas*)atlasPtr, (unsigned int)extraFlags); - */ - - /** - * Hinting greatly impacts visuals (and glyph sizes). - * When disabled, FreeType generates blurrier glyphs, more or less matches the stb's output. - * The Default hinting mode usually looks good, but may distort glyphs in an unusual way. - * The Light hinting mode generates fuzzier glyphs but better matches Microsoft's rasterizer. - *

- * You can set those flags on a per font basis in ImFontConfig::RasterizerFlags. - * Use the 'extra_flags' parameter of BuildFontAtlas() to force a flag on all your fonts. - */ - public static final class RasterizerFlags { - /** - * By default, hinting is enabled and the font's native hinter is preferred over the auto-hinter. - * Disable hinting. This generally generates 'blurrier' bitmap glyphs when the glyph are rendered in any of the anti-aliased modes. - */ - public static final int NoHinting = 1; - /** - * Disable auto-hinter. - */ - public static final int NoAutoHint = 1 << 1; - /** - * Indicates that the auto-hinter is preferred over the font's native hinter. - */ - public static final int ForceAutoHint = 1 << 2; - /** - * A lighter hinting algorithm for gray-level modes. Many generated glyphs are fuzzier but better resemble their original shape. - * This is achieved by snapping glyphs to the pixel grid only vertically (Y-axis), - * as is done by Microsoft's ClearType and Adobe's proprietary font renderer. - * This preserves inter-glyph spacing in horizontal text. - */ - public static final int LightHinting = 1 << 3; - /** - * Strong hinting algorithm that should only be used for monochrome output. - */ - public static final int MonoHinting = 1 << 4; - /** - * Styling: Should we artificially embolden the font? - */ - public static final int Bold = 1 << 5; - /** - * Styling: Should we slant the font, emulating italic style? - */ - public static final int Oblique = 1 << 6; - /** - * Disable anti-aliasing. Combine this with MonoHinting for best results! - */ - public static final int Monochrome = 1 << 7; - } -} diff --git a/imgui-binding/src/main/java/imgui/ImGuiPlatformIO.java b/imgui-binding/src/main/java/imgui/ImGuiPlatformIO.java index dd7ab65..2cbc4ec 100644 --- a/imgui-binding/src/main/java/imgui/ImGuiPlatformIO.java +++ b/imgui-binding/src/main/java/imgui/ImGuiPlatformIO.java @@ -70,7 +70,6 @@ import imgui.callback.ImPlatformFuncViewportSuppImVec2; * Platform functions are typically called before their Renderer counterpart, apart from Destroy which are called the other way. */ public final class ImGuiPlatformIO extends ImGuiStruct { - private static final ImGuiViewport MAIN_VIEWPORT = new ImGuiViewport(0); private static final ImGuiViewport TMP_VIEWPORT = new ImGuiViewport(0); private static final ImGuiPlatformMonitor TMP_MONITOR = new ImGuiPlatformMonitor(0); private static final ImVec2 TMP_IM_VEC2 = new ImVec2(); @@ -530,18 +529,6 @@ public final class ImGuiPlatformIO extends ImGuiStruct { // Viewports list (the list is updated by calling ImGui::EndFrame or ImGui::Render) // (in the future we will attempt to organize this feature to remove the need for a "main viewport") - /** - * Guaranteed to be == Viewports[0] - */ - public ImGuiViewport getMainViewport() { - MAIN_VIEWPORT.ptr = nGetMainViewport(); - return MAIN_VIEWPORT; - } - - private native long nGetMainViewport(); /* - return (intptr_t)IMGUI_PLATFORM_IO->MainViewport; - */ - public native int getViewportsSize(); /* return IMGUI_PLATFORM_IO->Viewports.Size; */ diff --git a/imgui-binding/src/main/java/imgui/ImGuiViewport.java b/imgui-binding/src/main/java/imgui/ImGuiViewport.java index 6abe6d9..4f5cbf8 100644 --- a/imgui-binding/src/main/java/imgui/ImGuiViewport.java +++ b/imgui-binding/src/main/java/imgui/ImGuiViewport.java @@ -129,63 +129,59 @@ public final class ImGuiViewport extends ImGuiStruct { */ /** - * Work Area: Offset from Pos to top-left corner of Work Area. Generally (0,0) or (0,+main_menu_bar_height). - * Work Area is Full Area but without menu-bars/status-bars (so WorkArea always fit inside Pos/Size!) + * Work Area: Position of the viewport minus task bars, menus bars, status bars. */ - public native void getWorkOffsetMin(ImVec2 dstImVec2); /* - Jni::ImVec2Cpy(env, &IMGUI_VIEWPORT->WorkOffsetMin, dstImVec2); + public native void getWorkPos(ImVec2 dstImVec2); /* + Jni::ImVec2Cpy(env, IMGUI_VIEWPORT->WorkPos, dstImVec2); */ /** - * Work Area: Offset from Pos to top-left corner of Work Area. Generally (0,0) or (0,+main_menu_bar_height). - * Work Area is Full Area but without menu-bars/status-bars (so WorkArea always fit inside Pos/Size!) + * Work Area: Position of the viewport minus task bars, menus bars, status bars. */ - public native float getWorkOffsetMinX(); /* - return IMGUI_VIEWPORT->WorkOffsetMin.x; + public native float getWorkPosX(); /* + return IMGUI_VIEWPORT->WorkPos.x; */ /** - * Work Area: Offset from Pos to top-left corner of Work Area. Generally (0,0) or (0,+main_menu_bar_height). - * Work Area is Full Area but without menu-bars/status-bars (so WorkArea always fit inside Pos/Size!) + * Work Area: Position of the viewport minus task bars, menus bars, status bars. */ - public native float getWorkOffsetMinY(); /* - return IMGUI_VIEWPORT->WorkOffsetMin.y; + public native float getWorkPosY(); /* + return IMGUI_VIEWPORT->WorkPos.y; */ /** - * Work Area: Offset from Pos to top-left corner of Work Area. Generally (0,0) or (0,+main_menu_bar_height). - * Work Area is Full Area but without menu-bars/status-bars (so WorkArea always fit inside Pos/Size!) + * Work Area: Position of the viewport minus task bars, menus bars, status bars. */ - public native void seWorkOffsetMin(float x, float y); /* - IMGUI_VIEWPORT->WorkOffsetMin = ImVec2(x, y); + public native void setWorkPos(float x, float y); /* + IMGUI_VIEWPORT->WorkPos = ImVec2(x, y); */ /** - * Work Area: Offset from Pos+Size to bottom-right corner of Work Area. Generally (0,0) or (0,-status_bar_height). + * Work Area: Size of the viewport minus task bars, menu bars, status bars. */ - public native void getWorkOffsetMax(ImVec2 dstImVec2); /* - Jni::ImVec2Cpy(env, &IMGUI_VIEWPORT->WorkOffsetMax, dstImVec2); + public native void getWorkSize(ImVec2 dstImVec2); /* + Jni::ImVec2Cpy(env, IMGUI_VIEWPORT->WorkSize, dstImVec2); */ /** - * Work Area: Offset from Pos+Size to bottom-right corner of Work Area. Generally (0,0) or (0,-status_bar_height). + * Work Area: Size of the viewport minus task bars, menu bars, status bars. */ - public native float getWorkOffsetMaxX(); /* - return IMGUI_VIEWPORT->WorkOffsetMax.x; + public native float getWorkSizeX(); /* + return IMGUI_VIEWPORT->WorkSize.x; */ /** - * Work Area: Offset from Pos+Size to bottom-right corner of Work Area. Generally (0,0) or (0,-status_bar_height). + * Work Area: Size of the viewport minus task bars, menu bars, status bars. */ - public native float getWorkOffsetMaxY(); /* - return IMGUI_VIEWPORT->WorkOffsetMax.y; + public native float getWorkSizeY(); /* + return IMGUI_VIEWPORT->WorkSize.y; */ /** - * Work Area: Offset from Pos+Size to bottom-right corner of Work Area. Generally (0,0) or (0,-status_bar_height). + * Work Area: Size of the viewport minus task bars, menu bars, status bars. */ - public native void seWorkOffsetMax(float x, float y); /* - IMGUI_VIEWPORT->WorkOffsetMax = ImVec2(x, y); + public native void setWorkSize(float x, float y); /* + IMGUI_VIEWPORT->WorkSize = ImVec2(x, y); */ /** @@ -202,18 +198,6 @@ public final class ImGuiViewport extends ImGuiStruct { IMGUI_VIEWPORT->DpiScale = dpiScale; */ - /** - * The ImDrawData corresponding to this viewport. Valid after Render() and until the next call to NewFrame(). - */ - public ImDrawData getDrawData() { - DRAW_DATA.ptr = nGetDrawData(); - return DRAW_DATA; - } - - private native long nGetDrawData(); /* - return (intptr_t)IMGUI_VIEWPORT->DrawData; - */ - /** * (Advanced) 0: no parent. Instruct the platform backend to setup a parent/child relationship between platform windows. */ @@ -228,6 +212,18 @@ public final class ImGuiViewport extends ImGuiStruct { IMGUI_VIEWPORT->ParentViewportId = parentViewportId; */ + /** + * The ImDrawData corresponding to this viewport. Valid after Render() and until the next call to NewFrame(). + */ + public ImDrawData getDrawData() { + DRAW_DATA.ptr = nGetDrawData(); + return DRAW_DATA; + } + + private native long nGetDrawData(); /* + return (intptr_t)IMGUI_VIEWPORT->DrawData; + */ + // Our design separate the Renderer and Platform backends to facilitate combining default backends with each others. // When our create your own backend for a custom engine, it is possible that both Renderer and Platform will be handled // by the same system and you may not need to use all the UserData/Handle fields. @@ -337,7 +333,7 @@ public final class ImGuiViewport extends ImGuiStruct { IMGUI_VIEWPORT->PlatformRequestClose = platformRequestClose; */ - // Access work-area rectangle with GetWorkXXX functions (see comments above) + // Helpers public native void getCenter(ImVec2 dstImVec2); /* Jni::ImVec2Cpy(env, IMGUI_VIEWPORT->GetCenter(), dstImVec2); @@ -351,27 +347,15 @@ public final class ImGuiViewport extends ImGuiStruct { return IMGUI_VIEWPORT->GetCenter().y; */ - public native void getWorkPos(ImVec2 dstImVec2); /* - Jni::ImVec2Cpy(env, IMGUI_VIEWPORT->GetWorkPos(), dstImVec2); + public native void getWorkCenter(ImVec2 dstImVec2); /* + Jni::ImVec2Cpy(env, IMGUI_VIEWPORT->GetWorkCenter(), dstImVec2); */ - public native float getWorkPosX(); /* - return IMGUI_VIEWPORT->GetWorkPos().x; + public native float getWorkCenterX(); /* + return IMGUI_VIEWPORT->GetWorkCenter().x; */ - public native float getWorkPosY(); /* - return IMGUI_VIEWPORT->GetWorkPos().y; - */ - - public native void getWorkSize(ImVec2 dstImVec2); /* - Jni::ImVec2Cpy(env, IMGUI_VIEWPORT->GetWorkSize(), dstImVec2); - */ - - public native float getWorkSizeX(); /* - return IMGUI_VIEWPORT->GetWorkSize().x; - */ - - public native float getWorkSizeY(); /* - return IMGUI_VIEWPORT->GetWorkSize().y; + public native float getWorkCenterY(); /* + return IMGUI_VIEWPORT->GetWorkCenter().y; */ } diff --git a/imgui-binding/src/main/java/imgui/flag/ImGuiFreeTypeBuilderFlags.java b/imgui-binding/src/main/java/imgui/flag/ImGuiFreeTypeBuilderFlags.java new file mode 100644 index 0000000..8a6b0d5 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/flag/ImGuiFreeTypeBuilderFlags.java @@ -0,0 +1,45 @@ +package imgui.flag; + +public final class ImGuiFreeTypeBuilderFlags { + private ImGuiFreeTypeBuilderFlags() { + } + + /** + * Disable hinting. This generally generates 'blurrier' bitmap glyphs when the glyph are rendered in any of the anti-aliased modes. + */ + public static final int NoHinting = 1; + /** + * Disable auto-hinter. + */ + public static final int NoAutoHint = 1 << 1; + /** + * Indicates that the auto-hinter is preferred over the font's native hinter. + */ + public static final int ForceAutoHint = 1 << 2; + /** + * A lighter hinting algorithm for gray-level modes. Many generated glyphs are fuzzier but better resemble their original shape. + * This is achieved by snapping glyphs to the pixel grid only vertically (Y-axis), as is done by Microsoft's ClearType and Adobe's proprietary font renderer. + * This preserves inter-glyph spacing in horizontal text. + */ + public static final int LightHinting = 1 << 3; + /** + * Strong hinting algorithm that should only be used for monochrome output. + */ + public static final int MonoHinting = 1 << 4; + /** + * Styling: Should we artificially embolden the font? + */ + public static final int Bold = 1 << 5; + /** + * Styling: Should we slant the font, emulating italic style? + */ + public static final int Oblique = 1 << 6; + /** + * Disable anti-aliasing. Combine this with MonoHinting for best results! + */ + public static final int Monochrome = 1 << 7; + /** + * Enable FreeType color-layered glyphs1 + */ + public static final int LoadColor = 1 << 8; +} diff --git a/imgui-binding/src/main/java/imgui/flag/ImGuiViewportFlags.java b/imgui-binding/src/main/java/imgui/flag/ImGuiViewportFlags.java index f67e39c..c243ed3 100644 --- a/imgui-binding/src/main/java/imgui/flag/ImGuiViewportFlags.java +++ b/imgui-binding/src/main/java/imgui/flag/ImGuiViewportFlags.java @@ -8,47 +8,59 @@ public final class ImGuiViewportFlags { } public static final int None = 0; + /** + * Represent a Platform Window. + */ + public static final int IsPlatformWindow = 1; + /** + * Represent a Platform Monitor (unused yet) + */ + public static final int IsPlatformMonitor = 1 << 1; + /** + * Platform Window: is created/managed by the application (rather than a dear imgui backend) + */ + public static final int OwnedByApp = 1 << 2; /** * Platform Window: Disable platform decorations: title bar, borders, etc. * (generally set all windows, but if ImGuiConfigFlags_ViewportsDecoration is set we only set this on popups/tooltips) */ - public static final int NoDecoration = 1; + public static final int NoDecoration = 1 << 3; /** - * Platform Window: Disable platform task bar icon - * (generally set on popups/tooltips, or all windows if ImGuiConfigFlags_ViewportsNoTaskBarIcon is set) + * Platform Window: Disable platform task bar icon (generally set on popups/tooltips, or all windows if ImGuiConfigFlags_ViewportsNoTaskBarIcon is set) */ - public static final int NoTaskBarIcon = 1 << 1; + public static final int NoTaskBarIcon = 1 << 4; /** * Platform Window: Don't take focus when created. */ - public static final int NoFocusOnAppearing = 1 << 2; + public static final int NoFocusOnAppearing = 1 << 5; /** * Platform Window: Don't take focus when clicked on. */ - public static final int NoFocusOnClick = 1 << 3; + public static final int NoFocusOnClick = 1 << 6; /** * Platform Window: Make mouse pass through so we can drag this window while peaking behind it. */ - public static final int NoInputs = 1 << 4; + public static final int NoInputs = 1 << 7; /** * Platform Window: Renderer doesn't need to clear the framebuffer ahead (because we will fill it entirely). */ - public static final int NoRendererClear = 1 << 5; + public static final int NoRendererClear = 1 << 8; /** * Platform Window: Display on top (for tooltips only). */ - public static final int TopMost = 1 << 6; + public static final int TopMost = 1 << 9; /** - * Platform Window: Window is minimized, can skip render. When minimized we tend to avoid using the viewport pos/size for clipping window or testing if they are contained in the viewport. + * Platform Window: Window is minimized, can skip render. + * When minimized we tend to avoid using the viewport pos/size for clipping window or testing if they are contained in the viewport. */ - public static final int Minimized = 1 << 7; + public static final int Minimized = 1 << 10; /** - * Platform Window: Avoid merging this window into another host window. This can only be set via ImGuiWindowClass viewport flags override - * (because we need to now ahead if we are going to create a viewport in the first place!). + * Platform Window: Avoid merging this window into another host window. + * This can only be set via ImGuiWindowClass viewport flags override (because we need to now ahead if we are going to create a viewport in the first place!). */ - public static final int NoAutoMerge = 1 << 8; + public static final int NoAutoMerge = 1 << 11; /** * Main viewport: can host multiple imgui windows (secondary viewports are associated to a single window). */ - public static final int CanHostOtherWindows = 1 << 9; + public static final int CanHostOtherWindows = 1 << 12; } diff --git a/imgui-binding/src/main/native/imconfig.h b/imgui-binding/src/main/native/imconfig.h deleted file mode 100644 index ffa0832..0000000 --- a/imgui-binding/src/main/native/imconfig.h +++ /dev/null @@ -1,108 +0,0 @@ -//----------------------------------------------------------------------------- -// COMPILE-TIME OPTIONS FOR DEAR IMGUI -// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. -// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. -//----------------------------------------------------------------------------- -// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it) -// B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template. -//----------------------------------------------------------------------------- -// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp -// files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures. -// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. -// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using. -//----------------------------------------------------------------------------- - -#pragma once - -//---- Define assertion handler. Defaults to calling assert(). -// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. -//#define IM_ASSERT(_EXPR) MyAssert(_EXPR) -//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts - -//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows -// Using dear imgui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. -//#define IMGUI_API __declspec( dllexport ) -//#define IMGUI_API __declspec( dllimport ) - -//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. -//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS - -//---- Disable all of Dear ImGui or don't implement standard windows. -// It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp. -//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. -//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended. -//#define IMGUI_DISABLE_METRICS_WINDOW // Disable metrics/debugger window: ShowMetricsWindow() will be empty. - -//---- Don't implement some functions to reduce linkage requirements. -//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. -//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow. -//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime). -//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). -//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) -//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. -//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. -//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). - -//---- Include imgui_user.h at the end of imgui.h as a convenience -//#define IMGUI_INCLUDE_IMGUI_USER_H - -//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) -//#define IMGUI_USE_BGRA_PACKED_COLOR - -//---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...) -//#define IMGUI_USE_WCHAR32 - -//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version -// By default the embedded implementations are declared static and not available outside of imgui cpp files. -//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" -//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" -//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION -//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION - -//---- Use stb_printf's faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) -// Requires 'stb_sprintf.h' to be available in the include path. Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by STB sprintf. -// #define IMGUI_USE_STB_SPRINTF - -//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. -// This will be inlined as part of ImVec2 and ImVec4 class declarations. -/* -#define IM_VEC2_CLASS_EXTRA \ - ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \ - operator MyVec2() const { return MyVec2(x,y); } -#define IM_VEC4_CLASS_EXTRA \ - ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ - operator MyVec4() const { return MyVec4(x,y,z,w); } -*/ - -//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. -// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). -// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. -// Read about ImGuiBackendFlags_RendererHasVtxOffset for details. -//#define ImDrawIdx unsigned int - -//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) -//struct ImDrawList; -//struct ImDrawCmd; -//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); -//#define ImDrawCallback MyImDrawCallback - -//---- Debug Tools: Macro to break in Debugger -// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) -//#define IM_DEBUG_BREAK IM_ASSERT(0) -//#define IM_DEBUG_BREAK __debugbreak() - -//---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(), -// (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.) -// This adds a small runtime cost which is why it is not enabled by default. -//#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX - -//---- Debug Tools: Enable slower asserts -//#define IMGUI_DEBUG_PARANOID - -//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files. -/* -namespace ImGui -{ - void MyFunction(const char* name, const MyMatrix44& v); -} -*/