diff --git a/Hypercube.Client/Graphics/ImGui/ImGui.cs b/Hypercube.Client/Graphics/ImGui/ImGui.cs index 7772fdf..410eb85 100644 --- a/Hypercube.Client/Graphics/ImGui/ImGui.cs +++ b/Hypercube.Client/Graphics/ImGui/ImGui.cs @@ -76,39 +76,4 @@ private void OnInputScroll(ref ScrollHandledEvent args) { _controller.UpdateMouseScroll(args.Offset); } - - public void Begin(string name) - { - _controller.Begin(name); - } - - public void Text(string label) - { - _controller.Text(label); - } - - public bool Button(string label) - { - return _controller.Button(label); - } - - public void End() - { - _controller.End(); - } - - public void DockSpaceOverViewport() - { - _controller.DockSpaceOverViewport(); - } - - public void ShowDemoWindow() - { - _controller.ShowDemoWindow(); - } - - public void ShowDebugInput() - { - _controller.ShowDebugInput(); - } } \ No newline at end of file diff --git a/Hypercube.Example.Client/Example.cs b/Hypercube.Example.Client/Example.cs index 5c17a87..1d6f3da 100644 --- a/Hypercube.Example.Client/Example.cs +++ b/Hypercube.Example.Client/Example.cs @@ -45,16 +45,7 @@ public void PostInject() private void Startup(ref RuntimeStartupEvent args) { - for (var i = 0; i < 10; i++) - { - var x = _random.NextSingle() * 10 - 5; - var y = _random.NextSingle() * 10 - 5; - - var coord = new SceneCoordinates(SceneId.Nullspace, new Vector2(x, y)); - CreateEntity(coord, new RectangleShape(Vector2.One * 2f)); - CreateEntity(coord, new CircleShape(1f)); - } - + CreateEntity(new SceneCoordinates(SceneId.Nullspace, new Vector2(0, 11)), new RectangleShape(new Vector2(40, 1)), BodyType.Static); CreateEntity(new SceneCoordinates(SceneId.Nullspace, new Vector2(0, -11)), @@ -80,7 +71,17 @@ private void Startup(ref RuntimeStartupEvent args) private void ImGuiRender(ref ImGuiRenderEvent args) { var imGui = args.Instance; - imGui.ShowDebugInput(); + + imGui.Begin("Test"); + if (imGui.Button("Spawn")) + { + var x = _random.NextSingle() * 10 - 5; + var y = _random.NextSingle() * 10 - 5; + var coord = new SceneCoordinates(SceneId.Nullspace, new Vector2(x, y)); + CreateEntity(coord, new RectangleShape(Vector2.One * 2f)); + CreateEntity(coord, new CircleShape(1f)); + } + imGui.End(); } private void CreateEntity(SceneCoordinates coordinates, IShape shape, BodyType type = BodyType.Dynamic) diff --git a/Hypercube.ImGui/IImGui.cs b/Hypercube.ImGui/IImGui.cs index bb0718c..b9b16fa 100644 --- a/Hypercube.ImGui/IImGui.cs +++ b/Hypercube.ImGui/IImGui.cs @@ -1,13 +1,119 @@ -namespace Hypercube.ImGui; +using Hypercube.Mathematics.Vectors; +using ImGuiNET; +using JetBrains.Annotations; +namespace Hypercube.ImGui; + +[PublicAPI] public interface IImGui -{ - void Begin(string name); - void Text(string label); - bool Button(string label); - void End(); - - void DockSpaceOverViewport(); - void ShowDemoWindow(); - void ShowDebugInput(); +{ + public void Dummy(Vector2 size) + { + ImGuiNET.ImGui.Dummy(size); + } + + public bool ArrowButton(string label, ImGuiDirection direction) + { + return ImGuiNET.ImGui.ArrowButton(label, (ImGuiDir) direction); + } + + public bool CheckboxFlags(string label, ref int flags, int value) + { + return ImGuiNET.ImGui.CheckboxFlags(label, ref flags, value); + } + + public void Text(string label) + { + ImGuiNET.ImGui.Text(label); + } + + public bool Button(string label) + { + return ImGuiNET.ImGui.Button(label); + } + + public void Begin(string name) + { + ImGuiNET.ImGui.Begin(name); + } + + public bool Checkbox(string label, ref bool value) + { + return ImGuiNET.ImGui.Checkbox(label, ref value); + } + + public void Bullet() + { + ImGuiNET.ImGui.Bullet(); + } + + public void Columns() + { + ImGuiNET.ImGui.Columns(); + } + + public void Columns(int count) + { + ImGuiNET.ImGui.Columns(count); + } + + public void Columns(int count, string id) + { + ImGuiNET.ImGui.Columns(count, id); + } + + public void Columns(int count, string id, bool border) + { + ImGuiNET.ImGui.Columns(count, id, border); + } + + public void Combo(string label, ref int item, string separatedItems) + { + ImGuiNET.ImGui.Combo(label, ref item, separatedItems); + } + + public void Image(nint texture, Vector2 size) + { + ImGuiNET.ImGui.Image(texture, size); + } + + public void Image(nint texture, Vector2 size, Vector2 uv) + { + ImGuiNET.ImGui.Image(texture, size, uv); + } + + public void Separator() + { + ImGuiNET.ImGui.Separator(); + } + + public void Spacing() + { + ImGuiNET.ImGui.Spacing(); + } + + public void BeginGroup() + { + ImGuiNET.ImGui.BeginGroup(); + } + + public void BeginMenu(string label) + { + ImGuiNET.ImGui.BeginMenu(label); + } + + public void End() + { + ImGuiNET.ImGui.End(); + } + + public void DockSpaceOverViewport() + { + ImGuiNET.ImGui.DockSpaceOverViewport(); + } + + public void ShowDemoWindow() + { + ImGuiNET.ImGui.ShowDemoWindow(); + } } \ No newline at end of file diff --git a/Hypercube.ImGui/IImGuiController.cs b/Hypercube.ImGui/IImGuiController.cs index 9a74e4a..60d078d 100644 --- a/Hypercube.ImGui/IImGuiController.cs +++ b/Hypercube.ImGui/IImGuiController.cs @@ -1,8 +1,10 @@ using Hypercube.Input; using Hypercube.Mathematics.Vectors; +using JetBrains.Annotations; namespace Hypercube.ImGui; +[PublicAPI] public interface IImGuiController : IImGui { event Action? OnErrorHandled; @@ -15,5 +17,4 @@ public interface IImGuiController : IImGui void UpdateMousePosition(Vector2Int position); void UpdateMouseButtons(MouseButton button, bool state); void UpdateMouseScroll(Vector2 offset); - void UpdateMouseCursor(); } \ No newline at end of file diff --git a/Hypercube.ImGui/ImGuiDirection.cs b/Hypercube.ImGui/ImGuiDirection.cs new file mode 100644 index 0000000..63c9a42 --- /dev/null +++ b/Hypercube.ImGui/ImGuiDirection.cs @@ -0,0 +1,16 @@ +using JetBrains.Annotations; + +namespace Hypercube.ImGui; + +[PublicAPI] +public enum ImGuiDirection +{ + None = -1, + + Left = 0, + Right = 1, + Up = 2, + Down = 3, + + Count = 4 +} \ No newline at end of file diff --git a/Hypercube.ImGui/ImGuiFactory.cs b/Hypercube.ImGui/ImGuiFactory.cs index a7da7ba..e78cb79 100644 --- a/Hypercube.ImGui/ImGuiFactory.cs +++ b/Hypercube.ImGui/ImGuiFactory.cs @@ -1,12 +1,14 @@ using Hypercube.Graphics.Windowing; using Hypercube.ImGui.Implementations; +using JetBrains.Annotations; namespace Hypercube.ImGui; +[PublicAPI] public static class ImGuiFactory { public static IImGuiController Create(WindowHandle window) { - return new GlfwImGuiController(window); + return new OpenGLImGuiController(window); } } \ No newline at end of file diff --git a/Hypercube.ImGui/Implementations/GlfwImGuiController.Input.cs b/Hypercube.ImGui/Implementations/OpenGLImGuiController.Input.cs similarity index 87% rename from Hypercube.ImGui/Implementations/GlfwImGuiController.Input.cs rename to Hypercube.ImGui/Implementations/OpenGLImGuiController.Input.cs index f593ece..5b53c2f 100644 --- a/Hypercube.ImGui/Implementations/GlfwImGuiController.Input.cs +++ b/Hypercube.ImGui/Implementations/OpenGLImGuiController.Input.cs @@ -3,7 +3,7 @@ namespace Hypercube.ImGui.Implementations; -public partial class GlfwImGuiController +public partial class OpenGLImGuiController { private const int MouseButtons = 5; @@ -30,9 +30,4 @@ public void UpdateMouseScroll(Vector2 offset) _io.MouseWheelH = offset.X; _io.MouseWheel = offset.Y; } - - public void UpdateMouseCursor() - { - - } } \ No newline at end of file diff --git a/Hypercube.ImGui/Implementations/GlfwImGuiController.Render.cs b/Hypercube.ImGui/Implementations/OpenGLImGuiController.Render.cs similarity index 99% rename from Hypercube.ImGui/Implementations/GlfwImGuiController.Render.cs rename to Hypercube.ImGui/Implementations/OpenGLImGuiController.Render.cs index 40dba3f..d9c4713 100644 --- a/Hypercube.ImGui/Implementations/GlfwImGuiController.Render.cs +++ b/Hypercube.ImGui/Implementations/OpenGLImGuiController.Render.cs @@ -7,7 +7,7 @@ namespace Hypercube.ImGui.Implementations; -public partial class GlfwImGuiController +public partial class OpenGLImGuiController { public void Render() { diff --git a/Hypercube.ImGui/Implementations/GlfwImGuiController.cs b/Hypercube.ImGui/Implementations/OpenGLImGuiController.cs similarity index 81% rename from Hypercube.ImGui/Implementations/GlfwImGuiController.cs rename to Hypercube.ImGui/Implementations/OpenGLImGuiController.cs index bab287b..6c8fc5f 100644 --- a/Hypercube.ImGui/Implementations/GlfwImGuiController.cs +++ b/Hypercube.ImGui/Implementations/OpenGLImGuiController.cs @@ -6,14 +6,12 @@ using Hypercube.OpenGL.Utilities.Helpers; using ImGuiNET; using JetBrains.Annotations; -using OpenTK.Windowing.GraphicsLibraryFramework; using OpenToolkit.Graphics.OpenGL4; -using static OpenTK.Windowing.GraphicsLibraryFramework.GLFWCallbacks; namespace Hypercube.ImGui.Implementations; [PublicAPI] -public partial class GlfwImGuiController : IImGuiController, IDisposable +public partial class OpenGLImGuiController : IImGuiController, IDisposable { private const int Framerate = 60; @@ -35,7 +33,7 @@ public partial class GlfwImGuiController : IImGuiController, IDisposable private int _indexBufferSize; private bool _frameBegun; - public GlfwImGuiController(WindowHandle window) + public OpenGLImGuiController(WindowHandle window) { _window = window; _mousePressed = new bool[(int) ImGuiMouseButton.COUNT]; @@ -46,7 +44,6 @@ public void Initialize() { var context = ImGuiNET.ImGui.CreateContext(); ImGuiNET.ImGui.SetCurrentContext(context); - ImGuiNET.ImGui.StyleColorsDark(); InitializeIO(); @@ -123,51 +120,13 @@ public void Update(float deltaTime) ImGuiNET.ImGui.NewFrame(); } - public void Begin(string name) - { - ImGuiNET.ImGui.Begin(name); - } - - public void Text(string label) - { - ImGuiNET.ImGui.Text(label); - } - - public bool Button(string label) - { - return ImGuiNET.ImGui.Button(label); - } - - public void End() - { - ImGuiNET.ImGui.End(); - } - - public void DockSpaceOverViewport() - { - ImGuiNET.ImGui.DockSpaceOverViewport(); - } - - public void ShowDemoWindow() - { - ImGuiNET.ImGui.ShowDemoWindow(); - } - - public void ShowDebugInput() - { - Begin("ImGui input"); - - Text($"Mouse LBM: {_io.MouseDown[0]}"); - Text($"Mouse RBM: {_io.MouseDown[1]}"); - Text($"Mouse position: {_io.MousePos}"); - Text($"Mouse wheel: <{_io.MouseWheel}, {_io.MouseWheelH}>"); - - End(); - } - public void Dispose() { + _shader.Dispose(); + _vao.Dispose(); + _vbo.Dispose(); + _ebo.Dispose(); } private void CreateFontsTexture() @@ -201,7 +160,7 @@ private void CreateFontsTexture() private void CheckErrors(string title) { - var errorString = GLHelper.CheckErrors($"{nameof(GlfwImGuiController)} {title}"); + var errorString = GLHelper.CheckErrors($"{nameof(OpenGLImGuiController)} {title}"); if (errorString == string.Empty) return;