diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index a962476d3e..ab0add25df 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -212,7 +212,7 @@ namespace OpenRA BeforeGameStart(); var map = modData.PrepareMap(mapUID); - viewport = new Viewport(new int2(Renderer.Resolution), map.Bounds, Renderer); + viewport = new Viewport(map.Bounds); orderManager.world = new World(modData.Manifest, map, orderManager, isShellmap); worldRenderer = new WorldRenderer(orderManager.world); orderManager.world.LoadComplete(worldRenderer); @@ -328,7 +328,7 @@ namespace OpenRA PerfHistory.items["render_flip"].hasNormalTick = false; JoinLocal(); - viewport = new Viewport(new int2(Renderer.Resolution), Rectangle.Empty, Renderer); + viewport = new Viewport(Rectangle.Empty); if (Game.Settings.Server.Dedicated) { diff --git a/OpenRA.Game/Graphics/Renderer.cs b/OpenRA.Game/Graphics/Renderer.cs index ccdbc0526c..2d510ff999 100644 --- a/OpenRA.Game/Graphics/Renderer.cs +++ b/OpenRA.Game/Graphics/Renderer.cs @@ -123,7 +123,7 @@ namespace OpenRA.Graphics static IGraphicsDevice device; - public static Size Resolution { get { return device.WindowSize; } } + public Size Resolution { get { return device.WindowSize; } } // Work around a bug in OSX 10.6.8 / mono 2.10.2 / SDL 1.2.14 // which makes the window non-interactive in Windowed/Pseudofullscreen mode. diff --git a/OpenRA.Game/Graphics/TerrainRenderer.cs b/OpenRA.Game/Graphics/TerrainRenderer.cs index cc092e2b6f..5891664df9 100644 --- a/OpenRA.Game/Graphics/TerrainRenderer.cs +++ b/OpenRA.Game/Graphics/TerrainRenderer.cs @@ -48,7 +48,7 @@ namespace OpenRA.Graphics { int verticesPerRow = 4*map.Bounds.Width; - int visibleRows = (int)(viewport.Height * 1f / Game.CellSize / viewport.Zoom + 2); + int visibleRows = (int)(Game.Renderer.Resolution.Height * 1f / Game.CellSize / viewport.Zoom + 2); int firstRow = (int)(viewport.Location.Y * 1f / Game.CellSize - map.Bounds.Top); int lastRow = firstRow + visibleRows; diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index eb3ada7af7..5dbb2f7b74 100755 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -22,15 +22,13 @@ namespace OpenRA.Graphics public class Viewport { - readonly int2 screenSize; - readonly Renderer renderer; readonly Rectangle mapBounds; Rectangle scrollLimits; int2 scrollPosition; // Top-left of the viewport, in world-px units public float2 Location { get { return scrollPosition; } } - public float2 CenterLocation { get { return scrollPosition + 0.5f/Zoom*screenSize.ToFloat2(); } } + public float2 CenterLocation { get { return scrollPosition + 0.5f/Zoom * new float2(Game.Renderer.Resolution); } } public Rectangle WorldRect { @@ -38,14 +36,11 @@ namespace OpenRA.Graphics { return new Rectangle(scrollPosition.X / Game.CellSize, scrollPosition.Y / Game.CellSize, - (int)(screenSize.X / Zoom / Game.CellSize), - (int)(screenSize.Y / Zoom / Game.CellSize)); + (int)(Game.Renderer.Resolution.Width / Zoom / Game.CellSize), + (int)(Game.Renderer.Resolution.Height / Zoom / Game.CellSize)); } } - public int Width { get { return screenSize.X; } } - public int Height { get { return screenSize.Y; } } - float zoom = 1f; public float Zoom { @@ -61,13 +56,13 @@ namespace OpenRA.Graphics // Update scroll limits var viewTL = (Game.CellSize*new float2(mapBounds.Left, mapBounds.Top)).ToInt2(); var viewBR = (Game.CellSize*new float2(mapBounds.Right, mapBounds.Bottom)).ToInt2(); - var border = (.5f/Zoom * screenSize.ToFloat2()).ToInt2(); + var border = (.5f/Zoom * new float2(Game.Renderer.Resolution)).ToInt2(); scrollLimits = Rectangle.FromLTRB(viewTL.X - border.X, viewTL.Y - border.Y, viewBR.X - border.X, viewBR.Y - border.Y); // Re-center viewport - scrollPosition = NormalizeScrollPosition((oldCenter - 0.5f / Zoom * screenSize.ToFloat2()).ToInt2()); + scrollPosition = NormalizeScrollPosition((oldCenter - 0.5f / Zoom * new float2(Game.Renderer.Resolution)).ToInt2()); } } @@ -108,32 +103,30 @@ namespace OpenRA.Graphics return ret; } - public Viewport(int2 screenSize, Rectangle mapBounds, Renderer renderer) + public Viewport(Rectangle mapBounds) { - this.screenSize = screenSize; - this.renderer = renderer; this.mapBounds = mapBounds; Zoom = Game.Settings.Graphics.PixelDouble ? 2 : 1; scrollPosition = new int2(scrollLimits.Location) + new int2(scrollLimits.Size)/2; } - public void DrawRegions( WorldRenderer wr, IInputHandler inputHandler ) + public void DrawRegions(WorldRenderer wr, IInputHandler inputHandler) { - renderer.BeginFrame(scrollPosition, Zoom); + Game.Renderer.BeginFrame(scrollPosition, Zoom); if (wr != null) wr.Draw(); - using( new PerfSample("render_widgets") ) + using (new PerfSample("render_widgets")) { Ui.Draw(); var cursorName = Ui.Root.GetCursorOuter(Viewport.LastMousePos) ?? "default"; - CursorProvider.DrawCursor(renderer, cursorName, Viewport.LastMousePos, (int)cursorFrame); + CursorProvider.DrawCursor(Game.Renderer, cursorName, Viewport.LastMousePos, (int)cursorFrame); } - using( new PerfSample("render_flip") ) + using (new PerfSample("render_flip")) { - renderer.EndFrame( inputHandler ); + Game.Renderer.EndFrame(inputHandler); } } @@ -154,7 +147,7 @@ namespace OpenRA.Graphics public void Center(float2 loc) { - scrollPosition = NormalizeScrollPosition((Game.CellSize * loc - 1f/(2*Zoom)*screenSize.ToFloat2()).ToInt2()); + scrollPosition = NormalizeScrollPosition((Game.CellSize * loc - 1f/(2*Zoom)*new float2(Game.Renderer.Resolution)).ToInt2()); } public void Center(IEnumerable actors) @@ -172,8 +165,8 @@ namespace OpenRA.Graphics var origin = Location.ToInt2(); var left = Math.Max(0, Game.CellSize * r.Left - origin.X)*Zoom; var top = Math.Max(0, Game.CellSize * r.Top - origin.Y)*Zoom; - var right = Math.Min((Game.CellSize * r.Right - origin.X) * Zoom, Width); - var bottom = Math.Min((Game.CellSize * r.Bottom - origin.Y) * Zoom, Height); + var right = Math.Min((Game.CellSize * r.Right - origin.X) * Zoom, Game.Renderer.Resolution.Width); + var bottom = Math.Min((Game.CellSize * r.Bottom - origin.Y) * Zoom, Game.Renderer.Resolution.Height); return Rectangle.FromLTRB((int)left, (int)top, (int)right, (int)bottom); } @@ -188,7 +181,7 @@ namespace OpenRA.Graphics { var boundary = new int2(1,1); // Add a curtain of cells around the viewport to account for rounding errors var tl = ViewToWorld(int2.Zero).ToInt2() - boundary; - var br = ViewToWorld(new int2(Width, Height)).ToInt2() + boundary; + var br = ViewToWorld(new int2(Game.Renderer.Resolution.Width, Game.Renderer.Resolution.Height)).ToInt2() + boundary; cachedRect = Rectangle.Intersect(Rectangle.FromLTRB(tl.X, tl.Y, br.X, br.Y), world.Map.Bounds); cachedScroll = scrollPosition; diff --git a/OpenRA.Game/Widgets/DropDownButtonWidget.cs b/OpenRA.Game/Widgets/DropDownButtonWidget.cs index dff82bafd1..96a5e35cc4 100644 --- a/OpenRA.Game/Widgets/DropDownButtonWidget.cs +++ b/OpenRA.Game/Widgets/DropDownButtonWidget.cs @@ -71,7 +71,7 @@ namespace OpenRA.Widgets // Mask to prevent any clicks from being sent to other widgets fullscreenMask = new MaskWidget(); - fullscreenMask.Bounds = new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height); + fullscreenMask.Bounds = new Rectangle(0, 0, Game.Renderer.Resolution.Width, Game.Renderer.Resolution.Height); fullscreenMask.OnMouseDown += mi => RemovePanel(); if (onCancel != null) fullscreenMask.OnMouseDown += _ => onCancel(); diff --git a/OpenRA.Game/Widgets/TooltipContainerWidget.cs b/OpenRA.Game/Widgets/TooltipContainerWidget.cs old mode 100755 new mode 100644 index 6e0b9a7bee..d8fe7f8408 --- a/OpenRA.Game/Widgets/TooltipContainerWidget.cs +++ b/OpenRA.Game/Widgets/TooltipContainerWidget.cs @@ -54,8 +54,8 @@ namespace OpenRA.Widgets var pos = Viewport.LastMousePos + CursorOffset; if (tooltip != null) { - if (pos.X + tooltip.Bounds.Right > Game.viewport.Width) - pos.X = Game.viewport.Width - tooltip.Bounds.Right; + if (pos.X + tooltip.Bounds.Right > Game.Renderer.Resolution.Width) + pos.X = Game.Renderer.Resolution.Width - tooltip.Bounds.Right; } return pos; diff --git a/OpenRA.Game/Widgets/ViewportControllerWidget.cs b/OpenRA.Game/Widgets/ViewportControllerWidget.cs old mode 100755 new mode 100644 index 10324995b0..86948d7275 --- a/OpenRA.Game/Widgets/ViewportControllerWidget.cs +++ b/OpenRA.Game/Widgets/ViewportControllerWidget.cs @@ -206,9 +206,9 @@ namespace OpenRA.Widgets directions |= ScrollDirection.Left; if (Viewport.LastMousePos.Y < EdgeScrollThreshold) directions |= ScrollDirection.Up; - if (Viewport.LastMousePos.X >= Game.viewport.Width - EdgeScrollThreshold) + if (Viewport.LastMousePos.X >= Game.Renderer.Resolution.Width - EdgeScrollThreshold) directions |= ScrollDirection.Right; - if (Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeScrollThreshold) + if (Viewport.LastMousePos.Y >= Game.Renderer.Resolution.Height - EdgeScrollThreshold) directions |= ScrollDirection.Down; return directions; diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 0e066ec0e0..beb4756679 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -188,15 +188,15 @@ namespace OpenRA.Widgets { // Parse the YAML equations to find the widget bounds var parentBounds = (Parent == null) - ? new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height) + ? new Rectangle(0, 0, Game.Renderer.Resolution.Width, Game.Renderer.Resolution.Height) : Parent.Bounds; var substitutions = args.ContainsKey("substitutions") ? new Dictionary((Dictionary)args["substitutions"]) : new Dictionary(); - substitutions.Add("WINDOW_RIGHT", Game.viewport.Width); - substitutions.Add("WINDOW_BOTTOM", Game.viewport.Height); + substitutions.Add("WINDOW_RIGHT", Game.Renderer.Resolution.Width); + substitutions.Add("WINDOW_BOTTOM", Game.Renderer.Resolution.Height); substitutions.Add("PARENT_RIGHT", parentBounds.Width); substitutions.Add("PARENT_LEFT", parentBounds.Left); substitutions.Add("PARENT_TOP", parentBounds.Top); diff --git a/OpenRA.Mods.Cnc/CncLoadScreen.cs b/OpenRA.Mods.Cnc/CncLoadScreen.cs index 5c96d4959e..3ee853fa18 100644 --- a/OpenRA.Mods.Cnc/CncLoadScreen.cs +++ b/OpenRA.Mods.Cnc/CncLoadScreen.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Cnc if (r == null) return; var s = new Sheet("mods/cnc/uibits/chrome.png"); - var res = Renderer.Resolution; + var res = r.Resolution; bounds = new Rectangle(0, 0, res.Width, res.Height); ss = new[] diff --git a/OpenRA.Mods.D2k/D2kLoadScreen.cs b/OpenRA.Mods.D2k/D2kLoadScreen.cs index 8183238456..d0dc9c7337 100644 --- a/OpenRA.Mods.D2k/D2kLoadScreen.cs +++ b/OpenRA.Mods.D2k/D2kLoadScreen.cs @@ -41,8 +41,8 @@ namespace OpenRA.Mods.D2k var s = new Sheet("mods/d2k/uibits/loadscreen.png"); Logo = new Sprite(s, new Rectangle(0, 0, 256, 256), TextureChannel.Alpha); stripe = new Sprite(s, new Rectangle(256, 0, 256, 256), TextureChannel.Alpha); - stripeRect = new Rectangle(0, Renderer.Resolution.Height / 2 - 128, Renderer.Resolution.Width, 256); - logoPos = new float2(Renderer.Resolution.Width / 2 - 128, Renderer.Resolution.Height / 2 - 128); + stripeRect = new Rectangle(0, r.Resolution.Height / 2 - 128, r.Resolution.Width, 256); + logoPos = new float2(r.Resolution.Width / 2 - 128, r.Resolution.Height / 2 - 128); } public void Display() @@ -64,7 +64,7 @@ namespace OpenRA.Mods.D2k r.BeginFrame(float2.Zero, 1f); WidgetUtils.FillRectWithSprite(stripeRect, stripe); r.RgbaSpriteRenderer.DrawSprite(Logo, logoPos); - r.Fonts["Bold"].DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White); + r.Fonts["Bold"].DrawText(text, new float2(r.Resolution.Width - textSize.X - 20, r.Resolution.Height - textSize.Y - 20), Color.White); r.EndFrame(new NullInputHandler()); } diff --git a/OpenRA.Mods.RA/Missions/MissionWidgets.cs b/OpenRA.Mods.RA/Missions/MissionWidgets.cs index 280c35262b..5da20131c9 100644 --- a/OpenRA.Mods.RA/Missions/MissionWidgets.cs +++ b/OpenRA.Mods.RA/Missions/MissionWidgets.cs @@ -28,9 +28,10 @@ namespace OpenRA.Mods.RA.Missions { if (!IsVisible()) return; + // TODO: Don't hardcode the screen position var font = Game.Renderer.Fonts["Bold"]; var text = Format.F(WidgetUtils.FormatTime(Timer.TicksLeft)); - var pos = new float2(Game.viewport.Width * 0.5f - font.Measure(text).X / 2, Game.viewport.Height * 0.1f); + var pos = new float2(Game.Renderer.Resolution.Width * 0.5f - font.Measure(text).X / 2, Game.Renderer.Resolution.Height * 0.1f); font.DrawTextWithContrast(text, pos, Timer.TicksLeft <= 25 * 60 && Game.LocalTick % 50 < 25 ? Color.Red : Color.White, Color.Black, 1); } } @@ -45,8 +46,9 @@ namespace OpenRA.Mods.RA.Missions { if (!IsVisible()) return; + // TODO: Don't hardcode the screen position var font = Game.Renderer.Fonts["Bold"]; - var pos = new float2(Game.viewport.Width * 0.5f - font.Measure(Text).X / 2, Game.viewport.Height * 0.1f); + var pos = new float2(Game.Renderer.Resolution.Width * 0.5f - font.Measure(Text).X / 2, Game.Renderer.Resolution.Height * 0.1f); font.DrawTextWithContrast(Text, pos, Color.White, Color.Black, 1); } } diff --git a/OpenRA.Mods.RA/RALoadScreen.cs b/OpenRA.Mods.RA/RALoadScreen.cs index 258bb1963d..43ee9b0439 100644 --- a/OpenRA.Mods.RA/RALoadScreen.cs +++ b/OpenRA.Mods.RA/RALoadScreen.cs @@ -44,8 +44,8 @@ namespace OpenRA.Mods.RA var s = new Sheet(Info["LoadScreenImage"]); Logo = new Sprite(s, new Rectangle(0,0,256,256), TextureChannel.Alpha); Stripe = new Sprite(s, new Rectangle(256,0,256,256), TextureChannel.Alpha); - StripeRect = new Rectangle(0, Renderer.Resolution.Height/2 - 128, Renderer.Resolution.Width, 256); - LogoPos = new float2(Renderer.Resolution.Width/2 - 128, Renderer.Resolution.Height/2 - 128); + StripeRect = new Rectangle(0, r.Resolution.Height/2 - 128, r.Resolution.Width, 256); + LogoPos = new float2(r.Resolution.Width/2 - 128, r.Resolution.Height/2 - 128); } public void Display() @@ -67,7 +67,7 @@ namespace OpenRA.Mods.RA r.BeginFrame(float2.Zero, 1f); WidgetUtils.FillRectWithSprite(StripeRect, Stripe); r.RgbaSpriteRenderer.DrawSprite(Logo, LogoPos); - r.Fonts["Bold"].DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White); + r.Fonts["Bold"].DrawText(text, new float2(r.Resolution.Width - textSize.X - 20, r.Resolution.Height - textSize.Y - 20), Color.White); r.EndFrame( new NullInputHandler() ); } diff --git a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs index 6b421354e8..30402a14ef 100755 --- a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs +++ b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs @@ -69,8 +69,8 @@ namespace OpenRA.Mods.RA.Widgets public override void Initialize(WidgetArgs args) { - paletteOpenOrigin = new float2(Game.viewport.Width - Columns*IconWidth - 23, 280); - paletteClosedOrigin = new float2(Game.viewport.Width - 16, 280); + paletteOpenOrigin = new float2(Game.Renderer.Resolution.Width - Columns*IconWidth - 23, 280); + paletteClosedOrigin = new float2(Game.Renderer.Resolution.Width - 16, 280); paletteOrigin = paletteClosedOrigin; base.Initialize(args); } @@ -280,19 +280,19 @@ namespace OpenRA.Mods.RA.Widgets // Tooltip if (tooltipItem != null && !paletteAnimating && paletteOpen) DrawProductionTooltip(world, tooltipItem, - new float2(Game.viewport.Width, origin.Y + numActualRows * IconHeight + 9).ToInt2()); + new float2(Game.Renderer.Resolution.Width, origin.Y + numActualRows * IconHeight + 9).ToInt2()); } // Palette Dock WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-top"), - new float2(Game.viewport.Width - 14, origin.Y - 23)); + new float2(Game.Renderer.Resolution.Width - 14, origin.Y - 23)); for (int i = 0; i < numActualRows; i++) WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-" + (i % 4).ToString()), - new float2(Game.viewport.Width - 14, origin.Y + IconHeight * i)); + new float2(Game.Renderer.Resolution.Width - 14, origin.Y + IconHeight * i)); WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-bottom"), - new float2(Game.viewport.Width - 14, origin.Y - 1 + IconHeight * numActualRows)); + new float2(Game.Renderer.Resolution.Width - 14, origin.Y - 1 + IconHeight * numActualRows)); return IconHeight * y + 9; } @@ -456,7 +456,7 @@ namespace OpenRA.Mods.RA.Widgets var longDescSize = Game.Renderer.Fonts["Regular"].Measure(tooltip.Description.Replace("\\n", "\n")).Y; if (!canBuildThis) longDescSize += 8; - WidgetUtils.DrawPanel("dialog4", new Rectangle(Game.viewport.Width - 300, pos.Y, 300, longDescSize + 65)); + WidgetUtils.DrawPanel("dialog4", new Rectangle(Game.Renderer.Resolution.Width - 300, pos.Y, 300, longDescSize + 65)); Game.Renderer.Fonts["Bold"].DrawText( tooltip.Name + ((buildable.Hotkey != null) ? " ({0})".F(buildable.Hotkey.ToUpper()) : ""), diff --git a/OpenRA.Mods.TS/TSLoadScreen.cs b/OpenRA.Mods.TS/TSLoadScreen.cs index bfb726866d..7723d80e45 100644 --- a/OpenRA.Mods.TS/TSLoadScreen.cs +++ b/OpenRA.Mods.TS/TSLoadScreen.cs @@ -40,8 +40,8 @@ namespace OpenRA.Mods.TS var s = new Sheet(Info["LoadScreenImage"]); Logo = new Sprite(s, new Rectangle(0,0,256,256), TextureChannel.Alpha); Stripe = new Sprite(s, new Rectangle(256,0,256,256), TextureChannel.Alpha); - StripeRect = new Rectangle(0, Renderer.Resolution.Height/2 - 128, Renderer.Resolution.Width, 256); - LogoPos = new float2(Renderer.Resolution.Width/2 - 128, Renderer.Resolution.Height/2 - 128); + StripeRect = new Rectangle(0, r.Resolution.Height/2 - 128, r.Resolution.Width, 256); + LogoPos = new float2(r.Resolution.Width/2 - 128, r.Resolution.Height/2 - 128); } public void Display() @@ -63,7 +63,7 @@ namespace OpenRA.Mods.TS r.BeginFrame(float2.Zero, 1f); WidgetUtils.FillRectWithSprite(StripeRect, Stripe); r.RgbaSpriteRenderer.DrawSprite(Logo, LogoPos); - r.Fonts["Bold"].DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White); + r.Fonts["Bold"].DrawText(text, new float2(r.Resolution.Width - textSize.X - 20, r.Resolution.Height - textSize.Y - 20), Color.White); r.EndFrame( new NullInputHandler() ); }