starting draw mode with right-click now also snaps to the grid or geometry (unless shift or control is used)

This commit is contained in:
codeimp 2008-12-16 15:10:40 +00:00
parent 43754e3671
commit 94d538434c
4 changed files with 28 additions and 14 deletions

View file

@ -203,9 +203,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Done // Done
renderer.Present(); renderer.Present();
} }
// This gets the aligned and snapped draw position // This returns the aligned and snapped draw position
private DrawnVertex GetCurrentPosition() public static DrawnVertex GetCurrentPosition(Vector2D mousemappos, bool snaptonearest, bool snaptogrid, IRenderer2D renderer, List<DrawnVertex> points)
{ {
DrawnVertex p = new DrawnVertex(); DrawnVertex p = new DrawnVertex();
@ -213,7 +213,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
if(snaptonearest) if(snaptonearest)
{ {
float vrange = VerticesMode.VERTEX_HIGHLIGHT_RANGE / renderer.Scale; float vrange = VerticesMode.VERTEX_HIGHLIGHT_RANGE / renderer.Scale;
// Go for all drawn points // Go for all drawn points
foreach(DrawnVertex v in points) foreach(DrawnVertex v in points)
{ {
@ -224,7 +224,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
return p; return p;
} }
} }
// Try the nearest vertex // Try the nearest vertex
Vertex nv = General.Map.Map.NearestVertexSquareRange(mousemappos, vrange); Vertex nv = General.Map.Map.NearestVertexSquareRange(mousemappos, vrange);
if(nv != null) if(nv != null)
@ -271,7 +271,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
} }
} }
} }
// Snap to grid? // Snap to grid?
if(snaptogrid) if(snaptogrid)
{ {
@ -288,7 +288,13 @@ namespace CodeImp.DoomBuilder.BuilderModes
return p; 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 // This draws a point at a specific location
public void DrawPointAt(Vector2D pos, bool stitch) public void DrawPointAt(Vector2D pos, bool stitch)
{ {
@ -435,7 +441,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
DrawPointAt(newpoint.pos, newpoint.stitch); DrawPointAt(newpoint.pos, newpoint.stitch);
} }
} }
// Remove a point // Remove a point
[BeginAction("removepoint")] [BeginAction("removepoint")]
public void RemovePoint() public void RemovePoint()
@ -449,7 +455,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
Update(); Update();
} }
// Finish drawing // Finish drawing
[BeginAction("finishdraw")] [BeginAction("finishdraw")]
public void FinishDraw() public void FinishDraw()
@ -457,7 +463,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Accept the changes // Accept the changes
General.Editing.AcceptMode(); General.Editing.AcceptMode();
} }
#endregion #endregion
} }
} }

View file

@ -342,8 +342,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
{ {
// Start drawing mode // Start drawing mode
DrawGeometryMode drawmode = new DrawGeometryMode(); DrawGeometryMode drawmode = new DrawGeometryMode();
drawmode.DrawPointAt(mousemappos, true); bool snaptogrid = General.Interface.ShiftState ^ General.Interface.SnapToGrid;
General.Editing.ChangeMode(drawmode); bool snaptonearest = General.Interface.CtrlState ^ General.Interface.AutoMerge;
DrawnVertex v = DrawGeometryMode.GetCurrentPosition(mousemappos, snaptonearest, snaptogrid, renderer, new List<DrawnVertex>());
drawmode.DrawPointAt(v.pos, v.stitch);
} }
base.OnEditBegin(); base.OnEditBegin();

View file

@ -428,7 +428,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
{ {
// Start drawing mode // Start drawing mode
DrawGeometryMode drawmode = new DrawGeometryMode(); 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<DrawnVertex>());
drawmode.DrawPointAt(v.pos, v.stitch);
General.Editing.ChangeMode(drawmode); General.Editing.ChangeMode(drawmode);
} }

View file

@ -274,7 +274,10 @@ namespace CodeImp.DoomBuilder.BuilderModes
{ {
// Start drawing mode // Start drawing mode
DrawGeometryMode drawmode = new DrawGeometryMode(); 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<DrawnVertex>());
drawmode.DrawPointAt(v.pos, v.stitch);
General.Editing.ChangeMode(drawmode); General.Editing.ChangeMode(drawmode);
} }
} }