Build 0.20.10.0

This commit is contained in:
Markus Isberg
2022-12-05 19:48:59 +02:00
parent 31d2dc658e
commit 9d2f160314
55 changed files with 335 additions and 3511 deletions

View File

@@ -111,6 +111,11 @@ namespace Microsoft.Xna.Framework {
/// Used for displaying uncommitted IME text.
/// </summary>
public event EventHandler<TextEditingEventArgs> TextEditing;
/// <summary>
/// Used for when a key is pressed, including modifiers.
/// </summary>
public event EventHandler<TextInputEventArgs> KeyDown;
#endif
#endregion Events
@@ -158,6 +163,11 @@ namespace Microsoft.Xna.Framework {
EventHelpers.Raise(this, TextInput, e);
}
protected void OnKeyDown(object sender, TextInputEventArgs e)
{
EventHelpers.Raise(this, KeyDown, e);
}
protected void OnTextEditing(object sender, TextEditingEventArgs e)
{
EventHelpers.Raise(this, TextEditing, e);

View File

@@ -75,6 +75,8 @@ internal static class Sdl
TextEditing = 0x302,
TextInput = 0x303,
TextEditingExt = 0x305,
MouseMotion = 0x400,
MouseButtonDown = 0x401,
MouseButtonup = 0x402,
@@ -139,6 +141,8 @@ internal static class Sdl
[FieldOffset(0)]
public Keyboard.TextEditingEvent Edit;
[FieldOffset(0)]
public Keyboard.TextEditingExtEvent EditExt;
[FieldOffset(0)]
public Keyboard.TextInputEvent Text;
[FieldOffset(0)]
public Mouse.WheelEvent Wheel;
@@ -241,8 +245,8 @@ internal static class Sdl
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate bool d_sdl_istextinputactive();
public static d_sdl_istextinputactive SDL_IsTextInputActive = FuncLoader.LoadFunction<d_sdl_istextinputactive>(NativeLibrary, "SDL_IsTextInputActive");
public delegate bool d_sdl_istextinputshown();
public static d_sdl_istextinputshown SDL_IsTextInputShown = FuncLoader.LoadFunction<d_sdl_istextinputshown>(NativeLibrary, "SDL_IsTextInputShown");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void d_sdl_starttextinput();
@@ -841,6 +845,17 @@ internal static class Sdl
public int Length;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct TextEditingExtEvent
{
public EventType Type;
public uint Timestamp;
public uint WindowId;
public byte* Text;
public int Start;
public int Length;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct TextInputEvent
{

View File

@@ -147,14 +147,7 @@ namespace Microsoft.Xna.Framework
character = '\0';
}
if (char.IsControl(character) ||
key == Keys.Left ||
key == Keys.Right ||
key == Keys.Up ||
key == Keys.Down)
{
_view.CallTextInput(character, key);
}
_view.CallKeyDown(character, key);
}
else if (ev.Type == Sdl.EventType.KeyUp)
{
@@ -164,10 +157,24 @@ namespace Microsoft.Xna.Framework
else if (ev.Type == Sdl.EventType.TextEditing)
{
string text;
unsafe { text = ReadString(ev.Text.Text); }
unsafe
{
text = ReadString(ev.Edit.Text);
}
_view.CallTextEditing(text, ev.Edit.Start, ev.Edit.Length);
}
else if (ev.Type == Sdl.EventType.TextEditingExt)
{
string text;
unsafe
{
text = ReadString(ev.EditExt.Text);
Sdl.Free((IntPtr)ev.EditExt.Text);
}
_view.CallTextEditing(text, ev.EditExt.Start, ev.EditExt.Length);
}
else if (ev.Type == Sdl.EventType.TextInput)
{
string text;

View File

@@ -117,7 +117,8 @@ namespace Microsoft.Xna.Framework
* By default SDL2 will hide IME popups since it probably assumes the game will implement their own suggestions box.
* We don't want that, so this hint will allow the system native IME popups to show up when typing in the game.
*/
Sdl.SetHint("SDL_HINT_IME_SHOW_UI", "1");
Sdl.SetHint("SDL_IME_SHOW_UI", "1");
Sdl.SetHint("SDL_IME_SUPPORT_EXTENDED_TEXT", "1");
// when running NUnit tests entry assembly can be null
if (Assembly.GetEntryAssembly() != null)
@@ -339,6 +340,11 @@ namespace Microsoft.Xna.Framework
OnTextInput(this, new TextInputEventArgs(c, key));
}
public void CallKeyDown(char c, Keys key = Keys.None)
{
OnKeyDown(this, new TextInputEventArgs(c, key));
}
public void CallTextEditing(string text, int start, int length)
{
OnTextEditing(this, new TextEditingEventArgs(text, start, length));

View File

@@ -4,6 +4,11 @@ namespace Microsoft.Xna.Framework
{
public static class TextInput
{
public static bool IsTextInputShown()
{
return Sdl.SDL_IsTextInputShown();
}
public static void StartTextInput()
{
Sdl.SDL_StartTextInput();