clean up low-level keyboard input
This commit is contained in:
@@ -18,9 +18,6 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
@@ -83,12 +80,12 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
|
||||
public bool HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers)
|
||||
public bool HandleKeyPress(KeyInput e)
|
||||
{
|
||||
if (Widget.SelectedWidget != null)
|
||||
return Widget.SelectedWidget.HandleKeyPressOuter(e, modifiers);
|
||||
return Widget.SelectedWidget.HandleKeyPressOuter(e);
|
||||
|
||||
if (rootWidget.HandleKeyPressOuter(e, modifiers))
|
||||
if (rootWidget.HandleKeyPressOuter(e))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -498,18 +498,18 @@ namespace OpenRA
|
||||
{ ')', '0' },
|
||||
};
|
||||
|
||||
public static void HandleKeyPress(KeyPressEventArgs e, Modifiers modifiers)
|
||||
public static void HandleKeyPress(KeyInput e)
|
||||
{
|
||||
int sync = world.SyncHash();
|
||||
|
||||
if (chrome.HandleKeyPress(e, modifiers))
|
||||
if (chrome.HandleKeyPress(e))
|
||||
return;
|
||||
|
||||
var c = RemapKeys.ContainsKey(e.KeyChar) ? RemapKeys[e.KeyChar] : e.KeyChar;
|
||||
|
||||
if (c >= '0' && c <= '9')
|
||||
Game.controller.selection.DoControlGroup(world,
|
||||
c - '0', modifiers);
|
||||
c - '0', e.Modifiers);
|
||||
|
||||
if (c == 08)
|
||||
Game.controller.GotoNextBase();
|
||||
|
||||
@@ -23,6 +23,16 @@ using System.Windows.Forms;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public struct MouseInput
|
||||
{
|
||||
public MouseInputEvent Event;
|
||||
public int2 Location;
|
||||
public MouseButton Button;
|
||||
public Modifiers Modifiers;
|
||||
}
|
||||
|
||||
public enum MouseInputEvent { Down, Move, Up };
|
||||
|
||||
[Flags]
|
||||
public enum MouseButton
|
||||
{
|
||||
@@ -41,13 +51,11 @@ namespace OpenRA
|
||||
Ctrl = (int)Keys.Control,
|
||||
}
|
||||
|
||||
public struct MouseInput
|
||||
public struct KeyInput
|
||||
{
|
||||
public MouseInputEvent Event;
|
||||
public int2 Location;
|
||||
public MouseButton Button;
|
||||
public char KeyChar;
|
||||
public string KeyName;
|
||||
public Modifiers Modifiers;
|
||||
public int VirtKey;
|
||||
}
|
||||
|
||||
public enum MouseInputEvent { Down, Move, Up };
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Orders;
|
||||
using OpenRA.Traits;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
@@ -142,12 +141,12 @@ namespace OpenRA.Widgets
|
||||
paletteOpen = true;
|
||||
currentTab = produces;
|
||||
}
|
||||
|
||||
public override bool HandleKeyPress (KeyPressEventArgs e, Modifiers modifiers)
|
||||
|
||||
public override bool HandleKeyPress(KeyInput e)
|
||||
{
|
||||
if (e.KeyChar == 09)
|
||||
TabChange((Control.ModifierKeys & Keys.Shift) == Keys.Shift);
|
||||
|
||||
TabChange(e.Modifiers.HasModifier(Modifiers.Shift));
|
||||
|
||||
DoBuildingHotkey(Char.ToLowerInvariant(e.KeyChar), Game.world);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
@@ -56,13 +55,13 @@ namespace OpenRA.Widgets
|
||||
|
||||
public override bool HandleInput(MouseInput mi) { return false; }
|
||||
|
||||
public override bool HandleKeyPress(KeyPressEventArgs e, Modifiers modifiers)
|
||||
public override bool HandleKeyPress(KeyInput e)
|
||||
{
|
||||
if (e.KeyChar == '\r')
|
||||
{
|
||||
if (composing)
|
||||
{
|
||||
if (modifiers.HasModifier(Modifiers.Shift))
|
||||
if (e.Modifiers.HasModifier(Modifiers.Shift))
|
||||
{
|
||||
teamChat ^= true;
|
||||
return true;
|
||||
@@ -82,7 +81,7 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
TakeFocus(new MouseInput());
|
||||
composing = true;
|
||||
teamChat ^= modifiers.HasModifier(Modifiers.Shift);
|
||||
teamChat ^= e.Modifiers.HasModifier(Modifiers.Shift);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -104,7 +103,7 @@ namespace OpenRA.Widgets
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.HandleKeyPress(e, modifiers);
|
||||
return base.HandleKeyPress(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace OpenRA.Widgets
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers)
|
||||
public override bool HandleKeyPress(KeyInput e)
|
||||
{
|
||||
// Only take input if we are focused
|
||||
if (!Focused)
|
||||
|
||||
@@ -22,7 +22,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
@@ -52,7 +51,7 @@ namespace OpenRA.Widgets
|
||||
public Func<MouseInput, bool> OnMouseDown = mi => false;
|
||||
public Func<MouseInput, bool> OnMouseUp = mi => false;
|
||||
public Func<MouseInput, bool> OnMouseMove = mi => false;
|
||||
public Func<KeyPressEventArgs, Modifiers, bool> OnKeyPress = (e, modifiers) => false;
|
||||
public Func<KeyInput, bool> OnKeyPress = e => false;
|
||||
|
||||
public Func<bool> IsVisible;
|
||||
|
||||
@@ -211,22 +210,22 @@ namespace OpenRA.Widgets
|
||||
}
|
||||
|
||||
|
||||
public virtual bool HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers) { return false; }
|
||||
public virtual bool HandleKeyPressOuter(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers)
|
||||
public virtual bool HandleKeyPress(KeyInput e) { return false; }
|
||||
public virtual bool HandleKeyPressOuter(KeyInput e)
|
||||
{
|
||||
if (!IsVisible())
|
||||
return false;
|
||||
|
||||
// Can any of our children handle this?
|
||||
foreach (var child in Children)
|
||||
if (child.HandleKeyPressOuter(e, modifiers))
|
||||
if (child.HandleKeyPressOuter(e))
|
||||
return true;
|
||||
|
||||
// Do any widgety behavior (enter text etc)
|
||||
var handled = HandleKeyPress(e,modifiers);
|
||||
var handled = HandleKeyPress(e);
|
||||
|
||||
// Apply any special logic added by delegates; they return true if they caught the input
|
||||
if (OnKeyPress(e,modifiers)) return true;
|
||||
if (OnKeyPress(e)) return true;
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
@@ -157,6 +157,29 @@ namespace OpenRA.GlRenderer
|
||||
| ((raw & Sdl.KMOD_SHIFT) != 0 ? Modifiers.Shift : 0);
|
||||
}
|
||||
|
||||
bool HandleSpecialKey(KeyInput k)
|
||||
{
|
||||
switch (k.VirtKey)
|
||||
{
|
||||
case Sdl.SDLK_F13:
|
||||
var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal)
|
||||
+ Path.DirectorySeparatorChar + DateTime.UtcNow.ToString("OpenRA-yyyy-MM-ddThhmmssZ") + ".bmp";
|
||||
Sdl.SDL_SaveBMP(surf, path);
|
||||
return true;
|
||||
|
||||
case Sdl.SDLK_F4:
|
||||
if (k.Modifiers.HasModifier(Modifiers.Alt))
|
||||
{
|
||||
OpenRA.Game.Exit();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Present()
|
||||
{
|
||||
Sdl.SDL_GL_SwapBuffers();
|
||||
@@ -202,34 +225,17 @@ namespace OpenRA.GlRenderer
|
||||
|
||||
case Sdl.SDL_KEYDOWN:
|
||||
{
|
||||
bool handled = true;
|
||||
switch (e.key.keysym.sym)
|
||||
bool handled = true;
|
||||
|
||||
var keyEvent = new KeyInput
|
||||
{
|
||||
case Sdl.SDLK_UP: Game.HandleArrowKeyScroll("up", true); break;
|
||||
case Sdl.SDLK_LEFT: Game.HandleArrowKeyScroll("left", true); break;
|
||||
case Sdl.SDLK_DOWN: Game.HandleArrowKeyScroll("down", true); break;
|
||||
case Sdl.SDLK_RIGHT: Game.HandleArrowKeyScroll("right", true); break;
|
||||
|
||||
case Sdl.SDLK_F13:
|
||||
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + Path.DirectorySeparatorChar + DateTime.UtcNow.ToString("OpenRA-yyyy-MM-ddThhmmssZ")+".bmp";
|
||||
Sdl.SDL_SaveBMP(surf,path);
|
||||
break;
|
||||
default:
|
||||
handled = false;
|
||||
break;
|
||||
}
|
||||
Modifiers = mods,
|
||||
KeyChar = (char) e.key.keysym.unicode,
|
||||
KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym )
|
||||
};
|
||||
|
||||
if (e.key.keysym.unicode != 0 && !handled)
|
||||
Game.HandleKeyPress(new KeyPressEventArgs((char)e.key.keysym.unicode), mods);
|
||||
|
||||
else if (mods != 0)
|
||||
{
|
||||
var keyName = Sdl.SDL_GetKeyName(e.key.keysym.sym);
|
||||
if (keyName.Length == 1)
|
||||
Game.HandleKeyPress(new KeyPressEventArgs(keyName[0]), mods);
|
||||
else if (keyName == "f4" && ((mods & Modifiers.Alt) != 0))
|
||||
OpenRA.Game.Exit();
|
||||
}
|
||||
if (!HandleSpecialKey(keyEvent))
|
||||
Game.HandleKeyPress(keyEvent);
|
||||
} break;
|
||||
|
||||
case Sdl.SDL_KEYUP:
|
||||
|
||||
Reference in New Issue
Block a user