From d7d0d371c667e77edd58d10a11d8848fa549fc3f Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 1 Nov 2010 18:39:37 +1300 Subject: [PATCH] (bob) refactor input dispatch; remove public Dispatch*Input from game; (chris) fix build failures due to rebase past gecko --- .../Graphics/IGraphicsDevice.cs | 2 +- .../Graphics/IInputHandler.cs | 21 +- OpenRA.FileFormats/OpenRA.FileFormats.csproj | 2 + OpenRA.Game/Game.cs | 27 +- OpenRA.Game/Graphics/Renderer.cs | 4 +- OpenRA.Game/Graphics/Viewport.cs | 4 +- OpenRA.Game/InputHandler.cs | 58 ++ OpenRA.Game/OpenRA.Game.csproj | 5 +- OpenRA.Gl/GraphicsDevice.cs | 510 +++++++++--------- OpenRA.Mods.Cnc/CncLoadScreen.cs | 4 +- OpenRA.Mods.RA/NullLoadScreen.cs | 6 +- OpenRA.Mods.RA/RALoadScreen.cs | 4 +- OpenRA.Renderer.Null/NullGraphicsDevice.cs | 37 +- 13 files changed, 359 insertions(+), 325 deletions(-) rename OpenRA.Game/MainWindow.cs => OpenRA.FileFormats/Graphics/IInputHandler.cs (67%) create mode 100755 OpenRA.Game/InputHandler.cs diff --git a/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs b/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs index 2d3d9821ec..beb79b8f18 100755 --- a/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs +++ b/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs @@ -40,7 +40,7 @@ namespace OpenRA.FileFormats.Graphics void Begin(); void End(); void Clear( Color color ); - void Present(); + void Present( IInputHandler inputHandler ); void DrawIndexedPrimitives( PrimitiveType type, Range vertexRange, Range indexRange ); void DrawIndexedPrimitives( PrimitiveType type, int vertexPool, int numPrimitives ); diff --git a/OpenRA.Game/MainWindow.cs b/OpenRA.FileFormats/Graphics/IInputHandler.cs similarity index 67% rename from OpenRA.Game/MainWindow.cs rename to OpenRA.FileFormats/Graphics/IInputHandler.cs index 2a0990f0d5..59b0a7a5ab 100755 --- a/OpenRA.Game/MainWindow.cs +++ b/OpenRA.FileFormats/Graphics/IInputHandler.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made @@ -9,16 +9,33 @@ #endregion using System; +using System.Collections.Generic; +using System.Linq; using System.Windows.Forms; namespace OpenRA { + public interface IInputHandler + { + void ModifierKeys( Modifiers mods ); + void OnKeyInput( KeyInput input ); + void OnMouseInput( MouseInput input ); + } + public struct MouseInput { public MouseInputEvent Event; - public int2 Location; public MouseButton Button; + public int2 Location; public Modifiers Modifiers; + + public MouseInput( MouseInputEvent ev, MouseButton button, int2 location, Modifiers mods ) + { + this.Event = ev; + this.Button = button; + this.Location = location; + this.Modifiers = mods; + } } public enum MouseInputEvent { Down, Move, Up }; diff --git a/OpenRA.FileFormats/OpenRA.FileFormats.csproj b/OpenRA.FileFormats/OpenRA.FileFormats.csproj index e0abdd058f..093bb41250 100644 --- a/OpenRA.FileFormats/OpenRA.FileFormats.csproj +++ b/OpenRA.FileFormats/OpenRA.FileFormats.csproj @@ -45,6 +45,7 @@ + False @@ -61,6 +62,7 @@ + diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index d02ed323c6..ff4e9512cb 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -99,7 +99,7 @@ namespace OpenRA using (new PerfSample("render")) { ++RenderFrame; - viewport.DrawRegions(worldRenderer); + viewport.DrawRegions(worldRenderer, new DefaultInputHandler( orderManager.world )); Sound.SetListenerPosition(viewport.Location + .5f * new float2(viewport.Width, viewport.Height)); } @@ -181,37 +181,14 @@ namespace OpenRA AfterGameStart( orderManager.world ); } - public static void DispatchMouseInput(MouseInputEvent ev, MouseEventArgs e, Modifiers modifierKeys) - { - Sync.CheckSyncUnchanged( orderManager.world, () => - { - var mi = new MouseInput - { - Button = (MouseButton)(int)e.Button, - Event = ev, - Location = new int2( e.Location ), - Modifiers = modifierKeys, - }; - Widget.HandleInput( mi ); - } ); - } - public static bool IsHost { get { return orderManager.Connection.LocalClientId == 0; } } - public static void HandleKeyEvent(KeyInput e) - { - Sync.CheckSyncUnchanged( orderManager.world, () => - { - Widget.HandleKeyPress( e ); - } ); - } - static Modifiers modifiers; public static Modifiers GetModifierKeys() { return modifiers; } - public static void HandleModifierKeys(Modifiers mods) { modifiers = mods; } + internal static void HandleModifierKeys(Modifiers mods) { modifiers = mods; } internal static void Initialize(Arguments args) { diff --git a/OpenRA.Game/Graphics/Renderer.cs b/OpenRA.Game/Graphics/Renderer.cs index 0a463f425e..0318ded34a 100644 --- a/OpenRA.Game/Graphics/Renderer.cs +++ b/OpenRA.Game/Graphics/Renderer.cs @@ -92,11 +92,11 @@ namespace OpenRA.Graphics s.Commit(); } - public void EndFrame() + public void EndFrame( IInputHandler inputHandler ) { Flush(); device.End(); - device.Present(); + device.Present( inputHandler ); } public void DrawBatch(IVertexBuffer vertices, IIndexBuffer indices, diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 9f0c1bb5ee..f7125d2077 100755 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -96,7 +96,7 @@ namespace OpenRA.Graphics this.scrollPosition = Game.CellSize* mapStart; } - public void DrawRegions( WorldRenderer wr ) + public void DrawRegions( WorldRenderer wr, IInputHandler inputHandler ) { renderer.BeginFrame(scrollPosition); wr.Draw(); @@ -107,7 +107,7 @@ namespace OpenRA.Graphics var c = new Cursor(cursorName); c.Draw(wr, (int)cursorFrame, Viewport.LastMousePos + Location); - renderer.EndFrame(); + renderer.EndFrame( inputHandler ); } public void Tick() diff --git a/OpenRA.Game/InputHandler.cs b/OpenRA.Game/InputHandler.cs new file mode 100755 index 0000000000..a938777587 --- /dev/null +++ b/OpenRA.Game/InputHandler.cs @@ -0,0 +1,58 @@ +#region Copyright & License Information +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using OpenRA.Widgets; +using OpenRA.Network; + +namespace OpenRA +{ + public class NullInputHandler : IInputHandler + { + // ignore all input + public void ModifierKeys( Modifiers mods ) { } + public void OnKeyInput( KeyInput input ) { } + public void OnMouseInput( MouseInput input ) { } + } + + public class DefaultInputHandler : IInputHandler + { + readonly World world; + public DefaultInputHandler( World world ) + { + this.world = world; + } + + public void ModifierKeys( Modifiers mods ) + { + Game.HandleModifierKeys( mods ); + } + + public void OnKeyInput( KeyInput input ) + { + Sync.CheckSyncUnchanged( world, () => + { + Widget.HandleKeyPress( input ); + } ); + } + + public void OnMouseInput( MouseInput input ) + { + Sync.CheckSyncUnchanged( world, () => + { + Widget.HandleInput( input ); + } ); + } + } +} diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index ca0a89839f..92d665fb2d 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -139,8 +139,6 @@ - - @@ -214,6 +212,7 @@ + @@ -257,4 +256,4 @@ --> - \ No newline at end of file + diff --git a/OpenRA.Gl/GraphicsDevice.cs b/OpenRA.Gl/GraphicsDevice.cs index f6242c878c..7cd548e67c 100755 --- a/OpenRA.Gl/GraphicsDevice.cs +++ b/OpenRA.Gl/GraphicsDevice.cs @@ -1,11 +1,11 @@ #region Copyright & License Information /* - * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see LICENSE. - */ +* Copyright 2007-2010 The OpenRA Developers (see AUTHORS) +* This file is part of OpenRA, which is free software. It is made +* available to you under the terms of the GNU General Public License +* as published by the Free Software Foundation. For more information, +* see LICENSE. +*/ #endregion using System; @@ -21,299 +21,301 @@ using Tao.Sdl; namespace OpenRA.GlRenderer { - public class GraphicsDevice : IGraphicsDevice - { - Size windowSize; - internal IntPtr cgContext; - internal int vertexProfile, fragmentProfile; + public class GraphicsDevice : IGraphicsDevice + { + Size windowSize; + internal IntPtr cgContext; + internal int vertexProfile, fragmentProfile; - IntPtr surf; + IntPtr surf; - public Size WindowSize { get { return windowSize; } } + public Size WindowSize { get { return windowSize; } } - public enum GlError - { - GL_NO_ERROR = Gl.GL_NO_ERROR, - GL_INVALID_ENUM = Gl.GL_INVALID_ENUM, - GL_INVALID_VALUE = Gl.GL_INVALID_VALUE, - GL_STACK_OVERFLOW = Gl.GL_STACK_OVERFLOW, - GL_STACK_UNDERFLOW = Gl.GL_STACK_UNDERFLOW, - GL_OUT_OF_MEMORY = Gl.GL_OUT_OF_MEMORY, - GL_TABLE_TOO_LARGE = Gl.GL_TABLE_TOO_LARGE, - } + public enum GlError + { + GL_NO_ERROR = Gl.GL_NO_ERROR, + GL_INVALID_ENUM = Gl.GL_INVALID_ENUM, + GL_INVALID_VALUE = Gl.GL_INVALID_VALUE, + GL_STACK_OVERFLOW = Gl.GL_STACK_OVERFLOW, + GL_STACK_UNDERFLOW = Gl.GL_STACK_UNDERFLOW, + GL_OUT_OF_MEMORY = Gl.GL_OUT_OF_MEMORY, + GL_TABLE_TOO_LARGE = Gl.GL_TABLE_TOO_LARGE, + } - internal static void CheckGlError() - { - var n = Gl.glGetError(); - if (n != Gl.GL_NO_ERROR) - throw new InvalidOperationException("GL Error: " + ((GlError)n).ToString()); - } + internal static void CheckGlError() + { + var n = Gl.glGetError(); + if( n != Gl.GL_NO_ERROR ) + throw new InvalidOperationException( "GL Error: " + ( (GlError)n ).ToString() ); + } - public GraphicsDevice(int width, int height, WindowMode window, bool vsync) - { - Sdl.SDL_Init(Sdl.SDL_INIT_NOPARACHUTE | Sdl.SDL_INIT_VIDEO); - Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_DOUBLEBUFFER, 1); - Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_RED_SIZE, 8); - Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_GREEN_SIZE, 8); - Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_BLUE_SIZE, 8); - Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_ALPHA_SIZE, 0); + public GraphicsDevice( int width, int height, WindowMode window, bool vsync ) + { + Sdl.SDL_Init( Sdl.SDL_INIT_NOPARACHUTE | Sdl.SDL_INIT_VIDEO ); + Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_DOUBLEBUFFER, 1 ); + Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_RED_SIZE, 8 ); + Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_GREEN_SIZE, 8 ); + Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_BLUE_SIZE, 8 ); + Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_ALPHA_SIZE, 0 ); - int windowFlags = 0; - switch (window) - { - case WindowMode.Fullscreen: - windowFlags |= Sdl.SDL_FULLSCREEN; - break; - case WindowMode.PseudoFullscreen: - // pseudo-fullscreen only reliably works on windows; fall back to fullscreen for everyone else - windowFlags |= (Environment.OSVersion.Platform == PlatformID.Win32NT) ? Sdl.SDL_NOFRAME : Sdl.SDL_FULLSCREEN; - Environment.SetEnvironmentVariable("SDL_VIDEO_WINDOW_POS", "0,0"); - break; - default: - break; - } + int windowFlags = 0; + switch( window ) + { + case WindowMode.Fullscreen: + windowFlags |= Sdl.SDL_FULLSCREEN; + break; + case WindowMode.PseudoFullscreen: + // pseudo-fullscreen only reliably works on windows; fall back to fullscreen for everyone else + windowFlags |= ( Environment.OSVersion.Platform == PlatformID.Win32NT ) ? Sdl.SDL_NOFRAME : Sdl.SDL_FULLSCREEN; + Environment.SetEnvironmentVariable( "SDL_VIDEO_WINDOW_POS", "0,0" ); + break; + default: + break; + } - surf = Sdl.SDL_SetVideoMode(width, height, 0, Sdl.SDL_OPENGL | windowFlags); + surf = Sdl.SDL_SetVideoMode( width, height, 0, Sdl.SDL_OPENGL | windowFlags ); - Sdl.SDL_WM_SetCaption("OpenRA", "OpenRA"); - Sdl.SDL_ShowCursor(0); - Sdl.SDL_EnableUNICODE(1); - Sdl.SDL_EnableKeyRepeat(Sdl.SDL_DEFAULT_REPEAT_DELAY, Sdl.SDL_DEFAULT_REPEAT_INTERVAL); + Sdl.SDL_WM_SetCaption( "OpenRA", "OpenRA" ); + Sdl.SDL_ShowCursor( 0 ); + Sdl.SDL_EnableUNICODE( 1 ); + Sdl.SDL_EnableKeyRepeat( Sdl.SDL_DEFAULT_REPEAT_DELAY, Sdl.SDL_DEFAULT_REPEAT_INTERVAL ); - CheckGlError(); + CheckGlError(); - windowSize = new Size(width, height); + windowSize = new Size( width, height ); - cgContext = Cg.cgCreateContext(); + cgContext = Cg.cgCreateContext(); - Cg.cgSetErrorCallback(CgErrorCallback); + Cg.cgSetErrorCallback( CgErrorCallback ); - CgGl.cgGLRegisterStates(cgContext); - CgGl.cgGLSetManageTextureParameters(cgContext, true); - vertexProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_VERTEX); - fragmentProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_FRAGMENT); + CgGl.cgGLRegisterStates( cgContext ); + CgGl.cgGLSetManageTextureParameters( cgContext, true ); + vertexProfile = CgGl.cgGLGetLatestProfile( CgGl.CG_GL_VERTEX ); + fragmentProfile = CgGl.cgGLGetLatestProfile( CgGl.CG_GL_FRAGMENT ); - //Console.WriteLine("VP Profile: " + vertexProfile); - //Console.WriteLine("FP Profile: " + fragmentProfile); + //Console.WriteLine("VP Profile: " + vertexProfile); + //Console.WriteLine("FP Profile: " + fragmentProfile); - Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY); - CheckGlError(); - Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY); - CheckGlError(); + Gl.glEnableClientState( Gl.GL_VERTEX_ARRAY ); + CheckGlError(); + Gl.glEnableClientState( Gl.GL_TEXTURE_COORD_ARRAY ); + CheckGlError(); - Sdl.SDL_SetModState(0); // i have had enough. - } + Sdl.SDL_SetModState( 0 ); // i have had enough. + } - static Cg.CGerrorCallbackFuncDelegate CgErrorCallback = () => - { - var err = Cg.cgGetError(); - var str = Cg.cgGetErrorString(err); - throw new InvalidOperationException( - string.Format("CG Error: {0}: {1}", err, str)); - }; + static Cg.CGerrorCallbackFuncDelegate CgErrorCallback = () => + { + var err = Cg.cgGetError(); + var str = Cg.cgGetErrorString( err ); + throw new InvalidOperationException( + string.Format( "CG Error: {0}: {1}", err, str ) ); + }; - public void EnableScissor(int left, int top, int width, int height) - { - if (width < 0) width = 0; - if (height < 0) height = 0; - Gl.glScissor(left, windowSize.Height - (top + height), width, height); - CheckGlError(); - Gl.glEnable(Gl.GL_SCISSOR_TEST); - CheckGlError(); - } + public void EnableScissor( int left, int top, int width, int height ) + { + if( width < 0 ) width = 0; + if( height < 0 ) height = 0; + Gl.glScissor( left, windowSize.Height - ( top + height ), width, height ); + CheckGlError(); + Gl.glEnable( Gl.GL_SCISSOR_TEST ); + CheckGlError(); + } - public void DisableScissor() - { - Gl.glDisable(Gl.GL_SCISSOR_TEST); - CheckGlError(); - } + public void DisableScissor() + { + Gl.glDisable( Gl.GL_SCISSOR_TEST ); + CheckGlError(); + } - public void Begin() { } - public void End() { } + public void Begin() { } + public void End() { } - public void Clear(Color c) - { - Gl.glClearColor(0, 0, 0, 0); - CheckGlError(); - Gl.glClear(Gl.GL_COLOR_BUFFER_BIT); - CheckGlError(); - } + public void Clear( Color c ) + { + Gl.glClearColor( 0, 0, 0, 0 ); + CheckGlError(); + Gl.glClear( Gl.GL_COLOR_BUFFER_BIT ); + CheckGlError(); + } - MouseButtons lastButtonBits = (MouseButtons)0; + MouseButton lastButtonBits = (MouseButton)0; - static MouseButtons MakeButton(byte b) - { - return b == Sdl.SDL_BUTTON_LEFT ? MouseButtons.Left - : b == Sdl.SDL_BUTTON_RIGHT ? MouseButtons.Right - : b == Sdl.SDL_BUTTON_MIDDLE ? MouseButtons.Middle - : 0; - } + static MouseButton MakeButton( byte b ) + { + return b == Sdl.SDL_BUTTON_LEFT ? MouseButton.Left + : b == Sdl.SDL_BUTTON_RIGHT ? MouseButton.Right + : b == Sdl.SDL_BUTTON_MIDDLE ? MouseButton.Middle + : 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); - } + 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 ); + } - 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; + 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; + case Sdl.SDLK_F4: + if( k.Modifiers.HasModifier( Modifiers.Alt ) ) + { + OpenRA.Game.Exit(); + return true; + } + return false; - default: - return false; - } - } + default: + return false; + } + } - public void Present() - { - Sdl.SDL_GL_SwapBuffers(); - Game.HasInputFocus = 0 != (Sdl.SDL_GetAppState() & Sdl.SDL_APPINPUTFOCUS); - - var mods = MakeModifiers(Sdl.SDL_GetModState()); - Game.HandleModifierKeys(mods); - MouseEventArgs pendingMotion = null; + public void Present( IInputHandler inputHandler ) + { + Sdl.SDL_GL_SwapBuffers(); + Game.HasInputFocus = 0 != ( Sdl.SDL_GetAppState() & Sdl.SDL_APPINPUTFOCUS ); - Sdl.SDL_Event e; - while (Sdl.SDL_PollEvent(out e) != 0) - { - switch (e.type) - { - case Sdl.SDL_QUIT: - OpenRA.Game.Exit(); - break; + var mods = MakeModifiers( Sdl.SDL_GetModState() ); + inputHandler.ModifierKeys( mods ); + MouseInput? pendingMotion = null; - case Sdl.SDL_MOUSEBUTTONDOWN: - { - if (pendingMotion != null) - { - Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods); - pendingMotion = null; - } + Sdl.SDL_Event e; + while( Sdl.SDL_PollEvent( out e ) != 0 ) + { + switch( e.type ) + { + case Sdl.SDL_QUIT: + OpenRA.Game.Exit(); + break; - var button = MakeButton(e.button.button); - lastButtonBits |= button; + case Sdl.SDL_MOUSEBUTTONDOWN: + { + if( pendingMotion != null ) + { + inputHandler.OnMouseInput( pendingMotion.Value ); + pendingMotion = null; + } - Game.DispatchMouseInput(MouseInputEvent.Down, - new MouseEventArgs(button, 1, e.button.x, e.button.y, 0), - mods); - } break; + var button = MakeButton( e.button.button ); + lastButtonBits |= button; - case Sdl.SDL_MOUSEBUTTONUP: - { - if (pendingMotion != null) - { - Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods); - pendingMotion = null; - } + inputHandler.OnMouseInput( new MouseInput( + MouseInputEvent.Down, button, new int2( e.button.x, e.button.y ), mods ) ); + } break; - var button = MakeButton(e.button.button); - lastButtonBits &= ~button; + case Sdl.SDL_MOUSEBUTTONUP: + { + if( pendingMotion != null ) + { + inputHandler.OnMouseInput( pendingMotion.Value ); + pendingMotion = null; + } - Game.DispatchMouseInput(MouseInputEvent.Up, - new MouseEventArgs(button, 1, e.button.x, e.button.y, 0), - mods); - } break; + var button = MakeButton( e.button.button ); + lastButtonBits &= ~button; - case Sdl.SDL_MOUSEMOTION: - { - pendingMotion = new MouseEventArgs(lastButtonBits, 0, e.motion.x, e.motion.y, 0); - } break; + inputHandler.OnMouseInput( new MouseInput( + MouseInputEvent.Up, button, new int2( e.button.x, e.button.y ), mods ) ); + } break; - case Sdl.SDL_KEYDOWN: - { - var keyEvent = new KeyInput - { - Event = KeyInputEvent.Down, - Modifiers = mods, - KeyChar = (char)e.key.keysym.unicode, - KeyName = Sdl.SDL_GetKeyName(e.key.keysym.sym), - VirtKey = e.key.keysym.sym - }; + case Sdl.SDL_MOUSEMOTION: + { + pendingMotion = new MouseInput( + MouseInputEvent.Move, + lastButtonBits, + new int2( e.motion.x, e.motion.y ), + mods ); + } break; - if (!HandleSpecialKey(keyEvent)) - Game.HandleKeyEvent(keyEvent); - } break; + case Sdl.SDL_KEYDOWN: + { + var keyEvent = new KeyInput + { + Event = KeyInputEvent.Down, + Modifiers = mods, + KeyChar = (char)e.key.keysym.unicode, + KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ), + VirtKey = e.key.keysym.sym + }; - case Sdl.SDL_KEYUP: - { - var keyEvent = new KeyInput - { - Event = KeyInputEvent.Up, - Modifiers = mods, - KeyChar = (char)e.key.keysym.unicode, - KeyName = Sdl.SDL_GetKeyName(e.key.keysym.sym), - VirtKey = e.key.keysym.sym - }; + if( !HandleSpecialKey( keyEvent ) ) + inputHandler.OnKeyInput( keyEvent ); + } break; - Game.HandleKeyEvent(keyEvent); - } break; - } - } + case Sdl.SDL_KEYUP: + { + var keyEvent = new KeyInput + { + Event = KeyInputEvent.Up, + Modifiers = mods, + KeyChar = (char)e.key.keysym.unicode, + KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ), + VirtKey = e.key.keysym.sym + }; - if (pendingMotion != null) - { - Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods); - pendingMotion = null; - } + inputHandler.OnKeyInput( keyEvent ); + } break; + } + } - CheckGlError(); - } + if( pendingMotion != null ) + { + inputHandler.OnMouseInput( pendingMotion.Value ); + pendingMotion = null; + } - public void DrawIndexedPrimitives(PrimitiveType pt, Range vertices, Range indices) - { - Gl.glDrawElements(ModeFromPrimitiveType(pt), indices.End - indices.Start, - Gl.GL_UNSIGNED_SHORT, new IntPtr(indices.Start * 2)); - CheckGlError(); - } + CheckGlError(); + } - public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives) - { - Gl.glDrawElements(ModeFromPrimitiveType(pt), numPrimitives * IndicesPerPrimitive(pt), - Gl.GL_UNSIGNED_SHORT, IntPtr.Zero); - CheckGlError(); - } + public void DrawIndexedPrimitives( PrimitiveType pt, Range vertices, Range indices ) + { + Gl.glDrawElements( ModeFromPrimitiveType( pt ), indices.End - indices.Start, + Gl.GL_UNSIGNED_SHORT, new IntPtr( indices.Start * 2 ) ); + CheckGlError(); + } - static int ModeFromPrimitiveType(PrimitiveType pt) - { - switch (pt) - { - case PrimitiveType.PointList: return Gl.GL_POINTS; - case PrimitiveType.LineList: return Gl.GL_LINES; - case PrimitiveType.TriangleList: return Gl.GL_TRIANGLES; - } - throw new NotImplementedException(); - } + public void DrawIndexedPrimitives( PrimitiveType pt, int numVerts, int numPrimitives ) + { + Gl.glDrawElements( ModeFromPrimitiveType( pt ), numPrimitives * IndicesPerPrimitive( pt ), + Gl.GL_UNSIGNED_SHORT, IntPtr.Zero ); + CheckGlError(); + } - static int IndicesPerPrimitive(PrimitiveType pt) - { - switch (pt) - { - case PrimitiveType.PointList: return 1; - case PrimitiveType.LineList: return 2; - case PrimitiveType.TriangleList: return 3; - } - throw new NotImplementedException(); - } + static int ModeFromPrimitiveType( PrimitiveType pt ) + { + switch( pt ) + { + case PrimitiveType.PointList: return Gl.GL_POINTS; + case PrimitiveType.LineList: return Gl.GL_LINES; + case PrimitiveType.TriangleList: return Gl.GL_TRIANGLES; + } + throw new NotImplementedException(); + } - public IVertexBuffer CreateVertexBuffer(int size) { return new VertexBuffer(this, size); } - public IIndexBuffer CreateIndexBuffer(int size) { return new IndexBuffer(this, size); } - public ITexture CreateTexture() { return new Texture(this); } - public ITexture CreateTexture(Bitmap bitmap) { return new Texture(this, bitmap); } - public IShader CreateShader(Stream stream) { return new Shader(this, stream); } - } + static int IndicesPerPrimitive( PrimitiveType pt ) + { + switch( pt ) + { + case PrimitiveType.PointList: return 1; + case PrimitiveType.LineList: return 2; + case PrimitiveType.TriangleList: return 3; + } + throw new NotImplementedException(); + } + + public IVertexBuffer CreateVertexBuffer( int size ) { return new VertexBuffer( this, size ); } + public IIndexBuffer CreateIndexBuffer( int size ) { return new IndexBuffer( this, size ); } + public ITexture CreateTexture() { return new Texture( this ); } + public ITexture CreateTexture( Bitmap bitmap ) { return new Texture( this, bitmap ); } + public IShader CreateShader( Stream stream ) { return new Shader( this, stream ); } + } } diff --git a/OpenRA.Mods.Cnc/CncLoadScreen.cs b/OpenRA.Mods.Cnc/CncLoadScreen.cs index c8ccf4fce1..01ed34934c 100644 --- a/OpenRA.Mods.Cnc/CncLoadScreen.cs +++ b/OpenRA.Mods.Cnc/CncLoadScreen.cs @@ -64,8 +64,8 @@ namespace OpenRA.Mods.Cnc r.BeginFrame(float2.Zero); WidgetUtils.FillRectWithSprite(StripeRect, Stripe); r.RgbaSpriteRenderer.DrawSprite(Logo, LogoPos); - Font.DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White); - r.EndFrame(); + Font.DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White); + r.EndFrame( new NullInputHandler() ); } } } diff --git a/OpenRA.Mods.RA/NullLoadScreen.cs b/OpenRA.Mods.RA/NullLoadScreen.cs index ae082585aa..43b9a7ddc6 100644 --- a/OpenRA.Mods.RA/NullLoadScreen.cs +++ b/OpenRA.Mods.RA/NullLoadScreen.cs @@ -19,9 +19,9 @@ namespace OpenRA.Mods.RA return; // Draw a black screen - Game.Renderer.BeginFrame(float2.Zero); - Game.Renderer.EndFrame(); - } + Game.Renderer.BeginFrame(float2.Zero); + Game.Renderer.EndFrame( new NullInputHandler() ); + } } } diff --git a/OpenRA.Mods.RA/RALoadScreen.cs b/OpenRA.Mods.RA/RALoadScreen.cs index f967ce9460..d32b19da44 100644 --- a/OpenRA.Mods.RA/RALoadScreen.cs +++ b/OpenRA.Mods.RA/RALoadScreen.cs @@ -64,8 +64,8 @@ namespace OpenRA.Mods.RA r.BeginFrame(float2.Zero); WidgetUtils.FillRectWithSprite(StripeRect, Stripe); r.RgbaSpriteRenderer.DrawSprite(Logo, LogoPos); - Font.DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White); - r.EndFrame(); + Font.DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White); + r.EndFrame( new NullInputHandler() ); } } } diff --git a/OpenRA.Renderer.Null/NullGraphicsDevice.cs b/OpenRA.Renderer.Null/NullGraphicsDevice.cs index b87f1b2856..4bab36e51a 100644 --- a/OpenRA.Renderer.Null/NullGraphicsDevice.cs +++ b/OpenRA.Renderer.Null/NullGraphicsDevice.cs @@ -1,10 +1,8 @@ using System.Drawing; using System.IO; -using System.Windows.Forms; using OpenRA.FileFormats.Graphics; using OpenRA.Graphics; - [assembly: Renderer(typeof(OpenRA.Renderer.Null.NullGraphicsDevice))] namespace OpenRA.Renderer.Null @@ -18,42 +16,23 @@ namespace OpenRA.Renderer.Null WindowSize = new Size(width, height); } - public void EnableScissor(int left, int top, int width, int height) - { - } - - public void DisableScissor() - { - } + public void EnableScissor(int left, int top, int width, int height) { } + public void DisableScissor() { } public void Begin() { } public void End() { } + public void Clear(Color c) { } - public void Clear(Color c) - { - } - - - public void Present() + public void Present(IInputHandler ih) { Game.HasInputFocus = false; - Game.HandleModifierKeys(Modifiers.None); + ih.ModifierKeys(Modifiers.None); } - public void DrawIndexedPrimitives(PrimitiveType pt, Range vertices, Range indices) - { - } - - public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives) - { - } - - - public IVertexBuffer CreateVertexBuffer(int size) - { - return new NullVertexBuffer(); - } + public void DrawIndexedPrimitives(PrimitiveType pt, Range vertices, Range indices) { } + public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives) { } + public IVertexBuffer CreateVertexBuffer(int size) { return new NullVertexBuffer(); } public IIndexBuffer CreateIndexBuffer(int size) { return new NullIndexBuffer(); } public ITexture CreateTexture() { return new NullTexture(); } public ITexture CreateTexture(Bitmap bitmap) { return new NullTexture(); }