Adds ability to paste text (ctrl/cmd+v) into chat.
This commit is contained in:
1
AUTHORS
1
AUTHORS
@@ -42,6 +42,7 @@ Also thanks to:
|
|||||||
* Gordon Martin (Happy0)
|
* Gordon Martin (Happy0)
|
||||||
* Ian T. Jacobsen (Smilex)
|
* Ian T. Jacobsen (Smilex)
|
||||||
* Igor Popov (ihptru)
|
* Igor Popov (ihptru)
|
||||||
|
* Imago
|
||||||
* Iran
|
* Iran
|
||||||
* James Dunne (jsd)
|
* James Dunne (jsd)
|
||||||
* Jason (atlimit8)
|
* Jason (atlimit8)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace OpenRA
|
|||||||
void Clear();
|
void Clear();
|
||||||
void Present();
|
void Present();
|
||||||
void PumpInput(IInputHandler inputHandler);
|
void PumpInput(IInputHandler inputHandler);
|
||||||
|
string GetClipboardText();
|
||||||
void DrawPrimitives(PrimitiveType type, int firstVertex, int numVertices);
|
void DrawPrimitives(PrimitiveType type, int firstVertex, int numVertices);
|
||||||
|
|
||||||
void SetLineWidth(float width);
|
void SetLineWidth(float width);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace OpenRA.Widgets
|
|||||||
public Color TextColorDisabled = ChromeMetrics.Get<Color>("TextfieldColorDisabled");
|
public Color TextColorDisabled = ChromeMetrics.Get<Color>("TextfieldColorDisabled");
|
||||||
public Color TextColorInvalid = ChromeMetrics.Get<Color>("TextfieldColorInvalid");
|
public Color TextColorInvalid = ChromeMetrics.Get<Color>("TextfieldColorInvalid");
|
||||||
|
|
||||||
public TextFieldWidget() {}
|
public TextFieldWidget() { }
|
||||||
protected TextFieldWidget(TextFieldWidget widget)
|
protected TextFieldWidget(TextFieldWidget widget)
|
||||||
: base(widget)
|
: base(widget)
|
||||||
{
|
{
|
||||||
@@ -101,6 +101,7 @@ namespace OpenRA.Widgets
|
|||||||
minValue = dist;
|
minValue = dist;
|
||||||
minIndex = i;
|
minIndex = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return minIndex;
|
return minIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +136,7 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
if (e.Key == Keycode.RIGHT)
|
if (e.Key == Keycode.RIGHT)
|
||||||
{
|
{
|
||||||
if (CursorPosition <= Text.Length-1)
|
if (CursorPosition <= Text.Length - 1)
|
||||||
CursorPosition++;
|
CursorPosition++;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -160,6 +161,7 @@ namespace OpenRA.Widgets
|
|||||||
Text = Text.Remove(CursorPosition, 1);
|
Text = Text.Remove(CursorPosition, 1);
|
||||||
OnTextEdited();
|
OnTextEdited();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,6 +170,25 @@ namespace OpenRA.Widgets
|
|||||||
CursorPosition--;
|
CursorPosition--;
|
||||||
Text = Text.Remove(CursorPosition, 1);
|
Text = Text.Remove(CursorPosition, 1);
|
||||||
OnTextEdited();
|
OnTextEdited();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.Key == Keycode.V &&
|
||||||
|
((Platform.CurrentPlatform != PlatformType.OSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
||||||
|
(Platform.CurrentPlatform == PlatformType.OSX && e.Modifiers.HasModifier(Modifiers.Meta))))
|
||||||
|
{
|
||||||
|
var clipboardText = Game.Renderer.Device.GetClipboardText();
|
||||||
|
|
||||||
|
// Take only the first line of the clipboard contents
|
||||||
|
var nl = clipboardText.IndexOf('\n');
|
||||||
|
if (nl > 0)
|
||||||
|
clipboardText = clipboardText.Substring(0, nl);
|
||||||
|
|
||||||
|
clipboardText = clipboardText.Trim();
|
||||||
|
if (clipboardText.Length > 0)
|
||||||
|
HandleTextInput(clipboardText);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -181,8 +202,14 @@ namespace OpenRA.Widgets
|
|||||||
if (MaxLength > 0 && Text.Length >= MaxLength)
|
if (MaxLength > 0 && Text.Length >= MaxLength)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Text = Text.Insert(CursorPosition, text);
|
var pasteLength = text.Length;
|
||||||
CursorPosition++;
|
|
||||||
|
// Truncate the pasted string if the total length (current + paste) is greater than the maximum.
|
||||||
|
if (MaxLength > 0 && MaxLength > Text.Length)
|
||||||
|
pasteLength = Math.Min(text.Length, MaxLength - Text.Length);
|
||||||
|
|
||||||
|
Text = Text.Insert(CursorPosition, text.Substring(0, pasteLength));
|
||||||
|
CursorPosition += pasteLength;
|
||||||
OnTextEdited();
|
OnTextEdited();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ namespace OpenRA.Renderer.Null
|
|||||||
public void Clear() { }
|
public void Clear() { }
|
||||||
public void Present() { }
|
public void Present() { }
|
||||||
|
|
||||||
|
public string GetClipboardText() { return ""; }
|
||||||
public void PumpInput(IInputHandler ih)
|
public void PumpInput(IInputHandler ih)
|
||||||
{
|
{
|
||||||
Game.HasInputFocus = false;
|
Game.HasInputFocus = false;
|
||||||
|
|||||||
@@ -238,6 +238,7 @@ namespace OpenRA.Renderer.Sdl2
|
|||||||
|
|
||||||
public void Present() { SDL.SDL_GL_SwapWindow(window); }
|
public void Present() { SDL.SDL_GL_SwapWindow(window); }
|
||||||
public void PumpInput(IInputHandler inputHandler) { input.PumpInput(inputHandler); }
|
public void PumpInput(IInputHandler inputHandler) { input.PumpInput(inputHandler); }
|
||||||
|
public string GetClipboardText() { return input.GetClipboardText(); }
|
||||||
public IVertexBuffer<Vertex> CreateVertexBuffer(int size) { return new VertexBuffer<Vertex>(size); }
|
public IVertexBuffer<Vertex> CreateVertexBuffer(int size) { return new VertexBuffer<Vertex>(size); }
|
||||||
public ITexture CreateTexture() { return new Texture(); }
|
public ITexture CreateTexture() { return new Texture(); }
|
||||||
public ITexture CreateTexture(Bitmap bitmap) { return new Texture(bitmap); }
|
public ITexture CreateTexture(Bitmap bitmap) { return new Texture(bitmap); }
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using SDL2;
|
using SDL2;
|
||||||
|
|
||||||
@@ -17,6 +19,8 @@ namespace OpenRA.Renderer.Sdl2
|
|||||||
{
|
{
|
||||||
MouseButton lastButtonBits = (MouseButton)0;
|
MouseButton lastButtonBits = (MouseButton)0;
|
||||||
|
|
||||||
|
public string GetClipboardText() { return SDL.SDL_GetClipboardText(); }
|
||||||
|
|
||||||
static MouseButton MakeButton(byte b)
|
static MouseButton MakeButton(byte b)
|
||||||
{
|
{
|
||||||
return b == SDL.SDL_BUTTON_LEFT ? MouseButton.Left
|
return b == SDL.SDL_BUTTON_LEFT ? MouseButton.Left
|
||||||
@@ -126,24 +130,9 @@ namespace OpenRA.Renderer.Sdl2
|
|||||||
|
|
||||||
case SDL.SDL_EventType.SDL_TEXTINPUT:
|
case SDL.SDL_EventType.SDL_TEXTINPUT:
|
||||||
{
|
{
|
||||||
string input;
|
var rawBytes = new byte[SDL.SDL_TEXTINPUTEVENT_TEXT_SIZE];
|
||||||
unsafe
|
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)));
|
||||||
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);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user