From 8ab65d357500133a386eb35894b025dde865265f Mon Sep 17 00:00:00 2001 From: Eric Mellino Date: Sun, 5 Mar 2017 15:31:16 -0800 Subject: [PATCH] More DrawList additions --- src/ImGui.NET/DrawList.cs | 33 +++++++++++++++++++++++++++++++++ src/ImGui.NET/ImGui.NET.csproj | 11 ++++++----- src/ImGui.NET/ImGui.cs | 15 +++++++++++++++ src/ImGui.NET/ImGuiNative.cs | 10 ++++++++-- 4 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/ImGui.NET/DrawList.cs b/src/ImGui.NET/DrawList.cs index 824d220..5e55c85 100644 --- a/src/ImGui.NET/DrawList.cs +++ b/src/ImGui.NET/DrawList.cs @@ -1,6 +1,8 @@ using System; +using System.Buffers; using System.Numerics; using System.Runtime.InteropServices; +using System.Text; namespace ImGuiNET { @@ -54,6 +56,37 @@ namespace ImGuiNET { ImGuiNative.ImDrawList_AddCircle(_nativeDrawList, center, radius, color, numSegments, thickness); } + + public unsafe void AddText(Vector2 position, string text, uint color) + { + int bytes = Encoding.UTF8.GetByteCount(text); + byte[] tempBytes = ArrayPool.Shared.Rent(bytes); + Encoding.UTF8.GetBytes(text, 0, text.Length, tempBytes, 0); + fixed (byte* bytePtr = &tempBytes[0]) + { + ImGuiNative.ImDrawList_AddText(_nativeDrawList, position, color, bytePtr, bytePtr + bytes); + } + } + + public void PushClipRect(Vector2 min, Vector2 max, bool intersectWithCurrentClipRect) + { + ImGuiNative.ImDrawList_PushClipRect(_nativeDrawList, min, max, intersectWithCurrentClipRect ? (byte)1 : (byte)0); + } + + public void PushClipRectFullScreen() + { + ImGuiNative.ImDrawList_PushClipRectFullScreen(_nativeDrawList); + } + + public void PopClipRect() + { + ImGuiNative.ImDrawList_PopClipRect(_nativeDrawList); + } + + public void AddDrawCmd() + { + ImGuiNative.ImDrawList_AddDrawCmd(_nativeDrawList); + } } /// diff --git a/src/ImGui.NET/ImGui.NET.csproj b/src/ImGui.NET/ImGui.NET.csproj index 3458056..8c5e283 100644 --- a/src/ImGui.NET/ImGui.NET.csproj +++ b/src/ImGui.NET/ImGui.NET.csproj @@ -16,11 +16,12 @@ bin\Release\ImGui.NET.xml - - - - - + + + + + + diff --git a/src/ImGui.NET/ImGui.cs b/src/ImGui.NET/ImGui.cs index a18c79b..73b4346 100644 --- a/src/ImGui.NET/ImGui.cs +++ b/src/ImGui.NET/ImGui.cs @@ -421,6 +421,11 @@ namespace ImGuiNET ImGuiNative.igSetNextWindowSize(size, condition); } + public static void SetNextWindowFocus() + { + ImGuiNative.igSetNextWindowFocus(); + } + public static void SetNextWindowPos(Vector2 position, SetCondition condition) { ImGuiNative.igSetNextWindowPos(position, condition); @@ -1002,6 +1007,16 @@ namespace ImGuiNET ImGuiNative.igSameLine(localPositionX, spacingW); } + public static void PushClipRect(Vector2 min, Vector2 max, bool intersectWithCurrentCliRect) + { + ImGuiNative.igPushClipRect(min, max, intersectWithCurrentCliRect ? (byte)1 : (byte)0); + } + + public static void PopClipRect() + { + ImGuiNative.igPopClipRect(); + } + public static bool IsLastItemHovered() { return ImGuiNative.igIsItemHovered(); diff --git a/src/ImGui.NET/ImGuiNative.cs b/src/ImGui.NET/ImGuiNative.cs index 11e2025..fbb41f1 100644 --- a/src/ImGui.NET/ImGuiNative.cs +++ b/src/ImGui.NET/ImGuiNative.cs @@ -604,6 +604,12 @@ namespace ImGuiNET //public static extern void igLogText(string fmt, ...); public static extern void igLogText(string fmt); + // Clipping + [DllImport(cimguiLib)] + public static extern void igPushClipRect(Vector2 clip_rect_min, Vector2 clip_rect_max, byte intersect_with_current_clip_rect); + [DllImport(cimguiLib)] + public static extern void igPopClipRect(); + // Utilities [DllImport(cimguiLib)] [return: MarshalAs(UnmanagedType.I1)] @@ -831,9 +837,9 @@ namespace ImGuiNET [DllImport(cimguiLib)] public static extern void ImDrawList_AddCircleFilled(NativeDrawList* list, Vector2 centre, float radius, uint col, int num_segments); [DllImport(cimguiLib)] - public static extern void ImDrawList_AddText(NativeDrawList* list, Vector2 pos, uint col, char* text_begin, char* text_end); + public static extern void ImDrawList_AddText(NativeDrawList* list, Vector2 pos, uint col, byte* text_begin, byte* text_end); [DllImport(cimguiLib)] - public static extern void ImDrawList_AddTextExt(NativeDrawList* list, NativeFont* font, float font_size, Vector2 pos, uint col, char* text_begin, char* text_end, float wrap_width, Vector4* cpu_fine_clip_rect); + public static extern void ImDrawList_AddTextExt(NativeDrawList* list, NativeFont* font, float font_size, Vector2 pos, uint col, byte* text_begin, byte* text_end, float wrap_width, Vector4* cpu_fine_clip_rect); [DllImport(cimguiLib)] public static extern void ImDrawList_AddImage(NativeDrawList* list, void* user_texture_id, Vector2 a, Vector2 b, Vector2 uv0, Vector2 uv1, uint col); [DllImport(cimguiLib)]