1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-28 19:13:38 +02:00
MLEM/MLEM/Extensions/WindowExtensions.cs
2019-12-05 22:15:49 +01:00

33 lines
996 B
C#

using System;
using System.Reflection;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace MLEM.Extensions {
public static class WindowExtensions {
private static readonly bool TextInputSupported = typeof(GameWindow).GetEvent("TextInput") != null;
public static bool AddTextInputListener(this GameWindow window, TextInputCallback callback) {
if (!SupportsTextInput())
return false;
TextInputAdder.Add(window, callback);
return true;
}
public static bool SupportsTextInput() {
return TextInputSupported;
}
public delegate void TextInputCallback(object sender, Keys key, char character);
private static class TextInputAdder {
public static void Add(GameWindow window, TextInputCallback callback) {
window.TextInput += (sender, args) => callback(sender, args.Key, args.Character);
}
}
}
}