mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-09-29 09:31:06 +02:00
33 lines
996 B
C#
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);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|