Added support for keyboard scrolling
This commit is contained in:
@@ -64,6 +64,11 @@ namespace OpenRA
|
|||||||
static bool mapChangePending;
|
static bool mapChangePending;
|
||||||
static Pair<Assembly, string>[] ModAssemblies;
|
static Pair<Assembly, string>[] ModAssemblies;
|
||||||
|
|
||||||
|
static internal bool scrollUp = false;
|
||||||
|
static internal bool scrollDown = false;
|
||||||
|
static internal bool scrollLeft = false;
|
||||||
|
static internal bool scrollRight = false;
|
||||||
|
|
||||||
static void LoadModPackages(Manifest manifest)
|
static void LoadModPackages(Manifest manifest)
|
||||||
{
|
{
|
||||||
FileSystem.UnmountAll();
|
FileSystem.UnmountAll();
|
||||||
@@ -308,6 +313,15 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (scrollUp == true)
|
||||||
|
viewport.Scroll(new float2(0, -10));
|
||||||
|
if (scrollRight == true)
|
||||||
|
viewport.Scroll(new float2(10, 0));
|
||||||
|
if (scrollDown == true)
|
||||||
|
viewport.Scroll(new float2(0, 10));
|
||||||
|
if (scrollLeft == true)
|
||||||
|
viewport.Scroll(new float2(-10, 0));
|
||||||
|
|
||||||
using (new PerfSample("render"))
|
using (new PerfSample("render"))
|
||||||
{
|
{
|
||||||
++RenderFrame;
|
++RenderFrame;
|
||||||
@@ -511,6 +525,26 @@ namespace OpenRA
|
|||||||
throw new InvalidOperationException("Desync in OnKeyPress");
|
throw new InvalidOperationException("Desync in OnKeyPress");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void HandleArrowKeyScroll(String k, Boolean pressed)
|
||||||
|
{
|
||||||
|
if (k == "up")
|
||||||
|
{
|
||||||
|
scrollUp = pressed;
|
||||||
|
}
|
||||||
|
if (k == "left")
|
||||||
|
{
|
||||||
|
scrollLeft = pressed;
|
||||||
|
}
|
||||||
|
if (k == "down")
|
||||||
|
{
|
||||||
|
scrollDown = pressed;
|
||||||
|
}
|
||||||
|
if (k == "right")
|
||||||
|
{
|
||||||
|
scrollRight = pressed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void HandleModifierKeys(Modifiers mods)
|
public static void HandleModifierKeys(Modifiers mods)
|
||||||
{
|
{
|
||||||
controller.SetModifiers(mods);
|
controller.SetModifiers(mods);
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace OpenRA.GlRenderer
|
|||||||
throw new InvalidOperationException("GL Error");
|
throw new InvalidOperationException("GL Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
public GraphicsDevice( int width, int height, bool windowed, bool vsync )
|
public GraphicsDevice(int width, int height, bool windowed, 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);
|
||||||
@@ -73,44 +73,44 @@ namespace OpenRA.GlRenderer
|
|||||||
|
|
||||||
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_INTERVAL, Sdl.SDL_DEFAULT_REPEAT_DELAY);
|
Sdl.SDL_EnableKeyRepeat(Sdl.SDL_DEFAULT_REPEAT_INTERVAL, Sdl.SDL_DEFAULT_REPEAT_DELAY);
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
@@ -195,21 +195,36 @@ namespace OpenRA.GlRenderer
|
|||||||
|
|
||||||
case Sdl.SDL_KEYDOWN:
|
case Sdl.SDL_KEYDOWN:
|
||||||
{
|
{
|
||||||
if( e.key.keysym.unicode != 0 )
|
switch (e.key.keysym.sym)
|
||||||
Game.HandleKeyPress( new KeyPressEventArgs( (char)e.key.keysym.unicode ), mods );
|
|
||||||
|
|
||||||
else if( mods != 0 )
|
|
||||||
{
|
{
|
||||||
var keyName = Sdl.SDL_GetKeyName( e.key.keysym.sym );
|
case Sdl.SDLK_UP: Game.HandleArrowKeyScroll("up", true); break;
|
||||||
if( keyName.Length == 1 )
|
case Sdl.SDLK_LEFT: Game.HandleArrowKeyScroll("left", true); break;
|
||||||
Game.HandleKeyPress( new KeyPressEventArgs( keyName[ 0 ] ), mods );
|
case Sdl.SDLK_DOWN: Game.HandleArrowKeyScroll("down", true); break;
|
||||||
else if( keyName == "f4" && ( ( mods & Modifiers.Alt ) != 0 ) )
|
case Sdl.SDLK_RIGHT: Game.HandleArrowKeyScroll("right", true); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.key.keysym.unicode != 0)
|
||||||
|
Game.HandleKeyPress(new KeyPressEventArgs((char)e.key.keysym.unicode), mods);
|
||||||
|
|
||||||
|
else if (mods != 0)
|
||||||
|
{
|
||||||
|
var keyName = Sdl.SDL_GetKeyName(e.key.keysym.sym);
|
||||||
|
if (keyName.Length == 1)
|
||||||
|
Game.HandleKeyPress(new KeyPressEventArgs(keyName[0]), mods);
|
||||||
|
else if (keyName == "f4" && ((mods & Modifiers.Alt) != 0))
|
||||||
OpenRA.Game.Exit();
|
OpenRA.Game.Exit();
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Sdl.SDL_KEYUP:
|
case Sdl.SDL_KEYUP:
|
||||||
{
|
{
|
||||||
|
switch (e.key.keysym.sym)
|
||||||
|
{
|
||||||
|
case Sdl.SDLK_UP: Game.HandleArrowKeyScroll("up", false); break;
|
||||||
|
case Sdl.SDLK_LEFT: Game.HandleArrowKeyScroll("left", false); break;
|
||||||
|
case Sdl.SDLK_DOWN: Game.HandleArrowKeyScroll("down", false); break;
|
||||||
|
case Sdl.SDLK_RIGHT: Game.HandleArrowKeyScroll("right", false); break;
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -217,21 +232,21 @@ namespace OpenRA.GlRenderer
|
|||||||
CheckGlError();
|
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();
|
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();
|
CheckGlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ModeFromPrimitiveType( PrimitiveType pt )
|
static int ModeFromPrimitiveType(PrimitiveType pt)
|
||||||
{
|
{
|
||||||
switch( pt )
|
switch (pt)
|
||||||
{
|
{
|
||||||
case PrimitiveType.PointList: return Gl.GL_POINTS;
|
case PrimitiveType.PointList: return Gl.GL_POINTS;
|
||||||
case PrimitiveType.LineList: return Gl.GL_LINES;
|
case PrimitiveType.LineList: return Gl.GL_LINES;
|
||||||
@@ -240,9 +255,9 @@ namespace OpenRA.GlRenderer
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int IndicesPerPrimitive( PrimitiveType pt )
|
static int IndicesPerPrimitive(PrimitiveType pt)
|
||||||
{
|
{
|
||||||
switch( pt )
|
switch (pt)
|
||||||
{
|
{
|
||||||
case PrimitiveType.PointList: return 1;
|
case PrimitiveType.PointList: return 1;
|
||||||
case PrimitiveType.LineList: return 2;
|
case PrimitiveType.LineList: return 2;
|
||||||
@@ -253,24 +268,24 @@ namespace OpenRA.GlRenderer
|
|||||||
|
|
||||||
#region IGraphicsDevice Members
|
#region IGraphicsDevice Members
|
||||||
|
|
||||||
public IVertexBuffer<Vertex> CreateVertexBuffer( int size )
|
public IVertexBuffer<Vertex> CreateVertexBuffer(int size)
|
||||||
{
|
{
|
||||||
return new VertexBuffer<Vertex>( this, size );
|
return new VertexBuffer<Vertex>(this, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexBuffer CreateIndexBuffer( int size )
|
public IIndexBuffer CreateIndexBuffer(int size)
|
||||||
{
|
{
|
||||||
return new IndexBuffer( this, size );
|
return new IndexBuffer(this, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ITexture CreateTexture( Bitmap bitmap )
|
public ITexture CreateTexture(Bitmap bitmap)
|
||||||
{
|
{
|
||||||
return new Texture( this, bitmap );
|
return new Texture(this, bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IShader CreateShader( Stream stream )
|
public IShader CreateShader(Stream stream)
|
||||||
{
|
{
|
||||||
return new Shader( this, stream );
|
return new Shader(this, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -291,7 +306,7 @@ namespace OpenRA.GlRenderer
|
|||||||
{
|
{
|
||||||
Bind();
|
Bind();
|
||||||
Gl.glBufferData(Gl.GL_ARRAY_BUFFER,
|
Gl.glBufferData(Gl.GL_ARRAY_BUFFER,
|
||||||
new IntPtr(Marshal.SizeOf(typeof(T))*data.Length), data, Gl.GL_DYNAMIC_DRAW);
|
new IntPtr(Marshal.SizeOf(typeof(T)) * data.Length), data, Gl.GL_DYNAMIC_DRAW);
|
||||||
GraphicsDevice.CheckGlError();
|
GraphicsDevice.CheckGlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,13 +392,13 @@ namespace OpenRA.GlRenderer
|
|||||||
string.Format("Cg compile failed ({0}):\n{1}", err, results));
|
string.Format("Cg compile failed ({0}):\n{1}", err, results));
|
||||||
}
|
}
|
||||||
|
|
||||||
technique = Cg.cgGetFirstTechnique( effect );
|
technique = Cg.cgGetFirstTechnique(effect);
|
||||||
if( technique == IntPtr.Zero )
|
if (technique == IntPtr.Zero)
|
||||||
throw new InvalidOperationException("No techniques");
|
throw new InvalidOperationException("No techniques");
|
||||||
while( Cg.cgValidateTechnique( technique ) == 0 )
|
while (Cg.cgValidateTechnique(technique) == 0)
|
||||||
{
|
{
|
||||||
technique = Cg.cgGetNextTechnique( technique );
|
technique = Cg.cgGetNextTechnique(technique);
|
||||||
if( technique == IntPtr.Zero )
|
if (technique == IntPtr.Zero)
|
||||||
throw new InvalidOperationException("No valid techniques");
|
throw new InvalidOperationException("No valid techniques");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -409,15 +424,15 @@ namespace OpenRA.GlRenderer
|
|||||||
public void SetValue(string name, ITexture t)
|
public void SetValue(string name, ITexture t)
|
||||||
{
|
{
|
||||||
var texture = (Texture)t;
|
var texture = (Texture)t;
|
||||||
var param = Cg.cgGetNamedEffectParameter( effect, name );
|
var param = Cg.cgGetNamedEffectParameter(effect, name);
|
||||||
if( param != IntPtr.Zero && texture != null )
|
if (param != IntPtr.Zero && texture != null)
|
||||||
CgGl.cgGLSetupSampler( param, texture.texture );
|
CgGl.cgGLSetupSampler(param, texture.texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValue(string name, float x, float y)
|
public void SetValue(string name, float x, float y)
|
||||||
{
|
{
|
||||||
var param = Cg.cgGetNamedEffectParameter(effect, name);
|
var param = Cg.cgGetNamedEffectParameter(effect, name);
|
||||||
if( param != IntPtr.Zero )
|
if (param != IntPtr.Zero)
|
||||||
CgGl.cgGLSetParameter2f(param, x, y);
|
CgGl.cgGLSetParameter2f(param, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -437,13 +452,13 @@ namespace OpenRA.GlRenderer
|
|||||||
|
|
||||||
public void SetData(Bitmap bitmap)
|
public void SetData(Bitmap bitmap)
|
||||||
{
|
{
|
||||||
if( !IsPowerOf2( bitmap.Width ) || !IsPowerOf2( bitmap.Height ) )
|
if (!IsPowerOf2(bitmap.Width) || !IsPowerOf2(bitmap.Height))
|
||||||
{
|
{
|
||||||
//throw new InvalidOperationException( "non-power-of-2-texture" );
|
//throw new InvalidOperationException( "non-power-of-2-texture" );
|
||||||
bitmap = new Bitmap( bitmap, new Size( NextPowerOf2( bitmap.Width ), NextPowerOf2( bitmap.Height ) ) );
|
bitmap = new Bitmap(bitmap, new Size(NextPowerOf2(bitmap.Width), NextPowerOf2(bitmap.Height)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Gl.glBindTexture( Gl.GL_TEXTURE_2D, texture );
|
Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture);
|
||||||
GraphicsDevice.CheckGlError();
|
GraphicsDevice.CheckGlError();
|
||||||
|
|
||||||
var bits = bitmap.LockBits(
|
var bits = bitmap.LockBits(
|
||||||
@@ -462,12 +477,12 @@ namespace OpenRA.GlRenderer
|
|||||||
bitmap.UnlockBits(bits);
|
bitmap.UnlockBits(bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsPowerOf2( int v )
|
bool IsPowerOf2(int v)
|
||||||
{
|
{
|
||||||
return ( v & ( v - 1 ) ) == 0;
|
return (v & (v - 1)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int NextPowerOf2( int v )
|
int NextPowerOf2(int v)
|
||||||
{
|
{
|
||||||
--v;
|
--v;
|
||||||
v |= v >> 1;
|
v |= v >> 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user