forked from mirror/DotRecast
added mouse inside
This commit is contained in:
parent
7206449253
commit
4e09b573be
|
@ -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;
|
||||
|
@ -132,17 +132,17 @@ public class RecastDemo
|
|||
if (scrollWheel.Y < 0)
|
||||
{
|
||||
// wheel down
|
||||
// if (!mouseOverMenu)
|
||||
// {
|
||||
if (!_mouseOverMenu)
|
||||
{
|
||||
scrollZoom += 1.0f;
|
||||
//}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if (!mouseOverMenu)
|
||||
// {
|
||||
if (!_mouseOverMenu)
|
||||
{
|
||||
scrollZoom -= 1.0f;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
float[] modelviewMatrix = dd.viewMatrix(cameraPos, cameraEulers);
|
||||
|
@ -196,8 +196,8 @@ public class RecastDemo
|
|||
{
|
||||
if (button == MouseButton.Right)
|
||||
{
|
||||
// if (!mouseOverMenu)
|
||||
// {
|
||||
if (!_mouseOverMenu)
|
||||
{
|
||||
// Rotate view
|
||||
rotate = true;
|
||||
movedDuringRotate = false;
|
||||
|
@ -205,12 +205,12 @@ public class RecastDemo
|
|||
origMousePos[1] = mousePos[1];
|
||||
origCameraEulers[0] = cameraEulers[0];
|
||||
origCameraEulers[1] = cameraEulers[1];
|
||||
//}
|
||||
}
|
||||
}
|
||||
else if (button == MouseButton.Middle)
|
||||
{
|
||||
// if (!mouseOverMenu)
|
||||
// {
|
||||
if (!_mouseOverMenu)
|
||||
{
|
||||
// Pan view
|
||||
pan = true;
|
||||
movedDuringPan = false;
|
||||
|
@ -219,7 +219,7 @@ public class RecastDemo
|
|||
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 (!_mouseOverMenu)
|
||||
{
|
||||
if (!movedDuringRotate)
|
||||
{
|
||||
processHitTest = true;
|
||||
processHitTestShift = true;
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
else if (button == MouseButton.Left)
|
||||
{
|
||||
// if (!mouseOverMenu)
|
||||
// {
|
||||
if (!_mouseOverMenu)
|
||||
{
|
||||
processHitTest = true;
|
||||
//processHitTestShift = (mods & Keys.GLFW_MOD_SHIFT) != 0 ? true : false;
|
||||
//processHitTestShift = (mods & Keys.) != 0 ? true : false;
|
||||
//}
|
||||
}
|
||||
}
|
||||
else if (button == MouseButton.Middle)
|
||||
{
|
||||
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
_mouseInside = ImGui.IsWindowHovered();
|
||||
|
||||
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.Separator();
|
||||
|
||||
|
@ -213,7 +208,8 @@ public class RcSettingsView : IRcView
|
|||
// nk_end(ctx);
|
||||
// }
|
||||
ImGui.NewLine();
|
||||
return mouseInside;
|
||||
|
||||
ImGui.End();
|
||||
}
|
||||
|
||||
public float getCellSize()
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -322,7 +322,7 @@ public class JumpLinkBuilderTool : Tool
|
|||
{
|
||||
}
|
||||
|
||||
public override void layout(IWindow ctx)
|
||||
public override void layout()
|
||||
{
|
||||
// if (!sample.getRecastResults().isEmpty()) {
|
||||
//
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -37,10 +37,14 @@ public class ToolsView : IRcView
|
|||
this.tools = tools;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
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)
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
return mouseOverUI;
|
||||
m.Draw();
|
||||
_mouseOverUI |= m.IsMouseInside();
|
||||
// if (_mouseOverUI)
|
||||
// {
|
||||
// Logger.Information("mouse hover!");
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue