Skip to content

Commit 01fced1

Browse files
committed
[WIP] Viewport support.
1 parent 4c9e157 commit 01fced1

31 files changed

+13783
-11408
lines changed

deps/cimgui/win-x64/cimgui.dll

915 KB
Binary file not shown.

src/CodeGenerator/definitions.json

+10,939-10,104
Large diffs are not rendered by default.

src/CodeGenerator/structs_and_enums.json

+1,728-1,251
Large diffs are not rendered by default.

src/ImGui.NET.SampleProgram.XNA/ImGuiRenderer.cs

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ protected virtual Effect UpdateEffect(Texture2D texture)
197197

198198
// MonoGame-specific //////////////////////
199199
var offset = .5f;
200+
offset = 0f;
200201
///////////////////////////////////////////
201202

202203
// FNA-specific ///////////////////////////
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using System.Text;
4+
5+
namespace ImGui.NET.SampleProgram
6+
{
7+
public class FixedAsciiString : IDisposable
8+
{
9+
public IntPtr DataPtr { get; }
10+
11+
public unsafe FixedAsciiString(string s)
12+
{
13+
int byteCount = Encoding.ASCII.GetByteCount(s);
14+
DataPtr = Marshal.AllocHGlobal(byteCount + 1);
15+
fixed (char* sPtr = s)
16+
{
17+
int end = Encoding.ASCII.GetBytes(sPtr, s.Length, (byte*)DataPtr, byteCount);
18+
((byte*)DataPtr)[end] = 0;
19+
}
20+
}
21+
22+
public void Dispose()
23+
{
24+
Marshal.FreeHGlobal(DataPtr);
25+
}
26+
}
27+
}

src/ImGui.NET.SampleProgram/ImGui.NET.SampleProgram.csproj

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
</PropertyGroup>
88

9+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
10+
<Prefer32Bit>true</Prefer32Bit>
11+
</PropertyGroup>
12+
913
<ItemGroup>
1014
<ProjectReference Include="..\ImGui.NET\ImGui.NET.csproj" />
11-
<PackageReference Include="Veldrid" Version="4.3.3" />
12-
<PackageReference Include="Veldrid.StartupUtilities" Version="4.3.3" />
15+
<PackageReference Include="Veldrid" Version="4.5.0" />
16+
<PackageReference Include="Veldrid.StartupUtilities" Version="4.5.0" />
1317
</ItemGroup>
1418

1519
<ItemGroup>

src/ImGui.NET.SampleProgram/ImGuiController.cs

+251-10
Large diffs are not rendered by default.

src/ImGui.NET.SampleProgram/Program.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class Program
2727
private static bool _showMemoryEditor = false;
2828
private static byte[] _memoryEditorData;
2929

30+
private static string _testInput = "TestInputDefaultValue";
31+
3032
static void SetThing(out float i, float val) { i = val; }
3133

3234
static void Main(string[] args)
@@ -35,6 +37,7 @@ static void Main(string[] args)
3537
VeldridStartup.CreateWindowAndGraphicsDevice(
3638
new WindowCreateInfo(50, 50, 1280, 720, WindowState.Normal, "ImGui.NET Sample Program"),
3739
new GraphicsDeviceOptions(true, null, true),
40+
GraphicsBackend.Direct3D11,
3841
out _window,
3942
out _gd);
4043
_window.Resized += () =>
@@ -43,7 +46,7 @@ static void Main(string[] args)
4346
_controller.WindowResized(_window.Width, _window.Height);
4447
};
4548
_cl = _gd.ResourceFactory.CreateCommandList();
46-
_controller = new ImGuiController(_gd, _gd.MainSwapchain.Framebuffer.OutputDescription, _window.Width, _window.Height);
49+
_controller = new ImGuiController(_gd, _window, _gd.MainSwapchain.Framebuffer.OutputDescription, _window.Width, _window.Height);
4750
_memoryEditor = new MemoryEditor();
4851
Random random = new Random();
4952
_memoryEditorData = Enumerable.Range(0, 1024).Select(i => (byte)random.Next(255)).ToArray();
@@ -64,6 +67,7 @@ static void Main(string[] args)
6467
_cl.End();
6568
_gd.SubmitCommands(_cl);
6669
_gd.SwapBuffers(_gd.MainSwapchain);
70+
_controller.SwapExtraWindows(_gd);
6771
}
6872

6973
// Clean up Veldrid resources
@@ -85,7 +89,13 @@ private static unsafe void SubmitUI()
8589
ImGui.SliderFloat("float", ref _f, 0, 1, _f.ToString("0.000"), 1); // Edit 1 float using a slider from 0.0f to 1.0f
8690
//ImGui.ColorEdit3("clear color", ref _clearColor); // Edit 3 floats representing a color
8791

92+
if (ImGui.InputTextMultiline("TestLabel", ref _testInput, ushort.MaxValue, new Vector2(200, 200)))
93+
{
94+
95+
}
96+
8897
ImGui.Text($"Mouse position: {ImGui.GetMousePos()}");
98+
ImGui.Text($"Mouse down: {ImGui.GetIO().MouseDown[0]}");
8999

90100
ImGui.Checkbox("Demo Window", ref _showDemoWindow); // Edit bools storing our windows open/close state
91101
ImGui.Checkbox("Another Window", ref _showAnotherWindow);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using ImGuiNET;
2+
using System;
3+
using System.Runtime.InteropServices;
4+
using Veldrid;
5+
using Veldrid.Sdl2;
6+
using Veldrid.StartupUtilities;
7+
8+
namespace ImGui.NET.SampleProgram
9+
{
10+
public class VeldridImGuiWindow : IDisposable
11+
{
12+
private readonly GCHandle _gcHandle;
13+
private readonly GraphicsDevice _gd;
14+
private readonly ImGuiViewportPtr _vp;
15+
private readonly Sdl2Window _window;
16+
private readonly Swapchain _sc;
17+
18+
public Sdl2Window Window => _window;
19+
public Swapchain Swapchain => _sc;
20+
21+
public VeldridImGuiWindow(GraphicsDevice gd, ImGuiViewportPtr vp)
22+
{
23+
_gcHandle = GCHandle.Alloc(this);
24+
_gd = gd;
25+
_vp = vp;
26+
27+
SDL_WindowFlags flags = SDL_WindowFlags.Hidden;
28+
if ((vp.Flags & ImGuiViewportFlags.NoTaskBarIcon) != 0)
29+
{
30+
flags |= SDL_WindowFlags.SkipTaskbar;
31+
}
32+
if ((vp.Flags & ImGuiViewportFlags.NoDecoration) != 0)
33+
{
34+
flags |= SDL_WindowFlags.Borderless;
35+
}
36+
else
37+
{
38+
flags |= SDL_WindowFlags.Resizable;
39+
}
40+
41+
if ((vp.Flags & ImGuiViewportFlags.TopMost) != 0)
42+
{
43+
flags |= SDL_WindowFlags.AlwaysOnTop;
44+
}
45+
46+
_window = new Sdl2Window(
47+
"No Title Yet",
48+
(int)vp.Pos.X, (int)vp.Pos.Y,
49+
(int)vp.Size.X, (int)vp.Size.Y,
50+
flags,
51+
false);
52+
_window.Resized += () => _vp.PlatformRequestResize = true;
53+
_window.Moved += p => _vp.PlatformRequestMove = true;
54+
_window.Closed += () => _vp.PlatformRequestClose = true;
55+
56+
SwapchainSource scSource = VeldridStartup.GetSwapchainSource(_window);
57+
SwapchainDescription scDesc = new SwapchainDescription(scSource, (uint)_window.Width, (uint)_window.Height, null, true, false);
58+
_sc = _gd.ResourceFactory.CreateSwapchain(scDesc);
59+
_window.Resized += () => _sc.Resize((uint)_window.Width, (uint)_window.Height);
60+
61+
vp.PlatformUserData = (IntPtr)_gcHandle;
62+
}
63+
64+
public VeldridImGuiWindow(GraphicsDevice gd, ImGuiViewportPtr vp, Sdl2Window window)
65+
{
66+
_gcHandle = GCHandle.Alloc(this);
67+
_gd = gd;
68+
_vp = vp;
69+
_window = window;
70+
vp.PlatformUserData = (IntPtr)_gcHandle;
71+
}
72+
73+
public void Update()
74+
{
75+
_window.PumpEvents();
76+
}
77+
78+
public void Dispose()
79+
{
80+
_sc.Dispose();
81+
_window.Close();
82+
_gcHandle.Free();
83+
}
84+
}
85+
}

src/ImGui.NET/Delegates.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Numerics;
3+
4+
namespace ImGuiNET
5+
{
6+
public delegate void Platform_CreateWindow(ImGuiViewportPtr vp); // Create a new platform window for the given viewport
7+
public delegate void Platform_DestroyWindow(ImGuiViewportPtr vp);
8+
public delegate void Platform_ShowWindow(ImGuiViewportPtr vp); // Newly created windows are initially hidden so SetWindowPos/Size/Title can be called on them first
9+
public delegate void Platform_SetWindowPos(ImGuiViewportPtr vp, Vector2 pos);
10+
public unsafe delegate void Platform_GetWindowPos(ImGuiViewportPtr vp, Vector2* outPos);
11+
public delegate void Platform_SetWindowSize(ImGuiViewportPtr vp, Vector2 size);
12+
public unsafe delegate void Platform_GetWindowSize(ImGuiViewportPtr vp, Vector2* outSize);
13+
public delegate void Platform_SetWindowFocus(ImGuiViewportPtr vp); // Move window to front and set input focus
14+
public delegate byte Platform_GetWindowFocus(ImGuiViewportPtr vp);
15+
public delegate byte Platform_GetWindowMinimized(ImGuiViewportPtr vp);
16+
public delegate void Platform_SetWindowTitle(ImGuiViewportPtr vp, IntPtr title);
17+
}

src/ImGui.NET/Generated/ImDrawListFlags.gen.cs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace ImGuiNET
33
[System.Flags]
44
public enum ImDrawListFlags
55
{
6+
None = 0,
67
AntiAliasedLines = 1 << 0,
78
AntiAliasedFill = 1 << 1,
89
}

0 commit comments

Comments
 (0)