From 7426b77dc4a4fc10ea56c3f4c8ac7f935127bd6d Mon Sep 17 00:00:00 2001 From: veilofsorrow Date: Tue, 28 Oct 2008 12:04:28 +0000 Subject: [PATCH] added view panning control --- Source/Editing/ClassicMode.cs | 48 +++++++++++++++++++++++++++++++++++ Source/Resources/Actions.cfg | 10 ++++++++ 2 files changed, 58 insertions(+) diff --git a/Source/Editing/ClassicMode.cs b/Source/Editing/ClassicMode.cs index 4d542c1f..fa430aec 100644 --- a/Source/Editing/ClassicMode.cs +++ b/Source/Editing/ClassicMode.cs @@ -61,6 +61,7 @@ namespace CodeImp.DoomBuilder.Editing // Mouse status protected Vector2D mousepos; + protected Vector2D mouselastpos; protected Vector2D mousemappos; protected Vector2D mousedownpos; protected Vector2D mousedownmappos; @@ -72,6 +73,9 @@ namespace CodeImp.DoomBuilder.Editing protected bool selecting; private Vector2D selectstart; protected RectangleF selectionrect; + + // View panning + protected bool panning; #endregion @@ -186,6 +190,21 @@ namespace CodeImp.DoomBuilder.Editing General.MainWindow.UpdateCoordinates(mousemappos); } + // This sets the view to be centered at x,y + private void ScrollTo(float x, float y) + { + // Scroll now + renderer2d.PositionView(x, y); + this.OnViewChanged(); + + // Redraw + General.MainWindow.RedrawDisplay(); + + // Determine new unprojected mouse coordinates + mousemappos = renderer2d.GetMapCoordinates(mousepos); + General.MainWindow.UpdateCoordinates(mousemappos); + } + // This zooms private void ZoomBy(float deltaz) { @@ -327,6 +346,7 @@ namespace CodeImp.DoomBuilder.Editing // Record last position mouseinside = true; + mouselastpos = mousepos; mousepos = new Vector2D(e.X, e.Y); mousemappos = renderer2d.GetMapCoordinates(mousepos); mousebuttons = e.Button; @@ -354,6 +374,9 @@ namespace CodeImp.DoomBuilder.Editing // Selecting? if(selecting) OnUpdateMultiSelection(); + + // Panning? + if (panning) OnUpdateViewPanning(); // Let the base class know base.OnMouseMove(e); @@ -520,11 +543,36 @@ namespace CodeImp.DoomBuilder.Editing renderer.RenderRectangle(selectionrect, SELECTION_BORDER_SIZE, General.Colors.Highlight.WithAlpha(SELECTION_ALPHA), true); } + + /// + /// This is called automatically when the mouse is moved while panning + /// + protected virtual void OnUpdateViewPanning() + { + // Get the map coordinates of the last mouse posision (before it moved) + Vector2D lastmappos; + lastmappos = renderer2d.GetMapCoordinates(mouselastpos); + + // Do the scroll + ScrollBy(lastmappos.x - mousemappos.x, lastmappos.y - mousemappos.y); + } #endregion #region ================== Actions + [BeginAction("pan_view", BaseAction = true)] + protected virtual void BeginViewPan() + { + panning = true; + } + + [EndAction("pan_view", BaseAction = true)] + protected virtual void EndViewPan() + { + panning = false; + } + #endregion } } diff --git a/Source/Resources/Actions.cfg b/Source/Resources/Actions.cfg index 4d22909f..f238b0e5 100644 --- a/Source/Resources/Actions.cfg +++ b/Source/Resources/Actions.cfg @@ -228,6 +228,16 @@ scrollsouth repeat = true; } +pan_view +{ + title = "Pan View"; + category = "classic"; + description = "Pans the map in the direction of the mouse while held down."; + allowkeys = true; + allowmouse = true; + allowscroll = false; +} + zoomin { title = "Zoom In";