From ce5038de786fd1b35f2b4ee716608d800ee5f983 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 18 Mar 2023 14:05:01 +0900 Subject: [PATCH] refactoring tool view --- src/DotRecast.Recast.Demo/RecastDemo.cs | 18 +++---- .../Settings/RcSettingsView.cs | 4 +- .../Tools/{ToolsUI.cs => ToolsView.cs} | 53 +++++++++---------- src/DotRecast.Recast.Demo/UI/IRcView.cs | 2 +- src/DotRecast.Recast.Demo/UI/RcViewSystem.cs | 15 ------ 5 files changed, 36 insertions(+), 56 deletions(-) rename src/DotRecast.Recast.Demo/Tools/{ToolsUI.cs => ToolsView.cs} (54%) diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index 2c975f7..c9b3864 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -95,7 +95,7 @@ public class RecastDemo : MouseListener private bool markerPositionSet; private readonly float[] markerPosition = new float[3]; - private ToolsUI toolsUI; + private ToolsView _toolsView; private RcSettingsView _rcSettingsView; private long prevFrameTime; private RecastDebugDraw dd; @@ -327,7 +327,7 @@ public class RecastDemo : MouseListener { DemoInputGeomProvider geom = DemoObjImporter.load(stream); //sample = new Sample(geom, ImmutableArray.Empty, null, settingsUI, dd); - toolsUI.setEnabled(true); + _toolsView.setEnabled(true); return geom; } @@ -351,7 +351,7 @@ public class RecastDemo : MouseListener if (mesh != null) { //sample = new Sample(null, ImmutableArray.Empty, mesh, settingsUI, dd); - toolsUI.setEnabled(true); + _toolsView.setEnabled(true); } } @@ -409,15 +409,16 @@ public class RecastDemo : MouseListener _rcSettingsView = new RcSettingsView(); - toolsUI = new ToolsUI( + _toolsView = new ToolsView( new TestNavmeshTool(), new OffMeshConnectionTool(), new ConvexVolumeTool(), new CrowdTool(), new JumpLinkBuilderTool(), - new DynamicUpdateTool()); + new DynamicUpdateTool() + ); - _viewSys = new RcViewSystem(window, _input, _rcSettingsView, toolsUI); + _viewSys = new RcViewSystem(window, _input, _rcSettingsView, _toolsView); DemoInputGeomProvider geom = loadInputMesh(Loader.ToBytes("nav_test.obj")); //sample = new Sample(geom, ImmutableArray.Empty, null, settingsUI, dd); @@ -701,13 +702,10 @@ public class RecastDemo : MouseListener private unsafe void OnWindowOnRender(double dt) { - _gl.ClearColor(Color.CornflowerBlue); + _gl.ClearColor(Color.CadetBlue); _gl.Clear(ClearBufferMask.ColorBufferBit); - mouseOverMenu = _viewSys.render(window, 0, 0, width, height, (int)mousePos[0], (int)mousePos[1]); - ImGui.Button("hello"); - ImGui.Button("world"); _imgui.Render(); diff --git a/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs b/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs index c70c17f..5e15be7 100644 --- a/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs +++ b/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs @@ -71,10 +71,10 @@ public class RcSettingsView : IRcView private bool meshInputTrigerred; private bool navMeshInputTrigerred; - public bool render(IWindow i, int x, int y, int width, int height, int mouseX, int mouseY) + public bool render(IWindow window, int x, int y, int width, int height, int mouseX, int mouseY) { ImGui.Begin("Properties"); - renderInternal(i, x, y, width, height, mouseX, mouseY); + renderInternal(window, x, y, width, height, mouseX, mouseY); ImGui.End(); return true; diff --git a/src/DotRecast.Recast.Demo/Tools/ToolsUI.cs b/src/DotRecast.Recast.Demo/Tools/ToolsView.cs similarity index 54% rename from src/DotRecast.Recast.Demo/Tools/ToolsUI.cs rename to src/DotRecast.Recast.Demo/Tools/ToolsView.cs index 18d0bed..8132d4c 100644 --- a/src/DotRecast.Recast.Demo/Tools/ToolsUI.cs +++ b/src/DotRecast.Recast.Demo/Tools/ToolsView.cs @@ -19,50 +19,47 @@ freely, subject to the following restrictions: using DotRecast.Core; using DotRecast.Recast.Demo.UI; +using ImGuiNET; using Silk.NET.Windowing; namespace DotRecast.Recast.Demo.Tools; -public class ToolsUI : IRcView +public class ToolsView : IRcView { //private readonly NkColor white = NkColor.create(); + private int _currentToolIdx = -1; private Tool currentTool; private bool enabled; private readonly Tool[] tools; - public ToolsUI(params Tool[] tools) + public ToolsView(params Tool[] tools) { this.tools = tools; } - public bool render(IWindow ctx, int x, int y, int width, int height, int mouseX, int mouseY) + public bool render(IWindow window, int x, int y, int width, int height, int mouseX, int mouseY) { bool mouseInside = false; - // nk_rgb(255, 255, 255, white); - // try (MemoryStack stack = stackPush()) { - // NkRect rect = NkRect.mallocStack(stack); - // if (nk_begin(ctx, "Tools", nk_rect(5, 5, 250, height - 10, rect), NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_TITLE)) { - // if (enabled) { - // foreach (Tool tool in tools) { - // nk_layout_row_dynamic(ctx, 20, 1); - // if (nk_option_label(ctx, tool.getName(), tool == currentTool)) { - // currentTool = tool; - // } - // } - // nk_layout_row_dynamic(ctx, 3, 1); - // nk_spacing(ctx, 1); - // if (currentTool != null) { - // currentTool.layout(ctx); - // } - // } - // nk_window_get_bounds(ctx, rect); - // if (mouseX >= rect.x() && mouseX <= rect.x() + rect.w() && mouseY >= rect.y() && mouseY <= rect.y() + rect.h()) { - // mouseInside = true; - // } - // } - // nk_end(ctx); - // } - return mouseInside; + ImGui.Begin("Tools"); + for (int i = 0; i < tools.Length; ++i) + { + var tool = tools[i]; + ImGui.RadioButton(tool.getName(), ref _currentToolIdx, i); + } + ImGui.NewLine(); + + if (0 > _currentToolIdx || _currentToolIdx >= tools.Length) + { + ImGui.End(); + return false; + } + + currentTool = tools[_currentToolIdx]; + ImGui.Text(currentTool.getName()); + ImGui.Separator(); + currentTool.layout(window); + ImGui.End(); + return true; } public void setEnabled(bool enabled) diff --git a/src/DotRecast.Recast.Demo/UI/IRcView.cs b/src/DotRecast.Recast.Demo/UI/IRcView.cs index 9885cb9..9cb4e93 100644 --- a/src/DotRecast.Recast.Demo/UI/IRcView.cs +++ b/src/DotRecast.Recast.Demo/UI/IRcView.cs @@ -22,5 +22,5 @@ namespace DotRecast.Recast.Demo.UI; public interface IRcView { - bool render(IWindow ctx, int x, int y, int width, int height, int mouseX, int mouseY); + bool render(IWindow window, int x, int y, int width, int height, int mouseX, int mouseY); } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/UI/RcViewSystem.cs b/src/DotRecast.Recast.Demo/UI/RcViewSystem.cs index 5dc3894..84d1cf3 100644 --- a/src/DotRecast.Recast.Demo/UI/RcViewSystem.cs +++ b/src/DotRecast.Recast.Demo/UI/RcViewSystem.cs @@ -41,21 +41,6 @@ public class RcViewSystem var mouse = new Mouse(input); _window = window; _gl = GL.GetApi(window); - // allocator = NkAllocator.create(); - // allocator.alloc((handle, old, size) => { - // long mem = nmemAlloc(size); - // if (mem == NULL) { - // throw new OutOfMemoryError(); - // } - // return mem; - // - // }); - // allocator.mfree((handle, ptr) => nmemFree(ptr)); - // background = NkColor.create(); - // nk_rgb(28, 48, 62, background); - // white = NkColor.create(); - // nk_rgb(255, 255, 255, white); - // nk_init(ctx, allocator, null); setupMouse(mouse); // setupClipboard(window); // glfwSetCharCallback(window, (w, codepoint) => nk_input_unicode(ctx, codepoint));