From a6d36fcb9aa5d805af1bd1594695bfacf7caab88 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Thu, 18 Feb 2010 08:18:46 +1300 Subject: [PATCH] allow feedback on window size; ask glfw how big a window we *actually* got. --- OpenRa.FileFormats/Graphics/IGraphicsDevice.cs | 2 ++ OpenRa.Game/Game.cs | 1 + OpenRa.Game/Graphics/Renderer.cs | 2 ++ OpenRa.Gl/GraphicsDevice.cs | 11 +++++++++-- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/OpenRa.FileFormats/Graphics/IGraphicsDevice.cs b/OpenRa.FileFormats/Graphics/IGraphicsDevice.cs index 4936b1947e..b4c3dc2360 100755 --- a/OpenRa.FileFormats/Graphics/IGraphicsDevice.cs +++ b/OpenRa.FileFormats/Graphics/IGraphicsDevice.cs @@ -28,6 +28,8 @@ namespace OpenRa.FileFormats.Graphics IShader CreateShader( Stream stream ); + Size WindowSize { get; } + void Begin(); void End(); void Clear( Color color ); diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 9c21c41716..6fbff46f52 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -370,6 +370,7 @@ namespace OpenRa bool windowed = !Game.Settings.Fullscreen; var resolution = GetResolution(settings); renderer = new Renderer(resolution, windowed); + resolution = renderer.Resolution; var controller = new Controller(() => (Modifiers)(int)0/*ModifierKeys*/); /* a bit of insane input routing */ diff --git a/OpenRa.Game/Graphics/Renderer.cs b/OpenRa.Game/Graphics/Renderer.cs index aa3033435b..7657590dbe 100644 --- a/OpenRa.Game/Graphics/Renderer.cs +++ b/OpenRa.Game/Graphics/Renderer.cs @@ -49,6 +49,8 @@ namespace OpenRa.Graphics SpriteRenderer rgbaRenderer; Sprite textSprite; + public Size Resolution { get { return device.WindowSize; } } + public Renderer(Size resolution, bool windowed) { device = CreateDevice( Assembly.LoadFile( Path.GetFullPath( "OpenRa.Gl.dll" ) ), resolution.Width, resolution.Height, windowed, false ); diff --git a/OpenRa.Gl/GraphicsDevice.cs b/OpenRa.Gl/GraphicsDevice.cs index eb21cc35c7..b86ef53552 100644 --- a/OpenRa.Gl/GraphicsDevice.cs +++ b/OpenRa.Gl/GraphicsDevice.cs @@ -45,6 +45,8 @@ namespace OpenRa.GlRenderer readonly Glfw.GLFWwindowclosefun windowCloseCallback; int mouseX, mouseY; + public Size WindowSize { get { return windowSize; } } + internal static void CheckGlError() { var n = Gl.glGetError(); @@ -55,7 +57,7 @@ namespace OpenRa.GlRenderer public GraphicsDevice( int width, int height, bool fullscreen, bool vsync ) { Glfw.glfwInit(); - Glfw.glfwOpenWindow(width, height, 0, 0, 0, 0, 0, 0, fullscreen ? Glfw.GLFW_FULLSCREEN : Glfw.GLFW_WINDOW); + Glfw.glfwOpenWindow(width, height, 0, 0, 0, 0, 0, 0, /*fullscreen ? Glfw.GLFW_FULLSCREEN : */Glfw.GLFW_WINDOW); bool initDone = false; var lastButtonBits = (MouseButtons)0; @@ -69,7 +71,11 @@ namespace OpenRa.GlRenderer Game.DispatchMouseInput( action == Glfw.GLFW_PRESS ? MouseInputEvent.Down : MouseInputEvent.Up, new MouseEventArgs( b, action == Glfw.GLFW_PRESS ? 1 : 0, mouseX, mouseY, 0 ), 0 ); - lastButtonBits = action == Glfw.GLFW_PRESS ? b : 0; + if (action == Glfw.GLFW_PRESS) lastButtonBits |= b; + else lastButtonBits &= ~b; + + if (action != Glfw.GLFW_PRESS && action != Glfw.GLFW_RELEASE) + throw new InvalidOperationException(); } ); Glfw.glfwSetMousePosCallback(mousePositionCallback = (x, y) => { @@ -86,6 +92,7 @@ namespace OpenRa.GlRenderer } ); CheckGlError(); + Glfw.glfwGetWindowSize(out width, out height); windowSize = new Size( width, height ); cgContext = Cg.cgCreateContext();