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

View File

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

View File

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

View File

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

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);
// 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()) {
//

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

View File

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

View File

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

View File

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

View File

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

View File

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