Adds ability to paste text (ctrl/cmd+v) into chat.

This commit is contained in:
ImagoTrigger
2014-08-29 14:23:57 -05:00
committed by Paul Chote
parent 6e5d1da468
commit eb2124bb89
6 changed files with 42 additions and 23 deletions

View File

@@ -8,6 +8,8 @@
*/
#endregion
using System;
using System.Runtime.InteropServices;
using System.Text;
using SDL2;
@@ -17,6 +19,8 @@ namespace OpenRA.Renderer.Sdl2
{
MouseButton lastButtonBits = (MouseButton)0;
public string GetClipboardText() { return SDL.SDL_GetClipboardText(); }
static MouseButton MakeButton(byte b)
{
return b == SDL.SDL_BUTTON_LEFT ? MouseButton.Left
@@ -126,24 +130,9 @@ namespace OpenRA.Renderer.Sdl2
case SDL.SDL_EventType.SDL_TEXTINPUT:
{
string input;
unsafe
{
var data = new byte[SDL.SDL_TEXTINPUTEVENT_TEXT_SIZE];
var i = 0;
for (; i < SDL.SDL_TEXTINPUTEVENT_TEXT_SIZE; i++)
{
var b = e.text.text[i];
if (b == '\0')
break;
data[i] = b;
}
input = Encoding.UTF8.GetString(data, 0, i);
}
inputHandler.OnTextInput(input);
var rawBytes = new byte[SDL.SDL_TEXTINPUTEVENT_TEXT_SIZE];
unsafe { Marshal.Copy((IntPtr)e.text.text, rawBytes, 0, SDL.SDL_TEXTINPUTEVENT_TEXT_SIZE); }
inputHandler.OnTextInput(Encoding.UTF8.GetString(rawBytes, 0, Array.IndexOf(rawBytes, (byte)0)));
break;
}