diff --git a/src/TSMapEditor/Rendering/MapView.cs b/src/TSMapEditor/Rendering/MapView.cs index 889c2e661..32a012303 100644 --- a/src/TSMapEditor/Rendering/MapView.cs +++ b/src/TSMapEditor/Rendering/MapView.cs @@ -61,6 +61,7 @@ public interface ICursorActionTarget public class MapView : XNAControl, ICursorActionTarget, IMutationTarget { private const float RightClickScrollRateDivisor = 64f; + private const float DragScrollRateDivisor = 16f; public MapView(WindowManager windowManager, Map map, TheaterGraphics theaterGraphics, EditorState editorState, MutationManager mutationManager, WindowController windowController) : base(windowManager) @@ -134,6 +135,10 @@ public CursorAction CursorAction private bool isRightClickScrolling = false; private Point rightClickScrollInitPos = new Point(-1, -1); + private bool isDragScrolling = false; + private Point dragScrollInitPos = new Point(-1, -1); + private Vector2 dragScrollInitCameraPos = new Vector2(-1, -1); + private MapWideOverlay mapWideOverlay; private Point lastClickedPoint; @@ -929,10 +934,13 @@ private void DrawRangeIndicator(Point2D cellCoords, double range, Color color) public override void OnMouseScrolled() { - if (Cursor.ScrollWheelValue > 0) - Camera.ZoomLevel += 0.1; - else - Camera.ZoomLevel -= 0.1; + if (!isDragScrolling) + { + if (Cursor.ScrollWheelValue > 0) + Camera.ZoomLevel += 0.1; + else + Camera.ZoomLevel -= 0.1; + } base.OnMouseScrolled(); } @@ -1033,13 +1041,35 @@ public override void OnMouseMove() // Right-click scrolling if (Cursor.RightDown) { - if (!isRightClickScrolling) + if (!isRightClickScrolling && !isDragScrolling) { isRightClickScrolling = true; rightClickScrollInitPos = GetCursorPoint(); Camera.FloatTopLeftPoint = Camera.TopLeftPoint.ToXNAVector(); } } + + // Drag scrolling + if (Cursor.MiddleDown) + { + if (!isRightClickScrolling) + { + if (!isDragScrolling) + { + dragScrollInitPos = GetCursorPoint(); + dragScrollInitCameraPos = Camera.FloatTopLeftPoint; + isDragScrolling = true; + } + else + { + var result = dragScrollInitPos - GetCursorPoint(); + float dragScrollRate = (float)((scrollRate / DragScrollRateDivisor) / Camera.ZoomLevel); + + Camera.FloatTopLeftPoint = new Vector2(dragScrollInitCameraPos.X + result.X * dragScrollRate, + dragScrollInitCameraPos.Y + result.Y * dragScrollRate); + } + } + } } public override void OnLeftClick() @@ -1092,6 +1122,13 @@ public override void OnRightClick() base.OnRightClick(); } + public override void OnMiddleClick() + { + isDragScrolling = false; + + base.OnMiddleClick(); + } + public override void Update(GameTime gameTime) { // Make scroll rate independent of FPS