-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Another refactoring: make sure input events are processed even if a w…
…idget was removed from the desktop
- Loading branch information
Showing
6 changed files
with
246 additions
and
190 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
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 was deleted.
Oops, something went wrong.
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,112 @@ | ||
using System.Collections.Generic; | ||
|
||
#if MONOGAME || FNA | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Input; | ||
#elif STRIDE | ||
using Stride.Core.Mathematics; | ||
using Stride.Input; | ||
#else | ||
using System.Numerics; | ||
using System.Drawing; | ||
using Myra.Platform; | ||
#endif | ||
|
||
namespace Myra.Graphics2D.UI | ||
{ | ||
internal enum InputEventType | ||
{ | ||
MouseLeft, | ||
MouseEntered, | ||
MouseMoved, | ||
MouseWheel, | ||
TouchLeft, | ||
TouchEntered, | ||
TouchMoved, | ||
TouchDown, | ||
TouchUp, | ||
TouchDoubleClick | ||
} | ||
|
||
internal interface IInputEventsProcessor | ||
{ | ||
void ProcessEvent(InputEventType eventType); | ||
} | ||
|
||
internal static class InputEventsManager | ||
{ | ||
private struct InputEvent | ||
{ | ||
public IInputEventsProcessor Processor; | ||
public InputEventType Type; | ||
|
||
public InputEvent(IInputEventsProcessor processor, InputEventType type) | ||
{ | ||
Processor = processor; | ||
Type = type; | ||
} | ||
} | ||
|
||
private static readonly Queue<InputEvent> _events = new Queue<InputEvent>(); | ||
|
||
public static void QueueMouseLeft(IInputEventsProcessor processor) | ||
{ | ||
_events.Enqueue(new InputEvent(processor, InputEventType.MouseLeft)); | ||
} | ||
|
||
public static void QueueMouseEntered(IInputEventsProcessor processor) | ||
{ | ||
_events.Enqueue(new InputEvent(processor, InputEventType.MouseEntered)); | ||
} | ||
|
||
public static void QueueMouseMoved(IInputEventsProcessor processor) | ||
{ | ||
_events.Enqueue(new InputEvent(processor, InputEventType.MouseMoved)); | ||
} | ||
|
||
public static void QueueMouseWheel(IInputEventsProcessor processor) | ||
{ | ||
_events.Enqueue(new InputEvent(processor, InputEventType.MouseWheel)); | ||
} | ||
|
||
public static void QueueTouchLeft(IInputEventsProcessor processor) | ||
{ | ||
_events.Enqueue(new InputEvent(processor, InputEventType.TouchLeft)); | ||
} | ||
|
||
public static void QueueTouchEntered(IInputEventsProcessor processor) | ||
{ | ||
_events.Enqueue(new InputEvent(processor, InputEventType.TouchEntered)); | ||
} | ||
|
||
public static void QueueTouchMoved(IInputEventsProcessor processor) | ||
{ | ||
_events.Enqueue(new InputEvent(processor, InputEventType.TouchMoved)); | ||
} | ||
|
||
public static void QueueTouchDown(IInputEventsProcessor processor) | ||
{ | ||
_events.Enqueue(new InputEvent(processor, InputEventType.TouchDown)); | ||
} | ||
|
||
public static void QueueTouchUp(IInputEventsProcessor processor) | ||
{ | ||
_events.Enqueue(new InputEvent(processor, InputEventType.TouchUp)); | ||
} | ||
|
||
public static void QueueTouchDoubleClick(IInputEventsProcessor processor) | ||
{ | ||
_events.Enqueue(new InputEvent(processor, InputEventType.TouchDoubleClick)); | ||
} | ||
|
||
public static void ProcessEvents() | ||
{ | ||
while(_events.Count > 0) | ||
{ | ||
var ev = _events.Dequeue(); | ||
|
||
ev.Processor.ProcessEvent(ev.Type); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.