added mouse inside

This commit is contained in:
ikpil 2023-03-23 00:29:25 +09:00
parent 7206449253
commit 4e09b573be
12 changed files with 85 additions and 76 deletions

View File

@ -83,7 +83,7 @@ public class RecastDemo
private readonly float[] mousePos = new float[2]; private readonly float[] mousePos = new float[2];
private bool mouseOverMenu; private bool _mouseOverMenu;
private bool pan; private bool pan;
private bool movedDuringPan; private bool movedDuringPan;
private bool rotate; private bool rotate;
@ -109,7 +109,7 @@ public class RecastDemo
private float _moveUp; private float _moveUp;
private float _moveDown; private float _moveDown;
private float _moveAccel; private float _moveAccel;
private bool markerPositionSet; private bool markerPositionSet;
private readonly float[] markerPosition = new float[3]; private readonly float[] markerPosition = new float[3];
private ToolsView toolsUI; private ToolsView toolsUI;
@ -132,17 +132,17 @@ public class RecastDemo
if (scrollWheel.Y < 0) if (scrollWheel.Y < 0)
{ {
// wheel down // wheel down
// if (!mouseOverMenu) if (!_mouseOverMenu)
// { {
scrollZoom += 1.0f; scrollZoom += 1.0f;
//} }
} }
else else
{ {
// if (!mouseOverMenu) if (!_mouseOverMenu)
// { {
scrollZoom -= 1.0f; scrollZoom -= 1.0f;
//} }
} }
float[] modelviewMatrix = dd.viewMatrix(cameraPos, cameraEulers); float[] modelviewMatrix = dd.viewMatrix(cameraPos, cameraEulers);
@ -196,30 +196,30 @@ public class RecastDemo
{ {
if (button == MouseButton.Right) if (button == MouseButton.Right)
{ {
// if (!mouseOverMenu) if (!_mouseOverMenu)
// { {
// Rotate view // Rotate view
rotate = true; rotate = true;
movedDuringRotate = false; movedDuringRotate = false;
origMousePos[0] = mousePos[0]; origMousePos[0] = mousePos[0];
origMousePos[1] = mousePos[1]; origMousePos[1] = mousePos[1];
origCameraEulers[0] = cameraEulers[0]; origCameraEulers[0] = cameraEulers[0];
origCameraEulers[1] = cameraEulers[1]; origCameraEulers[1] = cameraEulers[1];
//} }
} }
else if (button == MouseButton.Middle) else if (button == MouseButton.Middle)
{ {
// if (!mouseOverMenu) if (!_mouseOverMenu)
// { {
// Pan view // Pan view
pan = true; pan = true;
movedDuringPan = false; movedDuringPan = false;
origMousePos[0] = mousePos[0]; origMousePos[0] = mousePos[0];
origMousePos[1] = mousePos[1]; origMousePos[1] = mousePos[1];
origCameraPos[0] = cameraPos[0]; origCameraPos[0] = cameraPos[0];
origCameraPos[1] = cameraPos[1]; origCameraPos[1] = cameraPos[1];
origCameraPos[2] = cameraPos[2]; origCameraPos[2] = cameraPos[2];
//} }
} }
} }
else else
@ -228,23 +228,23 @@ public class RecastDemo
if (button == MouseButton.Right) if (button == MouseButton.Right)
{ {
rotate = false; rotate = false;
// if (!mouseOverMenu) if (!_mouseOverMenu)
// {
if (!movedDuringRotate)
{ {
processHitTest = true; if (!movedDuringRotate)
processHitTestShift = true; {
processHitTest = true;
processHitTestShift = true;
}
} }
//}
} }
else if (button == MouseButton.Left) else if (button == MouseButton.Left)
{ {
// if (!mouseOverMenu) if (!_mouseOverMenu)
// { {
processHitTest = true; processHitTest = true;
//processHitTestShift = (mods & Keys.GLFW_MOD_SHIFT) != 0 ? true : false; //processHitTestShift = (mods & Keys.GLFW_MOD_SHIFT) != 0 ? true : false;
//processHitTestShift = (mods & Keys.) != 0 ? true : false; //processHitTestShift = (mods & Keys.) != 0 ? true : false;
//} }
} }
else if (button == MouseButton.Middle) 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 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 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 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 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 tempMoveAccel = keyboard.IsKeyPressed(Key.ShiftLeft) || keyboard.IsKeyPressed(Key.ShiftRight) ? 1.0f : -1f;
_moveFront = DemoMath.clamp(_moveFront + tempMoveFront * dt * 4.0f, 0, 2.0f); _moveFront = DemoMath.clamp(_moveFront + tempMoveFront * dt * 4.0f, 0, 2.0f);
_moveLeft = DemoMath.clamp(_moveLeft + tempMoveLeft * 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); dd.fog(false);
mouseOverMenu = _viewSys.render(window, 0, 0, width, height, (int)mousePos[0], (int)mousePos[1]); _viewSys.Draw();
_mouseOverMenu = _viewSys.IsMouseOverUI();
_imgui.Render(); _imgui.Render();
window.SwapBuffers(); window.SwapBuffers();

View File

@ -71,18 +71,13 @@ public class RcSettingsView : IRcView
private bool meshInputTrigerred; private bool meshInputTrigerred;
private bool navMeshInputTrigerred; 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"); ImGui.Begin("Properties");
renderInternal(window, x, y, width, height, mouseX, mouseY); _mouseInside = ImGui.IsWindowHovered();
ImGui.End();
return true;
}
public bool renderInternal(IWindow win, int x, int y, int width, int height, int mouseX, int mouseY)
{
bool mouseInside = false;
ImGui.Text("Input Mesh"); ImGui.Text("Input Mesh");
ImGui.Separator(); ImGui.Separator();
@ -213,7 +208,8 @@ public class RcSettingsView : IRcView
// nk_end(ctx); // nk_end(ctx);
// } // }
ImGui.NewLine(); ImGui.NewLine();
return mouseInside;
ImGui.End();
} }
public float getCellSize() public float getCellSize()

View File

@ -185,7 +185,7 @@ public class ConvexVolumeTool : Tool
dd.end(); dd.end();
} }
public override void layout(IWindow ctx) public override void layout()
{ {
// nk_layout_row_dynamic(ctx, 20, 1); // nk_layout_row_dynamic(ctx, 20, 1);
ImGui.SliderFloat("Shape Height", ref boxHeight, 0.1f, 20f, "%.1f"); ImGui.SliderFloat("Shape Height", ref boxHeight, 0.1f, 20f, "%.1f");

View File

@ -684,7 +684,7 @@ public class CrowdTool : Tool
m_agentDebug.agent = agent; m_agentDebug.agent = agent;
} }
public override void layout(IWindow ctx) public override void layout()
{ {
// ToolMode previousToolMode = m_mode; // ToolMode previousToolMode = m_mode;
// nk_layout_row_dynamic(ctx, 20, 1); // nk_layout_row_dynamic(ctx, 20, 1);

View File

@ -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); // nk_layout_row_dynamic(ctx, 18, 1);
// if (nk_option_label(ctx, "Build", mode == ToolMode.BUILD)) { // if (nk_option_label(ctx, "Build", mode == ToolMode.BUILD)) {

View File

@ -322,7 +322,7 @@ public class JumpLinkBuilderTool : Tool
{ {
} }
public override void layout(IWindow ctx) public override void layout()
{ {
// if (!sample.getRecastResults().isEmpty()) { // if (!sample.getRecastResults().isEmpty()) {
// //

View File

@ -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); // nk_layout_row_dynamic(ctx, 20, 1);
// bidir = !nk_option_label(ctx, "One Way", !bidir); // bidir = !nk_option_label(ctx, "One Way", !bidir);

View File

@ -73,7 +73,7 @@ public class TestNavmeshTool : Tool
recalc(); recalc();
} }
public override void layout(IWindow ctx) public override void layout()
{ {
TestNavmeshToolMode previousToolMode = m_toolMode; TestNavmeshToolMode previousToolMode = m_toolMode;
int previousStraightPathOptions = m_straightPathOptions; int previousStraightPathOptions = m_straightPathOptions;

View File

@ -33,7 +33,7 @@ public abstract class Tool
public abstract void handleUpdate(float dt); public abstract void handleUpdate(float dt);
public abstract void layout(IWindow ctx); public abstract void layout();
public abstract string getName(); public abstract string getName();

View File

@ -36,11 +36,15 @@ public class ToolsView : IRcView
{ {
this.tools = tools; 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"); ImGui.Begin("Tools");
_mouseInside = ImGui.IsWindowHovered();
for (int i = 0; i < tools.Length; ++i) for (int i = 0; i < tools.Length; ++i)
{ {
var tool = tools[i]; var tool = tools[i];
@ -51,15 +55,15 @@ public class ToolsView : IRcView
if (0 > _currentToolIdx || _currentToolIdx >= tools.Length) if (0 > _currentToolIdx || _currentToolIdx >= tools.Length)
{ {
ImGui.End(); ImGui.End();
return false; return;
} }
currentTool = tools[_currentToolIdx]; currentTool = tools[_currentToolIdx];
ImGui.Text(currentTool.getName()); ImGui.Text(currentTool.getName());
ImGui.Separator(); ImGui.Separator();
currentTool.layout(window); currentTool.layout();
ImGui.End(); ImGui.End();
return true;
} }
public void setEnabled(bool enabled) public void setEnabled(bool enabled)

View File

@ -22,5 +22,6 @@ namespace DotRecast.Recast.Demo.UI;
public interface IRcView public interface IRcView
{ {
bool render(IWindow window, int x, int y, int width, int height, int mouseX, int mouseY); bool IsMouseInside();
void Draw();
} }

View File

@ -17,6 +17,8 @@ freely, subject to the following restrictions:
*/ */
using ImGuiNET; using ImGuiNET;
using Serilog;
using Serilog.Core;
using Silk.NET.Input; using Silk.NET.Input;
using Silk.NET.OpenGL; using Silk.NET.OpenGL;
using Silk.NET.Windowing; using Silk.NET.Windowing;
@ -25,6 +27,7 @@ namespace DotRecast.Recast.Demo.UI;
public class RcViewSystem public class RcViewSystem
{ {
private static readonly ILogger Logger = Log.ForContext<RecastDemo>();
// readonly NkAllocator allocator; // readonly NkAllocator allocator;
private readonly IWindow _window; private readonly IWindow _window;
@ -34,7 +37,8 @@ public class RcViewSystem
// readonly NkColor white; // readonly NkColor white;
private readonly IRcView[] _views; private readonly IRcView[] _views;
private readonly NuklearGL glContext; private readonly NuklearGL glContext;
private bool mouseOverUI; private bool _mouseOverUI;
public bool IsMouseOverUI() => _mouseOverUI;
public RcViewSystem(IWindow window, IInputContext input, params IRcView[] views) public RcViewSystem(IWindow window, IInputContext input, params IRcView[] views)
{ {
@ -131,14 +135,17 @@ public class RcViewSystem
// nk_input_end(ctx); // 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) 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;
} }
} }