refactor(input): extract the gameplay frame
This commit is contained in:
parent
0bc9fda9de
commit
c557038353
24 changed files with 2433 additions and 559 deletions
74
src/AcDream.App/Input/InputCaptureSources.cs
Normal file
74
src/AcDream.App/Input/InputCaptureSources.cs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
using AcDream.App.UI;
|
||||
|
||||
namespace AcDream.App.Input;
|
||||
|
||||
internal interface IInputCaptureSource
|
||||
{
|
||||
bool WantCaptureMouse { get; }
|
||||
bool WantCaptureKeyboard { get; }
|
||||
bool DevToolsWantCaptureKeyboard { get; }
|
||||
}
|
||||
|
||||
internal sealed class DevToolsInputCaptureSource
|
||||
{
|
||||
private readonly bool _enabled;
|
||||
|
||||
public DevToolsInputCaptureSource(bool enabled) => _enabled = enabled;
|
||||
|
||||
public bool WantCaptureMouse =>
|
||||
_enabled && ImGuiNET.ImGui.GetIO().WantCaptureMouse;
|
||||
|
||||
public bool WantCaptureKeyboard =>
|
||||
_enabled && ImGuiNET.ImGui.GetIO().WantCaptureKeyboard;
|
||||
}
|
||||
|
||||
internal sealed class RetainedUiInputCaptureSlot
|
||||
{
|
||||
public UiRoot? Root { get; set; }
|
||||
|
||||
public bool WantCaptureMouse => Root?.WantsMouse ?? false;
|
||||
public bool WantCaptureKeyboard => Root?.WantsKeyboard ?? false;
|
||||
}
|
||||
|
||||
internal sealed class CompositeInputCaptureSource : IInputCaptureSource
|
||||
{
|
||||
private readonly DevToolsInputCaptureSource _devTools;
|
||||
private readonly RetainedUiInputCaptureSlot _retained;
|
||||
|
||||
public CompositeInputCaptureSource(
|
||||
DevToolsInputCaptureSource devTools,
|
||||
RetainedUiInputCaptureSlot retained)
|
||||
{
|
||||
_devTools = devTools ?? throw new ArgumentNullException(nameof(devTools));
|
||||
_retained = retained ?? throw new ArgumentNullException(nameof(retained));
|
||||
}
|
||||
|
||||
public bool WantCaptureMouse =>
|
||||
_devTools.WantCaptureMouse || _retained.WantCaptureMouse;
|
||||
|
||||
public bool WantCaptureKeyboard =>
|
||||
DevToolsWantCaptureKeyboard || _retained.WantCaptureKeyboard;
|
||||
|
||||
public bool DevToolsWantCaptureKeyboard =>
|
||||
_devTools.WantCaptureKeyboard;
|
||||
}
|
||||
|
||||
internal sealed class DelegateInputCaptureSource : IInputCaptureSource
|
||||
{
|
||||
private readonly Func<bool> _wantCaptureMouse;
|
||||
private readonly Func<bool> _wantCaptureKeyboard;
|
||||
|
||||
public DelegateInputCaptureSource(
|
||||
Func<bool> wantCaptureMouse,
|
||||
Func<bool> wantCaptureKeyboard)
|
||||
{
|
||||
_wantCaptureMouse = wantCaptureMouse
|
||||
?? throw new ArgumentNullException(nameof(wantCaptureMouse));
|
||||
_wantCaptureKeyboard = wantCaptureKeyboard
|
||||
?? throw new ArgumentNullException(nameof(wantCaptureKeyboard));
|
||||
}
|
||||
|
||||
public bool WantCaptureMouse => _wantCaptureMouse();
|
||||
public bool WantCaptureKeyboard => _wantCaptureKeyboard();
|
||||
public bool DevToolsWantCaptureKeyboard => false;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue