(bob) refactor input dispatch; remove public Dispatch*Input from game; (chris) fix build failures due to rebase past gecko
This commit is contained in:
@@ -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<int> vertexRange, Range<int> indexRange );
|
||||
void DrawIndexedPrimitives( PrimitiveType type, int vertexPool, int numPrimitives );
|
||||
|
||||
@@ -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 };
|
||||
@@ -45,6 +45,7 @@
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Tao.Sdl, Version=1.2.13.0, Culture=neutral, PublicKeyToken=9c7a200e36c0094e">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
@@ -61,6 +62,7 @@
|
||||
<Compile Include="FileSystem.cs" />
|
||||
<Compile Include="Folder.cs" />
|
||||
<Compile Include="Graphics\IGraphicsDevice.cs" />
|
||||
<Compile Include="Graphics\IInputHandler.cs" />
|
||||
<Compile Include="Graphics\Vertex.cs" />
|
||||
<Compile Include="Manifest.cs" />
|
||||
<Compile Include="MiniYaml.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)
|
||||
{
|
||||
|
||||
@@ -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<T>(IVertexBuffer<T> vertices, IIndexBuffer indices,
|
||||
|
||||
@@ -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()
|
||||
|
||||
58
OpenRA.Game/InputHandler.cs
Executable file
58
OpenRA.Game/InputHandler.cs
Executable file
@@ -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 );
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,8 +139,6 @@
|
||||
<Compile Include="Graphics\SequenceProvider.cs" />
|
||||
<Compile Include="Graphics\SheetBuilder.cs" />
|
||||
<Compile Include="Graphics\HardwarePalette.cs" />
|
||||
<Compile Include="MainWindow.cs">
|
||||
</Compile>
|
||||
<Compile Include="Support\Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Graphics\Renderer.cs" />
|
||||
@@ -214,6 +212,7 @@
|
||||
<Compile Include="ActorInitializer.cs" />
|
||||
<Compile Include="ActorReference.cs" />
|
||||
<Compile Include="Misc.cs" />
|
||||
<Compile Include="InputHandler.cs" />
|
||||
<Compile Include="ModData.cs" />
|
||||
<Compile Include="Map.cs" />
|
||||
<Compile Include="Network\FrameData.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;
|
||||
@@ -45,129 +45,129 @@ namespace OpenRA.GlRenderer
|
||||
internal static void CheckGlError()
|
||||
{
|
||||
var n = Gl.glGetError();
|
||||
if (n != Gl.GL_NO_ERROR)
|
||||
throw new InvalidOperationException("GL Error: " + ((GlError)n).ToString());
|
||||
if( n != Gl.GL_NO_ERROR )
|
||||
throw new InvalidOperationException( "GL Error: " + ( (GlError)n ).ToString() );
|
||||
}
|
||||
|
||||
public GraphicsDevice(int width, int height, WindowMode window, bool vsync)
|
||||
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);
|
||||
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)
|
||||
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");
|
||||
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();
|
||||
|
||||
windowSize = new Size(width, height);
|
||||
windowSize = new Size( width, height );
|
||||
|
||||
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);
|
||||
|
||||
Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
|
||||
Gl.glEnableClientState( Gl.GL_VERTEX_ARRAY );
|
||||
CheckGlError();
|
||||
Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);
|
||||
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);
|
||||
var str = Cg.cgGetErrorString( err );
|
||||
throw new InvalidOperationException(
|
||||
string.Format("CG Error: {0}: {1}", err, str));
|
||||
string.Format( "CG Error: {0}: {1}", err, str ) );
|
||||
};
|
||||
|
||||
public void EnableScissor(int left, int top, int width, int height)
|
||||
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);
|
||||
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);
|
||||
Gl.glEnable( Gl.GL_SCISSOR_TEST );
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
public void DisableScissor()
|
||||
{
|
||||
Gl.glDisable(Gl.GL_SCISSOR_TEST);
|
||||
Gl.glDisable( Gl.GL_SCISSOR_TEST );
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
public void Begin() { }
|
||||
public void End() { }
|
||||
|
||||
public void Clear(Color c)
|
||||
public void Clear( Color c )
|
||||
{
|
||||
Gl.glClearColor(0, 0, 0, 0);
|
||||
Gl.glClearColor( 0, 0, 0, 0 );
|
||||
CheckGlError();
|
||||
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
|
||||
Gl.glClear( Gl.GL_COLOR_BUFFER_BIT );
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
MouseButtons lastButtonBits = (MouseButtons)0;
|
||||
MouseButton lastButtonBits = (MouseButton)0;
|
||||
|
||||
static MouseButtons MakeButton(byte b)
|
||||
static MouseButton 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
|
||||
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)
|
||||
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);
|
||||
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)
|
||||
bool HandleSpecialKey( KeyInput k )
|
||||
{
|
||||
switch (k.VirtKey)
|
||||
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);
|
||||
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))
|
||||
if( k.Modifiers.HasModifier( Modifiers.Alt ) )
|
||||
{
|
||||
OpenRA.Game.Exit();
|
||||
return true;
|
||||
@@ -179,19 +179,19 @@ namespace OpenRA.GlRenderer
|
||||
}
|
||||
}
|
||||
|
||||
public void Present()
|
||||
public void Present( IInputHandler inputHandler )
|
||||
{
|
||||
Sdl.SDL_GL_SwapBuffers();
|
||||
Game.HasInputFocus = 0 != (Sdl.SDL_GetAppState() & Sdl.SDL_APPINPUTFOCUS);
|
||||
Game.HasInputFocus = 0 != ( Sdl.SDL_GetAppState() & Sdl.SDL_APPINPUTFOCUS );
|
||||
|
||||
var mods = MakeModifiers(Sdl.SDL_GetModState());
|
||||
Game.HandleModifierKeys(mods);
|
||||
MouseEventArgs pendingMotion = null;
|
||||
var mods = MakeModifiers( Sdl.SDL_GetModState() );
|
||||
inputHandler.ModifierKeys( mods );
|
||||
MouseInput? pendingMotion = null;
|
||||
|
||||
Sdl.SDL_Event e;
|
||||
while (Sdl.SDL_PollEvent(out e) != 0)
|
||||
while( Sdl.SDL_PollEvent( out e ) != 0 )
|
||||
{
|
||||
switch (e.type)
|
||||
switch( e.type )
|
||||
{
|
||||
case Sdl.SDL_QUIT:
|
||||
OpenRA.Game.Exit();
|
||||
@@ -199,39 +199,41 @@ namespace OpenRA.GlRenderer
|
||||
|
||||
case Sdl.SDL_MOUSEBUTTONDOWN:
|
||||
{
|
||||
if (pendingMotion != null)
|
||||
if( pendingMotion != null )
|
||||
{
|
||||
Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods);
|
||||
inputHandler.OnMouseInput( pendingMotion.Value );
|
||||
pendingMotion = null;
|
||||
}
|
||||
|
||||
var button = MakeButton(e.button.button);
|
||||
var button = MakeButton( e.button.button );
|
||||
lastButtonBits |= button;
|
||||
|
||||
Game.DispatchMouseInput(MouseInputEvent.Down,
|
||||
new MouseEventArgs(button, 1, e.button.x, e.button.y, 0),
|
||||
mods);
|
||||
inputHandler.OnMouseInput( new MouseInput(
|
||||
MouseInputEvent.Down, button, new int2( e.button.x, e.button.y ), mods ) );
|
||||
} break;
|
||||
|
||||
case Sdl.SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
if (pendingMotion != null)
|
||||
if( pendingMotion != null )
|
||||
{
|
||||
Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods);
|
||||
inputHandler.OnMouseInput( pendingMotion.Value );
|
||||
pendingMotion = null;
|
||||
}
|
||||
|
||||
var button = MakeButton(e.button.button);
|
||||
var button = MakeButton( e.button.button );
|
||||
lastButtonBits &= ~button;
|
||||
|
||||
Game.DispatchMouseInput(MouseInputEvent.Up,
|
||||
new MouseEventArgs(button, 1, e.button.x, e.button.y, 0),
|
||||
mods);
|
||||
inputHandler.OnMouseInput( new MouseInput(
|
||||
MouseInputEvent.Up, button, new int2( e.button.x, e.button.y ), mods ) );
|
||||
} break;
|
||||
|
||||
case Sdl.SDL_MOUSEMOTION:
|
||||
{
|
||||
pendingMotion = new MouseEventArgs(lastButtonBits, 0, e.motion.x, e.motion.y, 0);
|
||||
pendingMotion = new MouseInput(
|
||||
MouseInputEvent.Move,
|
||||
lastButtonBits,
|
||||
new int2( e.motion.x, e.motion.y ),
|
||||
mods );
|
||||
} break;
|
||||
|
||||
case Sdl.SDL_KEYDOWN:
|
||||
@@ -241,12 +243,12 @@ namespace OpenRA.GlRenderer
|
||||
Event = KeyInputEvent.Down,
|
||||
Modifiers = mods,
|
||||
KeyChar = (char)e.key.keysym.unicode,
|
||||
KeyName = Sdl.SDL_GetKeyName(e.key.keysym.sym),
|
||||
KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
|
||||
VirtKey = e.key.keysym.sym
|
||||
};
|
||||
|
||||
if (!HandleSpecialKey(keyEvent))
|
||||
Game.HandleKeyEvent(keyEvent);
|
||||
if( !HandleSpecialKey( keyEvent ) )
|
||||
inputHandler.OnKeyInput( keyEvent );
|
||||
} break;
|
||||
|
||||
case Sdl.SDL_KEYUP:
|
||||
@@ -256,41 +258,41 @@ namespace OpenRA.GlRenderer
|
||||
Event = KeyInputEvent.Up,
|
||||
Modifiers = mods,
|
||||
KeyChar = (char)e.key.keysym.unicode,
|
||||
KeyName = Sdl.SDL_GetKeyName(e.key.keysym.sym),
|
||||
KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
|
||||
VirtKey = e.key.keysym.sym
|
||||
};
|
||||
|
||||
Game.HandleKeyEvent(keyEvent);
|
||||
inputHandler.OnKeyInput( keyEvent );
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pendingMotion != null)
|
||||
if( pendingMotion != null )
|
||||
{
|
||||
Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods);
|
||||
inputHandler.OnMouseInput( pendingMotion.Value );
|
||||
pendingMotion = null;
|
||||
}
|
||||
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
public void DrawIndexedPrimitives(PrimitiveType pt, Range<int> vertices, Range<int> indices)
|
||||
public void DrawIndexedPrimitives( PrimitiveType pt, Range<int> vertices, Range<int> indices )
|
||||
{
|
||||
Gl.glDrawElements(ModeFromPrimitiveType(pt), indices.End - indices.Start,
|
||||
Gl.GL_UNSIGNED_SHORT, new IntPtr(indices.Start * 2));
|
||||
Gl.glDrawElements( ModeFromPrimitiveType( pt ), indices.End - indices.Start,
|
||||
Gl.GL_UNSIGNED_SHORT, new IntPtr( indices.Start * 2 ) );
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives)
|
||||
public void DrawIndexedPrimitives( PrimitiveType pt, int numVerts, int numPrimitives )
|
||||
{
|
||||
Gl.glDrawElements(ModeFromPrimitiveType(pt), numPrimitives * IndicesPerPrimitive(pt),
|
||||
Gl.GL_UNSIGNED_SHORT, IntPtr.Zero);
|
||||
Gl.glDrawElements( ModeFromPrimitiveType( pt ), numPrimitives * IndicesPerPrimitive( pt ),
|
||||
Gl.GL_UNSIGNED_SHORT, IntPtr.Zero );
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
static int ModeFromPrimitiveType(PrimitiveType pt)
|
||||
static int ModeFromPrimitiveType( PrimitiveType pt )
|
||||
{
|
||||
switch (pt)
|
||||
switch( pt )
|
||||
{
|
||||
case PrimitiveType.PointList: return Gl.GL_POINTS;
|
||||
case PrimitiveType.LineList: return Gl.GL_LINES;
|
||||
@@ -299,9 +301,9 @@ namespace OpenRA.GlRenderer
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
static int IndicesPerPrimitive(PrimitiveType pt)
|
||||
static int IndicesPerPrimitive( PrimitiveType pt )
|
||||
{
|
||||
switch (pt)
|
||||
switch( pt )
|
||||
{
|
||||
case PrimitiveType.PointList: return 1;
|
||||
case PrimitiveType.LineList: return 2;
|
||||
@@ -310,10 +312,10 @@ namespace OpenRA.GlRenderer
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IVertexBuffer<Vertex> CreateVertexBuffer(int size) { return new VertexBuffer<Vertex>(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); }
|
||||
public IVertexBuffer<Vertex> CreateVertexBuffer( int size ) { return new VertexBuffer<Vertex>( 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 ); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Cnc
|
||||
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();
|
||||
r.EndFrame( new NullInputHandler() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
// Draw a black screen
|
||||
Game.Renderer.BeginFrame(float2.Zero);
|
||||
Game.Renderer.EndFrame();
|
||||
Game.Renderer.EndFrame( new NullInputHandler() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.RA
|
||||
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();
|
||||
r.EndFrame( new NullInputHandler() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<int> vertices, Range<int> indices)
|
||||
{
|
||||
}
|
||||
|
||||
public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public IVertexBuffer<Vertex> CreateVertexBuffer(int size)
|
||||
{
|
||||
return new NullVertexBuffer<Vertex>();
|
||||
}
|
||||
public void DrawIndexedPrimitives(PrimitiveType pt, Range<int> vertices, Range<int> indices) { }
|
||||
public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives) { }
|
||||
|
||||
public IVertexBuffer<Vertex> CreateVertexBuffer(int size) { return new NullVertexBuffer<Vertex>(); }
|
||||
public IIndexBuffer CreateIndexBuffer(int size) { return new NullIndexBuffer(); }
|
||||
public ITexture CreateTexture() { return new NullTexture(); }
|
||||
public ITexture CreateTexture(Bitmap bitmap) { return new NullTexture(); }
|
||||
|
||||
Reference in New Issue
Block a user