1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-06-27 23:09:10 +02:00
MLEM/MLEM/Extensions/WindowExtensions.cs
2020-02-06 01:33:24 +01:00

35 lines
1 KiB
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) {
#if !WEB
window.TextInput += (sender, args) => callback(sender, args.Key, args.Character);
#endif
}
}
}
}