diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 6270438ae6..af3d908477 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -41,12 +41,13 @@ namespace OpenRa.Game Visible = true; renderer = new Renderer(this, GetResolution(settings), false); - viewport = new Viewport(ClientSize); - - SheetBuilder.Initialize(renderer.Device); map = new Map(new IniFile(File.OpenRead("../../../" + settings.GetValue("map", "scm12ea.ini")))); + viewport = new Viewport(ClientSize, new float2(map.Size)); + + SheetBuilder.Initialize(renderer.Device); + TileMix = new Package("../../../" + map.Theater + ".mix"); renderer.SetPalette(new HardwarePalette(renderer.Device, map)); @@ -91,14 +92,10 @@ namespace OpenRa.Game if (e.Button == 0) return; - float2 scrollPos = new float2(viewport.ScrollPosition) + lastPos - new float2(e.Location); - float2 mapSize = 24 * new float2(map.Size) - viewport.Size + new float2(128, 0); + float2 p = new float2(e.Location); - scrollPos = scrollPos.Constrain(new Range(float2.Zero, mapSize)); - - lastPos = new float2(e.Location); - - viewport.ScrollPosition = scrollPos.ToPointF(); + viewport.Scroll(lastPos - p); + lastPos = p; } void Frame() diff --git a/OpenRa.Game/Viewport.cs b/OpenRa.Game/Viewport.cs index 99e4091f0d..38d1eadf75 100644 --- a/OpenRa.Game/Viewport.cs +++ b/OpenRa.Game/Viewport.cs @@ -2,18 +2,26 @@ using System; using System.Collections.Generic; using System.Text; using System.Drawing; +using BluntDirectX.Direct3D; namespace OpenRa.Game { class Viewport { readonly Size clientSize; + readonly float2 mapSize; PointF scrollPosition; public PointF ScrollPosition { get { return scrollPosition; } - set { scrollPosition = value; } + } + + public void Scroll(float2 delta) + { + float2 scrollPos = new float2(ScrollPosition) + delta; + scrollPos = scrollPos.Constrain(new Range(float2.Zero, mapSize)); + scrollPosition = scrollPos.ToPointF(); } public Size ClientSize @@ -21,9 +29,10 @@ namespace OpenRa.Game get { return clientSize; } } - public Viewport(Size clientSize) + public Viewport(Size clientSize, float2 mapSize) { this.clientSize = clientSize; + this.mapSize = 24 * mapSize - Size + new float2(128, 0); } public float2 Size { get { return new float2(clientSize); } }