Ian Burgmyer
7 years ago
6 changed files with 94 additions and 14 deletions
@ -0,0 +1,39 @@
|
||||
using SdlEvents = DotSDL.Sdl.Events; |
||||
|
||||
namespace DotSDL.Events { |
||||
/// <summary> |
||||
/// Converts from a SDL2-style event to a DotSDL-style <see cref="IEvent"/>. |
||||
/// </summary> |
||||
internal static class EventConversion { |
||||
private static readonly ResourceManager Resources = ResourceManager.Instance; |
||||
|
||||
/// <summary> |
||||
/// Converts an SDL2-style event to a DotSDL-style <see cref="IEvent"/>. |
||||
/// </summary> |
||||
/// <param name="sdlEvent">The event to convert.</param> |
||||
/// <returns>A DotSDL <see cref="IEvent"/> that can be passed to applications.</returns> |
||||
internal static IEvent Convert(object sdlEvent) { |
||||
switch(sdlEvent) { |
||||
case SdlEvents.SdlWindowEvent e: |
||||
return ConvertWindowEvent(e); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// |
||||
/// </summary> |
||||
/// <param name="e"></param> |
||||
/// <returns></returns> |
||||
private static WindowEvent ConvertWindowEvent(SdlEvents.SdlWindowEvent e) { |
||||
return new WindowEvent { |
||||
Timestamp = e.Timestamp, |
||||
Event = e.EventId, |
||||
Resource = Resources.GetResourceById(e.WindowId), |
||||
X = e.Data1, |
||||
Y = e.Data2 |
||||
}; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,21 @@
|
||||
using DotSDL.Graphics; |
||||
|
||||
namespace DotSDL.Events { |
||||
/// <summary> |
||||
/// Handles dispatching events to an application's windows and other objects. |
||||
/// </summary> |
||||
internal static class EventDispatcher { |
||||
/// <summary> |
||||
/// Dispatches an event to its associated object. |
||||
/// </summary> |
||||
/// <param name="ev">The event to process.</param> |
||||
internal static void Dispatch(IEvent ev) { |
||||
switch(ev) { |
||||
case WindowEvent e: |
||||
var window = (SdlWindow)e.Resource; |
||||
window.HandleEvent(e); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue