diff --git a/OpenRA.Renderer.Cg/GraphicsDevice.cs b/OpenRA.Renderer.Cg/GraphicsDevice.cs
index ff7673de06..38d96eb8d1 100755
--- a/OpenRA.Renderer.Cg/GraphicsDevice.cs
+++ b/OpenRA.Renderer.Cg/GraphicsDevice.cs
@@ -38,6 +38,7 @@ namespace OpenRA.Renderer.Cg
internal int vertexProfile, fragmentProfile;
IntPtr surf;
+ SdlInput input;
public Size WindowSize { get { return windowSize; } }
@@ -138,6 +139,8 @@ namespace OpenRA.Renderer.Cg
ErrorHandler.CheckGlError();
Sdl.SDL_SetModState( 0 ); // i have had enough.
+
+ input = new SdlInput( surf );
}
public void EnableScissor( int left, int top, int width, int height )
@@ -164,49 +167,6 @@ namespace OpenRA.Renderer.Cg
ErrorHandler.CheckGlError();
}
- MouseButton lastButtonBits = (MouseButton)0;
-
- 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
- : b == Sdl.SDL_BUTTON_WHEELDOWN ? MouseButton.WheelDown
- : b == Sdl.SDL_BUTTON_WHEELUP ? MouseButton.WheelUp
- : 0;
- }
-
- Modifiers MakeModifiers( int raw )
- {
- return ( ( raw & Sdl.KMOD_ALT ) != 0 ? Modifiers.Alt : 0 )
- | ( ( raw & Sdl.KMOD_CTRL ) != 0 ? Modifiers.Ctrl : 0 )
- | ( ( raw & Sdl.KMOD_META ) != 0 ? Modifiers.Meta : 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;
-
- 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();
@@ -214,98 +174,7 @@ namespace OpenRA.Renderer.Cg
public void PumpInput( IInputHandler inputHandler )
{
- Game.HasInputFocus = 0 != ( Sdl.SDL_GetAppState() & Sdl.SDL_APPINPUTFOCUS );
-
- var mods = MakeModifiers( Sdl.SDL_GetModState() );
- inputHandler.ModifierKeys( mods );
- MouseInput? pendingMotion = null;
-
- Sdl.SDL_Event e;
- while( Sdl.SDL_PollEvent( out e ) != 0 )
- {
- switch( e.type )
- {
- case Sdl.SDL_QUIT:
- OpenRA.Game.Exit();
- break;
-
- case Sdl.SDL_MOUSEBUTTONDOWN:
- {
- if( pendingMotion != null )
- {
- inputHandler.OnMouseInput( pendingMotion.Value );
- pendingMotion = null;
- }
-
- var button = MakeButton( e.button.button );
- lastButtonBits |= button;
-
- inputHandler.OnMouseInput( new MouseInput(
- MouseInputEvent.Down, button, new int2( e.button.x, e.button.y ), mods ) );
- } break;
-
- case Sdl.SDL_MOUSEBUTTONUP:
- {
- if( pendingMotion != null )
- {
- inputHandler.OnMouseInput( pendingMotion.Value );
- pendingMotion = null;
- }
-
- var button = MakeButton( e.button.button );
- lastButtonBits &= ~button;
-
- inputHandler.OnMouseInput( new MouseInput(
- MouseInputEvent.Up, button, new int2( e.button.x, e.button.y ), mods ) );
- } break;
-
- case Sdl.SDL_MOUSEMOTION:
- {
- pendingMotion = new MouseInput(
- MouseInputEvent.Move,
- lastButtonBits,
- new int2( e.motion.x, e.motion.y ),
- mods );
- } break;
-
- case Sdl.SDL_KEYDOWN:
- {
- var keyEvent = new KeyInput
- {
- Event = KeyInputEvent.Down,
- Modifiers = mods,
- UnicodeChar = (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;
-
- case Sdl.SDL_KEYUP:
- {
- var keyEvent = new KeyInput
- {
- Event = KeyInputEvent.Up,
- Modifiers = mods,
- UnicodeChar = (char)e.key.keysym.unicode,
- KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
- VirtKey = e.key.keysym.sym
- };
-
- inputHandler.OnKeyInput( keyEvent );
- } break;
- }
- }
-
- if( pendingMotion != null )
- {
- inputHandler.OnMouseInput( pendingMotion.Value );
- pendingMotion = null;
- }
-
- ErrorHandler.CheckGlError();
+ input.PumpInput( inputHandler );
}
public void DrawPrimitives( PrimitiveType pt, int firstVertex, int numVertices )
diff --git a/OpenRA.Renderer.Gl/GraphicsDevice.cs b/OpenRA.Renderer.Gl/GraphicsDevice.cs
index e70ade888b..4c3e9c35b0 100755
--- a/OpenRA.Renderer.Gl/GraphicsDevice.cs
+++ b/OpenRA.Renderer.Gl/GraphicsDevice.cs
@@ -35,6 +35,7 @@ namespace OpenRA.Renderer.Glsl
{
Size windowSize;
IntPtr surf;
+ SdlInput input;
public Size WindowSize { get { return windowSize; } }
@@ -113,6 +114,8 @@ namespace OpenRA.Renderer.Glsl
ErrorHandler.CheckGlError();
Sdl.SDL_SetModState( 0 );
+
+ input = new SdlInput( surf );
}
public void EnableScissor( int left, int top, int width, int height )
@@ -139,49 +142,6 @@ namespace OpenRA.Renderer.Glsl
ErrorHandler.CheckGlError();
}
- MouseButton lastButtonBits = (MouseButton)0;
-
- 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
- : b == Sdl.SDL_BUTTON_WHEELDOWN ? MouseButton.WheelDown
- : b == Sdl.SDL_BUTTON_WHEELUP ? MouseButton.WheelUp
- : 0;
- }
-
- Modifiers MakeModifiers( int raw )
- {
- return ( ( raw & Sdl.KMOD_ALT ) != 0 ? Modifiers.Alt : 0 )
- | ( ( raw & Sdl.KMOD_CTRL ) != 0 ? Modifiers.Ctrl : 0 )
- | ( ( raw & Sdl.KMOD_META ) != 0 ? Modifiers.Meta : 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;
-
- 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();
@@ -189,98 +149,7 @@ namespace OpenRA.Renderer.Glsl
public void PumpInput( IInputHandler inputHandler )
{
- Game.HasInputFocus = 0 != ( Sdl.SDL_GetAppState() & Sdl.SDL_APPINPUTFOCUS );
-
- var mods = MakeModifiers( Sdl.SDL_GetModState() );
- inputHandler.ModifierKeys( mods );
- MouseInput? pendingMotion = null;
-
- Sdl.SDL_Event e;
- while( Sdl.SDL_PollEvent( out e ) != 0 )
- {
- switch( e.type )
- {
- case Sdl.SDL_QUIT:
- OpenRA.Game.Exit();
- break;
-
- case Sdl.SDL_MOUSEBUTTONDOWN:
- {
- if( pendingMotion != null )
- {
- inputHandler.OnMouseInput( pendingMotion.Value );
- pendingMotion = null;
- }
-
- var button = MakeButton( e.button.button );
- lastButtonBits |= button;
-
- inputHandler.OnMouseInput( new MouseInput(
- MouseInputEvent.Down, button, new int2( e.button.x, e.button.y ), mods ) );
- } break;
-
- case Sdl.SDL_MOUSEBUTTONUP:
- {
- if( pendingMotion != null )
- {
- inputHandler.OnMouseInput( pendingMotion.Value );
- pendingMotion = null;
- }
-
- var button = MakeButton( e.button.button );
- lastButtonBits &= ~button;
-
- inputHandler.OnMouseInput( new MouseInput(
- MouseInputEvent.Up, button, new int2( e.button.x, e.button.y ), mods ) );
- } break;
-
- case Sdl.SDL_MOUSEMOTION:
- {
- pendingMotion = new MouseInput(
- MouseInputEvent.Move,
- lastButtonBits,
- new int2( e.motion.x, e.motion.y ),
- mods );
- } break;
-
- case Sdl.SDL_KEYDOWN:
- {
- var keyEvent = new KeyInput
- {
- Event = KeyInputEvent.Down,
- Modifiers = mods,
- UnicodeChar = (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;
-
- case Sdl.SDL_KEYUP:
- {
- var keyEvent = new KeyInput
- {
- Event = KeyInputEvent.Up,
- Modifiers = mods,
- UnicodeChar = (char)e.key.keysym.unicode,
- KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
- VirtKey = e.key.keysym.sym
- };
-
- inputHandler.OnKeyInput( keyEvent );
- } break;
- }
- }
-
- if( pendingMotion != null )
- {
- inputHandler.OnMouseInput( pendingMotion.Value );
- pendingMotion = null;
- }
-
- ErrorHandler.CheckGlError();
+ input.PumpInput(inputHandler);
}
public void DrawPrimitives( PrimitiveType pt, int firstVertex, int numVertices )
diff --git a/OpenRA.Renderer.SdlCommon/OpenRA.Renderer.SdlCommon.csproj b/OpenRA.Renderer.SdlCommon/OpenRA.Renderer.SdlCommon.csproj
index d77e983463..21bf9932a3 100644
--- a/OpenRA.Renderer.SdlCommon/OpenRA.Renderer.SdlCommon.csproj
+++ b/OpenRA.Renderer.SdlCommon/OpenRA.Renderer.SdlCommon.csproj
@@ -1 +1 @@
-
Debug
AnyCPU
9.0.21022
2.0
{52FD9F0B-B209-4ED7-8A32-AC8033363263}
Library
OpenRA.Renderer.SdlCommon
OpenRA.Renderer.SdlCommon
v3.5
true
full
false
..\
DEBUG
prompt
4
false
none
false
..\
prompt
4
false
{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}
OpenRA.FileFormats
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}
OpenRA.Game
\ No newline at end of file
+
Debug
AnyCPU
9.0.21022
2.0
{52FD9F0B-B209-4ED7-8A32-AC8033363263}
Library
OpenRA.Renderer.SdlCommon
OpenRA.Renderer.SdlCommon
v3.5
true
full
false
..\
DEBUG
prompt
4
false
none
false
..\
prompt
4
false
False
..\thirdparty\Tao\Tao.OpenGl.dll
False
..\thirdparty\Tao\Tao.Sdl.dll
{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}
OpenRA.FileFormats
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}
OpenRA.Game
\ No newline at end of file
diff --git a/OpenRA.Renderer.SdlCommon/SdlInput.cs b/OpenRA.Renderer.SdlCommon/SdlInput.cs
new file mode 100644
index 0000000000..2fe8cb95b4
--- /dev/null
+++ b/OpenRA.Renderer.SdlCommon/SdlInput.cs
@@ -0,0 +1,164 @@
+#region Copyright & License Information
+/*
+* Copyright 2007-2011 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 COPYING.
+*/
+#endregion
+
+using System;
+using System.Drawing;
+using System.IO;
+using Tao.OpenGl;
+using Tao.Sdl;
+
+namespace OpenRA.Renderer.SdlCommon
+{
+ public class SdlInput
+ {
+ MouseButton lastButtonBits = (MouseButton)0;
+ IntPtr surface;
+
+ public SdlInput( IntPtr surface ) { this.surface = surface; }
+
+ 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
+ : b == Sdl.SDL_BUTTON_WHEELDOWN ? MouseButton.WheelDown
+ : b == Sdl.SDL_BUTTON_WHEELUP ? MouseButton.WheelUp
+ : 0;
+ }
+
+ Modifiers MakeModifiers( int raw )
+ {
+ return ( ( raw & Sdl.KMOD_ALT ) != 0 ? Modifiers.Alt : 0 )
+ | ( ( raw & Sdl.KMOD_CTRL ) != 0 ? Modifiers.Ctrl : 0 )
+ | ( ( raw & Sdl.KMOD_META ) != 0 ? Modifiers.Meta : 0 )
+ | ( ( raw & Sdl.KMOD_SHIFT ) != 0 ? Modifiers.Shift : 0 );
+ }
+
+ public void PumpInput( IInputHandler inputHandler )
+ {
+ Game.HasInputFocus = 0 != ( Sdl.SDL_GetAppState() & Sdl.SDL_APPINPUTFOCUS );
+
+ var mods = MakeModifiers( Sdl.SDL_GetModState() );
+ inputHandler.ModifierKeys( mods );
+ MouseInput? pendingMotion = null;
+
+ Sdl.SDL_Event e;
+ while( Sdl.SDL_PollEvent( out e ) != 0 )
+ {
+ switch( e.type )
+ {
+ case Sdl.SDL_QUIT:
+ OpenRA.Game.Exit();
+ break;
+
+ case Sdl.SDL_MOUSEBUTTONDOWN:
+ {
+ if( pendingMotion != null )
+ {
+ inputHandler.OnMouseInput( pendingMotion.Value );
+ pendingMotion = null;
+ }
+
+ var button = MakeButton( e.button.button );
+ lastButtonBits |= button;
+
+ inputHandler.OnMouseInput( new MouseInput(
+ MouseInputEvent.Down, button, new int2( e.button.x, e.button.y ), mods ) );
+ } break;
+
+ case Sdl.SDL_MOUSEBUTTONUP:
+ {
+ if( pendingMotion != null )
+ {
+ inputHandler.OnMouseInput( pendingMotion.Value );
+ pendingMotion = null;
+ }
+
+ var button = MakeButton( e.button.button );
+ lastButtonBits &= ~button;
+
+ inputHandler.OnMouseInput( new MouseInput(
+ MouseInputEvent.Up, button, new int2( e.button.x, e.button.y ), mods ) );
+ } break;
+
+ case Sdl.SDL_MOUSEMOTION:
+ {
+ pendingMotion = new MouseInput(
+ MouseInputEvent.Move,
+ lastButtonBits,
+ new int2( e.motion.x, e.motion.y ),
+ mods );
+ } break;
+
+ case Sdl.SDL_KEYDOWN:
+ {
+ var keyEvent = new KeyInput
+ {
+ Event = KeyInputEvent.Down,
+ Modifiers = mods,
+ UnicodeChar = (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;
+
+ case Sdl.SDL_KEYUP:
+ {
+ var keyEvent = new KeyInput
+ {
+ Event = KeyInputEvent.Up,
+ Modifiers = mods,
+ UnicodeChar = (char)e.key.keysym.unicode,
+ KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
+ VirtKey = e.key.keysym.sym
+ };
+
+ inputHandler.OnKeyInput( keyEvent );
+ } break;
+ }
+ }
+
+ if( pendingMotion != null )
+ {
+ inputHandler.OnMouseInput( pendingMotion.Value );
+ pendingMotion = null;
+ }
+
+ ErrorHandler.CheckGlError();
+ }
+
+ 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( surface, path );
+ return true;
+
+ case Sdl.SDLK_F4:
+ if( k.Modifiers.HasModifier( Modifiers.Alt ) )
+ {
+ OpenRA.Game.Exit();
+ return true;
+ }
+ return false;
+
+ default:
+ return false;
+ }
+ }
+ }
+}
+