Add TouchScreen Manager (#2333)
This commit is contained in:
parent
b898bc84ce
commit
bfcc6a8ad6
8 changed files with 418 additions and 83 deletions
84
Ryujinx/Input/GTK3/GTK3Mouse.cs
Normal file
84
Ryujinx/Input/GTK3/GTK3Mouse.cs
Normal file
|
@ -0,0 +1,84 @@
|
|||
using Ryujinx.Common.Configuration.Hid;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Ryujinx.Input.GTK3
|
||||
{
|
||||
public class GTK3Mouse : IMouse
|
||||
{
|
||||
private GTK3MouseDriver _driver;
|
||||
|
||||
public GamepadFeaturesFlag Features => throw new NotImplementedException();
|
||||
|
||||
public string Id => "0";
|
||||
|
||||
public string Name => "GTKMouse";
|
||||
|
||||
public bool IsConnected => true;
|
||||
|
||||
public bool[] Buttons => _driver.PressedButtons;
|
||||
|
||||
public GTK3Mouse(GTK3MouseDriver driver)
|
||||
{
|
||||
_driver = driver;
|
||||
}
|
||||
|
||||
public Size ClientSize => _driver.GetClientSize();
|
||||
|
||||
public Vector2 GetPosition()
|
||||
{
|
||||
return _driver.CurrentPosition;
|
||||
}
|
||||
|
||||
public GamepadStateSnapshot GetMappedStateSnapshot()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Vector3 GetMotionData(MotionInputId inputId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public GamepadStateSnapshot GetStateSnapshot()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public (float, float) GetStick(StickInputId inputId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool IsButtonPressed(MouseButton button)
|
||||
{
|
||||
return _driver.IsButtonPressed(button);
|
||||
}
|
||||
|
||||
public bool IsPressed(GamepadButtonInputId inputId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Rumble(float lowFrequency, float highFrequency, uint durationMs)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetConfiguration(InputConfig configuration)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetTriggerThreshold(float triggerThreshold)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_driver = null;
|
||||
}
|
||||
}
|
||||
}
|
97
Ryujinx/Input/GTK3/GTK3MouseDriver.cs
Normal file
97
Ryujinx/Input/GTK3/GTK3MouseDriver.cs
Normal file
|
@ -0,0 +1,97 @@
|
|||
using Gdk;
|
||||
using Gtk;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Size = System.Drawing.Size;
|
||||
|
||||
namespace Ryujinx.Input.GTK3
|
||||
{
|
||||
public class GTK3MouseDriver : IGamepadDriver
|
||||
{
|
||||
private Widget _widget;
|
||||
private bool _isDisposed;
|
||||
|
||||
public bool[] PressedButtons { get; }
|
||||
|
||||
public Vector2 CurrentPosition { get; private set; }
|
||||
|
||||
public GTK3MouseDriver(Widget parent)
|
||||
{
|
||||
_widget = parent;
|
||||
|
||||
_widget.MotionNotifyEvent += Parent_MotionNotifyEvent;
|
||||
_widget.ButtonPressEvent += Parent_ButtonPressEvent;
|
||||
_widget.ButtonReleaseEvent += Parent_ButtonReleaseEvent;
|
||||
|
||||
PressedButtons = new bool[(int)MouseButton.Count];
|
||||
}
|
||||
|
||||
[GLib.ConnectBefore]
|
||||
private void Parent_ButtonReleaseEvent(object o, ButtonReleaseEventArgs args)
|
||||
{
|
||||
PressedButtons[args.Event.Button - 1] = false;
|
||||
}
|
||||
|
||||
[GLib.ConnectBefore]
|
||||
private void Parent_ButtonPressEvent(object o, ButtonPressEventArgs args)
|
||||
{
|
||||
PressedButtons[args.Event.Button - 1] = true;
|
||||
}
|
||||
|
||||
[GLib.ConnectBefore]
|
||||
private void Parent_MotionNotifyEvent(object o, MotionNotifyEventArgs args)
|
||||
{
|
||||
if (args.Event.Device.InputSource == InputSource.Mouse)
|
||||
{
|
||||
CurrentPosition = new Vector2((float)args.Event.X, (float)args.Event.Y);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsButtonPressed(MouseButton button)
|
||||
{
|
||||
return PressedButtons[(int) button];
|
||||
}
|
||||
|
||||
public Size GetClientSize()
|
||||
{
|
||||
return new Size(_widget.AllocatedWidth, _widget.AllocatedHeight);
|
||||
}
|
||||
|
||||
public string DriverName => "GTK3";
|
||||
|
||||
public event Action<string> OnGamepadConnected
|
||||
{
|
||||
add { }
|
||||
remove { }
|
||||
}
|
||||
|
||||
public event Action<string> OnGamepadDisconnected
|
||||
{
|
||||
add { }
|
||||
remove { }
|
||||
}
|
||||
|
||||
public ReadOnlySpan<string> GamepadsIds => new[] {"0"};
|
||||
|
||||
public IGamepad GetGamepad(string id)
|
||||
{
|
||||
return new GTK3Mouse(this);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isDisposed = true;
|
||||
|
||||
_widget.MotionNotifyEvent -= Parent_MotionNotifyEvent;
|
||||
_widget.ButtonPressEvent -= Parent_ButtonPressEvent;
|
||||
_widget.ButtonReleaseEvent -= Parent_ButtonReleaseEvent;
|
||||
|
||||
_widget = null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue