diff --git a/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs index dc47e93..085054b 100644 --- a/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs +++ b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs @@ -42,6 +42,14 @@ namespace ShiftOS.Frontend.GraphicsSubsystem } } + public static System.Drawing.Size ScreenSize + { + get + { + return new System.Drawing.Size(_game.graphicsDevice.PreferredBackBufferWidth, _game.graphicsDevice.PreferredBackBufferHeight); + } + } + public static void BringToFront(GUI.Control ctrl) { topLevels.Remove(ctrl); @@ -146,8 +154,8 @@ namespace ShiftOS.Frontend.GraphicsSubsystem graphics.Clear(Color.Transparent); var gfxContext = new GraphicsContext(graphics, batch, 0, 0, _target.Width, _target.Height); ctrl.Paint(gfxContext); - - graphics.SetRenderTarget(null); + + graphics.SetRenderTarget(_game.GameRenderTarget); TextureCaches[hc] = _target; batch.End(); } diff --git a/ShiftOS.Frontend/MainMenu.cs b/ShiftOS.Frontend/MainMenu.cs index a6d987f..db6ece9 100644 --- a/ShiftOS.Frontend/MainMenu.cs +++ b/ShiftOS.Frontend/MainMenu.cs @@ -154,7 +154,7 @@ namespace ShiftOS.Frontend _optionsSave.Click += () => { - if (UIManager.Viewport != _screenResolutions[_resIndex]) + if (UIManager.ScreenSize != _screenResolutions[_resIndex]) { Engine.Infobox.PromptYesNo("Confirm sentience edit", "Performing this operation requires your sentience to be re-established which may cause you to go unconscious. Do you wish to continue?", (sleep) => @@ -181,7 +181,7 @@ namespace ShiftOS.Frontend foreach(var mode in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes.OrderBy(x=>x.Width * x.Height)) { _screenResolutions.Add(new System.Drawing.Size(mode.Width, mode.Height)); - if (UIManager.Viewport == _screenResolutions.Last()) + if (UIManager.ScreenSize == _screenResolutions.Last()) _resIndex = _screenResolutions.Count - 1; } _fullscreen.Y = _sandbox.Y; diff --git a/ShiftOS.Frontend/ShiftOS.cs b/ShiftOS.Frontend/ShiftOS.cs index 7cc142e..3577574 100644 --- a/ShiftOS.Frontend/ShiftOS.cs +++ b/ShiftOS.Frontend/ShiftOS.cs @@ -29,6 +29,8 @@ namespace ShiftOS.Frontend private bool failEnded = false; private double failCharAddMS = 0; + public RenderTarget2D GameRenderTarget = null; + public Color UITint = Color.White; private bool DisplayDebugInfo = false; @@ -56,8 +58,8 @@ namespace ShiftOS.Frontend UIManager.InvalidateAll(); }; UIManager.Viewport = new System.Drawing.Size( - graphicsDevice.PreferredBackBufferWidth, - graphicsDevice.PreferredBackBufferHeight + 1280, + 720 ); Content.RootDirectory = "Content"; @@ -77,6 +79,7 @@ namespace ShiftOS.Frontend // keyboard events keyboardListener.KeyPressed += KeyboardListener_KeyPressed; + UIManager.Init(this); } @@ -164,6 +167,8 @@ namespace ShiftOS.Frontend /// protected override void LoadContent() { + GameRenderTarget = new RenderTarget2D(graphicsDevice.GraphicsDevice, 1280, 720); + // Create a new SpriteBatch, which can be used to draw textures. this.spriteBatch = new SpriteBatch(base.GraphicsDevice); @@ -255,7 +260,9 @@ namespace ShiftOS.Frontend //Let's get the mouse state var mouseState = Mouse.GetState(this.Window); - LastMouseState = mouseState; + int x = (int)GUI.ProgressBar.linear(mouseState.X, 0, graphicsDevice.PreferredBackBufferWidth, 0, 1280); + int y = (int)GUI.ProgressBar.linear(mouseState.Y, 0, graphicsDevice.PreferredBackBufferHeight, 0, 720); + LastMouseState = new MouseState(x, y, mouseState.ScrollWheelValue, mouseState.LeftButton, mouseState.MiddleButton, mouseState.RightButton, mouseState.XButton1, mouseState.XButton2); UIManager.ProcessMouseState(LastMouseState, mouseMS); if (mouseState.LeftButton == ButtonState.Pressed) @@ -329,8 +336,8 @@ namespace ShiftOS.Frontend var rasterizerState = new RasterizerState(); rasterizerState.CullMode = CullMode.None; rasterizerState.MultiSampleAntiAlias = true; - + graphicsDevice.GraphicsDevice.SetRenderTarget(GameRenderTarget); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.LinearWrap, DepthStencilState.Default, rasterizerState); @@ -344,7 +351,7 @@ namespace ShiftOS.Frontend - var mousepos = Mouse.GetState(this.Window).Position; + var mousepos = LastMouseState; spriteBatch.Draw(MouseTexture, new Rectangle(mousepos.X+1, mousepos.Y+1, MouseTexture.Width, MouseTexture.Height), Color.Black * 0.5f); spriteBatch.Draw(MouseTexture, new Rectangle(mousepos.X, mousepos.Y, MouseTexture.Width, MouseTexture.Height), Color.White); @@ -400,6 +407,10 @@ Red text means low framerate, a low framerate could be a sign of CPU hogging cod Text cache: {GraphicsContext.StringCaches.Count}", 0, 0, color, new System.Drawing.Font("Lucida Console", 9F, System.Drawing.FontStyle.Bold)); } + spriteBatch.End(); + graphicsDevice.GraphicsDevice.SetRenderTarget(null); + spriteBatch.Begin(); + spriteBatch.Draw(GameRenderTarget, new Rectangle(0, 0, graphicsDevice.PreferredBackBufferWidth, graphicsDevice.PreferredBackBufferHeight), Color.White); spriteBatch.End(); base.Draw(gameTime); }