From 4e09b573be94ade2d037e8611d086dd9a0b0db60 Mon Sep 17 00:00:00 2001 From: ikpil Date: Thu, 23 Mar 2023 00:29:25 +0900 Subject: [PATCH] added mouse inside --- src/DotRecast.Recast.Demo/RecastDemo.cs | 93 ++++++++++--------- .../Settings/RcSettingsView.cs | 18 ++-- .../Tools/ConvexVolumeTool.cs | 2 +- src/DotRecast.Recast.Demo/Tools/CrowdTool.cs | 2 +- .../Tools/DynamicUpdateTool.cs | 2 +- .../Tools/JumpLinkBuilderTool.cs | 2 +- .../Tools/OffMeshConnectionTool.cs | 2 +- .../Tools/TestNavmeshTool.cs | 2 +- src/DotRecast.Recast.Demo/Tools/Tool.cs | 2 +- src/DotRecast.Recast.Demo/Tools/ToolsView.cs | 14 ++- src/DotRecast.Recast.Demo/UI/IRcView.cs | 3 +- src/DotRecast.Recast.Demo/UI/RcViewSystem.cs | 19 ++-- 12 files changed, 85 insertions(+), 76 deletions(-) diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index 3822392..ac159d6 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -83,7 +83,7 @@ public class RecastDemo private readonly float[] mousePos = new float[2]; - private bool mouseOverMenu; + private bool _mouseOverMenu; private bool pan; private bool movedDuringPan; private bool rotate; @@ -109,7 +109,7 @@ public class RecastDemo private float _moveUp; private float _moveDown; private float _moveAccel; - + private bool markerPositionSet; private readonly float[] markerPosition = new float[3]; private ToolsView toolsUI; @@ -132,17 +132,17 @@ public class RecastDemo if (scrollWheel.Y < 0) { // wheel down - // if (!mouseOverMenu) - // { - scrollZoom += 1.0f; - //} + if (!_mouseOverMenu) + { + scrollZoom += 1.0f; + } } else { - // if (!mouseOverMenu) - // { - scrollZoom -= 1.0f; - //} + if (!_mouseOverMenu) + { + scrollZoom -= 1.0f; + } } float[] modelviewMatrix = dd.viewMatrix(cameraPos, cameraEulers); @@ -196,30 +196,30 @@ public class RecastDemo { if (button == MouseButton.Right) { - // if (!mouseOverMenu) - // { - // Rotate view - rotate = true; - movedDuringRotate = false; - origMousePos[0] = mousePos[0]; - origMousePos[1] = mousePos[1]; - origCameraEulers[0] = cameraEulers[0]; - origCameraEulers[1] = cameraEulers[1]; - //} + if (!_mouseOverMenu) + { + // Rotate view + rotate = true; + movedDuringRotate = false; + origMousePos[0] = mousePos[0]; + origMousePos[1] = mousePos[1]; + origCameraEulers[0] = cameraEulers[0]; + origCameraEulers[1] = cameraEulers[1]; + } } else if (button == MouseButton.Middle) { - // if (!mouseOverMenu) - // { - // Pan view - pan = true; - movedDuringPan = false; - origMousePos[0] = mousePos[0]; - origMousePos[1] = mousePos[1]; - origCameraPos[0] = cameraPos[0]; - origCameraPos[1] = cameraPos[1]; - origCameraPos[2] = cameraPos[2]; - //} + if (!_mouseOverMenu) + { + // Pan view + pan = true; + movedDuringPan = false; + origMousePos[0] = mousePos[0]; + origMousePos[1] = mousePos[1]; + origCameraPos[0] = cameraPos[0]; + origCameraPos[1] = cameraPos[1]; + origCameraPos[2] = cameraPos[2]; + } } } else @@ -228,23 +228,23 @@ public class RecastDemo if (button == MouseButton.Right) { rotate = false; - // if (!mouseOverMenu) - // { - if (!movedDuringRotate) + if (!_mouseOverMenu) { - processHitTest = true; - processHitTestShift = true; + if (!movedDuringRotate) + { + processHitTest = true; + processHitTestShift = true; + } } - //} } else if (button == MouseButton.Left) { - // if (!mouseOverMenu) - // { - processHitTest = true; - //processHitTestShift = (mods & Keys.GLFW_MOD_SHIFT) != 0 ? true : false; - //processHitTestShift = (mods & Keys.) != 0 ? true : false; - //} + if (!_mouseOverMenu) + { + processHitTest = true; + //processHitTestShift = (mods & Keys.GLFW_MOD_SHIFT) != 0 ? true : false; + //processHitTestShift = (mods & Keys.) != 0 ? true : false; + } } else if (button == MouseButton.Middle) { @@ -454,8 +454,8 @@ public class RecastDemo var tempMoveBack = keyboard.IsKeyPressed(Key.S) || keyboard.IsKeyPressed(Key.Down) ? 1.0f : -1f; var tempMoveRight = keyboard.IsKeyPressed(Key.D) || keyboard.IsKeyPressed(Key.Right) ? 1.0f : -1f; var tempMoveUp = keyboard.IsKeyPressed(Key.Q) || keyboard.IsKeyPressed(Key.PageUp) ? 1.0f : -1f; - var tempMoveDown= keyboard.IsKeyPressed(Key.E) || keyboard.IsKeyPressed(Key.PageDown) ? 1.0f : -1f; - var tempMoveAccel= keyboard.IsKeyPressed(Key.ShiftLeft) || keyboard.IsKeyPressed(Key.ShiftRight) ? 1.0f : -1f; + var tempMoveDown = keyboard.IsKeyPressed(Key.E) || keyboard.IsKeyPressed(Key.PageDown) ? 1.0f : -1f; + var tempMoveAccel = keyboard.IsKeyPressed(Key.ShiftLeft) || keyboard.IsKeyPressed(Key.ShiftRight) ? 1.0f : -1f; _moveFront = DemoMath.clamp(_moveFront + tempMoveFront * dt * 4.0f, 0, 2.0f); _moveLeft = DemoMath.clamp(_moveLeft + tempMoveLeft * dt * 4.0f, 0, 2.0f); @@ -767,7 +767,8 @@ public class RecastDemo dd.fog(false); - mouseOverMenu = _viewSys.render(window, 0, 0, width, height, (int)mousePos[0], (int)mousePos[1]); + _viewSys.Draw(); + _mouseOverMenu = _viewSys.IsMouseOverUI(); _imgui.Render(); window.SwapBuffers(); diff --git a/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs b/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs index 5e15be7..b6e570f 100644 --- a/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs +++ b/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs @@ -71,18 +71,13 @@ public class RcSettingsView : IRcView private bool meshInputTrigerred; private bool navMeshInputTrigerred; - public bool render(IWindow window, int x, int y, int width, int height, int mouseX, int mouseY) + private bool _mouseInside; + public bool IsMouseInside() => _mouseInside; + public void Draw() { ImGui.Begin("Properties"); - renderInternal(window, x, y, width, height, mouseX, mouseY); - ImGui.End(); - - return true; - } - - public bool renderInternal(IWindow win, int x, int y, int width, int height, int mouseX, int mouseY) - { - bool mouseInside = false; + _mouseInside = ImGui.IsWindowHovered(); + ImGui.Text("Input Mesh"); ImGui.Separator(); @@ -213,7 +208,8 @@ public class RcSettingsView : IRcView // nk_end(ctx); // } ImGui.NewLine(); - return mouseInside; + + ImGui.End(); } public float getCellSize() diff --git a/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs b/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs index d383cdd..65e36c2 100644 --- a/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs @@ -185,7 +185,7 @@ public class ConvexVolumeTool : Tool dd.end(); } - public override void layout(IWindow ctx) + public override void layout() { // nk_layout_row_dynamic(ctx, 20, 1); ImGui.SliderFloat("Shape Height", ref boxHeight, 0.1f, 20f, "%.1f"); diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs index 08a4571..612233c 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs @@ -684,7 +684,7 @@ public class CrowdTool : Tool m_agentDebug.agent = agent; } - public override void layout(IWindow ctx) + public override void layout() { // ToolMode previousToolMode = m_mode; // nk_layout_row_dynamic(ctx, 20, 1); diff --git a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs index bc831c2..7bc3839 100644 --- a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs @@ -479,7 +479,7 @@ public class DynamicUpdateTool : Tool } } - public override void layout(IWindow ctx) + public override void layout() { // nk_layout_row_dynamic(ctx, 18, 1); // if (nk_option_label(ctx, "Build", mode == ToolMode.BUILD)) { diff --git a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs index d008ed6..2779885 100644 --- a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs @@ -322,7 +322,7 @@ public class JumpLinkBuilderTool : Tool { } - public override void layout(IWindow ctx) + public override void layout() { // if (!sample.getRecastResults().isEmpty()) { // diff --git a/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionTool.cs b/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionTool.cs index 5b7586c..d748c90 100644 --- a/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionTool.cs @@ -109,7 +109,7 @@ public class OffMeshConnectionTool : Tool } } - public override void layout(IWindow ctx) + public override void layout() { // nk_layout_row_dynamic(ctx, 20, 1); // bidir = !nk_option_label(ctx, "One Way", !bidir); diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index 59a5407..83f79f5 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -73,7 +73,7 @@ public class TestNavmeshTool : Tool recalc(); } - public override void layout(IWindow ctx) + public override void layout() { TestNavmeshToolMode previousToolMode = m_toolMode; int previousStraightPathOptions = m_straightPathOptions; diff --git a/src/DotRecast.Recast.Demo/Tools/Tool.cs b/src/DotRecast.Recast.Demo/Tools/Tool.cs index 2af1ee7..ff800f1 100644 --- a/src/DotRecast.Recast.Demo/Tools/Tool.cs +++ b/src/DotRecast.Recast.Demo/Tools/Tool.cs @@ -33,7 +33,7 @@ public abstract class Tool public abstract void handleUpdate(float dt); - public abstract void layout(IWindow ctx); + public abstract void layout(); public abstract string getName(); diff --git a/src/DotRecast.Recast.Demo/Tools/ToolsView.cs b/src/DotRecast.Recast.Demo/Tools/ToolsView.cs index 8132d4c..6c30067 100644 --- a/src/DotRecast.Recast.Demo/Tools/ToolsView.cs +++ b/src/DotRecast.Recast.Demo/Tools/ToolsView.cs @@ -36,11 +36,15 @@ public class ToolsView : IRcView { this.tools = tools; } + + private bool _mouseInside; + public bool IsMouseInside() => _mouseInside; - public bool render(IWindow window, int x, int y, int width, int height, int mouseX, int mouseY) + public void Draw() { - bool mouseInside = false; ImGui.Begin("Tools"); + _mouseInside = ImGui.IsWindowHovered(); + for (int i = 0; i < tools.Length; ++i) { var tool = tools[i]; @@ -51,15 +55,15 @@ public class ToolsView : IRcView if (0 > _currentToolIdx || _currentToolIdx >= tools.Length) { ImGui.End(); - return false; + return; } currentTool = tools[_currentToolIdx]; ImGui.Text(currentTool.getName()); ImGui.Separator(); - currentTool.layout(window); + currentTool.layout(); + 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 9cb4e93..b66c1cc 100644 --- a/src/DotRecast.Recast.Demo/UI/IRcView.cs +++ b/src/DotRecast.Recast.Demo/UI/IRcView.cs @@ -22,5 +22,6 @@ namespace DotRecast.Recast.Demo.UI; public interface IRcView { - bool render(IWindow window, int x, int y, int width, int height, int mouseX, int mouseY); + bool IsMouseInside(); + void Draw(); } \ 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 84d1cf3..20472bc 100644 --- a/src/DotRecast.Recast.Demo/UI/RcViewSystem.cs +++ b/src/DotRecast.Recast.Demo/UI/RcViewSystem.cs @@ -17,6 +17,8 @@ freely, subject to the following restrictions: */ using ImGuiNET; +using Serilog; +using Serilog.Core; using Silk.NET.Input; using Silk.NET.OpenGL; using Silk.NET.Windowing; @@ -25,6 +27,7 @@ namespace DotRecast.Recast.Demo.UI; public class RcViewSystem { + private static readonly ILogger Logger = Log.ForContext(); // readonly NkAllocator allocator; private readonly IWindow _window; @@ -34,7 +37,8 @@ public class RcViewSystem // readonly NkColor white; private readonly IRcView[] _views; private readonly NuklearGL glContext; - private bool mouseOverUI; + private bool _mouseOverUI; + public bool IsMouseOverUI() => _mouseOverUI; public RcViewSystem(IWindow window, IInputContext input, params IRcView[] views) { @@ -131,14 +135,17 @@ public class RcViewSystem // nk_input_end(ctx); } - public bool render(IWindow ctx, int x, int y, int width, int height, int mouseX, int mouseY) + public void Draw() { - mouseOverUI = false; + _mouseOverUI = false; foreach (IRcView m in _views) { - mouseOverUI = m.render(ctx, x, y, width, height, mouseX, mouseY) | mouseOverUI; + m.Draw(); + _mouseOverUI |= m.IsMouseInside(); + // if (_mouseOverUI) + // { + // Logger.Information("mouse hover!"); + // } } - - return mouseOverUI; } } \ No newline at end of file