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 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<RecastBuilderResult>.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<RecastBuilderResult>.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<RecastBuilderResult>.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();

View File

@ -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;

View File

@ -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)

View File

@ -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);
}

View File

@ -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));