2008-04-20 22:54:24 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
2008-02-24 21:52:18 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
2008-04-20 22:54:24 +00:00
|
|
|
using System.Windows.Forms;
|
|
|
|
using System.IO;
|
|
|
|
using System.Reflection;
|
|
|
|
using CodeImp.DoomBuilder.Interface;
|
|
|
|
using CodeImp.DoomBuilder.IO;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
using System.Drawing;
|
|
|
|
using CodeImp.DoomBuilder.Editing;
|
2008-04-27 12:07:26 +00:00
|
|
|
using CodeImp.DoomBuilder.Controls;
|
2008-04-20 22:54:24 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2008-05-14 21:48:36 +00:00
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
2008-02-24 21:52:18 +00:00
|
|
|
{
|
2008-05-08 16:39:14 +00:00
|
|
|
[EditMode(SwitchAction = "drawlinesmode", Volatile = true)]
|
2008-04-20 22:54:24 +00:00
|
|
|
|
|
|
|
public class DrawGeometryMode : ClassicMode
|
2008-02-24 21:52:18 +00:00
|
|
|
{
|
2008-04-29 14:41:16 +00:00
|
|
|
#region ================== Structures
|
|
|
|
|
|
|
|
private struct DrawnVertex
|
|
|
|
{
|
|
|
|
public Vector2D pos;
|
|
|
|
public bool stitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2008-02-24 21:52:18 +00:00
|
|
|
#region ================== Constants
|
|
|
|
|
2008-04-29 20:59:59 +00:00
|
|
|
private const float LINE_THICKNESS = 0.8f;
|
2008-04-27 12:07:26 +00:00
|
|
|
|
2008-02-24 21:52:18 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
2008-04-20 22:54:24 +00:00
|
|
|
// Mode to return to
|
|
|
|
private EditMode basemode;
|
2008-02-24 21:52:18 +00:00
|
|
|
|
2008-04-20 22:54:24 +00:00
|
|
|
// Drawing points
|
2008-04-29 14:41:16 +00:00
|
|
|
private List<DrawnVertex> points;
|
2008-05-13 17:11:33 +00:00
|
|
|
private List<LineLengthLabel> labels;
|
2008-04-20 22:54:24 +00:00
|
|
|
|
|
|
|
// Keep track of view changes
|
|
|
|
private float lastoffsetx;
|
|
|
|
private float lastoffsety;
|
|
|
|
private float lastscale;
|
|
|
|
|
|
|
|
// Options
|
|
|
|
private bool snaptogrid; // SHIFT to toggle
|
|
|
|
private bool snaptonearest; // CTRL to enable
|
|
|
|
|
2008-02-24 21:52:18 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
2008-04-20 22:54:24 +00:00
|
|
|
// Just keep the base mode button checked
|
|
|
|
public override string EditModeButtonName { get { return basemode.GetType().Name; } }
|
2008-02-24 21:52:18 +00:00
|
|
|
|
2008-05-14 21:48:36 +00:00
|
|
|
internal EditMode BaseMode { get { return basemode; } }
|
|
|
|
|
2008-02-24 21:52:18 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public DrawGeometryMode()
|
|
|
|
{
|
|
|
|
// Initialize
|
2008-04-20 22:54:24 +00:00
|
|
|
this.basemode = General.Map.Mode;
|
2008-04-29 14:41:16 +00:00
|
|
|
points = new List<DrawnVertex>();
|
2008-05-13 17:11:33 +00:00
|
|
|
labels = new List<LineLengthLabel>();
|
2008-04-20 22:54:24 +00:00
|
|
|
|
2008-05-01 10:59:37 +00:00
|
|
|
// No selection in this mode
|
|
|
|
General.Map.Map.ClearAllSelected();
|
2008-05-01 19:31:49 +00:00
|
|
|
General.Map.Map.ClearAllMarks();
|
2008-05-01 10:59:37 +00:00
|
|
|
|
2008-02-24 21:52:18 +00:00
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
2008-04-20 22:54:24 +00:00
|
|
|
// Disposer
|
|
|
|
public override void Dispose()
|
2008-02-24 21:52:18 +00:00
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
2008-05-13 17:11:33 +00:00
|
|
|
if(labels != null)
|
|
|
|
foreach(LineLengthLabel l in labels) l.Dispose();
|
|
|
|
|
2008-02-24 21:52:18 +00:00
|
|
|
// Done
|
2008-04-20 22:54:24 +00:00
|
|
|
base.Dispose();
|
2008-02-24 21:52:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
2008-05-16 21:48:23 +00:00
|
|
|
// Engaging
|
|
|
|
public override void OnEngage()
|
|
|
|
{
|
|
|
|
base.OnEngage();
|
2008-05-18 07:31:33 +00:00
|
|
|
renderer.SetPresentation(Presentation.Standard);
|
|
|
|
|
2008-05-16 21:48:23 +00:00
|
|
|
// Set cursor
|
|
|
|
General.Interface.SetCursor(Cursors.Cross);
|
|
|
|
}
|
|
|
|
|
2008-04-20 22:54:24 +00:00
|
|
|
// Cancelled
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnCancel()
|
2008-04-20 22:54:24 +00:00
|
|
|
{
|
|
|
|
// Cancel base class
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnCancel();
|
2008-04-20 22:54:24 +00:00
|
|
|
|
|
|
|
// Return to original mode
|
2008-04-27 12:07:26 +00:00
|
|
|
Type t = basemode.GetType();
|
|
|
|
basemode = (EditMode)Activator.CreateInstance(t);
|
2008-04-20 22:54:24 +00:00
|
|
|
General.Map.ChangeMode(basemode);
|
|
|
|
}
|
|
|
|
|
2008-05-16 21:08:36 +00:00
|
|
|
// Accepted
|
|
|
|
public override void OnAccept()
|
2008-04-20 22:54:24 +00:00
|
|
|
{
|
2008-05-01 19:31:49 +00:00
|
|
|
List<Vertex> newverts = new List<Vertex>();
|
2008-05-07 22:46:15 +00:00
|
|
|
List<Vertex> intersectverts = new List<Vertex>();
|
2008-05-01 19:31:49 +00:00
|
|
|
List<Linedef> newlines = new List<Linedef>();
|
2008-05-08 12:04:20 +00:00
|
|
|
List<Linedef> oldlines = new List<Linedef>(General.Map.Map.Linedefs);
|
2008-05-08 13:44:48 +00:00
|
|
|
List<Sidedef> insidesides = new List<Sidedef>();
|
2008-05-01 19:31:49 +00:00
|
|
|
List<Vertex> mergeverts = new List<Vertex>();
|
|
|
|
List<Vertex> nonmergeverts = new List<Vertex>(General.Map.Map.Vertices);
|
2008-05-01 10:59:37 +00:00
|
|
|
MapSet map = General.Map.Map;
|
2008-05-08 13:04:18 +00:00
|
|
|
|
2008-04-20 22:54:24 +00:00
|
|
|
Cursor.Current = Cursors.AppStarting;
|
|
|
|
|
2008-05-08 13:04:18 +00:00
|
|
|
General.Settings.FindDefaultDrawSettings();
|
2008-05-16 21:08:36 +00:00
|
|
|
|
|
|
|
// When points have been drawn
|
|
|
|
if(points.Count > 0)
|
2008-04-20 22:54:24 +00:00
|
|
|
{
|
|
|
|
// Make undo for the draw
|
2008-05-17 06:24:16 +00:00
|
|
|
General.Map.UndoRedo.CreateUndo("Line draw", UndoGroup.None, 0);
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-05 21:38:52 +00:00
|
|
|
/***************************************************\
|
|
|
|
STEP 1: Create the new geometry
|
|
|
|
\***************************************************/
|
2008-05-01 19:31:49 +00:00
|
|
|
|
|
|
|
// Make first vertex
|
2008-05-05 22:01:27 +00:00
|
|
|
Vertex v1 = map.CreateVertex(points[0].pos);
|
2008-05-07 22:46:15 +00:00
|
|
|
v1.Marked = true;
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-01 19:31:49 +00:00
|
|
|
// Keep references
|
2008-05-01 10:59:37 +00:00
|
|
|
newverts.Add(v1);
|
|
|
|
if(points[0].stitch) mergeverts.Add(v1); else nonmergeverts.Add(v1);
|
2008-05-01 19:31:49 +00:00
|
|
|
|
|
|
|
// Go for all other points
|
2008-05-01 10:59:37 +00:00
|
|
|
for(int i = 1; i < points.Count; i++)
|
|
|
|
{
|
2008-05-01 19:31:49 +00:00
|
|
|
// Create vertex for point
|
2008-05-05 22:01:27 +00:00
|
|
|
Vertex v2 = map.CreateVertex(points[i].pos);
|
2008-05-07 22:46:15 +00:00
|
|
|
v2.Marked = true;
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-01 19:31:49 +00:00
|
|
|
// Keep references
|
2008-05-01 10:59:37 +00:00
|
|
|
newverts.Add(v2);
|
|
|
|
if(points[i].stitch) mergeverts.Add(v2); else nonmergeverts.Add(v2);
|
2008-05-01 19:31:49 +00:00
|
|
|
|
|
|
|
// Create line between point and previous
|
2008-05-01 10:59:37 +00:00
|
|
|
Linedef ld = map.CreateLinedef(v1, v2);
|
2008-05-01 19:31:49 +00:00
|
|
|
ld.Marked = true;
|
2008-05-01 10:59:37 +00:00
|
|
|
ld.Selected = true;
|
2008-05-08 05:45:30 +00:00
|
|
|
ld.ApplySidedFlags();
|
2008-05-06 21:31:20 +00:00
|
|
|
ld.UpdateCache();
|
2008-05-08 05:45:30 +00:00
|
|
|
newlines.Add(ld);
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-05 18:21:13 +00:00
|
|
|
// Should we split this line to merge with intersecting lines?
|
2008-05-08 12:04:20 +00:00
|
|
|
if(points[i - 1].stitch && points[i].stitch)
|
2008-05-05 18:21:13 +00:00
|
|
|
{
|
|
|
|
// Check if any other lines intersect this line
|
|
|
|
List<float> intersections = new List<float>();
|
2008-05-07 22:46:15 +00:00
|
|
|
Line2D measureline = ld.Line;
|
2008-05-05 18:21:13 +00:00
|
|
|
foreach(Linedef ld2 in map.Linedefs)
|
|
|
|
{
|
2008-05-07 22:46:15 +00:00
|
|
|
// Intersecting?
|
|
|
|
// We only keep the unit length from the start of the line and
|
|
|
|
// do the real splitting later, when all intersections are known
|
|
|
|
float u;
|
|
|
|
if(ld2.Line.GetIntersection(measureline, out u))
|
2008-05-05 18:21:13 +00:00
|
|
|
{
|
2008-05-07 22:46:15 +00:00
|
|
|
if(!float.IsNaN(u) && (u > 0.0f) && (u < 1.0f) && (ld2 != ld))
|
|
|
|
intersections.Add(u);
|
2008-05-05 18:21:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the intersections
|
|
|
|
intersections.Sort();
|
|
|
|
|
|
|
|
// Go for all found intersections
|
|
|
|
Linedef splitline = ld;
|
|
|
|
foreach(float u in intersections)
|
|
|
|
{
|
|
|
|
// Calculate exact coordinates where to split
|
|
|
|
// We use measureline for this, because the original line
|
|
|
|
// may already have changed in length due to a previous split
|
|
|
|
Vector2D splitpoint = measureline.GetCoordinatesAt(u);
|
|
|
|
|
|
|
|
// Make the vertex
|
2008-05-05 22:01:27 +00:00
|
|
|
Vertex splitvertex = map.CreateVertex(splitpoint);
|
2008-05-07 22:46:15 +00:00
|
|
|
splitvertex.Marked = true;
|
|
|
|
newverts.Add(splitvertex);
|
|
|
|
mergeverts.Add(splitvertex); // <-- add to merge?
|
|
|
|
intersectverts.Add(splitvertex);
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-05 18:21:13 +00:00
|
|
|
// The Split method ties the end of the original line to the given
|
|
|
|
// vertex and starts a new line at the given vertex, so continue
|
|
|
|
// splitting with the new line, because the intersections are sorted
|
|
|
|
// from low to high (beginning at the original line start)
|
|
|
|
splitline = splitline.Split(splitvertex);
|
2008-05-08 05:45:30 +00:00
|
|
|
splitline.ApplySidedFlags();
|
2008-05-05 18:21:13 +00:00
|
|
|
newlines.Add(splitline);
|
|
|
|
}
|
|
|
|
}
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-01 19:31:49 +00:00
|
|
|
// Next
|
2008-05-01 10:59:37 +00:00
|
|
|
v1 = v2;
|
|
|
|
}
|
2008-05-05 18:21:13 +00:00
|
|
|
|
2008-05-07 22:46:15 +00:00
|
|
|
// Join merge vertices so that overlapping vertices in the draw become one.
|
|
|
|
MapSet.JoinVertices(mergeverts, mergeverts, false, MapSet.STITCH_DISTANCE);
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-08 12:04:20 +00:00
|
|
|
// We prefer a closed polygon, because then we can determine the interior properly
|
|
|
|
// Check if the two ends of the polygon are closed
|
|
|
|
bool drawingclosed = false;
|
|
|
|
if(newlines.Count > 0)
|
|
|
|
{
|
|
|
|
// When not closed, we will try to find a path to close it
|
|
|
|
Linedef firstline = newlines[0];
|
|
|
|
Linedef lastline = newlines[newlines.Count - 1];
|
|
|
|
drawingclosed = (firstline.Start == lastline.End);
|
|
|
|
if(!drawingclosed)
|
|
|
|
{
|
|
|
|
// First and last vertex stitch with geometry?
|
|
|
|
if(points[0].stitch && points[points.Count - 1].stitch)
|
|
|
|
{
|
|
|
|
// Find out where they will stitch
|
|
|
|
Linedef l1 = MapSet.NearestLinedefRange(oldlines, firstline.Start.Position, MapSet.STITCH_DISTANCE);
|
|
|
|
Linedef l2 = MapSet.NearestLinedefRange(oldlines, lastline.End.Position, MapSet.STITCH_DISTANCE);
|
|
|
|
if((l1 != null) && (l2 != null))
|
|
|
|
{
|
|
|
|
List<LinedefSide> shortestpath = null;
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-08 12:04:20 +00:00
|
|
|
// Same line?
|
|
|
|
if(l1 == l2)
|
|
|
|
{
|
|
|
|
// Then just connect the two
|
|
|
|
shortestpath = new List<LinedefSide>();
|
|
|
|
shortestpath.Add(new LinedefSide(l1, true));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Find the shortest, closest path between these lines
|
|
|
|
List<List<LinedefSide>> paths = new List<List<LinedefSide>>(8);
|
|
|
|
paths.Add(SectorTools.FindClosestPath(l1, true, l2, true, true));
|
|
|
|
paths.Add(SectorTools.FindClosestPath(l1, true, l2, false, true));
|
|
|
|
paths.Add(SectorTools.FindClosestPath(l1, false, l2, true, true));
|
|
|
|
paths.Add(SectorTools.FindClosestPath(l1, false, l2, false, true));
|
|
|
|
paths.Add(SectorTools.FindClosestPath(l2, true, l1, true, true));
|
|
|
|
paths.Add(SectorTools.FindClosestPath(l2, true, l1, false, true));
|
|
|
|
paths.Add(SectorTools.FindClosestPath(l2, false, l1, true, true));
|
|
|
|
paths.Add(SectorTools.FindClosestPath(l2, false, l1, false, true));
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-08 12:04:20 +00:00
|
|
|
foreach(List<LinedefSide> p in paths)
|
|
|
|
if((p != null) && ((shortestpath == null) || (p.Count < shortestpath.Count))) shortestpath = p;
|
|
|
|
}
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-08 12:04:20 +00:00
|
|
|
// Found a path?
|
|
|
|
if(shortestpath != null)
|
|
|
|
{
|
2008-05-18 18:32:56 +00:00
|
|
|
// Check which direction the path goes in
|
|
|
|
if(shortestpath[0].Line == l1)
|
|
|
|
{
|
|
|
|
// Begin at start
|
|
|
|
v1 = firstline.Start;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Begin at end
|
|
|
|
v1 = lastline.End;
|
|
|
|
}
|
|
|
|
|
2008-05-08 12:04:20 +00:00
|
|
|
// Go for all vertices in the path to make additional lines
|
|
|
|
for(int i = 1; i < shortestpath.Count; i++)
|
|
|
|
{
|
|
|
|
// Get the next position
|
|
|
|
Vector2D v2pos = shortestpath[i].Front ? shortestpath[i].Line.Start.Position : shortestpath[i].Line.End.Position;
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-08 12:04:20 +00:00
|
|
|
// Make the new vertex
|
|
|
|
Vertex v2 = map.CreateVertex(v2pos);
|
|
|
|
v2.Marked = true;
|
|
|
|
mergeverts.Add(v2);
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-08 12:04:20 +00:00
|
|
|
// Make the line
|
|
|
|
Linedef ld = map.CreateLinedef(v1, v2);
|
|
|
|
ld.Marked = true;
|
|
|
|
ld.Selected = true;
|
|
|
|
ld.ApplySidedFlags();
|
|
|
|
ld.UpdateCache();
|
|
|
|
newlines.Add(ld);
|
|
|
|
|
|
|
|
// Next
|
|
|
|
v1 = v2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make the final line
|
2008-05-18 18:32:56 +00:00
|
|
|
Linedef lld;
|
|
|
|
|
|
|
|
// Check which direction the path goes in
|
|
|
|
if(shortestpath[0].Line == l1)
|
|
|
|
{
|
|
|
|
// Path stops at end
|
|
|
|
lld = map.CreateLinedef(v1, lastline.End);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Path stops at begin
|
|
|
|
lld = map.CreateLinedef(v1, firstline.Start);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup line
|
2008-05-08 12:04:20 +00:00
|
|
|
lld.Marked = true;
|
|
|
|
lld.Selected = true;
|
|
|
|
lld.ApplySidedFlags();
|
|
|
|
lld.UpdateCache();
|
|
|
|
newlines.Add(lld);
|
|
|
|
|
|
|
|
// Drawing is now closed
|
|
|
|
drawingclosed = true;
|
|
|
|
|
|
|
|
// Join merge vertices so that overlapping vertices in the draw become one.
|
|
|
|
MapSet.JoinVertices(mergeverts, mergeverts, false, MapSet.STITCH_DISTANCE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-07 22:46:15 +00:00
|
|
|
// Merge intersetion vertices with the new lines. This completes the
|
|
|
|
// self intersections for which splits were made above.
|
|
|
|
map.Update(true, false);
|
|
|
|
MapSet.SplitLinesByVertices(newlines, intersectverts, MapSet.STITCH_DISTANCE, null);
|
2008-05-08 05:45:30 +00:00
|
|
|
MapSet.SplitLinesByVertices(newlines, mergeverts, MapSet.STITCH_DISTANCE, null);
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-05 21:38:52 +00:00
|
|
|
/***************************************************\
|
|
|
|
STEP 2: Merge the new geometry
|
|
|
|
\***************************************************/
|
|
|
|
|
2008-05-06 21:31:20 +00:00
|
|
|
// In step 3 we will make sectors on the front sides and join sectors on the
|
|
|
|
// back sides, but because the user could have drawn counterclockwise or just
|
|
|
|
// some weird polygon this could result in problems. The following code adjusts
|
|
|
|
// the direction of all new lines so that their front (right) side is facing
|
|
|
|
// the interior of the new drawn polygon.
|
|
|
|
map.Update(true, false);
|
|
|
|
foreach(Linedef ld in newlines)
|
|
|
|
{
|
|
|
|
// Find closest path starting with the front of this linedef
|
2008-05-08 05:45:30 +00:00
|
|
|
List<LinedefSide> pathlines = SectorTools.FindClosestPath(ld, true, true);
|
2008-05-06 21:31:20 +00:00
|
|
|
if(pathlines != null)
|
|
|
|
{
|
|
|
|
// Make polygon
|
|
|
|
LinedefTracePath tracepath = new LinedefTracePath(pathlines);
|
|
|
|
Polygon pathpoly = tracepath.MakePolygon();
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-06 21:31:20 +00:00
|
|
|
// Check if the front of the line is outside the polygon
|
|
|
|
if(!pathpoly.Intersect(ld.GetSidePoint(true)))
|
|
|
|
{
|
2008-05-07 22:46:15 +00:00
|
|
|
// Now trace from the back side of the line to see if
|
|
|
|
// the back side lies in the interior. I don't want to
|
|
|
|
// flip the line if it is not helping.
|
|
|
|
|
|
|
|
// Find closest path starting with the back of this linedef
|
2008-05-08 05:45:30 +00:00
|
|
|
pathlines = SectorTools.FindClosestPath(ld, false, true);
|
2008-05-07 22:46:15 +00:00
|
|
|
if(pathlines != null)
|
|
|
|
{
|
|
|
|
// Make polygon
|
|
|
|
tracepath = new LinedefTracePath(pathlines);
|
|
|
|
pathpoly = tracepath.MakePolygon();
|
|
|
|
|
|
|
|
// Check if the back of the line is inside the polygon
|
|
|
|
if(pathpoly.Intersect(ld.GetSidePoint(false)))
|
|
|
|
{
|
|
|
|
// We must flip this linedef to face the interior
|
|
|
|
ld.FlipVertices();
|
|
|
|
ld.FlipSidedefs();
|
2008-05-08 05:45:30 +00:00
|
|
|
ld.UpdateCache();
|
2008-05-07 22:46:15 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-06 21:31:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-08 22:01:37 +00:00
|
|
|
// Mark only the vertices that should be merged
|
|
|
|
map.ClearMarkedVertices(false);
|
|
|
|
foreach(Vertex v in mergeverts) v.Marked = true;
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-07 22:46:15 +00:00
|
|
|
// Before this point, the new geometry is not linked with the existing geometry.
|
|
|
|
// Now perform standard geometry stitching to merge the new geometry with the rest
|
|
|
|
// of the map. The marked vertices indicate the new geometry.
|
2008-05-01 14:10:38 +00:00
|
|
|
map.StitchGeometry();
|
2008-05-07 22:46:15 +00:00
|
|
|
map.Update(true, false);
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-05 21:38:52 +00:00
|
|
|
// Find our new lines again, because they have been merged with the other geometry
|
2008-05-08 22:01:37 +00:00
|
|
|
// but their Marked property is copied where they have joined.
|
2008-05-05 18:21:13 +00:00
|
|
|
newlines = map.GetMarkedLinedefs(true);
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-05 21:38:52 +00:00
|
|
|
/***************************************************\
|
|
|
|
STEP 3: Join and create new sectors
|
|
|
|
\***************************************************/
|
|
|
|
|
2008-05-08 12:04:20 +00:00
|
|
|
// The code below atempts to create sectors on the front sides of the drawn
|
|
|
|
// geometry and joins sectors on the back sides of the drawn geometry.
|
|
|
|
// This code does not change any geometry, it only makes/updates sidedefs.
|
2008-05-19 06:51:55 +00:00
|
|
|
bool sidescreated = false;
|
2008-05-01 19:31:49 +00:00
|
|
|
bool[] frontsdone = new bool[newlines.Count];
|
2008-05-05 15:35:58 +00:00
|
|
|
bool[] backsdone = new bool[newlines.Count];
|
2008-05-01 19:31:49 +00:00
|
|
|
for(int i = 0; i < newlines.Count; i++)
|
|
|
|
{
|
|
|
|
Linedef ld = newlines[i];
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-01 19:31:49 +00:00
|
|
|
// Front not marked as done?
|
|
|
|
if(!frontsdone[i])
|
|
|
|
{
|
2008-05-05 21:38:52 +00:00
|
|
|
// Find a way to create a sector here
|
|
|
|
List<LinedefSide> sectorlines = SectorTools.FindPotentialSectorAt(ld, true);
|
|
|
|
if(sectorlines != null)
|
2008-05-01 19:31:49 +00:00
|
|
|
{
|
2008-05-19 06:51:55 +00:00
|
|
|
sidescreated = true;
|
|
|
|
|
2008-05-05 21:38:52 +00:00
|
|
|
// Make the new sector
|
|
|
|
Sector newsector = SectorTools.MakeSector(sectorlines);
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-01 19:31:49 +00:00
|
|
|
// Go for all sidedefs in this new sector
|
|
|
|
foreach(Sidedef sd in newsector.Sidedefs)
|
|
|
|
{
|
2008-05-08 13:44:48 +00:00
|
|
|
// Keep list of sides inside created sectors
|
|
|
|
insidesides.Add(sd);
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-01 19:31:49 +00:00
|
|
|
// Side matches with a side of our new lines?
|
|
|
|
int lineindex = newlines.IndexOf(sd.Line);
|
|
|
|
if(lineindex > -1)
|
|
|
|
{
|
|
|
|
// Mark this side as done
|
2008-05-05 15:35:58 +00:00
|
|
|
if(sd.IsFront)
|
|
|
|
frontsdone[lineindex] = true;
|
|
|
|
else
|
|
|
|
backsdone[lineindex] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Back not marked as done?
|
|
|
|
if(!backsdone[i])
|
|
|
|
{
|
2008-05-05 21:38:52 +00:00
|
|
|
// Find a way to create a sector here
|
|
|
|
List<LinedefSide> sectorlines = SectorTools.FindPotentialSectorAt(ld, false);
|
|
|
|
if(sectorlines != null)
|
2008-05-05 15:35:58 +00:00
|
|
|
{
|
2008-05-05 21:38:52 +00:00
|
|
|
// We don't always want to create a new sector on the back sides
|
|
|
|
// So first check if any of the surrounding lines originally have sidedefs
|
|
|
|
Sidedef joinsidedef = null;
|
|
|
|
foreach(LinedefSide ls in sectorlines)
|
2008-05-05 15:35:58 +00:00
|
|
|
{
|
2008-05-05 21:38:52 +00:00
|
|
|
if(ls.Front && (ls.Line.Front != null))
|
2008-05-05 15:35:58 +00:00
|
|
|
{
|
2008-05-05 21:38:52 +00:00
|
|
|
joinsidedef = ls.Line.Front;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(!ls.Front && (ls.Line.Back != null))
|
|
|
|
{
|
|
|
|
joinsidedef = ls.Line.Back;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-05 21:38:52 +00:00
|
|
|
// Join?
|
|
|
|
if(joinsidedef != null)
|
|
|
|
{
|
2008-05-19 06:51:55 +00:00
|
|
|
sidescreated = true;
|
|
|
|
|
2008-05-05 21:38:52 +00:00
|
|
|
// Join the new sector
|
|
|
|
Sector newsector = SectorTools.JoinSector(sectorlines, joinsidedef);
|
|
|
|
|
|
|
|
// Go for all sidedefs in this new sector
|
|
|
|
foreach(Sidedef sd in newsector.Sidedefs)
|
|
|
|
{
|
|
|
|
// Side matches with a side of our new lines?
|
|
|
|
int lineindex = newlines.IndexOf(sd.Line);
|
|
|
|
if(lineindex > -1)
|
|
|
|
{
|
|
|
|
// Mark this side as done
|
|
|
|
if(sd.IsFront)
|
|
|
|
frontsdone[lineindex] = true;
|
|
|
|
else
|
|
|
|
backsdone[lineindex] = true;
|
|
|
|
}
|
2008-05-01 19:31:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-05 18:21:13 +00:00
|
|
|
|
|
|
|
// Make corrections for backward linedefs
|
|
|
|
MapSet.FlipBackwardLinedefs(newlines);
|
2008-05-05 22:22:53 +00:00
|
|
|
|
2008-05-08 13:44:48 +00:00
|
|
|
// Remove all unneeded textures
|
|
|
|
foreach(Linedef ld in newlines)
|
|
|
|
{
|
|
|
|
if(ld.Front != null) ld.Front.RemoveUnneededTextures(true);
|
|
|
|
if(ld.Back != null) ld.Back.RemoveUnneededTextures(true);
|
|
|
|
}
|
|
|
|
foreach(Sidedef sd in insidesides)
|
|
|
|
{
|
|
|
|
sd.RemoveUnneededTextures(true);
|
|
|
|
}
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-05-19 06:51:55 +00:00
|
|
|
// Check if any of our new lines have sides
|
|
|
|
if(sidescreated)
|
|
|
|
{
|
|
|
|
// Then remove the lines which have no sides at all
|
|
|
|
for(int i = newlines.Count - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
// Remove the line if it has no sides
|
|
|
|
if((newlines[i].Front == null) && (newlines[i].Back == null)) newlines[i].Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-05 22:22:53 +00:00
|
|
|
// Snap to map format accuracy
|
|
|
|
General.Map.Map.SnapAllToAccuracy();
|
2008-05-16 21:08:36 +00:00
|
|
|
|
2008-04-20 22:54:24 +00:00
|
|
|
// Update cached values
|
2008-05-01 10:59:37 +00:00
|
|
|
map.Update();
|
2008-04-20 22:54:24 +00:00
|
|
|
|
|
|
|
// Map is changed
|
|
|
|
General.Map.IsChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Done
|
|
|
|
Cursor.Current = Cursors.Default;
|
2008-05-16 21:08:36 +00:00
|
|
|
|
|
|
|
// Return to original mode
|
|
|
|
Type t = basemode.GetType();
|
|
|
|
basemode = (EditMode)Activator.CreateInstance(t);
|
|
|
|
General.Map.ChangeMode(basemode);
|
2008-04-20 22:54:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This checks if the view offset/zoom changed and updates the check
|
|
|
|
protected bool CheckViewChanged()
|
|
|
|
{
|
|
|
|
bool viewchanged = false;
|
2008-04-27 12:07:26 +00:00
|
|
|
|
2008-04-20 22:54:24 +00:00
|
|
|
// View changed?
|
|
|
|
if(renderer.OffsetX != lastoffsetx) viewchanged = true;
|
|
|
|
if(renderer.OffsetY != lastoffsety) viewchanged = true;
|
|
|
|
if(renderer.Scale != lastscale) viewchanged = true;
|
|
|
|
|
|
|
|
// Keep view information
|
|
|
|
lastoffsetx = renderer.OffsetX;
|
|
|
|
lastoffsety = renderer.OffsetY;
|
|
|
|
lastscale = renderer.Scale;
|
|
|
|
|
|
|
|
// Return result
|
|
|
|
return viewchanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This redraws the display
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnRedrawDisplay()
|
2008-04-20 22:54:24 +00:00
|
|
|
{
|
|
|
|
// Render lines
|
|
|
|
if(renderer.StartPlotter(true))
|
|
|
|
{
|
|
|
|
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
|
|
|
|
renderer.PlotVerticesSet(General.Map.Map.Vertices);
|
|
|
|
renderer.Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render things
|
|
|
|
if(renderer.StartThings(true))
|
|
|
|
{
|
|
|
|
renderer.RenderThingSet(General.Map.Map.Things);
|
|
|
|
renderer.Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Normal update
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This updates the dragging
|
|
|
|
private void Update()
|
|
|
|
{
|
2008-05-08 22:01:37 +00:00
|
|
|
PixelColor stitchcolor = General.Colors.Highlight;
|
|
|
|
PixelColor losecolor = General.Colors.Selection;
|
2008-05-05 18:21:13 +00:00
|
|
|
PixelColor color;
|
|
|
|
|
2008-04-20 22:54:24 +00:00
|
|
|
snaptogrid = General.Interface.ShiftState ^ General.Interface.SnapToGrid;
|
2008-04-29 14:41:16 +00:00
|
|
|
snaptonearest = General.Interface.CtrlState ^ General.Interface.AutoMerge;
|
2008-04-20 22:54:24 +00:00
|
|
|
|
2008-05-05 18:21:13 +00:00
|
|
|
DrawnVertex lastp = new DrawnVertex();
|
2008-04-29 14:41:16 +00:00
|
|
|
DrawnVertex curp = GetCurrentPosition();
|
2008-04-27 12:07:26 +00:00
|
|
|
float vsize = ((float)renderer.VertexSize + 1.0f) / renderer.Scale;
|
2008-05-08 22:01:37 +00:00
|
|
|
float vsizeborder = ((float)renderer.VertexSize + 3.0f) / renderer.Scale;
|
2008-04-27 12:07:26 +00:00
|
|
|
|
2008-05-13 17:11:33 +00:00
|
|
|
// The last label's end must go to the mouse cursor
|
|
|
|
if(labels.Count > 0) labels[labels.Count - 1].End = curp.pos;
|
|
|
|
|
2008-04-20 22:54:24 +00:00
|
|
|
// Render drawing lines
|
|
|
|
if(renderer.StartOverlay(true))
|
|
|
|
{
|
2008-04-27 12:07:26 +00:00
|
|
|
// Go for all points to draw lines
|
|
|
|
if(points.Count > 0)
|
|
|
|
{
|
|
|
|
// Render lines
|
2008-05-05 18:21:13 +00:00
|
|
|
lastp = points[0];
|
2008-04-27 12:07:26 +00:00
|
|
|
for(int i = 1; i < points.Count; i++)
|
|
|
|
{
|
2008-05-05 18:21:13 +00:00
|
|
|
// Determine line color
|
2008-05-08 22:01:37 +00:00
|
|
|
if(lastp.stitch && points[i].stitch) color = stitchcolor;
|
|
|
|
else color = losecolor;
|
2008-05-05 18:21:13 +00:00
|
|
|
|
|
|
|
// Render line
|
|
|
|
renderer.RenderLine(lastp.pos, points[i].pos, LINE_THICKNESS, color, true);
|
|
|
|
lastp = points[i];
|
2008-04-27 12:07:26 +00:00
|
|
|
}
|
2008-05-05 18:21:13 +00:00
|
|
|
|
|
|
|
// Determine line color
|
2008-05-08 22:01:37 +00:00
|
|
|
if(lastp.stitch && snaptonearest) color = stitchcolor;
|
|
|
|
else color = losecolor;
|
2008-05-05 18:21:13 +00:00
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
// Render line to cursor
|
2008-05-05 18:21:13 +00:00
|
|
|
renderer.RenderLine(lastp.pos, curp.pos, LINE_THICKNESS, color, true);
|
2008-04-27 12:07:26 +00:00
|
|
|
|
|
|
|
// Render vertices
|
|
|
|
for(int i = 0; i < points.Count; i++)
|
2008-04-29 14:41:16 +00:00
|
|
|
{
|
2008-05-08 22:01:37 +00:00
|
|
|
// Determine line color
|
|
|
|
if(points[i].stitch) color = stitchcolor;
|
|
|
|
else color = losecolor;
|
|
|
|
|
|
|
|
// Render line
|
|
|
|
renderer.RenderRectangleFilled(new RectangleF(points[i].pos.x - vsize, points[i].pos.y - vsize, vsize * 2.0f, vsize * 2.0f), color, true);
|
2008-04-29 14:41:16 +00:00
|
|
|
}
|
2008-04-27 12:07:26 +00:00
|
|
|
}
|
2008-05-08 22:01:37 +00:00
|
|
|
|
2008-05-05 18:21:13 +00:00
|
|
|
// Determine point color
|
2008-05-08 22:01:37 +00:00
|
|
|
if(snaptonearest) color = stitchcolor;
|
|
|
|
else color = losecolor;
|
2008-05-05 18:21:13 +00:00
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
// Render vertex at cursor
|
2008-05-05 18:21:13 +00:00
|
|
|
renderer.RenderRectangleFilled(new RectangleF(curp.pos.x - vsize, curp.pos.y - vsize, vsize * 2.0f, vsize * 2.0f), color, true);
|
2008-04-27 12:07:26 +00:00
|
|
|
|
2008-05-13 17:11:33 +00:00
|
|
|
// Go for all labels
|
|
|
|
foreach(LineLengthLabel l in labels) renderer.RenderText(l.TextLabel);
|
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
// Done
|
2008-04-20 22:54:24 +00:00
|
|
|
renderer.Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Done
|
|
|
|
renderer.Present();
|
|
|
|
}
|
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
// This gets the aligned and snapped draw position
|
2008-04-29 14:41:16 +00:00
|
|
|
private DrawnVertex GetCurrentPosition()
|
2008-04-27 12:07:26 +00:00
|
|
|
{
|
2008-04-29 14:41:16 +00:00
|
|
|
DrawnVertex p = new DrawnVertex();
|
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
// Snap to nearest?
|
|
|
|
if(snaptonearest)
|
|
|
|
{
|
|
|
|
float vrange = VerticesMode.VERTEX_HIGHLIGHT_RANGE / renderer.Scale;
|
|
|
|
|
|
|
|
// Go for all drawn points
|
2008-04-29 14:41:16 +00:00
|
|
|
foreach(DrawnVertex v in points)
|
2008-04-27 12:07:26 +00:00
|
|
|
{
|
2008-04-29 14:41:16 +00:00
|
|
|
Vector2D delta = mousemappos - v.pos;
|
|
|
|
if(delta.GetLengthSq() < (vrange * vrange))
|
|
|
|
{
|
|
|
|
p.pos = v.pos;
|
|
|
|
p.stitch = true;
|
|
|
|
return p;
|
|
|
|
}
|
2008-04-27 12:07:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try the nearest vertex
|
|
|
|
Vertex nv = General.Map.Map.NearestVertexSquareRange(mousemappos, vrange);
|
2008-04-29 14:41:16 +00:00
|
|
|
if(nv != null)
|
|
|
|
{
|
|
|
|
p.pos = nv.Position;
|
|
|
|
p.stitch = true;
|
|
|
|
return p;
|
|
|
|
}
|
2008-04-27 12:07:26 +00:00
|
|
|
|
|
|
|
// Try the nearest linedef
|
|
|
|
Linedef nl = General.Map.Map.NearestLinedefRange(mousemappos, LinedefsMode.LINEDEF_HIGHLIGHT_RANGE / renderer.Scale);
|
|
|
|
if(nl != null)
|
|
|
|
{
|
|
|
|
// Snap to grid?
|
|
|
|
if(snaptogrid)
|
|
|
|
{
|
2008-04-29 14:41:16 +00:00
|
|
|
// Get grid intersection coordinates
|
|
|
|
List<Vector2D> coords = nl.GetGridIntersections();
|
|
|
|
|
|
|
|
// Find nearest grid intersection
|
|
|
|
float found_distance = float.MaxValue;
|
|
|
|
Vector2D found_coord = new Vector2D();
|
|
|
|
foreach(Vector2D v in coords)
|
|
|
|
{
|
|
|
|
Vector2D delta = mousemappos - v;
|
|
|
|
if(delta.GetLengthSq() < found_distance)
|
|
|
|
{
|
|
|
|
found_distance = delta.GetLengthSq();
|
|
|
|
found_coord = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Align to the closest grid intersection
|
|
|
|
p.pos = found_coord;
|
|
|
|
p.stitch = true;
|
|
|
|
return p;
|
2008-04-27 12:07:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Aligned to line
|
2008-04-29 14:41:16 +00:00
|
|
|
p.pos = nl.NearestOnLine(mousemappos);
|
|
|
|
p.stitch = true;
|
|
|
|
return p;
|
2008-04-27 12:07:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Snap to grid?
|
|
|
|
if(snaptogrid)
|
|
|
|
{
|
|
|
|
// Aligned to grid
|
2008-04-29 14:41:16 +00:00
|
|
|
p.pos = General.Map.Grid.SnappedToGrid(mousemappos);
|
2008-05-01 10:59:37 +00:00
|
|
|
p.stitch = snaptonearest;
|
2008-04-29 14:41:16 +00:00
|
|
|
return p;
|
2008-04-27 12:07:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Normal position
|
2008-04-29 14:41:16 +00:00
|
|
|
p.pos = mousemappos;
|
2008-05-01 10:59:37 +00:00
|
|
|
p.stitch = snaptonearest;
|
2008-04-29 14:41:16 +00:00
|
|
|
return p;
|
2008-04-27 12:07:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-20 22:54:24 +00:00
|
|
|
// Mouse moving
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnMouseMove(MouseEventArgs e)
|
2008-04-20 22:54:24 +00:00
|
|
|
{
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnMouseMove(e);
|
2008-04-20 22:54:24 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2008-05-17 08:00:25 +00:00
|
|
|
// This draws a point at a specific location
|
|
|
|
public void DrawPointAt(Vector2D pos, bool stitch)
|
|
|
|
{
|
|
|
|
DrawnVertex newpoint = new DrawnVertex();
|
|
|
|
newpoint.pos = pos;
|
|
|
|
newpoint.stitch = stitch;
|
|
|
|
points.Add(newpoint);
|
|
|
|
labels.Add(new LineLengthLabel());
|
|
|
|
labels[labels.Count - 1].Start = newpoint.pos;
|
|
|
|
if(labels.Count > 1) labels[labels.Count - 2].End = newpoint.pos;
|
|
|
|
Update();
|
|
|
|
|
|
|
|
// Check if point stitches with the first
|
|
|
|
if((points.Count > 1) && (points[points.Count - 1].stitch))
|
|
|
|
{
|
|
|
|
Vector2D p1 = points[0].pos;
|
|
|
|
Vector2D p2 = points[points.Count - 1].pos;
|
|
|
|
Vector2D delta = p1 - p2;
|
|
|
|
if((Math.Abs(delta.x) <= 0.001f) && (Math.Abs(delta.y) <= 0.001f))
|
|
|
|
{
|
|
|
|
// Finish drawing
|
|
|
|
FinishDraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
// Drawing a point
|
|
|
|
[BeginAction("drawpoint")]
|
|
|
|
public void DrawPoint()
|
|
|
|
{
|
|
|
|
// Mouse inside window?
|
|
|
|
if(General.Interface.MouseInDisplay)
|
|
|
|
{
|
2008-05-13 17:11:33 +00:00
|
|
|
DrawnVertex newpoint = GetCurrentPosition();
|
2008-05-17 08:00:25 +00:00
|
|
|
DrawPointAt(newpoint.pos, newpoint.stitch);
|
2008-04-27 12:07:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove a point
|
|
|
|
[BeginAction("removepoint")]
|
|
|
|
public void RemovePoint()
|
|
|
|
{
|
|
|
|
if(points.Count > 0) points.RemoveAt(points.Count - 1);
|
2008-05-13 17:11:33 +00:00
|
|
|
if(labels.Count > 0)
|
|
|
|
{
|
|
|
|
labels[labels.Count - 1].Dispose();
|
|
|
|
labels.RemoveAt(labels.Count - 1);
|
|
|
|
}
|
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finish drawing
|
|
|
|
[BeginAction("finishdraw")]
|
|
|
|
public void FinishDraw()
|
2008-04-20 22:54:24 +00:00
|
|
|
{
|
2008-05-16 21:08:36 +00:00
|
|
|
// Accept the changes
|
|
|
|
General.Map.AcceptMode();
|
2008-04-20 22:54:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// When a key is released
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnKeyUp(KeyEventArgs e)
|
2008-04-20 22:54:24 +00:00
|
|
|
{
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnKeyUp(e);
|
2008-04-29 14:41:16 +00:00
|
|
|
if((snaptogrid != (General.Interface.ShiftState ^ General.Interface.SnapToGrid)) ||
|
|
|
|
(snaptonearest != (General.Interface.CtrlState ^ General.Interface.AutoMerge))) Update();
|
2008-04-20 22:54:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// When a key is pressed
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnKeyDown(KeyEventArgs e)
|
2008-04-20 22:54:24 +00:00
|
|
|
{
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnKeyDown(e);
|
2008-04-29 14:41:16 +00:00
|
|
|
if((snaptogrid != (General.Interface.ShiftState ^ General.Interface.SnapToGrid)) ||
|
|
|
|
(snaptonearest != (General.Interface.CtrlState ^ General.Interface.AutoMerge))) Update();
|
2008-04-20 22:54:24 +00:00
|
|
|
}
|
|
|
|
|
2008-02-24 21:52:18 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|