mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-03-29 18:06:52 +00:00
Implemented KeyPress event for Sdl2NativeWindow.
This commit is contained in:
parent
f851d8887c
commit
6ee04b2ff9
|
@ -37,6 +37,7 @@ using System.Drawing.Imaging;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace OpenTK.Platform.SDL2
|
namespace OpenTK.Platform.SDL2
|
||||||
{
|
{
|
||||||
|
@ -150,6 +151,14 @@ namespace OpenTK.Platform.SDL2
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case EventType.TEXTINPUT:
|
||||||
|
if (windows.TryGetValue(ev.Text.WindowID, out window))
|
||||||
|
{
|
||||||
|
ProcessTextInputEvent(window, ev.Text);
|
||||||
|
processed = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case EventType.KEYDOWN:
|
case EventType.KEYDOWN:
|
||||||
case EventType.KEYUP:
|
case EventType.KEYUP:
|
||||||
if (windows.TryGetValue(ev.Key.WindowID, out window))
|
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);
|
//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)
|
static void ProcessMotionEvent(Sdl2NativeWindow window, Event ev)
|
||||||
{
|
{
|
||||||
float scale = window.ClientSize.Width / (float)window.Size.Width;
|
float scale = window.ClientSize.Width / (float)window.Size.Width;
|
||||||
|
|
Loading…
Reference in a new issue