Build 0.20.4.0

This commit is contained in:
Markus Isberg
2022-11-11 17:57:23 +02:00
parent edaf4b09fe
commit 54712b5dc9
201 changed files with 7618 additions and 2020 deletions
@@ -240,6 +240,22 @@ internal static class Sdl
return pointer;
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate bool d_sdl_istextinputactive();
public static d_sdl_istextinputactive SDL_IsTextInputActive = FuncLoader.LoadFunction<d_sdl_istextinputactive>(NativeLibrary, "SDL_IsTextInputActive");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void d_sdl_starttextinput();
public static d_sdl_starttextinput SDL_StartTextInput = FuncLoader.LoadFunction<d_sdl_starttextinput>(NativeLibrary, "SDL_StartTextInput");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void d_sdl_stoptextinput();
public static d_sdl_stoptextinput SDL_StopTextInput = FuncLoader.LoadFunction<d_sdl_stoptextinput>(NativeLibrary, "SDL_StopTextInput");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void d_sdl_settextinputrect(ref Rectangle rect);
public static d_sdl_settextinputrect SDL_SetTextInputRect = FuncLoader.LoadFunction<d_sdl_settextinputrect>(NativeLibrary, "SDL_SetTextInputRect");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void d_sdl_clearerror();
public static d_sdl_clearerror ClearError = FuncLoader.LoadFunction<d_sdl_clearerror>(NativeLibrary, "SDL_ClearError");
@@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
@@ -136,8 +137,7 @@ namespace Microsoft.Xna.Framework
{
var key = KeyboardUtil.ToXna(ev.Key.Keysym.Sym);
if (!_keys.Contains(key))
_keys.Add(key);
if (!_keys.Contains(key)) _keys.Add(key);
//TODO: rethink all of this
char character = (char)KeyboardUtil.ApplyModifiers(ev.Key.Keysym.Sym, ev.Key.Keysym.Mod);
@@ -161,24 +161,23 @@ namespace Microsoft.Xna.Framework
var key = KeyboardUtil.ToXna(ev.Key.Keysym.Sym);
_keys.Remove(key);
}
else if (ev.Type == Sdl.EventType.TextEditing)
{
string text;
unsafe { text = ReadString(ev.Text.Text); }
_view.CallTextEditing(text, ev.Edit.Start, ev.Edit.Length);
}
else if (ev.Type == Sdl.EventType.TextInput)
{
int len = 0;
string text = String.Empty;
unsafe
string text;
unsafe { text = ReadString(ev.Text.Text); }
if (text.Length is 0) { continue; }
foreach (char c in text)
{
while (Marshal.ReadByte ((IntPtr)ev.Text.Text, len) != 0) {
len++;
}
var buffer = new byte [len];
Marshal.Copy ((IntPtr)ev.Text.Text, buffer, 0, len);
text = System.Text.Encoding.UTF8.GetString (buffer);
}
if (text.Length == 0)
continue;
foreach (var c in text)
{
var key = KeyboardUtil.ToXna((int)c);
var key = KeyboardUtil.ToXna(c);
_view.CallTextInput(c, key);
}
}
@@ -194,11 +193,22 @@ namespace Microsoft.Xna.Framework
IsActive = false;
else if (ev.Window.EventID == Sdl.Window.EventId.Moved)
_view.Moved();
else if (ev.Window.EventID == Sdl.Window.EventId.Close)
_isExiting++;
else if (ev.Window.EventID == Sdl.Window.EventId.Close) _isExiting++;
}
}
}
static unsafe string ReadString(byte* ptr)
{
int len = 0;
while (Marshal.ReadByte((IntPtr)ptr, len) != 0)
{
len++;
}
var buffer = new byte [len];
Marshal.Copy((IntPtr)ptr, buffer, 0, len);
return Encoding.UTF8.GetString(buffer);
}
}
public override void StartRunLoop()
@@ -113,6 +113,12 @@ namespace Microsoft.Xna.Framework
Sdl.SetHint("SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS", "0");
Sdl.SetHint("SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS", "1");
/*
* 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");
// when running NUnit tests entry assembly can be null
if (Assembly.GetEntryAssembly() != null)
{
@@ -333,6 +339,11 @@ namespace Microsoft.Xna.Framework
OnTextInput(this, new TextInputEventArgs(c, key));
}
public void CallTextEditing(string text, int start, int length)
{
OnTextEditing(this, new TextEditingEventArgs(text, start, length));
}
public void DropFile(string filePath)
{
OnFileDropped(new FileDropEventArgs(filePath));