diff --git a/OpenRa.Game/Controller.cs b/OpenRa.Game/Controller.cs index 021d31e52d..71e4fef5ed 100644 --- a/OpenRa.Game/Controller.cs +++ b/OpenRa.Game/Controller.cs @@ -29,17 +29,9 @@ namespace OpenRa { public class Controller : IHandleInput { - public IOrderGenerator orderGenerator; + public IOrderGenerator orderGenerator = new UnitOrderGenerator(); public Selection selection = new Selection(); - readonly Func GetModifierKeys; - - public Controller(Func getModifierKeys) - { - GetModifierKeys = getModifierKeys; - CancelInputMode(); - } - public void CancelInputMode() { orderGenerator = new UnitOrderGenerator(); } public bool ToggleInputMode() where T : IOrderGenerator, new() @@ -123,6 +115,7 @@ namespace OpenRa } public float2 MousePosition { get { return dragEnd; } } + Modifiers modifiers; public string ChooseCursor( World world ) { @@ -134,7 +127,7 @@ namespace OpenRa { Location = ( Game.CellSize * MousePosition - Game.viewport.Location ).ToInt2(), Button = MouseButton.Right, - Modifiers = GetModifierKeys(), + Modifiers = modifiers }; return orderGenerator.GetCursor( world, MousePosition.ToInt2(), mi ); @@ -145,5 +138,7 @@ namespace OpenRa throw new InvalidOperationException( "Desync in Controller.ChooseCursor" ); } } + + public void SetModifiers(Modifiers mods) { modifiers = mods; } } } diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index fca6a83f82..db1b55d8bc 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -341,6 +341,11 @@ namespace OpenRa throw new InvalidOperationException( "Desync in OnKeyPress" ); } + public static void HandleModifierKeys(Modifiers mods) + { + controller.SetModifiers(mods); + } + static Size GetResolution(Settings settings) { var desktopResolution = Screen.PrimaryScreen.Bounds.Size; @@ -354,9 +359,6 @@ namespace OpenRa desktopResolution.Height); } - // [DllImport("user32")] - // static extern int ShowCursor([MarshalAs(UnmanagedType.Bool)] bool visible); - public static void PreInit(Settings settings) { while (!Directory.Exists("mods")) @@ -383,7 +385,7 @@ namespace OpenRa renderer = new Renderer(resolution, windowed); resolution = renderer.Resolution; - var controller = new Controller(() => (Modifiers)(int)0/*ModifierKeys*/); /* a bit of insane input routing */ + var controller = new Controller(); /* a bit of insane input routing */ Game.Initialize(Game.Settings.Map, renderer, new int2(resolution), Game.Settings.Player, controller); diff --git a/OpenRa.Gl/GraphicsDevice.cs b/OpenRa.Gl/GraphicsDevice.cs index 59ed94b298..a995c18f0a 100644 --- a/OpenRa.Gl/GraphicsDevice.cs +++ b/OpenRa.Gl/GraphicsDevice.cs @@ -124,7 +124,6 @@ namespace OpenRa.GlRenderer CheckGlError(); } - Modifiers mods = 0; MouseButtons lastButtonBits = (MouseButtons)0; static MouseButtons MakeButton(byte b) @@ -135,10 +134,20 @@ namespace OpenRa.GlRenderer : 0; } + static Modifiers MakeModifiers(int raw) + { + return ((raw & Sdl.KMOD_ALT) != 0 ? Modifiers.Alt : 0) + | ((raw & Sdl.KMOD_CTRL) != 0 ? Modifiers.Ctrl : 0) + | ((raw & Sdl.KMOD_SHIFT) != 0 ? Modifiers.Shift : 0); + } + public void Present() { Sdl.SDL_GL_SwapBuffers(); + var mods = MakeModifiers(Sdl.SDL_GetModState()); + Game.HandleModifierKeys(mods); + Sdl.SDL_Event e; while (Sdl.SDL_PollEvent(out e) != 0) { @@ -177,9 +186,6 @@ namespace OpenRa.GlRenderer case Sdl.SDL_KEYDOWN: { - mods = ( ( e.key.keysym.mod & Sdl.KMOD_ALT ) != 0 ? Modifiers.Alt : 0 ) - | ( ( e.key.keysym.mod & Sdl.KMOD_CTRL ) != 0 ? Modifiers.Ctrl : 0 ) - | ( ( e.key.keysym.mod & Sdl.KMOD_SHIFT ) != 0 ? Modifiers.Shift : 0 ); if( e.key.keysym.unicode != 0 ) Game.HandleKeyPress( new KeyPressEventArgs( (char)e.key.keysym.unicode ), mods );