Implemented KeyPress event for Sdl2NativeWindow.

This commit is contained in:
Elias Holzer 2013-11-22 18:05:11 +01:00
parent f851d8887c
commit 6ee04b2ff9

View file

@ -37,6 +37,7 @@ using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using OpenTK;
using OpenTK.Input;
using System.Text;
namespace OpenTK.Platform.SDL2
{
@ -150,6 +151,14 @@ namespace OpenTK.Platform.SDL2
}
break;
case EventType.TEXTINPUT:
if (windows.TryGetValue(ev.Text.WindowID, out window))
{
ProcessTextInputEvent(window, ev.Text);
processed = true;
}
break;
case EventType.KEYDOWN:
case EventType.KEYUP:
if (windows.TryGetValue(ev.Key.WindowID, out window))
@ -226,6 +235,30 @@ namespace OpenTK.Platform.SDL2
//window.keyboard.SetKey(TranslateKey(key.scancode), (uint)key.scancode, key_pressed);
}
static unsafe void ProcessTextInputEvent(Sdl2NativeWindow window, TextInputEvent ev)
{
var keyPress = window.KeyPress;
if (keyPress != null)
{
var length = 0;
byte* pText = ev.Text;
while (*pText != 0)
{
length++;
pText++;
}
using (var stream = new System.IO.UnmanagedMemoryStream(ev.Text, length))
using (var reader = new System.IO.StreamReader(stream, Encoding.UTF8))
{
var text = reader.ReadToEnd();
foreach (var c in text)
{
keyPress(window, new KeyPressEventArgs(c));
}
}
}
}
static void ProcessMotionEvent(Sdl2NativeWindow window, Event ev)
{
float scale = window.ClientSize.Width / (float)window.Size.Width;