From eed23dbd390c2dbf239e1b81d7747e49b4364610 Mon Sep 17 00:00:00 2001 From: SpaiR Date: Mon, 10 Feb 2020 23:18:12 +0300 Subject: [PATCH] Update binding API to Dear ImGui v1.75 --- .../src/main/java/imgui/ImDrawList.java | 33 ++++++--- imgui-binding/src/main/java/imgui/ImFont.java | 16 ++--- imgui-binding/src/main/java/imgui/ImGui.java | 68 ++++++++++--------- .../src/main/java/imgui/ImGuiIO.java | 2 +- .../src/main/java/imgui/ImGuiStyle.java | 16 +++++ .../java/imgui/enums/ImGuiMouseButton.java | 15 ++++ .../java/imgui/enums/ImGuiMouseCursor.java | 3 +- 7 files changed, 102 insertions(+), 51 deletions(-) create mode 100644 imgui-binding/src/main/java/imgui/enums/ImGuiMouseButton.java diff --git a/imgui-binding/src/main/java/imgui/ImDrawList.java b/imgui-binding/src/main/java/imgui/ImDrawList.java index 7c03900..4545b79 100644 --- a/imgui-binding/src/main/java/imgui/ImDrawList.java +++ b/imgui-binding/src/main/java/imgui/ImDrawList.java @@ -105,6 +105,9 @@ public final class ImDrawList { // Primitives // - For rectangular primitives, "pMin" and "pMax" represent the upper-left and lower-right corners. + // - For circle primitives, use "num_segments == 0" to automatically calculate tessellation (preferred). + // In future versions we will use textures to provide cheaper and higher-quality circles. + // Use AddNgon() and AddNgonFilled() functions if you need to guaranteed a specific number of sides. public native void addLine(float p1X, float p1Y, float p2X, float p2Y, int col); /* getDrawList(env->GetIntField(object, drawListTypeID))->AddLine(ImVec2(p1X, p1Y), ImVec2(p2X, p2Y), col); @@ -190,6 +193,18 @@ public final class ImDrawList { getDrawList(env->GetIntField(object, drawListTypeID))->AddCircleFilled(ImVec2(centreX, centreY), radius, col, numSegments); */ + public native void AddNgon(float centreX, float centreY, float radius, int col, int numSegments); /* + getDrawList(env->GetIntField(object, drawListTypeID))->AddNgon(ImVec2(centreX, centreY), radius, col, numSegments); + */ + + public native void AddNgon(float centreX, float centreY, float radius, int col, int numSegments, float thickness); /* + getDrawList(env->GetIntField(object, drawListTypeID))->AddNgon(ImVec2(centreX, centreY), radius, col, numSegments, thickness); + */ + + public native void AddNgonFilled(float centreX, float centreY, float radius, int col, int numSegments); /* + getDrawList(env->GetIntField(object, drawListTypeID))->AddNgonFilled(ImVec2(centreX, centreY), radius, col, numSegments); + */ + public native void addText(float posX, float posY, int col, String textBegin); /* getDrawList(env->GetIntField(object, drawListTypeID))->AddText(ImVec2(posX, posY), col, textBegin); */ @@ -225,12 +240,12 @@ public final class ImDrawList { getDrawList(env->GetIntField(object, drawListTypeID))->AddConvexPolyFilled(_points, numPoints, col); */ - public native void addBezierCurve(float pos0X, float pos0Y, float cp0X, float cp0Y, float cp1X, float cp1Y, float pos1X, float pos1Y, int col, float thickness); /* - getDrawList(env->GetIntField(object, drawListTypeID))->AddBezierCurve(ImVec2(pos0X, pos0Y), ImVec2(cp0X, cp0Y), ImVec2(cp1X, cp1Y), ImVec2(pos1X, pos1Y), col, thickness); + public native void addBezierCurve(float p1X, float p1Y, float p2X, float p2Y, float p3X, float p3Y, float p4X, float p4Y, int col, float thickness); /* + getDrawList(env->GetIntField(object, drawListTypeID))->AddBezierCurve(ImVec2(p1X, p1Y), ImVec2(p2X, p2Y), ImVec2(p3X, p3Y), ImVec2(p4X, p4Y), col, thickness); */ - public native void addBezierCurve(float pos0X, float pos0Y, float cp0X, float cp0Y, float cp1X, float cp1Y, float pos1X, float pos1Y, int col, float thickness, int numSegments); /* - getDrawList(env->GetIntField(object, drawListTypeID))->AddBezierCurve(ImVec2(pos0X, pos0Y), ImVec2(cp0X, cp0Y), ImVec2(cp1X, cp1Y), ImVec2(pos1X, pos1Y), col, thickness, numSegments); + public native void addBezierCurve(float p1X, float p1Y, float p2X, float p2Y, float p3X, float p3Y, float p4X, float p4Y, int col, float thickness, int numSegments); /* + getDrawList(env->GetIntField(object, drawListTypeID))->AddBezierCurve(ImVec2(p1X, p1Y), ImVec2(p2X, p2Y), ImVec2(p3X, p3Y), ImVec2(p4X, p4Y), col, thickness, numSegments); */ // Image primitives @@ -338,8 +353,8 @@ public final class ImDrawList { getDrawList(env->GetIntField(object, drawListTypeID))->PathArcToFast(ImVec2(centerX, centerY), radius, aMinOf12, aMaxOf12); */ - public native void pathBezierCurveTo(float p1X, float p1Y, float p2X, float p2Y, float p3X, float p3Y, int numSegments); /* - getDrawList(env->GetIntField(object, drawListTypeID))->PathBezierCurveTo(ImVec2(p1X, p1Y), ImVec2(p2X, p2Y), ImVec2(p3X, p3Y), numSegments); + public native void pathBezierCurveTo(float p2X, float p2Y, float p3X, float p3Y, float p4X, float p4Y, int numSegments); /* + getDrawList(env->GetIntField(object, drawListTypeID))->PathBezierCurveTo(ImVec2(p2X, p2Y), ImVec2(p3X, p3Y), ImVec2(p4X, p4Y), numSegments); */ public native void pathRect(float rectMinX, float rectMinY, float rectMaxX, float rectMaxY); /* @@ -355,8 +370,10 @@ public final class ImDrawList { */ // Advanced: Channels - // - Use to split render into layers. By switching channels to can render out-of-order (e.g. submit foreground primitives before background primitives) - // - Use to minimize draw calls (e.g. if going back-and-forth between multiple non-overlapping clipping rectangles, prefer to append into separate channels then merge at the end) + // - Use to split render into layers. By switching channels to can render out-of-order (e.g. submit FG primitives before BG primitives) + // - Use to minimize draw calls (e.g. if going back-and-forth between multiple clipping rectangles, prefer to append into separate channels then merge at the end) + // Prefer using your own persistent copy of ImDrawListSplitter as you can stack them. + // Using the ImDrawList::ChannelsXXXX you cannot stack a split over another. public native void channelsSplit(int count); /* ImDrawList* drawList = getDrawList(env->GetIntField(object, drawListTypeID)); diff --git a/imgui-binding/src/main/java/imgui/ImFont.java b/imgui-binding/src/main/java/imgui/ImFont.java index 0a784e9..31be5ac 100644 --- a/imgui-binding/src/main/java/imgui/ImFont.java +++ b/imgui-binding/src/main/java/imgui/ImFont.java @@ -135,6 +135,14 @@ public final class ImFont implements ImDestroyable { IM_FONT->EllipsisChar = (ImWchar)ellipsisChar; */ + public native boolean getDirtyLookupTables(); /* + return IM_FONT->DirtyLookupTables; + */ + + public native void setDirtyLookupTables(boolean dirtyLookupTables); /* + IM_FONT->DirtyLookupTables = dirtyLookupTables; + */ + /** * Base font scale, multiplied by the per-window font scale which you can adjust with SetWindowFontScale() */ @@ -191,13 +199,5 @@ public final class ImFont implements ImDestroyable { IM_FONT->MetricsTotalSurface = metricsTotalSurface; */ - public native boolean getDirtyLookupTables(); /* - return IM_FONT->DirtyLookupTables; - */ - - public native void setDirtyLookupTables(boolean dirtyLookupTables); /* - IM_FONT->DirtyLookupTables = dirtyLookupTables; - */ - // TODO methods } diff --git a/imgui-binding/src/main/java/imgui/ImGui.java b/imgui-binding/src/main/java/imgui/ImGui.java index 3c6c7cc..76879f8 100644 --- a/imgui-binding/src/main/java/imgui/ImGui.java +++ b/imgui-binding/src/main/java/imgui/ImGui.java @@ -529,7 +529,7 @@ public final class ImGui { */ /** - * Set next window background color alpha. helper to easily modify ImGuiCol_WindowBg/ChildBg/PopupBg. + * Set next window background color alpha. helper to easily override the Alpha component of ImGuiCol_WindowBg/ChildBg/PopupBg. * You may also use ImGuiWindowFlags_NoBackground. */ public static native void setNextWindowBgAlpha(float alpha); /* @@ -1495,6 +1495,7 @@ public final class ImGui { // - 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 (vSpeed=0.2f: mouse needs to move by 5 pixels to increase value by 1). For gamepad/keyboard navigation, minimum speed is Max(vSpeed, minimum_step_at_given_precision). // - Use vMin < vMax to clamp edits to given limits. Note that CTRL+Click manual input can override those limits. + // - Use v_max = FLT_MAX / INT_MAX etc to avoid clamping to a maximum, same with v_min = -FLT_MAX / INT_MIN to avoid clamping to a minimum. // - Use vMin > vMax to lock edits. public static native boolean dragFloat(String label, float[] v); /* @@ -2520,7 +2521,7 @@ public final class ImGui { */ // 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 + // - If you want to use InputText() with std::string or any custom dynamic string type, see misc/cpp/imgui_stdlib.h and comments in imgui_demo.cpp. // - Most of the ImGuiInputTextFlags flags are only useful for InputText() and not for InputFloatX, InputIntX, InputDouble etc. /*JNI @@ -3655,6 +3656,7 @@ public final class ImGui { // - 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(). + // - We default to use the right mouse (ImGuiMouseButton_Right=1) for the Popup Context functions. // (*) You 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. @@ -3839,7 +3841,8 @@ public final class ImGui { // Columns // - You can also use SameLine(posX) 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!) - // - By end of the 2019 we will expose a new 'Table' api which will replace columns. + // - There is a maximum of 64 columns. + // - Currently working on new 'Tables' api which will replace columns (see GitHub #2957) public static native void columns(); /* ImGui::Columns(); @@ -4451,7 +4454,9 @@ public final class ImGui { ImGui::ColorConvertHSVtoRGB(hsv[0], hsv[1], hsv[2], rgb[0], rgb[1], rgb[2]); */ - // Inputs Utilities + // Inputs Utilities: Keyboard + // - For 'int user_key_index' you can use your own indices/enums according to how your backend/engine stored them in io.KeysDown[]. + // - We don't know the meaning of those value. You can use GetKeyIndex() to map a ImGuiKey_ value into the user index. /** * Map ImGuiKey_* values into user's key index. == io.KeyMap[key] @@ -4461,22 +4466,21 @@ public final class ImGui { */ /** - * Is key being held. == io.KeysDown[userKeyIndex]. note that imgui doesn't know the semantic of each entry of io.KeysDown[]. - * Use your own indices/enums according to how your backend/engine stored them into io.KeysDown[]! + * Is key being held. == io.KeysDown[user_key_index]. */ public static native boolean isKeyDown(int userKeyIndex); /* return ImGui::IsKeyDown(userKeyIndex); */ /** - * Was key pressed (went from !Down to Down). if repeat=true, uses io.KeyRepeatDelay / KeyRepeatRate + * Was key pressed (went from !Down to Down)? if repeat=true, uses io.KeyRepeatDelay / KeyRepeatRate */ public static native boolean isKeyPressed(int userKeyIndex); /* return ImGui::IsKeyPressed(userKeyIndex); */ /** - * Was key pressed (went from !Down to Down). if repeat=true, uses io.KeyRepeatDelay / KeyRepeatRate + * Was key pressed (went from !Down to Down)? if repeat=true, uses io.KeyRepeatDelay / KeyRepeatRate */ public static native boolean isKeyPressed(int userKeyIndex, boolean repeat); /* return ImGui::IsKeyPressed(userKeyIndex, repeat); @@ -4497,6 +4501,29 @@ public final class ImGui { return ImGui::GetKeyPressedAmount(keyIndex, repeatDelay, rate); */ + /** + * Attention: misleading name! manually override io.WantCaptureKeyboard flag next frame (said flag is entirely left for your application to handle). + * e.g. force capture keyboard when your widget is being hovered. + * This is equivalent to setting "io.WantCaptureKeyboard = wantCaptureKeyboardValue"; after the next NewFrame() call. + */ + public static native void captureKeyboardFromApp(); /* + ImGui::CaptureKeyboardFromApp(); + */ + + /** + * Attention: misleading name! manually override io.WantCaptureKeyboard flag next frame (said flag is entirely left for your application to handle). + * e.g. force capture keyboard when your widget is being hovered. + * This is equivalent to setting "io.WantCaptureKeyboard = wantCaptureKeyboardValue"; after the next NewFrame() call. + */ + public static native void captureKeyboardFromApp(boolean wantCaptureKeyboardValue); /* + ImGui::CaptureKeyboardFromApp(wantCaptureKeyboardValue); + */ + + // Inputs Utilities: Mouse + // - To refer to a mouse button, you may use named enums in your code e.g. ImGuiMouseButton_Left, ImGuiMouseButton_Right. + // - You can also use regular integer: it is forever guaranteed that 0=Left, 1=Right, 2=Middle. + // - Dragging operations are only reported after mouse has moved a certain distance away from the initial clicking position (see 'lock_threshold' and 'io.MouseDraggingThreshold') + /** * Is mouse button held (0=left, 1=right, 2=middle) */ @@ -4536,13 +4563,6 @@ public final class ImGui { return ImGui::IsMouseReleased(button); */ - /** - * Is mouse dragging. if lockThreshold {@code < -1.0f} uses io.MouseDraggingThreshold - */ - public static native boolean isMouseDragging(); /* - return ImGui::IsMouseDragging(); - */ - /** * Is mouse dragging. if lockThreshold {@code < -1.0f} uses io.MouseDraggingThreshold */ @@ -4647,24 +4667,6 @@ public final class ImGui { ImGui::SetMouseCursor(type); */ - /** - * Attention: misleading name! manually override io.WantCaptureKeyboard flag next frame (said flag is entirely left for your application to handle). - * e.g. force capture keyboard when your widget is being hovered. - * This is equivalent to setting "io.WantCaptureKeyboard = wantCaptureKeyboardValue"; after the next NewFrame() call. - */ - public static native void captureKeyboardFromApp(); /* - ImGui::CaptureKeyboardFromApp(); - */ - - /** - * Attention: misleading name! manually override io.WantCaptureKeyboard flag next frame (said flag is entirely left for your application to handle). - * e.g. force capture keyboard when your widget is being hovered. - * This is equivalent to setting "io.WantCaptureKeyboard = wantCaptureKeyboardValue"; after the next NewFrame() call. - */ - public static native void captureKeyboardFromApp(boolean wantCaptureKeyboardValue); /* - ImGui::CaptureKeyboardFromApp(wantCaptureKeyboardValue); - */ - /** * Attention: misleading name! manually override io.WantCaptureMouse flag next frame (said flag is entirely left for your application to handle). * This is equivalent to setting "io.WantCaptureMouse = wantCaptureMouseValue;" after the next NewFrame() call. diff --git a/imgui-binding/src/main/java/imgui/ImGuiIO.java b/imgui-binding/src/main/java/imgui/ImGuiIO.java index 256b0a4..5ff23d8 100644 --- a/imgui-binding/src/main/java/imgui/ImGuiIO.java +++ b/imgui-binding/src/main/java/imgui/ImGuiIO.java @@ -319,7 +319,7 @@ public final class ImGuiIO { */ // Optional: Access OS clipboard - // (default to use native Win32 clipboard on Windows, otherwise uses a private clipboard. Override to access OS clipboard on other architectures) + // (default to use native Win32 clipIsMouseDraggingboard on Windows, otherwise uses a private clipboard. Override to access OS clipboard on other architectures) /*JNI jobject _setClipboardTextCallback = NULL; diff --git a/imgui-binding/src/main/java/imgui/ImGuiStyle.java b/imgui-binding/src/main/java/imgui/ImGuiStyle.java index 43bea1f..dfab070 100644 --- a/imgui-binding/src/main/java/imgui/ImGuiStyle.java +++ b/imgui-binding/src/main/java/imgui/ImGuiStyle.java @@ -406,6 +406,22 @@ public final class ImGuiStyle { ImGui::GetStyle().CurveTessellationTol = curveTessellationTol; */ + /** + * Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. + * Decrease for higher quality but more geometry. + */ + public native float getCircleSegmentMaxError(); /* + return ImGui::GetStyle().CircleSegmentMaxError; + */ + + /** + * Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. + * Decrease for higher quality but more geometry. + */ + public native void setCircleSegmentMaxError(float circleSegmentMaxError); /* + ImGui::GetStyle().CircleSegmentMaxError = circleSegmentMaxError; + */ + // Colors // BINDING NOTICE: buff is a 2d array with sizes: [ImGuiCol_COUNT][4] // diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiMouseButton.java b/imgui-binding/src/main/java/imgui/enums/ImGuiMouseButton.java new file mode 100644 index 0000000..b451488 --- /dev/null +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiMouseButton.java @@ -0,0 +1,15 @@ +package imgui.enums; + +/** + * Identify a mouse button. + * Those values are guaranteed to be stable and we frequently use 0/1 directly. Named enums provided for convenience. + */ +public final class ImGuiMouseButton { + private ImGuiMouseButton() { + } + + public static final int Left = 0; + public static final int Right = 1; + public static final int Middle = 2; + public static final int COUNT = 5; +} diff --git a/imgui-binding/src/main/java/imgui/enums/ImGuiMouseCursor.java b/imgui-binding/src/main/java/imgui/enums/ImGuiMouseCursor.java index 4cc5c1d..cf7187b 100644 --- a/imgui-binding/src/main/java/imgui/enums/ImGuiMouseCursor.java +++ b/imgui-binding/src/main/java/imgui/enums/ImGuiMouseCursor.java @@ -17,5 +17,6 @@ public final class ImGuiMouseCursor { public static final int ResizeNESW = 5; // When hovering over the bottom-left corner of a window public static final int ResizeNWSE = 6; // When hovering over the bottom-right corner of a window public static final int Hand = 7; // (Unused by Dear ImGui functions. Use for e.g. hyperlinks) - public static final int COUNT = 8; + public static final int NotAllowed = 8; // When hovering something with disallowed interaction. Usually a crossed circle. + public static final int COUNT = 9; }