From 27e9bf5fc11c5219f130fc6dc52ae24cb37649af Mon Sep 17 00:00:00 2001 From: Eric Mellino Date: Wed, 10 Jan 2018 00:22:29 -0800 Subject: [PATCH] Update to imgui 1.52 (no native binary updates). --- src/ImGui.NET.SampleProgram/MemoryEditor.cs | 4 +- src/ImGui.NET.SampleProgram/SampleWindow.cs | 2 +- src/ImGui.NET/FocusedFlags.cs | 10 +++ src/ImGui.NET/FontConfig.cs | 16 ++++- src/ImGui.NET/HoveredFlags.cs | 15 +++++ src/ImGui.NET/ImGui.cs | 69 ++++++++++++++------- src/ImGui.NET/ImGuiNative.cs | 28 +++++---- src/ImGui.NET/NativeIO.cs | 40 ++++++++++-- src/ImGui.NET/TreeNodeFlags.cs | 5 +- 9 files changed, 141 insertions(+), 48 deletions(-) create mode 100644 src/ImGui.NET/FocusedFlags.cs create mode 100644 src/ImGui.NET/HoveredFlags.cs diff --git a/src/ImGui.NET.SampleProgram/MemoryEditor.cs b/src/ImGui.NET.SampleProgram/MemoryEditor.cs index 32db707..9eca8f5 100644 --- a/src/ImGui.NET.SampleProgram/MemoryEditor.cs +++ b/src/ImGui.NET.SampleProgram/MemoryEditor.cs @@ -162,7 +162,7 @@ namespace ImGuiNET else { ImGui.Text(FixedHex(mem_data[addr], 2)); - if (AllowEdits && ImGui.IsLastItemHovered() && ImGui.IsMouseClicked(0)) + if (AllowEdits && ImGui.IsItemHovered(HoveredFlags.Default) && ImGui.IsMouseClicked(0)) { DataEditingTakeFocus = true; DataEditingAddr = addr; @@ -197,7 +197,7 @@ namespace ImGuiNET ImGui.Separator(); - ImGuiNative.igAlignFirstTextHeightToWidgets(); + ImGuiNative.igAlignTextToFramePadding(); ImGui.PushItemWidth(50); ImGuiNative.igPushAllowKeyboardFocus(false); int rows_backup = Rows; diff --git a/src/ImGui.NET.SampleProgram/SampleWindow.cs b/src/ImGui.NET.SampleProgram/SampleWindow.cs index 9a7c836..4708bdb 100644 --- a/src/ImGui.NET.SampleProgram/SampleWindow.cs +++ b/src/ImGui.NET.SampleProgram/SampleWindow.cs @@ -203,7 +203,7 @@ namespace ImGuiNET ImGui.GetStyle().WindowRounding = 0; ImGui.SetNextWindowSize(new System.Numerics.Vector2(_nativeWindow.Width - 10, _nativeWindow.Height - 20), Condition.Always); - ImGui.SetNextWindowPosCenter(Condition.Always); + ImGui.SetNextWindowPos(ImGui.GetIO().DisplaySize, Condition.Always, new System.Numerics.Vector2(1f)); ImGui.BeginWindow("ImGUI.NET Sample Program", ref _mainWindowOpened, WindowFlags.NoResize | WindowFlags.NoTitleBar | WindowFlags.NoMove); ImGui.BeginMainMenuBar(); diff --git a/src/ImGui.NET/FocusedFlags.cs b/src/ImGui.NET/FocusedFlags.cs new file mode 100644 index 0000000..e3a018d --- /dev/null +++ b/src/ImGui.NET/FocusedFlags.cs @@ -0,0 +1,10 @@ +namespace ImGuiNET +{ + // Flags for ImGui::IsWindowFocused() + public enum FocusedFlags + { + ChildWindows = 1 << 0, // IsWindowFocused(): Return true if any children of the window is focused + RootWindow = 1 << 1, // IsWindowFocused(): Test from root window (top most parent of the current hierarchy) + RootAndChildWindows = RootWindow | ChildWindows + } +} diff --git a/src/ImGui.NET/FontConfig.cs b/src/ImGui.NET/FontConfig.cs index cb2de36..60a0cec 100644 --- a/src/ImGui.NET/FontConfig.cs +++ b/src/ImGui.NET/FontConfig.cs @@ -19,7 +19,7 @@ namespace ImGuiNET /// TTF data ownership taken by the container ImFontAtlas (will delete memory itself). /// Set to true. /// - public bool FontDataOwnedByAtlas; + public byte FontDataOwnedByAtlas; /// /// 0. /// Index of font within TTF file @@ -43,7 +43,7 @@ namespace ImGuiNET /// Align every character to pixel boundary (if enabled, set OversampleH/V to 1). /// Set to false. /// - public bool PixelSnapH; + public byte PixelSnapH; /// /// Extra spacing (in pixels) between glyphs. /// Set to (0, 0). @@ -62,7 +62,17 @@ namespace ImGuiNET /// Merge into previous ImFont, so you can combine multiple inputs font into one ImFont (e.g. ASCII font + icons + Japanese glyphs). /// Set to false. /// - public bool MergeMode; + public byte MergeMode; + /// + /// Settings for custom font rasterizer (e.g. ImGuiFreeType). Leave as zero if you aren't using one. + /// Defaults to 0. + /// + public uint RasterizerFlags; + /// + /// Brighten (>1.0f) or darken (<1.0f) font output. Brightening small fonts may be a good workaround to make them more readable. + /// Defaults to 1.0. + /// + public float RasterizerMultiply; // [Internal] /// diff --git a/src/ImGui.NET/HoveredFlags.cs b/src/ImGui.NET/HoveredFlags.cs new file mode 100644 index 0000000..c89da3b --- /dev/null +++ b/src/ImGui.NET/HoveredFlags.cs @@ -0,0 +1,15 @@ +namespace ImGuiNET +{ + // Flags for ImGui::IsItemHovered(), ImGui::IsWindowHovered() + public enum HoveredFlags + { + Default = 0, // Return true if directly over the item/window, not obstructed by another window, not obstructed by an active popup or modal blocking inputs under them. + ChildWindows = 1 << 0, // IsWindowHovered() only: Return true if any children of the window is hovered + RootWindow = 1 << 1, // IsWindowHovered() only: Test from root window (top most parent of the current hierarchy) + AllowWhenBlockedByPopup = 1 << 2, // Return true even if a popup window is normally blocking access to this item/window + AllowWhenBlockedByActiveItem = 1 << 4, // Return true even if an active item is blocking access to this item/window. Useful for Drag and Drop patterns. + AllowWhenOverlapped = 1 << 5, // Return true even if the position is overlapped by another window + RectOnly = AllowWhenBlockedByPopup | AllowWhenBlockedByActiveItem | AllowWhenOverlapped, + RootAndChildWindows = RootWindow | ChildWindows + } +} diff --git a/src/ImGui.NET/ImGui.cs b/src/ImGui.NET/ImGui.cs index 29450fc..6562788 100644 --- a/src/ImGui.NET/ImGui.cs +++ b/src/ImGui.NET/ImGui.cs @@ -443,14 +443,9 @@ namespace ImGuiNET ImGuiNative.igSetNextWindowFocus(); } - public static void SetNextWindowPos(Vector2 position, Condition condition) + public static void SetNextWindowPos(Vector2 position, Condition condition, Vector2 pivot) { - ImGuiNative.igSetNextWindowPos(position, condition); - } - - public static void SetNextWindowPosCenter(Condition condition) - { - ImGuiNative.igSetNextWindowPosCenter(condition); + ImGuiNative.igSetNextWindowPos(position, condition, pivot); } public static void AddInputCharacter(char keyChar) @@ -532,7 +527,7 @@ namespace ImGuiNET { return ImGuiNative.igBegin2(windowTitle, ref opened, startingSize, 1f, flags); } - + public static bool BeginWindow(string windowTitle, ref bool opened, Vector2 startingSize, float backgroundAlpha, WindowFlags flags) { return ImGuiNative.igBegin2(windowTitle, ref opened, startingSize, backgroundAlpha, flags); @@ -709,6 +704,11 @@ namespace ImGuiNET return ImGuiNative.igIsKeyReleased(keyIndex); } + public static int GetKeyPressedAmount(int keyIndex, float repeatDelay, float rate) + { + return ImGuiNative.igGetKeyPressedAmount(keyIndex, repeatDelay, rate); + } + public static bool IsMouseDown(int button) { return ImGuiNative.igIsMouseDown(button); @@ -729,19 +729,19 @@ namespace ImGuiNET return ImGuiNative.igIsMouseReleased(button); } - public static bool IsWindowRectHovered() + public static bool IsAnyWindowHovered() { - return ImGuiNative.igIsWindowRectHovered(); + return ImGuiNative.igIsAnyWindowHovered(); } - public static bool IsAnyWindowHovered() + public static bool IsWindowFocused(FocusedFlags flags) { - return ImGuiNative.igIsAnyWindowHovered(); + return ImGuiNative.igIsWindowFocused(flags); } - public static bool IsWindowFocused() + public static bool IsWindowHovered(HoveredFlags flags) { - return ImGuiNative.igIsWindowFocused(); + return ImGuiNative.igIsWindowHovered(flags); } public static bool IsMouseHoveringRect(Vector2 minPosition, Vector2 maxPosition, bool clip) @@ -749,6 +749,16 @@ namespace ImGuiNET return ImGuiNative.igIsMouseHoveringRect(minPosition, maxPosition, clip); } + public static unsafe bool IsMousePosValid() + { + return ImGuiNative.igIsMousePosValid(null); + } + + public static unsafe bool IsMousePosValid(Vector2 mousePos) + { + return ImGuiNative.igIsMousePosValid(&mousePos); + } + public static bool IsMouseDragging(int button, float lockThreshold) { return ImGuiNative.igIsMouseDragging(button, lockThreshold); @@ -811,6 +821,12 @@ namespace ImGuiNET ImGuiNative.igSetCursorScreenPos(pos); } + public static void AlignTextToFramePadding() + { + ImGuiNative.igAlignTextToFramePadding(); + } + + public static bool BeginChild(string id, bool border = false, WindowFlags flags = 0) { return BeginChild(id, new Vector2(0, 0), border, flags); @@ -884,6 +900,11 @@ namespace ImGuiNET return ImGuiNative.igBeginMainMenuBar(); } + public static bool OpenPopupOnItemClick(string id, int mouseButton) + { + return ImGuiNative.igOpenPopupOnItemClick(id, mouseButton); + } + public static bool BeginPopup(string id) { return ImGuiNative.igBeginPopup(id); @@ -1048,21 +1069,16 @@ namespace ImGuiNET ImGuiNative.igPopClipRect(); } - public static bool IsLastItemHovered() - { - return ImGuiNative.igIsItemHovered(); - } - - public static bool IsItemRectHovered() + public static bool IsItemHovered(HoveredFlags flags) { - return ImGuiNative.igIsItemRectHovered(); + return ImGuiNative.igIsItemHovered(flags); } public static bool IsLastItemActive() { return ImGuiNative.igIsItemActive(); } - + public static bool IsLastItemVisible() { return ImGuiNative.igIsItemVisible(); @@ -1129,6 +1145,11 @@ namespace ImGuiNET return result; } + public static bool IsWindowAppearing() + { + return ImGuiNative.igIsWindowAppearing(); + } + public static void SetWindowFontScale(float scale) { ImGuiNative.igSetWindowFontScale(scale); @@ -1163,10 +1184,10 @@ namespace ImGuiNET { ImGuiNative.igSetKeyboardFocusHere(offset); } - + public static void CalcListClipping(int itemsCount, float itemsHeight, ref int outItemsDisplayStart, ref int outItemsDisplayEnd) { ImGuiNative.igCalcListClipping(itemsCount, itemsHeight, ref outItemsDisplayStart, ref outItemsDisplayEnd); - } + } } } diff --git a/src/ImGui.NET/ImGuiNative.cs b/src/ImGui.NET/ImGuiNative.cs index ea29231..fc58b1e 100644 --- a/src/ImGui.NET/ImGuiNative.cs +++ b/src/ImGui.NET/ImGuiNative.cs @@ -73,6 +73,9 @@ namespace ImGuiNET [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] public static extern NativeDrawList* igGetWindowDrawList(); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs(UnmanagedType.I1)] + public static extern bool igIsWindowAppearing(); + [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] public static extern void igSetWindowFontScale(float scale); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] public static extern void igGetWindowPos(out Vector2 @out); @@ -85,11 +88,8 @@ namespace ImGuiNET [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool igIsWindowCollapsed(); - [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] - public static extern void igSetNextWindowPos(Vector2 pos, Condition cond); - [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] - public static extern void igSetNextWindowPosCenter(Condition cond); + public static extern void igSetNextWindowPos(Vector2 pos, Condition cond, Vector2 pivot); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] public static extern void igSetNextWindowSize(Vector2 size, Condition cond); public delegate void ImGuiSizeConstraintCallback(IntPtr data); @@ -228,7 +228,7 @@ namespace ImGuiNET [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] public static extern void igSetCursorScreenPos(Vector2 pos); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] - public static extern void igAlignFirstTextHeightToWidgets(); + public static extern void igAlignTextToFramePadding(); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] public static extern float igGetTextLineHeight(); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] @@ -584,6 +584,9 @@ namespace ImGuiNET public static extern void igOpenPopup(string str_id); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] + public static extern bool igOpenPopupOnItemClick(string str_id, int mouse_button); + [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs(UnmanagedType.I1)] public static extern bool igBeginPopup(string str_id); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] @@ -630,10 +633,7 @@ namespace ImGuiNET // Utilities [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] - public static extern bool igIsItemHovered(); - [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] - [return: MarshalAs(UnmanagedType.I1)] - public static extern bool igIsItemRectHovered(); + public static extern bool igIsItemHovered(HoveredFlags flags); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool igIsItemActive(); @@ -660,10 +660,10 @@ namespace ImGuiNET [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] - public static extern bool igIsWindowHovered(); + public static extern bool igIsWindowHovered(HoveredFlags flags); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] - public static extern bool igIsWindowFocused(); + public static extern bool igIsWindowFocused(FocusedFlags flags); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool igIsRootWindowFocused(); @@ -719,6 +719,8 @@ namespace ImGuiNET [return: MarshalAs(UnmanagedType.I1)] public static extern bool igIsKeyReleased(int user_key_index); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] + public static extern int igGetKeyPressedAmount(int key_index, float repeat_delay, float rate); + [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool igIsMouseDown(int button); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] @@ -732,10 +734,10 @@ namespace ImGuiNET public static extern bool igIsMouseReleased(int button); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] - public static extern bool igIsWindowRectHovered(); + public static extern bool igIsAnyWindowHovered(); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] - public static extern bool igIsAnyWindowHovered(); + public static extern bool igIsMousePosValid(Vector2* mousePos); [DllImport(cimguiLib, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool igIsMouseHoveringRect(Vector2 pos_min, Vector2 pos_max, bool clip); diff --git a/src/ImGui.NET/NativeIO.cs b/src/ImGui.NET/NativeIO.cs index 4bdb3c5..ae852e4 100644 --- a/src/ImGui.NET/NativeIO.cs +++ b/src/ImGui.NET/NativeIO.cs @@ -118,6 +118,11 @@ namespace ImGuiNET /// Default value: True on OSX; false otherwise. /// public byte OSXBehaviors; + /// + /// Enable blinking cursor, for users who consider it annoying. + /// Default value: true. + /// + public byte OptCursorBlink; //------------------------------------------------------------------ // User Functions @@ -196,6 +201,9 @@ namespace ImGuiNET /// Keyboard modifier pressed: Alt /// public byte KeyAlt; + /// + /// Keyboard modifier pressed: Cmd/Super/Windows + /// public byte KeySuper; /// /// Keyboard keys that are pressed (in whatever storage order you naturally have access to keyboard data) @@ -224,6 +232,10 @@ namespace ImGuiNET /// public byte WantTextInput; /// + /// MousePos has been altered, back-end should reposition mouse on next frame. Set only when 'NavMovesMouse=true'. + /// + public byte WantMoveMouse; + /// /// Framerate estimation, in frame per second. Rolling average estimation based on IO.DeltaTime over 120 frames. /// public float Framerate; @@ -258,10 +270,6 @@ namespace ImGuiNET /// public Vector2 MousePosPrev; /// - /// Mouse button went from !Down to Down - /// - public fixed byte MouseClicked[5]; - /// /// Position at time of clicking /// public Vector2 MouseClickedPos0; @@ -286,6 +294,10 @@ namespace ImGuiNET /// public fixed float MouseClickedTime[5]; /// + /// Mouse button went from !Down to Down + /// + public fixed byte MouseClicked[5]; + /// /// Has mouse button been double-clicked? /// public fixed byte MouseDoubleClicked[5]; @@ -307,6 +319,26 @@ namespace ImGuiNET /// public fixed float MouseDownDurationPrev[5]; /// + /// Maximum distance, absolute, on each axis, of how much mouse has traveled from the clicking point + /// + public Vector2 MouseDragMaxDistanceAbs0; + /// + /// Maximum distance, absolute, on each axis, of how much mouse has traveled from the clicking point + /// + public Vector2 MouseDragMaxDistanceAbs1; + /// + /// Maximum distance, absolute, on each axis, of how much mouse has traveled from the clicking point + /// + public Vector2 MouseDragMaxDistanceAbs2; + /// + /// Maximum distance, absolute, on each axis, of how much mouse has traveled from the clicking point + /// + public Vector2 MouseDragMaxDistanceAbs3; + /// + /// Maximum distance, absolute, on each axis, of how much mouse has traveled from the clicking point + /// + public Vector2 MouseDragMaxDistanceAbs4; + /// /// Squared maximum distance of how much mouse has traveled from the click point /// public fixed float MouseDragMaxDistanceSqr[5]; diff --git a/src/ImGui.NET/TreeNodeFlags.cs b/src/ImGui.NET/TreeNodeFlags.cs index 96c122a..6e84d47 100644 --- a/src/ImGui.NET/TreeNodeFlags.cs +++ b/src/ImGui.NET/TreeNodeFlags.cs @@ -45,7 +45,10 @@ namespace ImGuiNET /// Display a bullet instead of arrow /// Bullet = 1 << 9, - + /// + /// Use FramePadding (even for an unframed text node) to vertically align text baseline + /// + FramePadding = 1 << 10, CollapsingHeader = Framed | NoAutoOpenOnLog }; }