-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: Adds touch support to Winforms based GameForm #1664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4ab9f70
add touch support for Winforms based GameForm
joreg c73271b
PointerSDL now uses GetFingerId() from baseclass (to be in line with …
joreg 13d11c8
Merge branch 'master' into dev/joreg/add-touch-to-winforms
joreg 2c1bc62
Touch position is now normalized 0..1 like in other implementations
joreg 1956f70
Update sources/engine/Stride.Input/Windows/PointerWinforms.cs
joreg 82f7fae
Update sources/engine/Stride.Games/Desktop/GameForm.cs
joreg 77e2101
fixed potentially problematic cast
joreg 325a7fa
Merge branch 'dev/joreg/add-touch-to-winforms' of https://github.com/…
joreg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,84 @@ | ||
| // Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) | ||
| // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. | ||
|
|
||
| #if STRIDE_UI_WINFORMS | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Windows.Forms; | ||
| using Stride.Core.Extensions; | ||
| using Stride.Core.Mathematics; | ||
| using Stride.Games; | ||
| using static Stride.Games.TouchUtils; | ||
|
|
||
| namespace Stride.Input | ||
| { | ||
| /// <summary> | ||
| /// Class handling finger touch inputs using the Winforms backend | ||
| /// </summary> | ||
| internal class PointerWinforms : PointerDeviceBase, IDisposable | ||
| { | ||
| private readonly GameForm uiControl; | ||
|
|
||
| public PointerWinforms(InputSourceWinforms source, Control uiControl) | ||
| { | ||
| Source = source; | ||
| this.uiControl = uiControl as GameForm; | ||
joreg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| this.uiControl.FingerMoveActions += OnFingerMoveEvent; | ||
| this.uiControl.FingerPressActions += OnFingerPressEvent; | ||
| this.uiControl.FingerReleaseActions += OnFingerReleaseEvent; | ||
|
|
||
| uiControl.Resize += OnSizeChanged; | ||
| OnSizeChanged(uiControl, EventArgs.Empty); | ||
|
|
||
| Id = InputDeviceUtils.DeviceNameToGuid(uiControl.Handle.ToString() + Name); | ||
| } | ||
|
|
||
| public override string Name => "Winforms Pointer"; | ||
|
|
||
| public override Guid Id { get; } | ||
|
|
||
| public override IInputSource Source { get; } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| uiControl.FingerMoveActions -= OnFingerMoveEvent; | ||
| uiControl.FingerPressActions -= OnFingerPressEvent; | ||
| uiControl.FingerReleaseActions -= OnFingerReleaseEvent; | ||
|
|
||
| uiControl.Resize -= OnSizeChanged; | ||
| } | ||
|
|
||
| private void OnSizeChanged(object sender, EventArgs eventArgs) | ||
| { | ||
| SetSurfaceSize(new Vector2(uiControl.ClientSize.Width, uiControl.ClientSize.Height)); | ||
| } | ||
|
|
||
| private void HandleFingerEvent(POINTER_TOUCH_INFO e, PointerEventType type) | ||
| { | ||
| var pointerInfo = e.pointerInfo; | ||
| var point = uiControl.PointToClient(new System.Drawing.Point(pointerInfo.ptPixelLocationX, pointerInfo.ptPixelLocationY)); | ||
| var pixel = new Vector2(point.X, point.Y); | ||
| var newPosition = Normalize(pixel); | ||
| var id = GetFingerId(pointerInfo.sourceDevice.ToInt64(), pointerInfo.pointerId, type); | ||
|
|
||
| PointerState.PointerInputEvents.Add(new PointerDeviceState.InputEvent { Type = type, Position = newPosition, Id = id }); | ||
| } | ||
|
|
||
| private void OnFingerMoveEvent(POINTER_TOUCH_INFO e) | ||
| { | ||
| HandleFingerEvent(e, PointerEventType.Moved); | ||
| } | ||
|
|
||
| private void OnFingerPressEvent(POINTER_TOUCH_INFO e) | ||
| { | ||
| HandleFingerEvent(e, PointerEventType.Pressed); | ||
| } | ||
|
|
||
| private void OnFingerReleaseEvent(POINTER_TOUCH_INFO e) | ||
| { | ||
| HandleFingerEvent(e, PointerEventType.Released); | ||
| } | ||
| } | ||
| } | ||
| #endif | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.