Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzibyte committed Dec 15, 2024
1 parent 515ffbf commit f20a155
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 6 deletions.
75 changes: 75 additions & 0 deletions osu.Framework/Input/Handlers/Pen/PenHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Input.StateChanges;
using osu.Framework.Platform;
using osu.Framework.Statistics;
using osuTK;
using osuTK.Input;

namespace osu.Framework.Input.Handlers.Pen
{
/// <summary>
/// Handles pen events from an <see cref="ISDLWindow"/>.
/// This outputs simple mouse input with <see cref="ISourcedFromPen"/> markers embedded.
/// </summary>
public class PenHandler : InputHandler
{
private static readonly GlobalStatistic<ulong> statistic_total_events = GlobalStatistics.Get<ulong>(StatisticGroupFor<PenHandler>(), "Total events");

public override string Description => "Pen";

public override bool IsActive => true;

public override bool Initialize(GameHost host)
{
if (!base.Initialize(host))
return false;

if (!(host.Window is ISDLWindow sdlWindow))
return false;

Enabled.BindValueChanged(enabled =>
{
if (enabled.NewValue)
{
sdlWindow.PenIn += handlePenIn;
sdlWindow.PenOut += handlePenOut;
sdlWindow.PenMove += handlePenMove;
sdlWindow.PenDown += handlePenDown;
sdlWindow.PenUp += handlePenUp;
}
else
{
sdlWindow.PenIn -= handlePenIn;
sdlWindow.PenOut -= handlePenOut;
sdlWindow.PenMove -= handlePenMove;
sdlWindow.PenDown -= handlePenDown;
sdlWindow.PenUp -= handlePenUp;
}
}, true);

return true;
}

private void handlePenIn()
{
// The first pen motion will validate the mouse position, we don't have to do anything here.
}

private void handlePenOut() => enqueueInput(new MouseInvalidatePositionInputFromPen());

private void handlePenMove(Vector2 position) => enqueueInput(new MousePositionAbsoluteInputFromPen { Position = position });

private void handlePenDown(MouseButton button) => enqueueInput(new MouseButtonInputFromPen(button, true));

private void handlePenUp(MouseButton button) => enqueueInput(new MouseButtonInputFromPen(button, false));

private void enqueueInput(IInput input)
{
PendingInputs.Enqueue(input);
FrameStatistics.Increment(StatisticsCounterType.MouseEvents);
statistic_total_events.Value++;
}
}
}
18 changes: 15 additions & 3 deletions osu.Framework/Input/PassThroughInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,28 @@ protected override bool Handle(UIEvent e)
switch (e)
{
case MouseDownEvent mouseDown:
new MouseButtonInput(mouseDown.Button, true).Apply(CurrentState, this);
if (e.CurrentState.Mouse.LastSource is ISourcedFromPen)
new MouseButtonInputFromPen(mouseDown.Button, true).Apply(CurrentState, this);
else
new MouseButtonInput(mouseDown.Button, true).Apply(CurrentState, this);
break;

case MouseUpEvent mouseUp:
new MouseButtonInput(mouseUp.Button, false).Apply(CurrentState, this);
if (e.CurrentState.Mouse.LastSource is ISourcedFromPen)
new MouseButtonInputFromPen(mouseUp.Button, false).Apply(CurrentState, this);
else
new MouseButtonInput(mouseUp.Button, false).Apply(CurrentState, this);
break;

case MouseMoveEvent mouseMove:
if (mouseMove.ScreenSpaceMousePosition != CurrentState.Mouse.Position)
new MousePositionAbsoluteInput { Position = mouseMove.ScreenSpaceMousePosition }.Apply(CurrentState, this);
{
if (e.CurrentState.Mouse.LastSource is ISourcedFromPen)
new MousePositionAbsoluteInputFromPen { Position = mouseMove.ScreenSpaceMousePosition }.Apply(CurrentState, this);
else
new MousePositionAbsoluteInput { Position = mouseMove.ScreenSpaceMousePosition }.Apply(CurrentState, this);
}

break;

case ScrollEvent scroll:
Expand Down
12 changes: 12 additions & 0 deletions osu.Framework/Input/StateChanges/ISourcedFromPen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

namespace osu.Framework.Input.StateChanges
{
/// <summary>
/// Denotes mouse input which was sourced from a pen.
/// </summary>
public interface ISourcedFromPen : IInput
{
}
}
15 changes: 15 additions & 0 deletions osu.Framework/Input/StateChanges/MouseButtonInputFromPen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osuTK.Input;

namespace osu.Framework.Input.StateChanges
{
public class MouseButtonInputFromPen : MouseButtonInput, ISourcedFromPen
{
public MouseButtonInputFromPen(MouseButton button, bool isPressed)
: base(button, isPressed)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

namespace osu.Framework.Input.StateChanges
{
public class MouseInvalidatePositionInputFromPen : MouseInvalidatePositionInput, ISourcedFromPen
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

namespace osu.Framework.Input.StateChanges
{
public class MousePositionAbsoluteInputFromPen : MousePositionAbsoluteInput, ISourcedFromPen
{
}
}
5 changes: 5 additions & 0 deletions osu.Framework/Platform/ISDLWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ internal interface ISDLWindow : IWindow
event Action<MouseButton> MouseDown;
event Action<MouseButton> MouseUp;
event Action<Vector2, bool> MouseWheel;
event Action PenIn;
event Action PenOut;
event Action<Vector2> PenMove;
event Action<MouseButton> PenDown;
event Action<MouseButton> PenUp;
event Action<Key> KeyDown;
event Action<Key> KeyUp;
event Action<string> TextInput;
Expand Down
6 changes: 6 additions & 0 deletions osu.Framework/Platform/SDL2/SDL2Window_Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@ private void updateConfineMode()
/// </summary>
public event Action<MouseButton>? MouseUp;

public event Action<MouseButton>? PenDown;

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Code Quality

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Code Quality

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, SingleThread)

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, SingleThread)

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, MultiThreaded)

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, MultiThreaded)

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, SingleThread)

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, SingleThread)

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, SingleThread)

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, SingleThread)

The event 'SDL2Window.PenDown' is never used

Check warning on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (iOS)

The event 'SDL2Window.PenDown' is never used

Check warning on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (iOS)

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, SingleThread)

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, SingleThread)

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenDown' is never used

Check failure on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenDown' is never used

Check warning on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

The event 'SDL2Window.PenDown' is never used

Check warning on line 601 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

The event 'SDL2Window.PenDown' is never used
public event Action<MouseButton>? PenUp;

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Code Quality

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Code Quality

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, SingleThread)

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, SingleThread)

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, MultiThreaded)

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, MultiThreaded)

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, SingleThread)

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, SingleThread)

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, SingleThread)

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, SingleThread)

The event 'SDL2Window.PenUp' is never used

Check warning on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (iOS)

The event 'SDL2Window.PenUp' is never used

Check warning on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (iOS)

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, SingleThread)

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, SingleThread)

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenUp' is never used

Check failure on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenUp' is never used

Check warning on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

The event 'SDL2Window.PenUp' is never used

Check warning on line 602 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

The event 'SDL2Window.PenUp' is never used
public event Action<Vector2>? PenMove;

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Code Quality

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Code Quality

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, SingleThread)

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, SingleThread)

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, MultiThreaded)

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, MultiThreaded)

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, SingleThread)

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, SingleThread)

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, SingleThread)

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, SingleThread)

The event 'SDL2Window.PenMove' is never used

Check warning on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (iOS)

The event 'SDL2Window.PenMove' is never used

Check warning on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (iOS)

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, SingleThread)

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, SingleThread)

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenMove' is never used

Check failure on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenMove' is never used

Check warning on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

The event 'SDL2Window.PenMove' is never used

Check warning on line 603 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

The event 'SDL2Window.PenMove' is never used
public event Action? PenIn;

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Code Quality

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Code Quality

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, SingleThread)

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, SingleThread)

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, MultiThreaded)

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, MultiThreaded)

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, SingleThread)

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, SingleThread)

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, SingleThread)

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, SingleThread)

The event 'SDL2Window.PenIn' is never used

Check warning on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (iOS)

The event 'SDL2Window.PenIn' is never used

Check warning on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (iOS)

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, SingleThread)

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, SingleThread)

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenIn' is never used

Check failure on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenIn' is never used

Check warning on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

The event 'SDL2Window.PenIn' is never used

Check warning on line 604 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

The event 'SDL2Window.PenIn' is never used
public event Action? PenOut;

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Code Quality

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Code Quality

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, SingleThread)

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, SingleThread)

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, MultiThreaded)

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, MultiThreaded)

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, SingleThread)

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (macOS, macos-latest, Debug, SingleThread)

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, SingleThread)

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Linux, ubuntu-latest, Release, SingleThread)

The event 'SDL2Window.PenOut' is never used

Check warning on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (iOS)

The event 'SDL2Window.PenOut' is never used

Check warning on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (iOS)

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, SingleThread)

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, SingleThread)

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenOut' is never used

Check failure on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Test (Windows, windows-latest, Debug, MultiThreaded)

The event 'SDL2Window.PenOut' is never used

Check warning on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

The event 'SDL2Window.PenOut' is never used

Check warning on line 605 in osu.Framework/Platform/SDL2/SDL2Window_Input.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

The event 'SDL2Window.PenOut' is never used

protected void TriggerMouseUp(MouseButton button) => MouseUp?.Invoke(button);

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions osu.Framework/Platform/SDL3/SDL3Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,11 @@ protected virtual void HandleEvent(SDL_Event e)
case SDL_EventType.SDL_EVENT_PEN_MOTION:
handlePenMotionEvent(e.pmotion);
break;

case SDL_EventType.SDL_EVENT_PEN_PROXIMITY_IN:
case SDL_EventType.SDL_EVENT_PEN_PROXIMITY_OUT:
handlePenProximityEvent(e.pproximity);
break;
}
}

Expand Down
62 changes: 59 additions & 3 deletions osu.Framework/Platform/SDL3/SDL3Window_Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,23 @@ private void handleKeyboardEvent(SDL_KeyboardEvent evtKey)

private void handleKeymapChangedEvent() => KeymapChanged?.Invoke();

private void handlePenProximityEvent(SDL_PenProximityEvent evtPenProximity)
{
switch (evtPenProximity.type)
{
case SDL_EventType.SDL_EVENT_PEN_PROXIMITY_IN:
PenIn?.Invoke();
break;

case SDL_EventType.SDL_EVENT_PEN_PROXIMITY_OUT:
PenOut?.Invoke();
break;
}
}

private void handlePenMotionEvent(SDL_PenMotionEvent evtPenMotion)
{
MouseMove?.Invoke(new Vector2(evtPenMotion.x * Scale, evtPenMotion.y * Scale));
PenMove?.Invoke(new Vector2(evtPenMotion.x * Scale, evtPenMotion.y * Scale));
}

private void handlePenTouchEvent(SDL_PenTouchEvent evtPenTouch)
Expand Down Expand Up @@ -544,7 +558,7 @@ private void handlePenPressEvent(byte penButton, bool pressed)
}

penPressedButtons |= mask;
MouseDown?.Invoke(button);
PenDown?.Invoke(button);
}
else
{
Expand All @@ -555,7 +569,7 @@ private void handlePenPressEvent(byte penButton, bool pressed)
}

penPressedButtons &= ~mask;
MouseUp?.Invoke(button);
PenUp?.Invoke(button);
}
}

Expand Down Expand Up @@ -672,6 +686,13 @@ private void updateConfineMode()

protected void TriggerMouseWheel(Vector2 delta, bool precise) => MouseWheel?.Invoke(delta, precise);

/// <summary>
/// Invoked when the current position of the mouse cursor is no longer valid to read.
/// </summary>
public event Action? MouseInvalidatePosition;

protected void TriggerMouseInvalidatePosition() => MouseInvalidatePosition?.Invoke();

/// <summary>
/// Invoked when the user moves the mouse cursor within the window.
/// </summary>
Expand All @@ -698,6 +719,41 @@ private void updateConfineMode()

protected void TriggerMouseUp(MouseButton button) => MouseUp?.Invoke(button);

/// <summary>
/// Invoked when the pen is close to the screen and its motion became tracked.
/// </summary>
public event Action? PenIn;

protected void TriggerPenIn() => PenIn?.Invoke();

/// <summary>
/// Invoked when the pen became far from the screen and motion will no longer be tracked.
/// </summary>
public event Action? PenOut;

protected void TriggerPenOut() => PenOut?.Invoke();

/// <summary>
/// Invoked when the user moves their pen.
/// </summary>
public event Action<Vector2>? PenMove;

protected void TriggerPenMove(float x, float y) => PenMove?.Invoke(new Vector2(x, y));

/// <summary>
/// Invoked when the pen produced a button press, as a result of pressing the pen down or by pressing an auxiliary button.
/// </summary>
public event Action<MouseButton>? PenDown;

protected void TriggerPenDown(MouseButton button) => PenDown?.Invoke(button);

/// <summary>
/// Invoked when the button press signaled by <see cref="PenDown"/> has been released.
/// </summary>
public event Action<MouseButton>? PenUp;

protected void TriggerPenUp(MouseButton button) => PenUp?.Invoke(button);

/// <summary>
/// Invoked when the user presses a key.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions osu.Framework/Platform/SDLGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using osu.Framework.Input.Handlers.Keyboard;
using osu.Framework.Input.Handlers.Midi;
using osu.Framework.Input.Handlers.Mouse;
using osu.Framework.Input.Handlers.Pen;
using osu.Framework.Input.Handlers.Tablet;
using osu.Framework.Input.Handlers.Touch;
using osu.Framework.Platform.SDL2;
Expand Down Expand Up @@ -47,6 +48,7 @@ protected override IEnumerable<InputHandler> CreateAvailableInputHandlers() =>
// tablet should get priority over mouse to correctly handle cases where tablet drivers report as mice as well.
new OpenTabletDriverHandler(),
new MouseHandler(),
new PenHandler(),
new TouchHandler(),
new JoystickHandler(),
new MidiHandler(),
Expand Down

0 comments on commit f20a155

Please sign in to comment.