(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 Begin();
|
||||||
void End();
|
void End();
|
||||||
void Clear( Color color );
|
void Clear( Color color );
|
||||||
void Present();
|
void Present( IInputHandler inputHandler );
|
||||||
|
|
||||||
void DrawIndexedPrimitives( PrimitiveType type, Range<int> vertexRange, Range<int> indexRange );
|
void DrawIndexedPrimitives( PrimitiveType type, Range<int> vertexRange, Range<int> indexRange );
|
||||||
void DrawIndexedPrimitives( PrimitiveType type, int vertexPool, int numPrimitives );
|
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)
|
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
@@ -9,16 +9,33 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
|
public interface IInputHandler
|
||||||
|
{
|
||||||
|
void ModifierKeys( Modifiers mods );
|
||||||
|
void OnKeyInput( KeyInput input );
|
||||||
|
void OnMouseInput( MouseInput input );
|
||||||
|
}
|
||||||
|
|
||||||
public struct MouseInput
|
public struct MouseInput
|
||||||
{
|
{
|
||||||
public MouseInputEvent Event;
|
public MouseInputEvent Event;
|
||||||
public int2 Location;
|
|
||||||
public MouseButton Button;
|
public MouseButton Button;
|
||||||
|
public int2 Location;
|
||||||
public Modifiers Modifiers;
|
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 };
|
public enum MouseInputEvent { Down, Move, Up };
|
||||||
@@ -45,6 +45,7 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Windows.Forms" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="Tao.Sdl, Version=1.2.13.0, Culture=neutral, PublicKeyToken=9c7a200e36c0094e">
|
<Reference Include="Tao.Sdl, Version=1.2.13.0, Culture=neutral, PublicKeyToken=9c7a200e36c0094e">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
@@ -61,6 +62,7 @@
|
|||||||
<Compile Include="FileSystem.cs" />
|
<Compile Include="FileSystem.cs" />
|
||||||
<Compile Include="Folder.cs" />
|
<Compile Include="Folder.cs" />
|
||||||
<Compile Include="Graphics\IGraphicsDevice.cs" />
|
<Compile Include="Graphics\IGraphicsDevice.cs" />
|
||||||
|
<Compile Include="Graphics\IInputHandler.cs" />
|
||||||
<Compile Include="Graphics\Vertex.cs" />
|
<Compile Include="Graphics\Vertex.cs" />
|
||||||
<Compile Include="Manifest.cs" />
|
<Compile Include="Manifest.cs" />
|
||||||
<Compile Include="MiniYaml.cs" />
|
<Compile Include="MiniYaml.cs" />
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ namespace OpenRA
|
|||||||
using (new PerfSample("render"))
|
using (new PerfSample("render"))
|
||||||
{
|
{
|
||||||
++RenderFrame;
|
++RenderFrame;
|
||||||
viewport.DrawRegions(worldRenderer);
|
viewport.DrawRegions(worldRenderer, new DefaultInputHandler( orderManager.world ));
|
||||||
Sound.SetListenerPosition(viewport.Location + .5f * new float2(viewport.Width, viewport.Height));
|
Sound.SetListenerPosition(viewport.Location + .5f * new float2(viewport.Width, viewport.Height));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,37 +181,14 @@ namespace OpenRA
|
|||||||
AfterGameStart( orderManager.world );
|
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
|
public static bool IsHost
|
||||||
{
|
{
|
||||||
get { return orderManager.Connection.LocalClientId == 0; }
|
get { return orderManager.Connection.LocalClientId == 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void HandleKeyEvent(KeyInput e)
|
|
||||||
{
|
|
||||||
Sync.CheckSyncUnchanged( orderManager.world, () =>
|
|
||||||
{
|
|
||||||
Widget.HandleKeyPress( e );
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
static Modifiers modifiers;
|
static Modifiers modifiers;
|
||||||
public static Modifiers GetModifierKeys() { return 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)
|
internal static void Initialize(Arguments args)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -92,11 +92,11 @@ namespace OpenRA.Graphics
|
|||||||
s.Commit();
|
s.Commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EndFrame()
|
public void EndFrame( IInputHandler inputHandler )
|
||||||
{
|
{
|
||||||
Flush();
|
Flush();
|
||||||
device.End();
|
device.End();
|
||||||
device.Present();
|
device.Present( inputHandler );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawBatch<T>(IVertexBuffer<T> vertices, IIndexBuffer indices,
|
public void DrawBatch<T>(IVertexBuffer<T> vertices, IIndexBuffer indices,
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ namespace OpenRA.Graphics
|
|||||||
this.scrollPosition = Game.CellSize* mapStart;
|
this.scrollPosition = Game.CellSize* mapStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawRegions( WorldRenderer wr )
|
public void DrawRegions( WorldRenderer wr, IInputHandler inputHandler )
|
||||||
{
|
{
|
||||||
renderer.BeginFrame(scrollPosition);
|
renderer.BeginFrame(scrollPosition);
|
||||||
wr.Draw();
|
wr.Draw();
|
||||||
@@ -107,7 +107,7 @@ namespace OpenRA.Graphics
|
|||||||
var c = new Cursor(cursorName);
|
var c = new Cursor(cursorName);
|
||||||
c.Draw(wr, (int)cursorFrame, Viewport.LastMousePos + Location);
|
c.Draw(wr, (int)cursorFrame, Viewport.LastMousePos + Location);
|
||||||
|
|
||||||
renderer.EndFrame();
|
renderer.EndFrame( inputHandler );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
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\SequenceProvider.cs" />
|
||||||
<Compile Include="Graphics\SheetBuilder.cs" />
|
<Compile Include="Graphics\SheetBuilder.cs" />
|
||||||
<Compile Include="Graphics\HardwarePalette.cs" />
|
<Compile Include="Graphics\HardwarePalette.cs" />
|
||||||
<Compile Include="MainWindow.cs">
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Support\Program.cs" />
|
<Compile Include="Support\Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Graphics\Renderer.cs" />
|
<Compile Include="Graphics\Renderer.cs" />
|
||||||
@@ -214,6 +212,7 @@
|
|||||||
<Compile Include="ActorInitializer.cs" />
|
<Compile Include="ActorInitializer.cs" />
|
||||||
<Compile Include="ActorReference.cs" />
|
<Compile Include="ActorReference.cs" />
|
||||||
<Compile Include="Misc.cs" />
|
<Compile Include="Misc.cs" />
|
||||||
|
<Compile Include="InputHandler.cs" />
|
||||||
<Compile Include="ModData.cs" />
|
<Compile Include="ModData.cs" />
|
||||||
<Compile Include="Map.cs" />
|
<Compile Include="Map.cs" />
|
||||||
<Compile Include="Network\FrameData.cs" />
|
<Compile Include="Network\FrameData.cs" />
|
||||||
@@ -257,4 +256,4 @@
|
|||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
* 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
|
* available to you under the terms of the GNU General Public License
|
||||||
* as published by the Free Software Foundation. For more information,
|
* as published by the Free Software Foundation. For more information,
|
||||||
* see LICENSE.
|
* see LICENSE.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@@ -21,299 +21,301 @@ using Tao.Sdl;
|
|||||||
|
|
||||||
namespace OpenRA.GlRenderer
|
namespace OpenRA.GlRenderer
|
||||||
{
|
{
|
||||||
public class GraphicsDevice : IGraphicsDevice
|
public class GraphicsDevice : IGraphicsDevice
|
||||||
{
|
{
|
||||||
Size windowSize;
|
Size windowSize;
|
||||||
internal IntPtr cgContext;
|
internal IntPtr cgContext;
|
||||||
internal int vertexProfile, fragmentProfile;
|
internal int vertexProfile, fragmentProfile;
|
||||||
|
|
||||||
IntPtr surf;
|
IntPtr surf;
|
||||||
|
|
||||||
public Size WindowSize { get { return windowSize; } }
|
public Size WindowSize { get { return windowSize; } }
|
||||||
|
|
||||||
public enum GlError
|
public enum GlError
|
||||||
{
|
{
|
||||||
GL_NO_ERROR = Gl.GL_NO_ERROR,
|
GL_NO_ERROR = Gl.GL_NO_ERROR,
|
||||||
GL_INVALID_ENUM = Gl.GL_INVALID_ENUM,
|
GL_INVALID_ENUM = Gl.GL_INVALID_ENUM,
|
||||||
GL_INVALID_VALUE = Gl.GL_INVALID_VALUE,
|
GL_INVALID_VALUE = Gl.GL_INVALID_VALUE,
|
||||||
GL_STACK_OVERFLOW = Gl.GL_STACK_OVERFLOW,
|
GL_STACK_OVERFLOW = Gl.GL_STACK_OVERFLOW,
|
||||||
GL_STACK_UNDERFLOW = Gl.GL_STACK_UNDERFLOW,
|
GL_STACK_UNDERFLOW = Gl.GL_STACK_UNDERFLOW,
|
||||||
GL_OUT_OF_MEMORY = Gl.GL_OUT_OF_MEMORY,
|
GL_OUT_OF_MEMORY = Gl.GL_OUT_OF_MEMORY,
|
||||||
GL_TABLE_TOO_LARGE = Gl.GL_TABLE_TOO_LARGE,
|
GL_TABLE_TOO_LARGE = Gl.GL_TABLE_TOO_LARGE,
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void CheckGlError()
|
internal static void CheckGlError()
|
||||||
{
|
{
|
||||||
var n = Gl.glGetError();
|
var n = Gl.glGetError();
|
||||||
if (n != Gl.GL_NO_ERROR)
|
if( n != Gl.GL_NO_ERROR )
|
||||||
throw new InvalidOperationException("GL Error: " + ((GlError)n).ToString());
|
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_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_DOUBLEBUFFER, 1 );
|
||||||
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_RED_SIZE, 8);
|
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_GREEN_SIZE, 8 );
|
||||||
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_BLUE_SIZE, 8);
|
Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_BLUE_SIZE, 8 );
|
||||||
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_ALPHA_SIZE, 0);
|
Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_ALPHA_SIZE, 0 );
|
||||||
|
|
||||||
int windowFlags = 0;
|
int windowFlags = 0;
|
||||||
switch (window)
|
switch( window )
|
||||||
{
|
{
|
||||||
case WindowMode.Fullscreen:
|
case WindowMode.Fullscreen:
|
||||||
windowFlags |= Sdl.SDL_FULLSCREEN;
|
windowFlags |= Sdl.SDL_FULLSCREEN;
|
||||||
break;
|
break;
|
||||||
case WindowMode.PseudoFullscreen:
|
case WindowMode.PseudoFullscreen:
|
||||||
// pseudo-fullscreen only reliably works on windows; fall back to fullscreen for everyone else
|
// 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;
|
windowFlags |= ( Environment.OSVersion.Platform == PlatformID.Win32NT ) ? Sdl.SDL_NOFRAME : Sdl.SDL_FULLSCREEN;
|
||||||
Environment.SetEnvironmentVariable("SDL_VIDEO_WINDOW_POS", "0,0");
|
Environment.SetEnvironmentVariable( "SDL_VIDEO_WINDOW_POS", "0,0" );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
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_WM_SetCaption( "OpenRA", "OpenRA" );
|
||||||
Sdl.SDL_ShowCursor(0);
|
Sdl.SDL_ShowCursor( 0 );
|
||||||
Sdl.SDL_EnableUNICODE(1);
|
Sdl.SDL_EnableUNICODE( 1 );
|
||||||
Sdl.SDL_EnableKeyRepeat(Sdl.SDL_DEFAULT_REPEAT_DELAY, Sdl.SDL_DEFAULT_REPEAT_INTERVAL);
|
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.cgGLRegisterStates( cgContext );
|
||||||
CgGl.cgGLSetManageTextureParameters(cgContext, true);
|
CgGl.cgGLSetManageTextureParameters( cgContext, true );
|
||||||
vertexProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_VERTEX);
|
vertexProfile = CgGl.cgGLGetLatestProfile( CgGl.CG_GL_VERTEX );
|
||||||
fragmentProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_FRAGMENT);
|
fragmentProfile = CgGl.cgGLGetLatestProfile( CgGl.CG_GL_FRAGMENT );
|
||||||
|
|
||||||
//Console.WriteLine("VP Profile: " + vertexProfile);
|
//Console.WriteLine("VP Profile: " + vertexProfile);
|
||||||
//Console.WriteLine("FP Profile: " + fragmentProfile);
|
//Console.WriteLine("FP Profile: " + fragmentProfile);
|
||||||
|
|
||||||
Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
|
Gl.glEnableClientState( Gl.GL_VERTEX_ARRAY );
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);
|
Gl.glEnableClientState( Gl.GL_TEXTURE_COORD_ARRAY );
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
|
|
||||||
Sdl.SDL_SetModState(0); // i have had enough.
|
Sdl.SDL_SetModState( 0 ); // i have had enough.
|
||||||
}
|
}
|
||||||
|
|
||||||
static Cg.CGerrorCallbackFuncDelegate CgErrorCallback = () =>
|
static Cg.CGerrorCallbackFuncDelegate CgErrorCallback = () =>
|
||||||
{
|
{
|
||||||
var err = Cg.cgGetError();
|
var err = Cg.cgGetError();
|
||||||
var str = Cg.cgGetErrorString(err);
|
var str = Cg.cgGetErrorString( err );
|
||||||
throw new InvalidOperationException(
|
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( width < 0 ) width = 0;
|
||||||
if (height < 0) height = 0;
|
if( height < 0 ) height = 0;
|
||||||
Gl.glScissor(left, windowSize.Height - (top + height), width, height);
|
Gl.glScissor( left, windowSize.Height - ( top + height ), width, height );
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
Gl.glEnable(Gl.GL_SCISSOR_TEST);
|
Gl.glEnable( Gl.GL_SCISSOR_TEST );
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DisableScissor()
|
public void DisableScissor()
|
||||||
{
|
{
|
||||||
Gl.glDisable(Gl.GL_SCISSOR_TEST);
|
Gl.glDisable( Gl.GL_SCISSOR_TEST );
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Begin() { }
|
public void Begin() { }
|
||||||
public void End() { }
|
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();
|
CheckGlError();
|
||||||
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
|
Gl.glClear( Gl.GL_COLOR_BUFFER_BIT );
|
||||||
CheckGlError();
|
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
|
return b == Sdl.SDL_BUTTON_LEFT ? MouseButton.Left
|
||||||
: b == Sdl.SDL_BUTTON_RIGHT ? MouseButtons.Right
|
: b == Sdl.SDL_BUTTON_RIGHT ? MouseButton.Right
|
||||||
: b == Sdl.SDL_BUTTON_MIDDLE ? MouseButtons.Middle
|
: b == Sdl.SDL_BUTTON_MIDDLE ? MouseButton.Middle
|
||||||
: 0;
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Modifiers MakeModifiers(int raw)
|
static Modifiers MakeModifiers( int raw )
|
||||||
{
|
{
|
||||||
return ((raw & Sdl.KMOD_ALT) != 0 ? Modifiers.Alt : 0)
|
return ( ( raw & Sdl.KMOD_ALT ) != 0 ? Modifiers.Alt : 0 )
|
||||||
| ((raw & Sdl.KMOD_CTRL) != 0 ? Modifiers.Ctrl : 0)
|
| ( ( raw & Sdl.KMOD_CTRL ) != 0 ? Modifiers.Ctrl : 0 )
|
||||||
| ((raw & Sdl.KMOD_SHIFT) != 0 ? Modifiers.Shift : 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:
|
case Sdl.SDLK_F13:
|
||||||
var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal)
|
var path = Environment.GetFolderPath( Environment.SpecialFolder.Personal )
|
||||||
+ Path.DirectorySeparatorChar + DateTime.UtcNow.ToString("OpenRA-yyyy-MM-ddThhmmssZ") + ".bmp";
|
+ Path.DirectorySeparatorChar + DateTime.UtcNow.ToString( "OpenRA-yyyy-MM-ddThhmmssZ" ) + ".bmp";
|
||||||
Sdl.SDL_SaveBMP(surf, path);
|
Sdl.SDL_SaveBMP( surf, path );
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case Sdl.SDLK_F4:
|
case Sdl.SDLK_F4:
|
||||||
if (k.Modifiers.HasModifier(Modifiers.Alt))
|
if( k.Modifiers.HasModifier( Modifiers.Alt ) )
|
||||||
{
|
{
|
||||||
OpenRA.Game.Exit();
|
OpenRA.Game.Exit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Present()
|
public void Present( IInputHandler inputHandler )
|
||||||
{
|
{
|
||||||
Sdl.SDL_GL_SwapBuffers();
|
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;
|
|
||||||
|
|
||||||
Sdl.SDL_Event e;
|
var mods = MakeModifiers( Sdl.SDL_GetModState() );
|
||||||
while (Sdl.SDL_PollEvent(out e) != 0)
|
inputHandler.ModifierKeys( mods );
|
||||||
{
|
MouseInput? pendingMotion = null;
|
||||||
switch (e.type)
|
|
||||||
{
|
|
||||||
case Sdl.SDL_QUIT:
|
|
||||||
OpenRA.Game.Exit();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Sdl.SDL_MOUSEBUTTONDOWN:
|
Sdl.SDL_Event e;
|
||||||
{
|
while( Sdl.SDL_PollEvent( out e ) != 0 )
|
||||||
if (pendingMotion != null)
|
{
|
||||||
{
|
switch( e.type )
|
||||||
Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods);
|
{
|
||||||
pendingMotion = null;
|
case Sdl.SDL_QUIT:
|
||||||
}
|
OpenRA.Game.Exit();
|
||||||
|
break;
|
||||||
|
|
||||||
var button = MakeButton(e.button.button);
|
case Sdl.SDL_MOUSEBUTTONDOWN:
|
||||||
lastButtonBits |= button;
|
{
|
||||||
|
if( pendingMotion != null )
|
||||||
|
{
|
||||||
|
inputHandler.OnMouseInput( pendingMotion.Value );
|
||||||
|
pendingMotion = null;
|
||||||
|
}
|
||||||
|
|
||||||
Game.DispatchMouseInput(MouseInputEvent.Down,
|
var button = MakeButton( e.button.button );
|
||||||
new MouseEventArgs(button, 1, e.button.x, e.button.y, 0),
|
lastButtonBits |= button;
|
||||||
mods);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case Sdl.SDL_MOUSEBUTTONUP:
|
inputHandler.OnMouseInput( new MouseInput(
|
||||||
{
|
MouseInputEvent.Down, button, new int2( e.button.x, e.button.y ), mods ) );
|
||||||
if (pendingMotion != null)
|
} break;
|
||||||
{
|
|
||||||
Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods);
|
|
||||||
pendingMotion = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var button = MakeButton(e.button.button);
|
case Sdl.SDL_MOUSEBUTTONUP:
|
||||||
lastButtonBits &= ~button;
|
{
|
||||||
|
if( pendingMotion != null )
|
||||||
|
{
|
||||||
|
inputHandler.OnMouseInput( pendingMotion.Value );
|
||||||
|
pendingMotion = null;
|
||||||
|
}
|
||||||
|
|
||||||
Game.DispatchMouseInput(MouseInputEvent.Up,
|
var button = MakeButton( e.button.button );
|
||||||
new MouseEventArgs(button, 1, e.button.x, e.button.y, 0),
|
lastButtonBits &= ~button;
|
||||||
mods);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case Sdl.SDL_MOUSEMOTION:
|
inputHandler.OnMouseInput( new MouseInput(
|
||||||
{
|
MouseInputEvent.Up, button, new int2( e.button.x, e.button.y ), mods ) );
|
||||||
pendingMotion = new MouseEventArgs(lastButtonBits, 0, e.motion.x, e.motion.y, 0);
|
} break;
|
||||||
} break;
|
|
||||||
|
|
||||||
case Sdl.SDL_KEYDOWN:
|
case Sdl.SDL_MOUSEMOTION:
|
||||||
{
|
{
|
||||||
var keyEvent = new KeyInput
|
pendingMotion = new MouseInput(
|
||||||
{
|
MouseInputEvent.Move,
|
||||||
Event = KeyInputEvent.Down,
|
lastButtonBits,
|
||||||
Modifiers = mods,
|
new int2( e.motion.x, e.motion.y ),
|
||||||
KeyChar = (char)e.key.keysym.unicode,
|
mods );
|
||||||
KeyName = Sdl.SDL_GetKeyName(e.key.keysym.sym),
|
} break;
|
||||||
VirtKey = e.key.keysym.sym
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!HandleSpecialKey(keyEvent))
|
case Sdl.SDL_KEYDOWN:
|
||||||
Game.HandleKeyEvent(keyEvent);
|
{
|
||||||
} break;
|
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:
|
if( !HandleSpecialKey( keyEvent ) )
|
||||||
{
|
inputHandler.OnKeyInput( keyEvent );
|
||||||
var keyEvent = new KeyInput
|
} break;
|
||||||
{
|
|
||||||
Event = KeyInputEvent.Up,
|
|
||||||
Modifiers = mods,
|
|
||||||
KeyChar = (char)e.key.keysym.unicode,
|
|
||||||
KeyName = Sdl.SDL_GetKeyName(e.key.keysym.sym),
|
|
||||||
VirtKey = e.key.keysym.sym
|
|
||||||
};
|
|
||||||
|
|
||||||
Game.HandleKeyEvent(keyEvent);
|
case Sdl.SDL_KEYUP:
|
||||||
} break;
|
{
|
||||||
}
|
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)
|
inputHandler.OnKeyInput( keyEvent );
|
||||||
{
|
} break;
|
||||||
Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods);
|
}
|
||||||
pendingMotion = null;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
CheckGlError();
|
if( pendingMotion != null )
|
||||||
}
|
{
|
||||||
|
inputHandler.OnMouseInput( pendingMotion.Value );
|
||||||
|
pendingMotion = null;
|
||||||
|
}
|
||||||
|
|
||||||
public void DrawIndexedPrimitives(PrimitiveType pt, Range<int> vertices, Range<int> indices)
|
CheckGlError();
|
||||||
{
|
}
|
||||||
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, Range<int> vertices, Range<int> indices )
|
||||||
{
|
{
|
||||||
Gl.glDrawElements(ModeFromPrimitiveType(pt), numPrimitives * IndicesPerPrimitive(pt),
|
Gl.glDrawElements( ModeFromPrimitiveType( pt ), indices.End - indices.Start,
|
||||||
Gl.GL_UNSIGNED_SHORT, IntPtr.Zero);
|
Gl.GL_UNSIGNED_SHORT, new IntPtr( indices.Start * 2 ) );
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ModeFromPrimitiveType(PrimitiveType pt)
|
public void DrawIndexedPrimitives( PrimitiveType pt, int numVerts, int numPrimitives )
|
||||||
{
|
{
|
||||||
switch (pt)
|
Gl.glDrawElements( ModeFromPrimitiveType( pt ), numPrimitives * IndicesPerPrimitive( pt ),
|
||||||
{
|
Gl.GL_UNSIGNED_SHORT, IntPtr.Zero );
|
||||||
case PrimitiveType.PointList: return Gl.GL_POINTS;
|
CheckGlError();
|
||||||
case PrimitiveType.LineList: return Gl.GL_LINES;
|
}
|
||||||
case PrimitiveType.TriangleList: return Gl.GL_TRIANGLES;
|
|
||||||
}
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
static int IndicesPerPrimitive(PrimitiveType pt)
|
static int ModeFromPrimitiveType( PrimitiveType pt )
|
||||||
{
|
{
|
||||||
switch (pt)
|
switch( pt )
|
||||||
{
|
{
|
||||||
case PrimitiveType.PointList: return 1;
|
case PrimitiveType.PointList: return Gl.GL_POINTS;
|
||||||
case PrimitiveType.LineList: return 2;
|
case PrimitiveType.LineList: return Gl.GL_LINES;
|
||||||
case PrimitiveType.TriangleList: return 3;
|
case PrimitiveType.TriangleList: return Gl.GL_TRIANGLES;
|
||||||
}
|
}
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IVertexBuffer<Vertex> CreateVertexBuffer(int size) { return new VertexBuffer<Vertex>(this, size); }
|
static int IndicesPerPrimitive( PrimitiveType pt )
|
||||||
public IIndexBuffer CreateIndexBuffer(int size) { return new IndexBuffer(this, size); }
|
{
|
||||||
public ITexture CreateTexture() { return new Texture(this); }
|
switch( pt )
|
||||||
public ITexture CreateTexture(Bitmap bitmap) { return new Texture(this, bitmap); }
|
{
|
||||||
public IShader CreateShader(Stream stream) { return new Shader(this, stream); }
|
case PrimitiveType.PointList: return 1;
|
||||||
}
|
case PrimitiveType.LineList: return 2;
|
||||||
|
case PrimitiveType.TriangleList: return 3;
|
||||||
|
}
|
||||||
|
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 ); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ namespace OpenRA.Mods.Cnc
|
|||||||
r.BeginFrame(float2.Zero);
|
r.BeginFrame(float2.Zero);
|
||||||
WidgetUtils.FillRectWithSprite(StripeRect, Stripe);
|
WidgetUtils.FillRectWithSprite(StripeRect, Stripe);
|
||||||
r.RgbaSpriteRenderer.DrawSprite(Logo, LogoPos);
|
r.RgbaSpriteRenderer.DrawSprite(Logo, LogoPos);
|
||||||
Font.DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White);
|
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() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ namespace OpenRA.Mods.RA
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Draw a black screen
|
// Draw a black screen
|
||||||
Game.Renderer.BeginFrame(float2.Zero);
|
Game.Renderer.BeginFrame(float2.Zero);
|
||||||
Game.Renderer.EndFrame();
|
Game.Renderer.EndFrame( new NullInputHandler() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ namespace OpenRA.Mods.RA
|
|||||||
r.BeginFrame(float2.Zero);
|
r.BeginFrame(float2.Zero);
|
||||||
WidgetUtils.FillRectWithSprite(StripeRect, Stripe);
|
WidgetUtils.FillRectWithSprite(StripeRect, Stripe);
|
||||||
r.RgbaSpriteRenderer.DrawSprite(Logo, LogoPos);
|
r.RgbaSpriteRenderer.DrawSprite(Logo, LogoPos);
|
||||||
Font.DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White);
|
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.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
|
||||||
using OpenRA.FileFormats.Graphics;
|
using OpenRA.FileFormats.Graphics;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
|
||||||
|
|
||||||
[assembly: Renderer(typeof(OpenRA.Renderer.Null.NullGraphicsDevice))]
|
[assembly: Renderer(typeof(OpenRA.Renderer.Null.NullGraphicsDevice))]
|
||||||
|
|
||||||
namespace OpenRA.Renderer.Null
|
namespace OpenRA.Renderer.Null
|
||||||
@@ -18,42 +16,23 @@ namespace OpenRA.Renderer.Null
|
|||||||
WindowSize = new Size(width, height);
|
WindowSize = new Size(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnableScissor(int left, int top, int width, int height)
|
public void EnableScissor(int left, int top, int width, int height) { }
|
||||||
{
|
public void DisableScissor() { }
|
||||||
}
|
|
||||||
|
|
||||||
public void DisableScissor()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Begin() { }
|
public void Begin() { }
|
||||||
public void End() { }
|
public void End() { }
|
||||||
|
public void Clear(Color c) { }
|
||||||
|
|
||||||
public void Clear(Color c)
|
public void Present(IInputHandler ih)
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void Present()
|
|
||||||
{
|
{
|
||||||
Game.HasInputFocus = false;
|
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, Range<int> vertices, Range<int> indices) { }
|
||||||
{
|
public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives) { }
|
||||||
}
|
|
||||||
|
|
||||||
public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public IVertexBuffer<Vertex> CreateVertexBuffer(int size)
|
|
||||||
{
|
|
||||||
return new NullVertexBuffer<Vertex>();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public IVertexBuffer<Vertex> CreateVertexBuffer(int size) { return new NullVertexBuffer<Vertex>(); }
|
||||||
public IIndexBuffer CreateIndexBuffer(int size) { return new NullIndexBuffer(); }
|
public IIndexBuffer CreateIndexBuffer(int size) { return new NullIndexBuffer(); }
|
||||||
public ITexture CreateTexture() { return new NullTexture(); }
|
public ITexture CreateTexture() { return new NullTexture(); }
|
||||||
public ITexture CreateTexture(Bitmap bitmap) { return new NullTexture(); }
|
public ITexture CreateTexture(Bitmap bitmap) { return new NullTexture(); }
|
||||||
|
|||||||
Reference in New Issue
Block a user