diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 08bf870ace..ed3b4fc652 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -22,6 +22,8 @@ namespace OpenRA.Graphics readonly float2 screenSize; float2 scrollPosition; readonly Renderer renderer; + readonly int2 mapStart; + readonly int2 mapEnd; public float2 Location { get { return scrollPosition; } } @@ -35,13 +37,31 @@ namespace OpenRA.Graphics public void Scroll(float2 delta) { - scrollPosition = scrollPosition + delta; + float2 topLeftBorder = (Game.CellSize* mapStart).ToFloat2(); + float2 bottomRightBorder = (Game.CellSize* mapEnd).ToFloat2(); + float2 newScrollPosition = scrollPosition + delta; + + if(newScrollPosition.Y < topLeftBorder.Y) + newScrollPosition.Y = topLeftBorder.Y; + + if(newScrollPosition.X < topLeftBorder.X) + newScrollPosition.X = topLeftBorder.X; + + if(newScrollPosition.Y > bottomRightBorder.Y-screenSize.Y) + newScrollPosition.Y = bottomRightBorder.Y-screenSize.Y; + + if(newScrollPosition.X > bottomRightBorder.X-screenSize.X) + newScrollPosition.X = bottomRightBorder.X-screenSize.X; + + scrollPosition = newScrollPosition; } public Viewport(float2 screenSize, int2 mapStart, int2 mapEnd, Renderer renderer) { this.screenSize = screenSize; this.renderer = renderer; + this.mapStart = mapStart; + this.mapEnd = mapEnd; this.scrollPosition = Game.CellSize* mapStart; } diff --git a/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs b/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs index bc91a4f936..f82530b569 100644 --- a/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs +++ b/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs @@ -50,7 +50,7 @@ namespace OpenRA.Widgets { if (!Game.Settings.Game.ViewportEdgeScroll) return null; - + if (Edge.Includes(ScrollDirection.Up) && Edge.Includes(ScrollDirection.Left)) return "scroll-tl"; if (Edge.Includes(ScrollDirection.Up) && Edge.Includes(ScrollDirection.Right))