refactoring tool view

This commit is contained in:
ikpil 2023-03-18 14:05:01 +09:00
parent 804316b600
commit ce5038de78
5 changed files with 36 additions and 56 deletions

View File

@ -95,7 +95,7 @@ public class RecastDemo : MouseListener
private bool markerPositionSet; private bool markerPositionSet;
private readonly float[] markerPosition = new float[3]; private readonly float[] markerPosition = new float[3];
private ToolsUI toolsUI; private ToolsView _toolsView;
private RcSettingsView _rcSettingsView; private RcSettingsView _rcSettingsView;
private long prevFrameTime; private long prevFrameTime;
private RecastDebugDraw dd; private RecastDebugDraw dd;
@ -327,7 +327,7 @@ public class RecastDemo : MouseListener
{ {
DemoInputGeomProvider geom = DemoObjImporter.load(stream); DemoInputGeomProvider geom = DemoObjImporter.load(stream);
//sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsUI, dd); //sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsUI, dd);
toolsUI.setEnabled(true); _toolsView.setEnabled(true);
return geom; return geom;
} }
@ -351,7 +351,7 @@ public class RecastDemo : MouseListener
if (mesh != null) if (mesh != null)
{ {
//sample = new Sample(null, ImmutableArray<RecastBuilderResult>.Empty, mesh, settingsUI, dd); //sample = new Sample(null, ImmutableArray<RecastBuilderResult>.Empty, mesh, settingsUI, dd);
toolsUI.setEnabled(true); _toolsView.setEnabled(true);
} }
} }
@ -409,15 +409,16 @@ public class RecastDemo : MouseListener
_rcSettingsView = new RcSettingsView(); _rcSettingsView = new RcSettingsView();
toolsUI = new ToolsUI( _toolsView = new ToolsView(
new TestNavmeshTool(), new TestNavmeshTool(),
new OffMeshConnectionTool(), new OffMeshConnectionTool(),
new ConvexVolumeTool(), new ConvexVolumeTool(),
new CrowdTool(), new CrowdTool(),
new JumpLinkBuilderTool(), 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")); DemoInputGeomProvider geom = loadInputMesh(Loader.ToBytes("nav_test.obj"));
//sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsUI, dd); //sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsUI, dd);
@ -701,13 +702,10 @@ public class RecastDemo : MouseListener
private unsafe void OnWindowOnRender(double dt) private unsafe void OnWindowOnRender(double dt)
{ {
_gl.ClearColor(Color.CornflowerBlue); _gl.ClearColor(Color.CadetBlue);
_gl.Clear(ClearBufferMask.ColorBufferBit); _gl.Clear(ClearBufferMask.ColorBufferBit);
mouseOverMenu = _viewSys.render(window, 0, 0, width, height, (int)mousePos[0], (int)mousePos[1]); mouseOverMenu = _viewSys.render(window, 0, 0, width, height, (int)mousePos[0], (int)mousePos[1]);
ImGui.Button("hello");
ImGui.Button("world");
_imgui.Render(); _imgui.Render();

View File

@ -71,10 +71,10 @@ public class RcSettingsView : IRcView
private bool meshInputTrigerred; private bool meshInputTrigerred;
private bool navMeshInputTrigerred; 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"); ImGui.Begin("Properties");
renderInternal(i, x, y, width, height, mouseX, mouseY); renderInternal(window, x, y, width, height, mouseX, mouseY);
ImGui.End(); ImGui.End();
return true; return true;

View File

@ -19,50 +19,47 @@ freely, subject to the following restrictions:
using DotRecast.Core; using DotRecast.Core;
using DotRecast.Recast.Demo.UI; using DotRecast.Recast.Demo.UI;
using ImGuiNET;
using Silk.NET.Windowing; using Silk.NET.Windowing;
namespace DotRecast.Recast.Demo.Tools; namespace DotRecast.Recast.Demo.Tools;
public class ToolsUI : IRcView public class ToolsView : IRcView
{ {
//private readonly NkColor white = NkColor.create(); //private readonly NkColor white = NkColor.create();
private int _currentToolIdx = -1;
private Tool currentTool; private Tool currentTool;
private bool enabled; private bool enabled;
private readonly Tool[] tools; private readonly Tool[] tools;
public ToolsUI(params Tool[] tools) public ToolsView(params Tool[] tools)
{ {
this.tools = 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; bool mouseInside = false;
// nk_rgb(255, 255, 255, white); ImGui.Begin("Tools");
// try (MemoryStack stack = stackPush()) { for (int i = 0; i < tools.Length; ++i)
// 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)) { var tool = tools[i];
// if (enabled) { ImGui.RadioButton(tool.getName(), ref _currentToolIdx, i);
// foreach (Tool tool in tools) { }
// nk_layout_row_dynamic(ctx, 20, 1); ImGui.NewLine();
// if (nk_option_label(ctx, tool.getName(), tool == currentTool)) {
// currentTool = tool; if (0 > _currentToolIdx || _currentToolIdx >= tools.Length)
// } {
// } ImGui.End();
// nk_layout_row_dynamic(ctx, 3, 1); return false;
// nk_spacing(ctx, 1); }
// if (currentTool != null) {
// currentTool.layout(ctx); currentTool = tools[_currentToolIdx];
// } ImGui.Text(currentTool.getName());
// } ImGui.Separator();
// nk_window_get_bounds(ctx, rect); currentTool.layout(window);
// if (mouseX >= rect.x() && mouseX <= rect.x() + rect.w() && mouseY >= rect.y() && mouseY <= rect.y() + rect.h()) { ImGui.End();
// mouseInside = true; return true;
// }
// }
// nk_end(ctx);
// }
return mouseInside;
} }
public void setEnabled(bool enabled) public void setEnabled(bool enabled)

View File

@ -22,5 +22,5 @@ namespace DotRecast.Recast.Demo.UI;
public interface IRcView 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);
} }

View File

@ -41,21 +41,6 @@ public class RcViewSystem
var mouse = new Mouse(input); var mouse = new Mouse(input);
_window = window; _window = window;
_gl = GL.GetApi(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); setupMouse(mouse);
// setupClipboard(window); // setupClipboard(window);
// glfwSetCharCallback(window, (w, codepoint) => nk_input_unicode(ctx, codepoint)); // glfwSetCharCallback(window, (w, codepoint) => nk_input_unicode(ctx, codepoint));