2008-02-19 19:04:19 +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;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
|
|
|
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;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
|
|
|
{
|
|
|
|
// 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]
|
|
|
|
|
2008-02-24 21:52:18 +00:00
|
|
|
public sealed class DragSectorsMode : DragGeometryMode
|
2008-02-19 19:04:19 +00:00
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
private ICollection<Linedef> selectedlines;
|
|
|
|
private ICollection<Linedef> unselectedlines;
|
|
|
|
private ICollection<Sector> selectedsectors;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor to start dragging immediately
|
|
|
|
public DragSectorsMode(EditMode basemode, Sector dragitem, Vector2D dragstartmappos)
|
|
|
|
{
|
|
|
|
// Get the nearest vertex for snapping
|
2008-04-07 12:20:48 +00:00
|
|
|
Vertex nearest = MapSet.NearestVertex(General.Map.Map.GetVerticesFromLinesSelection(true), dragstartmappos);
|
2008-02-19 19:04:19 +00:00
|
|
|
|
|
|
|
// Get selected lines
|
|
|
|
selectedlines = General.Map.Map.GetLinedefsSelection(true);
|
|
|
|
unselectedlines = General.Map.Map.GetLinedefsSelection(false);
|
|
|
|
selectedsectors = General.Map.Map.GetSectorsSelection(true);
|
|
|
|
|
|
|
|
// Initialize
|
|
|
|
base.StartDrag(basemode, nearest, dragstartmappos,
|
|
|
|
General.Map.Map.GetVerticesFromLinesSelection(true),
|
|
|
|
General.Map.Map.GetVerticesFromLinesSelectionEx(false));
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// Mode engages
|
|
|
|
public override void Engage()
|
|
|
|
{
|
|
|
|
base.Engage();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disenagaging
|
|
|
|
public override void Disengage()
|
|
|
|
{
|
|
|
|
base.Disengage();
|
|
|
|
|
|
|
|
// When not cancelled
|
|
|
|
if(!cancelled)
|
|
|
|
{
|
|
|
|
// If only a single sector was selected, deselect it now
|
2008-02-21 06:47:43 +00:00
|
|
|
if(selectedsectors.Count == 1)
|
|
|
|
{
|
|
|
|
General.Map.Map.ClearSelectedSectors();
|
|
|
|
General.Map.Map.ClearSelectedLinedefs();
|
|
|
|
}
|
2008-02-19 19:04:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This redraws the display
|
|
|
|
public unsafe override void RedrawDisplay()
|
|
|
|
{
|
2008-02-19 21:32:40 +00:00
|
|
|
bool viewchanged = CheckViewChanged();
|
2008-02-19 19:04:19 +00:00
|
|
|
|
|
|
|
// Start rendering
|
|
|
|
if(renderer.Start(true, viewchanged))
|
|
|
|
{
|
|
|
|
// Uncomment this to see triangulation
|
|
|
|
/*
|
|
|
|
foreach(Sector s in General.Map.Map.Sectors)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < s.Triangles.Count; i += 3)
|
|
|
|
{
|
|
|
|
renderer.RenderLine(s.Triangles[i + 0], s.Triangles[i + 1], General.Colors.Selection);
|
|
|
|
renderer.RenderLine(s.Triangles[i + 1], s.Triangles[i + 2], General.Colors.Selection);
|
|
|
|
renderer.RenderLine(s.Triangles[i + 2], s.Triangles[i + 0], General.Colors.Selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Redraw things when view changed
|
2008-02-19 21:32:40 +00:00
|
|
|
if(viewchanged)
|
2008-02-19 19:04:19 +00:00
|
|
|
{
|
|
|
|
renderer.SetThingsRenderOrder(false);
|
|
|
|
renderer.RenderThingSet(General.Map.Map.Things);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render lines and vertices
|
|
|
|
renderer.RenderLinedefSet(unselectedlines);
|
|
|
|
renderer.RenderLinedefSet(selectedlines);
|
|
|
|
renderer.RenderVerticesSet(General.Map.Map.Vertices);
|
|
|
|
|
|
|
|
// 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.RenderVertex(dragitem, ColorCollection.HIGHLIGHT);
|
|
|
|
|
|
|
|
// Done
|
|
|
|
renderer.Finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|