Пример #1
0
        private static unsafe void ProcessTextInputEvent(Sdl2NativeWindow window, TextInputEvent ev)
        {
            // Calculate the length of the typed text string
            int length;

            for (length = 0; length < TextInputEvent.TextSize && ev.Text[length] != '\0'; length++)
            {
                ;
            }

            // Make sure we have enough space to decode this string
            int decoded_length = Encoding.UTF8.GetCharCount(ev.Text, length);

            if (window.DecodeTextBuffer.Length < decoded_length)
            {
                Array.Resize(
                    ref window.DecodeTextBuffer,
                    2 * Math.Max(decoded_length, window.DecodeTextBuffer.Length));
            }

            // Decode the string from UTF8 to .Net UTF16
            fixed(char *pBuffer = window.DecodeTextBuffer)
            {
                decoded_length = System.Text.Encoding.UTF8.GetChars(
                    ev.Text,
                    length,
                    pBuffer,
                    window.DecodeTextBuffer.Length);
            }

            for (int i = 0; i < decoded_length; i++)
            {
                window.OnKeyPress(window.DecodeTextBuffer[i]);
            }
        }
        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));
                        }
                    }
            }
        }
Пример #3
0
        static unsafe void ProcessTextInputEvent(Sdl2NativeWindow window, TextInputEvent ev)
        {
            // Calculate the length of the typed text string
            int length;
            for (length = 0; length < TextInputEvent.TextSize && ev.Text[length] != '\0'; length++)
                ;

            // Make sure we have enough space to decode this string
            int decoded_length = Encoding.UTF8.GetCharCount(ev.Text, length);
            if (window.DecodeTextBuffer.Length < decoded_length)
            {
                Array.Resize(
                    ref window.DecodeTextBuffer,
                    2 * Math.Max(decoded_length, window.DecodeTextBuffer.Length));
            }

            // Decode the string from UTF8 to .Net UTF16
            fixed (char* pBuffer = window.DecodeTextBuffer)
            {
                decoded_length = System.Text.Encoding.UTF8.GetChars(
                    ev.Text,
                    length,
                    pBuffer,
                    window.DecodeTextBuffer.Length);
            }

            for (int i = 0; i < decoded_length; i++)
            {
                window.OnKeyPress(window.DecodeTextBuffer[i]);
            }
        }
Пример #4
0
 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));
             }
         }
     }
 }