2009-04-19 18:07:22 +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
|
|
|
|
|
|
|
|
using System;
|
2016-04-25 14:48:39 +00:00
|
|
|
using System.Collections.Generic;
|
2009-04-19 18:07:22 +00:00
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
using CodeImp.DoomBuilder.Editing;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
|
|
|
{
|
|
|
|
// No action or button for this mode, it is automatic.
|
|
|
|
// The EditMode attribute does not have to be specified unless the
|
|
|
|
// mode must be activated by class name rather than direct instance.
|
|
|
|
// In that case, just specifying the attribute like this is enough:
|
|
|
|
// [EditMode]
|
|
|
|
|
|
|
|
[EditMode(DisplayName = "Vertices",
|
2011-12-03 14:49:53 +00:00
|
|
|
AllowCopyPaste = false,
|
2009-04-19 18:07:22 +00:00
|
|
|
Volatile = true)]
|
|
|
|
|
|
|
|
public sealed class DragVerticesMode : DragGeometryMode
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor to start dragging immediately
|
2016-04-25 14:48:39 +00:00
|
|
|
public DragVerticesMode(Vector2D dragstartmappos)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Mark what we are dragging
|
|
|
|
General.Map.Map.ClearAllMarks(false);
|
|
|
|
General.Map.Map.MarkSelectedVertices(true, true);
|
|
|
|
|
|
|
|
// Initialize
|
|
|
|
base.StartDrag(dragstartmappos);
|
2015-09-25 13:20:53 +00:00
|
|
|
undodescription = (selectedverts.Count == 1 ? "Drag vertex" : "Drag " + selectedverts.Count + " vertices"); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
public override void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
|
|
|
|
// Done
|
|
|
|
base.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// Disenagaging
|
|
|
|
public override void OnDisengage()
|
|
|
|
{
|
|
|
|
// Select vertices from marks
|
|
|
|
General.Map.Map.ClearSelectedVertices();
|
|
|
|
General.Map.Map.SelectMarkedVertices(true, true);
|
2016-05-18 20:31:40 +00:00
|
|
|
|
|
|
|
//mxd. Mark stable lines now (marks will be carried to split lines by MapSet.StitchGeometry())
|
|
|
|
HashSet<Linedef> stablelines = (!cancelled ? new HashSet<Linedef>(General.Map.Map.LinedefsFromMarkedVertices(false, true, false)) : new HashSet<Linedef>());
|
|
|
|
foreach(Linedef l in stablelines) l.Marked = true;
|
|
|
|
|
|
|
|
//mxd. Mark moved sectors (used in Linedef.Join())
|
|
|
|
HashSet<Sector> draggeddsectors = (!cancelled ? General.Map.Map.GetUnselectedSectorsFromLinedefs(stablelines) : new HashSet<Sector>());
|
|
|
|
foreach(Sector s in draggeddsectors) s.Marked = true;
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Perform normal disengage
|
|
|
|
base.OnDisengage();
|
|
|
|
|
|
|
|
// When not cancelled
|
|
|
|
if(!cancelled)
|
|
|
|
{
|
2016-05-19 21:44:39 +00:00
|
|
|
//mxd. If linedefs were dragged, reattach/add/remove sidedefs
|
|
|
|
if(stablelines.Count > 0)
|
2016-04-25 14:48:39 +00:00
|
|
|
{
|
2016-05-18 20:31:40 +00:00
|
|
|
// Get new lines from linedef marks...
|
|
|
|
HashSet<Linedef> newlines = new HashSet<Linedef>(General.Map.Map.GetMarkedLinedefs(true));
|
|
|
|
|
|
|
|
// Marked lines were created during linedef splitting
|
|
|
|
HashSet<Linedef> changedlines = new HashSet<Linedef>(stablelines);
|
|
|
|
changedlines.UnionWith(newlines);
|
|
|
|
|
|
|
|
// Get sectors, which have all their linedefs selected (otherwise those would be destroyed after moving the selection)
|
|
|
|
HashSet<Sector> toadjust = General.Map.Map.GetUnselectedSectorsFromLinedefs(changedlines);
|
|
|
|
|
|
|
|
if(changedlines.Count > 0)
|
|
|
|
{
|
2016-05-19 21:44:39 +00:00
|
|
|
// Reattach/add/remove outer sidedefs
|
2016-05-18 20:31:40 +00:00
|
|
|
Tools.AdjustOuterSidedefs(toadjust, changedlines);
|
|
|
|
|
|
|
|
// Split outer sectors
|
|
|
|
Tools.SplitOuterSectors(changedlines);
|
|
|
|
|
|
|
|
// Additional verts may've been created
|
|
|
|
if(selectedverts.Count > 1)
|
|
|
|
{
|
|
|
|
foreach(Linedef l in changedlines)
|
|
|
|
{
|
|
|
|
l.Start.Selected = true;
|
|
|
|
l.End.Selected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-25 14:48:39 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// If only a single vertex was selected, deselect it now
|
|
|
|
if(selectedverts.Count == 1) General.Map.Map.ClearSelectedVertices();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This redraws the display
|
|
|
|
public override void OnRedrawDisplay()
|
|
|
|
{
|
|
|
|
bool viewchanged = CheckViewChanged();
|
|
|
|
|
|
|
|
renderer.RedrawSurface();
|
|
|
|
|
2009-06-11 21:21:20 +00:00
|
|
|
UpdateRedraw();
|
|
|
|
|
|
|
|
// Redraw things when view changed
|
|
|
|
if(viewchanged)
|
|
|
|
{
|
|
|
|
if(renderer.StartThings(true))
|
|
|
|
{
|
2016-04-01 10:49:19 +00:00
|
|
|
renderer.RenderThingSet(General.Map.Map.Things, General.Settings.ActiveThingsAlpha);
|
2009-06-11 21:21:20 +00:00
|
|
|
renderer.Finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderer.Present();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This redraws only the required things
|
|
|
|
protected override void UpdateRedraw()
|
|
|
|
{
|
2009-04-19 18:07:22 +00:00
|
|
|
// Start rendering
|
|
|
|
if(renderer.StartPlotter(true))
|
|
|
|
{
|
|
|
|
// Render lines and vertices
|
|
|
|
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
|
|
|
|
renderer.PlotVerticesSet(unselectedverts);
|
|
|
|
renderer.PlotVerticesSet(selectedverts);
|
|
|
|
|
|
|
|
// Draw the dragged item highlighted
|
|
|
|
// This is important to know, because this item is used
|
|
|
|
// for snapping to the grid and snapping to nearest items
|
|
|
|
renderer.PlotVertex(dragitem, ColorCollection.HIGHLIGHT);
|
|
|
|
|
|
|
|
// Done
|
|
|
|
renderer.Finish();
|
|
|
|
}
|
|
|
|
|
2014-01-13 08:06:56 +00:00
|
|
|
//mxd. Render things
|
2014-12-03 23:15:26 +00:00
|
|
|
if(renderer.StartThings(true))
|
|
|
|
{
|
2016-03-30 11:29:39 +00:00
|
|
|
renderer.RenderThingSet(General.Map.ThingsFilter.HiddenThings, General.Settings.HiddenThingsAlpha);
|
2016-04-01 10:49:19 +00:00
|
|
|
renderer.RenderThingSet(unselectedthings, General.Settings.ActiveThingsAlpha);
|
|
|
|
renderer.RenderThingSet(selectedthings, General.Settings.ActiveThingsAlpha);
|
2014-01-13 08:06:56 +00:00
|
|
|
renderer.Finish();
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Redraw overlay
|
|
|
|
if(renderer.StartOverlay(true))
|
|
|
|
{
|
2016-04-25 14:48:39 +00:00
|
|
|
renderer.RenderText(labels);
|
2009-04-19 18:07:22 +00:00
|
|
|
renderer.Finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|