forked from ppy/osu-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
515ffbf
commit f20a155
Showing
11 changed files
with
212 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
osu.Framework/Input/StateChanges/MouseButtonInputFromPen.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
osu.Framework/Input/StateChanges/MouseInvalidatePositionInputFromPen.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
osu.Framework/Input/StateChanges/MousePositionAbsoluteInputFromPen.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters