From 943a9f9f856d508bdbe3799f503ac2ebb2e85356 Mon Sep 17 00:00:00 2001 From: codeimp Date: Mon, 26 Jan 2009 15:20:04 +0000 Subject: [PATCH] added automatic zoom in on selected object in Map Analysis mode --- .../BuilderModes/ErrorChecks/ErrorResult.cs | 71 +++++++++++++++++++ .../ErrorChecks/ResultLineMissingFront.cs | 1 + .../ErrorChecks/ResultLineMissingSides.cs | 1 + .../ErrorChecks/ResultLineNotDoubleSided.cs | 1 + .../ErrorChecks/ResultLineNotSingleSided.cs | 1 + .../ErrorChecks/ResultLineOverlapping.cs | 2 + .../ErrorChecks/ResultStuckedThing.cs | 1 + .../ErrorChecks/ResultThingOutside.cs | 1 + .../FindReplace/FindReplaceObject.cs | 8 +-- .../FindReplace/FindReplaceType.cs | 2 +- .../BuilderModes/Interface/ErrorCheckForm.cs | 1 + 11 files changed, 85 insertions(+), 5 deletions(-) diff --git a/Source/BuilderModes/ErrorChecks/ErrorResult.cs b/Source/BuilderModes/ErrorChecks/ErrorResult.cs index a2500e7f..825ddd77 100644 --- a/Source/BuilderModes/ErrorChecks/ErrorResult.cs +++ b/Source/BuilderModes/ErrorChecks/ErrorResult.cs @@ -33,6 +33,7 @@ using CodeImp.DoomBuilder.Editing; using CodeImp.DoomBuilder.Actions; using CodeImp.DoomBuilder.Types; using CodeImp.DoomBuilder.Config; +using System.Drawing; #endregion @@ -43,6 +44,7 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Variables protected string description; + protected List viewobjects; #endregion @@ -64,6 +66,7 @@ namespace CodeImp.DoomBuilder.BuilderModes public ErrorResult() { // Initialize + viewobjects = new List(1); } #endregion @@ -112,6 +115,74 @@ namespace CodeImp.DoomBuilder.BuilderModes { } + // Call this to zoom in on the given selection + public void ZoomToObject() + { + List points = new List(); + RectangleF area = MapSet.CreateEmptyArea(); + + // Add all points to a list + foreach(MapElement obj in viewobjects) + { + if(obj is Vertex) + { + points.Add((obj as Vertex).Position); + } + else if(obj is Linedef) + { + points.Add((obj as Linedef).Start.Position); + points.Add((obj as Linedef).End.Position); + } + else if(obj is Sector) + { + Sector s = (obj as Sector); + foreach(Sidedef sd in s.Sidedefs) + { + points.Add(sd.Line.Start.Position); + points.Add(sd.Line.End.Position); + } + } + else if(obj is Thing) + { + Thing t = (obj as Thing); + Vector2D p = (Vector2D)t.Position; + points.Add(p); + points.Add(p + new Vector2D(t.Size * 2.0f, t.Size * 2.0f)); + points.Add(p + new Vector2D(t.Size * 2.0f, -t.Size * 2.0f)); + points.Add(p + new Vector2D(-t.Size * 2.0f, t.Size * 2.0f)); + points.Add(p + new Vector2D(-t.Size * 2.0f, -t.Size * 2.0f)); + } + else + { + General.Fail("Unknown object given to zoom in on."); + } + } + + // Make a view area from the points + foreach(Vector2D p in points) area = MapSet.IncreaseArea(area, p); + + // Make the area square, using the largest side + if(area.Width > area.Height) + { + float delta = area.Width - area.Height; + area.Y -= delta * 0.5f; + area.Height += delta; + } + else + { + float delta = area.Height - area.Width; + area.X -= delta * 0.5f; + area.Width += delta; + } + + // Add padding + area.Inflate(100f, 100f); + + // Zoom to area + ClassicMode editmode = (General.Editing.Mode as ClassicMode); + editmode.CenterOnArea(area, 0.6f); + } + #endregion } } diff --git a/Source/BuilderModes/ErrorChecks/ResultLineMissingFront.cs b/Source/BuilderModes/ErrorChecks/ResultLineMissingFront.cs index 492cf5e9..e6ccb2de 100644 --- a/Source/BuilderModes/ErrorChecks/ResultLineMissingFront.cs +++ b/Source/BuilderModes/ErrorChecks/ResultLineMissingFront.cs @@ -63,6 +63,7 @@ namespace CodeImp.DoomBuilder.BuilderModes { // Initialize this.line = l; + this.viewobjects.Add(l); this.description = "This linedef has a back sidedef, but is missing a front sidedef. " + "A line must have at least a front side and optionally a back side! " + "Click Flip Linedef if the line is supposed to be single-sided."; diff --git a/Source/BuilderModes/ErrorChecks/ResultLineMissingSides.cs b/Source/BuilderModes/ErrorChecks/ResultLineMissingSides.cs index b07e63f2..23031ec2 100644 --- a/Source/BuilderModes/ErrorChecks/ResultLineMissingSides.cs +++ b/Source/BuilderModes/ErrorChecks/ResultLineMissingSides.cs @@ -67,6 +67,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Initialize this.line = l; + this.viewobjects.Add(l); this.description = "This linedef is missing front and back sidedefs." + "A line must have at least a front side and optionally a back side!"; diff --git a/Source/BuilderModes/ErrorChecks/ResultLineNotDoubleSided.cs b/Source/BuilderModes/ErrorChecks/ResultLineNotDoubleSided.cs index 46095141..ebe3d8be 100644 --- a/Source/BuilderModes/ErrorChecks/ResultLineNotDoubleSided.cs +++ b/Source/BuilderModes/ErrorChecks/ResultLineNotDoubleSided.cs @@ -63,6 +63,7 @@ namespace CodeImp.DoomBuilder.BuilderModes { // Initialize this.line = l; + this.viewobjects.Add(l); this.description = "This linedef is marked as double-sided, but is missing the back sidedef. Click Make Single-Sided to remove the double-sided flag from the line."; // One solution is to remove the double-sided flag diff --git a/Source/BuilderModes/ErrorChecks/ResultLineNotSingleSided.cs b/Source/BuilderModes/ErrorChecks/ResultLineNotSingleSided.cs index 0163d1ce..5bbe5f88 100644 --- a/Source/BuilderModes/ErrorChecks/ResultLineNotSingleSided.cs +++ b/Source/BuilderModes/ErrorChecks/ResultLineNotSingleSided.cs @@ -61,6 +61,7 @@ namespace CodeImp.DoomBuilder.BuilderModes { // Initialize this.line = l; + this.viewobjects.Add(l); this.description = "This linedef is marked as single-sided, but has both a front and a back sidedef. Click Make Double-Sided to flag the line as double-sided." + " Or click Remove Sidedef to remove the sidedef on the back side (making the line really single-sided)."; } diff --git a/Source/BuilderModes/ErrorChecks/ResultLineOverlapping.cs b/Source/BuilderModes/ErrorChecks/ResultLineOverlapping.cs index 5b1e3b07..877e3fac 100644 --- a/Source/BuilderModes/ErrorChecks/ResultLineOverlapping.cs +++ b/Source/BuilderModes/ErrorChecks/ResultLineOverlapping.cs @@ -61,6 +61,8 @@ namespace CodeImp.DoomBuilder.BuilderModes // Initialize this.line1 = l1; this.line2 = l2; + this.viewobjects.Add(l1); + this.viewobjects.Add(l2); this.description = "These linedefs are overlapping and they do not reference the same sector on all sides. Overlapping lines is only allowed when they reference the same sector on all sides."; } diff --git a/Source/BuilderModes/ErrorChecks/ResultStuckedThing.cs b/Source/BuilderModes/ErrorChecks/ResultStuckedThing.cs index 92c70809..8810391f 100644 --- a/Source/BuilderModes/ErrorChecks/ResultStuckedThing.cs +++ b/Source/BuilderModes/ErrorChecks/ResultStuckedThing.cs @@ -60,6 +60,7 @@ namespace CodeImp.DoomBuilder.BuilderModes { // Initialize this.thing = t; + this.viewobjects.Add(t); this.description = "This thing is stucked in a wall (single-sided line) and will likely not be able to move around."; } diff --git a/Source/BuilderModes/ErrorChecks/ResultThingOutside.cs b/Source/BuilderModes/ErrorChecks/ResultThingOutside.cs index 3694446f..9f556d49 100644 --- a/Source/BuilderModes/ErrorChecks/ResultThingOutside.cs +++ b/Source/BuilderModes/ErrorChecks/ResultThingOutside.cs @@ -60,6 +60,7 @@ namespace CodeImp.DoomBuilder.BuilderModes { // Initialize this.thing = t; + this.viewobjects.Add(t); this.description = "This thing is completely outside the map."; } diff --git a/Source/BuilderModes/FindReplace/FindReplaceObject.cs b/Source/BuilderModes/FindReplace/FindReplaceObject.cs index 7b700fff..00c94ec1 100644 --- a/Source/BuilderModes/FindReplace/FindReplaceObject.cs +++ b/Source/BuilderModes/FindReplace/FindReplaceObject.cs @@ -101,10 +101,10 @@ namespace CodeImp.DoomBuilder.BuilderModes Thing t = (obj as Thing); Vector2D p = (Vector2D)t.Position; points.Add(p); - points.Add(p + new Vector2D(t.Size, t.Size)); - points.Add(p + new Vector2D(t.Size, -t.Size)); - points.Add(p + new Vector2D(-t.Size, t.Size)); - points.Add(p + new Vector2D(-t.Size, -t.Size)); + points.Add(p + new Vector2D(t.Size * 2.0f, t.Size * 2.0f)); + points.Add(p + new Vector2D(t.Size * 2.0f, -t.Size * 2.0f)); + points.Add(p + new Vector2D(-t.Size * 2.0f, t.Size * 2.0f)); + points.Add(p + new Vector2D(-t.Size * 2.0f, -t.Size * 2.0f)); } } diff --git a/Source/BuilderModes/FindReplace/FindReplaceType.cs b/Source/BuilderModes/FindReplace/FindReplaceType.cs index 6bbd2e04..54e6b1ec 100644 --- a/Source/BuilderModes/FindReplace/FindReplaceType.cs +++ b/Source/BuilderModes/FindReplace/FindReplaceType.cs @@ -155,7 +155,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Zoom to area ClassicMode editmode = (General.Editing.Mode as ClassicMode); - editmode.CenterOnArea(area, 1f); + editmode.CenterOnArea(area, 0.6f); } #endregion diff --git a/Source/BuilderModes/Interface/ErrorCheckForm.cs b/Source/BuilderModes/Interface/ErrorCheckForm.cs index 65eea652..079808df 100644 --- a/Source/BuilderModes/Interface/ErrorCheckForm.cs +++ b/Source/BuilderModes/Interface/ErrorCheckForm.cs @@ -375,6 +375,7 @@ namespace CodeImp.DoomBuilder.BuilderModes fix1.Visible = (r.Buttons >= 1); fix2.Visible = (r.Buttons >= 2); fix3.Visible = (r.Buttons >= 3); + r.ZoomToObject(); } else {