From 94d538434c3cb1f8dec9223ef32137c7dc0ef504 Mon Sep 17 00:00:00 2001 From: codeimp Date: Tue, 16 Dec 2008 15:10:40 +0000 Subject: [PATCH] starting draw mode with right-click now also snaps to the grid or geometry (unless shift or control is used) --- .../ClassicModes/DrawGeometryMode.cs | 26 ++++++++++++------- .../BuilderModes/ClassicModes/LinedefsMode.cs | 6 +++-- .../BuilderModes/ClassicModes/SectorsMode.cs | 5 +++- .../BuilderModes/ClassicModes/VerticesMode.cs | 5 +++- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs b/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs index 1ac30b1a..13400ff6 100644 --- a/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs +++ b/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs @@ -203,9 +203,9 @@ namespace CodeImp.DoomBuilder.BuilderModes // Done renderer.Present(); } - - // This gets the aligned and snapped draw position - private DrawnVertex GetCurrentPosition() + + // This returns the aligned and snapped draw position + public static DrawnVertex GetCurrentPosition(Vector2D mousemappos, bool snaptonearest, bool snaptogrid, IRenderer2D renderer, List points) { DrawnVertex p = new DrawnVertex(); @@ -213,7 +213,7 @@ namespace CodeImp.DoomBuilder.BuilderModes if(snaptonearest) { float vrange = VerticesMode.VERTEX_HIGHLIGHT_RANGE / renderer.Scale; - + // Go for all drawn points foreach(DrawnVertex v in points) { @@ -224,7 +224,7 @@ namespace CodeImp.DoomBuilder.BuilderModes return p; } } - + // Try the nearest vertex Vertex nv = General.Map.Map.NearestVertexSquareRange(mousemappos, vrange); if(nv != null) @@ -271,7 +271,7 @@ namespace CodeImp.DoomBuilder.BuilderModes } } } - + // Snap to grid? if(snaptogrid) { @@ -288,7 +288,13 @@ namespace CodeImp.DoomBuilder.BuilderModes return p; } } - + + // This gets the aligned and snapped draw position + private DrawnVertex GetCurrentPosition() + { + return GetCurrentPosition(mousemappos, snaptonearest, snaptogrid, renderer, points); + } + // This draws a point at a specific location public void DrawPointAt(Vector2D pos, bool stitch) { @@ -435,7 +441,7 @@ namespace CodeImp.DoomBuilder.BuilderModes DrawPointAt(newpoint.pos, newpoint.stitch); } } - + // Remove a point [BeginAction("removepoint")] public void RemovePoint() @@ -449,7 +455,7 @@ namespace CodeImp.DoomBuilder.BuilderModes Update(); } - + // Finish drawing [BeginAction("finishdraw")] public void FinishDraw() @@ -457,7 +463,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Accept the changes General.Editing.AcceptMode(); } - + #endregion } } diff --git a/Source/BuilderModes/ClassicModes/LinedefsMode.cs b/Source/BuilderModes/ClassicModes/LinedefsMode.cs index 75e717d5..e9332503 100644 --- a/Source/BuilderModes/ClassicModes/LinedefsMode.cs +++ b/Source/BuilderModes/ClassicModes/LinedefsMode.cs @@ -342,8 +342,10 @@ namespace CodeImp.DoomBuilder.BuilderModes { // Start drawing mode DrawGeometryMode drawmode = new DrawGeometryMode(); - drawmode.DrawPointAt(mousemappos, true); - General.Editing.ChangeMode(drawmode); + bool snaptogrid = General.Interface.ShiftState ^ General.Interface.SnapToGrid; + bool snaptonearest = General.Interface.CtrlState ^ General.Interface.AutoMerge; + DrawnVertex v = DrawGeometryMode.GetCurrentPosition(mousemappos, snaptonearest, snaptogrid, renderer, new List()); + drawmode.DrawPointAt(v.pos, v.stitch); } base.OnEditBegin(); diff --git a/Source/BuilderModes/ClassicModes/SectorsMode.cs b/Source/BuilderModes/ClassicModes/SectorsMode.cs index 00d60b6d..e69f7e22 100644 --- a/Source/BuilderModes/ClassicModes/SectorsMode.cs +++ b/Source/BuilderModes/ClassicModes/SectorsMode.cs @@ -428,7 +428,10 @@ namespace CodeImp.DoomBuilder.BuilderModes { // Start drawing mode DrawGeometryMode drawmode = new DrawGeometryMode(); - drawmode.DrawPointAt(mousemappos, true); + bool snaptogrid = General.Interface.ShiftState ^ General.Interface.SnapToGrid; + bool snaptonearest = General.Interface.CtrlState ^ General.Interface.AutoMerge; + DrawnVertex v = DrawGeometryMode.GetCurrentPosition(mousemappos, snaptonearest, snaptogrid, renderer, new List()); + drawmode.DrawPointAt(v.pos, v.stitch); General.Editing.ChangeMode(drawmode); } diff --git a/Source/BuilderModes/ClassicModes/VerticesMode.cs b/Source/BuilderModes/ClassicModes/VerticesMode.cs index 86e59744..fd1a8fb9 100644 --- a/Source/BuilderModes/ClassicModes/VerticesMode.cs +++ b/Source/BuilderModes/ClassicModes/VerticesMode.cs @@ -274,7 +274,10 @@ namespace CodeImp.DoomBuilder.BuilderModes { // Start drawing mode DrawGeometryMode drawmode = new DrawGeometryMode(); - drawmode.DrawPointAt(mousemappos, true); + bool snaptogrid = General.Interface.ShiftState ^ General.Interface.SnapToGrid; + bool snaptonearest = General.Interface.CtrlState ^ General.Interface.AutoMerge; + DrawnVertex v = DrawGeometryMode.GetCurrentPosition(mousemappos, snaptonearest, snaptogrid, renderer, new List()); + drawmode.DrawPointAt(v.pos, v.stitch); General.Editing.ChangeMode(drawmode); } }