2007-11-07 21:14:27 +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;
|
2007-12-05 19:39:09 +00:00
|
|
|
using System.Drawing;
|
2008-01-02 21:49:43 +00:00
|
|
|
using CodeImp.DoomBuilder.Editing;
|
2007-11-07 21:14:27 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
2007-11-07 21:14:27 +00:00
|
|
|
{
|
2008-01-04 00:16:58 +00:00
|
|
|
// 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:
|
2008-01-02 21:49:43 +00:00
|
|
|
[EditMode]
|
2008-01-04 00:16:58 +00:00
|
|
|
|
2008-02-24 21:52:18 +00:00
|
|
|
public sealed class DragVerticesMode : DragGeometryMode
|
2007-11-07 21:14:27 +00:00
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
2007-12-01 18:29:58 +00:00
|
|
|
private ICollection<Vertex> selectedverts;
|
2007-12-01 01:32:56 +00:00
|
|
|
private ICollection<Vertex> unselectedverts;
|
2007-11-15 23:38:09 +00:00
|
|
|
|
2007-11-07 21:14:27 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
2008-01-02 21:49:43 +00:00
|
|
|
|
2007-11-07 21:14:27 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor to start dragging immediately
|
2007-12-26 00:31:32 +00:00
|
|
|
public DragVerticesMode(EditMode basemode, Vertex dragitem, Vector2D dragstartmappos)
|
2007-11-07 21:14:27 +00:00
|
|
|
{
|
2008-02-19 18:54:04 +00:00
|
|
|
// Get selected vertices
|
2007-12-01 18:29:58 +00:00
|
|
|
selectedverts = General.Map.Map.GetVerticesSelection(true);
|
|
|
|
unselectedverts = General.Map.Map.GetVerticesSelection(false);
|
|
|
|
|
2008-02-19 18:54:04 +00:00
|
|
|
// Initialize
|
|
|
|
base.StartDrag(basemode, dragitem, dragstartmappos,
|
|
|
|
General.Map.Map.GetVerticesSelection(true),
|
|
|
|
General.Map.Map.GetVerticesSelection(false));
|
2008-02-15 12:15:46 +00:00
|
|
|
|
2007-11-07 21:14:27 +00:00
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
// Disposer
|
2007-11-07 21:14:27 +00:00
|
|
|
public override void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
|
|
|
|
// Done
|
2008-02-19 18:54:04 +00:00
|
|
|
base.Dispose();
|
2007-11-07 21:14:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
2007-11-10 01:58:08 +00:00
|
|
|
|
2007-11-10 19:24:52 +00:00
|
|
|
// Mode engages
|
|
|
|
public override void Engage()
|
|
|
|
{
|
|
|
|
base.Engage();
|
|
|
|
}
|
|
|
|
|
2007-11-10 01:58:08 +00:00
|
|
|
// Disenagaging
|
|
|
|
public override void Disengage()
|
|
|
|
{
|
2007-11-10 19:24:52 +00:00
|
|
|
base.Disengage();
|
|
|
|
|
2007-11-10 01:58:08 +00:00
|
|
|
// When not cancelled
|
|
|
|
if(!cancelled)
|
|
|
|
{
|
2007-12-01 01:32:56 +00:00
|
|
|
// If only a single vertex was selected, deselect it now
|
2007-12-01 18:29:58 +00:00
|
|
|
if(selectedverts.Count == 1) General.Map.Map.ClearSelectedVertices();
|
2007-11-10 01:58:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-10 19:24:52 +00:00
|
|
|
// This redraws the display
|
|
|
|
public unsafe override void RedrawDisplay()
|
2007-11-10 01:58:08 +00:00
|
|
|
{
|
2008-02-19 21:32:40 +00:00
|
|
|
bool viewchanged = CheckViewChanged();
|
2008-02-15 12:15:46 +00:00
|
|
|
|
2007-11-21 12:50:56 +00:00
|
|
|
// Start rendering
|
2008-02-15 12:15:46 +00:00
|
|
|
if(renderer.Start(true, viewchanged))
|
2007-11-10 19:24:52 +00:00
|
|
|
{
|
2008-01-13 21:23:59 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2008-02-15 12:15:46 +00:00
|
|
|
|
|
|
|
// Redraw things when view changed
|
2008-02-19 21:32:40 +00:00
|
|
|
if(viewchanged)
|
2008-02-15 12:15:46 +00:00
|
|
|
{
|
|
|
|
renderer.SetThingsRenderOrder(false);
|
|
|
|
renderer.RenderThingSet(General.Map.Map.Things);
|
|
|
|
}
|
2008-01-13 21:23:59 +00:00
|
|
|
|
2007-11-10 19:24:52 +00:00
|
|
|
// Render lines and vertices
|
|
|
|
renderer.RenderLinedefSet(General.Map.Map.Linedefs);
|
2007-12-01 18:29:58 +00:00
|
|
|
renderer.RenderVerticesSet(unselectedverts);
|
|
|
|
renderer.RenderVerticesSet(selectedverts);
|
2007-11-10 19:24:52 +00:00
|
|
|
|
2007-11-15 23:38:09 +00:00
|
|
|
// 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);
|
|
|
|
|
2007-11-10 19:24:52 +00:00
|
|
|
// Done
|
2007-11-21 12:50:56 +00:00
|
|
|
renderer.Finish();
|
2007-11-10 19:24:52 +00:00
|
|
|
}
|
2007-11-10 01:58:08 +00:00
|
|
|
}
|
|
|
|
|
2007-11-07 21:14:27 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|